llglstates.h

Go to the documentation of this file.
00001 
00032 //THIS HEADER SHOULD ONLY BE INCLUDED FROM llgl.h
00033 #ifndef LL_LLGLSTATES_H
00034 #define LL_LLGLSTATES_H
00035 
00036 #ifdef WIN32
00037 #       define WIN32_LEAN_AND_MEAN
00038 #       include <winsock2.h>
00039 #       include <windows.h>
00040 #endif
00041 
00042 #if LL_DARWIN
00043 #include <AGL/gl.h>
00044 #else
00045 #include "llglheaders.h"
00046 #endif
00047 
00048 //----------------------------------------------------------------------------
00049 
00050 class LLGLDepthTest
00051 {
00052         // Enabled by default
00053 public:
00054         LLGLDepthTest(GLboolean depth_enabled, GLboolean write_enabled = GL_TRUE, GLenum depth_func = GL_LEQUAL)
00055                 : mPrevDepthEnabled(sDepthEnabled), mPrevDepthFunc(sDepthFunc), mPrevWriteEnabled(sWriteEnabled)
00056         {
00057                 if (depth_enabled != sDepthEnabled)
00058                 {
00059                         if (depth_enabled) glEnable(GL_DEPTH_TEST);
00060                         else glDisable(GL_DEPTH_TEST);
00061                         sDepthEnabled = depth_enabled;
00062                 }
00063                 if (depth_func != sDepthFunc)
00064                 {
00065                         glDepthFunc(depth_func);
00066                         sDepthFunc = depth_func;
00067                 }
00068                 if (write_enabled != sWriteEnabled)
00069                 {
00070                         glDepthMask(write_enabled);
00071                         sWriteEnabled = write_enabled;
00072                 }
00073         }
00074         ~LLGLDepthTest()
00075         {
00076                 if (sDepthEnabled != mPrevDepthEnabled )
00077                 {
00078                         if (mPrevDepthEnabled) glEnable(GL_DEPTH_TEST);
00079                         else glDisable(GL_DEPTH_TEST);
00080                         sDepthEnabled = mPrevDepthEnabled;
00081                 }
00082                 if (sDepthFunc != mPrevDepthFunc)
00083                 {
00084                         glDepthFunc(mPrevDepthFunc);
00085                         sDepthFunc = mPrevDepthFunc;
00086                 }
00087                 if (sWriteEnabled != mPrevWriteEnabled )
00088                 {
00089                         glDepthMask(mPrevWriteEnabled);
00090                         sWriteEnabled = mPrevWriteEnabled;
00091                 }
00092         }
00093         GLboolean mPrevDepthEnabled;
00094         GLenum mPrevDepthFunc;
00095         GLboolean mPrevWriteEnabled;
00096 private:
00097         static GLboolean sDepthEnabled; // defaults to GL_FALSE
00098         static GLenum sDepthFunc; // defaults to GL_LESS
00099         static GLboolean sWriteEnabled; // defaults to GL_TRUE
00100 };
00101 
00102 //----------------------------------------------------------------------------
00103 
00104 class LLGLSDefault
00105 {
00106 protected:
00107         LLGLEnable mTexture2D, mColorMaterial;
00108         LLGLDisable mAlphaTest, mBlend, mCullFace, mDither, mFog, 
00109                 mLineSmooth, mLineStipple, mNormalize, mPolygonSmooth,
00110                 mTextureGenQ, mTextureGenR, mTextureGenS, mTextureGenT;
00111 public:
00112         LLGLSDefault()
00113                 :
00114                 // Enable
00115                 mTexture2D(GL_TEXTURE_2D),
00116                 mColorMaterial(GL_COLOR_MATERIAL),
00117                 // Disable
00118                 mAlphaTest(GL_ALPHA_TEST),
00119                 mBlend(GL_BLEND), 
00120                 mCullFace(GL_CULL_FACE),
00121                 mDither(GL_DITHER),
00122                 mFog(GL_FOG), 
00123                 mLineSmooth(GL_LINE_SMOOTH),
00124                 mLineStipple(GL_LINE_STIPPLE),
00125                 mNormalize(GL_NORMALIZE),
00126                 mPolygonSmooth(GL_POLYGON_SMOOTH),
00127                 mTextureGenQ(GL_TEXTURE_GEN_Q), 
00128                 mTextureGenR(GL_TEXTURE_GEN_R),
00129                 mTextureGenS(GL_TEXTURE_GEN_S), 
00130                 mTextureGenT(GL_TEXTURE_GEN_T)
00131         { }
00132 };
00133 
00134 class LLGLSTexture 
00135 {
00136 protected:
00137         LLGLEnable mTexture2D;
00138 public:
00139         LLGLSTexture()
00140                 : mTexture2D(GL_TEXTURE_2D)
00141         {}
00142 };
00143 
00144 
00145 class LLGLSNoTexture 
00146 {
00147 protected:
00148         LLGLDisable mTexture2D;
00149 public:
00150         LLGLSNoTexture()
00151                 : mTexture2D(GL_TEXTURE_2D)
00152         {}
00153 };
00154 
00155 class LLGLSObjectSelect // : public LLGLSDefault
00156 { 
00157 protected:
00158         LLGLDisable mBlend, mFog, mTexture2D, mAlphaTest;
00159         LLGLEnable mCullFace;
00160 public:
00161         LLGLSObjectSelect()
00162                 : mBlend(GL_BLEND), mFog(GL_FOG), mTexture2D(GL_TEXTURE_2D), 
00163                   mAlphaTest(GL_ALPHA_TEST),
00164                   mCullFace(GL_CULL_FACE)
00165         {}
00166 };
00167 
00168 class LLGLSObjectSelectAlpha // : public LLGLSObjectSelect
00169 {
00170 protected:
00171         LLGLEnable mTexture2D, mAlphaTest;
00172 public:
00173         LLGLSObjectSelectAlpha()
00174                 : mTexture2D(GL_TEXTURE_2D), mAlphaTest(GL_ALPHA_TEST)
00175         {}
00176 };
00177 
00178 //----------------------------------------------------------------------------
00179 
00180 class LLGLSUIDefault // : public LLGLSDefault
00181 { 
00182 protected:
00183         LLGLEnable mBlend, mAlphaTest, mTexture2D;
00184         LLGLDisable mCullFace;
00185         LLGLDepthTest mDepthTest;
00186 public:
00187         LLGLSUIDefault() 
00188                 : mBlend(GL_BLEND), mAlphaTest(GL_ALPHA_TEST),
00189                   mTexture2D(GL_TEXTURE_2D), 
00190                   mCullFace(GL_CULL_FACE),
00191                   mDepthTest(GL_FALSE, GL_TRUE, GL_LEQUAL)
00192         {}
00193 };
00194 
00195 class LLGLSNoAlphaTest // : public LLGLSUIDefault
00196 {
00197 protected:
00198         LLGLDisable mAlphaTest;
00199 public:
00200         LLGLSNoAlphaTest()
00201                 : mAlphaTest(GL_ALPHA_TEST)
00202         {}
00203 };
00204 
00205 class LLGLSNoTextureNoAlphaTest // : public LLGLSUIDefault
00206 {
00207 protected:
00208         LLGLDisable mAlphaTest;
00209         LLGLDisable mTexture2D;
00210 public:
00211         LLGLSNoTextureNoAlphaTest()
00212                 : mAlphaTest(GL_ALPHA_TEST),
00213                   mTexture2D(GL_TEXTURE_2D)
00214         {}
00215 };
00216 
00217 //----------------------------------------------------------------------------
00218 
00219 class LLGLSFog
00220 {
00221 protected:
00222         LLGLEnable mFog;
00223 public:
00224         LLGLSFog()
00225                 : mFog(GL_FOG)
00226         {}
00227 };
00228 
00229 class LLGLSNoFog
00230 {
00231 protected:
00232         LLGLDisable mFog;
00233 public:
00234         LLGLSNoFog()
00235                 : mFog(GL_FOG)
00236         {}
00237 };
00238 
00239 //----------------------------------------------------------------------------
00240 
00241 class LLGLSPipeline // : public LLGLSDefault
00242 { 
00243 protected:
00244         LLGLEnable mCullFace;
00245         LLGLDepthTest mDepthTest;
00246 public:
00247         LLGLSPipeline()
00248                 : mCullFace(GL_CULL_FACE),
00249                   mDepthTest(GL_TRUE, GL_TRUE, GL_LEQUAL)
00250         { }             
00251 };
00252 
00253 class LLGLSPipelineAlpha // : public LLGLSPipeline
00254 { 
00255 protected:
00256         LLGLEnable mBlend, mAlphaTest;
00257 public:
00258         LLGLSPipelineAlpha()
00259                 : mBlend(GL_BLEND),
00260                   mAlphaTest(GL_ALPHA_TEST)
00261         { }
00262 };
00263 
00264 class LLGLSPipelineEmbossBump // : public LLGLSPipelineAlpha
00265 {
00266 protected:
00267         LLGLDisable mFog;
00268 public:
00269         LLGLSPipelineEmbossBump()
00270                 : mFog(GL_FOG)
00271         { }
00272 };
00273 
00274 class LLGLSPipelineSelection // : public LLGLSPipelineAlpha
00275 { 
00276 protected:
00277         LLGLDisable mCullFace;
00278 public:
00279         LLGLSPipelineSelection()
00280                 : mCullFace(GL_CULL_FACE)
00281         {}
00282 };
00283 
00284 class LLGLSPipelineAvatar // : public LLGLSPipeline
00285 {
00286 protected:
00287         LLGLEnable mNormalize;
00288 public:
00289         LLGLSPipelineAvatar()
00290                 : mNormalize(GL_NORMALIZE)
00291         {}
00292 };
00293 
00294 class LLGLSPipelineSkyBox // : public LLGLSPipeline
00295 { 
00296 protected:
00297         LLGLDisable mAlphaTest, mCullFace, mFog;
00298 public:
00299         LLGLSPipelineSkyBox()
00300                 : mAlphaTest(GL_ALPHA_TEST), mCullFace(GL_CULL_FACE), mFog(GL_FOG)
00301         { }
00302 };
00303 
00304 class LLGLSTracker // : public LLGLSDefault
00305 {
00306 protected:
00307         LLGLEnable mCullFace, mBlend, mAlphaTest;
00308         LLGLDisable mTexture2D;
00309 public:
00310         LLGLSTracker() :
00311                 mCullFace(GL_CULL_FACE),
00312                 mBlend(GL_BLEND),
00313                 mAlphaTest(GL_ALPHA_TEST),
00314                 mTexture2D(GL_TEXTURE_2D)               
00315         {}
00316 };
00317 
00318 //----------------------------------------------------------------------------
00319 
00320 class LLGLSSpecular
00321 {
00322 public:
00323         LLGLSSpecular(const LLColor4& color, F32 shininess)
00324         {
00325                 if (shininess > 0.0f)
00326                 {
00327                         glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, color.mV);
00328                         S32 shiny = (S32)(shininess*128.f);
00329                         shiny = llclamp(shiny,0,128);
00330                         glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, shiny);
00331                 }
00332         }
00333         ~LLGLSSpecular()
00334         {
00335                 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, LLColor4(0.f,0.f,0.f,0.f).mV);
00336                 glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, 0);
00337         }
00338 };
00339 
00340 //----------------------------------------------------------------------------
00341 
00342 
00343 #endif

Generated on Thu Jul 1 06:08:40 2010 for Second Life Viewer by  doxygen 1.4.7