diff options
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); | 
