PageRenderTime 38ms CodeModel.GetById 1ms app.highlight 31ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/llrender/llglstates.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 265 lines | 199 code | 30 blank | 36 comment | 2 complexity | 2f3a78e6cf076b4de982974f332bb492 MD5 | raw file
  1/** 
  2 * @file llglstates.h
  3 * @brief LLGL states definitions
  4 *
  5 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27//THIS HEADER SHOULD ONLY BE INCLUDED FROM llgl.h
 28#ifndef LL_LLGLSTATES_H
 29#define LL_LLGLSTATES_H
 30
 31#include "llimagegl.h"
 32
 33//----------------------------------------------------------------------------
 34
 35class LLGLDepthTest
 36{
 37	// Enabled by default
 38public:
 39	LLGLDepthTest(GLboolean depth_enabled, GLboolean write_enabled = GL_TRUE, GLenum depth_func = GL_LEQUAL);
 40	
 41	~LLGLDepthTest();
 42	
 43	void checkState();
 44
 45	GLboolean mPrevDepthEnabled;
 46	GLenum mPrevDepthFunc;
 47	GLboolean mPrevWriteEnabled;
 48private:
 49	static GLboolean sDepthEnabled; // defaults to GL_FALSE
 50	static GLenum sDepthFunc; // defaults to GL_LESS
 51	static GLboolean sWriteEnabled; // defaults to GL_TRUE
 52};
 53
 54//----------------------------------------------------------------------------
 55
 56class LLGLSDefault
 57{
 58protected:
 59	LLGLEnable mColorMaterial;
 60	LLGLDisable mAlphaTest, mBlend, mCullFace, mDither, mFog, 
 61		mLineSmooth, mLineStipple, mNormalize, mPolygonSmooth,
 62		mTextureGenQ, mTextureGenR, mTextureGenS, mTextureGenT,
 63		mGLMultisample;
 64public:
 65	LLGLSDefault()
 66		:
 67		// Enable
 68		mColorMaterial(GL_COLOR_MATERIAL),
 69		// Disable
 70		mAlphaTest(GL_ALPHA_TEST),
 71		mBlend(GL_BLEND), 
 72		mCullFace(GL_CULL_FACE),
 73		mDither(GL_DITHER),
 74		mFog(GL_FOG), 
 75		mLineSmooth(GL_LINE_SMOOTH),
 76		mLineStipple(GL_LINE_STIPPLE),
 77		mNormalize(GL_NORMALIZE),
 78		mPolygonSmooth(GL_POLYGON_SMOOTH),
 79		mTextureGenQ(GL_TEXTURE_GEN_Q), 
 80		mTextureGenR(GL_TEXTURE_GEN_R),
 81		mTextureGenS(GL_TEXTURE_GEN_S), 
 82		mTextureGenT(GL_TEXTURE_GEN_T),
 83		mGLMultisample(GL_MULTISAMPLE_ARB)
 84	{ }
 85};
 86
 87class LLGLSObjectSelect
 88{ 
 89protected:
 90	LLGLDisable mBlend, mFog, mAlphaTest;
 91	LLGLEnable mCullFace;
 92public:
 93	LLGLSObjectSelect()
 94		: mBlend(GL_BLEND), mFog(GL_FOG), 
 95		  mAlphaTest(GL_ALPHA_TEST),
 96		  mCullFace(GL_CULL_FACE)
 97	{ }
 98};
 99
100class LLGLSObjectSelectAlpha
101{
102protected:
103	LLGLEnable mAlphaTest;
104public:
105	LLGLSObjectSelectAlpha()
106		: mAlphaTest(GL_ALPHA_TEST)
107	{}
108};
109
110//----------------------------------------------------------------------------
111
112class LLGLSUIDefault
113{ 
114protected:
115	LLGLEnable mBlend, mAlphaTest;
116	LLGLDisable mCullFace;
117	LLGLDepthTest mDepthTest;
118public:
119	LLGLSUIDefault() 
120		: mBlend(GL_BLEND), mAlphaTest(GL_ALPHA_TEST),
121		  mCullFace(GL_CULL_FACE),
122		  mDepthTest(GL_FALSE, GL_TRUE, GL_LEQUAL)
123	{}
124};
125
126class LLGLSNoAlphaTest // : public LLGLSUIDefault
127{
128protected:
129	LLGLDisable mAlphaTest;
130public:
131	LLGLSNoAlphaTest()
132		: mAlphaTest(GL_ALPHA_TEST)
133	{}
134};
135
136//----------------------------------------------------------------------------
137
138class LLGLSFog
139{
140protected:
141	LLGLEnable mFog;
142public:
143	LLGLSFog()
144		: mFog(GL_FOG)
145	{}
146};
147
148class LLGLSNoFog
149{
150protected:
151	LLGLDisable mFog;
152public:
153	LLGLSNoFog()
154		: mFog(GL_FOG)
155	{}
156};
157
158//----------------------------------------------------------------------------
159
160class LLGLSPipeline
161{ 
162protected:
163	LLGLEnable mCullFace;
164	LLGLDepthTest mDepthTest;
165public:
166	LLGLSPipeline()
167		: mCullFace(GL_CULL_FACE),
168		  mDepthTest(GL_TRUE, GL_TRUE, GL_LEQUAL)
169	{ }		
170};
171
172class LLGLSPipelineAlpha // : public LLGLSPipeline
173{ 
174protected:
175	LLGLEnable mBlend, mAlphaTest;
176public:
177	LLGLSPipelineAlpha()
178		: mBlend(GL_BLEND),
179		  mAlphaTest(GL_ALPHA_TEST)
180	{ }
181};
182
183class LLGLSPipelineEmbossBump
184{
185protected:
186	LLGLDisable mFog;
187public:
188	LLGLSPipelineEmbossBump()
189		: mFog(GL_FOG)
190	{ }
191};
192
193class LLGLSPipelineSelection
194{ 
195protected:
196	LLGLDisable mCullFace;
197public:
198	LLGLSPipelineSelection()
199		: mCullFace(GL_CULL_FACE)
200	{}
201};
202
203class LLGLSPipelineAvatar
204{
205protected:
206	LLGLEnable mNormalize;
207public:
208	LLGLSPipelineAvatar()
209		: mNormalize(GL_NORMALIZE)
210	{}
211};
212
213class LLGLSPipelineSkyBox
214{ 
215protected:
216	LLGLDisable mAlphaTest, mCullFace, mFog;
217public:
218	LLGLSPipelineSkyBox()
219		: mAlphaTest(GL_ALPHA_TEST), mCullFace(GL_CULL_FACE), mFog(GL_FOG)
220	{ }
221};
222
223class LLGLSTracker
224{
225protected:
226	LLGLEnable mCullFace, mBlend, mAlphaTest;
227public:
228	LLGLSTracker() :
229		mCullFace(GL_CULL_FACE),
230		mBlend(GL_BLEND),
231		mAlphaTest(GL_ALPHA_TEST)
232		
233	{ }
234};
235
236//----------------------------------------------------------------------------
237
238class LLGLSSpecular
239{
240public:
241	F32 mShininess;
242	LLGLSSpecular(const LLColor4& color, F32 shininess)
243	{
244		mShininess = shininess;
245		if (mShininess > 0.0f)
246		{
247			glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, color.mV);
248			S32 shiny = (S32)(shininess*128.f);
249			shiny = llclamp(shiny,0,128);
250			glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, shiny);
251		}
252	}
253	~LLGLSSpecular()
254	{
255		if (mShininess > 0.f)
256		{
257			glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, LLColor4(0.f,0.f,0.f,0.f).mV);
258			glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, 0);
259		}
260	}
261};
262
263//----------------------------------------------------------------------------
264
265#endif