diff options
author | Jacek Antonelli | 2008-09-06 18:24:57 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-09-06 18:25:07 -0500 |
commit | 798d367d54a6c6379ad355bd8345fa40e31e7fe9 (patch) | |
tree | 1921f1708cd0240648c97bc02df2c2ab5f2fc41e /linden/indra/llrender/llgl.h | |
parent | Second Life viewer sources 1.20.15 (diff) | |
download | meta-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.h | 378 |
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 | |||
51 | extern BOOL gDebugGL; | ||
52 | |||
53 | #define LL_GL_ERRS LL_ERRS("RenderState") | ||
54 | |||
55 | class LLSD; | ||
56 | |||
57 | // Manage GL extensions... | ||
58 | class LLGLManager | ||
59 | { | ||
60 | public: | ||
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 | |||
134 | private: | ||
135 | void initExtensions(); | ||
136 | void initGLStates(); | ||
137 | void initGLImages(); | ||
138 | }; | ||
139 | |||
140 | extern LLGLManager gGLManager; | ||
141 | |||
142 | class LLQuaternion; | ||
143 | class LLMatrix4; | ||
144 | |||
145 | void rotate_quat(LLQuaternion& rotation); | ||
146 | |||
147 | void flush_glerror(); // Flush GL errors when we know we're handling them correctly. | ||
148 | |||
149 | void assert_glerror(); | ||
150 | |||
151 | void 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 | */ | ||
218 | class LLGLState | ||
219 | { | ||
220 | public: | ||
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 | |||
230 | protected: | ||
231 | static std::map<LLGLenum, LLGLboolean> sStateMap; | ||
232 | |||
233 | public: | ||
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); } | ||
240 | protected: | ||
241 | LLGLenum mState; | ||
242 | BOOL mWasEnabled; | ||
243 | BOOL mIsEnabled; | ||
244 | }; | ||
245 | |||
246 | // New LLGLState class wrappers that don't depend on actual GL flags. | ||
247 | class LLGLEnableBlending : public LLGLState | ||
248 | { | ||
249 | public: | ||
250 | LLGLEnableBlending(bool enable); | ||
251 | }; | ||
252 | |||
253 | class LLGLEnableAlphaReject : public LLGLState | ||
254 | { | ||
255 | public: | ||
256 | LLGLEnableAlphaReject(bool enable); | ||
257 | }; | ||
258 | |||
259 | /// TODO: Being deprecated. | ||
260 | class LLGLEnable : public LLGLState | ||
261 | { | ||
262 | public: | ||
263 | LLGLEnable(LLGLenum state) : LLGLState(state, TRUE) {} | ||
264 | }; | ||
265 | |||
266 | /// TODO: Being deprecated. | ||
267 | class LLGLDisable : public LLGLState | ||
268 | { | ||
269 | public: | ||
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 | */ | ||
285 | class LLGLUserClipPlane | ||
286 | { | ||
287 | public: | ||
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 | |||
294 | private: | ||
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 | */ | ||
307 | class LLGLClampToFarClip | ||
308 | { | ||
309 | public: | ||
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 | */ | ||
318 | class LLGLNamePool | ||
319 | { | ||
320 | public: | ||
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 | |||
351 | protected: | ||
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 | |||
359 | extern LLMatrix4 gGLObliqueProjectionInverse; | ||
360 | |||
361 | #include "llglstates.h" | ||
362 | |||
363 | void init_glstates(); | ||
364 | void enable_vertex_weighting(const S32 index); | ||
365 | void disable_vertex_weighting(const S32 index); | ||
366 | void enable_binormals(const S32 index); | ||
367 | void disable_binormals(const S32 index); | ||
368 | void enable_cloth_weights(const S32 index); | ||
369 | void disable_cloth_weights(const S32 index); | ||
370 | void set_vertex_weights(const S32 index, const U32 stride, const F32 *weights); | ||
371 | void set_vertex_clothing_weights(const S32 index, const U32 stride, const LLVector4 *weights); | ||
372 | void set_binormals(const S32 index, const U32 stride, const LLVector3 *binormals); | ||
373 | void set_palette(U8* palette_data); | ||
374 | void parse_gl_version( S32* major, S32* minor, S32* release, std::string* vendor_specific ); | ||
375 | |||
376 | extern BOOL gClothRipple; | ||
377 | extern BOOL gNoRender; | ||
378 | #endif // LL_LLGL_H | ||