aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llwindow/llgl.h
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llwindow/llgl.h')
-rw-r--r--linden/indra/llwindow/llgl.h272
1 files changed, 272 insertions, 0 deletions
diff --git a/linden/indra/llwindow/llgl.h b/linden/indra/llwindow/llgl.h
new file mode 100644
index 0000000..1c93b63
--- /dev/null
+++ b/linden/indra/llwindow/llgl.h
@@ -0,0 +1,272 @@
1/**
2 * @file llgl.h
3 * @brief LLGL definition
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#ifndef LL_LLGL_H
29#define LL_LLGL_H
30
31// This file contains various stuff for handling gl extensions and other gl related stuff.
32
33#include <string>
34#include <map>
35
36#include "llerror.h"
37#include "v4color.h"
38#include "llstring.h"
39#include "stdtypes.h"
40#include "v4math.h"
41#include "llgltypes.h"
42
43#define LL_GL_ERRS llerrs
44
45// Manage GL extensions...
46class LLGLManager
47{
48public:
49 LLGLManager();
50
51 bool initGL();
52 void shutdownGL();
53
54 void initWGL(); // Initializes stupid WGL extensions
55
56 LLString getRawGLString(); // For sending to simulator
57
58 BOOL mInited;
59 BOOL mIsDisabled;
60
61 // Extensions used by everyone
62 BOOL mHasMultitexture;
63 S32 mNumTextureUnits;
64 BOOL mHasMipMapGeneration;
65 BOOL mHasAnyAGP;
66 BOOL mHasPalettedTextures;
67 BOOL mHasCompressedTextures;
68
69 // ARB Extensions
70 BOOL mHasVertexBufferObject;
71 BOOL mHasPBuffer;
72 BOOL mHasShaderObjects;
73 BOOL mHasVertexShader;
74 BOOL mHasFragmentShader;
75 BOOL mHasOcclusionQuery;
76
77 // nVidia extensions.
78 BOOL mHasAnisotropic;
79 BOOL mHasNVVertexArrayRange;
80 BOOL mHasNVFence;
81 BOOL mHasARBEnvCombine;
82
83 // ATI extensions.
84 BOOL mHasATIVAO;
85 BOOL mIsRadeon8500; // Radeon 8500/9000
86 BOOL mIsRadeon9700;
87 BOOL mIsMobilityRadeon9000;
88 BOOL mIsGF2or4MX;
89 BOOL mIsGF3;
90 BOOL mIsGFFX;
91 BOOL mIsATI;
92 BOOL mATIOffsetVerticalLines;
93 BOOL mIsNVIDIA;
94 BOOL mIsIntel;
95 BOOL mHasCubeMap;
96
97#if LL_WINDOWS
98 BOOL mHasWGLARBPixelFormat;
99#endif // LL_WINDOWS
100
101#if LL_DARWIN
102 // Apple extensions.
103 BOOL mHasAPPLEVertexArrayRange;
104 BOOL mHasAPPLEFence;
105 BOOL mHasAPPLEVAO;
106#endif
107
108 // Misc exitensions
109 BOOL mHasSeparateSpecularColor;
110
111 S32 mDriverVersionMajor;
112 S32 mDriverVersionMinor;
113 S32 mDriverVersionRelease;
114 F32 mGLVersion; // e.g = 1.4
115 LLString mDriverVersionVendorString;
116
117 S32 mVRAM; // VRAM in MB
118 S32 mGLMaxVertexRange;
119 S32 mGLMaxIndexRange;
120 BOOL mSoftwareBlendSSE;
121
122 void getPixelFormat(); // Get the best pixel format
123
124 LLString getGLInfoString();
125
126 // In ALL CAPS
127 LLString mGLVendor;
128
129 // In ALL CAPS
130 LLString mGLRenderer;
131
132private:
133 void initExtensions();
134 void initGLStates();
135 void initGLImages();
136};
137
138extern LLGLManager gGLManager;
139
140class LLQuaternion;
141class LLMatrix4;
142
143void rotate_quat(LLQuaternion& rotation);
144
145void flush_glerror(); // Flush GL errors when we know we're handling them correctly.
146
147void assert_glerror();
148
149void clear_glerror();
150
151#if LL_DEBUG
152# define stop_glerror() assert_glerror()
153# define llglassertok() assert_glerror()
154#else
155# define stop_glerror()
156# define llglassertok()
157#endif
158
159#define llglassertok_always() assert_glerror()
160
161////////////////////////
162//
163// Note: U32's are GLEnum's...
164//
165
166// This is a class for GL state management
167
168/*
169 GL STATE MANAGEMENT DESCRIPTION
170
171 LLGLState and its two subclasses, LLGLEnable and LLGLDisable, manage the current
172 enable/disable states of the GL to prevent redundant setting of state within a
173 render path or the accidental corruption of what state the next path expects.
174
175 Essentially, wherever you would call glEnable set a state and then
176 subsequently reset it by calling glDisable (or vice versa), make an instance of
177 LLGLEnable with the state you want to set, and assume it will be restored to its
178 original state when that instance of LLGLEnable is destroyed. It is good practice
179 to exploit stack frame controls for optimal setting/unsetting and readability of
180 code. In llglstates.h, there are a collection of helper classes that define groups
181 of enables/disables that can cause multiple states to be set with the creation of
182 one instance.
183
184 Sample usage:
185
186 //disable lighting for rendering hud objects
187 //INCORRECT USAGE
188 LLGLEnable lighting(GL_LIGHTING);
189 renderHUD();
190 LLGLDisable lighting(GL_LIGHTING);
191
192 //CORRECT USAGE
193 {
194 LLGLEnable lighting(GL_LIGHTING);
195 renderHUD();
196 }
197
198 If a state is to be set on a conditional, the following mechanism
199 is useful:
200
201 {
202 LLGLEnable lighting(light_hud ? GL_LIGHTING : 0);
203 renderHUD();
204 }
205
206 A LLGLState initialized with a parameter of 0 does nothing.
207
208 LLGLState works by maintaining a map of the current GL states, and ignoring redundant
209 enables/disables. If a redundant call is attempted, it becomes a noop, otherwise,
210 it is set in the constructor and reset in the destructor.
211
212 For debugging GL state corruption, running with debug enabled will trigger asserts
213 if the existing GL state does not match the expected GL state.
214
215*/
216class LLGLState
217{
218public:
219 static void initClass();
220 static void restoreGL();
221
222 static void dumpStates();
223 static void checkStates();
224 static void checkTextureChannels();
225 static void checkClientArrays();
226
227protected:
228 static std::map<LLGLenum, LLGLboolean> sStateMap;
229
230public:
231 enum { CURRENT_STATE = -2 };
232 LLGLState(LLGLenum state, S32 enabled = CURRENT_STATE);
233 ~LLGLState();
234 void setEnabled(S32 enabled);
235 void enable() { setEnabled(TRUE); }
236 void disable() { setEnabled(FALSE); }
237protected:
238 LLGLenum mState;
239 BOOL mWasEnabled;
240 BOOL mIsEnabled;
241};
242
243class LLGLEnable : public LLGLState
244{
245public:
246 LLGLEnable(LLGLenum state) : LLGLState(state, TRUE) {}
247};
248
249class LLGLDisable : public LLGLState
250{
251public:
252 LLGLDisable(LLGLenum state) : LLGLState(state, FALSE) {}
253};
254
255#include "llglstates.h"
256
257void init_glstates();
258void enable_vertex_weighting(const S32 index);
259void disable_vertex_weighting(const S32 index);
260void enable_binormals(const S32 index);
261void disable_binormals(const S32 index);
262void enable_cloth_weights(const S32 index);
263void disable_cloth_weights(const S32 index);
264void set_vertex_weights(const S32 index, const F32 *weights);
265void set_vertex_clothing_weights(const S32 index, const U32 stride, const LLVector4 *weights);
266void set_binormals(const S32 index, const U32 stride, const LLVector3 *binormals);
267void set_palette(U8* palette_data);
268void parse_gl_version( S32* major, S32* minor, S32* release, LLString* vendor_specific );
269
270extern BOOL gClothRipple;
271extern BOOL gNoRender;
272#endif // LL_LLGL_H