aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llrender/llgl.h
diff options
context:
space:
mode:
authorJacek Antonelli2008-09-06 18:24:57 -0500
committerJacek Antonelli2008-09-06 18:25:07 -0500
commit798d367d54a6c6379ad355bd8345fa40e31e7fe9 (patch)
tree1921f1708cd0240648c97bc02df2c2ab5f2fc41e /linden/indra/llrender/llgl.h
parentSecond Life viewer sources 1.20.15 (diff)
downloadmeta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.zip
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.gz
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.bz2
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.xz
Second Life viewer sources 1.21.0-RC
Diffstat (limited to 'linden/indra/llrender/llgl.h')
-rw-r--r--linden/indra/llrender/llgl.h378
1 files changed, 378 insertions, 0 deletions
diff --git a/linden/indra/llrender/llgl.h b/linden/indra/llrender/llgl.h
new file mode 100644
index 0000000..cb368d7
--- /dev/null
+++ b/linden/indra/llrender/llgl.h
@@ -0,0 +1,378 @@
1/**
2 * @file llgl.h
3 * @brief LLGL definition
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#ifndef LL_LLGL_H
33#define LL_LLGL_H
34
35// This file contains various stuff for handling gl extensions and other gl related stuff.
36
37#include <string>
38#include <map>
39
40#include "llerror.h"
41#include "v4color.h"
42#include "llstring.h"
43#include "stdtypes.h"
44#include "v4math.h"
45#include "llplane.h"
46#include "llgltypes.h"
47
48#include "llglheaders.h"
49#include "glh/glh_linear.h"
50
51extern BOOL gDebugGL;
52
53#define LL_GL_ERRS LL_ERRS("RenderState")
54
55class LLSD;
56
57// Manage GL extensions...
58class LLGLManager
59{
60public:
61 LLGLManager();
62
63 bool initGL();
64 void shutdownGL();
65
66 void initWGL(); // Initializes stupid WGL extensions
67
68 std::string getRawGLString(); // For sending to simulator
69
70 BOOL mInited;
71 BOOL mIsDisabled;
72
73 // Extensions used by everyone
74 BOOL mHasMultitexture;
75 S32 mNumTextureUnits;
76 BOOL mHasMipMapGeneration;
77 BOOL mHasPalettedTextures;
78 BOOL mHasCompressedTextures;
79 BOOL mHasFramebufferObject;
80
81 // ARB Extensions
82 BOOL mHasVertexBufferObject;
83 BOOL mHasPBuffer;
84 BOOL mHasShaderObjects;
85 BOOL mHasVertexShader;
86 BOOL mHasFragmentShader;
87 BOOL mHasOcclusionQuery;
88 BOOL mHasPointParameters;
89
90 // Other extensions.
91 BOOL mHasAnisotropic;
92 BOOL mHasARBEnvCombine;
93 BOOL mHasCubeMap;
94
95 // Vendor-specific extensions
96 BOOL mIsATI;
97 BOOL mIsNVIDIA;
98 BOOL mIsIntel;
99 BOOL mIsGF2or4MX;
100 BOOL mIsGF3;
101 BOOL mIsGFFX;
102 BOOL mATIOffsetVerticalLines;
103 BOOL mATIOldDriver;
104
105 // Whether this version of GL is good enough for SL to use
106 BOOL mHasRequirements;
107
108 // Misc extensions
109 BOOL mHasSeparateSpecularColor;
110
111 S32 mDriverVersionMajor;
112 S32 mDriverVersionMinor;
113 S32 mDriverVersionRelease;
114 F32 mGLVersion; // e.g = 1.4
115 std::string mDriverVersionVendorString;
116
117 S32 mVRAM; // VRAM in MB
118 S32 mGLMaxVertexRange;
119 S32 mGLMaxIndexRange;
120
121 void getPixelFormat(); // Get the best pixel format
122
123 std::string getGLInfoString();
124 void printGLInfoString();
125 void getGLInfo(LLSD& info);
126
127 // In ALL CAPS
128 std::string mGLVendor;
129 std::string mGLVendorShort;
130
131 // In ALL CAPS
132 std::string mGLRenderer;
133
134private:
135 void initExtensions();
136 void initGLStates();
137 void initGLImages();
138};
139
140extern LLGLManager gGLManager;
141
142class LLQuaternion;
143class LLMatrix4;
144
145void rotate_quat(LLQuaternion& rotation);
146
147void flush_glerror(); // Flush GL errors when we know we're handling them correctly.
148
149void assert_glerror();
150
151void clear_glerror();
152
153//#if LL_DEBUG
154# define stop_glerror() assert_glerror()
155# define llglassertok() assert_glerror()
156//#else
157//# define stop_glerror()
158//# define llglassertok()
159//#endif
160
161#define llglassertok_always() assert_glerror()
162
163////////////////////////
164//
165// Note: U32's are GLEnum's...
166//
167
168// This is a class for GL state management
169
170/*
171 GL STATE MANAGEMENT DESCRIPTION
172
173 LLGLState and its two subclasses, LLGLEnable and LLGLDisable, manage the current
174 enable/disable states of the GL to prevent redundant setting of state within a
175 render path or the accidental corruption of what state the next path expects.
176
177 Essentially, wherever you would call glEnable set a state and then
178 subsequently reset it by calling glDisable (or vice versa), make an instance of
179 LLGLEnable with the state you want to set, and assume it will be restored to its
180 original state when that instance of LLGLEnable is destroyed. It is good practice
181 to exploit stack frame controls for optimal setting/unsetting and readability of
182 code. In llglstates.h, there are a collection of helper classes that define groups
183 of enables/disables that can cause multiple states to be set with the creation of
184 one instance.
185
186 Sample usage:
187
188 //disable lighting for rendering hud objects
189 //INCORRECT USAGE
190 LLGLEnable lighting(GL_LIGHTING);
191 renderHUD();
192 LLGLDisable lighting(GL_LIGHTING);
193
194 //CORRECT USAGE
195 {
196 LLGLEnable lighting(GL_LIGHTING);
197 renderHUD();
198 }
199
200 If a state is to be set on a conditional, the following mechanism
201 is useful:
202
203 {
204 LLGLEnable lighting(light_hud ? GL_LIGHTING : 0);
205 renderHUD();
206 }
207
208 A LLGLState initialized with a parameter of 0 does nothing.
209
210 LLGLState works by maintaining a map of the current GL states, and ignoring redundant
211 enables/disables. If a redundant call is attempted, it becomes a noop, otherwise,
212 it is set in the constructor and reset in the destructor.
213
214 For debugging GL state corruption, running with debug enabled will trigger asserts
215 if the existing GL state does not match the expected GL state.
216
217*/
218class LLGLState
219{
220public:
221 static void initClass();
222 static void restoreGL();
223
224 static void resetTextureStates();
225 static void dumpStates();
226 static void checkStates(const std::string& msg = "");
227 static void checkTextureChannels(const std::string& msg = "");
228 static void checkClientArrays(const std::string& msg = "", U32 data_mask = 0x0001);
229
230protected:
231 static std::map<LLGLenum, LLGLboolean> sStateMap;
232
233public:
234 enum { CURRENT_STATE = -2 };
235 LLGLState(LLGLenum state, S32 enabled = CURRENT_STATE);
236 ~LLGLState();
237 void setEnabled(S32 enabled);
238 void enable() { setEnabled(TRUE); }
239 void disable() { setEnabled(FALSE); }
240protected:
241 LLGLenum mState;
242 BOOL mWasEnabled;
243 BOOL mIsEnabled;
244};
245
246// New LLGLState class wrappers that don't depend on actual GL flags.
247class LLGLEnableBlending : public LLGLState
248{
249public:
250 LLGLEnableBlending(bool enable);
251};
252
253class LLGLEnableAlphaReject : public LLGLState
254{
255public:
256 LLGLEnableAlphaReject(bool enable);
257};
258
259/// TODO: Being deprecated.
260class LLGLEnable : public LLGLState
261{
262public:
263 LLGLEnable(LLGLenum state) : LLGLState(state, TRUE) {}
264};
265
266/// TODO: Being deprecated.
267class LLGLDisable : public LLGLState
268{
269public:
270 LLGLDisable(LLGLenum state) : LLGLState(state, FALSE) {}
271};
272
273/*
274 Store and modify projection matrix to create an oblique
275 projection that clips to the specified plane. Oblique
276 projections alter values in the depth buffer, so this
277 class should not be used mid-renderpass.
278
279 Restores projection matrix on destruction.
280 GL_MODELVIEW_MATRIX is active whenever program execution
281 leaves this class.
282 Does not stack.
283 Caches inverse of projection matrix used in gGLObliqueProjectionInverse
284*/
285class LLGLUserClipPlane
286{
287public:
288
289 LLGLUserClipPlane(const LLPlane& plane, const glh::matrix4f& modelview, const glh::matrix4f& projection);
290 ~LLGLUserClipPlane();
291
292 void setPlane(F32 a, F32 b, F32 c, F32 d);
293
294private:
295 glh::matrix4f mProjection;
296 glh::matrix4f mModelview;
297};
298
299/*
300 Modify and load projection matrix to push depth values to far clip plane.
301
302 Restores projection matrix on destruction.
303 GL_MODELVIEW_MATRIX is active whenever program execution
304 leaves this class.
305 Does not stack.
306*/
307class LLGLClampToFarClip
308{
309public:
310 LLGLClampToFarClip(glh::matrix4f projection);
311 ~LLGLClampToFarClip();
312};
313
314/*
315 Generic pooling scheme for things which use GL names (used for occlusion queries and vertex buffer objects).
316 Prevents thrashing of GL name caches by avoiding calls to glGenFoo and glDeleteFoo.
317*/
318class LLGLNamePool
319{
320public:
321 typedef struct
322 {
323 GLuint name;
324 BOOL used;
325 } NameEntry;
326
327 struct CompareUsed
328 {
329 bool operator()(const NameEntry& lhs, const NameEntry& rhs)
330 {
331 return lhs.used < rhs.used; //FALSE entries first
332 }
333 };
334
335 typedef std::vector<NameEntry> name_list_t;
336 name_list_t mNameList;
337
338 LLGLNamePool();
339 virtual ~LLGLNamePool();
340
341 void upkeep();
342 void cleanup();
343
344 GLuint allocate();
345 void release(GLuint name);
346
347 static void registerPool(LLGLNamePool* pool);
348 static void upkeepPools();
349 static void cleanupPools();
350
351protected:
352 typedef std::vector<LLGLNamePool*> pool_list_t;
353 static pool_list_t sInstances;
354
355 virtual GLuint allocateName() = 0;
356 virtual void releaseName(GLuint name) = 0;
357};
358
359extern LLMatrix4 gGLObliqueProjectionInverse;
360
361#include "llglstates.h"
362
363void init_glstates();
364void enable_vertex_weighting(const S32 index);
365void disable_vertex_weighting(const S32 index);
366void enable_binormals(const S32 index);
367void disable_binormals(const S32 index);
368void enable_cloth_weights(const S32 index);
369void disable_cloth_weights(const S32 index);
370void set_vertex_weights(const S32 index, const U32 stride, const F32 *weights);
371void set_vertex_clothing_weights(const S32 index, const U32 stride, const LLVector4 *weights);
372void set_binormals(const S32 index, const U32 stride, const LLVector3 *binormals);
373void set_palette(U8* palette_data);
374void parse_gl_version( S32* major, S32* minor, S32* release, std::string* vendor_specific );
375
376extern BOOL gClothRipple;
377extern BOOL gNoRender;
378#endif // LL_LLGL_H