Change Encyclo button name and macros icon
[ryzomcore.git] / nel / src / 3d / driver / opengl / driver_opengl_states.h
blobe4b5eb518d15a3c3e3f631cf0388dddbd403053f
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2010 Robert TIMM (rti) <mail@rtti.de>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef NL_DRIVER_OPENGL_STATES_H
21 #define NL_DRIVER_OPENGL_STATES_H
23 #include "nel/misc/types_nl.h"
24 #include "nel/3d/vertex_buffer.h"
26 namespace NL3D {
28 #ifdef NL_STATIC
29 #ifdef USE_OPENGLES
30 namespace NLDRIVERGLES {
31 #else
32 namespace NLDRIVERGL {
33 #endif
34 #endif
36 // ***************************************************************************
37 /**
38 * Class for optimizing calls to openGL states, by caching old ones.
39 * All following call with OpenGL must be done with only one instance of this class:
40 - glEnable() glDisable() with:
41 - GL_BLEND
42 - GL_CULL_FACE
43 - GL_ALPHA_TEST
44 - GL_LIGHTING
45 - GL_LIGHT0 + i .....
46 - GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP_ARB/OES.
47 - GL_TEXTURE_GEN_S, GL_TEXTURE_GEN_T, GL_TEXTURE_GEN_R
48 - GL_COLOR_MATERIAL
49 - GL_FOG
50 - GL_MULTISAMPLE_ARB
51 - glActiveTextureARB()
52 - glClientActiveTextureARB()
53 - glEnableClientState() glDisableClientState() with:
54 - GL_VERTEX_ARRAY
55 - GL_NORMAL_ARRAY
56 - GL_VERTEX_WEIGHTING_EXT
57 - GL_COLOR_ARRAY
58 - GL_SECONDARY_COLOR_ARRAY_EXT
59 - GL_TEXTURE_COORD_ARRAY
60 - GL_VERTEX_ATTRIB_ARRAY0_NV + i.
61 - glDepthMask()
62 - glAlphaFunc()
63 - glBlendFunc()
64 - glDepthFunc()
65 - glMaterialf() and glMaterialfv() for:
66 - GL_EMISSION
67 - GL_AMBIENT
68 - GL_DIFFUSE
69 - GL_SPECULAR
70 - GL_SHININESS
71 - glDepthRange()
72 - glColorMaterial()
73 - glTexGeni()
74 * \author Lionel Berenguier
75 * \author Nevrax France
76 * \date 2001
78 class CDriverGLStates
80 public:
81 /// Constructor. no-op.
82 CDriverGLStates();
83 // init. Do it just after setDisplay()
84 void init(bool supportTextureCubeMap, bool supportTextureRectangle, uint maxLight);
86 /// Reset all OpenGL states of interest to default, and update caching. This don't apply to light.
87 void forceDefaults(uint nbTextureStages);
89 /// \name enable if !0
90 // @{
91 void enableBlend(uint enable);
92 void enableFog(uint enable);
93 void enableCullFace(uint enable);
94 /// enable and set good AlphaFunc.
95 void enableAlphaTest(uint enable);
96 void enableZWrite(uint enable);
97 // overall lighting enabled
98 void enableLighting(uint enable);
99 bool isLightingEnabled() const { return _CurLighting; }
100 /// enable/disable specific light. num must be < "maxLight" param set in init()
101 void enableLight(uint num, uint enable);
102 bool isLightEnabled(uint num) const;
103 /// enable/disable stencil test
104 void enableStencilTest(bool enable);
105 bool isStencilTestEnabled() const { return _CurStencilTest; }
106 /// enable/disable multisample
107 void enableMultisample(bool enable);
108 bool isMultisampleEnabled() const { return _CurMultisample; }
109 // @}
111 /// glBlendFunc.
112 void blendFunc(GLenum src, GLenum dst);
113 /// glDepthFunc.
114 void depthFunc(GLenum zcomp);
115 /// glAlphaFunc
116 void alphaFunc(float threshold);
117 /// glStencilFunc
118 void stencilFunc(GLenum stencilFunc, GLint ref, GLuint mask);
119 /// glStencilOp
120 void stencilOp(GLenum fail, GLenum zfail, GLenum zpass);
121 /// glStencilMask
122 void stencilMask(uint mask);
124 /// \name Material setting.
125 /// Each f() get an uint32 for fast comparison, and OpenGL colors.
126 // @{
127 void setEmissive(uint32 packedColor, const GLfloat color[4]);
128 void setAmbient(uint32 packedColor, const GLfloat color[4]);
129 void setDiffuse(uint32 packedColor, const GLfloat color[4]);
130 void setSpecular(uint32 packedColor, const GLfloat color[4]);
131 void setShininess(float shin);
132 void setVertexColorLighted(bool enable);
133 void setDepthRange (float znear, float zfar);
134 void getDepthRange(float &znear, float &zfar) const { znear = _DepthRangeNear; zfar = _DepthRangeFar; }
135 /** Set z-bias
136 * NB : this is done in window coordinate, not in world coordinate as with CMaterial
138 void setZBias(float zbias);
139 // NB: set 0 to reset TexGen.
140 void setTexGenMode (uint stage, GLint mode);
141 // @}
145 /// \name Texture Mode setting.
146 // @{
147 enum TTextureMode {TextureDisabled, Texture2D, TextureRect, TextureCubeMap, TextureModeCount};
148 /// same as glActiveTextureARB(). useful for setTextureMode.
149 void activeTextureARB(uint stage);
150 /// same as active texture arb, but with no cache check
151 void forceActiveTextureARB(uint stage);
152 /// get active texture
153 uint getActiveTextureARB() const { return _CurrentActiveTextureARB; }
154 /** change if needed the texture mode of the current active Texture ARB.
155 * NB: if CubeMap extension not supported, TextureCubeMap <=> TextureDisabled.
157 void setTextureMode(TTextureMode texMode);
158 TTextureMode getTextureMode() const { return _TextureMode[_CurrentActiveTextureARB]; }
159 // reset texture mode to the default (disabled) for the current stage. It forces the state (useful after texture shaders)
160 void resetTextureMode();
161 // @}
163 /// \name Vertex Array enabling.
164 /// equivalent to glEnableClientState() / glDisableClientState(). NB: Not modified by forceDefaults()
165 // @{
166 void enableVertexArray(bool enable);
167 void enableNormalArray(bool enable);
168 void enableWeightArray(bool enable);
169 void enableColorArray(bool enable);
170 void enableSecondaryColorArray(bool enable);
171 /// same as glClientActiveTextureARB(). useful for enableTexCoordArray.
172 void clientActiveTextureARB(uint stage);
173 /// NB: caller must call correct clientActiveTextureARB() before.
174 void enableTexCoordArray(bool enable);
175 /** For vertexProgram. do not check if supported or not.
177 void enableVertexAttribArray(uint glIndex, bool enable);
178 /** Same as enableVertexAttribArray, but for EXTVertexShader (need variant ID)
179 * \param firstVariantSymbol the first variant symbol
181 void enableVertexAttribArrayForEXTVertexShader(uint glIndex, bool enable, uint *variants);
183 // special version for ARB_vertex_program used with ARB_vertex_buffer or ATI_vertex_attrib_array_object
184 void enableVertexAttribArrayARB(uint glIndex, bool enable);
187 // @}
190 // ARB_vertex_buffer_object buffer binding
191 void bindARBVertexBuffer(uint objectID);
192 void forceBindARBVertexBuffer(uint objectID);
193 uint getCurrBoundARBVertexBuffer() const { return _CurrARBVertexBuffer; }
195 enum TCullMode { CCW = 0, CW };
196 void setCullMode(TCullMode cullMode);
197 TCullMode getCullMode() const;
199 private:
200 bool _CurBlend;
201 bool _CurFog;
202 bool _CurCullFace;
203 bool _CurAlphaTest;
204 bool _CurLighting;
205 bool _CurZWrite;
206 bool _CurStencilTest;
207 bool _CurMultisample;
209 GLenum _CurBlendSrc;
210 GLenum _CurBlendDst;
211 GLenum _CurDepthFunc;
212 GLenum _CurStencilFunc;
213 GLint _CurStencilRef;
214 GLuint _CurStencilMask;
215 GLenum _CurStencilOpFail;
216 GLenum _CurStencilOpZFail;
217 GLenum _CurStencilOpZPass;
218 GLuint _CurStencilWriteMask;
219 float _CurAlphaTestThreshold;
221 uint32 _CurEmissive;
222 uint32 _CurAmbient;
223 uint32 _CurDiffuse;
224 uint32 _CurSpecular;
225 float _CurShininess;
226 bool _VertexColorLighted;
228 bool _TextureCubeMapSupported;
229 bool _TextureRectangleSupported;
230 uint _CurrentActiveTextureARB;
231 TTextureMode _TextureMode[8];
233 bool _VertexArrayEnabled;
234 bool _NormalArrayEnabled;
235 bool _WeightArrayEnabled;
236 bool _ColorArrayEnabled;
237 bool _SecondaryColorArrayEnabled;
238 uint _CurrentClientActiveTextureARB;
239 bool _TexCoordArrayEnabled[8];
240 bool _VertexAttribArrayEnabled[CVertexBuffer::NumValue];
242 GLint _TexGenMode[8];
244 uint _CurrARBVertexBuffer;
246 float _DepthRangeNear;
247 float _DepthRangeFar;
248 float _ZBias; // NB : zbias is in window coordinates
250 TCullMode _CullMode;
252 private:
253 void updateDepthRange();
255 // Mirror of glEnable() and GL_LIGHT0+i
256 enum {MaxLight=8};
257 uint _MaxDriverLight;
258 bool _CurLight[MaxLight];
261 #ifdef NL_STATIC
262 } // NLDRIVERGL/ES
263 #endif
265 } // NL3D
268 #endif // NL_DRIVER_OPENGL_STATES_H
270 /* End of driver_opengl_states.h */