1 module gfmod.opengl.textureunit;
2 
3 import derelict.opengl3.gl3;
4 
5 import /*gfmod.core.log,  */
6        gfmod.opengl.opengl;
7 
8 /// Cache state of OpenGL texture units.
9 /// Use deprecated image units!
10 final class TextureUnits
11 {
12     public
13     {
14         /// Creates a TextureUnits object.
15         /// This is automatically done by loading OpenGL.
16         this(OpenGL gl)
17         {
18             _gl = gl;
19 
20             // Gets the max total image units
21             // Note: each shader stage has its own max to deal with
22             _textureUnitsCount = gl.maxCombinedImageUnits();
23         }
24 
25         /// Sets the "active texture" which is more precisely active texture unit.
26         /// Throws: $(D OpenGLException) on error.
27         void setActiveTexture(int texture)
28         {
29             if (_textureUnitsCount == 1)
30                 return;
31 
32             if (glActiveTexture is null)
33                 return;
34 
35             glActiveTexture(GL_TEXTURE0 + texture);
36             _gl.runtimeCheck();
37         }
38     }
39 
40     private
41     {
42         OpenGL _gl;
43         int _textureUnitsCount;
44     }
45 }