csplugincommon/opengl/glstates.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 2002 by Anders Stenberg 00003 Written by Anders Stenberg 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public 00016 License along with this library; if not, write to the Free 00017 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00020 #ifndef __CS_GLSTATES_H__ 00021 #define __CS_GLSTATES_H__ 00022 00027 #if defined(CS_OPENGL_PATH) 00028 #include CS_HEADER_GLOBAL(CS_OPENGL_PATH,gl.h) 00029 #else 00030 #include <GL/gl.h> 00031 #endif 00032 00033 #include "csextern_gl.h" 00034 #include "csgeom/math.h" 00035 #include "glextmanager.h" 00036 00040 // Set to 'true' to force state changing commands. For debugging. 00041 #define FORCE_STATE_CHANGE false/*true*/ 00042 00043 #define DECLARE_CACHED_BOOL(name) \ 00044 bool enabled_##name; 00045 00046 #define IMPLEMENT_CACHED_BOOL(name) \ 00047 void Enable_##name () \ 00048 { \ 00049 if (!currentContext->enabled_##name || FORCE_STATE_CHANGE) \ 00050 { \ 00051 currentContext->enabled_##name = true; \ 00052 glEnable (name); \ 00053 } \ 00054 } \ 00055 void Disable_##name () \ 00056 { \ 00057 if (currentContext->enabled_##name || FORCE_STATE_CHANGE) { \ 00058 currentContext->enabled_##name = false; \ 00059 glDisable (name); \ 00060 } \ 00061 } \ 00062 bool IsEnabled_##name () const \ 00063 { \ 00064 return currentContext->enabled_##name; \ 00065 } 00066 00067 #define DECLARE_CACHED_BOOL_CURRENTLAYER(name) \ 00068 AutoArray<bool> enabled_##name; 00069 00070 #define IMPLEMENT_CACHED_BOOL_CURRENTLAYER(name) \ 00071 void Enable_##name () \ 00072 { \ 00073 const int currentUnit = currentContext->currentUnit; \ 00074 if (!currentContext->enabled_##name[currentUnit] || FORCE_STATE_CHANGE) \ 00075 { \ 00076 ActivateTU (activateTexEnable); \ 00077 currentContext->enabled_##name[currentUnit] = true; \ 00078 glEnable (name); \ 00079 } \ 00080 } \ 00081 void Disable_##name () \ 00082 { \ 00083 const int currentUnit = currentContext->currentUnit; \ 00084 if (currentContext->enabled_##name[currentUnit] || FORCE_STATE_CHANGE) \ 00085 { \ 00086 ActivateTU (activateTexEnable); \ 00087 currentContext->enabled_##name[currentUnit] = false; \ 00088 glDisable (name); \ 00089 } \ 00090 } \ 00091 bool IsEnabled_##name () const \ 00092 { \ 00093 const int currentUnit = currentContext->currentUnit; \ 00094 return currentContext->enabled_##name[currentUnit]; \ 00095 } 00096 00097 #define DECLARE_CACHED_PARAMETER_1(func, name, type1, param1) \ 00098 type1 parameter_##param1; 00099 00100 #define IMPLEMENT_CACHED_PARAMETER_1(func, name, type1, param1) \ 00101 void Set##name (type1 param1, bool forced = false) \ 00102 { \ 00103 if (forced || (param1 != currentContext->parameter_##param1) || FORCE_STATE_CHANGE) \ 00104 { \ 00105 currentContext->parameter_##param1 = param1; \ 00106 func (param1); \ 00107 } \ 00108 } \ 00109 void Get##name (type1 & param1) const\ 00110 { \ 00111 param1 = currentContext->parameter_##param1; \ 00112 } 00113 00114 #define DECLARE_CACHED_PARAMETER_2(func, name, type1, param1, type2, param2) \ 00115 type1 parameter_##param1; \ 00116 type2 parameter_##param2; 00117 00118 #define IMPLEMENT_CACHED_PARAMETER_2(func, name, type1, param1, type2, param2) \ 00119 void Set##name (type1 param1, type2 param2, bool forced = false) \ 00120 { \ 00121 if (forced || (param1 != currentContext->parameter_##param1) || \ 00122 (param2 != currentContext->parameter_##param2) || FORCE_STATE_CHANGE) \ 00123 { \ 00124 currentContext->parameter_##param1 = param1; \ 00125 currentContext->parameter_##param2 = param2; \ 00126 func (param1, param2); \ 00127 } \ 00128 } \ 00129 void Get##name (type1 & param1, type2 & param2) const\ 00130 { \ 00131 param1 = currentContext->parameter_##param1; \ 00132 param2 = currentContext->parameter_##param2; \ 00133 } 00134 00135 #define DECLARE_CACHED_PARAMETER_3(func, name, type1, param1, type2, param2, type3, param3) \ 00136 type1 parameter_##param1; \ 00137 type2 parameter_##param2; \ 00138 type3 parameter_##param3; 00139 00140 #define IMPLEMENT_CACHED_PARAMETER_3(func, name, type1, param1, type2, param2, type3, param3) \ 00141 void Set##name (type1 param1, type2 param2, type3 param3, bool forced = false) \ 00142 { \ 00143 if (forced || (param1 != currentContext->parameter_##param1) \ 00144 || (param2 != currentContext->parameter_##param2) \ 00145 || (param3 != currentContext->parameter_##param3) || FORCE_STATE_CHANGE) \ 00146 { \ 00147 currentContext->parameter_##param1 = param1; \ 00148 currentContext->parameter_##param2 = param2; \ 00149 currentContext->parameter_##param3 = param3; \ 00150 func (param1, param2, param3); \ 00151 } \ 00152 } \ 00153 void Get##name (type1 ¶m1, type2 & param2, type3 & param3) const\ 00154 { \ 00155 param1 = currentContext->parameter_##param1; \ 00156 param2 = currentContext->parameter_##param2; \ 00157 param3 = currentContext->parameter_##param3; \ 00158 } 00159 00160 #define DECLARE_CACHED_PARAMETER_3_BUF(func, name, type1, param1, type2, param2, type3, param3, vbo) \ 00161 type1 parameter_##param1; \ 00162 type2 parameter_##param2; \ 00163 type3 parameter_##param3; \ 00164 GLuint parameter_##vbo; 00165 00166 #define IMPLEMENT_CACHED_PARAMETER_3_BUF(func, name, type1, param1, type2, param2, type3, param3, vbo) \ 00167 void Set##name (type1 param1, type2 param2, type3 param3, bool forced = false) \ 00168 { \ 00169 if (forced || (param1 != currentContext->parameter_##param1) \ 00170 || (param2 != currentContext->parameter_##param2) \ 00171 || (param3 != currentContext->parameter_##param3) \ 00172 || (currentContext->currentBufferID[csGLStateCacheContext::boElementArray] \ 00173 != currentContext->parameter_##vbo) \ 00174 || FORCE_STATE_CHANGE) \ 00175 { \ 00176 currentContext->parameter_##param1 = param1; \ 00177 currentContext->parameter_##param2 = param2; \ 00178 currentContext->parameter_##param3 = param3; \ 00179 if (extmgr->CS_GL_ARB_vertex_buffer_object) \ 00180 { \ 00181 ApplyBufferBinding (csGLStateCacheContext::boElementArray); \ 00182 currentContext->parameter_##vbo \ 00183 = currentContext->currentBufferID[csGLStateCacheContext::boElementArray];\ 00184 } \ 00185 func (param1, param2, param3); \ 00186 } \ 00187 } \ 00188 void Get##name (type1 ¶m1, type2 & param2, type3 & param3) const\ 00189 { \ 00190 param1 = currentContext->parameter_##param1; \ 00191 param2 = currentContext->parameter_##param2; \ 00192 param3 = currentContext->parameter_##param3; \ 00193 } 00194 00195 #define DECLARE_CACHED_PARAMETER_4(func, name, type1, param1, \ 00196 type2, param2, type3, param3, type4, param4) \ 00197 type1 parameter_##param1; \ 00198 type2 parameter_##param2; \ 00199 type3 parameter_##param3; \ 00200 type4 parameter_##param4; 00201 00202 #define IMPLEMENT_CACHED_PARAMETER_4(func, name, type1, param1, \ 00203 type2, param2, type3, param3, type4, param4) \ 00204 void Set##name (type1 param1, type2 param2, type3 param3, type4 param4, \ 00205 bool forced = false) \ 00206 { \ 00207 if (forced || (param1 != currentContext->parameter_##param1) || \ 00208 (param2 != currentContext->parameter_##param2) || \ 00209 (param3 != currentContext->parameter_##param3) || \ 00210 (param4 != currentContext->parameter_##param4) || FORCE_STATE_CHANGE) \ 00211 { \ 00212 currentContext->parameter_##param1 = param1; \ 00213 currentContext->parameter_##param2 = param2; \ 00214 currentContext->parameter_##param3 = param3; \ 00215 currentContext->parameter_##param4 = param4; \ 00216 func (param1, param2, param3, param4); \ 00217 } \ 00218 } \ 00219 void Get##name (type1 ¶m1, type2 & param2, type3 & param3, type4& param4) const\ 00220 { \ 00221 param1 = currentContext->parameter_##param1; \ 00222 param2 = currentContext->parameter_##param2; \ 00223 param3 = currentContext->parameter_##param3; \ 00224 param4 = currentContext->parameter_##param4; \ 00225 } 00226 00227 #define DECLARE_CACHED_PARAMETER_4_BUF(func, name, type1, param1, \ 00228 type2, param2, type3, param3, type4, param4, vbo) \ 00229 type1 parameter_##param1; \ 00230 type2 parameter_##param2; \ 00231 type3 parameter_##param3; \ 00232 type4 parameter_##param4; \ 00233 GLuint parameter_##vbo; 00234 00235 #define IMPLEMENT_CACHED_PARAMETER_4_BUF(func, name, type1, param1, \ 00236 type2, param2, type3, param3, type4, param4, vbo) \ 00237 void Set##name (type1 param1, type2 param2, type3 param3, type4 param4, \ 00238 bool forced = false) \ 00239 { \ 00240 if (forced || (param1 != currentContext->parameter_##param1) || \ 00241 (param2 != currentContext->parameter_##param2) || \ 00242 (param3 != currentContext->parameter_##param3) || \ 00243 (param4 != currentContext->parameter_##param4) \ 00244 || (currentContext->currentBufferID[csGLStateCacheContext::boElementArray] \ 00245 != currentContext->parameter_##vbo) \ 00246 || FORCE_STATE_CHANGE) \ 00247 { \ 00248 currentContext->parameter_##param1 = param1; \ 00249 currentContext->parameter_##param2 = param2; \ 00250 currentContext->parameter_##param3 = param3; \ 00251 currentContext->parameter_##param4 = param4; \ 00252 if (extmgr->CS_GL_ARB_vertex_buffer_object) \ 00253 { \ 00254 ApplyBufferBinding (csGLStateCacheContext::boElementArray); \ 00255 currentContext->parameter_##vbo = \ 00256 currentContext->currentBufferID[csGLStateCacheContext::boElementArray];\ 00257 } \ 00258 func (param1, param2, param3, param4); \ 00259 } \ 00260 } \ 00261 void Get##name (type1 ¶m1, type2 & param2, type3 & param3, type4& param4) const\ 00262 { \ 00263 param1 = currentContext->parameter_##param1; \ 00264 param2 = currentContext->parameter_##param2; \ 00265 param3 = currentContext->parameter_##param3; \ 00266 param4 = currentContext->parameter_##param4; \ 00267 } 00268 00269 #define DECLARE_CACHED_CLIENT_STATE(name) \ 00270 bool enabled_##name; 00271 00272 #define IMPLEMENT_CACHED_CLIENT_STATE(name) \ 00273 void Enable_##name () \ 00274 { \ 00275 if (!currentContext->enabled_##name || FORCE_STATE_CHANGE) \ 00276 { \ 00277 currentContext->enabled_##name = true; \ 00278 glEnableClientState (name); \ 00279 } \ 00280 } \ 00281 void Disable_##name () \ 00282 { \ 00283 if (currentContext->enabled_##name || FORCE_STATE_CHANGE) { \ 00284 currentContext->enabled_##name = false; \ 00285 glDisableClientState (name); \ 00286 } \ 00287 } \ 00288 bool IsEnabled_##name () const \ 00289 { \ 00290 return currentContext->enabled_##name; \ 00291 } 00292 00293 #define DECLARE_CACHED_CLIENT_STATE_LAYER(name) \ 00294 AutoArray<bool> enabled_##name; 00295 00296 #define IMPLEMENT_CACHED_CLIENT_STATE_LAYER(name) \ 00297 void Enable_##name () \ 00298 { \ 00299 const int currentUnit = currentContext->currentUnit; \ 00300 if (!currentContext->enabled_##name[currentUnit] || FORCE_STATE_CHANGE) \ 00301 { \ 00302 ActivateTU (activateTexCoord); \ 00303 currentContext->enabled_##name[currentUnit] = true; \ 00304 glEnableClientState (name); \ 00305 } \ 00306 } \ 00307 void Disable_##name () \ 00308 { \ 00309 const int currentUnit = currentContext->currentUnit; \ 00310 if (currentContext->enabled_##name[currentUnit] || FORCE_STATE_CHANGE) \ 00311 { \ 00312 ActivateTU (activateTexCoord); \ 00313 currentContext->enabled_##name[currentUnit] = false; \ 00314 glDisableClientState (name); \ 00315 } \ 00316 } \ 00317 bool IsEnabled_##name () const \ 00318 { \ 00319 const int currentUnit = currentContext->currentUnit; \ 00320 return currentContext->enabled_##name[currentUnit]; \ 00321 } 00322 00323 #define DECLARE_CACHED_PARAMETER_1_LAYER(func, name, type1, param1) \ 00324 AutoArray<type1> parameter_##param1; 00325 00326 #define IMPLEMENT_CACHED_PARAMETER_1_LAYER(func, name, type1, param1) \ 00327 void Set##name (type1 param1, bool forced = false) \ 00328 { \ 00329 if (forced || \ 00330 (param1 != currentContext->parameter_##param1[currentContext->currentUnit] \ 00331 || FORCE_STATE_CHANGE)) \ 00332 { \ 00333 ActivateTU (); \ 00334 currentContext->parameter_##param1[currentContext->currentUnit] = param1; \ 00335 func (param1); \ 00336 } \ 00337 } \ 00338 void Get##name (type1 ¶m1) const\ 00339 { \ 00340 param1 = currentContext->parameter_##param1[currentContext->currentUnit]; \ 00341 } 00342 00343 #define DECLARE_CACHED_PARAMETER_2_LAYER(func, name, type1, param1, \ 00344 type2, param2) \ 00345 AutoArray<type1> parameter_##param1; \ 00346 AutoArray<type2> parameter_##param2; 00347 00348 #define IMPLEMENT_CACHED_PARAMETER_2_LAYER(func, name, type1, param1, \ 00349 type2, param2) \ 00350 void Set##name (type1 param1, type2 param2, bool forced = false) \ 00351 { \ 00352 if (forced || (param1 != currentContext->parameter_##param1[ \ 00353 currentContext->currentUnit]) || \ 00354 (param2 != currentContext->parameter_##param2[ \ 00355 currentContext->currentUnit]) \ 00356 || FORCE_STATE_CHANGE) \ 00357 { \ 00358 ActivateTU (); \ 00359 currentContext->parameter_##param1[currentContext->currentUnit] = param1; \ 00360 currentContext->parameter_##param2[currentContext->currentUnit] = param2; \ 00361 func (param1, param2); \ 00362 } \ 00363 } \ 00364 void Get##name (type1 ¶m1, type2 & param2) const\ 00365 { \ 00366 param1 = currentContext->parameter_##param1[currentContext->currentUnit]; \ 00367 param2 = currentContext->parameter_##param2[currentContext->currentUnit]; \ 00368 } 00369 00370 #define DECLARE_CACHED_PARAMETER_3_LAYER(func, name, type1, param1, \ 00371 type2, param2, type3, param3) \ 00372 AutoArray<type1> parameter_##param1; \ 00373 AutoArray<type2> parameter_##param2; \ 00374 AutoArray<type3> parameter_##param3; 00375 00376 00377 #define IMPLEMENT_CACHED_PARAMETER_3_LAYER(func, name, type1, param1, \ 00378 type2, param2, type3, param3) \ 00379 void Set##name (type1 param1, type2 param2, type3 param3,\ 00380 bool forced = false) \ 00381 { \ 00382 if (forced || (param1 != currentContext->parameter_##param1[ \ 00383 currentContext->currentUnit]) || \ 00384 (param2 != currentContext->parameter_##param2[ \ 00385 currentContext->currentUnit]) || \ 00386 (param3 != currentContext->parameter_##param3[ \ 00387 currentContext->currentUnit]) \ 00388 || FORCE_STATE_CHANGE) \ 00389 { \ 00390 ActivateTU (); \ 00391 currentContext->parameter_##param1[currentContext->currentUnit] = param1; \ 00392 currentContext->parameter_##param2[currentContext->currentUnit] = param2; \ 00393 currentContext->parameter_##param3[currentContext->currentUnit] = param3; \ 00394 func (param1, param2, param3); \ 00395 } \ 00396 } \ 00397 void Get##name (type1 ¶m1, type2 & param2, type3 & param3) const\ 00398 { \ 00399 param1 = currentContext->parameter_##param1[currentContext->currentUnit]; \ 00400 param2 = currentContext->parameter_##param2[currentContext->currentUnit]; \ 00401 param3 = currentContext->parameter_##param3[currentContext->currentUnit]; \ 00402 } 00403 00404 00405 #define DECLARE_CACHED_PARAMETER_4_BUF_LAYER(func, name, type1, param1, \ 00406 type2, param2, type3, param3, type4, param4, vbo) \ 00407 AutoArray<type1> parameter_##param1; \ 00408 AutoArray<type2> parameter_##param2; \ 00409 AutoArray<type3> parameter_##param3; \ 00410 AutoArray<type4> parameter_##param4; \ 00411 AutoArray<GLuint> parameter_##vbo; 00412 00413 #define IMPLEMENT_CACHED_PARAMETER_4_BUF_LAYER(func, name, type1, param1, \ 00414 type2, param2, type3, param3, type4, param4, vbo) \ 00415 void Set##name (type1 param1, type2 param2, type3 param3, type4 param4, \ 00416 bool forced = false) \ 00417 { \ 00418 const int currentUnit = currentContext->currentUnit; \ 00419 if (forced \ 00420 || (param1 != currentContext->parameter_##param1[currentUnit]) \ 00421 || (param2 != currentContext->parameter_##param2[currentUnit]) \ 00422 || (param3 != currentContext->parameter_##param3[currentUnit]) \ 00423 || (param4 != currentContext->parameter_##param4[currentUnit]) \ 00424 || (currentContext->currentBufferID[csGLStateCacheContext::boElementArray]\ 00425 != currentContext->parameter_##vbo[currentUnit]) \ 00426 || FORCE_STATE_CHANGE) \ 00427 { \ 00428 ActivateTU (activateTexCoord); \ 00429 currentContext->parameter_##param1[currentUnit] = param1; \ 00430 currentContext->parameter_##param2[currentUnit] = param2; \ 00431 currentContext->parameter_##param3[currentUnit] = param3; \ 00432 currentContext->parameter_##param4[currentUnit] = param4; \ 00433 if (extmgr->CS_GL_ARB_vertex_buffer_object) \ 00434 { \ 00435 ApplyBufferBinding (csGLStateCacheContext::boElementArray); \ 00436 currentContext->parameter_##vbo[currentUnit] = \ 00437 currentContext->currentBufferID[csGLStateCacheContext::boElementArray];\ 00438 } \ 00439 func (param1, param2, param3, param4); \ 00440 } \ 00441 } \ 00442 void Get##name (type1 ¶m1, type2 & param2, type3 & param3, \ 00443 type4& param4) const \ 00444 { \ 00445 const int currentUnit = currentContext->currentUnit; \ 00446 param1 = currentContext->parameter_##param1[currentUnit]; \ 00447 param2 = currentContext->parameter_##param2[currentUnit]; \ 00448 param3 = currentContext->parameter_##param3[currentUnit]; \ 00449 param4 = currentContext->parameter_##param4[currentUnit]; \ 00450 } 00451 00452 00453 class csGLStateCacheContext 00454 { 00455 template<typename T> 00456 struct AutoArray 00457 { 00458 T* p; 00459 00460 AutoArray() : p (0) {} 00461 ~AutoArray() 00462 { 00463 delete[] p; 00464 } 00465 void Setup (size_t n) 00466 { 00467 CS_ASSERT (p == 0); 00468 p = new T[n]; 00469 } 00470 00471 T& operator[] (size_t idx) 00472 { 00473 return p[idx]; 00474 } 00475 }; 00476 public: 00477 csGLExtensionManager* extmgr; 00478 00479 // Special caches 00480 AutoArray<GLuint> boundtexture; 00481 GLint numImageUnits; 00482 GLint numTexCoords; 00483 int currentUnit; 00484 int activeUnit[2]; 00485 enum 00486 { 00487 boElementArray = 0, boIndexArray, boPixelPack, boPixelUnpack, 00488 00489 boCount 00490 }; 00491 GLuint currentBufferID[boCount]; 00492 GLuint activeBufferID[boCount]; 00493 static int GLBufferTargetToCacheIndex (GLenum target) 00494 { 00495 switch (target) 00496 { 00497 case GL_ARRAY_BUFFER_ARB: return boElementArray; 00498 case GL_ELEMENT_ARRAY_BUFFER_ARB: return boIndexArray; 00499 case GL_PIXEL_PACK_BUFFER_ARB: return boPixelPack; 00500 case GL_PIXEL_UNPACK_BUFFER_ARB: return boPixelUnpack; 00501 default: return -1; 00502 } 00503 } 00504 static GLenum CacheIndexToGLBufferTarget (int index) 00505 { 00506 static const GLenum localIndexToGLBufferTarget[boCount] = 00507 { GL_ARRAY_BUFFER_ARB, GL_ELEMENT_ARRAY_BUFFER_ARB, 00508 GL_PIXEL_PACK_BUFFER_ARB, GL_PIXEL_UNPACK_BUFFER_ARB }; 00509 return localIndexToGLBufferTarget[index]; 00510 } 00511 00512 // BlendFunc/BlendFuncSeparate 00513 GLenum blend_sourceRGB; 00514 GLenum blend_destinationRGB; 00515 GLenum blend_sourceA; 00516 GLenum blend_destinationA; 00517 00518 // Pixel storage 00519 GLint pixelUnpackAlignment; 00520 bool pixelUnpackSwapBytes; 00521 00522 // Standardized caches 00523 DECLARE_CACHED_BOOL (GL_DEPTH_TEST) 00524 DECLARE_CACHED_BOOL (GL_BLEND) 00525 DECLARE_CACHED_BOOL (GL_DITHER) 00526 DECLARE_CACHED_BOOL (GL_STENCIL_TEST) 00527 DECLARE_CACHED_BOOL (GL_CULL_FACE) 00528 DECLARE_CACHED_BOOL (GL_POLYGON_OFFSET_FILL) 00529 DECLARE_CACHED_BOOL (GL_LIGHTING) 00530 DECLARE_CACHED_BOOL (GL_ALPHA_TEST) 00531 DECLARE_CACHED_BOOL (GL_SCISSOR_TEST) 00532 DECLARE_CACHED_BOOL (GL_TEXTURE_GEN_S) 00533 DECLARE_CACHED_BOOL (GL_TEXTURE_GEN_T) 00534 DECLARE_CACHED_BOOL (GL_TEXTURE_GEN_R) 00535 DECLARE_CACHED_BOOL (GL_TEXTURE_GEN_Q) 00536 DECLARE_CACHED_BOOL (GL_FOG) 00537 DECLARE_CACHED_BOOL (GL_COLOR_SUM_EXT) 00538 DECLARE_CACHED_BOOL (GL_VERTEX_PROGRAM_POINT_SIZE_ARB) 00539 DECLARE_CACHED_BOOL (GL_POINT_SPRITE_ARB) 00540 DECLARE_CACHED_BOOL_CURRENTLAYER (GL_TEXTURE_1D) 00541 DECLARE_CACHED_BOOL_CURRENTLAYER (GL_TEXTURE_2D) 00542 DECLARE_CACHED_BOOL_CURRENTLAYER (GL_TEXTURE_3D) 00543 DECLARE_CACHED_BOOL_CURRENTLAYER (GL_TEXTURE_CUBE_MAP) 00544 DECLARE_CACHED_BOOL_CURRENTLAYER (GL_TEXTURE_RECTANGLE_ARB) 00545 DECLARE_CACHED_PARAMETER_2 (glAlphaFunc, AlphaFunc, GLenum, alpha_func, GLclampf, alpha_ref) 00546 DECLARE_CACHED_PARAMETER_1 (glCullFace, CullFace, GLenum, cull_mode) 00547 DECLARE_CACHED_PARAMETER_1 (glDepthFunc, DepthFunc, GLenum, depth_func) 00548 DECLARE_CACHED_PARAMETER_1 (glDepthMask, DepthMask, GLboolean, depth_mask) 00549 DECLARE_CACHED_PARAMETER_1 (glShadeModel, ShadeModel, GLenum, shade_model) 00550 DECLARE_CACHED_PARAMETER_3 (glStencilFunc, StencilFunc, GLenum, stencil_func, GLint, stencil_ref, GLuint, stencil_mask) 00551 DECLARE_CACHED_PARAMETER_3 (glStencilOp, StencilOp, GLenum, stencil_fail, GLenum, stencil_zfail, GLenum, stencil_zpass) 00552 DECLARE_CACHED_PARAMETER_1 (glStencilMask, StencilMask, GLuint, maskl) 00553 DECLARE_CACHED_PARAMETER_4 (glColorMask, ColorMask, GLboolean, wmRed, \ 00554 GLboolean, wmGreen, GLboolean, wmBlue, GLboolean, wmAlpha) 00555 00556 DECLARE_CACHED_CLIENT_STATE (GL_VERTEX_ARRAY) 00557 DECLARE_CACHED_CLIENT_STATE (GL_COLOR_ARRAY) 00558 DECLARE_CACHED_CLIENT_STATE (GL_SECONDARY_COLOR_ARRAY_EXT) 00559 DECLARE_CACHED_CLIENT_STATE (GL_NORMAL_ARRAY) 00560 DECLARE_CACHED_CLIENT_STATE_LAYER (GL_TEXTURE_COORD_ARRAY) 00561 00562 DECLARE_CACHED_PARAMETER_1 (glMatrixMode, MatrixMode, GLenum, matrixMode) 00563 00564 DECLARE_CACHED_PARAMETER_4_BUF (glVertexPointer, VertexPointer, GLint, vsize, 00565 GLenum, vtype, GLsizei, vstride, GLvoid*, vpointer, vvbo) 00566 DECLARE_CACHED_PARAMETER_3_BUF (glNormalPointer, NormalPointer, GLenum, ntype, 00567 GLsizei, nstride, GLvoid*, npointer, nvbo) 00568 DECLARE_CACHED_PARAMETER_4_BUF (glColorPointer, ColorPointer, GLint, csize, 00569 GLenum, ctype, GLsizei, cstride, GLvoid*, cpointer, cvbo) 00570 DECLARE_CACHED_PARAMETER_4_BUF (extmgr->glSecondaryColorPointerEXT, 00571 SecondaryColorPointerEXT, GLint, scsize, GLenum, sctype, GLsizei, scstride, 00572 GLvoid*, scpointer, scvbo); 00573 DECLARE_CACHED_PARAMETER_4_BUF_LAYER (glTexCoordPointer, TexCoordPointer, GLint, tsize, 00574 GLenum, ttype, GLsizei, tstride, GLvoid*, tpointer, tvbo) 00575 00576 csGLStateCacheContext (csGLExtensionManager* extmgr) 00577 { 00578 csGLStateCacheContext::extmgr = extmgr; 00579 00580 // Need to init exts here b/c we need the image units count 00581 extmgr->InitGL_ARB_multitexture (); 00582 extmgr->InitGL_ARB_fragment_program (); 00583 00584 if (extmgr->CS_GL_ARB_fragment_program) 00585 { 00586 glGetIntegerv (GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &numImageUnits); 00587 glGetIntegerv (GL_MAX_TEXTURE_COORDS_ARB, &numTexCoords); 00588 } 00589 else if (extmgr->CS_GL_ARB_multitexture) 00590 { 00591 glGetIntegerv (GL_MAX_TEXTURE_UNITS_ARB, &numImageUnits); 00592 numTexCoords = numImageUnits; 00593 } 00594 else 00595 { 00596 numTexCoords = numImageUnits = 1; 00597 } 00598 00599 boundtexture.Setup (numImageUnits); 00600 enabled_GL_TEXTURE_1D.Setup (numImageUnits); 00601 enabled_GL_TEXTURE_2D.Setup (numImageUnits); 00602 enabled_GL_TEXTURE_3D.Setup (numImageUnits); 00603 enabled_GL_TEXTURE_CUBE_MAP.Setup (numImageUnits); 00604 enabled_GL_TEXTURE_RECTANGLE_ARB.Setup (numImageUnits); 00605 00606 enabled_GL_TEXTURE_COORD_ARRAY.Setup (numTexCoords); 00607 parameter_tsize.Setup (numTexCoords); 00608 parameter_ttype.Setup (numTexCoords); 00609 parameter_tstride.Setup (numTexCoords); 00610 parameter_tpointer.Setup (numTexCoords); 00611 parameter_tvbo.Setup (numTexCoords); 00612 00613 memset (activeBufferID, 0, sizeof (activeBufferID)); 00614 } 00615 00620 void InitCache() 00621 { 00622 int i; 00623 glGetIntegerv (GL_ALPHA_TEST_FUNC, (GLint*)¶meter_alpha_func); 00624 glGetFloatv (GL_ALPHA_TEST_REF, ¶meter_alpha_ref); 00625 if (extmgr->CS_GL_EXT_blend_func_separate) 00626 { 00627 glGetIntegerv (GL_BLEND_SRC_RGB_EXT, (GLint*)&blend_sourceRGB); 00628 glGetIntegerv (GL_BLEND_SRC_ALPHA_EXT, (GLint*)&blend_sourceA); 00629 glGetIntegerv (GL_BLEND_DST_RGB_EXT, (GLint*)&blend_destinationRGB); 00630 glGetIntegerv (GL_BLEND_DST_ALPHA_EXT, (GLint*)&blend_destinationA); 00631 } 00632 else 00633 { 00634 glGetIntegerv (GL_BLEND_SRC, (GLint*)&blend_sourceRGB); 00635 blend_sourceA = blend_sourceRGB; 00636 glGetIntegerv (GL_BLEND_DST, (GLint*)&blend_destinationRGB); 00637 blend_destinationA = blend_destinationRGB; 00638 } 00639 glGetIntegerv (GL_CULL_FACE_MODE, (GLint*)¶meter_cull_mode); 00640 glGetIntegerv (GL_DEPTH_FUNC, (GLint*)¶meter_depth_func); 00641 glGetBooleanv (GL_DEPTH_WRITEMASK, ¶meter_depth_mask); 00642 glGetIntegerv (GL_SHADE_MODEL, (GLint*)¶meter_shade_model); 00643 glGetIntegerv (GL_STENCIL_BITS, (GLint*)¶meter_maskl); 00644 glGetIntegerv (GL_STENCIL_FUNC, (GLint*)¶meter_stencil_func); 00645 glGetIntegerv (GL_STENCIL_VALUE_MASK, (GLint*)¶meter_stencil_mask); 00646 glGetIntegerv (GL_STENCIL_REF, ¶meter_stencil_ref); 00647 glGetIntegerv (GL_STENCIL_FAIL, (GLint*)¶meter_stencil_fail); 00648 glGetIntegerv (GL_STENCIL_PASS_DEPTH_FAIL, (GLint*)¶meter_stencil_zfail); 00649 glGetIntegerv (GL_STENCIL_PASS_DEPTH_PASS, (GLint*)¶meter_stencil_zpass); 00650 glGetIntegerv (GL_MATRIX_MODE, (GLint*)¶meter_matrixMode); 00651 GLboolean writemask[4]; 00652 glGetBooleanv (GL_COLOR_WRITEMASK, writemask); 00653 parameter_wmRed = writemask[0]; 00654 parameter_wmGreen = writemask[1]; 00655 parameter_wmBlue = writemask[2]; 00656 parameter_wmAlpha = writemask[3]; 00657 enabled_GL_DEPTH_TEST = (glIsEnabled (GL_DEPTH_TEST) == GL_TRUE); 00658 enabled_GL_BLEND = (glIsEnabled (GL_BLEND) == GL_TRUE); 00659 enabled_GL_DITHER = (glIsEnabled (GL_DITHER) == GL_TRUE); 00660 enabled_GL_STENCIL_TEST = (glIsEnabled (GL_STENCIL_TEST) == GL_TRUE); 00661 enabled_GL_CULL_FACE = (glIsEnabled (GL_CULL_FACE) == GL_TRUE); 00662 enabled_GL_POLYGON_OFFSET_FILL = (glIsEnabled (GL_POLYGON_OFFSET_FILL) == GL_TRUE); 00663 enabled_GL_LIGHTING = (glIsEnabled (GL_LIGHTING) == GL_TRUE); 00664 enabled_GL_ALPHA_TEST = (glIsEnabled (GL_ALPHA_TEST) == GL_TRUE); 00665 enabled_GL_TEXTURE_GEN_S = (glIsEnabled (GL_TEXTURE_GEN_S) == GL_TRUE); 00666 enabled_GL_TEXTURE_GEN_T = (glIsEnabled (GL_TEXTURE_GEN_T) == GL_TRUE); 00667 enabled_GL_TEXTURE_GEN_R = (glIsEnabled (GL_TEXTURE_GEN_R) == GL_TRUE); 00668 enabled_GL_TEXTURE_GEN_Q = (glIsEnabled (GL_TEXTURE_GEN_Q) == GL_TRUE); 00669 enabled_GL_FOG = (glIsEnabled (GL_FOG) == GL_TRUE); 00670 00671 memset (boundtexture.p, 0, numImageUnits * sizeof (GLuint)); 00672 currentUnit = 0; 00673 memset (activeUnit, 0, sizeof (activeUnit)); 00674 if (extmgr->CS_GL_ARB_multitexture) 00675 { 00676 for (i = numImageUnits; i-- > 0; ) 00677 { 00678 extmgr->glActiveTextureARB (GL_TEXTURE0_ARB + i); 00679 enabled_GL_TEXTURE_1D[i] = (glIsEnabled (GL_TEXTURE_1D) == GL_TRUE); 00680 enabled_GL_TEXTURE_2D[i] = (glIsEnabled (GL_TEXTURE_2D) == GL_TRUE); 00681 enabled_GL_TEXTURE_3D[i] = (glIsEnabled (GL_TEXTURE_3D) == GL_TRUE); 00682 enabled_GL_TEXTURE_CUBE_MAP[i] = (glIsEnabled (GL_TEXTURE_CUBE_MAP) == GL_TRUE); 00683 if (extmgr->CS_GL_ARB_texture_rectangle 00684 || extmgr->CS_GL_EXT_texture_rectangle 00685 || extmgr->CS_GL_NV_texture_rectangle) 00686 enabled_GL_TEXTURE_RECTANGLE_ARB[i] = (glIsEnabled (GL_TEXTURE_RECTANGLE_ARB) == GL_TRUE); 00687 else 00688 enabled_GL_TEXTURE_RECTANGLE_ARB[i] = false; 00689 } 00690 for (i = numTexCoords; i-- > 0; ) 00691 { 00692 extmgr->glClientActiveTextureARB (GL_TEXTURE0_ARB + i); 00693 enabled_GL_TEXTURE_COORD_ARRAY[i] = (glIsEnabled (GL_TEXTURE_COORD_ARRAY) == GL_TRUE); 00694 glGetIntegerv (GL_TEXTURE_COORD_ARRAY_SIZE, (GLint*)¶meter_tsize[i]); 00695 glGetIntegerv (GL_TEXTURE_COORD_ARRAY_STRIDE, (GLint*)¶meter_tstride[i]); 00696 glGetIntegerv (GL_TEXTURE_COORD_ARRAY_TYPE, (GLint*)¶meter_ttype[i]); 00697 glGetPointerv (GL_TEXTURE_COORD_ARRAY_POINTER, ¶meter_tpointer[i]); 00698 if (extmgr->CS_GL_ARB_vertex_buffer_object) 00699 glGetIntegerv (GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB, 00700 (GLint*)¶meter_tvbo[i]); 00701 } 00702 } 00703 else 00704 { 00705 enabled_GL_TEXTURE_1D[0] = (glIsEnabled (GL_TEXTURE_1D) == GL_TRUE); 00706 enabled_GL_TEXTURE_2D[0] = (glIsEnabled (GL_TEXTURE_2D) == GL_TRUE); 00707 enabled_GL_TEXTURE_3D[0] = (glIsEnabled (GL_TEXTURE_3D) == GL_TRUE); 00708 enabled_GL_TEXTURE_CUBE_MAP[0] = (glIsEnabled (GL_TEXTURE_CUBE_MAP) == GL_TRUE); 00709 enabled_GL_TEXTURE_COORD_ARRAY[0] = (glIsEnabled (GL_TEXTURE_COORD_ARRAY) == GL_TRUE); 00710 if (extmgr->CS_GL_ARB_texture_rectangle 00711 || extmgr->CS_GL_EXT_texture_rectangle 00712 || extmgr->CS_GL_NV_texture_rectangle) 00713 enabled_GL_TEXTURE_RECTANGLE_ARB[0] = (glIsEnabled (GL_TEXTURE_RECTANGLE_ARB) == GL_TRUE); 00714 else 00715 enabled_GL_TEXTURE_RECTANGLE_ARB[0] = false; 00716 glGetIntegerv (GL_TEXTURE_COORD_ARRAY_SIZE, (GLint*)¶meter_tsize[0]); 00717 glGetIntegerv (GL_TEXTURE_COORD_ARRAY_STRIDE, (GLint*)¶meter_tstride[0]); 00718 glGetIntegerv (GL_TEXTURE_COORD_ARRAY_TYPE, (GLint*)¶meter_ttype[0]); 00719 glGetPointerv (GL_TEXTURE_COORD_ARRAY_POINTER, ¶meter_tpointer[0]); 00720 if (extmgr->CS_GL_ARB_vertex_buffer_object) 00721 glGetIntegerv (GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB, 00722 (GLint*)¶meter_tvbo[0]); 00723 for (i = 1 ; i < numImageUnits; i++) 00724 { 00725 enabled_GL_TEXTURE_1D[i] = enabled_GL_TEXTURE_1D[0]; 00726 enabled_GL_TEXTURE_2D[i] = enabled_GL_TEXTURE_2D[0]; 00727 enabled_GL_TEXTURE_3D[i] = enabled_GL_TEXTURE_3D[0]; 00728 enabled_GL_TEXTURE_CUBE_MAP[i] = enabled_GL_TEXTURE_CUBE_MAP[0]; 00729 enabled_GL_TEXTURE_COORD_ARRAY[i] = enabled_GL_TEXTURE_COORD_ARRAY[0]; 00730 enabled_GL_TEXTURE_RECTANGLE_ARB[i] = enabled_GL_TEXTURE_RECTANGLE_ARB[0]; 00731 parameter_tsize[i] = parameter_tsize[0]; 00732 parameter_tstride[i] = parameter_tstride[0]; 00733 parameter_ttype[i] = parameter_ttype[0]; 00734 parameter_tpointer[i] = parameter_tpointer[0]; 00735 } 00736 } 00737 enabled_GL_SCISSOR_TEST = (glIsEnabled (GL_SCISSOR_TEST) == GL_TRUE); 00738 enabled_GL_VERTEX_ARRAY = (glIsEnabled (GL_VERTEX_ARRAY) == GL_TRUE); 00739 enabled_GL_COLOR_ARRAY = (glIsEnabled (GL_COLOR_ARRAY) == GL_TRUE); 00740 if (extmgr->CS_GL_EXT_secondary_color) 00741 enabled_GL_SECONDARY_COLOR_ARRAY_EXT = 00742 (glIsEnabled (GL_SECONDARY_COLOR_ARRAY_EXT) == GL_TRUE); 00743 else 00744 enabled_GL_SECONDARY_COLOR_ARRAY_EXT = false; 00745 enabled_GL_NORMAL_ARRAY = (glIsEnabled (GL_NORMAL_ARRAY) == GL_TRUE); 00746 00747 if (extmgr->CS_GL_ARB_vertex_program) 00748 enabled_GL_VERTEX_PROGRAM_POINT_SIZE_ARB = 00749 (glIsEnabled (GL_VERTEX_PROGRAM_POINT_SIZE_ARB) == GL_TRUE); 00750 else 00751 enabled_GL_VERTEX_PROGRAM_POINT_SIZE_ARB = false; 00752 if (extmgr->CS_GL_ARB_point_sprite) 00753 enabled_GL_POINT_SPRITE_ARB = 00754 (glIsEnabled (GL_POINT_SPRITE_ARB) == GL_TRUE); 00755 else 00756 enabled_GL_POINT_SPRITE_ARB = false; 00757 00758 memset (currentBufferID, 0, sizeof (currentBufferID)); 00759 { 00760 enum { extVBO = 1, extPBO = 2 }; 00761 static const GLenum requiredExt[boCount] = 00762 { extVBO, extVBO, extPBO, extPBO }; 00763 00764 int boExt = 0; 00765 if (extmgr->CS_GL_ARB_vertex_buffer_object) boExt |= extVBO; 00766 if (extmgr->CS_GL_ARB_pixel_buffer_object) boExt |= extPBO; 00767 for (int b = 0; b < boCount; b++) 00768 { 00769 if (requiredExt[b] & boExt) 00770 { 00771 static const GLenum localIndexToGLBufferBinding[boCount] = 00772 { GL_ARRAY_BUFFER_BINDING_ARB, GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB, 00773 GL_PIXEL_PACK_BUFFER_BINDING_ARB, GL_PIXEL_UNPACK_BUFFER_BINDING_ARB }; 00774 glGetIntegerv (localIndexToGLBufferBinding[b], 00775 (GLint*)&activeBufferID[b]); 00776 } 00777 } 00778 } 00779 00780 glGetIntegerv (GL_VERTEX_ARRAY_SIZE, (GLint*)¶meter_vsize); 00781 glGetIntegerv (GL_VERTEX_ARRAY_STRIDE, (GLint*)¶meter_vstride); 00782 glGetIntegerv (GL_VERTEX_ARRAY_TYPE, (GLint*)¶meter_vtype); 00783 glGetPointerv (GL_VERTEX_ARRAY_POINTER, ¶meter_vpointer); 00784 if (extmgr->CS_GL_ARB_vertex_buffer_object) 00785 glGetIntegerv (GL_VERTEX_ARRAY_BUFFER_BINDING_ARB, (GLint*)¶meter_vvbo); 00786 00787 glGetIntegerv (GL_NORMAL_ARRAY_STRIDE, (GLint*)¶meter_nstride); 00788 glGetIntegerv (GL_NORMAL_ARRAY_TYPE, (GLint*)¶meter_ntype); 00789 glGetPointerv (GL_NORMAL_ARRAY_POINTER, ¶meter_npointer); 00790 if (extmgr->CS_GL_ARB_vertex_buffer_object) 00791 glGetIntegerv (GL_NORMAL_ARRAY_BUFFER_BINDING_ARB, (GLint*)¶meter_nvbo); 00792 00793 glGetIntegerv (GL_COLOR_ARRAY_SIZE, (GLint*)¶meter_csize); 00794 glGetIntegerv (GL_COLOR_ARRAY_STRIDE, (GLint*)¶meter_cstride); 00795 glGetIntegerv (GL_COLOR_ARRAY_TYPE, (GLint*)¶meter_ctype); 00796 glGetPointerv (GL_COLOR_ARRAY_POINTER, ¶meter_cpointer); 00797 if (extmgr->CS_GL_ARB_vertex_buffer_object) 00798 glGetIntegerv (GL_COLOR_ARRAY_BUFFER_BINDING_ARB, (GLint*)¶meter_cvbo); 00799 00800 if (extmgr->CS_GL_EXT_secondary_color) 00801 { 00802 glGetIntegerv (GL_SECONDARY_COLOR_ARRAY_SIZE_EXT, 00803 (GLint*)¶meter_scsize); 00804 glGetIntegerv (GL_SECONDARY_COLOR_ARRAY_STRIDE_EXT, 00805 (GLint*)¶meter_scstride); 00806 glGetIntegerv (GL_SECONDARY_COLOR_ARRAY_TYPE_EXT, 00807 (GLint*)¶meter_sctype); 00808 glGetPointerv (GL_SECONDARY_COLOR_ARRAY_POINTER_EXT, 00809 ¶meter_scpointer); 00810 if (extmgr->CS_GL_ARB_vertex_buffer_object) 00811 glGetIntegerv (GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB, 00812 (GLint*)¶meter_scvbo); 00813 enabled_GL_COLOR_SUM_EXT = glIsEnabled (GL_COLOR_SUM_EXT) != GL_FALSE; 00814 } 00815 else 00816 { 00817 parameter_scsize = 0; 00818 parameter_scstride = 0; 00819 parameter_sctype = 0; 00820 parameter_scpointer = 0; 00821 enabled_GL_COLOR_SUM_EXT = false; 00822 } 00823 00824 glGetIntegerv (GL_UNPACK_ALIGNMENT, &pixelUnpackAlignment); 00825 GLint v; 00826 glGetIntegerv (GL_UNPACK_SWAP_BYTES, &v); 00827 pixelUnpackSwapBytes = v != 0; 00828 } 00829 }; 00830 00831 00842 class csGLStateCache 00843 { 00844 enum 00845 { 00846 texServer = 0, 00847 texClient = 1 00848 }; 00849 public: 00850 csGLExtensionManager* extmgr; 00851 csGLStateCacheContext* currentContext; 00852 00853 csGLStateCache (csGLExtensionManager* extmgr) 00854 { 00855 csGLStateCache::extmgr = extmgr; 00856 currentContext = 0; 00857 } 00858 00859 void SetContext (csGLStateCacheContext *context) 00860 { 00861 currentContext = context; 00862 } 00863 00864 // Standardized caches 00865 IMPLEMENT_CACHED_BOOL (GL_DEPTH_TEST) 00866 IMPLEMENT_CACHED_BOOL (GL_BLEND) 00867 IMPLEMENT_CACHED_BOOL (GL_DITHER) 00868 IMPLEMENT_CACHED_BOOL (GL_STENCIL_TEST) 00869 IMPLEMENT_CACHED_BOOL (GL_CULL_FACE) 00870 IMPLEMENT_CACHED_BOOL (GL_POLYGON_OFFSET_FILL) 00871 IMPLEMENT_CACHED_BOOL (GL_LIGHTING) 00872 IMPLEMENT_CACHED_BOOL (GL_ALPHA_TEST) 00873 IMPLEMENT_CACHED_BOOL (GL_SCISSOR_TEST) 00874 IMPLEMENT_CACHED_BOOL (GL_TEXTURE_GEN_S) 00875 IMPLEMENT_CACHED_BOOL (GL_TEXTURE_GEN_T) 00876 IMPLEMENT_CACHED_BOOL (GL_TEXTURE_GEN_R) 00877 IMPLEMENT_CACHED_BOOL (GL_TEXTURE_GEN_Q) 00878 IMPLEMENT_CACHED_BOOL (GL_FOG) 00879 IMPLEMENT_CACHED_BOOL (GL_COLOR_SUM_EXT) 00880 IMPLEMENT_CACHED_BOOL (GL_VERTEX_PROGRAM_POINT_SIZE_ARB) 00881 IMPLEMENT_CACHED_BOOL (GL_POINT_SPRITE_ARB) 00882 IMPLEMENT_CACHED_BOOL_CURRENTLAYER (GL_TEXTURE_1D) 00883 IMPLEMENT_CACHED_BOOL_CURRENTLAYER (GL_TEXTURE_2D) 00884 IMPLEMENT_CACHED_BOOL_CURRENTLAYER (GL_TEXTURE_3D) 00885 IMPLEMENT_CACHED_BOOL_CURRENTLAYER (GL_TEXTURE_CUBE_MAP) 00886 IMPLEMENT_CACHED_BOOL_CURRENTLAYER (GL_TEXTURE_RECTANGLE_ARB) 00887 IMPLEMENT_CACHED_PARAMETER_2 (glAlphaFunc, AlphaFunc, GLenum, alpha_func, GLclampf, alpha_ref) 00888 IMPLEMENT_CACHED_PARAMETER_1 (glCullFace, CullFace, GLenum, cull_mode) 00889 IMPLEMENT_CACHED_PARAMETER_1 (glDepthFunc, DepthFunc, GLenum, depth_func) 00890 IMPLEMENT_CACHED_PARAMETER_1 (glDepthMask, DepthMask, GLboolean, depth_mask) 00891 IMPLEMENT_CACHED_PARAMETER_1 (glShadeModel, ShadeModel, GLenum, shade_model) 00892 IMPLEMENT_CACHED_PARAMETER_3 (glStencilFunc, StencilFunc, GLenum, stencil_func, GLint, stencil_ref, GLuint, stencil_mask) 00893 IMPLEMENT_CACHED_PARAMETER_3 (glStencilOp, StencilOp, GLenum, stencil_fail, GLenum, stencil_zfail, GLenum, stencil_zpass) 00894 IMPLEMENT_CACHED_PARAMETER_1 (glStencilMask, StencilMask, GLuint, maskl) 00895 IMPLEMENT_CACHED_PARAMETER_4 (glColorMask, ColorMask, GLboolean, wmRed, \ 00896 GLboolean, wmGreen, GLboolean, wmBlue, GLboolean, wmAlpha) 00897 00898 IMPLEMENT_CACHED_CLIENT_STATE (GL_VERTEX_ARRAY) 00899 IMPLEMENT_CACHED_CLIENT_STATE (GL_COLOR_ARRAY) 00900 IMPLEMENT_CACHED_CLIENT_STATE (GL_SECONDARY_COLOR_ARRAY_EXT) 00901 IMPLEMENT_CACHED_CLIENT_STATE (GL_NORMAL_ARRAY) 00902 IMPLEMENT_CACHED_CLIENT_STATE_LAYER (GL_TEXTURE_COORD_ARRAY) 00903 00904 IMPLEMENT_CACHED_PARAMETER_1 (glMatrixMode, MatrixMode, GLenum, matrixMode) 00905 00906 IMPLEMENT_CACHED_PARAMETER_4_BUF (glVertexPointer, VertexPointer, GLint, vsize, 00907 GLenum, vtype, GLsizei, vstride, GLvoid*, vpointer, vvbo); 00908 IMPLEMENT_CACHED_PARAMETER_3_BUF (glNormalPointer, NormalPointer, GLenum, ntype, 00909 GLsizei, nstride, GLvoid*, npointer, nvbo); 00910 IMPLEMENT_CACHED_PARAMETER_4_BUF (glColorPointer, ColorPointer, GLint, csize, 00911 GLenum, ctype, GLsizei, cstride, GLvoid*, cpointer, cvbo); 00912 IMPLEMENT_CACHED_PARAMETER_4_BUF (extmgr->glSecondaryColorPointerEXT, 00913 SecondaryColorPointerExt, GLint, scsize, GLenum, sctype, GLsizei, scstride, 00914 GLvoid*, scpointer, scvbo); 00915 IMPLEMENT_CACHED_PARAMETER_4_BUF_LAYER (glTexCoordPointer, TexCoordPointer, GLint, tsize, 00916 GLenum, ttype, GLsizei, tstride, GLvoid*, tpointer, tvbo); 00917 00918 // Special caches 00919 void SetTexture (GLenum target, GLuint texture) 00920 { 00921 const int currentUnit = currentContext->currentUnit; 00922 if (texture != currentContext->boundtexture[currentUnit]) 00923 { 00924 ActivateTU (activateImage); 00925 currentContext->boundtexture[currentUnit] = texture; 00926 glBindTexture (target, texture); 00927 } 00928 } 00929 GLuint GetTexture (GLenum /*target*/) 00930 { 00931 const int currentUnit = currentContext->currentUnit; 00932 return currentContext->boundtexture[currentUnit]; 00933 } 00934 GLuint GetTexture (GLenum /*target*/, int unit) 00935 { 00936 return currentContext->boundtexture[unit]; 00937 } 00943 void SetCurrentTU (int unit) 00944 { 00945 currentContext->currentUnit = unit; 00946 } 00948 int GetCurrentTU () 00949 { 00950 return currentContext->currentUnit; 00951 } 00953 static const int activateTexCoord = 1 << texClient; 00955 static const int activateImage = 1 << texServer; 00957 static const int activateMatrix = 1 << texServer; 00959 static const int activateTexEnv = 1 << texServer; 00964 static const int activateTexGen = 1 << texServer; 00966 static const int activateTexEnable = 1 << texServer; 00974 void ActivateTU (uint usage) 00975 { 00976 int currentUnit = currentContext->currentUnit; 00977 for (int i = 0; i < 2; i++) 00978 { 00979 if (currentContext->activeUnit[i] != currentUnit) 00980 { 00981 GLuint tu = GL_TEXTURE0_ARB + currentUnit; 00982 if (usage & (1 << i)) 00983 { 00984 if (i == texClient) 00985 extmgr->glClientActiveTextureARB (tu); 00986 else 00987 extmgr->glActiveTextureARB (tu); 00988 currentContext->activeUnit[i] = currentUnit; 00989 } 00990 } 00991 } 00992 } 00993 00994 void ApplyBufferBinding (int index) 00995 { 00996 GLuint id = currentContext->currentBufferID[index]; 00997 if (currentContext->activeBufferID[index] != id) 00998 { 00999 extmgr->glBindBufferARB ( 01000 csGLStateCacheContext::CacheIndexToGLBufferTarget (index), id); 01001 currentContext->activeBufferID[index] = id; 01002 } 01003 } 01004 01010 void SetBufferARB (GLenum target, GLuint id, bool applyNow = false) 01011 { 01012 int index = csGLStateCacheContext::GLBufferTargetToCacheIndex (target); 01013 CS_ASSERT (index >= 0); 01014 currentContext->currentBufferID[index] = id; 01015 if (applyNow) ApplyBufferBinding (index); 01016 } 01017 01023 GLuint GetBufferARB (GLenum target) 01024 { 01025 int index = csGLStateCacheContext::GLBufferTargetToCacheIndex (target); 01026 CS_ASSERT (index >= 0); 01027 return currentContext->currentBufferID[index]; 01028 } 01029 01032 void SetBlendFunc (GLenum blend_source, GLenum blend_destination, 01033 bool forced = false) 01034 { 01035 if (forced 01036 || (blend_source != currentContext->blend_sourceRGB) 01037 || (blend_source != currentContext->blend_sourceA) 01038 || (blend_destination != currentContext->blend_destinationRGB) 01039 || (blend_destination != currentContext->blend_destinationA) 01040 || FORCE_STATE_CHANGE) 01041 { 01042 currentContext->blend_sourceRGB = blend_source; 01043 currentContext->blend_sourceA = blend_source; 01044 currentContext->blend_destinationRGB = blend_destination; 01045 currentContext->blend_destinationA = blend_destination; 01046 glBlendFunc (blend_source, blend_destination); 01047 } 01048 } 01049 void GetBlendFunc (GLenum& blend_source, GLenum& blend_destination) const 01050 { 01051 blend_source = currentContext->blend_sourceRGB; 01052 blend_destination = currentContext->blend_destinationRGB; 01053 } 01054 void SetBlendFuncSeparate (GLenum blend_sourceRGB, 01055 GLenum blend_destinationRGB, 01056 GLenum blend_sourceA, 01057 GLenum blend_destinationA, 01058 bool forced = false) 01059 { 01060 if (forced 01061 || (blend_sourceRGB != currentContext->blend_sourceRGB) 01062 || (blend_sourceA != currentContext->blend_sourceA) 01063 || (blend_destinationRGB != currentContext->blend_destinationRGB) 01064 || (blend_destinationA != currentContext->blend_destinationA) 01065 || FORCE_STATE_CHANGE) 01066 { 01067 currentContext->blend_sourceRGB = blend_sourceRGB; 01068 currentContext->blend_sourceA = blend_sourceA; 01069 currentContext->blend_destinationRGB = blend_destinationRGB; 01070 currentContext->blend_destinationA = blend_destinationA; 01071 extmgr->glBlendFuncSeparateEXT (blend_sourceRGB, blend_destinationRGB, 01072 blend_sourceA, blend_destinationA); 01073 } 01074 } 01075 void GetBlendFuncSeparate (GLenum& blend_sourceRGB, 01076 GLenum& blend_destinationRGB, 01077 GLenum& blend_sourceA, 01078 GLenum& blend_destinationA) const 01079 { 01080 blend_sourceRGB = currentContext->blend_sourceRGB; 01081 blend_destinationRGB = currentContext->blend_destinationRGB; 01082 blend_sourceA = currentContext->blend_sourceA; 01083 blend_destinationA = currentContext->blend_destinationA; 01084 } 01089 GLint GetPixelUnpackAlignment () 01090 { return currentContext->pixelUnpackAlignment; } 01091 void SetPixelUnpackAlignment (GLint alignment) 01092 { 01093 if (alignment != currentContext->pixelUnpackAlignment) 01094 { 01095 glPixelStorei (GL_UNPACK_ALIGNMENT, alignment); 01096 currentContext->pixelUnpackAlignment = alignment; 01097 } 01098 } 01099 bool GetPixelUnpackSwapBytes () 01100 { return currentContext->pixelUnpackSwapBytes; } 01101 void SetPixelUnpackSwapBytes (GLint swap) 01102 { 01103 bool swapAsbool = (swap != 0); 01104 if (swapAsbool != currentContext->pixelUnpackSwapBytes) 01105 { 01106 glPixelStorei (GL_UNPACK_SWAP_BYTES, (GLint)swap); 01107 currentContext->pixelUnpackSwapBytes = swapAsbool; 01108 } 01109 } 01112 01113 GLint GetNumImageUnits() const { return currentContext->numImageUnits; } 01115 GLint GetNumTexCoords() const { return currentContext->numTexCoords; } 01116 }; 01117 01118 #undef IMPLEMENT_CACHED_BOOL 01119 #undef IMPLEMENT_CACHED_BOOL_CURRENTLAYER 01120 #undef IMPLEMENT_CACHED_PARAMETER_1 01121 #undef IMPLEMENT_CACHED_PARAMETER_2 01122 #undef IMPLEMENT_CACHED_PARAMETER_3 01123 #undef IMPLEMENT_CACHED_PARAMETER_4 01124 #undef IMPLEMENT_CACHED_PARAMETER_1_LAYER 01125 #undef IMPLEMENT_CACHED_PARAMETER_2_LAYER 01126 #undef IMPLEMENT_CACHED_PARAMETER_3_LAYER 01127 #undef IMPLEMENT_CACHED_PARAMETER_4_LAYER 01128 #undef IMPLEMENT_CACHED_CLIENT_STATE 01129 #undef IMPLEMENT_CACHED_CLIENT_STATE_LAYER 01130 01131 #undef DECLARE_CACHED_BOOL 01132 #undef DECLARE_CACHED_BOOL_CURRENTLAYER 01133 #undef DECLARE_CACHED_PARAMETER_1 01134 #undef DECLARE_CACHED_PARAMETER_2 01135 #undef DECLARE_CACHED_PARAMETER_3 01136 #undef DECLARE_CACHED_PARAMETER_4 01137 #undef DECLARE_CACHED_PARAMETER_1_LAYER 01138 #undef DECLARE_CACHED_PARAMETER_2_LAYER 01139 #undef DECLARE_CACHED_PARAMETER_3_LAYER 01140 #undef DECLARE_CACHED_PARAMETER_4_LAYER 01141 #undef DECLARE_CACHED_CLIENT_STATE 01142 #undef DECLARE_CACHED_CLIENT_STATE_LAYER 01143 01144 #undef FORCE_STATE_CHANGE 01145 01148 #endif // __CS_GLSTATES_H__
Generated for Crystal Space 1.4.0 by doxygen 1.5.8