aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llrender/llglstates.h
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llrender/llglstates.h')
-rw-r--r--linden/indra/llrender/llglstates.h302
1 files changed, 302 insertions, 0 deletions
diff --git a/linden/indra/llrender/llglstates.h b/linden/indra/llrender/llglstates.h
new file mode 100644
index 0000000..e53640c
--- /dev/null
+++ b/linden/indra/llrender/llglstates.h
@@ -0,0 +1,302 @@
1/**
2 * @file llglstates.h
3 * @brief LLGL states definitions
4 *
5 * $LicenseInfo:firstyear=2001&license=viewergpl$
6 *
7 * Copyright (c) 2001-2008, Linden Research, Inc.
8 *
9 * Second Life Viewer Source Code
10 * The source code in this file ("Source Code") is provided by Linden Lab
11 * to you under the terms of the GNU General Public License, version 2.0
12 * ("GPL"), unless you have obtained a separate licensing agreement
13 * ("Other License"), formally executed by you and Linden Lab. Terms of
14 * the GPL can be found in doc/GPL-license.txt in this distribution, or
15 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
16 *
17 * There are special exceptions to the terms and conditions of the GPL as
18 * it is applied to this Source Code. View the full text of the exception
19 * in the file doc/FLOSS-exception.txt in this software distribution, or
20 * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
21 *
22 * By copying, modifying or distributing this software, you acknowledge
23 * that you have read and understood your obligations described above,
24 * and agree to abide by those obligations.
25 *
26 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
27 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
28 * COMPLETENESS OR PERFORMANCE.
29 * $/LicenseInfo$
30 */
31
32//THIS HEADER SHOULD ONLY BE INCLUDED FROM llgl.h
33#ifndef LL_LLGLSTATES_H
34#define LL_LLGLSTATES_H
35
36#include "llimagegl.h"
37
38//----------------------------------------------------------------------------
39
40class LLGLDepthTest
41{
42 // Enabled by default
43public:
44 LLGLDepthTest(GLboolean depth_enabled, GLboolean write_enabled = GL_TRUE, GLenum depth_func = GL_LEQUAL);
45
46 ~LLGLDepthTest();
47
48 GLboolean mPrevDepthEnabled;
49 GLenum mPrevDepthFunc;
50 GLboolean mPrevWriteEnabled;
51private:
52 static GLboolean sDepthEnabled; // defaults to GL_FALSE
53 static GLenum sDepthFunc; // defaults to GL_LESS
54 static GLboolean sWriteEnabled; // defaults to GL_TRUE
55};
56
57//----------------------------------------------------------------------------
58
59class LLGLSDefault
60{
61protected:
62 LLGLEnable mColorMaterial;
63 LLGLDisable mAlphaTest, mBlend, mCullFace, mDither, mFog,
64 mLineSmooth, mLineStipple, mNormalize, mPolygonSmooth,
65 mTextureGenQ, mTextureGenR, mTextureGenS, mTextureGenT,
66 mGLMultisample;
67public:
68 LLGLSDefault()
69 :
70 // Enable
71 mColorMaterial(GL_COLOR_MATERIAL),
72 // Disable
73 mAlphaTest(GL_ALPHA_TEST),
74 mBlend(GL_BLEND),
75 mCullFace(GL_CULL_FACE),
76 mDither(GL_DITHER),
77 mFog(GL_FOG),
78 mLineSmooth(GL_LINE_SMOOTH),
79 mLineStipple(GL_LINE_STIPPLE),
80 mNormalize(GL_NORMALIZE),
81 mPolygonSmooth(GL_POLYGON_SMOOTH),
82 mTextureGenQ(GL_TEXTURE_GEN_Q),
83 mTextureGenR(GL_TEXTURE_GEN_R),
84 mTextureGenS(GL_TEXTURE_GEN_S),
85 mTextureGenT(GL_TEXTURE_GEN_T),
86 mGLMultisample(GL_MULTISAMPLE_ARB)
87 { }
88};
89
90class LLGLSNoTexture
91{
92public:
93 LLGLSNoTexture()
94 { LLImageGL::unbindTexture(0); }
95};
96
97class LLGLSObjectSelect
98{
99protected:
100 LLGLDisable mBlend, mFog, mAlphaTest;
101 LLGLEnable mCullFace;
102public:
103 LLGLSObjectSelect()
104 : mBlend(GL_BLEND), mFog(GL_FOG),
105 mAlphaTest(GL_ALPHA_TEST),
106 mCullFace(GL_CULL_FACE)
107 { LLImageGL::unbindTexture(0); }
108};
109
110class LLGLSObjectSelectAlpha
111{
112protected:
113 LLGLEnable mAlphaTest;
114public:
115 LLGLSObjectSelectAlpha()
116 : mAlphaTest(GL_ALPHA_TEST)
117 {}
118};
119
120//----------------------------------------------------------------------------
121
122class LLGLSUIDefault
123{
124protected:
125 LLGLEnable mBlend, mAlphaTest;
126 LLGLDisable mCullFace;
127 LLGLDepthTest mDepthTest;
128public:
129 LLGLSUIDefault()
130 : mBlend(GL_BLEND), mAlphaTest(GL_ALPHA_TEST),
131 mCullFace(GL_CULL_FACE),
132 mDepthTest(GL_FALSE, GL_TRUE, GL_LEQUAL)
133 {}
134};
135
136class LLGLSNoAlphaTest // : public LLGLSUIDefault
137{
138protected:
139 LLGLDisable mAlphaTest;
140public:
141 LLGLSNoAlphaTest()
142 : mAlphaTest(GL_ALPHA_TEST)
143 {}
144};
145
146class LLGLSNoTextureNoAlphaTest // : public LLGLSUIDefault
147{
148protected:
149 LLGLDisable mAlphaTest;
150public:
151 LLGLSNoTextureNoAlphaTest()
152 : mAlphaTest(GL_ALPHA_TEST)
153
154 { LLImageGL::unbindTexture(0); }
155};
156
157//----------------------------------------------------------------------------
158
159class LLGLSFog
160{
161protected:
162 LLGLEnable mFog;
163public:
164 LLGLSFog()
165 : mFog(GL_FOG)
166 {}
167};
168
169class LLGLSNoFog
170{
171protected:
172 LLGLDisable mFog;
173public:
174 LLGLSNoFog()
175 : mFog(GL_FOG)
176 {}
177};
178
179//----------------------------------------------------------------------------
180
181class LLGLSPipeline
182{
183protected:
184 LLGLEnable mCullFace;
185 LLGLDepthTest mDepthTest;
186public:
187 LLGLSPipeline()
188 : mCullFace(GL_CULL_FACE),
189 mDepthTest(GL_TRUE, GL_TRUE, GL_LEQUAL)
190 { }
191};
192
193class LLGLSPipelineAlpha // : public LLGLSPipeline
194{
195protected:
196 LLGLEnable mBlend, mAlphaTest;
197public:
198 LLGLSPipelineAlpha()
199 : mBlend(GL_BLEND),
200 mAlphaTest(GL_ALPHA_TEST)
201 { }
202};
203
204class LLGLSPipelineEmbossBump
205{
206protected:
207 LLGLDisable mFog;
208public:
209 LLGLSPipelineEmbossBump()
210 : mFog(GL_FOG)
211 { }
212};
213
214class LLGLSPipelineSelection
215{
216protected:
217 LLGLDisable mCullFace;
218public:
219 LLGLSPipelineSelection()
220 : mCullFace(GL_CULL_FACE)
221 {}
222};
223
224class LLGLSPipelineAvatar
225{
226protected:
227 LLGLEnable mNormalize;
228public:
229 LLGLSPipelineAvatar()
230 : mNormalize(GL_NORMALIZE)
231 {}
232};
233
234class LLGLSPipelineSkyBox
235{
236protected:
237 LLGLDisable mAlphaTest, mCullFace, mFog;
238public:
239 LLGLSPipelineSkyBox()
240 : mAlphaTest(GL_ALPHA_TEST), mCullFace(GL_CULL_FACE), mFog(GL_FOG)
241 { }
242};
243
244class LLGLSTracker
245{
246protected:
247 LLGLEnable mCullFace, mBlend, mAlphaTest;
248public:
249 LLGLSTracker() :
250 mCullFace(GL_CULL_FACE),
251 mBlend(GL_BLEND),
252 mAlphaTest(GL_ALPHA_TEST)
253
254 { LLImageGL::unbindTexture(0); }
255};
256
257//----------------------------------------------------------------------------
258
259class LLGLSSpecular
260{
261public:
262 LLGLSSpecular(const LLColor4& color, F32 shininess)
263 {
264 if (shininess > 0.0f)
265 {
266 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, color.mV);
267 S32 shiny = (S32)(shininess*128.f);
268 shiny = llclamp(shiny,0,128);
269 glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, shiny);
270 }
271 }
272 ~LLGLSSpecular()
273 {
274 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, LLColor4(0.f,0.f,0.f,0.f).mV);
275 glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, 0);
276 }
277};
278
279//----------------------------------------------------------------------------
280
281
282class LLGLSBlendFunc : public LLGLSPipeline {
283protected:
284 GLint mSavedSrc, mSavedDst;
285 LLGLEnable mBlend;
286
287public:
288 LLGLSBlendFunc(GLenum srcFunc, GLenum dstFunc) :
289 mBlend(GL_BLEND)
290 {
291 glGetIntegerv(GL_BLEND_SRC, &mSavedSrc);
292 glGetIntegerv(GL_BLEND_DST, &mSavedDst);
293 glBlendFunc(srcFunc, dstFunc);
294 }
295
296 ~LLGLSBlendFunc(void) {
297 glBlendFunc(mSavedSrc, mSavedDst);
298 }
299};
300
301
302#endif