1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 21:30:03 -04:00

glow: reuse the same GL texture when possible (#1142)

This commit is contained in:
Emil Ernerfeldt
2022-01-21 19:51:52 +01:00
committed by GitHub
parent 30f9700f6c
commit 8138a073e7
2 changed files with 76 additions and 98 deletions

View File

@@ -2,80 +2,6 @@
use glow::HasContext;
use std::option::Option::Some;
use crate::painter::TextureFilter;
pub(crate) fn srgb_texture2d(
gl: &glow::Context,
is_webgl_1: bool,
srgb_support: bool,
texture_filter: TextureFilter,
data: &[u8],
w: usize,
h: usize,
) -> glow::Texture {
assert_eq!(data.len(), w * h * 4);
assert!(w >= 1);
assert!(h >= 1);
unsafe {
let tex = gl.create_texture().unwrap();
gl.bind_texture(glow::TEXTURE_2D, Some(tex));
gl.tex_parameter_i32(
glow::TEXTURE_2D,
glow::TEXTURE_MAG_FILTER,
texture_filter.glow_code() as i32,
);
gl.tex_parameter_i32(
glow::TEXTURE_2D,
glow::TEXTURE_MIN_FILTER,
texture_filter.glow_code() as i32,
);
gl.tex_parameter_i32(
glow::TEXTURE_2D,
glow::TEXTURE_WRAP_S,
glow::CLAMP_TO_EDGE as i32,
);
gl.tex_parameter_i32(
glow::TEXTURE_2D,
glow::TEXTURE_WRAP_T,
glow::CLAMP_TO_EDGE as i32,
);
if is_webgl_1 {
let format = if srgb_support {
glow::SRGB_ALPHA
} else {
glow::RGBA
};
gl.tex_image_2d(
glow::TEXTURE_2D,
0,
format as i32,
w as i32,
h as i32,
0,
format,
glow::UNSIGNED_BYTE,
Some(data),
);
} else {
gl.tex_storage_2d(glow::TEXTURE_2D, 1, glow::SRGB8_ALPHA8, w as i32, h as i32);
gl.tex_sub_image_2d(
glow::TEXTURE_2D,
0,
0,
0,
w as i32,
h as i32,
glow::RGBA,
glow::UNSIGNED_BYTE,
glow::PixelUnpackData::Slice(data),
);
}
check_for_gl_error(gl, "srgb_texture2d");
tex
}
}
pub fn check_for_gl_error(gl: &glow::Context, context: &str) {
let error_code = unsafe { gl.get_error() };
if error_code != glow::NO_ERROR {