1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "stdopengl.h"
19 #include "driver_opengl.h"
21 // ***************************************************************************
22 // define it For Debug purpose only. Normal use is to hide this line
23 //#define NL3D_GLSTATE_DISABLE_CACHE
33 namespace NLDRIVERGLES
{
35 namespace NLDRIVERGL
{
39 // ***************************************************************************
40 CDriverGLStates::CDriverGLStates()
42 H_AUTO_OGL(CDriverGLStates_CDriverGLStates
)
43 _TextureCubeMapSupported
= false;
44 _CurrARBVertexBuffer
= 0;
45 _DepthRangeNear
= 0.f
;
53 // ***************************************************************************
54 void CDriverGLStates::init(bool supportTextureCubeMap
, bool supportTextureRectangle
, uint maxLight
)
56 H_AUTO_OGL(CDriverGLStates_init
)
57 _TextureCubeMapSupported
= supportTextureCubeMap
;
58 _TextureRectangleSupported
= supportTextureRectangle
;
59 _MaxDriverLight
= maxLight
;
60 _MaxDriverLight
= std::min(_MaxDriverLight
, uint(MaxLight
));
62 // By default all arrays are disabled.
63 _VertexArrayEnabled
= false;
64 _NormalArrayEnabled
= false;
65 _WeightArrayEnabled
= false;
66 _ColorArrayEnabled
= false;
67 _SecondaryColorArrayEnabled
= false;
69 for(i
=0; i
<sizeof(_TexCoordArrayEnabled
)/sizeof(_TexCoordArrayEnabled
[0]); i
++)
71 _TexCoordArrayEnabled
[i
]= false;
73 for(i
=0; i
<CVertexBuffer::NumValue
; i
++)
75 _VertexAttribArrayEnabled
[i
]= false;
77 _DepthRangeNear
= 0.f
;
80 // by default all lights are disabled (not reseted in forceDefaults)
81 for(i
=0; i
<MaxLight
; i
++)
88 // ***************************************************************************
89 void CDriverGLStates::forceDefaults(uint nbStages
)
91 H_AUTO_OGL(CDriverGLStates_forceDefaults
);
100 _CurStencilTest
=false;
101 _CurMultisample
= false;
106 glEnable(GL_CULL_FACE
);
107 glDisable(GL_ALPHA_TEST
);
108 glDisable(GL_LIGHTING
);
109 glDepthMask(GL_TRUE
);
110 glDisable(GL_MULTISAMPLE_ARB
);
113 _CurBlendSrc
= GL_SRC_ALPHA
;
114 _CurBlendDst
= GL_ONE_MINUS_SRC_ALPHA
;
115 _CurDepthFunc
= GL_LEQUAL
;
116 _CurStencilFunc
= GL_ALWAYS
;
118 _CurStencilMask
= std::numeric_limits
<GLuint
>::max();
119 _CurStencilOpFail
= GL_KEEP
;
120 _CurStencilOpZFail
= GL_KEEP
;
121 _CurStencilOpZPass
= GL_KEEP
;
122 _CurStencilWriteMask
= std::numeric_limits
<GLuint
>::max();
123 _CurAlphaTestThreshold
= 0.5f
;
126 glBlendFunc(_CurBlendSrc
, _CurBlendDst
);
127 glDepthFunc(_CurDepthFunc
);
128 glStencilFunc(_CurStencilFunc
, _CurStencilRef
, _CurStencilMask
);
129 glStencilOp(_CurStencilOpFail
, _CurStencilOpZFail
, _CurStencilOpZPass
);
130 glStencilMask(_CurStencilWriteMask
);
131 glAlphaFunc(GL_GREATER
, _CurAlphaTestThreshold
);
136 uint32 packedOne
= (CRGBA(255,255,255,255)).getPacked();
137 uint32 packedZero
= (CRGBA(0,0,0,255)).getPacked();
138 _CurEmissive
= packedZero
;
139 _CurAmbient
= packedOne
;
140 _CurDiffuse
= packedOne
;
141 _CurSpecular
= packedZero
;
144 // Lighted vertex color
145 _VertexColorLighted
=false;
146 glDisable(GL_COLOR_MATERIAL
);
149 static const GLfloat one
[4]= {1,1,1,1};
150 static const GLfloat zero
[4]= {0,0,0,1};
151 glMaterialfv(GL_FRONT_AND_BACK
, GL_EMISSION
, zero
);
152 glMaterialfv(GL_FRONT_AND_BACK
, GL_AMBIENT
, one
);
153 glMaterialfv(GL_FRONT_AND_BACK
, GL_DIFFUSE
, one
);
154 glMaterialfv(GL_FRONT_AND_BACK
, GL_SPECULAR
, zero
);
155 glMaterialf(GL_FRONT_AND_BACK
, GL_SHININESS
, _CurShininess
);
159 for(stage
=0;stage
<nbStages
; stage
++)
161 // disable texturing.
162 nglActiveTextureARB(GL_TEXTURE0_ARB
+stage
);
164 glDisable(GL_TEXTURE_2D
);
166 if(_TextureCubeMapSupported
)
168 glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
170 glDisable(GL_TEXTURE_GEN_STR_OES
);
174 _TextureMode
[stage
]= TextureDisabled
;
177 _TexGenMode
[stage
] = 0;
180 if(_TextureRectangleSupported
)
181 glDisable(GL_TEXTURE_RECTANGLE_NV
);
183 glDisable(GL_TEXTURE_GEN_S
);
184 glDisable(GL_TEXTURE_GEN_T
);
185 glDisable(GL_TEXTURE_GEN_R
);
186 glDisable(GL_TEXTURE_GEN_Q
);
190 // ActiveTexture current texture to 0.
191 nglActiveTextureARB(GL_TEXTURE0_ARB
);
192 nglClientActiveTextureARB(GL_TEXTURE0_ARB
);
194 _CurrentActiveTextureARB
= 0;
195 _CurrentClientActiveTextureARB
= 0;
198 _DepthRangeNear
= 0.f
;
199 _DepthRangeFar
= 1.f
;
203 glDepthRangef (0.f
, 1.f
);
213 // ***************************************************************************
214 void CDriverGLStates::enableBlend(uint enable
)
216 H_AUTO_OGL(CDriverGLStates_enableBlend
)
217 // If different from current setup, update.
218 bool enabled
= (enable
!=0);
219 #ifndef NL3D_GLSTATE_DISABLE_CACHE
220 if( enabled
!= _CurBlend
)
233 // ***************************************************************************
234 void CDriverGLStates::enableCullFace(uint enable
)
236 H_AUTO_OGL(CDriverGLStates_enableCullFace
)
237 // If different from current setup, update.
238 bool enabled
= (enable
!=0);
239 #ifndef NL3D_GLSTATE_DISABLE_CACHE
240 if( enabled
!= _CurCullFace
)
244 _CurCullFace
= enabled
;
247 glEnable(GL_CULL_FACE
);
249 glDisable(GL_CULL_FACE
);
253 // ***************************************************************************
254 void CDriverGLStates::enableAlphaTest(uint enable
)
256 H_AUTO_OGL(CDriverGLStates_enableAlphaTest
)
257 // If different from current setup, update.
258 bool enabled
= (enable
!=0);
259 #ifndef NL3D_GLSTATE_DISABLE_CACHE
260 if( enabled
!= _CurAlphaTest
)
264 _CurAlphaTest
= enabled
;
269 glEnable(GL_ALPHA_TEST
);
273 glDisable(GL_ALPHA_TEST
);
280 // ***************************************************************************
281 void CDriverGLStates::enableLighting(uint enable
)
283 H_AUTO_OGL(CDriverGLStates_enableLighting
)
284 // If different from current setup, update.
285 bool enabled
= (enable
!=0);
286 #ifndef NL3D_GLSTATE_DISABLE_CACHE
287 if( enabled
!= _CurLighting
)
291 _CurLighting
= enabled
;
294 glEnable(GL_LIGHTING
);
297 glDisable(GL_LIGHTING
);
302 // ***************************************************************************
303 void CDriverGLStates::enableLight(uint num
, uint enable
)
305 H_AUTO_OGL(CDriverGLStates_enableLight
)
306 if(num
>=_MaxDriverLight
)
309 // If different from current setup, update.
310 bool enabled
= (enable
!=0);
311 #ifndef NL3D_GLSTATE_DISABLE_CACHE
312 if( enabled
!= _CurLight
[num
] )
316 _CurLight
[num
]= enabled
;
319 glEnable ((GLenum
)(GL_LIGHT0
+num
));
321 glDisable ((GLenum
)(GL_LIGHT0
+num
));
325 // ***************************************************************************
326 bool CDriverGLStates::isLightEnabled(uint num
) const
328 H_AUTO_OGL(CDriverGLStates_isLightEnabled
)
329 if(num
>=_MaxDriverLight
)
332 return _CurLight
[num
];
336 // ***************************************************************************
337 void CDriverGLStates::enableZWrite(uint enable
)
339 H_AUTO_OGL(CDriverGLStates_enableZWrite
)
340 // If different from current setup, update.
341 bool enabled
= (enable
!=0);
342 #ifndef NL3D_GLSTATE_DISABLE_CACHE
343 if( enabled
!= _CurZWrite
)
350 glDepthMask(GL_TRUE
);
352 glDepthMask(GL_FALSE
);
357 // ***************************************************************************
358 void CDriverGLStates::enableStencilTest(bool enable
)
360 H_AUTO_OGL(CDriverGLStates_enableStencilTest
);
362 // If different from current setup, update.
363 #ifndef NL3D_GLSTATE_DISABLE_CACHE
364 if( enable
!= _CurStencilTest
)
368 _CurStencilTest
= enable
;
371 glEnable(GL_STENCIL_TEST
);
373 glDisable(GL_STENCIL_TEST
);
377 // ***************************************************************************
378 void CDriverGLStates::enableMultisample(bool enable
)
380 H_AUTO_OGL(CDriverGLStates_enableMultisample
);
382 // If different from current setup, update.
383 #ifndef NL3D_GLSTATE_DISABLE_CACHE
384 if( enable
!= _CurMultisample
)
388 _CurMultisample
= enable
;
392 glEnable(GL_MULTISAMPLE_ARB
);
394 glDisable(GL_MULTISAMPLE_ARB
);
398 // ***************************************************************************
399 void CDriverGLStates::blendFunc(GLenum src
, GLenum dst
)
401 H_AUTO_OGL(CDriverGLStates_blendFunc
)
402 // If different from current setup, update.
403 #ifndef NL3D_GLSTATE_DISABLE_CACHE
404 if( src
!= _CurBlendSrc
|| dst
!=_CurBlendDst
)
411 glBlendFunc(_CurBlendSrc
, _CurBlendDst
);
415 // ***************************************************************************
416 void CDriverGLStates::depthFunc(GLenum zcomp
)
418 H_AUTO_OGL(CDriverGLStates_depthFunc
)
419 // If different from current setup, update.
420 #ifndef NL3D_GLSTATE_DISABLE_CACHE
421 if( zcomp
!= _CurDepthFunc
)
425 _CurDepthFunc
= zcomp
;
427 glDepthFunc(_CurDepthFunc
);
432 // ***************************************************************************
433 void CDriverGLStates::alphaFunc(float threshold
)
435 H_AUTO_OGL(CDriverGLStates_alphaFunc
)
436 #ifndef NL3D_GLSTATE_DISABLE_CACHE
437 if(threshold
!= _CurAlphaTestThreshold
)
441 _CurAlphaTestThreshold
= threshold
;
443 glAlphaFunc(GL_GREATER
, _CurAlphaTestThreshold
);
448 // ***************************************************************************
449 void CDriverGLStates::stencilFunc(GLenum func
, GLint ref
, GLuint mask
)
451 H_AUTO_OGL(CDriverGLStates_stencilFunc
)
452 #ifndef NL3D_GLSTATE_DISABLE_CACHE
453 if((func
!=_CurStencilFunc
) || (ref
!=_CurStencilRef
) || (mask
!=_CurStencilMask
))
457 _CurStencilFunc
= func
;
458 _CurStencilRef
= ref
;
459 _CurStencilMask
= mask
;
462 glStencilFunc(_CurStencilFunc
, _CurStencilRef
, _CurStencilMask
);
467 // ***************************************************************************
468 void CDriverGLStates::stencilOp(GLenum fail
, GLenum zfail
, GLenum zpass
)
470 H_AUTO_OGL(CDriverGLStates_stencilOp
)
471 #ifndef NL3D_GLSTATE_DISABLE_CACHE
472 if((fail
!=_CurStencilOpFail
) || (zfail
!=_CurStencilOpZFail
) || (zpass
!=_CurStencilOpZPass
))
476 _CurStencilOpFail
= fail
;
477 _CurStencilOpZFail
= zfail
;
478 _CurStencilOpZPass
= zpass
;
481 glStencilOp(_CurStencilOpFail
, _CurStencilOpZFail
, _CurStencilOpZPass
);
485 // ***************************************************************************
486 void CDriverGLStates::stencilMask(GLuint mask
)
488 H_AUTO_OGL(CDriverGLStates_stencilMask
)
489 #ifndef NL3D_GLSTATE_DISABLE_CACHE
490 if(mask
!=_CurStencilWriteMask
)
494 _CurStencilWriteMask
= mask
;
497 glStencilMask(_CurStencilWriteMask
);
502 // ***************************************************************************
503 void CDriverGLStates::setEmissive(uint32 packedColor
, const GLfloat color
[4])
505 H_AUTO_OGL(CDriverGLStates_setEmissive
)
506 #ifndef NL3D_GLSTATE_DISABLE_CACHE
507 if( packedColor
!=_CurEmissive
)
510 _CurEmissive
= packedColor
;
511 glMaterialfv(GL_FRONT_AND_BACK
, GL_EMISSION
, color
);
515 // ***************************************************************************
516 void CDriverGLStates::setAmbient(uint32 packedColor
, const GLfloat color
[4])
518 H_AUTO_OGL(CDriverGLStates_setAmbient
)
519 #ifndef NL3D_GLSTATE_DISABLE_CACHE
520 if( packedColor
!=_CurAmbient
)
523 _CurAmbient
= packedColor
;
524 glMaterialfv(GL_FRONT_AND_BACK
, GL_AMBIENT
, color
);
528 // ***************************************************************************
529 void CDriverGLStates::setDiffuse(uint32 packedColor
, const GLfloat color
[4])
531 H_AUTO_OGL(CDriverGLStates_setDiffuse
)
532 #ifndef NL3D_GLSTATE_DISABLE_CACHE
533 if( packedColor
!=_CurDiffuse
)
536 _CurDiffuse
= packedColor
;
537 glMaterialfv(GL_FRONT_AND_BACK
, GL_DIFFUSE
, color
);
541 // ***************************************************************************
542 void CDriverGLStates::setSpecular(uint32 packedColor
, const GLfloat color
[4])
544 H_AUTO_OGL(CDriverGLStates_setSpecular
)
545 #ifndef NL3D_GLSTATE_DISABLE_CACHE
546 if( packedColor
!=_CurSpecular
)
549 _CurSpecular
= packedColor
;
550 glMaterialfv(GL_FRONT_AND_BACK
, GL_SPECULAR
, color
);
554 // ***************************************************************************
555 void CDriverGLStates::setShininess(float shin
)
557 H_AUTO_OGL(CDriverGLStates_setShininess
)
558 #ifndef NL3D_GLSTATE_DISABLE_CACHE
559 if( shin
!= _CurShininess
)
563 glMaterialf(GL_FRONT_AND_BACK
, GL_SHININESS
, shin
);
568 // ***************************************************************************
569 static void convColor(CRGBA col
, GLfloat glcol
[4])
571 H_AUTO_OGL(convColor
)
572 static const float OO255
= 1.0f
/255;
573 glcol
[0]= col
.R
*OO255
;
574 glcol
[1]= col
.G
*OO255
;
575 glcol
[2]= col
.B
*OO255
;
576 glcol
[3]= col
.A
*OO255
;
579 // ***************************************************************************
580 void CDriverGLStates::setVertexColorLighted(bool enable
)
582 H_AUTO_OGL(CDriverGLStates_setVertexColorLighted
)
583 #ifndef NL3D_GLSTATE_DISABLE_CACHE
584 if( enable
!= _VertexColorLighted
)
587 _VertexColorLighted
= enable
;
589 if (_VertexColorLighted
)
591 glEnable (GL_COLOR_MATERIAL
);
593 glColorMaterial (GL_FRONT_AND_BACK
, GL_DIFFUSE
);
598 glDisable (GL_COLOR_MATERIAL
);
599 // Since we leave glColorMaterial mode, GL diffuse is now scracth. reset him to current value.
601 diffCol
.R
= (uint8
)((_CurDiffuse
>> 24) & 255);
602 diffCol
.G
= (uint8
)((_CurDiffuse
>> 16) & 255);
603 diffCol
.B
= (uint8
)((_CurDiffuse
>> 8) & 255);
604 diffCol
.A
= (uint8
)((_CurDiffuse
) & 255);
606 convColor(diffCol
, glColor
);
607 glMaterialfv(GL_FRONT_AND_BACK
, GL_DIFFUSE
, glColor
);
613 // ***************************************************************************
614 void CDriverGLStates::updateDepthRange()
616 H_AUTO_OGL(CDriverGLStates_updateDepthRange
);
618 float delta
= _ZBias
* (_DepthRangeFar
- _DepthRangeNear
);
620 glDepthRange(delta
+ _DepthRangeNear
, delta
+ _DepthRangeFar
);
623 // ***************************************************************************
624 void CDriverGLStates::setZBias(float zbias
)
626 H_AUTO_OGL(CDriverGLStates_setZBias
)
627 #ifndef NL3D_GLSTATE_DISABLE_CACHE
637 // ***************************************************************************
638 void CDriverGLStates::setDepthRange(float znear
, float zfar
)
640 H_AUTO_OGL(CDriverGLStates_setDepthRange
)
641 nlassert(znear
!= zfar
);
642 #ifndef NL3D_GLSTATE_DISABLE_CACHE
643 if (znear
!= _DepthRangeNear
|| zfar
!= _DepthRangeFar
)
646 _DepthRangeNear
= znear
;
647 _DepthRangeFar
= zfar
;
652 // ***************************************************************************
653 void CDriverGLStates::setTexGenMode (uint stage
, GLint mode
)
655 H_AUTO_OGL(CDriverGLStates_setTexGenMode
);
657 #ifndef NL3D_GLSTATE_DISABLE_CACHE
658 if (mode
!= _TexGenMode
[stage
])
661 _TexGenMode
[stage
] = mode
;
663 if (!_TextureCubeMapSupported
) return;
668 glDisable(GL_TEXTURE_GEN_STR_OES
);
670 glDisable( GL_TEXTURE_GEN_S
);
671 glDisable( GL_TEXTURE_GEN_T
);
672 glDisable( GL_TEXTURE_GEN_R
);
673 glDisable( GL_TEXTURE_GEN_Q
);
679 nglTexGeniOES(GL_TEXTURE_GEN_STR_OES
, GL_TEXTURE_GEN_MODE_OES
, mode
);
681 glTexGeni( GL_S
, GL_TEXTURE_GEN_MODE
, mode
);
682 glTexGeni( GL_T
, GL_TEXTURE_GEN_MODE
, mode
);
683 glTexGeni( GL_R
, GL_TEXTURE_GEN_MODE
, mode
);
686 /* Object or Eye Space ? => enable W generation. VERY IMPORTANT because
687 was a bug with VegetableRender and ShadowRender:
688 - Vegetable use the TexCoord1.w in his VertexProgram
689 - Shadow Render don't use any TexCoord in VB (since projected)
690 => TexCoord1.w dirty!!
693 // if(mode==GL_OBJECT_LINEAR || mode==GL_EYE_LINEAR)
695 // nglTexGeniOES(GL_TEXTURE_GEN_STR_OES, GL_TEXTURE_GEN_MODE_OES, mode);
696 // glEnable(GL_TEXTURE_GEN_STR_OES);
700 // glDisable(GL_TEXTURE_GEN_STR_OES);
703 if(mode
==GL_OBJECT_LINEAR
|| mode
==GL_EYE_LINEAR
)
705 glTexGeni( GL_Q
, GL_TEXTURE_GEN_MODE
, mode
);
706 glEnable( GL_TEXTURE_GEN_Q
);
710 glDisable( GL_TEXTURE_GEN_Q
);
716 glEnable(GL_TEXTURE_GEN_STR_OES
);
718 glEnable( GL_TEXTURE_GEN_S
);
719 glEnable( GL_TEXTURE_GEN_T
);
720 glEnable( GL_TEXTURE_GEN_R
);
726 // ***************************************************************************
727 void CDriverGLStates::resetTextureMode()
729 H_AUTO_OGL(CDriverGLStates_resetTextureMode
);
731 glDisable(GL_TEXTURE_2D
);
733 if (_TextureCubeMapSupported
)
735 glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
739 if (_TextureRectangleSupported
)
741 glDisable(GL_TEXTURE_RECTANGLE_NV
);
745 _TextureMode
[_CurrentActiveTextureARB
]= TextureDisabled
;
749 // ***************************************************************************
750 void CDriverGLStates::setTextureMode(TTextureMode texMode
)
752 H_AUTO_OGL(CDriverGLStates_setTextureMode
)
753 TTextureMode oldTexMode
= _TextureMode
[_CurrentActiveTextureARB
];
754 if(oldTexMode
!= texMode
)
756 // Disable first old mode.
757 if (oldTexMode
== Texture2D
)
759 glDisable(GL_TEXTURE_2D
);
761 else if (oldTexMode
== TextureRect
)
764 if(_TextureRectangleSupported
)
766 glDisable(GL_TEXTURE_RECTANGLE_NV
);
771 glDisable(GL_TEXTURE_2D
);
774 else if (oldTexMode
== TextureCubeMap
)
776 if(_TextureCubeMapSupported
)
778 glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
782 glDisable(GL_TEXTURE_2D
);
787 if(texMode
== Texture2D
)
789 glEnable(GL_TEXTURE_2D
);
791 else if(texMode
== TextureRect
)
794 if(_TextureRectangleSupported
)
796 glEnable(GL_TEXTURE_RECTANGLE_NV
);
801 glEnable(GL_TEXTURE_2D
);
804 else if(texMode
== TextureCubeMap
)
806 if(_TextureCubeMapSupported
)
808 glEnable(GL_TEXTURE_CUBE_MAP_ARB
);
812 glEnable(GL_TEXTURE_2D
);
817 _TextureMode
[_CurrentActiveTextureARB
]= texMode
;
822 // ***************************************************************************
823 void CDriverGLStates::activeTextureARB(uint stage
)
825 H_AUTO_OGL(CDriverGLStates_activeTextureARB
);
827 if( _CurrentActiveTextureARB
!= stage
)
829 nglActiveTextureARB(GL_TEXTURE0_ARB
+stage
);
831 _CurrentActiveTextureARB
= stage
;
835 // ***************************************************************************
836 void CDriverGLStates::forceActiveTextureARB(uint stage
)
838 H_AUTO_OGL(CDriverGLStates_forceActiveTextureARB
);
840 nglActiveTextureARB(GL_TEXTURE0_ARB
+stage
);
842 _CurrentActiveTextureARB
= stage
;
845 // ***************************************************************************
846 void CDriverGLStates::enableVertexArray(bool enable
)
848 H_AUTO_OGL(CDriverGLStates_enableVertexArray
);
850 if(_VertexArrayEnabled
!= enable
)
853 glEnableClientState(GL_VERTEX_ARRAY
);
855 glDisableClientState(GL_VERTEX_ARRAY
);
857 _VertexArrayEnabled
= enable
;
860 // ***************************************************************************
861 void CDriverGLStates::enableNormalArray(bool enable
)
863 H_AUTO_OGL(CDriverGLStates_enableNormalArray
)
864 if(_NormalArrayEnabled
!= enable
)
867 glEnableClientState(GL_NORMAL_ARRAY
);
869 glDisableClientState(GL_NORMAL_ARRAY
);
870 _NormalArrayEnabled
= enable
;
875 // ***************************************************************************
876 void CDriverGLStates::enableWeightArray(bool enable
)
878 H_AUTO_OGL(CDriverGLStates_enableWeightArray
);
880 if(_WeightArrayEnabled
!= enable
)
884 glEnableClientState(GL_VERTEX_WEIGHTING_EXT
);
886 glDisableClientState(GL_VERTEX_WEIGHTING_EXT
);
889 _WeightArrayEnabled
= enable
;
892 // ***************************************************************************
893 void CDriverGLStates::enableColorArray(bool enable
)
895 H_AUTO_OGL(CDriverGLStates_enableColorArray
);
897 if(_ColorArrayEnabled
!= enable
)
900 glEnableClientState(GL_COLOR_ARRAY
);
902 glDisableClientState(GL_COLOR_ARRAY
);
903 _ColorArrayEnabled
= enable
;
910 // ***************************************************************************
911 void CDriverGLStates::enableSecondaryColorArray(bool enable
)
913 H_AUTO_OGL(CDriverGLStates_enableSecondaryColorArray
);
915 if(_SecondaryColorArrayEnabled
!= enable
)
919 glEnableClientState(GL_SECONDARY_COLOR_ARRAY_EXT
);
921 glDisableClientState(GL_SECONDARY_COLOR_ARRAY_EXT
);
924 _SecondaryColorArrayEnabled
= enable
;
930 // GeForceFx Bug: Must reset Secondary color to 0 (if comes from a VP), else bugs
931 nglSecondaryColor3ubEXT(0,0,0);
937 // ***************************************************************************
938 void CDriverGLStates::clientActiveTextureARB(uint stage
)
940 H_AUTO_OGL(CDriverGLStates_clientActiveTextureARB
);
942 if( _CurrentClientActiveTextureARB
!= stage
)
944 nglClientActiveTextureARB(GL_TEXTURE0_ARB
+stage
);
945 _CurrentClientActiveTextureARB
= stage
;
949 // ***************************************************************************
950 void CDriverGLStates::enableTexCoordArray(bool enable
)
952 H_AUTO_OGL(CDriverGLStates_enableTexCoordArray
);
954 if(_TexCoordArrayEnabled
[_CurrentClientActiveTextureARB
] != enable
)
957 glEnableClientState(GL_TEXTURE_COORD_ARRAY
);
959 glDisableClientState(GL_TEXTURE_COORD_ARRAY
);
962 _TexCoordArrayEnabled
[_CurrentClientActiveTextureARB
]= enable
;
966 // ***************************************************************************
967 void CDriverGLStates::enableVertexAttribArray(uint glIndex
, bool enable
)
969 H_AUTO_OGL(CDriverGLStates_enableVertexAttribArray
);
971 if(_VertexAttribArrayEnabled
[glIndex
] != enable
)
975 glEnableClientState(glIndex
+GL_VERTEX_ATTRIB_ARRAY0_NV
);
977 glDisableClientState(glIndex
+GL_VERTEX_ATTRIB_ARRAY0_NV
);
980 _VertexAttribArrayEnabled
[glIndex
]= enable
;
984 // ***************************************************************************
985 void CDriverGLStates::enableVertexAttribArrayARB(uint glIndex
,bool enable
)
987 H_AUTO_OGL(CDriverGLStates_enableVertexAttribArrayARB
);
989 #ifndef NL3D_GLSTATE_DISABLE_CACHE
990 if(_VertexAttribArrayEnabled
[glIndex
] != enable
)
995 nglEnableVertexAttribArrayARB(glIndex
);
997 nglDisableVertexAttribArrayARB(glIndex
);
1000 _VertexAttribArrayEnabled
[glIndex
]= enable
;
1004 // ***************************************************************************
1005 void CDriverGLStates::enableVertexAttribArrayForEXTVertexShader(uint glIndex
, bool enable
, uint
*variants
)
1007 H_AUTO_OGL(CDriverGLStates_enableVertexAttribArrayForEXTVertexShader
);
1009 if(_VertexAttribArrayEnabled
[glIndex
] != enable
)
1014 enableVertexArray(enable
);
1016 case 1: // skin weight
1017 #ifndef USE_OPENGLES
1019 nglEnableVariantClientStateEXT(variants
[CDriverGL::EVSSkinWeightVariant
]);
1021 nglDisableVariantClientStateEXT(variants
[CDriverGL::EVSSkinWeightVariant
]);
1025 enableNormalArray(enable
);
1028 enableColorArray(enable
);
1030 case 4: // secondary color
1031 #ifndef USE_OPENGLES
1033 nglEnableVariantClientStateEXT(variants
[CDriverGL::EVSSecondaryColorVariant
]);
1035 nglDisableVariantClientStateEXT(variants
[CDriverGL::EVSSecondaryColorVariant
]);
1038 case 5: // fog coordinate
1039 #ifndef USE_OPENGLES
1041 nglEnableVariantClientStateEXT(variants
[CDriverGL::EVSFogCoordsVariant
]);
1043 nglDisableVariantClientStateEXT(variants
[CDriverGL::EVSFogCoordsVariant
]);
1046 case 6: // palette skin
1047 #ifndef USE_OPENGLES
1049 nglEnableVariantClientStateEXT(variants
[CDriverGL::EVSPaletteSkinVariant
]);
1051 nglDisableVariantClientStateEXT(variants
[CDriverGL::EVSPaletteSkinVariant
]);
1065 clientActiveTextureARB(glIndex
- 8);
1066 enableTexCoordArray(enable
);
1069 nlstop
; // invalid value
1072 _VertexAttribArrayEnabled
[glIndex
]= enable
;
1078 // ***************************************************************************
1079 void CDriverGLStates::enableFog(uint enable
)
1081 H_AUTO_OGL(CDriverGLStates_enableFog
)
1082 // If different from current setup, update.
1083 bool enabled
= (enable
!=0);
1084 #ifndef NL3D_GLSTATE_DISABLE_CACHE
1085 if( enabled
!= _CurFog
)
1098 // ***************************************************************************
1099 void CDriverGLStates::forceBindARBVertexBuffer(uint objectID
)
1101 H_AUTO_OGL(CDriverGLStates_forceBindARBVertexBuffer
)
1103 nglBindBufferARB(GL_ARRAY_BUFFER_ARB
, objectID
);
1105 _CurrARBVertexBuffer
= objectID
;
1108 // ***************************************************************************
1109 void CDriverGLStates::bindARBVertexBuffer(uint objectID
)
1111 H_AUTO_OGL(CDriverGLStates_bindARBVertexBuffer
)
1112 #ifndef NL3D_GLSTATE_DISABLE_CACHE
1113 if (objectID
!= _CurrARBVertexBuffer
)
1116 forceBindARBVertexBuffer(objectID
);
1120 // ***************************************************************************
1121 void CDriverGLStates::setCullMode(TCullMode cullMode
)
1123 H_AUTO_OGL(CDriverGLStates_setCullMode
)
1124 #ifndef NL3D_GLSTATE_DISABLE_CACHE
1125 if (cullMode
!= _CullMode
)
1128 glCullFace(cullMode
== CCW
? GL_BACK
: GL_FRONT
);
1129 _CullMode
= cullMode
;
1133 // ***************************************************************************
1134 CDriverGLStates::TCullMode
CDriverGLStates::getCullMode() const
1136 H_AUTO_OGL(CDriverGLStates_CDriverGLStates
)