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