CrystalSpace

Public API Reference

Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

glstates.h

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 
00023 #if defined(CS_OPENGL_PATH)
00024 #include CS_HEADER_GLOBAL(CS_OPENGL_PATH,gl.h)
00025 #else
00026 #include <GL/gl.h>
00027 #endif
00028 
00029 #include "csextern_gl.h"
00030 #include "glextmanager.h"
00031 
00032 // Set to 'true' to force state changing commands. For debugging.
00033 #define FORCE_STATE_CHANGE                        false/*true*/
00034 
00035 #define DECLARE_CACHED_BOOL(name) \
00036   bool enabled_##name;
00037 
00038 #define IMPLEMENT_CACHED_BOOL(name) \
00039   void Enable_##name () \
00040   { \
00041     if (!currentContext->enabled_##name || FORCE_STATE_CHANGE) \
00042     { \
00043       currentContext->enabled_##name = true;  \
00044       glEnable (name); \
00045     } \
00046   } \
00047   void Disable_##name () \
00048   { \
00049     if (currentContext->enabled_##name || FORCE_STATE_CHANGE) { \
00050       currentContext->enabled_##name = false;  \
00051       glDisable (name); \
00052     } \
00053   } \
00054   bool IsEnabled_##name () const \
00055   { \
00056     return currentContext->enabled_##name; \
00057   }
00058 
00059 #define CS_GL_MAX_LAYER 16
00060 
00061 #define DECLARE_CACHED_BOOL_CURRENTLAYER(name) \
00062   bool enabled_##name[CS_GL_MAX_LAYER];
00063 
00064 #define IMPLEMENT_CACHED_BOOL_CURRENTLAYER(name) \
00065   void Enable_##name () \
00066   { \
00067     if (!currentContext->enabled_##name[currentContext->currentUnit] || FORCE_STATE_CHANGE) \
00068     { \
00069       ActivateTU (); \
00070       currentContext->enabled_##name[currentContext->currentUnit] = true;  \
00071       glEnable (name); \
00072     } \
00073   } \
00074   void Disable_##name () \
00075   { \
00076     if (currentContext->enabled_##name[currentContext->currentUnit] || FORCE_STATE_CHANGE) \
00077     { \
00078       ActivateTU (); \
00079       currentContext->enabled_##name[currentContext->currentUnit] = false;  \
00080       glDisable (name); \
00081     } \
00082   } \
00083   bool IsEnabled_##name () const \
00084   { \
00085     return currentContext->enabled_##name[currentContext->currentUnit]; \
00086   }
00087 
00088 #define DECLARE_CACHED_PARAMETER_1(func, name, type1, param1) \
00089   type1 parameter_##param1;
00090 
00091 #define IMPLEMENT_CACHED_PARAMETER_1(func, name, type1, param1) \
00092   void Set##name (type1 param1, bool forced = false) \
00093   { \
00094     if (forced || (param1 != currentContext->parameter_##param1) || FORCE_STATE_CHANGE) \
00095     { \
00096       currentContext->parameter_##param1 = param1;  \
00097       func (param1); \
00098     } \
00099   } \
00100   void Get##name (type1 & param1) const\
00101   { \
00102     param1 = currentContext->parameter_##param1;  \
00103   }
00104 
00105 #define DECLARE_CACHED_PARAMETER_2(func, name, type1, param1, type2, param2) \
00106   type1 parameter_##param1; \
00107   type2 parameter_##param2;
00108 
00109 #define IMPLEMENT_CACHED_PARAMETER_2(func, name, type1, param1, type2, param2) \
00110   void Set##name (type1 param1, type2 param2, bool forced = false) \
00111   { \
00112     if (forced || (param1 != currentContext->parameter_##param1) || \
00113         (param2 != currentContext->parameter_##param2) || FORCE_STATE_CHANGE) \
00114     { \
00115       currentContext->parameter_##param1 = param1;  \
00116       currentContext->parameter_##param2 = param2;  \
00117       func (param1, param2); \
00118     } \
00119   } \
00120   void Get##name (type1 & param1, type2 & param2) const\
00121   { \
00122     param1 = currentContext->parameter_##param1;  \
00123     param2 = currentContext->parameter_##param2;  \
00124   }
00125 
00126 #define DECLARE_CACHED_PARAMETER_3(func, name, type1, param1, type2, param2, type3, param3) \
00127   type1 parameter_##param1; \
00128   type2 parameter_##param2; \
00129   type3 parameter_##param3;
00130 
00131 #define IMPLEMENT_CACHED_PARAMETER_3(func, name, type1, param1, type2, param2, type3, param3) \
00132   void Set##name (type1 param1, type2 param2, type3 param3, bool forced = false) \
00133   { \
00134     if (forced || (param1 != currentContext->parameter_##param1) \
00135         || (param2 != currentContext->parameter_##param2) \
00136         || (param3 != currentContext->parameter_##param3) || FORCE_STATE_CHANGE) \
00137     { \
00138       currentContext->parameter_##param1 = param1;  \
00139       currentContext->parameter_##param2 = param2;  \
00140       currentContext->parameter_##param3 = param3;  \
00141       func (param1, param2, param3); \
00142     } \
00143   } \
00144   void Get##name (type1 &param1, type2 & param2, type3 & param3) const\
00145   { \
00146     param1 = currentContext->parameter_##param1;  \
00147     param2 = currentContext->parameter_##param2;  \
00148     param3 = currentContext->parameter_##param3;  \
00149   }
00150 
00151 #define DECLARE_CACHED_PARAMETER_4(func, name, type1, param1, \
00152   type2, param2, type3, param3, type4, param4) \
00153   type1 parameter_##param1; \
00154   type2 parameter_##param2; \
00155   type3 parameter_##param3; \
00156   type4 parameter_##param4;
00157 
00158 #define IMPLEMENT_CACHED_PARAMETER_4(func, name, type1, param1, \
00159     type2, param2, type3, param3, type4, param4) \
00160   void Set##name (type1 param1, type2 param2, type3 param3, type4 param4, \
00161     bool forced = false) \
00162   { \
00163     if (forced || (param1 != currentContext->parameter_##param1) || \
00164       (param2 != currentContext->parameter_##param2) || \
00165       (param3 != currentContext->parameter_##param3) || \
00166       (param4 != currentContext->parameter_##param4) || FORCE_STATE_CHANGE) \
00167     { \
00168       currentContext->parameter_##param1 = param1;  \
00169       currentContext->parameter_##param2 = param2;  \
00170       currentContext->parameter_##param3 = param3;  \
00171       currentContext->parameter_##param4 = param4;  \
00172       func (param1, param2, param3, param4); \
00173     } \
00174   } \
00175   void Get##name (type1 &param1, type2 & param2, type3 & param3, type4& param4) const\
00176   { \
00177     param1 = currentContext->parameter_##param1;  \
00178     param2 = currentContext->parameter_##param2;  \
00179     param3 = currentContext->parameter_##param3;  \
00180     param4 = currentContext->parameter_##param4;  \
00181   }
00182 
00183 #define DECLARE_CACHED_CLIENT_STATE(name)             \
00184   bool enabled_##name;
00185 
00186 #define IMPLEMENT_CACHED_CLIENT_STATE(name)           \
00187   void Enable_##name () \
00188   { \
00189     if (!currentContext->enabled_##name || FORCE_STATE_CHANGE) \
00190     { \
00191       currentContext->enabled_##name = true;  \
00192       glEnableClientState (name); \
00193     } \
00194   } \
00195   void Disable_##name () \
00196   { \
00197     if (currentContext->enabled_##name || FORCE_STATE_CHANGE) { \
00198       currentContext->enabled_##name = false;  \
00199       glDisableClientState (name); \
00200     } \
00201   } \
00202   bool IsEnabled_##name () const \
00203   { \
00204     return currentContext->enabled_##name; \
00205   }
00206 
00207 #define DECLARE_CACHED_CLIENT_STATE_LAYER(name)       \
00208   bool enabled_##name[CS_GL_MAX_LAYER];
00209 
00210 #define IMPLEMENT_CACHED_CLIENT_STATE_LAYER(name)             \
00211   void Enable_##name () \
00212   { \
00213     if (!currentContext->enabled_##name[currentContext->currentUnit] \
00214         || FORCE_STATE_CHANGE) \
00215     { \
00216       ActivateTU (); \
00217       currentContext->enabled_##name[currentContext->currentUnit] = true;  \
00218       glEnableClientState (name); \
00219     } \
00220   } \
00221   void Disable_##name () \
00222   { \
00223     if (currentContext->enabled_##name[currentContext->currentUnit] \
00224         || FORCE_STATE_CHANGE) { \
00225       ActivateTU (); \
00226       currentContext->enabled_##name[currentContext->currentUnit] = false;  \
00227       glDisableClientState (name); \
00228     } \
00229   } \
00230   bool IsEnabled_##name () const \
00231   { \
00232     return currentContext->enabled_##name[currentContext->currentUnit]; \
00233   }
00234 
00235 #define DECLARE_CACHED_PARAMETER_1_LAYER(func, name, type1, param1) \
00236   type1 parameter_##param1[CS_GL_MAX_LAYER];
00237 
00238 #define IMPLEMENT_CACHED_PARAMETER_1_LAYER(func, name, type1, param1) \
00239   void Set##name (type1 param1, bool forced = false) \
00240   { \
00241     if (forced || \
00242         (param1 != currentContext->parameter_##param1[currentContext->currentUnit] \
00243         || FORCE_STATE_CHANGE)) \
00244     { \
00245       ActivateTU (); \
00246       currentContext->parameter_##param1[currentContext->currentUnit] = param1;  \
00247       func (param1); \
00248     } \
00249   } \
00250   void Get##name (type1 &param1) const\
00251   { \
00252     param1 = currentContext->parameter_##param1[currentContext->currentUnit];  \
00253   }
00254 
00255 #define DECLARE_CACHED_PARAMETER_2_LAYER(func, name, type1, param1, \
00256   type2, param2) \
00257   type1 parameter_##param1[CS_GL_MAX_LAYER]; \
00258   type2 parameter_##param2[CS_GL_MAX_LAYER];
00259 
00260 #define IMPLEMENT_CACHED_PARAMETER_2_LAYER(func, name, type1, param1, \
00261   type2, param2) \
00262   void Set##name (type1 param1, type2 param2, bool forced = false) \
00263   { \
00264     if (forced || (param1 != currentContext->parameter_##param1[ \
00265                     currentContext->currentUnit]) || \
00266                   (param2 != currentContext->parameter_##param2[ \
00267                     currentContext->currentUnit]) \
00268                || FORCE_STATE_CHANGE) \
00269     { \
00270       ActivateTU (); \
00271       currentContext->parameter_##param1[currentContext->currentUnit] = param1;  \
00272       currentContext->parameter_##param2[currentContext->currentUnit] = param2;  \
00273       func (param1, param2); \
00274     } \
00275   } \
00276   void Get##name (type1 &param1, type2 & param2) const\
00277   { \
00278     param1 = currentContext->parameter_##param1[currentContext->currentUnit];  \
00279     param2 = currentContext->parameter_##param2[currentContext->currentUnit];  \
00280   }
00281 
00282 #define DECLARE_CACHED_PARAMETER_3_LAYER(func, name, type1, param1, \
00283   type2, param2, type3, param3) \
00284   type1 parameter_##param1[CS_GL_MAX_LAYER]; \
00285   type2 parameter_##param2[CS_GL_MAX_LAYER]; \
00286   type3 parameter_##param3[CS_GL_MAX_LAYER];
00287 
00288 
00289 #define IMPLEMENT_CACHED_PARAMETER_3_LAYER(func, name, type1, param1, \
00290   type2, param2, type3, param3) \
00291   void Set##name (type1 param1, type2 param2, type3 param3,\
00292     bool forced = false) \
00293   { \
00294     if (forced || (param1 != currentContext->parameter_##param1[ \
00295                     currentContext->currentUnit]) || \
00296                   (param2 != currentContext->parameter_##param2[ \
00297                     currentContext->currentUnit]) || \
00298                   (param3 != currentContext->parameter_##param3[ \
00299                     currentContext->currentUnit]) \
00300                || FORCE_STATE_CHANGE) \
00301     { \
00302       ActivateTU (); \
00303       currentContext->parameter_##param1[currentContext->currentUnit] = param1;  \
00304       currentContext->parameter_##param2[currentContext->currentUnit] = param2;  \
00305       currentContext->parameter_##param3[currentContext->currentUnit] = param3;  \
00306       func (param1, param2, param3); \
00307     } \
00308   } \
00309   void Get##name (type1 &param1, type2 & param2, type3 & param3) const\
00310   { \
00311     param1 = currentContext->parameter_##param1[currentContext->currentUnit];  \
00312     param2 = currentContext->parameter_##param2[currentContext->currentUnit];  \
00313     param3 = currentContext->parameter_##param3[currentContext->currentUnit];  \
00314   }
00315 
00316 
00317 #define DECLARE_CACHED_PARAMETER_4_LAYER(func, name, type1, param1, \
00318   type2, param2, type3, param3, type4, param4) \
00319   type1 parameter_##param1[CS_GL_MAX_LAYER]; \
00320   type2 parameter_##param2[CS_GL_MAX_LAYER]; \
00321   type3 parameter_##param3[CS_GL_MAX_LAYER]; \
00322   type4 parameter_##param4[CS_GL_MAX_LAYER];
00323 
00324 #define IMPLEMENT_CACHED_PARAMETER_4_LAYER(func, name, type1, param1, \
00325     type2, param2, type3, param3, type4, param4) \
00326   void Set##name (type1 param1, type2 param2, type3 param3, type4 param4, \
00327     bool forced = false) \
00328   { \
00329     if (forced || (param1 != currentContext->parameter_##param1[ \
00330                       currentContext->currentUnit]) || \
00331                   (param2 != currentContext->parameter_##param2[ \
00332                       currentContext->currentUnit]) || \
00333                   (param3 != currentContext->parameter_##param3[ \
00334                       currentContext->currentUnit]) || \
00335                   (param4 != currentContext->parameter_##param4[ \
00336                       currentContext->currentUnit]) \
00337               || FORCE_STATE_CHANGE) \
00338     { \
00339       ActivateTU (); \
00340       currentContext->parameter_##param1[currentContext->currentUnit] = param1;  \
00341       currentContext->parameter_##param2[currentContext->currentUnit] = param2;  \
00342       currentContext->parameter_##param3[currentContext->currentUnit] = param3;  \
00343       currentContext->parameter_##param4[currentContext->currentUnit] = param4;  \
00344       func (param1, param2, param3, param4); \
00345     } \
00346   } \
00347   void Get##name (type1 &param1, type2 & param2, type3 & param3, type4& param4) const\
00348   { \
00349     param1 = currentContext->parameter_##param1[currentContext->currentUnit];  \
00350     param2 = currentContext->parameter_##param2[currentContext->currentUnit];  \
00351     param3 = currentContext->parameter_##param3[currentContext->currentUnit];  \
00352     param4 = currentContext->parameter_##param4[currentContext->currentUnit];  \
00353   }
00354 
00355 
00356 CS_CSPLUGINCOMMON_GL_EXPORT class csGLStateCacheContext
00357 {
00358 public:
00359   csGLExtensionManager* extmgr;
00360 
00361   // Special caches
00362   GLuint boundtexture[CS_GL_MAX_LAYER]; // 32 max texture layers
00363   int currentUnit, activeUnit;
00364   GLuint currentBufferID, currentIndexID;
00365 
00366   // Standardized caches
00367   DECLARE_CACHED_BOOL (GL_DEPTH_TEST)
00368   DECLARE_CACHED_BOOL (GL_BLEND)
00369   DECLARE_CACHED_BOOL (GL_DITHER)
00370   DECLARE_CACHED_BOOL (GL_STENCIL_TEST)
00371   DECLARE_CACHED_BOOL (GL_CULL_FACE)
00372   DECLARE_CACHED_BOOL (GL_POLYGON_OFFSET_FILL)
00373   DECLARE_CACHED_BOOL (GL_LIGHTING)
00374   DECLARE_CACHED_BOOL (GL_ALPHA_TEST)
00375   DECLARE_CACHED_BOOL (GL_SCISSOR_TEST)
00376   DECLARE_CACHED_BOOL (GL_TEXTURE_GEN_S)
00377   DECLARE_CACHED_BOOL (GL_TEXTURE_GEN_T)
00378   DECLARE_CACHED_BOOL (GL_TEXTURE_GEN_R)
00379   DECLARE_CACHED_BOOL (GL_FOG)
00380   DECLARE_CACHED_BOOL_CURRENTLAYER (GL_TEXTURE_1D)
00381   DECLARE_CACHED_BOOL_CURRENTLAYER (GL_TEXTURE_2D)
00382   DECLARE_CACHED_BOOL_CURRENTLAYER (GL_TEXTURE_3D)
00383   DECLARE_CACHED_BOOL_CURRENTLAYER (GL_TEXTURE_CUBE_MAP)
00384   DECLARE_CACHED_BOOL_CURRENTLAYER (GL_TEXTURE_RECTANGLE_ARB)
00385   DECLARE_CACHED_PARAMETER_2 (glAlphaFunc, AlphaFunc, GLenum, alpha_func, GLclampf, alpha_ref)
00386   DECLARE_CACHED_PARAMETER_2 (glBlendFunc, BlendFunc, GLenum, blend_source, GLenum, blend_destination)
00387   DECLARE_CACHED_PARAMETER_1 (glCullFace, CullFace, GLenum, cull_mode)
00388   DECLARE_CACHED_PARAMETER_1 (glDepthFunc, DepthFunc, GLenum, depth_func)
00389   DECLARE_CACHED_PARAMETER_1 (glDepthMask, DepthMask, GLboolean, depth_mask)
00390   DECLARE_CACHED_PARAMETER_1 (glShadeModel, ShadeModel, GLenum, shade_model)
00391   DECLARE_CACHED_PARAMETER_3 (glStencilFunc, StencilFunc, GLenum, stencil_func, GLint, stencil_ref, GLuint, stencil_mask)
00392   DECLARE_CACHED_PARAMETER_3 (glStencilOp, StencilOp, GLenum, stencil_fail, GLenum, stencil_zfail, GLenum, stencil_zpass)
00393   DECLARE_CACHED_PARAMETER_1 (glStencilMask, StencilMask, GLuint, maskl)
00394   DECLARE_CACHED_PARAMETER_4 (glColorMask, ColorMask, GLboolean, wmRed, \
00395     GLboolean, wmGreen, GLboolean, wmBlue, GLboolean, wmAlpha)
00396 
00397   DECLARE_CACHED_CLIENT_STATE (GL_VERTEX_ARRAY)
00398   DECLARE_CACHED_CLIENT_STATE (GL_COLOR_ARRAY)
00399   DECLARE_CACHED_CLIENT_STATE (GL_NORMAL_ARRAY)
00400   DECLARE_CACHED_CLIENT_STATE_LAYER (GL_TEXTURE_COORD_ARRAY)
00401 
00402   DECLARE_CACHED_PARAMETER_1 (glMatrixMode, MatrixMode, GLenum, matrixMode)
00403   
00404   DECLARE_CACHED_PARAMETER_4 (glVertexPointer, VertexPointer, GLint, vsize,
00405     GLenum, vtype, GLsizei, vstride, GLvoid*, vpointer)
00406   DECLARE_CACHED_PARAMETER_3 (glNormalPointer, NormalPointer, GLenum, ntype,
00407     GLsizei, nstride, GLvoid*, npointer)
00408   DECLARE_CACHED_PARAMETER_4 (glColorPointer, ColorPointer, GLint, csize,
00409     GLenum, ctype, GLsizei, cstride, GLvoid*, cpointer)
00410   DECLARE_CACHED_PARAMETER_4_LAYER (glTexCoordPointer, TexCoordPointer, GLint, tsize,
00411     GLenum, ttype, GLsizei, tstride, GLvoid*, tpointer)
00412   
00413   csGLStateCacheContext (csGLExtensionManager* extmgr)
00414   {
00415     csGLStateCacheContext::extmgr = extmgr;
00416   }
00417 
00418 
00420   void InitCache()
00421   {
00422     int i;
00423     glGetIntegerv (GL_ALPHA_TEST_FUNC, (GLint*)&parameter_alpha_func);
00424     glGetFloatv (GL_ALPHA_TEST_REF, &parameter_alpha_ref);
00425     glGetIntegerv (GL_BLEND_SRC, (GLint*)&parameter_blend_source);
00426     glGetIntegerv (GL_BLEND_DST, (GLint*)&parameter_blend_destination);
00427     glGetIntegerv (GL_CULL_FACE_MODE, (GLint*)&parameter_cull_mode);
00428     glGetIntegerv (GL_DEPTH_FUNC, (GLint*)&parameter_depth_func);
00429     glGetBooleanv (GL_DEPTH_WRITEMASK, &parameter_depth_mask);
00430     glGetIntegerv (GL_SHADE_MODEL, (GLint*)&parameter_shade_model);
00431     glGetIntegerv (GL_STENCIL_BITS, (GLint*)&parameter_maskl);
00432     glGetIntegerv (GL_STENCIL_FUNC, (GLint*)&parameter_stencil_func);
00433     glGetIntegerv (GL_STENCIL_VALUE_MASK, (GLint*)&parameter_stencil_mask);
00434     glGetIntegerv (GL_STENCIL_REF, &parameter_stencil_ref);
00435     glGetIntegerv (GL_STENCIL_FAIL, (GLint*)&parameter_stencil_fail);
00436     glGetIntegerv (GL_STENCIL_PASS_DEPTH_FAIL, (GLint*)&parameter_stencil_zfail);
00437     glGetIntegerv (GL_STENCIL_PASS_DEPTH_PASS, (GLint*)&parameter_stencil_zpass);
00438     glGetIntegerv (GL_MATRIX_MODE, (GLint*)&parameter_matrixMode);
00439     GLboolean writemask[4];
00440     glGetBooleanv (GL_COLOR_WRITEMASK, writemask);
00441     parameter_wmRed = writemask[0];
00442     parameter_wmGreen = writemask[1];
00443     parameter_wmBlue = writemask[2];
00444     parameter_wmAlpha = writemask[3];
00445     enabled_GL_DEPTH_TEST = glIsEnabled (GL_DEPTH_TEST);
00446     enabled_GL_BLEND = glIsEnabled (GL_BLEND);
00447     enabled_GL_DITHER = glIsEnabled (GL_DITHER);
00448     enabled_GL_STENCIL_TEST = glIsEnabled (GL_STENCIL_TEST);
00449     enabled_GL_CULL_FACE = glIsEnabled (GL_CULL_FACE);
00450     enabled_GL_POLYGON_OFFSET_FILL = glIsEnabled (GL_POLYGON_OFFSET_FILL);
00451     enabled_GL_LIGHTING = glIsEnabled (GL_LIGHTING);
00452     enabled_GL_ALPHA_TEST = glIsEnabled (GL_ALPHA_TEST);
00453     enabled_GL_TEXTURE_GEN_S = glIsEnabled (GL_TEXTURE_GEN_S);
00454     enabled_GL_TEXTURE_GEN_T = glIsEnabled (GL_TEXTURE_GEN_T);
00455     enabled_GL_TEXTURE_GEN_R = glIsEnabled (GL_TEXTURE_GEN_R);
00456     enabled_GL_FOG = glIsEnabled (GL_FOG);
00457 
00458     if (extmgr->CS_GL_ARB_multitexture)
00459     {
00460       for (i = 0 ; i < CS_GL_MAX_LAYER; i++)
00461       {
00462         extmgr->glActiveTextureARB (GL_TEXTURE0_ARB + i);
00463         extmgr->glClientActiveTextureARB (GL_TEXTURE0_ARB + i);
00464         enabled_GL_TEXTURE_1D[i] = glIsEnabled (GL_TEXTURE_1D);
00465         enabled_GL_TEXTURE_2D[i] = glIsEnabled (GL_TEXTURE_2D);
00466         enabled_GL_TEXTURE_3D[i] = glIsEnabled (GL_TEXTURE_3D);
00467         enabled_GL_TEXTURE_CUBE_MAP[i] = glIsEnabled (GL_TEXTURE_CUBE_MAP);
00468         enabled_GL_TEXTURE_COORD_ARRAY[i] = glIsEnabled (GL_TEXTURE_COORD_ARRAY);
00469         if (extmgr->CS_GL_ARB_texture_rectangle
00470           || extmgr->CS_GL_EXT_texture_rectangle
00471           || extmgr->CS_GL_NV_texture_rectangle)
00472           enabled_GL_TEXTURE_RECTANGLE_ARB[i] = glIsEnabled (GL_TEXTURE_RECTANGLE_ARB);
00473         else
00474           enabled_GL_TEXTURE_RECTANGLE_ARB[i] = false;
00475         glGetIntegerv (GL_TEXTURE_COORD_ARRAY_SIZE, (GLint*)&parameter_tsize[i]);
00476         glGetIntegerv (GL_TEXTURE_COORD_ARRAY_STRIDE, (GLint*)&parameter_tstride[i]);
00477         glGetIntegerv (GL_TEXTURE_COORD_ARRAY_TYPE, (GLint*)&parameter_ttype[i]);
00478         glGetPointerv (GL_TEXTURE_COORD_ARRAY_POINTER, &parameter_tpointer[i]);
00479       }
00480     } 
00481     else 
00482     {
00483       enabled_GL_TEXTURE_1D[0] = glIsEnabled (GL_TEXTURE_1D);
00484       enabled_GL_TEXTURE_2D[0] = glIsEnabled (GL_TEXTURE_2D);
00485       enabled_GL_TEXTURE_3D[0] = glIsEnabled (GL_TEXTURE_3D);
00486       enabled_GL_TEXTURE_CUBE_MAP[0] = glIsEnabled (GL_TEXTURE_CUBE_MAP);
00487       enabled_GL_TEXTURE_COORD_ARRAY[0] = glIsEnabled (GL_TEXTURE_COORD_ARRAY);
00488         if (extmgr->CS_GL_ARB_texture_rectangle
00489           || extmgr->CS_GL_EXT_texture_rectangle
00490           || extmgr->CS_GL_NV_texture_rectangle)
00491           enabled_GL_TEXTURE_RECTANGLE_ARB[0] = glIsEnabled (GL_TEXTURE_RECTANGLE_ARB);
00492         else
00493           enabled_GL_TEXTURE_RECTANGLE_ARB[0] = false;
00494       glGetIntegerv (GL_TEXTURE_COORD_ARRAY_SIZE, (GLint*)&parameter_tsize[0]);
00495       glGetIntegerv (GL_TEXTURE_COORD_ARRAY_STRIDE, (GLint*)&parameter_tstride[0]);
00496       glGetIntegerv (GL_TEXTURE_COORD_ARRAY_TYPE, (GLint*)&parameter_ttype[0]);
00497       glGetPointerv (GL_TEXTURE_COORD_ARRAY_POINTER, &parameter_tpointer[0]);
00498       for (i = 1 ; i < CS_GL_MAX_LAYER; i++)
00499       {
00500         enabled_GL_TEXTURE_1D[i] = enabled_GL_TEXTURE_1D[0];
00501         enabled_GL_TEXTURE_2D[i] = enabled_GL_TEXTURE_2D[0];
00502         enabled_GL_TEXTURE_3D[i] = enabled_GL_TEXTURE_3D[0];
00503         enabled_GL_TEXTURE_CUBE_MAP[i] = enabled_GL_TEXTURE_CUBE_MAP[0];
00504         enabled_GL_TEXTURE_COORD_ARRAY[i] = enabled_GL_TEXTURE_COORD_ARRAY[0];
00505         enabled_GL_TEXTURE_RECTANGLE_ARB[i] = enabled_GL_TEXTURE_RECTANGLE_ARB[0];
00506       }
00507     }
00508     enabled_GL_SCISSOR_TEST = glIsEnabled (GL_SCISSOR_TEST);
00509     enabled_GL_VERTEX_ARRAY = glIsEnabled (GL_VERTEX_ARRAY);
00510     enabled_GL_COLOR_ARRAY = glIsEnabled (GL_COLOR_ARRAY);
00511     enabled_GL_NORMAL_ARRAY = glIsEnabled (GL_NORMAL_ARRAY);
00512 
00513     if (extmgr->CS_GL_ARB_multitexture)
00514     {
00515       extmgr->glActiveTextureARB (GL_TEXTURE0_ARB);
00516       extmgr->glClientActiveTextureARB (GL_TEXTURE0_ARB);
00517     }
00518     memset (boundtexture, 0, CS_GL_MAX_LAYER * sizeof (GLuint));
00519     currentUnit = 0;
00520     activeUnit = 0;
00521     currentBufferID = 0;
00522     currentIndexID = 0;
00523 
00524     glGetIntegerv (GL_VERTEX_ARRAY_SIZE, (GLint*)&parameter_vsize);
00525     glGetIntegerv (GL_VERTEX_ARRAY_STRIDE, (GLint*)&parameter_vstride);
00526     glGetIntegerv (GL_VERTEX_ARRAY_TYPE, (GLint*)&parameter_vtype);
00527     glGetPointerv (GL_VERTEX_ARRAY_POINTER, &parameter_vpointer);
00528 
00529     glGetIntegerv (GL_NORMAL_ARRAY_STRIDE, (GLint*)&parameter_nstride);
00530     glGetIntegerv (GL_NORMAL_ARRAY_TYPE, (GLint*)&parameter_ntype);
00531     glGetPointerv (GL_NORMAL_ARRAY_POINTER, &parameter_npointer);
00532 
00533     glGetIntegerv (GL_COLOR_ARRAY_SIZE, (GLint*)&parameter_csize);
00534     glGetIntegerv (GL_COLOR_ARRAY_STRIDE, (GLint*)&parameter_cstride);
00535     glGetIntegerv (GL_COLOR_ARRAY_TYPE, (GLint*)&parameter_ctype);
00536     glGetPointerv (GL_COLOR_ARRAY_POINTER, &parameter_cpointer);
00537   }
00538 };
00539 
00540 
00547 CS_CSPLUGINCOMMON_GL_EXPORT class csGLStateCache
00548 {
00549 public:
00550   csGLExtensionManager* extmgr;
00551   csGLStateCacheContext* currentContext;
00552 
00553   csGLStateCache (csGLExtensionManager* extmgr)
00554   {
00555     csGLStateCache::extmgr = extmgr;
00556     currentContext = 0;
00557   }
00558 
00559   void SetContext (csGLStateCacheContext *context)
00560   {
00561     currentContext = context;
00562   }
00563 
00564   // Standardized caches
00565   IMPLEMENT_CACHED_BOOL (GL_DEPTH_TEST)
00566   IMPLEMENT_CACHED_BOOL (GL_BLEND)
00567   IMPLEMENT_CACHED_BOOL (GL_DITHER)
00568   IMPLEMENT_CACHED_BOOL (GL_STENCIL_TEST)
00569   IMPLEMENT_CACHED_BOOL (GL_CULL_FACE)
00570   IMPLEMENT_CACHED_BOOL (GL_POLYGON_OFFSET_FILL)
00571   IMPLEMENT_CACHED_BOOL (GL_LIGHTING)
00572   IMPLEMENT_CACHED_BOOL (GL_ALPHA_TEST)
00573   IMPLEMENT_CACHED_BOOL (GL_SCISSOR_TEST)
00574   IMPLEMENT_CACHED_BOOL (GL_TEXTURE_GEN_S)
00575   IMPLEMENT_CACHED_BOOL (GL_TEXTURE_GEN_T)
00576   IMPLEMENT_CACHED_BOOL (GL_TEXTURE_GEN_R)
00577   IMPLEMENT_CACHED_BOOL (GL_FOG)
00578   IMPLEMENT_CACHED_BOOL_CURRENTLAYER (GL_TEXTURE_1D)
00579   IMPLEMENT_CACHED_BOOL_CURRENTLAYER (GL_TEXTURE_2D)
00580   IMPLEMENT_CACHED_BOOL_CURRENTLAYER (GL_TEXTURE_3D)
00581   IMPLEMENT_CACHED_BOOL_CURRENTLAYER (GL_TEXTURE_CUBE_MAP)
00582   IMPLEMENT_CACHED_BOOL_CURRENTLAYER (GL_TEXTURE_RECTANGLE_ARB)
00583   IMPLEMENT_CACHED_PARAMETER_2 (glAlphaFunc, AlphaFunc, GLenum, alpha_func, GLclampf, alpha_ref)
00584   IMPLEMENT_CACHED_PARAMETER_2 (glBlendFunc, BlendFunc, GLenum, blend_source, GLenum, blend_destination)
00585   IMPLEMENT_CACHED_PARAMETER_1 (glCullFace, CullFace, GLenum, cull_mode)
00586   IMPLEMENT_CACHED_PARAMETER_1 (glDepthFunc, DepthFunc, GLenum, depth_func)
00587   IMPLEMENT_CACHED_PARAMETER_1 (glDepthMask, DepthMask, GLboolean, depth_mask)
00588   IMPLEMENT_CACHED_PARAMETER_1 (glShadeModel, ShadeModel, GLenum, shade_model)
00589   IMPLEMENT_CACHED_PARAMETER_3 (glStencilFunc, StencilFunc, GLenum, stencil_func, GLint, stencil_ref, GLuint, stencil_mask)
00590   IMPLEMENT_CACHED_PARAMETER_3 (glStencilOp, StencilOp, GLenum, stencil_fail, GLenum, stencil_zfail, GLenum, stencil_zpass)
00591   IMPLEMENT_CACHED_PARAMETER_1 (glStencilMask, StencilMask, GLuint, maskl)
00592   IMPLEMENT_CACHED_PARAMETER_4 (glColorMask, ColorMask, GLboolean, wmRed, \
00593     GLboolean, wmGreen, GLboolean, wmBlue, GLboolean, wmAlpha)
00594 
00595   IMPLEMENT_CACHED_CLIENT_STATE (GL_VERTEX_ARRAY)
00596   IMPLEMENT_CACHED_CLIENT_STATE (GL_COLOR_ARRAY)
00597   IMPLEMENT_CACHED_CLIENT_STATE (GL_NORMAL_ARRAY)
00598   IMPLEMENT_CACHED_CLIENT_STATE_LAYER (GL_TEXTURE_COORD_ARRAY)
00599 
00600   IMPLEMENT_CACHED_PARAMETER_1 (glMatrixMode, MatrixMode, GLenum, matrixMode)
00601   
00602   IMPLEMENT_CACHED_PARAMETER_4 (glVertexPointer, VertexPointer, GLint, vsize,
00603     GLenum, vtype, GLsizei, vstride, GLvoid*, vpointer);
00604   IMPLEMENT_CACHED_PARAMETER_3 (glNormalPointer, NormalPointer, GLenum, ntype,
00605     GLsizei, nstride, GLvoid*, npointer);
00606   IMPLEMENT_CACHED_PARAMETER_4 (glColorPointer, ColorPointer, GLint, csize,
00607     GLenum, ctype, GLsizei, cstride, GLvoid*, cpointer);
00608   IMPLEMENT_CACHED_PARAMETER_4_LAYER (glTexCoordPointer, TexCoordPointer, GLint, tsize,
00609     GLenum, ttype, GLsizei, tstride, GLvoid*, tpointer);
00610   
00611   // Special caches
00612   void SetTexture (GLenum target, GLuint texture)
00613   {
00614     if (texture != currentContext->boundtexture[currentContext->currentUnit])
00615     {
00616       ActivateTU ();
00617       currentContext->boundtexture[currentContext->currentUnit] = texture;
00618       glBindTexture (target, texture);
00619     }
00620   }
00621   GLuint GetTexture (GLenum /*target*/)
00622   {
00623     return currentContext->boundtexture[currentContext->currentUnit];
00624   }
00625   GLuint GetTexture (GLenum /*target*/, int unit)
00626   {
00627     return currentContext->boundtexture[unit];
00628   }
00633   void SetActiveTU (int unit)
00634   {
00635     currentContext->currentUnit = unit;   
00636   }
00637   int GetActiveTU ()
00638   {
00639     return currentContext->currentUnit;
00640   }
00641   void ActivateTU ()
00642   {
00643     if (currentContext->activeUnit != currentContext->currentUnit && extmgr->CS_GL_ARB_multitexture)
00644     {
00645       extmgr->glActiveTextureARB (GL_TEXTURE0_ARB + currentContext->currentUnit);
00646       extmgr->glClientActiveTextureARB (GL_TEXTURE0_ARB + currentContext->currentUnit);
00647     }
00648     currentContext->activeUnit = currentContext->currentUnit;
00649   }
00650 
00651   //VBO buffers
00652   void SetBufferARB (GLenum target, GLuint id)
00653   {
00654     if (target == GL_ELEMENT_ARRAY_BUFFER_ARB)
00655     {
00656       if (id != currentContext->currentIndexID)
00657       {
00658         extmgr->glBindBufferARB (target, id);
00659         currentContext->currentIndexID = id;
00660       }
00661     } 
00662     else 
00663     {
00664       if (id != currentContext->currentBufferID)
00665       {
00666         extmgr->glBindBufferARB (target, id);
00667         currentContext->currentBufferID = id;
00668         currentContext->parameter_vpointer = (GLvoid*)~0; //invalidate vertexpointer
00669         currentContext->parameter_npointer = (GLvoid*)~0; //invalidate vertexpointer
00670         currentContext->parameter_cpointer = (GLvoid*)~0; //invalidate vertexpointer
00671         memset(&currentContext->parameter_tpointer, ~0, sizeof(GLvoid*)*CS_GL_MAX_LAYER);
00672       }
00673     }
00674   }
00675 
00676   GLuint GetBufferARB (GLenum target)
00677   {
00678     if (target == GL_ELEMENT_ARRAY_BUFFER_ARB)
00679     {
00680       return currentContext->currentIndexID;
00681     } 
00682     else 
00683     {
00684       return currentContext->currentBufferID;
00685     }
00686   }
00687 };
00688 
00689 #undef IMPLEMENT_CACHED_BOOL
00690 #undef IMPLEMENT_CACHED_BOOL_CURRENTLAYER
00691 #undef IMPLEMENT_CACHED_PARAMETER_1
00692 #undef IMPLEMENT_CACHED_PARAMETER_2
00693 #undef IMPLEMENT_CACHED_PARAMETER_3
00694 #undef IMPLEMENT_CACHED_PARAMETER_4
00695 #undef IMPLEMENT_CACHED_PARAMETER_1_LAYER
00696 #undef IMPLEMENT_CACHED_PARAMETER_2_LAYER
00697 #undef IMPLEMENT_CACHED_PARAMETER_3_LAYER
00698 #undef IMPLEMENT_CACHED_PARAMETER_4_LAYER
00699 #undef IMPLEMENT_CACHED_CLIENT_STATE
00700 #undef IMPLEMENT_CACHED_CLIENT_STATE_LAYER
00701 
00702 #undef DECLARE_CACHED_BOOL
00703 #undef DECLARE_CACHED_BOOL_CURRENTLAYER
00704 #undef DECLARE_CACHED_PARAMETER_1
00705 #undef DECLARE_CACHED_PARAMETER_2
00706 #undef DECLARE_CACHED_PARAMETER_3
00707 #undef DECLARE_CACHED_PARAMETER_4
00708 #undef DECLARE_CACHED_PARAMETER_1_LAYER
00709 #undef DECLARE_CACHED_PARAMETER_2_LAYER
00710 #undef DECLARE_CACHED_PARAMETER_3_LAYER
00711 #undef DECLARE_CACHED_PARAMETER_4_LAYER
00712 #undef DECLARE_CACHED_CLIENT_STATE
00713 #undef DECLARE_CACHED_CLIENT_STATE_LAYER
00714 
00715 #undef FORCE_STATE_CHANGE
00716 
00717 #endif // __CS_GLSTATES_H__

Generated for Crystal Space by doxygen 1.4.4