From 32ff6ce2d75e898cd350172916751ec13226d5f8 Mon Sep 17 00:00:00 2001 From: LLLL Colonq Date: Wed, 9 Apr 2025 03:13:42 -0400 Subject: Reorganize into workspace --- src/texture.rs | 83 ---------------------------------------------------------- 1 file changed, 83 deletions(-) delete mode 100644 src/texture.rs (limited to 'src/texture.rs') diff --git a/src/texture.rs b/src/texture.rs deleted file mode 100644 index 68272cb..0000000 --- a/src/texture.rs +++ /dev/null @@ -1,83 +0,0 @@ -use glow::HasContext; -use image::EncodableLayout; - -use crate::context; - -pub struct Texture { - pub tex: glow::Texture, -} - -impl Texture { - pub fn new_empty(ctx: &context::Context) -> Self { - unsafe { - let tex = ctx.gl.create_texture().expect("failed to create texture"); - ctx.gl.bind_texture(glow::TEXTURE_2D, Some(tex)); - ctx.gl.tex_parameter_i32(glow::TEXTURE_2D, glow::TEXTURE_WRAP_S, glow::CLAMP_TO_EDGE as i32); - ctx.gl.tex_parameter_i32(glow::TEXTURE_2D, glow::TEXTURE_WRAP_T, glow::CLAMP_TO_EDGE as i32); - ctx.gl.tex_parameter_i32(glow::TEXTURE_2D, glow::TEXTURE_MIN_FILTER, glow::NEAREST as i32); - ctx.gl.tex_parameter_i32(glow::TEXTURE_2D, glow::TEXTURE_MAG_FILTER, glow::NEAREST as i32); - Self { - tex, - } - } - } - - pub fn new(ctx: &context::Context, bytes: &[u8]) -> Self { - let rgba = image::io::Reader::new(std::io::Cursor::new(bytes)) - .with_guessed_format() - .expect("failed to guess image format") - .decode() - .expect("failed to decode image") - .into_rgba8(); - let pixels = rgba.as_bytes(); - unsafe { - let tex = ctx.gl.create_texture().expect("failed to create texture"); - ctx.gl.bind_texture(glow::TEXTURE_2D, Some(tex)); - ctx.gl.tex_parameter_i32(glow::TEXTURE_2D, glow::TEXTURE_WRAP_S, glow::CLAMP_TO_EDGE as i32); - ctx.gl.tex_parameter_i32(glow::TEXTURE_2D, glow::TEXTURE_WRAP_T, glow::CLAMP_TO_EDGE as i32); - ctx.gl.tex_parameter_i32(glow::TEXTURE_2D, glow::TEXTURE_MIN_FILTER, glow::NEAREST as i32); - ctx.gl.tex_parameter_i32(glow::TEXTURE_2D, glow::TEXTURE_MAG_FILTER, glow::NEAREST as i32); - ctx.gl.tex_image_2d( - glow::TEXTURE_2D, - 0, - glow::RGBA as i32, - rgba.width() as i32, - rgba.height() as i32, - 0, - glow::RGBA, - glow::UNSIGNED_BYTE, - Some(pixels), - ); - ctx.gl.generate_mipmap(glow::TEXTURE_2D); - - Self { - tex, - } - } - } - - pub fn set_anisotropic_filtering(&self, ctx: &context::Context) { - unsafe { - ctx.gl.bind_texture(glow::TEXTURE_2D, Some(self.tex)); - ctx.gl.tex_parameter_i32(glow::TEXTURE_2D, glow::TEXTURE_WRAP_S, glow::REPEAT as i32); - ctx.gl.tex_parameter_i32(glow::TEXTURE_2D, glow::TEXTURE_WRAP_T, glow::REPEAT as i32); - ctx.gl.tex_parameter_i32(glow::TEXTURE_2D, glow::TEXTURE_MIN_FILTER, glow::LINEAR_MIPMAP_LINEAR as i32); - ctx.gl.tex_parameter_i32(glow::TEXTURE_2D, glow::TEXTURE_MAG_FILTER, glow::LINEAR as i32); - ctx.gl.tex_parameter_f32(glow::TEXTURE_2D, glow::TEXTURE_MAX_ANISOTROPY_EXT, 4.0); - } - } - - pub fn bind(&self, ctx: &context::Context) { - unsafe { - ctx.gl.active_texture(glow::TEXTURE0); - ctx.gl.bind_texture(glow::TEXTURE_2D, Some(self.tex)); - } - } - - pub fn bind_index(&self, ctx: &context::Context, idx: u32) { - unsafe { - ctx.gl.active_texture(glow::TEXTURE0 + idx); - ctx.gl.bind_texture(glow::TEXTURE_2D, Some(self.tex)); - } - } -} -- cgit v1.2.3