From c230f5aaea3df46ae9a4d7c1c9761e55ef827b82 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 27 Nov 2023 20:02:08 +0100 Subject: feat(engine): add lighting maps --- engine/src/opengl/texture.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'engine/src/opengl/texture.rs') 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 { + match texture_id.into_inner() { + #( + N => Some(Self::No~N), + )* + _ => None + } + } + } + }); + }; +} + +texture_unit_enum!(cnt = 31); -- cgit v1.2.3-18-g5258