Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Rendering/vtkOpenGLStateCache.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkOpenGLStateCache.h,v $
00005   Language:  C++
00006 
00007 Copyright (c) 1993-2001 Ken Martin, Will Schroeder, Bill Lorensen 
00008 All rights reserved.
00009 
00010 Redistribution and use in source and binary forms, with or without
00011 modification, are permitted provided that the following conditions are met:
00012 
00013  * Redistributions of source code must retain the above copyright notice,
00014    this list of conditions and the following disclaimer.
00015 
00016  * Redistributions in binary form must reproduce the above copyright notice,
00017    this list of conditions and the following disclaimer in the documentation
00018    and/or other materials provided with the distribution.
00019 
00020  * Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names
00021    of any contributors may be used to endorse or promote products derived
00022    from this software without specific prior written permission.
00023 
00024  * Modified source versions must be plainly marked as such, and must not be
00025    misrepresented as being the original software.
00026 
00027 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00028 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00029 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00030 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
00031 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00032 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00033 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00034 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00035 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00036 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037 
00038 =========================================================================*/
00039 //*************************************************************************
00040 /*
00041   GlStateCache_Cache============================================
00042   This simply checks for redundancies in state-change requests and
00043   only calls the real OpenGL call if there has in fact been a change.
00044   This cannot, however, fix problems with the ordering of calls.
00045 */
00046 
00047 #ifndef VTK_IMPLEMENT_MESA_CXX
00048 #ifdef __APPLE__
00049 #include <OpenGL/gl.h>
00050 #else
00051 #include <GL/gl.h>
00052 #endif
00053 #endif
00054 
00055 #define vtkOpenGLCall_glEnable vtkOpenGLStateCache::CurrentGLCache->glEnable
00056 #define vtkOpenGLCall_glDisable vtkOpenGLStateCache::CurrentGLCache->glDisable
00057 #define vtkOpenGLCall_glAlphaFunc vtkOpenGLStateCache::CurrentGLCache->glAlphaFunc
00058 #define vtkOpenGLCall_glBlendFunc vtkOpenGLStateCache::CurrentGLCache->glBlendFunc
00059 #define vtkOpenGLCall_glDepthFunc vtkOpenGLStateCache::CurrentGLCache->glDepthFunc
00060 #define vtkOpenGLCall_glTexEnvf vtkOpenGLStateCache::CurrentGLCache->glTexEnvf
00061 #define vtkOpenGLCall_glLightModeli vtkOpenGLStateCache::CurrentGLCache->glLightModeli
00062 #define vtkOpenGLCall_glLightModelfv vtkOpenGLStateCache::CurrentGLCache->glLightMOdelfv
00063 #define vtkOpenGLCall_glLightfv vtkOpenGLStateCache::CurrentGLCache->glLightfv
00064 #define vtkOpenGLCall_glLightf vtkOpenGLStateCache::CurrentGLCache->glLightf
00065 #define vtkOpenGLCall_glLighti vtkOpenGLStateCache::CurrentGLCache->glLighti
00066 #define vtkOpenGLCall_glMaterialfv vtkOpenGLStateCache::CurrentGLCache->glMaterialfv
00067 #define vtkOpenGLCall_glShadeModel vtkOpenGLStateCache::CurrentGLCache->glShadeModel
00068 #define vtkOpenGLCall_glClearColor vtkOpenGLStateCache::CurrentGLCache->glClearColor
00069 #define vtkOpenGLCall_glClearDepth vtkOpenGLStateCache::CurrentGLCache->glClearDepth
00070 #define vtkOpenGLCall_glDepthMask vtkOpenGLStateCache::CurrentGLCache->glDepthMask
00071 #define vtkOpenGLCall_glCullFace vtkOpenGLStateCache::CurrentGLCache->glCullFace
00072 #define vtkOpenGLCall_glClear vtkOpenGLStateCache::CurrentGLCache->glClear
00073 #define vtkOpenGLCall_glDrawBuffer vtkOpenGLStateCache::CurrentGLCache->glDrawBuffer
00074 #define vtkOpenGLCall_glMatrixMode vtkOpenGLStateCache::CurrentGLCache->glMatrixMode
00075 #define vtkOpenGLCall_glViewport vtkOpenGLStateCache::CurrentGLCache->glViewport
00076 #define vtkOpenGLCall_glScissor vtkOpenGLStateCache::CurrentGLCache->glScissor
00077 #define vtkOpenGLCall_glClipPlane vtkOpenGLStateCache::CurrentGLCache->glClipPlane
00078 #define vtkOpenGLCall_glColorMaterial vtkOpenGLStateCache::CurrentGLCache->glColorMaterial
00079 #define vtkOpenGLCall_glPointSize vtkOpenGLStateCache::CurrentGLCache->glPointSize
00080 #define vtkOpenGLCall_glLineWidth vtkOpenGLStateCache::CurrentGLCache->glLineWidth
00081 #define vtkOpenGLCall_glLineStipple vtkOpenGLStateCache::CurrentGLCache->glLineStipple
00082 #define vtkOpenGLCall_glDepthRange vtkOpenGLStateCache::CurrentGLCache->glDepthRange
00083 #define vtkOpenGLCall_glPolygonOffset vtkOpenGLStateCache::CurrentGLCache->glPolygonOffset
00084 
00085 #define vtkOpenGLCall_glPushMatrix glPushMatrix
00086 #define vtkOpenGLCall_glPopMatrix glPopMatrix
00087 #define vtkOpenGLCall_glMultMatrixd glMultMatrixd
00088 #define vtkOpenGLCall_glLoadMatrixd glLoadMatrixd
00089 #define vtkOpenGLCall_glLoadIdentity glLoadIdentity
00090 #define vtkOpenGLCall_glSelectBuffer glSelectBuffer
00091 #define vtkOpenGLCall_glRenderMode glRenderMode
00092 #define vtkOpenGLCall_glInitNames glInitNames
00093 #define vtkOpenGLCall_glPushName glPushName
00094 #define vtkOpenGLCall_glLoadName glLoadName
00095 #define vtkOpenGLCall_glGetIntegerv glGetIntegerv
00096 #define vtkOpenGLCall_glIsTexture glIsTexture
00097 #define vtkOpenGLCall_glDeleteTextures glDeleteTexture
00098 #define vtkOpenGLCall_glGenTextures glGenTextures
00099 #define vtkOpenGLCall_glBindTexture glBindTexture
00100 #define vtkOpenGLCall_glTexParameterf glTextParameterf
00101 #define vtkOpenGLCall_glTexCoord2fv glTexCoord2fv
00102 #define vtkOpenGLCall_glVertex3fv glVertex3fv
00103 #define vtkOpenGLCall_glNormal3fv glNormal3fv
00104 #define vtkOpenGLCall_glColor3f glColor3f
00105 #define vtkOpenGLCall_glColor4ubv glColor4ubv
00106 #define vtkOpenGLCall_glColor4fv glColor4fv
00107 #define vtkOpenGLCall_glBegin glBegin
00108 #define vtkOpenGLCall_glEnd glEnd
00109 #define vtkOpenGLCall_glTexImage2D glTextImage2D
00110 #define vtkOpenGLCall_glDeleteLists glDeleteLists
00111 #define vtkOpenGLCall_glIsList glIsList
00112 #define vtkOpenGLCall_glGenLists glGenLists
00113 #define vtkOpenGLCall_glCallList glCallList
00114 #define vtkOpenGLCall_glReadBuffer glReadBuffer
00115 #define vtkOpenGLCall_glPixelStorei glPixelStorei
00116 #define vtkOpenGLCall_glReadPixels glReadPixels
00117 #define vtkOpenGLCall_glRasterPos3f glRasterPos3f
00118 #define vtkOpenGLCall_glDrawPixels glDrawPixels
00119 #define vtkOpenGLCall_glRasterPos2f glRasterPos2f
00120 #define vtkOpenGLCall_glNewList glNewList
00121 #define vtkOpenGLCall_glEndList glEndList
00122 
00123 class vtkOpenGLStateCache  
00124 {
00125 public:
00126   static vtkOpenGLStateCache *CurrentGLCache; // recursive definition
00127 
00128   vtkOpenGLStateCache(); // set all members to initial values
00129   ~vtkOpenGLStateCache(); // delete any dynamic objects
00130   void Initialize();
00131 
00132   // GL_BLEND         = 0x0BE2
00133   // GL_POINT_SMOOTH  = 0x0B10
00134   // GL_LINE_SMOOTH   = 0x0B20
00135   // GL_POLYGON_SMOOTH= 0x0B41
00136   // GL_DEPTH_TEST    = 0x0B71
00137   // GL_ALPHA_TEST    = 0x0BC0
00138   // GL_TEXTURE_2D    = 0x0DE1
00139   // GL_CLIP_PLANE0+i = 0x3000
00140   // GL_LIGHTING      = 0x0B50
00141   // GL_COLOR_MATERIAL= 0x0B57
00142   // GL_NORMALIZE     = 0x0BA1
00143   // GL_CULL_FACE     = 0x0B44
00144   // GL_SCISSOR_TEST  = 0x0C11
00145   // GL_POLYGON_OFFSET_FILL = 0x8037
00146   // GL_LINE_STIPPLE  = 0x0B24
00147   // GL_LIGHT+i       = 0x4000
00148   char Enable_buckets[0xDE1-0xB10+1]; // 0xB10-0xDE1
00149   char Enable_GL_LIGHT_buckets[8]; // 0x4000 + i (0<i<8)
00150   char Enable_GL_CLIP_PLANE_buckets[8]; // 0x8000 + i (0<i<8)
00151   /* Need to have special handling for disabling and enabling the 
00152      GL_LIGHT's because they are disabling too many lights!
00153      need to propagate in how many lights are actually *on*
00154      and only apply the op to them.
00155    */
00156   inline void glEnable(GLenum e) 
00157     {
00158       register int ex;
00159       register char *val=0;
00160       if(e&0x4000)
00161         {
00162         ex=e-0x4000;
00163         if(ex<8) {val=Enable_GL_LIGHT_buckets+ex; }
00164         }    
00165       else 
00166         {
00167         if(e&0x8000)
00168           {
00169           ex=e-0x8000;
00170           if(ex<8) { val=Enable_GL_CLIP_PLANE_buckets+ex; }
00171           }
00172         else 
00173           {
00174           if(e>=0xB10 && e<=0xDE1)
00175             {
00176             ex=e-0xB10;
00177             val=Enable_buckets+ex;
00178             }
00179           else
00180             {
00181             printf("Error: glEnable of 0x%X failed\n",e);
00182             }
00183           }
00184         }
00185       if(val && *val!=1)
00186         {
00187         *val=1;
00188         ::glEnable(e);
00189         }
00190     }
00191   inline void glDisable(GLenum e) 
00192     {
00193       register int ex;
00194       register char *val=0;
00195       if(e&0x4000)
00196         {
00197         ex=e-0x4000;
00198         if(ex<8) { val=Enable_GL_LIGHT_buckets+ex; }
00199         }    
00200       else
00201         {
00202         if(e&0x8000)
00203           {
00204           ex=e-0x8000;
00205           if(ex<8) { val=Enable_GL_CLIP_PLANE_buckets+ex; }
00206           }
00207         else 
00208           {
00209           if(e>=0xB10 && e<=0xDE1)
00210             {
00211             ex=e-0xB10;
00212             val=Enable_buckets+ex;
00213             }
00214           else
00215             {
00216             printf("Error: glEnable of 0x%X failed\n",e);
00217             }
00218           }
00219         }
00220       if(val && *val!=0)
00221         {
00222         *val=0;
00223         ::glDisable(e);
00224         }
00225     }
00226   
00227   // GL_GREATER = 0x0204, (GLclampf) 0
00228   GLclampf AlphaFunc_bucket;
00229   inline void glAlphaFunc(GLenum e,GLclampf cf) 
00230     {
00231       if(e==GL_GREATER && cf!=AlphaFunc_bucket)
00232         {
00233         AlphaFunc_bucket=cf;
00234         ::glAlphaFunc(e,cf);
00235         }
00236     }
00237   
00238   // GL_SRC_ALPHA = 0x0302, GL_ONE_MINUS_SRC_ALPHA = 0x0303
00239   GLenum BlendFunc_bucket; // multibucket if any other blendfunc is used
00240   inline void glBlendFunc(GLenum e,GLenum e1) 
00241     {
00242       if(e==GL_SRC_ALPHA && e1!=BlendFunc_bucket)
00243         {
00244         BlendFunc_bucket=e1;
00245         ::glBlendFunc(e,e1);
00246         }
00247     }
00248   
00249   // GL_GREATER = 0x0204
00250   // GL_LESS    = 0x0201
00251   // GL_LEQUAL  = 0x0203
00252   GLenum DepthFunc_bucket;
00253   inline void glDepthFunc(GLenum e) 
00254     {
00255       if(e!=DepthFunc_bucket)
00256         {
00257         DepthFunc_bucket=e;
00258         ::glDepthFunc(e);
00259         }
00260     }
00261   
00262   // GL_TEXTURE_ENV = 0x2300, GL_TEXTURE_ENV_MODE = 0x2200, GL_MODULATE = 0x2100
00263   GLfloat TexEnvf_MODE_bucket; // total kludge right now
00264   inline void glTexEnvf(GLenum e,GLenum e1,GLfloat f) 
00265     {
00266       if(e==GL_TEXTURE_ENV && e1==GL_TEXTURE_ENV_MODE)
00267         {
00268         if(f!=TexEnvf_MODE_bucket)
00269           {
00270           TexEnvf_MODE_bucket=f;
00271           ::glTexEnvf(e,e1,f);
00272           }
00273         }
00274     }
00275   
00276   // GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE/FALSE
00277   // GL_LIGHT_MODEL_TWO_SIDE, 0
00278   GLint LightModeli_LIGHT_MODEL_TWO_SIDE_bucket; // shoudld check other modes
00279   inline void glLightModeli(GLenum e,GLint i) 
00280     {
00281       if(e==GL_LIGHT_MODEL_TWO_SIDE && i!=LightModeli_LIGHT_MODEL_TWO_SIDE_bucket){
00282       LightModeli_LIGHT_MODEL_TWO_SIDE_bucket=i;
00283       ::glLightModeli(e,i);
00284       }
00285     }
00286   
00287   // GL_LIGHT_MODEL_AMBIENT, fvect(amb color), A=1.0
00288   // GL_LIGHT_MODEL_AMBIENT = 0x0B53
00289   GLfloat LightModelfv_LIGHT_MODEL_AMBIENT_bucket[3];
00290   inline void glLightModelfv(GLenum e,GLfloat *fv) 
00291     {
00292       if(e==GL_LIGHT_MODEL_AMBIENT && 
00293          (fv[0]!=LightModelfv_LIGHT_MODEL_AMBIENT_bucket[0] ||
00294           fv[1]!=LightModelfv_LIGHT_MODEL_AMBIENT_bucket[1] ||
00295           fv[2]!=LightModelfv_LIGHT_MODEL_AMBIENT_bucket[2])){
00296       fv[0]=LightModelfv_LIGHT_MODEL_AMBIENT_bucket[0];
00297       fv[1]=LightModelfv_LIGHT_MODEL_AMBIENT_bucket[1];
00298       fv[2]=LightModelfv_LIGHT_MODEL_AMBIENT_bucket[2]; 
00299       ::glLightModelfv(e,fv);
00300       }
00301     }
00302   
00303   // light=GL_LIGHT index
00304   // pname= lighting type
00305   //   GL_DIFFUSE        = 0x1201
00306   //   GL_SPECULAR       = 0x1202
00307   //   GL_POSITION       = 0x1203
00308   //   GL_SPOT_DIRECTION = 0x1204
00309   GLfloat Lightfv_buckets[8*4*8];
00310   inline void glLightfv( GLenum light, GLenum pname, const GLfloat *params) 
00311     {
00312       register GLfloat *val = Lightfv_buckets + ((((int)(pname-0x1201))|((int)(light-GL_LIGHT0)<<3))<<2);
00313       if(params[0]!=val[0] ||
00314          params[1]!=val[1] ||
00315          params[2]!=val[2] ||
00316          params[3]!=val[3])
00317         {
00318         val[0]=params[0];
00319         val[1]=params[1];
00320         val[2]=params[2];
00321         val[3]=params[3];
00322         ::glLightfv(light,pname,params);
00323         }
00324     } 
00325   
00326   // light=GL_LIGHT index
00327   // pname= lighting parameter
00328   //   GL_SPOT_EXPONENT        = 0x1205
00329   //   GL_SPOT_CUTOFF          = 0x1206
00330   //   GL_CONSTANT_ATTENUATION = 0x1207
00331   //   GL_LINEAR_ATTENUATION   = 0x1208
00332   //   GL_QUADRATIC_ATTENUATION= 0x1209
00333   GLfloat Lightf_buckets[8*8];
00334   GLint Lighti_SPOT_CUTOFF_buckets[8];
00335   inline void glLightf( GLenum light, GLenum pname, GLfloat f){
00336     register GLfloat *val=Lightf_buckets+(((int)(light-GL_LIGHT0)<<3)|((int)(pname-0x1205)));
00337     if(val[0]!=f)
00338       {
00339       val[0]=f;
00340       ::glLightf(light,pname,f);
00341       if(pname==GL_SPOT_CUTOFF) // invalidate integer spot cutoff
00342         Lighti_SPOT_CUTOFF_buckets[light-GL_LIGHT0]=-1;
00343       }
00344   }
00345   
00346   // light=GL_LIGHT index
00347   // pname=lighting parameter
00348   //   GL_SPOT_CUTOFF = 0x1206
00349   // needs to invalidate the float light cutoff
00350   inline void glLighti( GLenum light, GLenum pname, GLint f) 
00351     {
00352       if(pname==GL_SPOT_CUTOFF && f!=Lighti_SPOT_CUTOFF_buckets[light-GL_LIGHT0]){
00353       Lighti_SPOT_CUTOFF_buckets[light-GL_LIGHT0]=f;
00354       ::glLighti(light,pname,f);
00355       // need to invalidate the float cutoff
00356       Lightf_buckets[((int)(light-GL_LIGHT0)<<3)|0x02] = -1.0f;
00357       }
00358     }  
00359   
00360   // Face, GL_AMBIENT, float Info[4] 
00361   //   GL_FRONT          = 0x0404  
00362   //   GL_BACK           = 0x0405
00363   //   GL_FRONT_AND_BACK = 0x0408
00364   // GL_AMBIENT   = 0x1200
00365   // GL_DIFFUSE   = 0x1201
00366   // GL_SPECULAR  = 0x1202
00367   // GL_EMISSION  = 0x1600
00368   // GL_SHININESS = 0x1601
00369   // GL_AMBIENT_AND_DIFFUSE = 0x1602
00370   // GL_COLOR_INDEXES       = 0x1603
00371   GLfloat Materialfv_buckets[8*8*4]; 
00372   inline void glMaterialfv(GLenum face, GLenum pname, const GLfloat *params ) 
00373     {
00374       register int idx;
00375       register GLfloat *val;
00376       if(pname>=0x1600) 
00377         {
00378         idx=pname-0x1600 + 4; // put it just past the 120x buckets
00379         }
00380       else 
00381         {
00382         idx=pname-0x1200;
00383         }
00384       // FRONT/BACK and FRONT_AND_BACK should do both.
00385       // or perhaps should be a separate state key?
00386       // For now, we will treat FRONT_AND_BACK independently
00387       // because from a practical standpoint, that's how 
00388       // it tends to get used.
00389       val = Materialfv_buckets + ((((face-0x0404)<<3)|idx)<<2);
00390       if(val[0]!=params[0] ||
00391          val[1]!=params[1] || 
00392          val[2]!=params[2] ||
00393          val[3]!=params[3])
00394         {
00395         val[0]=params[0];
00396         val[1]=params[1];
00397         val[2]=params[2];
00398         val[3]=params[3];
00399         ::glMaterialfv(face,pname,params);
00400         }
00401     }
00402 
00403   /*
00404     a=0;
00405     a|=(val[0]^params[0])
00406     a|=(val[1]^params[1])
00407     a|=(val[2]^params[2])
00408     a|=(val[3]^params[3])
00409    */
00410   // GL_FLAT   = 0x1D00
00411   // GL_SMOOTH = 0x1D01
00412   GLenum ShadeModel_bucket; 
00413   inline void glShadeModel(GLenum e)
00414     {
00415       if(ShadeModel_bucket!=e)
00416         {
00417         ShadeModel_bucket=e;
00418         ::glShadeModel(e);
00419         }
00420     }
00421   
00422   GLclampf ClearColor_buckets[4];
00423   inline void glClearColor(GLclampf r,GLclampf g,GLclampf b,GLclampf a)
00424     {
00425       register GLclampf *c=ClearColor_buckets;
00426       if(c[0]!=r ||
00427          c[1]!=g ||
00428          c[2]!=b ||
00429          c[3]!=a)
00430         {
00431         c[0]=r;
00432         c[1]=g;
00433         c[2]=b;
00434         c[3]=a;
00435         ::glClearColor(r,g,b,a);
00436         }
00437     }
00438   
00439   GLclampd ClearDepth_bucket;
00440   inline void glClearDepth(GLclampd d) 
00441     { 
00442       if(d!=ClearDepth_bucket)
00443         {
00444         ClearDepth_bucket=d;
00445         ::glClearDepth(d);
00446         }
00447     }
00448   
00449   GLclampf DepthMask_bucket;
00450   inline void glDepthMask(GLenum e)
00451     {
00452       if(DepthMask_bucket!=e)
00453         {
00454         DepthMask_bucket=e;
00455         ::glDepthMask(e);
00456         }
00457     }
00458   
00459   // GL_FRONT = 0x0404
00460   // GL_BACK  = 0x0405
00461   GLenum CullFace_bucket;
00462   inline void glCullFace(GLenum e)
00463     {
00464       if(CullFace_bucket!=e)
00465         {
00466         CullFace_bucket=e;
00467         ::glCullFace(e);
00468         }
00469     }
00470   
00471   // well, lets go ahead and let it clear when it wants to
00472   inline void glClear(GLbitfield b) { ::glClear(b);}
00473   // GL_BACK_LEFT  = 0x0402
00474   // GL_BACK_RIGHT = 0x0403
00475   // GL_FRONT      = 0x0404
00476   // GL_BACK       = 0x0405
00477   GLenum DrawBuffer_bucket;
00478   inline void glDrawBuffer(GLenum e) {
00479     if(e!=DrawBuffer_bucket){
00480       DrawBuffer_bucket=e;
00481       ::glDrawBuffer(e);
00482     }
00483   }
00484   //============Matrix Ops (behave different for deferred ops)===
00485   // GL_MODELVIEW=0x1700
00486   // GL_PROJECTION=0x1701
00487   GLenum  MatrixMode_bucket;
00488   inline void glMatrixMode(GLenum e) {
00489     if(e!=MatrixMode_bucket){
00490       MatrixMode_bucket=e;
00491       ::glMatrixMode(e);
00492     }
00493   }
00494 
00495   GLint Viewport_bucket[4];
00496   inline void glViewport(GLint llx,GLint lly,GLint u,GLint v){
00497     register GLint *val=Viewport_bucket;
00498     if(val[0]!=llx ||
00499        val[1]!=lly ||
00500        val[2]!=u ||
00501        val[3]!=v){
00502       val[0]=llx;
00503       val[1]=lly;
00504       val[2]=u;
00505       val[3]=v;
00506       ::glViewport(llx,lly,u,v);
00507     }
00508   }
00509   // only needs to be called if scissor changes (and it usually won't)
00510   GLint Scissor_bucket[4];
00511   inline void glScissor(GLint llx,GLint lly,GLint u,GLint v){
00512     register GLint *val=Scissor_bucket;
00513     if(val[0]!=llx ||
00514        val[1]!=lly ||
00515        val[2]!=u ||
00516        val[3]!=v){
00517       val[0]=llx;
00518       val[1]=lly;
00519       val[2]=u;
00520       val[3]=v;
00521       ::glScissor(llx,lly,u,v);
00522     }
00523   }
00524   
00525   // what is the order of the clip plane eqn???
00526   // GL_CLIP_PLANE0 = 0x3000
00527   GLdouble ClipPlane_bucket[4*GL_MAX_CLIP_PLANES];
00528   inline void glClipPlane(GLenum e,const GLdouble *eqn){
00529     register GLdouble *val=ClipPlane_bucket + ((e-0x3000)<<2);
00530     if(val[0]!=eqn[0] ||
00531        val[1]!=eqn[1] ||
00532        val[2]!=eqn[2] ||
00533        val[3]!=eqn[3]){
00534       val[0]=eqn[0];
00535       val[1]=eqn[1];
00536       val[2]=eqn[2];
00537       val[3]=eqn[3];
00538       ::glClipPlane(e,eqn);
00539     }
00540   }
00541 
00542   // face= 
00543   //   GL_FRONT          = 0x0404  
00544   //   GL_BACK           = 0x0405
00545   //   GL_FRONT_AND_BACK = 0x0408
00546   GLenum ColorMaterial_bucket[8];
00547   inline void glColorMaterial(GLenum face,GLenum mode ){
00548     register GLenum *val= ColorMaterial_bucket + (face-0x0404);
00549     if(*val!=mode){
00550       *val=mode;
00551       ::glColorMaterial(face,mode);
00552     }
00553   }
00554   GLfloat PointSize_bucket;
00555   inline void glPointSize(GLfloat f) {
00556     if(f!=PointSize_bucket){
00557       PointSize_bucket=f;
00558       ::glPointSize(f);
00559     }
00560   }
00561   GLfloat LineWidth_bucket;
00562   inline void glLineWidth(GLfloat f){
00563     if(f!=LineWidth_bucket){
00564       LineWidth_bucket=f;
00565       ::glPointSize(f);
00566     }
00567   }
00568   GLint LineStipple_FACTOR_bucket;
00569   GLushort LineStipple_PATTERN_bucket;
00570   inline void glLineStipple(GLint factor, GLushort pattern )
00571     {
00572       if(factor!=LineStipple_FACTOR_bucket ||
00573          pattern!=LineStipple_PATTERN_bucket)
00574         {
00575         LineStipple_FACTOR_bucket=factor;
00576         LineStipple_PATTERN_bucket=pattern;
00577         ::glLineStipple(factor,pattern);
00578         }
00579     }
00580 
00581   GLclampd DepthRange_NEAR_bucket;
00582   GLclampd DepthRange_FAR_bucket;
00583   inline void glDepthRange(GLclampd nearval,GLclampd farval )
00584     {
00585       if(DepthRange_NEAR_bucket!=nearval ||
00586          DepthRange_FAR_bucket!=farval)
00587         {
00588         DepthRange_NEAR_bucket=nearval;
00589         DepthRange_FAR_bucket=farval;
00590         ::glDepthRange(nearval,farval);
00591         }
00592     }
00593   
00594 #ifdef GL_VERSION_1_1
00595   // enable GL_POLYGON_OFFSET_FILL = 0x8037
00596   GLfloat PolygonOffset_bucket[2];
00597   inline void glPolygonOffset( GLfloat f,GLfloat u) {
00598     if(PolygonOffset_bucket[0]!=f ||
00599        PolygonOffset_bucket[1]!=u){
00600       PolygonOffset_bucket[0]=f;
00601       PolygonOffset_bucket[1]=u;
00602       ::glPolygonOffset(f,u);
00603     }
00604   }
00605 #endif
00606 };
00607 
00608 
00609 //#ifdef vtkOpenGLStateCache_Cache
00610 //#undef vtkOpenGLStateCache_Cache
00611 //#endif

Generated on Thu Mar 28 14:19:33 2002 for VTK by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001