diff options
author | HampusM <hampus@hampusmat.com> | 2023-11-27 20:02:08 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-11-27 20:02:08 +0100 |
commit | c230f5aaea3df46ae9a4d7c1c9761e55ef827b82 (patch) | |
tree | 9e429a33df6e12f4b2f9adf87d08dad2a0127756 /engine/src/opengl/texture.rs | |
parent | 935f35455ac2e3547cdd21cd4596538958a7217e (diff) |
feat(engine): add lighting maps
Diffstat (limited to 'engine/src/opengl/texture.rs')
-rw-r--r-- | engine/src/opengl/texture.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/engine/src/opengl/texture.rs b/engine/src/opengl/texture.rs index 4186479..56eb118 100644 --- a/engine/src/opengl/texture.rs +++ b/engine/src/opengl/texture.rs @@ -1,6 +1,7 @@ use std::ptr::null; use crate::opengl::currently_bound::CurrentlyBound; +use crate::texture::Id; use crate::vector::Vec2; #[derive(Debug)] @@ -234,3 +235,44 @@ impl PixelDataFormat } } } + +pub fn set_active_texture_unit(texture_unit: TextureUnit) +{ + unsafe { + gl::ActiveTexture(texture_unit.into_gl()); + } +} + +macro_rules! texture_unit_enum { + (cnt=$cnt: literal) => { + seq_macro::seq!(N in 0..$cnt { + #[derive(Debug, Clone, Copy)] + pub enum TextureUnit { + #( + No~N, + )* + } + + impl TextureUnit { + fn into_gl(self) -> gl::types::GLenum { + match self { + #( + Self::No~N => gl::TEXTURE~N, + )* + } + } + + pub fn from_texture_id(texture_id: Id) -> Option<Self> { + match texture_id.into_inner() { + #( + N => Some(Self::No~N), + )* + _ => None + } + } + } + }); + }; +} + +texture_unit_enum!(cnt = 31); |