Fix issue in Rocket.lua script.
[Cafu-Engine.git] / Libs / MaterialSystem / Common / OpenGLState.cpp
blob80b136cc827f19007e1ac8d3c2801d832e78fb5c
1 /*
2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
5 */
7 /********************/
8 /*** OpenGL State ***/
9 /********************/
11 #include <stdlib.h>
12 #include "OpenGLState.hpp"
13 #include "OpenGLEx.hpp"
14 #include "DepRelMatrix.hpp"
17 const GLenum OpenGLStateT::MeshToOpenGLType[]={ GL_POINTS, GL_LINES, GL_LINE_STRIP, GL_LINE_LOOP, GL_TRIANGLES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_QUADS, GL_QUAD_STRIP, GL_POLYGON };
18 const GLenum OpenGLStateT::WindingToOpenGL[]={ GL_CW, GL_CCW };
19 const GLenum OpenGLStateT::BlendFactorToOpenGL[]={ GL_ZERO, GL_ZERO, GL_ONE, GL_DST_COLOR, GL_SRC_COLOR, GL_ONE_MINUS_DST_COLOR, GL_ONE_MINUS_SRC_COLOR, GL_DST_ALPHA, GL_SRC_ALPHA, GL_ONE_MINUS_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA };
20 const GLenum OpenGLStateT::PolygonModeToOpenGL[]={ GL_FILL, GL_LINE, GL_POINT };
21 const GLenum OpenGLStateT::PolygonModeToOpenGL_Offset[]={ GL_POLYGON_OFFSET_FILL, GL_POLYGON_OFFSET_LINE, GL_POLYGON_OFFSET_POINT };
22 const GLenum OpenGLStateT::MatrixModeToOpenGL[]={ GL_MODELVIEW, GL_PROJECTION, GL_TEXTURE, GL_MATRIX0_ARB };
25 OpenGLStateT::OpenGLStateT()
27 Reset();
31 OpenGLStateT* OpenGLStateT::GetInstance()
33 static OpenGLStateT* OpenGLState=new OpenGLStateT();
35 return OpenGLState;
39 void OpenGLStateT::Reset()
41 ActiveTexUnit_Unit =GL_TEXTURE0_ARB;
42 ActiveTexUnit_Index=0;
43 cf::glActiveTextureARB(ActiveTexUnit_Unit);
45 AlphaFunc_Func=GL_ALWAYS;
46 AlphaFunc_Ref =0;
47 glAlphaFunc(AlphaFunc_Func, AlphaFunc_Ref);
49 BlendFunc_sfactor=GL_ONE;
50 BlendFunc_dfactor=GL_ZERO;
51 glBlendFunc(BlendFunc_sfactor, BlendFunc_dfactor);
53 DepthFunc_Func=GL_LEQUAL;
54 glDepthFunc(DepthFunc_Func);
56 if (cf::GL_EXT_stencil_two_side_AVAIL) cf::glActiveStencilFaceEXT(GL_FRONT);
57 StencilFunc_Func[0]=GL_ALWAYS;
58 StencilFunc_ref [0]=0;
59 StencilFunc_mask[0]=~0;
60 glStencilFunc(StencilFunc_Func[0], StencilFunc_ref[0], StencilFunc_mask[0]);
61 StencilOp_fail [0]=GL_KEEP;
62 StencilOp_zfail[0]=GL_KEEP;
63 StencilOp_zpass[0]=GL_KEEP;
64 glStencilOp(StencilOp_fail[0], StencilOp_zfail[0], StencilOp_zpass[0]);
66 if (cf::GL_EXT_stencil_two_side_AVAIL) cf::glActiveStencilFaceEXT(GL_BACK);
67 StencilFunc_Func[1]=GL_ALWAYS;
68 StencilFunc_ref [1]=0;
69 StencilFunc_mask[1]=~0;
70 glStencilFunc(StencilFunc_Func[1], StencilFunc_ref[1], StencilFunc_mask[1]);
71 StencilOp_fail [1]=GL_KEEP;
72 StencilOp_zfail[1]=GL_KEEP;
73 StencilOp_zpass[1]=GL_KEEP;
74 glStencilOp(StencilOp_fail[1], StencilOp_zfail[1], StencilOp_zpass[1]);
76 ActiveStencilFace_Mode=GL_FRONT;
77 if (cf::GL_EXT_stencil_two_side_AVAIL) cf::glActiveStencilFaceEXT(ActiveStencilFace_Mode);
79 ColorMask_FlagRed =GL_TRUE;
80 ColorMask_FlagGreen=GL_TRUE;
81 ColorMask_FlagBlue =GL_TRUE;
82 ColorMask_FlagAlpha=GL_TRUE;
83 glColorMask(ColorMask_FlagRed, ColorMask_FlagGreen, ColorMask_FlagBlue, ColorMask_FlagAlpha);
85 DepthMask_Flag=GL_TRUE;
86 glDepthMask(DepthMask_Flag);
88 CullFace_mode=GL_BACK;
89 glCullFace(CullFace_mode);
91 FrontFace_mode=GL_CCW;
92 glFrontFace(FrontFace_mode);
94 PolygonMode_mode=GL_FILL;
95 glPolygonMode(GL_FRONT_AND_BACK, PolygonMode_mode);
97 PolygonOffset_factor=0.0;
98 PolygonOffset_units =0.0;
99 glPolygonOffset(PolygonOffset_factor, PolygonOffset_units);
101 IsEnabled_AlphaTest =false; glDisable(GL_ALPHA_TEST );
102 IsEnabled_AutoNormal =false; glDisable(GL_AUTO_NORMAL );
103 IsEnabled_Blend =false; glDisable(GL_BLEND );
104 // IsEnabled_ClipPlanei =false; glDisable(GL_CLIP_PLANEi );
105 IsEnabled_ColorMaterial =false; glDisable(GL_COLOR_MATERIAL );
106 IsEnabled_CullFace =false; glDisable(GL_CULL_FACE );
107 IsEnabled_DepthTest =true; glEnable (GL_DEPTH_TEST );
108 IsEnabled_Dither =false; glDisable(GL_DITHER );
109 IsEnabled_Fog =false; glDisable(GL_FOG );
110 // IsEnabled_Lighti =false; glDisable(GL_LIGHTi );
111 IsEnabled_Lighting =false; glDisable(GL_LIGHTING );
112 IsEnabled_LineSmooth =false; glDisable(GL_LINE_SMOOTH );
113 IsEnabled_LineStipple =false; glDisable(GL_LINE_STIPPLE );
114 IsEnabled_LogicOp =false; glDisable(GL_LOGIC_OP );
115 IsEnabled_Normalize =false; glDisable(GL_NORMALIZE );
116 IsEnabled_PointSmooth =false; glDisable(GL_POINT_SMOOTH );
117 IsEnabled_PolygonSmooth =false; glDisable(GL_POLYGON_SMOOTH );
118 IsEnabled_PolygonStipple =false; glDisable(GL_POLYGON_STIPPLE );
119 IsEnabled_PolygonOffsetFill =false; glDisable(GL_POLYGON_OFFSET_FILL );
120 IsEnabled_PolygonOffsetLine =false; glDisable(GL_POLYGON_OFFSET_LINE );
121 IsEnabled_PolygonOffsetPoint=false; glDisable(GL_POLYGON_OFFSET_POINT);
122 IsEnabled_ScissorTest =false; glDisable(GL_SCISSOR_TEST );
123 IsEnabled_StencilTest =false; glDisable(GL_STENCIL_TEST );
124 IsEnabled_StencilTestTwoSide=false; if (cf::GL_EXT_stencil_two_side_AVAIL) glDisable(GL_STENCIL_TEST_TWO_SIDE_EXT);
127 // Reset the matrices.
128 for (unsigned long MM=0; MM<3+32; MM++)
130 LoadedMatrixID [MM]=0xFFFFFFFF;
131 LoadedMatrixAge[MM]=0;
133 // Intentionally don't pre-load any matrices here, because the GL_PROJECTION matrix might have been
134 // set by the OpenGL window code, which is external to the MatSys, opened before us, and has probably loaded a matrix already.
135 // It also isn't necessary to preload anything -- the above values guarantee that the next call to LoadMatrix() will always succeed.
138 // Reset the texture units.
139 GLint MaxTexUnits;
140 glGetIntegerv(cf::GL_ARB_vertex_and_fragment_program_AVAIL ? GL_MAX_TEXTURE_IMAGE_UNITS_ARB : GL_MAX_TEXTURE_UNITS_ARB, &MaxTexUnits);
142 // if (MaxTexUnits>8) Error("MaxTexUnits==%lu > 8.\n", MaxTexUnits);
144 for (unsigned long TUNr=0; TUNr<(unsigned long)MaxTexUnits && TUNr<8; TUNr++)
146 TexUnitStateT& TU=TexUnitStates[TUNr];
148 ActiveTextureUnit(GL_TEXTURE0_ARB+TUNr);
150 TU.TexObj1D =0; glBindTexture(GL_TEXTURE_1D, 0);
151 TU.TexObj2D =0; glBindTexture(GL_TEXTURE_2D, 0);
152 TU.TexObj3D =0; glBindTexture(GL_TEXTURE_3D, 0);
153 TU.TexObjCube=0; glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, 0);
155 glDisable(GL_TEXTURE_1D );
156 glDisable(GL_TEXTURE_2D );
157 glDisable(GL_TEXTURE_3D );
158 glDisable(GL_TEXTURE_CUBE_MAP_ARB);
160 TU.Texturing_IsEnabled=false;
161 TU.Texturing_Target =GL_TEXTURE_2D; // Arbitrary choice.
163 TU.IsEnabled_TextureGenQ=false; glDisable(GL_TEXTURE_GEN_Q);
164 TU.IsEnabled_TextureGenR=false; glDisable(GL_TEXTURE_GEN_R);
165 TU.IsEnabled_TextureGenS=false; glDisable(GL_TEXTURE_GEN_S);
166 TU.IsEnabled_TextureGenT=false; glDisable(GL_TEXTURE_GEN_T);
169 ActiveTextureUnit(GL_TEXTURE0_ARB);
173 void OpenGLStateT::ActiveTextureUnit(GLenum texUnit)
175 if (ActiveTexUnit_Unit==texUnit) return;
177 ActiveTexUnit_Unit =texUnit;
178 ActiveTexUnit_Index=ActiveTexUnit_Unit-GL_TEXTURE0_ARB;
180 cf::glActiveTextureARB(ActiveTexUnit_Unit);
184 void OpenGLStateT::AlphaFunc(GLenum func, GLclampf ref)
186 if (AlphaFunc_Func==func && AlphaFunc_Ref==ref) return;
188 AlphaFunc_Func=func;
189 AlphaFunc_Ref =ref;
191 glAlphaFunc(AlphaFunc_Func, AlphaFunc_Ref);
195 void OpenGLStateT::BlendFunc(GLenum sfactor, GLenum dfactor)
197 if (BlendFunc_sfactor==sfactor && BlendFunc_dfactor==dfactor) return;
199 BlendFunc_sfactor=sfactor;
200 BlendFunc_dfactor=dfactor;
202 glBlendFunc(BlendFunc_sfactor, BlendFunc_dfactor);
206 void OpenGLStateT::DepthFunc(GLenum func)
208 if (DepthFunc_Func==func) return;
210 DepthFunc_Func=func;
212 glDepthFunc(DepthFunc_Func);
216 void OpenGLStateT::ActiveStencilFace(GLenum mode)
218 if (ActiveStencilFace_Mode==mode) return;
220 ActiveStencilFace_Mode=mode;
222 if (!cf::GL_EXT_stencil_two_side_AVAIL) return;
223 cf::glActiveStencilFaceEXT(ActiveStencilFace_Mode);
227 void OpenGLStateT::StencilFunc(GLenum func, GLint ref, GLuint mask)
229 const unsigned long Index=(ActiveStencilFace_Mode==GL_FRONT) ? 0 : 1;
231 if (StencilFunc_Func[Index]==func && StencilFunc_ref[Index]==ref && StencilFunc_mask[Index]==mask) return;
233 StencilFunc_Func[Index]=func;
234 StencilFunc_ref [Index]=ref;
235 StencilFunc_mask[Index]=mask;
237 glStencilFunc(StencilFunc_Func[Index], StencilFunc_ref[Index], StencilFunc_mask[Index]);
241 void OpenGLStateT::StencilOp(GLenum fail, GLenum zfail, GLenum zpass)
243 const unsigned long Index=(ActiveStencilFace_Mode==GL_FRONT) ? 0 : 1;
245 if (StencilOp_fail[Index]==fail && StencilOp_zfail[Index]==zfail && StencilOp_zpass[Index]==zpass) return;
247 StencilOp_fail [Index]=fail;
248 StencilOp_zfail[Index]=zfail;
249 StencilOp_zpass[Index]=zpass;
251 glStencilOp(StencilOp_fail[Index], StencilOp_zfail[Index], StencilOp_zpass[Index]);
255 void OpenGLStateT::ColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
257 if (ColorMask_FlagRed==red && ColorMask_FlagGreen==green && ColorMask_FlagBlue==blue && ColorMask_FlagAlpha==alpha) return;
259 ColorMask_FlagRed =red;
260 ColorMask_FlagGreen=green;
261 ColorMask_FlagBlue =blue;
262 ColorMask_FlagAlpha=alpha;
264 glColorMask(ColorMask_FlagRed, ColorMask_FlagGreen, ColorMask_FlagBlue, ColorMask_FlagAlpha);
268 void OpenGLStateT::DepthMask(GLboolean flag)
270 if (DepthMask_Flag==flag) return;
272 DepthMask_Flag=flag;
274 glDepthMask(DepthMask_Flag);
278 void OpenGLStateT::CullFace(GLenum mode)
280 if (CullFace_mode==mode) return;
282 CullFace_mode=mode;
284 glCullFace(CullFace_mode);
288 void OpenGLStateT::FrontFace(GLenum mode)
290 if (FrontFace_mode==mode) return;
292 FrontFace_mode=mode;
294 glFrontFace(FrontFace_mode);
298 void OpenGLStateT::PolygonMode(GLenum mode)
300 if (PolygonMode_mode==mode) return;
302 PolygonMode_mode=mode;
304 glPolygonMode(GL_FRONT_AND_BACK, PolygonMode_mode);
308 void OpenGLStateT::PolygonOffset(GLfloat factor, GLfloat units)
310 if (PolygonOffset_factor==factor && PolygonOffset_units==units) return;
312 PolygonOffset_factor=factor;
313 PolygonOffset_units =units;
315 glPolygonOffset(PolygonOffset_factor, PolygonOffset_units);
319 void OpenGLStateT::Enable(GLenum cap)
321 switch (cap)
323 case GL_ALPHA_TEST: if (IsEnabled_AlphaTest ) return; IsEnabled_AlphaTest =true; break;
324 case GL_AUTO_NORMAL: if (IsEnabled_AutoNormal ) return; IsEnabled_AutoNormal =true; break;
325 case GL_BLEND: if (IsEnabled_Blend ) return; IsEnabled_Blend =true; break;
326 // case GL_CLIP_PLANEi: if (IsEnabled_ClipPlanei ) return; IsEnabled_ClipPlanei =true; break;
327 case GL_COLOR_MATERIAL: if (IsEnabled_ColorMaterial ) return; IsEnabled_ColorMaterial =true; break;
328 case GL_CULL_FACE: if (IsEnabled_CullFace ) return; IsEnabled_CullFace =true; break;
329 case GL_DEPTH_TEST: if (IsEnabled_DepthTest ) return; IsEnabled_DepthTest =true; break;
330 case GL_DITHER: if (IsEnabled_Dither ) return; IsEnabled_Dither =true; break;
331 case GL_FOG: if (IsEnabled_Fog ) return; IsEnabled_Fog =true; break;
332 // case GL_LIGHTi: if (IsEnabled_Lighti ) return; IsEnabled_Lighti =true; break;
333 case GL_LIGHTING: if (IsEnabled_Lighting ) return; IsEnabled_Lighting =true; break;
334 case GL_LINE_SMOOTH: if (IsEnabled_LineSmooth ) return; IsEnabled_LineSmooth =true; break;
335 case GL_LINE_STIPPLE: if (IsEnabled_LineStipple ) return; IsEnabled_LineStipple =true; break;
336 case GL_LOGIC_OP: if (IsEnabled_LogicOp ) return; IsEnabled_LogicOp =true; break;
337 case GL_NORMALIZE: if (IsEnabled_Normalize ) return; IsEnabled_Normalize =true; break;
338 case GL_POINT_SMOOTH: if (IsEnabled_PointSmooth ) return; IsEnabled_PointSmooth =true; break;
339 case GL_POLYGON_SMOOTH: if (IsEnabled_PolygonSmooth ) return; IsEnabled_PolygonSmooth =true; break;
340 case GL_POLYGON_STIPPLE: if (IsEnabled_PolygonStipple ) return; IsEnabled_PolygonStipple =true; break;
341 case GL_POLYGON_OFFSET_FILL: if (IsEnabled_PolygonOffsetFill ) return; IsEnabled_PolygonOffsetFill =true; break;
342 case GL_POLYGON_OFFSET_LINE: if (IsEnabled_PolygonOffsetLine ) return; IsEnabled_PolygonOffsetLine =true; break;
343 case GL_POLYGON_OFFSET_POINT: if (IsEnabled_PolygonOffsetPoint) return; IsEnabled_PolygonOffsetPoint=true; break;
344 case GL_SCISSOR_TEST: if (IsEnabled_ScissorTest ) return; IsEnabled_ScissorTest =true; break;
345 case GL_STENCIL_TEST: if (IsEnabled_StencilTest ) return; IsEnabled_StencilTest =true; break;
346 case GL_STENCIL_TEST_TWO_SIDE_EXT: if (IsEnabled_StencilTestTwoSide) return; IsEnabled_StencilTestTwoSide=true; if (!cf::GL_EXT_stencil_two_side_AVAIL) return; break;
347 case GL_TEXTURE_GEN_Q: if (TexUnitStates[ActiveTexUnit_Index].IsEnabled_TextureGenQ) return; TexUnitStates[ActiveTexUnit_Index].IsEnabled_TextureGenQ=true; break;
348 case GL_TEXTURE_GEN_R: if (TexUnitStates[ActiveTexUnit_Index].IsEnabled_TextureGenR) return; TexUnitStates[ActiveTexUnit_Index].IsEnabled_TextureGenR=true; break;
349 case GL_TEXTURE_GEN_S: if (TexUnitStates[ActiveTexUnit_Index].IsEnabled_TextureGenS) return; TexUnitStates[ActiveTexUnit_Index].IsEnabled_TextureGenS=true; break;
350 case GL_TEXTURE_GEN_T: if (TexUnitStates[ActiveTexUnit_Index].IsEnabled_TextureGenT) return; TexUnitStates[ActiveTexUnit_Index].IsEnabled_TextureGenT=true; break;
352 case GL_TEXTURE_1D: // Intentional fall-through!
353 case GL_TEXTURE_2D: // Intentional fall-through!
354 case GL_TEXTURE_3D: // Intentional fall-through!
355 case GL_TEXTURE_CUBE_MAP_ARB:
356 if (TexUnitStates[ActiveTexUnit_Index].Texturing_IsEnabled)
358 // The desired target is already enabled. Do nothing.
359 if (TexUnitStates[ActiveTexUnit_Index].Texturing_Target==cap) return;
361 // Another target is enabled. Disable it.
362 glDisable(TexUnitStates[ActiveTexUnit_Index].Texturing_Target);
365 // Enable the desired target.
366 TexUnitStates[ActiveTexUnit_Index].Texturing_IsEnabled=true;
367 TexUnitStates[ActiveTexUnit_Index].Texturing_Target =cap;
368 break;
370 // default: Warning("Unknown cap %lu (0x%X).\n", cap, cap);
373 glEnable(cap);
377 void OpenGLStateT::Disable(GLenum cap)
379 switch (cap)
381 case GL_ALPHA_TEST: if (!IsEnabled_AlphaTest ) return; IsEnabled_AlphaTest =false; break;
382 case GL_AUTO_NORMAL: if (!IsEnabled_AutoNormal ) return; IsEnabled_AutoNormal =false; break;
383 case GL_BLEND: if (!IsEnabled_Blend ) return; IsEnabled_Blend =false; break;
384 // case GL_CLIP_PLANEi: if (!IsEnabled_ClipPlanei ) return; IsEnabled_ClipPlanei =false; break;
385 case GL_COLOR_MATERIAL: if (!IsEnabled_ColorMaterial ) return; IsEnabled_ColorMaterial =false; break;
386 case GL_CULL_FACE: if (!IsEnabled_CullFace ) return; IsEnabled_CullFace =false; break;
387 case GL_DEPTH_TEST: if (!IsEnabled_DepthTest ) return; IsEnabled_DepthTest =false; break;
388 case GL_DITHER: if (!IsEnabled_Dither ) return; IsEnabled_Dither =false; break;
389 case GL_FOG: if (!IsEnabled_Fog ) return; IsEnabled_Fog =false; break;
390 // case GL_LIGHTi: if (!IsEnabled_Lighti ) return; IsEnabled_Lighti =false; break;
391 case GL_LIGHTING: if (!IsEnabled_Lighting ) return; IsEnabled_Lighting =false; break;
392 case GL_LINE_SMOOTH: if (!IsEnabled_LineSmooth ) return; IsEnabled_LineSmooth =false; break;
393 case GL_LINE_STIPPLE: if (!IsEnabled_LineStipple ) return; IsEnabled_LineStipple =false; break;
394 case GL_LOGIC_OP: if (!IsEnabled_LogicOp ) return; IsEnabled_LogicOp =false; break;
395 case GL_NORMALIZE: if (!IsEnabled_Normalize ) return; IsEnabled_Normalize =false; break;
396 case GL_POINT_SMOOTH: if (!IsEnabled_PointSmooth ) return; IsEnabled_PointSmooth =false; break;
397 case GL_POLYGON_SMOOTH: if (!IsEnabled_PolygonSmooth ) return; IsEnabled_PolygonSmooth =false; break;
398 case GL_POLYGON_STIPPLE: if (!IsEnabled_PolygonStipple ) return; IsEnabled_PolygonStipple =false; break;
399 case GL_POLYGON_OFFSET_FILL: if (!IsEnabled_PolygonOffsetFill ) return; IsEnabled_PolygonOffsetFill =false; break;
400 case GL_POLYGON_OFFSET_LINE: if (!IsEnabled_PolygonOffsetLine ) return; IsEnabled_PolygonOffsetLine =false; break;
401 case GL_POLYGON_OFFSET_POINT: if (!IsEnabled_PolygonOffsetPoint) return; IsEnabled_PolygonOffsetPoint=false; break;
402 case GL_SCISSOR_TEST: if (!IsEnabled_ScissorTest ) return; IsEnabled_ScissorTest =false; break;
403 case GL_STENCIL_TEST: if (!IsEnabled_StencilTest ) return; IsEnabled_StencilTest =false; break;
404 case GL_STENCIL_TEST_TWO_SIDE_EXT: if (!IsEnabled_StencilTestTwoSide) return; IsEnabled_StencilTestTwoSide=false; if (!cf::GL_EXT_stencil_two_side_AVAIL) return; break;
405 case GL_TEXTURE_GEN_Q: if (!TexUnitStates[ActiveTexUnit_Index].IsEnabled_TextureGenQ) return; TexUnitStates[ActiveTexUnit_Index].IsEnabled_TextureGenQ=false; break;
406 case GL_TEXTURE_GEN_R: if (!TexUnitStates[ActiveTexUnit_Index].IsEnabled_TextureGenR) return; TexUnitStates[ActiveTexUnit_Index].IsEnabled_TextureGenR=false; break;
407 case GL_TEXTURE_GEN_S: if (!TexUnitStates[ActiveTexUnit_Index].IsEnabled_TextureGenS) return; TexUnitStates[ActiveTexUnit_Index].IsEnabled_TextureGenS=false; break;
408 case GL_TEXTURE_GEN_T: if (!TexUnitStates[ActiveTexUnit_Index].IsEnabled_TextureGenT) return; TexUnitStates[ActiveTexUnit_Index].IsEnabled_TextureGenT=false; break;
410 case GL_TEXTURE_1D: // Intentional fall-through!
411 case GL_TEXTURE_2D: // Intentional fall-through!
412 case GL_TEXTURE_3D: // Intentional fall-through!
413 case GL_TEXTURE_CUBE_MAP_ARB:
414 // Nothing enabled? So there is nothing to disable.
415 if (!TexUnitStates[ActiveTexUnit_Index].Texturing_IsEnabled) return;
417 // Something is enabled, but they want to disable something else? (That in turn is already disabled anyway!) Don't.
418 if (cap!=TexUnitStates[ActiveTexUnit_Index].Texturing_Target) return;
420 // Disable the desired target.
421 TexUnitStates[ActiveTexUnit_Index].Texturing_IsEnabled=false;
422 break;
424 // default: Warning("Unknown cap %lu (0x%X).\n", cap, cap);
427 glDisable(cap);
431 /// This method loads a matrix.
432 /// @param MatrixMode The matrix mode for which the matrix should be loaded (MODELVIEW, PROJECTION, TEXTURE, MATRIX0, ...).
433 /// @param Matrix The matrix that is to be loaded. The matrix must be up-to-date already, i.e. Matrix.Update() must have been called by the caller!
434 /// Note that individual matrices are discriminated by their ID(!), not by their actual content value.
435 /// Also, the age of a matrix should increase whenever the matrix is modified.
436 void OpenGLStateT::LoadMatrix(MatrixModeT MatrixMode, const DepRelMatrixT& Matrix)
438 if (Matrix.ID!=LoadedMatrixID[MatrixMode] || Matrix.Age>LoadedMatrixAge[MatrixMode])
440 glMatrixMode(MatrixMode<MATRIX0 ? MatrixModeToOpenGL[MatrixMode] : GL_MATRIX0_ARB+(MatrixMode-MATRIX0));
441 glLoadMatrixf(&Matrix.Matrix.GetTranspose().m[0][0]);
443 LoadedMatrixID [MatrixMode]=Matrix.ID;
444 LoadedMatrixAge[MatrixMode]=Matrix.Age;
449 void OpenGLStateT::BindTexture(GLenum target, GLuint texture)
451 switch (target)
453 case GL_TEXTURE_1D: if (TexUnitStates[ActiveTexUnit_Index].TexObj1D ==texture) return; TexUnitStates[ActiveTexUnit_Index].TexObj1D =texture; break;
454 case GL_TEXTURE_2D: if (TexUnitStates[ActiveTexUnit_Index].TexObj2D ==texture) return; TexUnitStates[ActiveTexUnit_Index].TexObj2D =texture; break;
455 case GL_TEXTURE_3D: if (TexUnitStates[ActiveTexUnit_Index].TexObj3D ==texture) return; TexUnitStates[ActiveTexUnit_Index].TexObj3D =texture; break;
456 case GL_TEXTURE_CUBE_MAP_ARB: if (TexUnitStates[ActiveTexUnit_Index].TexObjCube==texture) return; TexUnitStates[ActiveTexUnit_Index].TexObjCube=texture; break;
458 // default: Warning("Unknown target %lu (0x%X).\n", target, target);
461 glBindTexture(target, texture);
465 void OpenGLStateT::TexEnv(GLenum target, GLenum pname, GLint param)
467 glTexEnvi(target, pname, param);
471 void OpenGLStateT::TexEnv(GLenum target, GLenum pname, GLfloat param)
473 glTexEnvf(target, pname, param);
477 void OpenGLStateT::TexEnv(GLenum target, GLenum pname, GLint* param)
479 glTexEnviv(target, pname, param);
483 void OpenGLStateT::TexEnv(GLenum target, GLenum pname, GLfloat* param)
485 glTexEnvfv(target, pname, param);