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 | |
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')
33 files changed, 6873 insertions, 984 deletions
diff --git a/linden/indra/llrender/CMakeLists.txt b/linden/indra/llrender/CMakeLists.txt new file mode 100644 index 0000000..76858d9 --- /dev/null +++ b/linden/indra/llrender/CMakeLists.txt | |||
@@ -0,0 +1,83 @@ | |||
1 | # -*- cmake -*- | ||
2 | |||
3 | project(llrender) | ||
4 | |||
5 | include(00-Common) | ||
6 | include(FreeType) | ||
7 | include(LLCommon) | ||
8 | include(LLImage) | ||
9 | include(LLMath) | ||
10 | include(LLRender) | ||
11 | include(LLWindow) | ||
12 | |||
13 | include_directories( | ||
14 | ${FREETYPE_INCLUDE_DIRS} | ||
15 | ${LLCOMMON_INCLUDE_DIRS} | ||
16 | ${LLIMAGE_INCLUDE_DIRS} | ||
17 | ${LLMATH_INCLUDE_DIRS} | ||
18 | ${LLRENDER_INCLUDE_DIRS} | ||
19 | ${LLWINDOW_INCLUDE_DIRS} | ||
20 | ) | ||
21 | |||
22 | set(llrender_SOURCE_FILES | ||
23 | llcubemap.cpp | ||
24 | llfont.cpp | ||
25 | llfontgl.cpp | ||
26 | llgldbg.cpp | ||
27 | llglslshader.cpp | ||
28 | llimagegl.cpp | ||
29 | llpostprocess.cpp | ||
30 | llrender.cpp | ||
31 | llrendersphere.cpp | ||
32 | llrendertarget.cpp | ||
33 | llshadermgr.cpp | ||
34 | llvertexbuffer.cpp | ||
35 | ) | ||
36 | |||
37 | set(llrender_HEADER_FILES | ||
38 | CMakeLists.txt | ||
39 | |||
40 | llcubemap.h | ||
41 | llfontgl.h | ||
42 | llfont.h | ||
43 | llgl.h | ||
44 | llgldbg.h | ||
45 | llglheaders.h | ||
46 | llglslshader.h | ||
47 | llglstates.h | ||
48 | llgltypes.h | ||
49 | llimagegl.h | ||
50 | llpostprocess.h | ||
51 | llrender.h | ||
52 | llrendersphere.h | ||
53 | llrendertarget.h | ||
54 | llshadermgr.h | ||
55 | llvertexbuffer.h | ||
56 | ) | ||
57 | |||
58 | set_source_files_properties(${llrender_HEADER_FILES} | ||
59 | PROPERTIES HEADER_FILE_ONLY TRUE) | ||
60 | |||
61 | list(APPEND llrender_SOURCE_FILES ${llrender_HEADER_FILES}) | ||
62 | |||
63 | if (SERVER AND NOT WINDOWS AND NOT DARWIN) | ||
64 | copy_server_sources( | ||
65 | llgl | ||
66 | ) | ||
67 | |||
68 | |||
69 | set_source_files_properties( | ||
70 | ${server_SOURCE_FILES} | ||
71 | PROPERTIES | ||
72 | COMPILE_FLAGS "-DLL_MESA=1 -DLL_MESA_HEADLESS=1" | ||
73 | ) | ||
74 | add_library (llrenderheadless | ||
75 | ${llrender_SOURCE_FILES} | ||
76 | ${server_SOURCE_FILES} | ||
77 | ) | ||
78 | else (SERVER AND NOT WINDOWS AND NOT DARWIN) | ||
79 | list(APPEND llrender_SOURCE_FILES | ||
80 | llgl.cpp | ||
81 | ) | ||
82 | endif (SERVER AND NOT WINDOWS AND NOT DARWIN) | ||
83 | add_library (llrender ${llrender_SOURCE_FILES}) | ||
diff --git a/linden/indra/llrender/files.darwin.lst b/linden/indra/llrender/files.darwin.lst deleted file mode 100644 index 2d27570..0000000 --- a/linden/indra/llrender/files.darwin.lst +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | llrender/llagpmempoolapple.cpp | ||
diff --git a/linden/indra/llrender/files.lst b/linden/indra/llrender/files.lst deleted file mode 100644 index 5dc9579..0000000 --- a/linden/indra/llrender/files.lst +++ /dev/null | |||
@@ -1,7 +0,0 @@ | |||
1 | llrender/llfont.cpp | ||
2 | llrender/llfontgl.cpp | ||
3 | llrender/llgldbg.cpp | ||
4 | llrender/llrender.cpp | ||
5 | llrender/llimagegl.cpp | ||
6 | llrender/llrendertarget.cpp | ||
7 | llrender/llvertexbuffer.cpp | ||
diff --git a/linden/indra/llrender/llcubemap.cpp b/linden/indra/llrender/llcubemap.cpp new file mode 100644 index 0000000..563d616 --- /dev/null +++ b/linden/indra/llrender/llcubemap.cpp | |||
@@ -0,0 +1,532 @@ | |||
1 | /** | ||
2 | * @file llcubemap.cpp | ||
3 | * @brief LLCubeMap class implementation | ||
4 | * | ||
5 | * $LicenseInfo:firstyear=2002&license=viewergpl$ | ||
6 | * | ||
7 | * Copyright (c) 2002-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 | #include "linden_common.h" | ||
32 | |||
33 | #include "llworkerthread.h" | ||
34 | |||
35 | #include "llcubemap.h" | ||
36 | |||
37 | #include "v4coloru.h" | ||
38 | #include "v3math.h" | ||
39 | #include "v3dmath.h" | ||
40 | #include "m3math.h" | ||
41 | #include "m4math.h" | ||
42 | #include "llcamera.h" | ||
43 | |||
44 | #include "llrender.h" | ||
45 | |||
46 | #include "llglheaders.h" | ||
47 | |||
48 | const F32 epsilon = 1e-7f; | ||
49 | const U16 RESOLUTION = 64; | ||
50 | |||
51 | #if LL_DARWIN | ||
52 | // mipmap generation on cubemap textures seems to be broken on the Mac for at least some cards. | ||
53 | // Since the cubemap is small (64x64 per face) and doesn't have any fine detail, turning off mipmaps is a usable workaround. | ||
54 | const BOOL use_cube_mipmaps = FALSE; | ||
55 | #else | ||
56 | const BOOL use_cube_mipmaps = FALSE; //current build works best without cube mipmaps | ||
57 | #endif | ||
58 | |||
59 | bool LLCubeMap::sUseCubeMaps = true; | ||
60 | |||
61 | LLCubeMap::LLCubeMap() | ||
62 | : mTextureStage(0), | ||
63 | mTextureCoordStage(0), | ||
64 | mMatrixStage(0) | ||
65 | { | ||
66 | } | ||
67 | |||
68 | LLCubeMap::~LLCubeMap() | ||
69 | { | ||
70 | } | ||
71 | |||
72 | void LLCubeMap::initGL() | ||
73 | { | ||
74 | llassert(gGLManager.mInited); | ||
75 | |||
76 | if (gGLManager.mHasCubeMap && LLCubeMap::sUseCubeMaps) | ||
77 | { | ||
78 | mTargets[0] = GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB; | ||
79 | mTargets[1] = GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB; | ||
80 | mTargets[2] = GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB; | ||
81 | mTargets[3] = GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB; | ||
82 | mTargets[4] = GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB; | ||
83 | mTargets[5] = GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB; | ||
84 | |||
85 | // Not initialized, do stuff. | ||
86 | if (mImages[0].isNull()) | ||
87 | { | ||
88 | GLuint texname = 0; | ||
89 | |||
90 | glGenTextures(1, &texname); | ||
91 | |||
92 | for (int i = 0; i < 6; i++) | ||
93 | { | ||
94 | mImages[i] = new LLImageGL(64, 64, 4, (use_cube_mipmaps? TRUE : FALSE)); | ||
95 | mImages[i]->setTarget(mTargets[i], GL_TEXTURE_CUBE_MAP_ARB); | ||
96 | mRawImages[i] = new LLImageRaw(64, 64, 4); | ||
97 | mImages[i]->createGLTexture(0, mRawImages[i], texname); | ||
98 | |||
99 | glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, texname); | ||
100 | mImages[i]->setClampCubemap (TRUE, TRUE, TRUE); | ||
101 | stop_glerror(); | ||
102 | } | ||
103 | } | ||
104 | disable(); | ||
105 | } | ||
106 | else | ||
107 | { | ||
108 | llwarns << "Using cube map without extension!" << llendl | ||
109 | } | ||
110 | } | ||
111 | |||
112 | void LLCubeMap::initRawData(const std::vector<LLPointer<LLImageRaw> >& rawimages) | ||
113 | { | ||
114 | bool flip_x[6] = { false, true, false, false, true, false }; | ||
115 | bool flip_y[6] = { true, true, true, false, true, true }; | ||
116 | bool transpose[6] = { false, false, false, false, true, true }; | ||
117 | |||
118 | // Yes, I know that this is inefficient! - djs 08/08/02 | ||
119 | for (int i = 0; i < 6; i++) | ||
120 | { | ||
121 | const U8 *sd = rawimages[i]->getData(); | ||
122 | U8 *td = mRawImages[i]->getData(); | ||
123 | |||
124 | S32 offset = 0; | ||
125 | S32 sx, sy, so; | ||
126 | for (int y = 0; y < 64; y++) | ||
127 | { | ||
128 | for (int x = 0; x < 64; x++) | ||
129 | { | ||
130 | sx = x; | ||
131 | sy = y; | ||
132 | if (flip_y[i]) | ||
133 | { | ||
134 | sy = 63 - y; | ||
135 | } | ||
136 | if (flip_x[i]) | ||
137 | { | ||
138 | sx = 63 - x; | ||
139 | } | ||
140 | if (transpose[i]) | ||
141 | { | ||
142 | S32 temp = sx; | ||
143 | sx = sy; | ||
144 | sy = temp; | ||
145 | } | ||
146 | |||
147 | so = 64*sy + sx; | ||
148 | so *= 4; | ||
149 | *(td + offset++) = *(sd + so++); | ||
150 | *(td + offset++) = *(sd + so++); | ||
151 | *(td + offset++) = *(sd + so++); | ||
152 | *(td + offset++) = *(sd + so++); | ||
153 | } | ||
154 | } | ||
155 | } | ||
156 | } | ||
157 | |||
158 | void LLCubeMap::initGLData() | ||
159 | { | ||
160 | for (int i = 0; i < 6; i++) | ||
161 | { | ||
162 | mImages[i]->setSubImage(mRawImages[i], 0, 0, 64, 64); | ||
163 | } | ||
164 | } | ||
165 | |||
166 | void LLCubeMap::init(const std::vector<LLPointer<LLImageRaw> >& rawimages) | ||
167 | { | ||
168 | if (!gGLManager.mIsDisabled) | ||
169 | { | ||
170 | initGL(); | ||
171 | initRawData(rawimages); | ||
172 | initGLData(); | ||
173 | } | ||
174 | } | ||
175 | |||
176 | GLuint LLCubeMap::getGLName() | ||
177 | { | ||
178 | return mImages[0]->getTexName(); | ||
179 | } | ||
180 | |||
181 | void LLCubeMap::bind() | ||
182 | { | ||
183 | if (gGLManager.mHasCubeMap && LLCubeMap::sUseCubeMaps) | ||
184 | { | ||
185 | // We assume that if they have cube mapping, they have multitexturing. | ||
186 | if (mTextureStage > 0) | ||
187 | { | ||
188 | gGL.getTexUnit(mTextureStage)->activate(); | ||
189 | } | ||
190 | glEnable(GL_TEXTURE_CUBE_MAP_ARB); | ||
191 | glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, mImages[0]->getTexName()); | ||
192 | |||
193 | mImages[0]->setMipFilterNearest (FALSE, FALSE); | ||
194 | if (mTextureStage > 0) | ||
195 | { | ||
196 | gGL.getTexUnit(0)->activate(); | ||
197 | } | ||
198 | } | ||
199 | else | ||
200 | { | ||
201 | llwarns << "Using cube map without extension!" << llendl | ||
202 | } | ||
203 | } | ||
204 | |||
205 | void LLCubeMap::enable(S32 stage) | ||
206 | { | ||
207 | enableTexture(stage); | ||
208 | enableTextureCoords(stage); | ||
209 | } | ||
210 | |||
211 | void LLCubeMap::enableTexture(S32 stage) | ||
212 | { | ||
213 | mTextureStage = stage; | ||
214 | if (gGLManager.mHasCubeMap && stage >= 0 && LLCubeMap::sUseCubeMaps) | ||
215 | { | ||
216 | if (stage > 0) | ||
217 | { | ||
218 | gGL.getTexUnit(stage)->activate(); | ||
219 | } | ||
220 | |||
221 | glEnable(GL_TEXTURE_CUBE_MAP_ARB); | ||
222 | |||
223 | if (stage > 0) | ||
224 | { | ||
225 | gGL.getTexUnit(0)->activate(); | ||
226 | } | ||
227 | } | ||
228 | } | ||
229 | |||
230 | void LLCubeMap::enableTextureCoords(S32 stage) | ||
231 | { | ||
232 | mTextureCoordStage = stage; | ||
233 | if (gGLManager.mHasCubeMap && stage >= 0 && LLCubeMap::sUseCubeMaps) | ||
234 | { | ||
235 | if (stage > 0) | ||
236 | { | ||
237 | gGL.getTexUnit(stage)->activate(); | ||
238 | } | ||
239 | |||
240 | glEnable(GL_TEXTURE_GEN_R); | ||
241 | glEnable(GL_TEXTURE_GEN_S); | ||
242 | glEnable(GL_TEXTURE_GEN_T); | ||
243 | |||
244 | glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP); | ||
245 | glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP); | ||
246 | glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP); | ||
247 | |||
248 | if (stage > 0) | ||
249 | { | ||
250 | gGL.getTexUnit(0)->activate(); | ||
251 | } | ||
252 | } | ||
253 | } | ||
254 | |||
255 | void LLCubeMap::disable(void) | ||
256 | { | ||
257 | disableTexture(); | ||
258 | disableTextureCoords(); | ||
259 | } | ||
260 | |||
261 | void LLCubeMap::disableTexture(void) | ||
262 | { | ||
263 | if (gGLManager.mHasCubeMap && mTextureStage >= 0 && LLCubeMap::sUseCubeMaps) | ||
264 | { | ||
265 | if (mTextureStage > 0) | ||
266 | { | ||
267 | gGL.getTexUnit(mTextureStage)->activate(); | ||
268 | } | ||
269 | glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, 0); | ||
270 | glDisable(GL_TEXTURE_CUBE_MAP_ARB); | ||
271 | if (mTextureStage > 0) | ||
272 | { | ||
273 | gGL.getTexUnit(0)->activate(); | ||
274 | } | ||
275 | } | ||
276 | } | ||
277 | |||
278 | void LLCubeMap::disableTextureCoords(void) | ||
279 | { | ||
280 | if (gGLManager.mHasCubeMap && mTextureCoordStage >= 0 && LLCubeMap::sUseCubeMaps) | ||
281 | { | ||
282 | if (mTextureCoordStage > 0) | ||
283 | { | ||
284 | gGL.getTexUnit(mTextureCoordStage)->activate(); | ||
285 | } | ||
286 | glDisable(GL_TEXTURE_GEN_S); | ||
287 | glDisable(GL_TEXTURE_GEN_T); | ||
288 | glDisable(GL_TEXTURE_GEN_R); | ||
289 | if (mTextureCoordStage > 0) | ||
290 | { | ||
291 | gGL.getTexUnit(0)->activate(); | ||
292 | } | ||
293 | } | ||
294 | } | ||
295 | |||
296 | void LLCubeMap::setMatrix(S32 stage) | ||
297 | { | ||
298 | mMatrixStage = stage; | ||
299 | |||
300 | if (stage > 0) | ||
301 | { | ||
302 | gGL.getTexUnit(stage)->activate(); | ||
303 | } | ||
304 | |||
305 | LLVector3 x(LLVector3d(gGLModelView+0)); | ||
306 | LLVector3 y(LLVector3d(gGLModelView+4)); | ||
307 | LLVector3 z(LLVector3d(gGLModelView+8)); | ||
308 | |||
309 | LLMatrix3 mat3; | ||
310 | mat3.setRows(x,y,z); | ||
311 | LLMatrix4 trans(mat3); | ||
312 | trans.transpose(); | ||
313 | |||
314 | glMatrixMode(GL_TEXTURE); | ||
315 | glPushMatrix(); | ||
316 | glLoadMatrixf((F32 *)trans.mMatrix); | ||
317 | glMatrixMode(GL_MODELVIEW); | ||
318 | |||
319 | if (stage > 0) | ||
320 | { | ||
321 | gGL.getTexUnit(0)->activate(); | ||
322 | } | ||
323 | } | ||
324 | |||
325 | void LLCubeMap::restoreMatrix() | ||
326 | { | ||
327 | if (mMatrixStage > 0) | ||
328 | { | ||
329 | gGL.getTexUnit(mMatrixStage)->activate(); | ||
330 | } | ||
331 | glMatrixMode(GL_TEXTURE); | ||
332 | glPopMatrix(); | ||
333 | glMatrixMode(GL_MODELVIEW); | ||
334 | |||
335 | if (mMatrixStage > 0) | ||
336 | { | ||
337 | gGL.getTexUnit(0)->activate(); | ||
338 | } | ||
339 | } | ||
340 | |||
341 | void LLCubeMap::setReflection (void) | ||
342 | { | ||
343 | glBindTexture (GL_TEXTURE_CUBE_MAP_ARB, getGLName()); | ||
344 | mImages[0]->setMipFilterNearest (FALSE, FALSE); | ||
345 | mImages[0]->setClampCubemap (TRUE, TRUE); | ||
346 | } | ||
347 | |||
348 | LLVector3 LLCubeMap::map(U8 side, U16 v_val, U16 h_val) const | ||
349 | { | ||
350 | LLVector3 dir; | ||
351 | |||
352 | const U8 curr_coef = side >> 1; // 0/1 = X axis, 2/3 = Y, 4/5 = Z | ||
353 | const S8 side_dir = (((side & 1) << 1) - 1); // even = -1, odd = 1 | ||
354 | const U8 i_coef = (curr_coef + 1) % 3; | ||
355 | const U8 j_coef = (i_coef + 1) % 3; | ||
356 | |||
357 | dir.mV[curr_coef] = side_dir; | ||
358 | |||
359 | switch (side) | ||
360 | { | ||
361 | case 0: // negative X | ||
362 | dir.mV[i_coef] = -F32((v_val<<1) + 1) / RESOLUTION + 1; | ||
363 | dir.mV[j_coef] = F32((h_val<<1) + 1) / RESOLUTION - 1; | ||
364 | break; | ||
365 | case 1: // positive X | ||
366 | dir.mV[i_coef] = -F32((v_val<<1) + 1) / RESOLUTION + 1; | ||
367 | dir.mV[j_coef] = -F32((h_val<<1) + 1) / RESOLUTION + 1; | ||
368 | break; | ||
369 | case 2: // negative Y | ||
370 | dir.mV[i_coef] = -F32((v_val<<1) + 1) / RESOLUTION + 1; | ||
371 | dir.mV[j_coef] = F32((h_val<<1) + 1) / RESOLUTION - 1; | ||
372 | break; | ||
373 | case 3: // positive Y | ||
374 | dir.mV[i_coef] = F32((v_val<<1) + 1) / RESOLUTION - 1; | ||
375 | dir.mV[j_coef] = F32((h_val<<1) + 1) / RESOLUTION - 1; | ||
376 | break; | ||
377 | case 4: // negative Z | ||
378 | dir.mV[i_coef] = -F32((h_val<<1) + 1) / RESOLUTION + 1; | ||
379 | dir.mV[j_coef] = -F32((v_val<<1) + 1) / RESOLUTION + 1; | ||
380 | break; | ||
381 | case 5: // positive Z | ||
382 | dir.mV[i_coef] = -F32((h_val<<1) + 1) / RESOLUTION + 1; | ||
383 | dir.mV[j_coef] = F32((v_val<<1) + 1) / RESOLUTION - 1; | ||
384 | break; | ||
385 | default: | ||
386 | dir.mV[i_coef] = F32((v_val<<1) + 1) / RESOLUTION - 1; | ||
387 | dir.mV[j_coef] = F32((h_val<<1) + 1) / RESOLUTION - 1; | ||
388 | } | ||
389 | |||
390 | dir.normVec(); | ||
391 | return dir; | ||
392 | } | ||
393 | |||
394 | |||
395 | BOOL LLCubeMap::project(F32& v_val, F32& h_val, BOOL& outside, | ||
396 | U8 side, const LLVector3& dir) const | ||
397 | { | ||
398 | const U8 curr_coef = side >> 1; // 0/1 = X axis, 2/3 = Y, 4/5 = Z | ||
399 | const S8 side_dir = (((side & 1) << 1) - 1); // even = -1, odd = 1 | ||
400 | const U8 i_coef = (curr_coef + 1) % 3; | ||
401 | const U8 j_coef = (i_coef + 1) % 3; | ||
402 | |||
403 | outside = TRUE; | ||
404 | if (side_dir * dir.mV[curr_coef] < 0) | ||
405 | return FALSE; | ||
406 | |||
407 | LLVector3 ray; | ||
408 | |||
409 | F32 norm_val = fabs(dir.mV[curr_coef]); | ||
410 | |||
411 | if (norm_val < epsilon) | ||
412 | norm_val = 1e-5f; | ||
413 | |||
414 | ray.mV[curr_coef] = side_dir; | ||
415 | ray.mV[i_coef] = dir.mV[i_coef] / norm_val; | ||
416 | ray.mV[j_coef] = dir.mV[j_coef] / norm_val; | ||
417 | |||
418 | |||
419 | const F32 i_val = (ray.mV[i_coef] + 1) * 0.5f * RESOLUTION; | ||
420 | const F32 j_val = (ray.mV[j_coef] + 1) * 0.5f * RESOLUTION; | ||
421 | |||
422 | switch (side) | ||
423 | { | ||
424 | case 0: // negative X | ||
425 | v_val = RESOLUTION - i_val; | ||
426 | h_val = j_val; | ||
427 | break; | ||
428 | case 1: // positive X | ||
429 | v_val = RESOLUTION - i_val; | ||
430 | h_val = RESOLUTION - j_val; | ||
431 | break; | ||
432 | case 2: // negative Y | ||
433 | v_val = RESOLUTION - i_val; | ||
434 | h_val = j_val; | ||
435 | break; | ||
436 | case 3: // positive Y | ||
437 | v_val = i_val; | ||
438 | h_val = j_val; | ||
439 | break; | ||
440 | case 4: // negative Z | ||
441 | v_val = RESOLUTION - j_val; | ||
442 | h_val = RESOLUTION - i_val; | ||
443 | break; | ||
444 | case 5: // positive Z | ||
445 | v_val = RESOLUTION - j_val; | ||
446 | h_val = i_val; | ||
447 | break; | ||
448 | default: | ||
449 | v_val = i_val; | ||
450 | h_val = j_val; | ||
451 | } | ||
452 | |||
453 | outside = ((v_val < 0) || (v_val > RESOLUTION) || | ||
454 | (h_val < 0) || (h_val > RESOLUTION)); | ||
455 | |||
456 | return TRUE; | ||
457 | } | ||
458 | |||
459 | BOOL LLCubeMap::project(F32& v_min, F32& v_max, F32& h_min, F32& h_max, | ||
460 | U8 side, LLVector3 dir[4]) const | ||
461 | { | ||
462 | v_min = h_min = RESOLUTION; | ||
463 | v_max = h_max = 0; | ||
464 | |||
465 | BOOL fully_outside = TRUE; | ||
466 | for (U8 vtx = 0; vtx < 4; ++vtx) | ||
467 | { | ||
468 | F32 v_val, h_val; | ||
469 | BOOL outside; | ||
470 | BOOL consider = project(v_val, h_val, outside, side, dir[vtx]); | ||
471 | if (!outside) | ||
472 | fully_outside = FALSE; | ||
473 | if (consider) | ||
474 | { | ||
475 | if (v_val < v_min) v_min = v_val; | ||
476 | if (v_val > v_max) v_max = v_val; | ||
477 | if (h_val < h_min) h_min = h_val; | ||
478 | if (h_val > h_max) h_max = h_val; | ||
479 | } | ||
480 | } | ||
481 | |||
482 | v_min = llmax(0.0f, v_min); | ||
483 | v_max = llmin(RESOLUTION - epsilon, v_max); | ||
484 | h_min = llmax(0.0f, h_min); | ||
485 | h_max = llmin(RESOLUTION - epsilon, h_max); | ||
486 | |||
487 | return !fully_outside; | ||
488 | } | ||
489 | |||
490 | |||
491 | void LLCubeMap::paintIn(LLVector3 dir[4], const LLColor4U& col) | ||
492 | { | ||
493 | F32 v_min, v_max, h_min, h_max; | ||
494 | LLVector3 center = dir[0] + dir[1] + dir[2] + dir[3]; | ||
495 | center.normVec(); | ||
496 | |||
497 | for (U8 side = 0; side < 6; ++side) | ||
498 | { | ||
499 | if (!project(v_min, v_max, h_min, h_max, side, dir)) | ||
500 | continue; | ||
501 | |||
502 | U8 *td = mRawImages[side]->getData(); | ||
503 | |||
504 | U16 v_minu = (U16) v_min; | ||
505 | U16 v_maxu = (U16) (ceil(v_max) + 0.5); | ||
506 | U16 h_minu = (U16) h_min; | ||
507 | U16 h_maxu = (U16) (ceil(h_max) + 0.5); | ||
508 | |||
509 | for (U16 v = v_minu; v < v_maxu; ++v) | ||
510 | for (U16 h = h_minu; h < h_maxu; ++h) | ||
511 | //for (U16 v = 0; v < RESOLUTION; ++v) | ||
512 | // for (U16 h = 0; h < RESOLUTION; ++h) | ||
513 | { | ||
514 | const LLVector3 ray = map(side, v, h); | ||
515 | if (ray * center > 0.999) | ||
516 | { | ||
517 | const U32 offset = (RESOLUTION * v + h) * 4; | ||
518 | for (U8 cc = 0; cc < 3; ++cc) | ||
519 | td[offset + cc] = U8((td[offset + cc] + col.mV[cc]) * 0.5); | ||
520 | } | ||
521 | } | ||
522 | mImages[side]->setSubImage(mRawImages[side], 0, 0, 64, 64); | ||
523 | } | ||
524 | } | ||
525 | |||
526 | void LLCubeMap::destroyGL() | ||
527 | { | ||
528 | for (S32 i = 0; i < 6; i++) | ||
529 | { | ||
530 | mImages[i] = NULL; | ||
531 | } | ||
532 | } | ||
diff --git a/linden/indra/llrender/llcubemap.h b/linden/indra/llrender/llcubemap.h new file mode 100644 index 0000000..45bfa16 --- /dev/null +++ b/linden/indra/llrender/llcubemap.h | |||
@@ -0,0 +1,89 @@ | |||
1 | /** | ||
2 | * @file llcubemap.h | ||
3 | * @brief LLCubeMap class definition | ||
4 | * | ||
5 | * $LicenseInfo:firstyear=2002&license=viewergpl$ | ||
6 | * | ||
7 | * Copyright (c) 2002-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_LLCUBEMAP_H | ||
33 | #define LL_LLCUBEMAP_H | ||
34 | |||
35 | #include "llgl.h" | ||
36 | |||
37 | #include <vector> | ||
38 | |||
39 | class LLVector3; | ||
40 | |||
41 | // Environment map hack! | ||
42 | class LLCubeMap : public LLRefCount | ||
43 | { | ||
44 | public: | ||
45 | LLCubeMap(); | ||
46 | void init(const std::vector<LLPointer<LLImageRaw> >& rawimages); | ||
47 | void initGL(); | ||
48 | void initRawData(const std::vector<LLPointer<LLImageRaw> >& rawimages); | ||
49 | void initGLData(); | ||
50 | |||
51 | void bind(); | ||
52 | void enable(S32 stage); | ||
53 | |||
54 | void enableTexture(S32 stage); | ||
55 | void enableTextureCoords(S32 stage); | ||
56 | |||
57 | void disable(void); | ||
58 | void disableTexture(void); | ||
59 | void disableTextureCoords(void); | ||
60 | void setMatrix(S32 stage); | ||
61 | void restoreMatrix(); | ||
62 | void setReflection (void); | ||
63 | |||
64 | void finishPaint(); | ||
65 | |||
66 | GLuint getGLName(); | ||
67 | |||
68 | LLVector3 map(U8 side, U16 v_val, U16 h_val) const; | ||
69 | BOOL project(F32& v_val, F32& h_val, BOOL& outside, | ||
70 | U8 side, const LLVector3& dir) const; | ||
71 | BOOL project(F32& v_min, F32& v_max, F32& h_min, F32& h_max, | ||
72 | U8 side, LLVector3 dir[4]) const; | ||
73 | void paintIn(LLVector3 dir[4], const LLColor4U& col); | ||
74 | void destroyGL(); | ||
75 | |||
76 | public: | ||
77 | static bool sUseCubeMaps; | ||
78 | |||
79 | protected: | ||
80 | ~LLCubeMap(); | ||
81 | LLGLenum mTargets[6]; | ||
82 | LLPointer<LLImageGL> mImages[6]; | ||
83 | LLPointer<LLImageRaw> mRawImages[6]; | ||
84 | S32 mTextureStage; | ||
85 | S32 mTextureCoordStage; | ||
86 | S32 mMatrixStage; | ||
87 | }; | ||
88 | |||
89 | #endif | ||
diff --git a/linden/indra/llrender/llfont.h b/linden/indra/llrender/llfont.h index 071e508..d937dfd 100644 --- a/linden/indra/llrender/llfont.h +++ b/linden/indra/llrender/llfont.h | |||
@@ -121,11 +121,11 @@ public: | |||
121 | // ^ ^ | 121 | // ^ ^ |
122 | // | | | 122 | // | | |
123 | // xxx x |Ascender | 123 | // xxx x |Ascender |
124 | // x x | | | 124 | // x x v | |
125 | // --------- xxxx-------------- Baseline | 125 | // --------- xxxx-------------- Baseline |
126 | // ^ x | | | 126 | // ^ x | |
127 | // | descender x | | | 127 | // | Descender x | |
128 | // v xxxx v |LineHeight | 128 | // v xxxx |LineHeight |
129 | // ----------------------- | | 129 | // ----------------------- | |
130 | // v | 130 | // v |
131 | // ------------------------------ | 131 | // ------------------------------ |
diff --git a/linden/indra/llrender/llfontgl.cpp b/linden/indra/llrender/llfontgl.cpp index 253bf50..a328196 100644 --- a/linden/indra/llrender/llfontgl.cpp +++ b/linden/indra/llrender/llfontgl.cpp | |||
@@ -48,7 +48,7 @@ F32 LLFontGL::sHorizDPI = 96.f; | |||
48 | F32 LLFontGL::sScaleX = 1.f; | 48 | F32 LLFontGL::sScaleX = 1.f; |
49 | F32 LLFontGL::sScaleY = 1.f; | 49 | F32 LLFontGL::sScaleY = 1.f; |
50 | BOOL LLFontGL::sDisplayFont = TRUE ; | 50 | BOOL LLFontGL::sDisplayFont = TRUE ; |
51 | LLString LLFontGL::sAppDir; | 51 | std::string LLFontGL::sAppDir; |
52 | 52 | ||
53 | LLFontGL* LLFontGL::sMonospace = NULL; | 53 | LLFontGL* LLFontGL::sMonospace = NULL; |
54 | LLFontGL* LLFontGL::sSansSerifSmall = NULL; | 54 | LLFontGL* LLFontGL::sSansSerifSmall = NULL; |
@@ -93,7 +93,7 @@ F32 llfont_round_y(F32 y) | |||
93 | } | 93 | } |
94 | 94 | ||
95 | // static | 95 | // static |
96 | U8 LLFontGL::getStyleFromString(const LLString &style) | 96 | U8 LLFontGL::getStyleFromString(const std::string &style) |
97 | { | 97 | { |
98 | S32 ret = 0; | 98 | S32 ret = 0; |
99 | if (style.find("NORMAL") != style.npos) | 99 | if (style.find("NORMAL") != style.npos) |
@@ -166,9 +166,9 @@ void LLFontGL::reset() | |||
166 | } | 166 | } |
167 | 167 | ||
168 | // static | 168 | // static |
169 | LLString LLFontGL::getFontPathSystem() | 169 | std::string LLFontGL::getFontPathSystem() |
170 | { | 170 | { |
171 | LLString system_path; | 171 | std::string system_path; |
172 | 172 | ||
173 | // Try to figure out where the system's font files are stored. | 173 | // Try to figure out where the system's font files are stored. |
174 | char *system_root = NULL; | 174 | char *system_root = NULL; |
@@ -199,9 +199,9 @@ LLString LLFontGL::getFontPathSystem() | |||
199 | 199 | ||
200 | 200 | ||
201 | // static | 201 | // static |
202 | LLString LLFontGL::getFontPathLocal() | 202 | std::string LLFontGL::getFontPathLocal() |
203 | { | 203 | { |
204 | LLString local_path; | 204 | std::string local_path; |
205 | 205 | ||
206 | // Backup files if we can't load from system fonts directory. | 206 | // Backup files if we can't load from system fonts directory. |
207 | // We could store this in an end-user writable directory to allow | 207 | // We could store this in an end-user writable directory to allow |
@@ -220,10 +220,10 @@ LLString LLFontGL::getFontPathLocal() | |||
220 | } | 220 | } |
221 | 221 | ||
222 | //static | 222 | //static |
223 | bool LLFontGL::loadFaceFallback(LLFontList *fontlistp, const LLString& fontname, const F32 point_size) | 223 | bool LLFontGL::loadFaceFallback(LLFontList *fontlistp, const std::string& fontname, const F32 point_size) |
224 | { | 224 | { |
225 | LLString local_path = getFontPathLocal(); | 225 | std::string local_path = getFontPathLocal(); |
226 | LLString sys_path = getFontPathSystem(); | 226 | std::string sys_path = getFontPathSystem(); |
227 | 227 | ||
228 | // The fontname string may contain multiple font file names separated by semicolons. | 228 | // The fontname string may contain multiple font file names separated by semicolons. |
229 | // Break it apart and try loading each one, in order. | 229 | // Break it apart and try loading each one, in order. |
@@ -235,7 +235,7 @@ bool LLFontGL::loadFaceFallback(LLFontList *fontlistp, const LLString& fontname, | |||
235 | for(token_iter = tokens.begin(); token_iter != tokens.end(); ++token_iter) | 235 | for(token_iter = tokens.begin(); token_iter != tokens.end(); ++token_iter) |
236 | { | 236 | { |
237 | LLFont *fontp = new LLFont(); | 237 | LLFont *fontp = new LLFont(); |
238 | LLString font_path = local_path + *token_iter; | 238 | std::string font_path = local_path + *token_iter; |
239 | if (!fontp->loadFace(font_path, point_size, sVertDPI, sHorizDPI, 2, TRUE)) | 239 | if (!fontp->loadFace(font_path, point_size, sVertDPI, sHorizDPI, 2, TRUE)) |
240 | { | 240 | { |
241 | font_path = sys_path + *token_iter; | 241 | font_path = sys_path + *token_iter; |
@@ -258,13 +258,13 @@ bool LLFontGL::loadFaceFallback(LLFontList *fontlistp, const LLString& fontname, | |||
258 | } | 258 | } |
259 | 259 | ||
260 | //static | 260 | //static |
261 | bool LLFontGL::loadFace(LLFontGL *fontp, const LLString& fontname, const F32 point_size, LLFontList *fallback_fontp) | 261 | bool LLFontGL::loadFace(LLFontGL *fontp, const std::string& fontname, const F32 point_size, LLFontList *fallback_fontp) |
262 | { | 262 | { |
263 | LLString local_path = getFontPathLocal(); | 263 | std::string local_path = getFontPathLocal(); |
264 | LLString font_path = local_path + fontname; | 264 | std::string font_path = local_path + fontname; |
265 | if (!fontp->loadFace(font_path, point_size, sVertDPI, sHorizDPI, 2, FALSE)) | 265 | if (!fontp->loadFace(font_path, point_size, sVertDPI, sHorizDPI, 2, FALSE)) |
266 | { | 266 | { |
267 | LLString sys_path = getFontPathSystem(); | 267 | std::string sys_path = getFontPathSystem(); |
268 | font_path = sys_path + fontname; | 268 | font_path = sys_path + fontname; |
269 | if (!fontp->loadFace(font_path, point_size, sVertDPI, sHorizDPI, 2, FALSE)) | 269 | if (!fontp->loadFace(font_path, point_size, sVertDPI, sHorizDPI, 2, FALSE)) |
270 | { | 270 | { |
@@ -280,12 +280,12 @@ bool LLFontGL::loadFace(LLFontGL *fontp, const LLString& fontname, const F32 poi | |||
280 | 280 | ||
281 | // static | 281 | // static |
282 | BOOL LLFontGL::initDefaultFonts(F32 screen_dpi, F32 x_scale, F32 y_scale, | 282 | BOOL LLFontGL::initDefaultFonts(F32 screen_dpi, F32 x_scale, F32 y_scale, |
283 | const LLString& monospace_file, F32 monospace_size, | 283 | const std::string& monospace_file, F32 monospace_size, |
284 | const LLString& sansserif_file, | 284 | const std::string& sansserif_file, |
285 | const LLString& sanserif_fallback_file, F32 ss_fallback_scale, | 285 | const std::string& sanserif_fallback_file, F32 ss_fallback_scale, |
286 | F32 small_size, F32 medium_size, F32 big_size, F32 huge_size, | 286 | F32 small_size, F32 medium_size, F32 big_size, F32 huge_size, |
287 | const LLString& sansserif_bold_file, F32 bold_size, | 287 | const std::string& sansserif_bold_file, F32 bold_size, |
288 | const LLString& app_dir) | 288 | const std::string& app_dir) |
289 | { | 289 | { |
290 | BOOL failed = FALSE; | 290 | BOOL failed = FALSE; |
291 | sVertDPI = (F32)llfloor(screen_dpi * y_scale); | 291 | sVertDPI = (F32)llfloor(screen_dpi * y_scale); |
@@ -554,7 +554,7 @@ BOOL LLFontGL::addChar(const llwchar wch) | |||
554 | } | 554 | } |
555 | 555 | ||
556 | 556 | ||
557 | S32 LLFontGL::renderUTF8(const LLString &text, const S32 offset, | 557 | S32 LLFontGL::renderUTF8(const std::string &text, const S32 offset, |
558 | const F32 x, const F32 y, | 558 | const F32 x, const F32 y, |
559 | const LLColor4 &color, | 559 | const LLColor4 &color, |
560 | const HAlign halign, const VAlign valign, | 560 | const HAlign halign, const VAlign valign, |
@@ -726,7 +726,7 @@ S32 LLFontGL::render(const LLWString &wstr, | |||
726 | if (getWidthF32(wstr.c_str(), 0, max_chars) * sScaleX > scaled_max_pixels) | 726 | if (getWidthF32(wstr.c_str(), 0, max_chars) * sScaleX > scaled_max_pixels) |
727 | { | 727 | { |
728 | // use four dots for ellipsis width to generate padding | 728 | // use four dots for ellipsis width to generate padding |
729 | const LLWString dots(utf8str_to_wstring(LLString("...."))); | 729 | const LLWString dots(utf8str_to_wstring(std::string("...."))); |
730 | scaled_max_pixels = llmax(0, scaled_max_pixels - llround(getWidthF32(dots.c_str()))); | 730 | scaled_max_pixels = llmax(0, scaled_max_pixels - llround(getWidthF32(dots.c_str()))); |
731 | draw_ellipses = TRUE; | 731 | draw_ellipses = TRUE; |
732 | } | 732 | } |
@@ -879,7 +879,7 @@ S32 LLFontGL::render(const LLWString &wstr, | |||
879 | //glLoadIdentity(); | 879 | //glLoadIdentity(); |
880 | //gGL.translatef(sCurOrigin.mX, sCurOrigin.mY, 0.0f); | 880 | //gGL.translatef(sCurOrigin.mX, sCurOrigin.mY, 0.0f); |
881 | //glScalef(sScaleX, sScaleY, 1.f); | 881 | //glScalef(sScaleX, sScaleY, 1.f); |
882 | renderUTF8("...", | 882 | renderUTF8(std::string("..."), |
883 | 0, | 883 | 0, |
884 | cur_x / sScaleX, (F32)y, | 884 | cur_x / sScaleX, (F32)y, |
885 | color, | 885 | color, |
@@ -902,7 +902,7 @@ LLImageGL *LLFontGL::getImageGL() const | |||
902 | return mImageGLp; | 902 | return mImageGLp; |
903 | } | 903 | } |
904 | 904 | ||
905 | S32 LLFontGL::getWidth(const LLString& utf8text) const | 905 | S32 LLFontGL::getWidth(const std::string& utf8text) const |
906 | { | 906 | { |
907 | LLWString wtext = utf8str_to_wstring(utf8text); | 907 | LLWString wtext = utf8str_to_wstring(utf8text); |
908 | return getWidth(wtext.c_str(), 0, S32_MAX); | 908 | return getWidth(wtext.c_str(), 0, S32_MAX); |
@@ -913,7 +913,7 @@ S32 LLFontGL::getWidth(const llwchar* wchars) const | |||
913 | return getWidth(wchars, 0, S32_MAX); | 913 | return getWidth(wchars, 0, S32_MAX); |
914 | } | 914 | } |
915 | 915 | ||
916 | S32 LLFontGL::getWidth(const LLString& utf8text, const S32 begin_offset, const S32 max_chars) const | 916 | S32 LLFontGL::getWidth(const std::string& utf8text, const S32 begin_offset, const S32 max_chars) const |
917 | { | 917 | { |
918 | LLWString wtext = utf8str_to_wstring(utf8text); | 918 | LLWString wtext = utf8str_to_wstring(utf8text); |
919 | return getWidth(wtext.c_str(), begin_offset, max_chars); | 919 | return getWidth(wtext.c_str(), begin_offset, max_chars); |
@@ -925,7 +925,7 @@ S32 LLFontGL::getWidth(const llwchar* wchars, const S32 begin_offset, const S32 | |||
925 | return llround(width); | 925 | return llround(width); |
926 | } | 926 | } |
927 | 927 | ||
928 | F32 LLFontGL::getWidthF32(const LLString& utf8text) const | 928 | F32 LLFontGL::getWidthF32(const std::string& utf8text) const |
929 | { | 929 | { |
930 | LLWString wtext = utf8str_to_wstring(utf8text); | 930 | LLWString wtext = utf8str_to_wstring(utf8text); |
931 | return getWidthF32(wtext.c_str(), 0, S32_MAX); | 931 | return getWidthF32(wtext.c_str(), 0, S32_MAX); |
@@ -936,7 +936,7 @@ F32 LLFontGL::getWidthF32(const llwchar* wchars) const | |||
936 | return getWidthF32(wchars, 0, S32_MAX); | 936 | return getWidthF32(wchars, 0, S32_MAX); |
937 | } | 937 | } |
938 | 938 | ||
939 | F32 LLFontGL::getWidthF32(const LLString& utf8text, const S32 begin_offset, const S32 max_chars ) const | 939 | F32 LLFontGL::getWidthF32(const std::string& utf8text, const S32 begin_offset, const S32 max_chars ) const |
940 | { | 940 | { |
941 | LLWString wtext = utf8str_to_wstring(utf8text); | 941 | LLWString wtext = utf8str_to_wstring(utf8text); |
942 | return getWidthF32(wtext.c_str(), begin_offset, max_chars); | 942 | return getWidthF32(wtext.c_str(), begin_offset, max_chars); |
@@ -1312,7 +1312,7 @@ void LLFontGL::clearEmbeddedChars() | |||
1312 | mEmbeddedChars.clear(); | 1312 | mEmbeddedChars.clear(); |
1313 | } | 1313 | } |
1314 | 1314 | ||
1315 | void LLFontGL::addEmbeddedChar( llwchar wc, LLImageGL* image, const LLString& label ) | 1315 | void LLFontGL::addEmbeddedChar( llwchar wc, LLImageGL* image, const std::string& label ) |
1316 | { | 1316 | { |
1317 | LLWString wlabel = utf8str_to_wstring(label); | 1317 | LLWString wlabel = utf8str_to_wstring(label); |
1318 | addEmbeddedChar(wc, image, wlabel); | 1318 | addEmbeddedChar(wc, image, wlabel); |
@@ -1429,40 +1429,40 @@ void LLFontGL::drawGlyph(const LLRectf& screen_rect, const LLRectf& uv_rect, con | |||
1429 | } | 1429 | } |
1430 | 1430 | ||
1431 | // static | 1431 | // static |
1432 | LLString LLFontGL::nameFromFont(const LLFontGL* fontp) | 1432 | std::string LLFontGL::nameFromFont(const LLFontGL* fontp) |
1433 | { | 1433 | { |
1434 | if (fontp == sSansSerifHuge) | 1434 | if (fontp == sSansSerifHuge) |
1435 | { | 1435 | { |
1436 | return LLString("SansSerifHuge"); | 1436 | return std::string("SansSerifHuge"); |
1437 | } | 1437 | } |
1438 | else if (fontp == sSansSerifSmall) | 1438 | else if (fontp == sSansSerifSmall) |
1439 | { | 1439 | { |
1440 | return LLString("SansSerifSmall"); | 1440 | return std::string("SansSerifSmall"); |
1441 | } | 1441 | } |
1442 | else if (fontp == sSansSerif) | 1442 | else if (fontp == sSansSerif) |
1443 | { | 1443 | { |
1444 | return LLString("SansSerif"); | 1444 | return std::string("SansSerif"); |
1445 | } | 1445 | } |
1446 | else if (fontp == sSansSerifBig) | 1446 | else if (fontp == sSansSerifBig) |
1447 | { | 1447 | { |
1448 | return LLString("SansSerifBig"); | 1448 | return std::string("SansSerifBig"); |
1449 | } | 1449 | } |
1450 | else if (fontp == sSansSerifBold) | 1450 | else if (fontp == sSansSerifBold) |
1451 | { | 1451 | { |
1452 | return LLString("SansSerifBold"); | 1452 | return std::string("SansSerifBold"); |
1453 | } | 1453 | } |
1454 | else if (fontp == sMonospace) | 1454 | else if (fontp == sMonospace) |
1455 | { | 1455 | { |
1456 | return LLString("Monospace"); | 1456 | return std::string("Monospace"); |
1457 | } | 1457 | } |
1458 | else | 1458 | else |
1459 | { | 1459 | { |
1460 | return LLString(); | 1460 | return std::string(); |
1461 | } | 1461 | } |
1462 | } | 1462 | } |
1463 | 1463 | ||
1464 | // static | 1464 | // static |
1465 | LLFontGL* LLFontGL::fontFromName(const LLString& font_name) | 1465 | LLFontGL* LLFontGL::fontFromName(const std::string& font_name) |
1466 | { | 1466 | { |
1467 | LLFontGL* gl_font = NULL; | 1467 | LLFontGL* gl_font = NULL; |
1468 | if (font_name == "SansSerifHuge") | 1468 | if (font_name == "SansSerifHuge") |
@@ -1493,16 +1493,16 @@ LLFontGL* LLFontGL::fontFromName(const LLString& font_name) | |||
1493 | } | 1493 | } |
1494 | 1494 | ||
1495 | // static | 1495 | // static |
1496 | LLString LLFontGL::nameFromHAlign(LLFontGL::HAlign align) | 1496 | std::string LLFontGL::nameFromHAlign(LLFontGL::HAlign align) |
1497 | { | 1497 | { |
1498 | if (align == LEFT) return LLString("left"); | 1498 | if (align == LEFT) return std::string("left"); |
1499 | else if (align == RIGHT) return LLString("right"); | 1499 | else if (align == RIGHT) return std::string("right"); |
1500 | else if (align == HCENTER) return LLString("center"); | 1500 | else if (align == HCENTER) return std::string("center"); |
1501 | else return LLString(); | 1501 | else return std::string(); |
1502 | } | 1502 | } |
1503 | 1503 | ||
1504 | // static | 1504 | // static |
1505 | LLFontGL::HAlign LLFontGL::hAlignFromName(const LLString& name) | 1505 | LLFontGL::HAlign LLFontGL::hAlignFromName(const std::string& name) |
1506 | { | 1506 | { |
1507 | LLFontGL::HAlign gl_hfont_align = LLFontGL::LEFT; | 1507 | LLFontGL::HAlign gl_hfont_align = LLFontGL::LEFT; |
1508 | if (name == "left") | 1508 | if (name == "left") |
@@ -1522,17 +1522,17 @@ LLFontGL::HAlign LLFontGL::hAlignFromName(const LLString& name) | |||
1522 | } | 1522 | } |
1523 | 1523 | ||
1524 | // static | 1524 | // static |
1525 | LLString LLFontGL::nameFromVAlign(LLFontGL::VAlign align) | 1525 | std::string LLFontGL::nameFromVAlign(LLFontGL::VAlign align) |
1526 | { | 1526 | { |
1527 | if (align == TOP) return LLString("top"); | 1527 | if (align == TOP) return std::string("top"); |
1528 | else if (align == VCENTER) return LLString("center"); | 1528 | else if (align == VCENTER) return std::string("center"); |
1529 | else if (align == BASELINE) return LLString("baseline"); | 1529 | else if (align == BASELINE) return std::string("baseline"); |
1530 | else if (align == BOTTOM) return LLString("bottom"); | 1530 | else if (align == BOTTOM) return std::string("bottom"); |
1531 | else return LLString(); | 1531 | else return std::string(); |
1532 | } | 1532 | } |
1533 | 1533 | ||
1534 | // static | 1534 | // static |
1535 | LLFontGL::VAlign LLFontGL::vAlignFromName(const LLString& name) | 1535 | LLFontGL::VAlign LLFontGL::vAlignFromName(const std::string& name) |
1536 | { | 1536 | { |
1537 | LLFontGL::VAlign gl_vfont_align = LLFontGL::BASELINE; | 1537 | LLFontGL::VAlign gl_vfont_align = LLFontGL::BASELINE; |
1538 | if (name == "top") | 1538 | if (name == "top") |
diff --git a/linden/indra/llrender/llfontgl.h b/linden/indra/llrender/llfontgl.h index 01046af..3f88e62 100644 --- a/linden/indra/llrender/llfontgl.h +++ b/linden/indra/llrender/llfontgl.h | |||
@@ -73,7 +73,7 @@ public: | |||
73 | }; | 73 | }; |
74 | 74 | ||
75 | // Takes a string with potentially several flags, i.e. "NORMAL|BOLD|ITALIC" | 75 | // Takes a string with potentially several flags, i.e. "NORMAL|BOLD|ITALIC" |
76 | static U8 getStyleFromString(const LLString &style); | 76 | static U8 getStyleFromString(const std::string &style); |
77 | 77 | ||
78 | LLFontGL(); | 78 | LLFontGL(); |
79 | LLFontGL(const LLFontGL &source); | 79 | LLFontGL(const LLFontGL &source); |
@@ -85,24 +85,24 @@ public: | |||
85 | LLFontGL &operator=(const LLFontGL &source); | 85 | LLFontGL &operator=(const LLFontGL &source); |
86 | 86 | ||
87 | static BOOL initDefaultFonts(F32 screen_dpi, F32 x_scale, F32 y_scale, | 87 | static BOOL initDefaultFonts(F32 screen_dpi, F32 x_scale, F32 y_scale, |
88 | const LLString& monospace_file, F32 monospace_size, | 88 | const std::string& monospace_file, F32 monospace_size, |
89 | const LLString& sansserif_file, | 89 | const std::string& sansserif_file, |
90 | const LLString& sansserif_fallback_file, F32 ss_fallback_scale, | 90 | const std::string& sansserif_fallback_file, F32 ss_fallback_scale, |
91 | F32 small_size, F32 medium_size, F32 large_size, F32 huge_size, | 91 | F32 small_size, F32 medium_size, F32 large_size, F32 huge_size, |
92 | const LLString& sansserif_bold_file, F32 bold_size, | 92 | const std::string& sansserif_bold_file, F32 bold_size, |
93 | const LLString& app_dir = LLString::null); | 93 | const std::string& app_dir = LLStringUtil::null); |
94 | 94 | ||
95 | static void destroyDefaultFonts(); | 95 | static void destroyDefaultFonts(); |
96 | static void destroyGL(); | 96 | static void destroyGL(); |
97 | 97 | ||
98 | static bool loadFaceFallback(LLFontList *fontp, const LLString& fontname, const F32 point_size); | 98 | static bool loadFaceFallback(LLFontList *fontp, const std::string& fontname, const F32 point_size); |
99 | static bool loadFace(LLFontGL *fontp, const LLString& fontname, const F32 point_size, LLFontList *fallback_fontp); | 99 | static bool loadFace(LLFontGL *fontp, const std::string& fontname, const F32 point_size, LLFontList *fallback_fontp); |
100 | /* virtual*/ BOOL loadFace(const std::string& filename, | 100 | /* virtual*/ BOOL loadFace(const std::string& filename, |
101 | const F32 point_size, const F32 vert_dpi, const F32 horz_dpi, | 101 | const F32 point_size, const F32 vert_dpi, const F32 horz_dpi, |
102 | const S32 components, BOOL is_fallback); | 102 | const S32 components, BOOL is_fallback); |
103 | 103 | ||
104 | 104 | ||
105 | S32 renderUTF8(const LLString &text, const S32 begin_offset, | 105 | S32 renderUTF8(const std::string &text, const S32 begin_offset, |
106 | S32 x, S32 y, | 106 | S32 x, S32 y, |
107 | const LLColor4 &color) const | 107 | const LLColor4 &color) const |
108 | { | 108 | { |
@@ -111,7 +111,7 @@ public: | |||
111 | S32_MAX, S32_MAX, NULL, FALSE); | 111 | S32_MAX, S32_MAX, NULL, FALSE); |
112 | } | 112 | } |
113 | 113 | ||
114 | S32 renderUTF8(const LLString &text, const S32 begin_offset, | 114 | S32 renderUTF8(const std::string &text, const S32 begin_offset, |
115 | S32 x, S32 y, | 115 | S32 x, S32 y, |
116 | const LLColor4 &color, | 116 | const LLColor4 &color, |
117 | HAlign halign, VAlign valign, U8 style = NORMAL) const | 117 | HAlign halign, VAlign valign, U8 style = NORMAL) const |
@@ -122,7 +122,7 @@ public: | |||
122 | } | 122 | } |
123 | 123 | ||
124 | // renderUTF8 does a conversion, so is slower! | 124 | // renderUTF8 does a conversion, so is slower! |
125 | S32 renderUTF8(const LLString &text, | 125 | S32 renderUTF8(const std::string &text, |
126 | S32 begin_offset, | 126 | S32 begin_offset, |
127 | F32 x, F32 y, | 127 | F32 x, F32 y, |
128 | const LLColor4 &color, | 128 | const LLColor4 &color, |
@@ -162,14 +162,14 @@ public: | |||
162 | /*virtual*/ F32 getAscenderHeight() const { return (F32)llround(mAscender / sScaleY); } | 162 | /*virtual*/ F32 getAscenderHeight() const { return (F32)llround(mAscender / sScaleY); } |
163 | /*virtual*/ F32 getDescenderHeight() const { return (F32)llround(mDescender / sScaleY); } | 163 | /*virtual*/ F32 getDescenderHeight() const { return (F32)llround(mDescender / sScaleY); } |
164 | 164 | ||
165 | virtual S32 getWidth(const LLString& utf8text) const; | 165 | virtual S32 getWidth(const std::string& utf8text) const; |
166 | virtual S32 getWidth(const llwchar* wchars) const; | 166 | virtual S32 getWidth(const llwchar* wchars) const; |
167 | virtual S32 getWidth(const LLString& utf8text, const S32 offset, const S32 max_chars ) const; | 167 | virtual S32 getWidth(const std::string& utf8text, const S32 offset, const S32 max_chars ) const; |
168 | virtual S32 getWidth(const llwchar* wchars, const S32 offset, const S32 max_chars, BOOL use_embedded = FALSE) const; | 168 | virtual S32 getWidth(const llwchar* wchars, const S32 offset, const S32 max_chars, BOOL use_embedded = FALSE) const; |
169 | 169 | ||
170 | virtual F32 getWidthF32(const LLString& utf8text) const; | 170 | virtual F32 getWidthF32(const std::string& utf8text) const; |
171 | virtual F32 getWidthF32(const llwchar* wchars) const; | 171 | virtual F32 getWidthF32(const llwchar* wchars) const; |
172 | virtual F32 getWidthF32(const LLString& text, const S32 offset, const S32 max_chars ) const; | 172 | virtual F32 getWidthF32(const std::string& text, const S32 offset, const S32 max_chars ) const; |
173 | virtual F32 getWidthF32(const llwchar* wchars, const S32 offset, const S32 max_chars, BOOL use_embedded = FALSE ) const; | 173 | virtual F32 getWidthF32(const llwchar* wchars, const S32 offset, const S32 max_chars, BOOL use_embedded = FALSE ) const; |
174 | 174 | ||
175 | // The following are called often, frequently with large buffers, so do not use a string interface | 175 | // The following are called often, frequently with large buffers, so do not use a string interface |
@@ -191,18 +191,18 @@ public: | |||
191 | 191 | ||
192 | LLImageGL *getImageGL() const; | 192 | LLImageGL *getImageGL() const; |
193 | 193 | ||
194 | void addEmbeddedChar( llwchar wc, LLImageGL* image, const LLString& label); | 194 | void addEmbeddedChar( llwchar wc, LLImageGL* image, const std::string& label); |
195 | void addEmbeddedChar( llwchar wc, LLImageGL* image, const LLWString& label); | 195 | void addEmbeddedChar( llwchar wc, LLImageGL* image, const LLWString& label); |
196 | void removeEmbeddedChar( llwchar wc ); | 196 | void removeEmbeddedChar( llwchar wc ); |
197 | 197 | ||
198 | static LLString nameFromFont(const LLFontGL* fontp); | 198 | static std::string nameFromFont(const LLFontGL* fontp); |
199 | static LLFontGL* fontFromName(const LLString& name); | 199 | static LLFontGL* fontFromName(const std::string& name); |
200 | 200 | ||
201 | static LLString nameFromHAlign(LLFontGL::HAlign align); | 201 | static std::string nameFromHAlign(LLFontGL::HAlign align); |
202 | static LLFontGL::HAlign hAlignFromName(const LLString& name); | 202 | static LLFontGL::HAlign hAlignFromName(const std::string& name); |
203 | 203 | ||
204 | static LLString nameFromVAlign(LLFontGL::VAlign align); | 204 | static std::string nameFromVAlign(LLFontGL::VAlign align); |
205 | static LLFontGL::VAlign vAlignFromName(const LLString& name); | 205 | static LLFontGL::VAlign vAlignFromName(const std::string& name); |
206 | 206 | ||
207 | static void setFontDisplay(BOOL flag) { sDisplayFont = flag ; } | 207 | static void setFontDisplay(BOOL flag) { sDisplayFont = flag ; } |
208 | 208 | ||
@@ -225,7 +225,7 @@ public: | |||
225 | static F32 sScaleX; | 225 | static F32 sScaleX; |
226 | static F32 sScaleY; | 226 | static F32 sScaleY; |
227 | static BOOL sDisplayFont ; | 227 | static BOOL sDisplayFont ; |
228 | static LLString sAppDir; // For loading fonts | 228 | static std::string sAppDir; // For loading fonts |
229 | 229 | ||
230 | static LLFontGL* sMonospace; // medium | 230 | static LLFontGL* sMonospace; // medium |
231 | static LLFontList* sMonospaceFallback; | 231 | static LLFontList* sMonospaceFallback; |
@@ -249,8 +249,8 @@ public: | |||
249 | 249 | ||
250 | protected: | 250 | protected: |
251 | /*virtual*/ BOOL addChar(const llwchar wch); | 251 | /*virtual*/ BOOL addChar(const llwchar wch); |
252 | static LLString getFontPathLocal(); | 252 | static std::string getFontPathLocal(); |
253 | static LLString getFontPathSystem(); | 253 | static std::string getFontPathSystem(); |
254 | 254 | ||
255 | protected: | 255 | protected: |
256 | LLPointer<LLImageRaw> mRawImageGLp; | 256 | LLPointer<LLImageRaw> mRawImageGLp; |
diff --git a/linden/indra/llrender/llgl.cpp b/linden/indra/llrender/llgl.cpp new file mode 100644 index 0000000..843bc79 --- /dev/null +++ b/linden/indra/llrender/llgl.cpp | |||
@@ -0,0 +1,1763 @@ | |||
1 | /** | ||
2 | * @file llgl.cpp | ||
3 | * @brief LLGL implementation | ||
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 file sets some global GL parameters, and implements some | ||
33 | // useful functions for GL operations. | ||
34 | |||
35 | #define GLH_EXT_SINGLE_FILE | ||
36 | |||
37 | #include "linden_common.h" | ||
38 | |||
39 | #include "boost/tokenizer.hpp" | ||
40 | |||
41 | #include "llsys.h" | ||
42 | |||
43 | #include "llgl.h" | ||
44 | #include "llrender.h" | ||
45 | |||
46 | #include "llerror.h" | ||
47 | #include "llquaternion.h" | ||
48 | #include "llmath.h" | ||
49 | #include "m4math.h" | ||
50 | #include "llstring.h" | ||
51 | |||
52 | #include "llglheaders.h" | ||
53 | |||
54 | #ifdef _DEBUG | ||
55 | //#define GL_STATE_VERIFY | ||
56 | #endif | ||
57 | |||
58 | BOOL gDebugGL = FALSE; | ||
59 | BOOL gClothRipple = FALSE; | ||
60 | BOOL gNoRender = FALSE; | ||
61 | LLMatrix4 gGLObliqueProjectionInverse; | ||
62 | |||
63 | #define LL_GL_NAME_POOLING 0 | ||
64 | |||
65 | LLGLNamePool::pool_list_t LLGLNamePool::sInstances; | ||
66 | |||
67 | #if (LL_WINDOWS || LL_LINUX) && !LL_MESA_HEADLESS | ||
68 | // ATI prototypes | ||
69 | // vertex blending prototypes | ||
70 | PFNGLWEIGHTPOINTERARBPROC glWeightPointerARB = NULL; | ||
71 | PFNGLVERTEXBLENDARBPROC glVertexBlendARB = NULL; | ||
72 | PFNGLWEIGHTFVARBPROC glWeightfvARB = NULL; | ||
73 | |||
74 | // Vertex buffer object prototypes | ||
75 | PFNGLBINDBUFFERARBPROC glBindBufferARB = NULL; | ||
76 | PFNGLDELETEBUFFERSARBPROC glDeleteBuffersARB = NULL; | ||
77 | PFNGLGENBUFFERSARBPROC glGenBuffersARB = NULL; | ||
78 | PFNGLISBUFFERARBPROC glIsBufferARB = NULL; | ||
79 | PFNGLBUFFERDATAARBPROC glBufferDataARB = NULL; | ||
80 | PFNGLBUFFERSUBDATAARBPROC glBufferSubDataARB = NULL; | ||
81 | PFNGLGETBUFFERSUBDATAARBPROC glGetBufferSubDataARB = NULL; | ||
82 | PFNGLMAPBUFFERARBPROC glMapBufferARB = NULL; | ||
83 | PFNGLUNMAPBUFFERARBPROC glUnmapBufferARB = NULL; | ||
84 | PFNGLGETBUFFERPARAMETERIVARBPROC glGetBufferParameterivARB = NULL; | ||
85 | PFNGLGETBUFFERPOINTERVARBPROC glGetBufferPointervARB = NULL; | ||
86 | |||
87 | // vertex object prototypes | ||
88 | PFNGLNEWOBJECTBUFFERATIPROC glNewObjectBufferATI = NULL; | ||
89 | PFNGLISOBJECTBUFFERATIPROC glIsObjectBufferATI = NULL; | ||
90 | PFNGLUPDATEOBJECTBUFFERATIPROC glUpdateObjectBufferATI = NULL; | ||
91 | PFNGLGETOBJECTBUFFERFVATIPROC glGetObjectBufferfvATI = NULL; | ||
92 | PFNGLGETOBJECTBUFFERIVATIPROC glGetObjectBufferivATI = NULL; | ||
93 | PFNGLFREEOBJECTBUFFERATIPROC glFreeObjectBufferATI = NULL; | ||
94 | PFNGLARRAYOBJECTATIPROC glArrayObjectATI = NULL; | ||
95 | PFNGLVERTEXATTRIBARRAYOBJECTATIPROC glVertexAttribArrayObjectATI = NULL; | ||
96 | PFNGLGETARRAYOBJECTFVATIPROC glGetArrayObjectfvATI = NULL; | ||
97 | PFNGLGETARRAYOBJECTIVATIPROC glGetArrayObjectivATI = NULL; | ||
98 | PFNGLVARIANTARRAYOBJECTATIPROC glVariantObjectArrayATI = NULL; | ||
99 | PFNGLGETVARIANTARRAYOBJECTFVATIPROC glGetVariantArrayObjectfvATI = NULL; | ||
100 | PFNGLGETVARIANTARRAYOBJECTIVATIPROC glGetVariantArrayObjectivATI = NULL; | ||
101 | |||
102 | // GL_ARB_occlusion_query | ||
103 | PFNGLGENQUERIESARBPROC glGenQueriesARB = NULL; | ||
104 | PFNGLDELETEQUERIESARBPROC glDeleteQueriesARB = NULL; | ||
105 | PFNGLISQUERYARBPROC glIsQueryARB = NULL; | ||
106 | PFNGLBEGINQUERYARBPROC glBeginQueryARB = NULL; | ||
107 | PFNGLENDQUERYARBPROC glEndQueryARB = NULL; | ||
108 | PFNGLGETQUERYIVARBPROC glGetQueryivARB = NULL; | ||
109 | PFNGLGETQUERYOBJECTIVARBPROC glGetQueryObjectivARB = NULL; | ||
110 | PFNGLGETQUERYOBJECTUIVARBPROC glGetQueryObjectuivARB = NULL; | ||
111 | |||
112 | // GL_ARB_point_parameters | ||
113 | PFNGLPOINTPARAMETERFARBPROC glPointParameterfARB = NULL; | ||
114 | PFNGLPOINTPARAMETERFVARBPROC glPointParameterfvARB = NULL; | ||
115 | |||
116 | // GL_EXT_framebuffer_object | ||
117 | PFNGLISRENDERBUFFEREXTPROC glIsRenderbufferEXT = NULL; | ||
118 | PFNGLBINDRENDERBUFFEREXTPROC glBindRenderbufferEXT = NULL; | ||
119 | PFNGLDELETERENDERBUFFERSEXTPROC glDeleteRenderbuffersEXT = NULL; | ||
120 | PFNGLGENRENDERBUFFERSEXTPROC glGenRenderbuffersEXT = NULL; | ||
121 | PFNGLRENDERBUFFERSTORAGEEXTPROC glRenderbufferStorageEXT = NULL; | ||
122 | PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC glGetRenderbufferParameterivEXT = NULL; | ||
123 | PFNGLISFRAMEBUFFEREXTPROC glIsFramebufferEXT = NULL; | ||
124 | PFNGLBINDFRAMEBUFFEREXTPROC glBindFramebufferEXT = NULL; | ||
125 | PFNGLDELETEFRAMEBUFFERSEXTPROC glDeleteFramebuffersEXT = NULL; | ||
126 | PFNGLGENFRAMEBUFFERSEXTPROC glGenFramebuffersEXT = NULL; | ||
127 | PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC glCheckFramebufferStatusEXT = NULL; | ||
128 | PFNGLFRAMEBUFFERTEXTURE1DEXTPROC glFramebufferTexture1DEXT = NULL; | ||
129 | PFNGLFRAMEBUFFERTEXTURE2DEXTPROC glFramebufferTexture2DEXT = NULL; | ||
130 | PFNGLFRAMEBUFFERTEXTURE3DEXTPROC glFramebufferTexture3DEXT = NULL; | ||
131 | PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC glFramebufferRenderbufferEXT = NULL; | ||
132 | PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC glGetFramebufferAttachmentParameterivEXT = NULL; | ||
133 | PFNGLGENERATEMIPMAPEXTPROC glGenerateMipmapEXT = NULL; | ||
134 | |||
135 | //shader object prototypes | ||
136 | PFNGLDELETEOBJECTARBPROC glDeleteObjectARB = NULL; | ||
137 | PFNGLGETHANDLEARBPROC glGetHandleARB = NULL; | ||
138 | PFNGLDETACHOBJECTARBPROC glDetachObjectARB = NULL; | ||
139 | PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB = NULL; | ||
140 | PFNGLSHADERSOURCEARBPROC glShaderSourceARB = NULL; | ||
141 | PFNGLCOMPILESHADERARBPROC glCompileShaderARB = NULL; | ||
142 | PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB = NULL; | ||
143 | PFNGLATTACHOBJECTARBPROC glAttachObjectARB = NULL; | ||
144 | PFNGLLINKPROGRAMARBPROC glLinkProgramARB = NULL; | ||
145 | PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB = NULL; | ||
146 | PFNGLVALIDATEPROGRAMARBPROC glValidateProgramARB = NULL; | ||
147 | PFNGLUNIFORM1FARBPROC glUniform1fARB = NULL; | ||
148 | PFNGLUNIFORM2FARBPROC glUniform2fARB = NULL; | ||
149 | PFNGLUNIFORM3FARBPROC glUniform3fARB = NULL; | ||
150 | PFNGLUNIFORM4FARBPROC glUniform4fARB = NULL; | ||
151 | PFNGLUNIFORM1IARBPROC glUniform1iARB = NULL; | ||
152 | PFNGLUNIFORM2IARBPROC glUniform2iARB = NULL; | ||
153 | PFNGLUNIFORM3IARBPROC glUniform3iARB = NULL; | ||
154 | PFNGLUNIFORM4IARBPROC glUniform4iARB = NULL; | ||
155 | PFNGLUNIFORM1FVARBPROC glUniform1fvARB = NULL; | ||
156 | PFNGLUNIFORM2FVARBPROC glUniform2fvARB = NULL; | ||
157 | PFNGLUNIFORM3FVARBPROC glUniform3fvARB = NULL; | ||
158 | PFNGLUNIFORM4FVARBPROC glUniform4fvARB = NULL; | ||
159 | PFNGLUNIFORM1IVARBPROC glUniform1ivARB = NULL; | ||
160 | PFNGLUNIFORM2IVARBPROC glUniform2ivARB = NULL; | ||
161 | PFNGLUNIFORM3IVARBPROC glUniform3ivARB = NULL; | ||
162 | PFNGLUNIFORM4IVARBPROC glUniform4ivARB = NULL; | ||
163 | PFNGLUNIFORMMATRIX2FVARBPROC glUniformMatrix2fvARB = NULL; | ||
164 | PFNGLUNIFORMMATRIX3FVARBPROC glUniformMatrix3fvARB = NULL; | ||
165 | PFNGLUNIFORMMATRIX4FVARBPROC glUniformMatrix4fvARB = NULL; | ||
166 | PFNGLGETOBJECTPARAMETERFVARBPROC glGetObjectParameterfvARB = NULL; | ||
167 | PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB = NULL; | ||
168 | PFNGLGETINFOLOGARBPROC glGetInfoLogARB = NULL; | ||
169 | PFNGLGETATTACHEDOBJECTSARBPROC glGetAttachedObjectsARB = NULL; | ||
170 | PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB = NULL; | ||
171 | PFNGLGETACTIVEUNIFORMARBPROC glGetActiveUniformARB = NULL; | ||
172 | PFNGLGETUNIFORMFVARBPROC glGetUniformfvARB = NULL; | ||
173 | PFNGLGETUNIFORMIVARBPROC glGetUniformivARB = NULL; | ||
174 | PFNGLGETSHADERSOURCEARBPROC glGetShaderSourceARB = NULL; | ||
175 | |||
176 | // vertex shader prototypes | ||
177 | #if LL_LINUX | ||
178 | PFNGLVERTEXATTRIB1DARBPROC glVertexAttrib1dARB = NULL; | ||
179 | PFNGLVERTEXATTRIB1DVARBPROC glVertexAttrib1dvARB = NULL; | ||
180 | PFNGLVERTEXATTRIB1FARBPROC glVertexAttrib1fARB = NULL; | ||
181 | PFNGLVERTEXATTRIB1FVARBPROC glVertexAttrib1fvARB = NULL; | ||
182 | PFNGLVERTEXATTRIB1SARBPROC glVertexAttrib1sARB = NULL; | ||
183 | PFNGLVERTEXATTRIB1SVARBPROC glVertexAttrib1svARB = NULL; | ||
184 | PFNGLVERTEXATTRIB2DARBPROC glVertexAttrib2dARB = NULL; | ||
185 | PFNGLVERTEXATTRIB2DVARBPROC glVertexAttrib2dvARB = NULL; | ||
186 | PFNGLVERTEXATTRIB2FARBPROC glVertexAttrib2fARB = NULL; | ||
187 | PFNGLVERTEXATTRIB2FVARBPROC glVertexAttrib2fvARB = NULL; | ||
188 | PFNGLVERTEXATTRIB2SARBPROC glVertexAttrib2sARB = NULL; | ||
189 | PFNGLVERTEXATTRIB2SVARBPROC glVertexAttrib2svARB = NULL; | ||
190 | PFNGLVERTEXATTRIB3DARBPROC glVertexAttrib3dARB = NULL; | ||
191 | PFNGLVERTEXATTRIB3DVARBPROC glVertexAttrib3dvARB = NULL; | ||
192 | PFNGLVERTEXATTRIB3FARBPROC glVertexAttrib3fARB = NULL; | ||
193 | PFNGLVERTEXATTRIB3FVARBPROC glVertexAttrib3fvARB = NULL; | ||
194 | PFNGLVERTEXATTRIB3SARBPROC glVertexAttrib3sARB = NULL; | ||
195 | PFNGLVERTEXATTRIB3SVARBPROC glVertexAttrib3svARB = NULL; | ||
196 | #endif // LL_LINUX | ||
197 | PFNGLVERTEXATTRIB4NBVARBPROC glVertexAttrib4nbvARB = NULL; | ||
198 | PFNGLVERTEXATTRIB4NIVARBPROC glVertexAttrib4nivARB = NULL; | ||
199 | PFNGLVERTEXATTRIB4NSVARBPROC glVertexAttrib4nsvARB = NULL; | ||
200 | PFNGLVERTEXATTRIB4NUBARBPROC glVertexAttrib4nubARB = NULL; | ||
201 | PFNGLVERTEXATTRIB4NUBVARBPROC glVertexAttrib4nubvARB = NULL; | ||
202 | PFNGLVERTEXATTRIB4NUIVARBPROC glVertexAttrib4nuivARB = NULL; | ||
203 | PFNGLVERTEXATTRIB4NUSVARBPROC glVertexAttrib4nusvARB = NULL; | ||
204 | #if LL_LINUX | ||
205 | PFNGLVERTEXATTRIB4BVARBPROC glVertexAttrib4bvARB = NULL; | ||
206 | PFNGLVERTEXATTRIB4DARBPROC glVertexAttrib4dARB = NULL; | ||
207 | PFNGLVERTEXATTRIB4DVARBPROC glVertexAttrib4dvARB = NULL; | ||
208 | PFNGLVERTEXATTRIB4FARBPROC glVertexAttrib4fARB = NULL; | ||
209 | PFNGLVERTEXATTRIB4FVARBPROC glVertexAttrib4fvARB = NULL; | ||
210 | PFNGLVERTEXATTRIB4IVARBPROC glVertexAttrib4ivARB = NULL; | ||
211 | PFNGLVERTEXATTRIB4SARBPROC glVertexAttrib4sARB = NULL; | ||
212 | PFNGLVERTEXATTRIB4SVARBPROC glVertexAttrib4svARB = NULL; | ||
213 | PFNGLVERTEXATTRIB4UBVARBPROC glVertexAttrib4ubvARB = NULL; | ||
214 | PFNGLVERTEXATTRIB4UIVARBPROC glVertexAttrib4uivARB = NULL; | ||
215 | PFNGLVERTEXATTRIB4USVARBPROC glVertexAttrib4usvARB = NULL; | ||
216 | PFNGLVERTEXATTRIBPOINTERARBPROC glVertexAttribPointerARB = NULL; | ||
217 | PFNGLENABLEVERTEXATTRIBARRAYARBPROC glEnableVertexAttribArrayARB = NULL; | ||
218 | PFNGLDISABLEVERTEXATTRIBARRAYARBPROC glDisableVertexAttribArrayARB = NULL; | ||
219 | PFNGLPROGRAMSTRINGARBPROC glProgramStringARB = NULL; | ||
220 | PFNGLBINDPROGRAMARBPROC glBindProgramARB = NULL; | ||
221 | PFNGLDELETEPROGRAMSARBPROC glDeleteProgramsARB = NULL; | ||
222 | PFNGLGENPROGRAMSARBPROC glGenProgramsARB = NULL; | ||
223 | PFNGLPROGRAMENVPARAMETER4DARBPROC glProgramEnvParameter4dARB = NULL; | ||
224 | PFNGLPROGRAMENVPARAMETER4DVARBPROC glProgramEnvParameter4dvARB = NULL; | ||
225 | PFNGLPROGRAMENVPARAMETER4FARBPROC glProgramEnvParameter4fARB = NULL; | ||
226 | PFNGLPROGRAMENVPARAMETER4FVARBPROC glProgramEnvParameter4fvARB = NULL; | ||
227 | PFNGLPROGRAMLOCALPARAMETER4DARBPROC glProgramLocalParameter4dARB = NULL; | ||
228 | PFNGLPROGRAMLOCALPARAMETER4DVARBPROC glProgramLocalParameter4dvARB = NULL; | ||
229 | PFNGLPROGRAMLOCALPARAMETER4FARBPROC glProgramLocalParameter4fARB = NULL; | ||
230 | PFNGLPROGRAMLOCALPARAMETER4FVARBPROC glProgramLocalParameter4fvARB = NULL; | ||
231 | PFNGLGETPROGRAMENVPARAMETERDVARBPROC glGetProgramEnvParameterdvARB = NULL; | ||
232 | PFNGLGETPROGRAMENVPARAMETERFVARBPROC glGetProgramEnvParameterfvARB = NULL; | ||
233 | PFNGLGETPROGRAMLOCALPARAMETERDVARBPROC glGetProgramLocalParameterdvARB = NULL; | ||
234 | PFNGLGETPROGRAMLOCALPARAMETERFVARBPROC glGetProgramLocalParameterfvARB = NULL; | ||
235 | PFNGLGETPROGRAMIVARBPROC glGetProgramivARB = NULL; | ||
236 | PFNGLGETPROGRAMSTRINGARBPROC glGetProgramStringARB = NULL; | ||
237 | PFNGLGETVERTEXATTRIBDVARBPROC glGetVertexAttribdvARB = NULL; | ||
238 | PFNGLGETVERTEXATTRIBFVARBPROC glGetVertexAttribfvARB = NULL; | ||
239 | PFNGLGETVERTEXATTRIBIVARBPROC glGetVertexAttribivARB = NULL; | ||
240 | PFNGLGETVERTEXATTRIBPOINTERVARBPROC glGetVertexAttribPointervARB = NULL; | ||
241 | PFNGLISPROGRAMARBPROC glIsProgramARB = NULL; | ||
242 | #endif // LL_LINUX | ||
243 | PFNGLBINDATTRIBLOCATIONARBPROC glBindAttribLocationARB = NULL; | ||
244 | PFNGLGETACTIVEATTRIBARBPROC glGetActiveAttribARB = NULL; | ||
245 | PFNGLGETATTRIBLOCATIONARBPROC glGetAttribLocationARB = NULL; | ||
246 | |||
247 | #if LL_WINDOWS | ||
248 | PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = NULL; | ||
249 | #endif | ||
250 | |||
251 | #if LL_LINUX | ||
252 | PFNGLCOLORTABLEEXTPROC glColorTableEXT = NULL; | ||
253 | #endif // LL_LINUX | ||
254 | |||
255 | #endif | ||
256 | |||
257 | LLGLManager gGLManager; | ||
258 | |||
259 | LLGLManager::LLGLManager() : | ||
260 | mInited(FALSE), | ||
261 | mIsDisabled(FALSE), | ||
262 | |||
263 | mHasMultitexture(FALSE), | ||
264 | mNumTextureUnits(1), | ||
265 | mHasMipMapGeneration(FALSE), | ||
266 | mHasPalettedTextures(FALSE), | ||
267 | mHasCompressedTextures(FALSE), | ||
268 | mHasFramebufferObject(FALSE), | ||
269 | |||
270 | mHasVertexBufferObject(FALSE), | ||
271 | mHasPBuffer(FALSE), | ||
272 | mHasShaderObjects(FALSE), | ||
273 | mHasVertexShader(FALSE), | ||
274 | mHasFragmentShader(FALSE), | ||
275 | mHasOcclusionQuery(FALSE), | ||
276 | mHasPointParameters(FALSE), | ||
277 | |||
278 | mHasAnisotropic(FALSE), | ||
279 | mHasARBEnvCombine(FALSE), | ||
280 | mHasCubeMap(FALSE), | ||
281 | |||
282 | mIsATI(FALSE), | ||
283 | mIsNVIDIA(FALSE), | ||
284 | mIsIntel(FALSE), | ||
285 | mIsGF2or4MX(FALSE), | ||
286 | mIsGF3(FALSE), | ||
287 | mIsGFFX(FALSE), | ||
288 | mATIOffsetVerticalLines(FALSE), | ||
289 | mATIOldDriver(FALSE), | ||
290 | |||
291 | mHasRequirements(TRUE), | ||
292 | |||
293 | mHasSeparateSpecularColor(FALSE), | ||
294 | |||
295 | mDriverVersionMajor(1), | ||
296 | mDriverVersionMinor(0), | ||
297 | mDriverVersionRelease(0), | ||
298 | mGLVersion(1.0f), | ||
299 | |||
300 | mVRAM(0), | ||
301 | mGLMaxVertexRange(0), | ||
302 | mGLMaxIndexRange(0) | ||
303 | { | ||
304 | } | ||
305 | |||
306 | //--------------------------------------------------------------------- | ||
307 | // Global initialization for GL | ||
308 | //--------------------------------------------------------------------- | ||
309 | void LLGLManager::initWGL() | ||
310 | { | ||
311 | mHasPBuffer = FALSE; | ||
312 | #if LL_WINDOWS && !LL_MESA_HEADLESS | ||
313 | if (!glh_init_extensions("WGL_ARB_pixel_format")) | ||
314 | { | ||
315 | LL_WARNS("RenderInit") << "No ARB pixel format extensions" << LL_ENDL; | ||
316 | } | ||
317 | |||
318 | if (ExtensionExists("WGL_EXT_swap_control", gGLHExts.mSysExts)) | ||
319 | { | ||
320 | GLH_EXT_NAME(wglSwapIntervalEXT) = (PFNWGLSWAPINTERVALEXTPROC)GLH_EXT_GET_PROC_ADDRESS("wglSwapIntervalEXT"); | ||
321 | } | ||
322 | |||
323 | if( !glh_init_extensions("WGL_ARB_pbuffer") ) | ||
324 | { | ||
325 | LL_WARNS("RenderInit") << "No ARB WGL PBuffer extensions" << LL_ENDL; | ||
326 | } | ||
327 | |||
328 | if( !glh_init_extensions("WGL_ARB_render_texture") ) | ||
329 | { | ||
330 | LL_WARNS("RenderInit") << "No ARB WGL render texture extensions" << LL_ENDL; | ||
331 | } | ||
332 | |||
333 | mHasPBuffer = ExtensionExists("WGL_ARB_pbuffer", gGLHExts.mSysExts) && | ||
334 | ExtensionExists("WGL_ARB_render_texture", gGLHExts.mSysExts) && | ||
335 | ExtensionExists("WGL_ARB_pixel_format", gGLHExts.mSysExts); | ||
336 | #endif | ||
337 | } | ||
338 | |||
339 | // return false if unable (or unwilling due to old drivers) to init GL | ||
340 | bool LLGLManager::initGL() | ||
341 | { | ||
342 | if (mInited) | ||
343 | { | ||
344 | LL_ERRS("RenderInit") << "Calling init on LLGLManager after already initialized!" << LL_ENDL; | ||
345 | } | ||
346 | |||
347 | GLint alpha_bits; | ||
348 | glGetIntegerv( GL_ALPHA_BITS, &alpha_bits ); | ||
349 | if( 8 != alpha_bits ) | ||
350 | { | ||
351 | LL_WARNS("RenderInit") << "Frame buffer has less than 8 bits of alpha. Avatar texture compositing will fail." << LL_ENDL; | ||
352 | } | ||
353 | |||
354 | // Extract video card strings and convert to upper case to | ||
355 | // work around driver-to-driver variation in capitalization. | ||
356 | mGLVendor = std::string((const char *)glGetString(GL_VENDOR)); | ||
357 | LLStringUtil::toUpper(mGLVendor); | ||
358 | |||
359 | mGLRenderer = std::string((const char *)glGetString(GL_RENDERER)); | ||
360 | LLStringUtil::toUpper(mGLRenderer); | ||
361 | |||
362 | parse_gl_version( &mDriverVersionMajor, | ||
363 | &mDriverVersionMinor, | ||
364 | &mDriverVersionRelease, | ||
365 | &mDriverVersionVendorString ); | ||
366 | |||
367 | mGLVersion = mDriverVersionMajor + mDriverVersionMinor * .1f; | ||
368 | |||
369 | // Trailing space necessary to keep "nVidia Corpor_ati_on" cards | ||
370 | // from being recognized as ATI. | ||
371 | if (mGLVendor.substr(0,4) == "ATI ") | ||
372 | { | ||
373 | mGLVendorShort = "ATI"; | ||
374 | BOOL mobile = FALSE; | ||
375 | if (mGLRenderer.find("MOBILITY") != std::string::npos) | ||
376 | { | ||
377 | mobile = TRUE; | ||
378 | } | ||
379 | mIsATI = TRUE; | ||
380 | |||
381 | #if LL_WINDOWS && !LL_MESA_HEADLESS | ||
382 | if (mDriverVersionRelease < 3842) | ||
383 | { | ||
384 | mATIOffsetVerticalLines = TRUE; | ||
385 | } | ||
386 | #endif // LL_WINDOWS | ||
387 | |||
388 | #if (LL_WINDOWS || LL_LINUX) && !LL_MESA_HEADLESS | ||
389 | // release 7277 is a point at which we verify that ATI OpenGL | ||
390 | // drivers get pretty stable with SL, ~Catalyst 8.2, | ||
391 | // for both Win32 and Linux. | ||
392 | if (mDriverVersionRelease < 7277 && | ||
393 | mDriverVersionRelease != 0) // 0 == Undetectable driver version - these get to pretend to be new ATI drivers, though that decision may be revisited. | ||
394 | { | ||
395 | mATIOldDriver = TRUE; | ||
396 | } | ||
397 | #endif // (LL_WINDOWS || LL_LINUX) && !LL_MESA_HEADLESS | ||
398 | } | ||
399 | else if (mGLVendor.find("NVIDIA ") != std::string::npos) | ||
400 | { | ||
401 | mGLVendorShort = "NVIDIA"; | ||
402 | mIsNVIDIA = TRUE; | ||
403 | if ( mGLRenderer.find("GEFORCE4 MX") != std::string::npos | ||
404 | || mGLRenderer.find("GEFORCE2") != std::string::npos | ||
405 | || mGLRenderer.find("GEFORCE 2") != std::string::npos | ||
406 | || mGLRenderer.find("GEFORCE4 460 GO") != std::string::npos | ||
407 | || mGLRenderer.find("GEFORCE4 440 GO") != std::string::npos | ||
408 | || mGLRenderer.find("GEFORCE4 420 GO") != std::string::npos) | ||
409 | { | ||
410 | mIsGF2or4MX = TRUE; | ||
411 | } | ||
412 | else if (mGLRenderer.find("GEFORCE FX") != std::string::npos | ||
413 | || mGLRenderer.find("QUADRO FX") != std::string::npos | ||
414 | || mGLRenderer.find("NV34") != std::string::npos) | ||
415 | { | ||
416 | mIsGFFX = TRUE; | ||
417 | } | ||
418 | else if(mGLRenderer.find("GEFORCE3") != std::string::npos) | ||
419 | { | ||
420 | mIsGF3 = TRUE; | ||
421 | } | ||
422 | |||
423 | } | ||
424 | else if (mGLVendor.find("INTEL") != std::string::npos | ||
425 | #if LL_LINUX | ||
426 | // The Mesa-based drivers put this in the Renderer string, | ||
427 | // not the Vendor string. | ||
428 | || mGLRenderer.find("INTEL") != std::string::npos | ||
429 | #endif //LL_LINUX | ||
430 | ) | ||
431 | { | ||
432 | mGLVendorShort = "INTEL"; | ||
433 | mIsIntel = TRUE; | ||
434 | } | ||
435 | else | ||
436 | { | ||
437 | mGLVendorShort = "MISC"; | ||
438 | } | ||
439 | |||
440 | // This is called here because it depends on the setting of mIsGF2or4MX, and sets up mHasMultitexture. | ||
441 | initExtensions(); | ||
442 | |||
443 | if (mHasMultitexture) | ||
444 | { | ||
445 | GLint num_tex_units; | ||
446 | glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &num_tex_units); | ||
447 | mNumTextureUnits = llmin(num_tex_units, (GLint)MAX_GL_TEXTURE_UNITS); | ||
448 | if (mIsIntel) | ||
449 | { | ||
450 | mNumTextureUnits = llmin(mNumTextureUnits, 2); | ||
451 | } | ||
452 | } | ||
453 | else | ||
454 | { | ||
455 | mHasRequirements = FALSE; | ||
456 | |||
457 | // We don't support cards that don't support the GL_ARB_multitexture extension | ||
458 | LL_WARNS("RenderInit") << "GL Drivers do not support GL_ARB_multitexture" << LL_ENDL; | ||
459 | return false; | ||
460 | } | ||
461 | |||
462 | |||
463 | initGLStates(); | ||
464 | return true; | ||
465 | } | ||
466 | |||
467 | void LLGLManager::getGLInfo(LLSD& info) | ||
468 | { | ||
469 | info["GLInfo"]["GLVendor"] = std::string((const char *)glGetString(GL_VENDOR)); | ||
470 | info["GLInfo"]["GLRenderer"] = std::string((const char *)glGetString(GL_RENDERER)); | ||
471 | info["GLInfo"]["GLVersion"] = std::string((const char *)glGetString(GL_VERSION)); | ||
472 | |||
473 | #if !LL_MESA_HEADLESS | ||
474 | std::string all_exts = ll_safe_string((const char *)gGLHExts.mSysExts); | ||
475 | boost::char_separator<char> sep(" "); | ||
476 | boost::tokenizer<boost::char_separator<char> > tok(all_exts, sep); | ||
477 | for(boost::tokenizer<boost::char_separator<char> >::iterator i = tok.begin(); i != tok.end(); ++i) | ||
478 | { | ||
479 | info["GLInfo"]["GLExtensions"].append(*i); | ||
480 | } | ||
481 | #endif | ||
482 | } | ||
483 | |||
484 | std::string LLGLManager::getGLInfoString() | ||
485 | { | ||
486 | std::string info_str; | ||
487 | std::string all_exts, line; | ||
488 | |||
489 | info_str += std::string("GL_VENDOR ") + ll_safe_string((const char *)glGetString(GL_VENDOR)) + std::string("\n"); | ||
490 | info_str += std::string("GL_RENDERER ") + ll_safe_string((const char *)glGetString(GL_RENDERER)) + std::string("\n"); | ||
491 | info_str += std::string("GL_VERSION ") + ll_safe_string((const char *)glGetString(GL_VERSION)) + std::string("\n"); | ||
492 | |||
493 | #if !LL_MESA_HEADLESS | ||
494 | all_exts = (const char *)gGLHExts.mSysExts; | ||
495 | LLStringUtil::replaceChar(all_exts, ' ', '\n'); | ||
496 | info_str += std::string("GL_EXTENSIONS:\n") + all_exts + std::string("\n"); | ||
497 | #endif | ||
498 | |||
499 | return info_str; | ||
500 | } | ||
501 | |||
502 | void LLGLManager::printGLInfoString() | ||
503 | { | ||
504 | std::string info_str; | ||
505 | std::string all_exts, line; | ||
506 | |||
507 | LL_INFOS("RenderInit") << "GL_VENDOR: " << ((const char *)glGetString(GL_VENDOR)) << LL_ENDL; | ||
508 | LL_INFOS("RenderInit") << "GL_RENDERER: " << ((const char *)glGetString(GL_RENDERER)) << LL_ENDL; | ||
509 | LL_INFOS("RenderInit") << "GL_VERSION: " << ((const char *)glGetString(GL_VERSION)) << LL_ENDL; | ||
510 | |||
511 | #if !LL_MESA_HEADLESS | ||
512 | all_exts = std::string(gGLHExts.mSysExts); | ||
513 | LLStringUtil::replaceChar(all_exts, ' ', '\n'); | ||
514 | LL_DEBUGS("RenderInit") << "GL_EXTENSIONS:\n" << all_exts << LL_ENDL; | ||
515 | #endif | ||
516 | } | ||
517 | |||
518 | std::string LLGLManager::getRawGLString() | ||
519 | { | ||
520 | std::string gl_string; | ||
521 | gl_string = ll_safe_string((char*)glGetString(GL_VENDOR)) + " " + ll_safe_string((char*)glGetString(GL_RENDERER)); | ||
522 | return gl_string; | ||
523 | } | ||
524 | |||
525 | void LLGLManager::shutdownGL() | ||
526 | { | ||
527 | if (mInited) | ||
528 | { | ||
529 | glFinish(); | ||
530 | stop_glerror(); | ||
531 | mInited = FALSE; | ||
532 | } | ||
533 | } | ||
534 | |||
535 | // these are used to turn software blending on. They appear in the Debug/Avatar menu | ||
536 | // presence of vertex skinning/blending or vertex programs will set these to FALSE by default. | ||
537 | |||
538 | extern LLCPUInfo gSysCPU; | ||
539 | |||
540 | void LLGLManager::initExtensions() | ||
541 | { | ||
542 | #if LL_MESA_HEADLESS | ||
543 | # if GL_ARB_multitexture | ||
544 | mHasMultitexture = TRUE; | ||
545 | # else | ||
546 | mHasMultitexture = FALSE; | ||
547 | # endif | ||
548 | # if GL_ARB_texture_env_combine | ||
549 | mHasARBEnvCombine = TRUE; | ||
550 | # else | ||
551 | mHasARBEnvCombine = FALSE; | ||
552 | # endif | ||
553 | # if GL_ARB_texture_compression | ||
554 | mHasCompressedTextures = TRUE; | ||
555 | # else | ||
556 | mHasCompressedTextures = FALSE; | ||
557 | # endif | ||
558 | # if GL_ARB_vertex_buffer_object | ||
559 | mHasVertexBufferObject = TRUE; | ||
560 | # else | ||
561 | mHasVertexBufferObject = FALSE; | ||
562 | # endif | ||
563 | # if GL_EXT_framebuffer_object | ||
564 | mHasFramebufferObject = TRUE; | ||
565 | # else | ||
566 | mHasFramebufferObject = FALSE; | ||
567 | # endif | ||
568 | mHasMipMapGeneration = FALSE; | ||
569 | mHasPalettedTextures = FALSE; | ||
570 | mHasSeparateSpecularColor = FALSE; | ||
571 | mHasAnisotropic = FALSE; | ||
572 | mHasCubeMap = FALSE; | ||
573 | mHasOcclusionQuery = FALSE; | ||
574 | mHasPointParameters = FALSE; | ||
575 | mHasShaderObjects = FALSE; | ||
576 | mHasVertexShader = FALSE; | ||
577 | mHasFragmentShader = FALSE; | ||
578 | #else // LL_MESA_HEADLESS | ||
579 | mHasMultitexture = glh_init_extensions("GL_ARB_multitexture"); | ||
580 | mHasMipMapGeneration = glh_init_extensions("GL_SGIS_generate_mipmap"); | ||
581 | mHasPalettedTextures = glh_init_extension("GL_EXT_paletted_texture"); | ||
582 | mHasSeparateSpecularColor = glh_init_extensions("GL_EXT_separate_specular_color"); | ||
583 | mHasAnisotropic = glh_init_extensions("GL_EXT_texture_filter_anisotropic"); | ||
584 | glh_init_extensions("GL_ARB_texture_cube_map"); | ||
585 | mHasCubeMap = ExtensionExists("GL_ARB_texture_cube_map", gGLHExts.mSysExts); | ||
586 | mHasARBEnvCombine = ExtensionExists("GL_ARB_texture_env_combine", gGLHExts.mSysExts); | ||
587 | mHasCompressedTextures = glh_init_extensions("GL_ARB_texture_compression"); | ||
588 | mHasOcclusionQuery = ExtensionExists("GL_ARB_occlusion_query", gGLHExts.mSysExts); | ||
589 | mHasVertexBufferObject = ExtensionExists("GL_ARB_vertex_buffer_object", gGLHExts.mSysExts); | ||
590 | // mask out FBO support when packed_depth_stencil isn't there 'cause we need it for LLRenderTarget -Brad | ||
591 | mHasFramebufferObject = ExtensionExists("GL_EXT_framebuffer_object", gGLHExts.mSysExts) | ||
592 | && ExtensionExists("GL_EXT_packed_depth_stencil", gGLHExts.mSysExts); | ||
593 | #if !LL_DARWIN | ||
594 | mHasPointParameters = !mIsATI && ExtensionExists("GL_ARB_point_parameters", gGLHExts.mSysExts); | ||
595 | #endif | ||
596 | mHasShaderObjects = ExtensionExists("GL_ARB_shader_objects", gGLHExts.mSysExts) && ExtensionExists("GL_ARB_shading_language_100", gGLHExts.mSysExts); | ||
597 | mHasVertexShader = ExtensionExists("GL_ARB_vertex_program", gGLHExts.mSysExts) && ExtensionExists("GL_ARB_vertex_shader", gGLHExts.mSysExts) | ||
598 | && ExtensionExists("GL_ARB_shading_language_100", gGLHExts.mSysExts); | ||
599 | mHasFragmentShader = ExtensionExists("GL_ARB_fragment_shader", gGLHExts.mSysExts) && ExtensionExists("GL_ARB_shading_language_100", gGLHExts.mSysExts); | ||
600 | #endif | ||
601 | |||
602 | #if LL_LINUX | ||
603 | // Our extension support for the Linux Client is very young with some | ||
604 | // potential driver gotchas, so offer a semi-secret way to turn it off. | ||
605 | if (getenv("LL_GL_NOEXT")) /* Flawfinder: ignore */ | ||
606 | { | ||
607 | //mHasMultitexture = FALSE; // NEEDED! | ||
608 | mHasARBEnvCombine = FALSE; | ||
609 | mHasCompressedTextures = FALSE; | ||
610 | mHasVertexBufferObject = FALSE; | ||
611 | mHasFramebufferObject = FALSE; | ||
612 | mHasMipMapGeneration = FALSE; | ||
613 | mHasPalettedTextures = FALSE; | ||
614 | mHasSeparateSpecularColor = FALSE; | ||
615 | mHasAnisotropic = FALSE; | ||
616 | mHasCubeMap = FALSE; | ||
617 | mHasOcclusionQuery = FALSE; | ||
618 | mHasPointParameters = FALSE; | ||
619 | mHasShaderObjects = FALSE; | ||
620 | mHasVertexShader = FALSE; | ||
621 | mHasFragmentShader = FALSE; | ||
622 | LL_WARNS("RenderInit") << "GL extension support DISABLED via LL_GL_NOEXT" << LL_ENDL; | ||
623 | } | ||
624 | else if (getenv("LL_GL_BASICEXT")) /* Flawfinder: ignore */ | ||
625 | { | ||
626 | // This switch attempts to turn off all support for exotic | ||
627 | // extensions which I believe correspond to fatal driver | ||
628 | // bug reports. This should be the default until we get a | ||
629 | // proper blacklist/whitelist on Linux. | ||
630 | mHasMipMapGeneration = FALSE; | ||
631 | mHasPalettedTextures = FALSE; | ||
632 | mHasAnisotropic = FALSE; | ||
633 | //mHasCubeMap = FALSE; // apparently fatal on Intel 915 & similar | ||
634 | //mHasOcclusionQuery = FALSE; // source of many ATI system hangs | ||
635 | mHasShaderObjects = FALSE; | ||
636 | mHasVertexShader = FALSE; | ||
637 | mHasFragmentShader = FALSE; | ||
638 | LL_WARNS("RenderInit") << "GL extension support forced to SIMPLE level via LL_GL_BASICEXT" << LL_ENDL; | ||
639 | } | ||
640 | if (getenv("LL_GL_BLACKLIST")) /* Flawfinder: ignore */ | ||
641 | { | ||
642 | // This lets advanced troubleshooters disable specific | ||
643 | // GL extensions to isolate problems with their hardware. | ||
644 | // SL-28126 | ||
645 | const char *const blacklist = getenv("LL_GL_BLACKLIST"); /* Flawfinder: ignore */ | ||
646 | LL_WARNS("RenderInit") << "GL extension support partially disabled via LL_GL_BLACKLIST: " << blacklist << LL_ENDL; | ||
647 | if (strchr(blacklist,'a')) mHasARBEnvCombine = FALSE; | ||
648 | if (strchr(blacklist,'b')) mHasCompressedTextures = FALSE; | ||
649 | if (strchr(blacklist,'c')) mHasVertexBufferObject = FALSE; | ||
650 | if (strchr(blacklist,'d')) mHasMipMapGeneration = FALSE;//S | ||
651 | if (strchr(blacklist,'e')) mHasPalettedTextures = FALSE;//S | ||
652 | // if (strchr(blacklist,'f')) mHasNVVertexArrayRange = FALSE;//S | ||
653 | // if (strchr(blacklist,'g')) mHasNVFence = FALSE;//S | ||
654 | if (strchr(blacklist,'h')) mHasSeparateSpecularColor = FALSE; | ||
655 | if (strchr(blacklist,'i')) mHasAnisotropic = FALSE;//S | ||
656 | if (strchr(blacklist,'j')) mHasCubeMap = FALSE;//S | ||
657 | // if (strchr(blacklist,'k')) mHasATIVAO = FALSE;//S | ||
658 | if (strchr(blacklist,'l')) mHasOcclusionQuery = FALSE; | ||
659 | if (strchr(blacklist,'m')) mHasShaderObjects = FALSE;//S | ||
660 | if (strchr(blacklist,'n')) mHasVertexShader = FALSE;//S | ||
661 | if (strchr(blacklist,'o')) mHasFragmentShader = FALSE;//S | ||
662 | if (strchr(blacklist,'p')) mHasPointParameters = FALSE;//S | ||
663 | if (strchr(blacklist,'q')) mHasFramebufferObject = FALSE;//S | ||
664 | } | ||
665 | #endif // LL_LINUX | ||
666 | |||
667 | #if LL_DARWIN || LL_LINUX | ||
668 | // MBW -- 12/4/2003 -- Using paletted textures causes a bunch of avatar rendering problems on the Mac. | ||
669 | // Not sure if this is due to driver problems or incorrect use of the extension, but I'm disabling it for now. | ||
670 | // Tofu - 2006-10-03 -- Same problem on Linux. | ||
671 | mHasPalettedTextures = false; | ||
672 | #endif | ||
673 | |||
674 | if (!mHasMultitexture) | ||
675 | { | ||
676 | LL_INFOS("RenderInit") << "Couldn't initialize multitexturing" << LL_ENDL; | ||
677 | } | ||
678 | if (!mHasMipMapGeneration) | ||
679 | { | ||
680 | LL_INFOS("RenderInit") << "Couldn't initialize mipmap generation" << LL_ENDL; | ||
681 | } | ||
682 | if (!mHasARBEnvCombine) | ||
683 | { | ||
684 | LL_INFOS("RenderInit") << "Couldn't initialize GL_ARB_texture_env_combine" << LL_ENDL; | ||
685 | } | ||
686 | if (!mHasPalettedTextures) | ||
687 | { | ||
688 | LL_INFOS("RenderInit") << "Couldn't initialize GL_EXT_paletted_texture" << LL_ENDL; | ||
689 | } | ||
690 | if (!mHasSeparateSpecularColor) | ||
691 | { | ||
692 | LL_INFOS("RenderInit") << "Couldn't initialize separate specular color" << LL_ENDL; | ||
693 | } | ||
694 | if (!mHasAnisotropic) | ||
695 | { | ||
696 | LL_INFOS("RenderInit") << "Couldn't initialize anisotropic filtering" << LL_ENDL; | ||
697 | } | ||
698 | if (!mHasCompressedTextures) | ||
699 | { | ||
700 | LL_INFOS("RenderInit") << "Couldn't initialize GL_ARB_texture_compression" << LL_ENDL; | ||
701 | } | ||
702 | if (!mHasOcclusionQuery) | ||
703 | { | ||
704 | LL_INFOS("RenderInit") << "Couldn't initialize GL_ARB_occlusion_query" << LL_ENDL; | ||
705 | } | ||
706 | if (!mHasPointParameters) | ||
707 | { | ||
708 | LL_INFOS("RenderInit") << "Couldn't initialize GL_ARB_point_parameters" << LL_ENDL; | ||
709 | } | ||
710 | if (!mHasShaderObjects) | ||
711 | { | ||
712 | LL_INFOS("RenderInit") << "Couldn't initialize GL_ARB_shader_objects" << LL_ENDL; | ||
713 | } | ||
714 | if (!mHasVertexShader) | ||
715 | { | ||
716 | LL_INFOS("RenderInit") << "Couldn't initialize GL_ARB_vertex_shader" << LL_ENDL; | ||
717 | } | ||
718 | if (!mHasFragmentShader) | ||
719 | { | ||
720 | LL_INFOS("RenderInit") << "Couldn't initialize GL_ARB_fragment_shader" << LL_ENDL; | ||
721 | } | ||
722 | |||
723 | // Disable certain things due to known bugs | ||
724 | if (mIsIntel && mHasMipMapGeneration) | ||
725 | { | ||
726 | LL_INFOS("RenderInit") << "Disabling mip-map generation for Intel GPUs" << LL_ENDL; | ||
727 | mHasMipMapGeneration = FALSE; | ||
728 | } | ||
729 | if (mIsATI && mHasMipMapGeneration) | ||
730 | { | ||
731 | LL_INFOS("RenderInit") << "Disabling mip-map generation for ATI GPUs (performance opt)" << LL_ENDL; | ||
732 | mHasMipMapGeneration = FALSE; | ||
733 | } | ||
734 | |||
735 | // Misc | ||
736 | glGetIntegerv(GL_MAX_ELEMENTS_VERTICES, (GLint*) &mGLMaxVertexRange); | ||
737 | glGetIntegerv(GL_MAX_ELEMENTS_INDICES, (GLint*) &mGLMaxIndexRange); | ||
738 | |||
739 | #if (LL_WINDOWS || LL_LINUX) && !LL_MESA_HEADLESS | ||
740 | LL_DEBUGS("RenderInit") << "GL Probe: Getting symbols" << LL_ENDL; | ||
741 | if (mHasVertexBufferObject) | ||
742 | { | ||
743 | glBindBufferARB = (PFNGLBINDBUFFERARBPROC)GLH_EXT_GET_PROC_ADDRESS("glBindBufferARB"); | ||
744 | if (glBindBufferARB) | ||
745 | { | ||
746 | glDeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC)GLH_EXT_GET_PROC_ADDRESS("glDeleteBuffersARB"); | ||
747 | glGenBuffersARB = (PFNGLGENBUFFERSARBPROC)GLH_EXT_GET_PROC_ADDRESS("glGenBuffersARB"); | ||
748 | glIsBufferARB = (PFNGLISBUFFERARBPROC)GLH_EXT_GET_PROC_ADDRESS("glIsBufferARB"); | ||
749 | glBufferDataARB = (PFNGLBUFFERDATAARBPROC)GLH_EXT_GET_PROC_ADDRESS("glBufferDataARB"); | ||
750 | glBufferSubDataARB = (PFNGLBUFFERSUBDATAARBPROC)GLH_EXT_GET_PROC_ADDRESS("glBufferSubDataARB"); | ||
751 | glGetBufferSubDataARB = (PFNGLGETBUFFERSUBDATAARBPROC)GLH_EXT_GET_PROC_ADDRESS("glGetBufferSubDataARB"); | ||
752 | glMapBufferARB = (PFNGLMAPBUFFERARBPROC)GLH_EXT_GET_PROC_ADDRESS("glMapBufferARB"); | ||
753 | glUnmapBufferARB = (PFNGLUNMAPBUFFERARBPROC)GLH_EXT_GET_PROC_ADDRESS("glUnmapBufferARB"); | ||
754 | glGetBufferParameterivARB = (PFNGLGETBUFFERPARAMETERIVARBPROC)GLH_EXT_GET_PROC_ADDRESS("glGetBufferParameterivARB"); | ||
755 | glGetBufferPointervARB = (PFNGLGETBUFFERPOINTERVARBPROC)GLH_EXT_GET_PROC_ADDRESS("glGetBufferPointervARB"); | ||
756 | } | ||
757 | else | ||
758 | { | ||
759 | mHasVertexBufferObject = FALSE; | ||
760 | } | ||
761 | } | ||
762 | if (mHasFramebufferObject) | ||
763 | { | ||
764 | glIsRenderbufferEXT = (PFNGLISRENDERBUFFEREXTPROC) GLH_EXT_GET_PROC_ADDRESS("glIsRenderbufferEXT"); | ||
765 | glBindRenderbufferEXT = (PFNGLBINDRENDERBUFFEREXTPROC) GLH_EXT_GET_PROC_ADDRESS("glBindRenderbufferEXT"); | ||
766 | glDeleteRenderbuffersEXT = (PFNGLDELETERENDERBUFFERSEXTPROC) GLH_EXT_GET_PROC_ADDRESS("glDeleteRenderbuffersEXT"); | ||
767 | glGenRenderbuffersEXT = (PFNGLGENRENDERBUFFERSEXTPROC) GLH_EXT_GET_PROC_ADDRESS("glGenRenderbuffersEXT"); | ||
768 | glRenderbufferStorageEXT = (PFNGLRENDERBUFFERSTORAGEEXTPROC) GLH_EXT_GET_PROC_ADDRESS("glRenderbufferStorageEXT"); | ||
769 | glGetRenderbufferParameterivEXT = (PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC) GLH_EXT_GET_PROC_ADDRESS("glGetRenderbufferParameterivEXT"); | ||
770 | glIsFramebufferEXT = (PFNGLISFRAMEBUFFEREXTPROC) GLH_EXT_GET_PROC_ADDRESS("glIsFramebufferEXT"); | ||
771 | glBindFramebufferEXT = (PFNGLBINDFRAMEBUFFEREXTPROC) GLH_EXT_GET_PROC_ADDRESS("glBindFramebufferEXT"); | ||
772 | glDeleteFramebuffersEXT = (PFNGLDELETEFRAMEBUFFERSEXTPROC) GLH_EXT_GET_PROC_ADDRESS("glDeleteFramebuffersEXT"); | ||
773 | glGenFramebuffersEXT = (PFNGLGENFRAMEBUFFERSEXTPROC) GLH_EXT_GET_PROC_ADDRESS("glGenFramebuffersEXT"); | ||
774 | glCheckFramebufferStatusEXT = (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC) GLH_EXT_GET_PROC_ADDRESS("glCheckFramebufferStatusEXT"); | ||
775 | glFramebufferTexture1DEXT = (PFNGLFRAMEBUFFERTEXTURE1DEXTPROC) GLH_EXT_GET_PROC_ADDRESS("glFramebufferTexture1DEXT"); | ||
776 | glFramebufferTexture2DEXT = (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC) GLH_EXT_GET_PROC_ADDRESS("glFramebufferTexture2DEXT"); | ||
777 | glFramebufferTexture3DEXT = (PFNGLFRAMEBUFFERTEXTURE3DEXTPROC) GLH_EXT_GET_PROC_ADDRESS("glFramebufferTexture3DEXT"); | ||
778 | glFramebufferRenderbufferEXT = (PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC) GLH_EXT_GET_PROC_ADDRESS("glFramebufferRenderbufferEXT"); | ||
779 | glGetFramebufferAttachmentParameterivEXT = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC) GLH_EXT_GET_PROC_ADDRESS("glGetFramebufferAttachmentParameterivEXT"); | ||
780 | glGenerateMipmapEXT = (PFNGLGENERATEMIPMAPEXTPROC) GLH_EXT_GET_PROC_ADDRESS("glGenerateMipmapEXT"); | ||
781 | } | ||
782 | #if !LL_LINUX | ||
783 | // This is expected to be a static symbol on Linux GL implementations | ||
784 | glDrawRangeElements = (PFNGLDRAWRANGEELEMENTSPROC)GLH_EXT_GET_PROC_ADDRESS("glDrawRangeElements"); | ||
785 | if (!glDrawRangeElements) | ||
786 | { | ||
787 | mGLMaxVertexRange = 0; | ||
788 | mGLMaxIndexRange = 0; | ||
789 | } | ||
790 | #endif // !LL_LINUX | ||
791 | #if LL_LINUX | ||
792 | // On Linux we need to get glColorTableEXT dynamically. | ||
793 | if (mHasPalettedTextures) | ||
794 | { | ||
795 | glColorTableEXT = (PFNGLCOLORTABLEEXTPROC)GLH_EXT_GET_PROC_ADDRESS("glColorTableEXT"); | ||
796 | } | ||
797 | #endif // LL_LINUX | ||
798 | if (mHasOcclusionQuery) | ||
799 | { | ||
800 | glGenQueriesARB = (PFNGLGENQUERIESARBPROC)GLH_EXT_GET_PROC_ADDRESS("glGenQueriesARB"); | ||
801 | glDeleteQueriesARB = (PFNGLDELETEQUERIESARBPROC)GLH_EXT_GET_PROC_ADDRESS("glDeleteQueriesARB"); | ||
802 | glIsQueryARB = (PFNGLISQUERYARBPROC)GLH_EXT_GET_PROC_ADDRESS("glIsQueryARB"); | ||
803 | glBeginQueryARB = (PFNGLBEGINQUERYARBPROC)GLH_EXT_GET_PROC_ADDRESS("glBeginQueryARB"); | ||
804 | glEndQueryARB = (PFNGLENDQUERYARBPROC)GLH_EXT_GET_PROC_ADDRESS("glEndQueryARB"); | ||
805 | glGetQueryivARB = (PFNGLGETQUERYIVARBPROC)GLH_EXT_GET_PROC_ADDRESS("glGetQueryivARB"); | ||
806 | glGetQueryObjectivARB = (PFNGLGETQUERYOBJECTIVARBPROC)GLH_EXT_GET_PROC_ADDRESS("glGetQueryObjectivARB"); | ||
807 | glGetQueryObjectuivARB = (PFNGLGETQUERYOBJECTUIVARBPROC)GLH_EXT_GET_PROC_ADDRESS("glGetQueryObjectuivARB"); | ||
808 | } | ||
809 | if (mHasPointParameters) | ||
810 | { | ||
811 | glPointParameterfARB = (PFNGLPOINTPARAMETERFARBPROC)GLH_EXT_GET_PROC_ADDRESS("glPointParameterfARB"); | ||
812 | glPointParameterfvARB = (PFNGLPOINTPARAMETERFVARBPROC)GLH_EXT_GET_PROC_ADDRESS("glPointParameterfvARB"); | ||
813 | } | ||
814 | if (mHasShaderObjects) | ||
815 | { | ||
816 | glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC) GLH_EXT_GET_PROC_ADDRESS("glDeleteObjectARB"); | ||
817 | glGetHandleARB = (PFNGLGETHANDLEARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetHandleARB"); | ||
818 | glDetachObjectARB = (PFNGLDETACHOBJECTARBPROC) GLH_EXT_GET_PROC_ADDRESS("glDetachObjectARB"); | ||
819 | glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC) GLH_EXT_GET_PROC_ADDRESS("glCreateShaderObjectARB"); | ||
820 | glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC) GLH_EXT_GET_PROC_ADDRESS("glShaderSourceARB"); | ||
821 | glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC) GLH_EXT_GET_PROC_ADDRESS("glCompileShaderARB"); | ||
822 | glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC) GLH_EXT_GET_PROC_ADDRESS("glCreateProgramObjectARB"); | ||
823 | glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC) GLH_EXT_GET_PROC_ADDRESS("glAttachObjectARB"); | ||
824 | glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC) GLH_EXT_GET_PROC_ADDRESS("glLinkProgramARB"); | ||
825 | glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUseProgramObjectARB"); | ||
826 | glValidateProgramARB = (PFNGLVALIDATEPROGRAMARBPROC) GLH_EXT_GET_PROC_ADDRESS("glValidateProgramARB"); | ||
827 | glUniform1fARB = (PFNGLUNIFORM1FARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform1fARB"); | ||
828 | glUniform2fARB = (PFNGLUNIFORM2FARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform2fARB"); | ||
829 | glUniform3fARB = (PFNGLUNIFORM3FARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform3fARB"); | ||
830 | glUniform4fARB = (PFNGLUNIFORM4FARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform4fARB"); | ||
831 | glUniform1iARB = (PFNGLUNIFORM1IARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform1iARB"); | ||
832 | glUniform2iARB = (PFNGLUNIFORM2IARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform2iARB"); | ||
833 | glUniform3iARB = (PFNGLUNIFORM3IARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform3iARB"); | ||
834 | glUniform4iARB = (PFNGLUNIFORM4IARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform4iARB"); | ||
835 | glUniform1fvARB = (PFNGLUNIFORM1FVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform1fvARB"); | ||
836 | glUniform2fvARB = (PFNGLUNIFORM2FVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform2fvARB"); | ||
837 | glUniform3fvARB = (PFNGLUNIFORM3FVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform3fvARB"); | ||
838 | glUniform4fvARB = (PFNGLUNIFORM4FVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform4fvARB"); | ||
839 | glUniform1ivARB = (PFNGLUNIFORM1IVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform1ivARB"); | ||
840 | glUniform2ivARB = (PFNGLUNIFORM2IVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform2ivARB"); | ||
841 | glUniform3ivARB = (PFNGLUNIFORM3IVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform3ivARB"); | ||
842 | glUniform4ivARB = (PFNGLUNIFORM4IVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform4ivARB"); | ||
843 | glUniformMatrix2fvARB = (PFNGLUNIFORMMATRIX2FVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniformMatrix2fvARB"); | ||
844 | glUniformMatrix3fvARB = (PFNGLUNIFORMMATRIX3FVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniformMatrix3fvARB"); | ||
845 | glUniformMatrix4fvARB = (PFNGLUNIFORMMATRIX4FVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniformMatrix4fvARB"); | ||
846 | glGetObjectParameterfvARB = (PFNGLGETOBJECTPARAMETERFVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetObjectParameterfvARB"); | ||
847 | glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetObjectParameterivARB"); | ||
848 | glGetInfoLogARB = (PFNGLGETINFOLOGARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetInfoLogARB"); | ||
849 | glGetAttachedObjectsARB = (PFNGLGETATTACHEDOBJECTSARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetAttachedObjectsARB"); | ||
850 | glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetUniformLocationARB"); | ||
851 | glGetActiveUniformARB = (PFNGLGETACTIVEUNIFORMARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetActiveUniformARB"); | ||
852 | glGetUniformfvARB = (PFNGLGETUNIFORMFVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetUniformfvARB"); | ||
853 | glGetUniformivARB = (PFNGLGETUNIFORMIVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetUniformivARB"); | ||
854 | glGetShaderSourceARB = (PFNGLGETSHADERSOURCEARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetShaderSourceARB"); | ||
855 | } | ||
856 | if (mHasVertexShader) | ||
857 | { | ||
858 | glGetAttribLocationARB = (PFNGLGETATTRIBLOCATIONARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetAttribLocationARB"); | ||
859 | glBindAttribLocationARB = (PFNGLBINDATTRIBLOCATIONARBPROC) GLH_EXT_GET_PROC_ADDRESS("glBindAttribLocationARB"); | ||
860 | glGetActiveAttribARB = (PFNGLGETACTIVEATTRIBARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetActiveAttribARB"); | ||
861 | glVertexAttrib1dARB = (PFNGLVERTEXATTRIB1DARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib1dARB"); | ||
862 | glVertexAttrib1dvARB = (PFNGLVERTEXATTRIB1DVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib1dvARB"); | ||
863 | glVertexAttrib1fARB = (PFNGLVERTEXATTRIB1FARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib1fARB"); | ||
864 | glVertexAttrib1fvARB = (PFNGLVERTEXATTRIB1FVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib1fvARB"); | ||
865 | glVertexAttrib1sARB = (PFNGLVERTEXATTRIB1SARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib1sARB"); | ||
866 | glVertexAttrib1svARB = (PFNGLVERTEXATTRIB1SVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib1svARB"); | ||
867 | glVertexAttrib2dARB = (PFNGLVERTEXATTRIB2DARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib2dARB"); | ||
868 | glVertexAttrib2dvARB = (PFNGLVERTEXATTRIB2DVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib2dvARB"); | ||
869 | glVertexAttrib2fARB = (PFNGLVERTEXATTRIB2FARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib2fARB"); | ||
870 | glVertexAttrib2fvARB = (PFNGLVERTEXATTRIB2FVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib2fvARB"); | ||
871 | glVertexAttrib2sARB = (PFNGLVERTEXATTRIB2SARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib2sARB"); | ||
872 | glVertexAttrib2svARB = (PFNGLVERTEXATTRIB2SVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib2svARB"); | ||
873 | glVertexAttrib3dARB = (PFNGLVERTEXATTRIB3DARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib3dARB"); | ||
874 | glVertexAttrib3dvARB = (PFNGLVERTEXATTRIB3DVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib3dvARB"); | ||
875 | glVertexAttrib3fARB = (PFNGLVERTEXATTRIB3FARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib3fARB"); | ||
876 | glVertexAttrib3fvARB = (PFNGLVERTEXATTRIB3FVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib3fvARB"); | ||
877 | glVertexAttrib3sARB = (PFNGLVERTEXATTRIB3SARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib3sARB"); | ||
878 | glVertexAttrib3svARB = (PFNGLVERTEXATTRIB3SVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib3svARB"); | ||
879 | glVertexAttrib4nbvARB = (PFNGLVERTEXATTRIB4NBVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4nbvARB"); | ||
880 | glVertexAttrib4nivARB = (PFNGLVERTEXATTRIB4NIVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4nivARB"); | ||
881 | glVertexAttrib4nsvARB = (PFNGLVERTEXATTRIB4NSVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4nsvARB"); | ||
882 | glVertexAttrib4nubARB = (PFNGLVERTEXATTRIB4NUBARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4nubARB"); | ||
883 | glVertexAttrib4nubvARB = (PFNGLVERTEXATTRIB4NUBVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4nubvARB"); | ||
884 | glVertexAttrib4nuivARB = (PFNGLVERTEXATTRIB4NUIVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4nuivARB"); | ||
885 | glVertexAttrib4nusvARB = (PFNGLVERTEXATTRIB4NUSVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4nusvARB"); | ||
886 | glVertexAttrib4bvARB = (PFNGLVERTEXATTRIB4BVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4bvARB"); | ||
887 | glVertexAttrib4dARB = (PFNGLVERTEXATTRIB4DARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4dARB"); | ||
888 | glVertexAttrib4dvARB = (PFNGLVERTEXATTRIB4DVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4dvARB"); | ||
889 | glVertexAttrib4fARB = (PFNGLVERTEXATTRIB4FARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4fARB"); | ||
890 | glVertexAttrib4fvARB = (PFNGLVERTEXATTRIB4FVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4fvARB"); | ||
891 | glVertexAttrib4ivARB = (PFNGLVERTEXATTRIB4IVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4ivARB"); | ||
892 | glVertexAttrib4sARB = (PFNGLVERTEXATTRIB4SARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4sARB"); | ||
893 | glVertexAttrib4svARB = (PFNGLVERTEXATTRIB4SVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4svARB"); | ||
894 | glVertexAttrib4ubvARB = (PFNGLVERTEXATTRIB4UBVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4ubvARB"); | ||
895 | glVertexAttrib4uivARB = (PFNGLVERTEXATTRIB4UIVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4uivARB"); | ||
896 | glVertexAttrib4usvARB = (PFNGLVERTEXATTRIB4USVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4usvARB"); | ||
897 | glVertexAttribPointerARB = (PFNGLVERTEXATTRIBPOINTERARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttribPointerARB"); | ||
898 | glEnableVertexAttribArrayARB = (PFNGLENABLEVERTEXATTRIBARRAYARBPROC) GLH_EXT_GET_PROC_ADDRESS("glEnableVertexAttribArrayARB"); | ||
899 | glDisableVertexAttribArrayARB = (PFNGLDISABLEVERTEXATTRIBARRAYARBPROC) GLH_EXT_GET_PROC_ADDRESS("glDisableVertexAttribArrayARB"); | ||
900 | glProgramStringARB = (PFNGLPROGRAMSTRINGARBPROC) GLH_EXT_GET_PROC_ADDRESS("glProgramStringARB"); | ||
901 | glBindProgramARB = (PFNGLBINDPROGRAMARBPROC) GLH_EXT_GET_PROC_ADDRESS("glBindProgramARB"); | ||
902 | glDeleteProgramsARB = (PFNGLDELETEPROGRAMSARBPROC) GLH_EXT_GET_PROC_ADDRESS("glDeleteProgramsARB"); | ||
903 | glGenProgramsARB = (PFNGLGENPROGRAMSARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGenProgramsARB"); | ||
904 | glProgramEnvParameter4dARB = (PFNGLPROGRAMENVPARAMETER4DARBPROC) GLH_EXT_GET_PROC_ADDRESS("glProgramEnvParameter4dARB"); | ||
905 | glProgramEnvParameter4dvARB = (PFNGLPROGRAMENVPARAMETER4DVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glProgramEnvParameter4dvARB"); | ||
906 | glProgramEnvParameter4fARB = (PFNGLPROGRAMENVPARAMETER4FARBPROC) GLH_EXT_GET_PROC_ADDRESS("glProgramEnvParameter4fARB"); | ||
907 | glProgramEnvParameter4fvARB = (PFNGLPROGRAMENVPARAMETER4FVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glProgramEnvParameter4fvARB"); | ||
908 | glProgramLocalParameter4dARB = (PFNGLPROGRAMLOCALPARAMETER4DARBPROC) GLH_EXT_GET_PROC_ADDRESS("glProgramLocalParameter4dARB"); | ||
909 | glProgramLocalParameter4dvARB = (PFNGLPROGRAMLOCALPARAMETER4DVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glProgramLocalParameter4dvARB"); | ||
910 | glProgramLocalParameter4fARB = (PFNGLPROGRAMLOCALPARAMETER4FARBPROC) GLH_EXT_GET_PROC_ADDRESS("glProgramLocalParameter4fARB"); | ||
911 | glProgramLocalParameter4fvARB = (PFNGLPROGRAMLOCALPARAMETER4FVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glProgramLocalParameter4fvARB"); | ||
912 | glGetProgramEnvParameterdvARB = (PFNGLGETPROGRAMENVPARAMETERDVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetProgramEnvParameterdvARB"); | ||
913 | glGetProgramEnvParameterfvARB = (PFNGLGETPROGRAMENVPARAMETERFVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetProgramEnvParameterfvARB"); | ||
914 | glGetProgramLocalParameterdvARB = (PFNGLGETPROGRAMLOCALPARAMETERDVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetProgramLocalParameterdvARB"); | ||
915 | glGetProgramLocalParameterfvARB = (PFNGLGETPROGRAMLOCALPARAMETERFVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetProgramLocalParameterfvARB"); | ||
916 | glGetProgramivARB = (PFNGLGETPROGRAMIVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetProgramivARB"); | ||
917 | glGetProgramStringARB = (PFNGLGETPROGRAMSTRINGARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetProgramStringARB"); | ||
918 | glGetVertexAttribdvARB = (PFNGLGETVERTEXATTRIBDVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetVertexAttribdvARB"); | ||
919 | glGetVertexAttribfvARB = (PFNGLGETVERTEXATTRIBFVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetVertexAttribfvARB"); | ||
920 | glGetVertexAttribivARB = (PFNGLGETVERTEXATTRIBIVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetVertexAttribivARB"); | ||
921 | glGetVertexAttribPointervARB = (PFNGLGETVERTEXATTRIBPOINTERVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glgetVertexAttribPointervARB"); | ||
922 | glIsProgramARB = (PFNGLISPROGRAMARBPROC) GLH_EXT_GET_PROC_ADDRESS("glIsProgramARB"); | ||
923 | } | ||
924 | LL_DEBUGS("RenderInit") << "GL Probe: Got symbols" << LL_ENDL; | ||
925 | #endif | ||
926 | |||
927 | mInited = TRUE; | ||
928 | } | ||
929 | |||
930 | void rotate_quat(LLQuaternion& rotation) | ||
931 | { | ||
932 | F32 angle_radians, x, y, z; | ||
933 | rotation.getAngleAxis(&angle_radians, &x, &y, &z); | ||
934 | glRotatef(angle_radians * RAD_TO_DEG, x, y, z); | ||
935 | } | ||
936 | |||
937 | void flush_glerror() | ||
938 | { | ||
939 | glGetError(); | ||
940 | } | ||
941 | |||
942 | void assert_glerror() | ||
943 | { | ||
944 | if (gNoRender || !gDebugGL) | ||
945 | { | ||
946 | return; | ||
947 | } | ||
948 | if (!gGLManager.mInited) | ||
949 | { | ||
950 | LL_ERRS("RenderInit") << "GL not initialized" << LL_ENDL; | ||
951 | } | ||
952 | // Create or update texture to be used with this data | ||
953 | GLenum error; | ||
954 | error = glGetError(); | ||
955 | BOOL quit = FALSE; | ||
956 | while (error) | ||
957 | { | ||
958 | quit = TRUE; | ||
959 | #ifndef LL_LINUX // *FIX: ! This should be an error for linux as well. | ||
960 | GLubyte const * gl_error_msg = gluErrorString(error); | ||
961 | if (NULL != gl_error_msg) | ||
962 | { | ||
963 | LL_WARNS("RenderState") << "GL Error:" << gl_error_msg << LL_ENDL; | ||
964 | } | ||
965 | else | ||
966 | { | ||
967 | // gluErrorString returns NULL for some extensions' error codes. | ||
968 | // you'll probably have to grep for the number in glext.h. | ||
969 | LL_WARNS("RenderState") << "GL Error: UNKNOWN 0x" << std::hex << error << LL_ENDL; | ||
970 | } | ||
971 | error = glGetError(); | ||
972 | #endif | ||
973 | } | ||
974 | |||
975 | if (quit) | ||
976 | { | ||
977 | llerrs << "One or more unhandled GL errors." << llendl; | ||
978 | } | ||
979 | } | ||
980 | |||
981 | void clear_glerror() | ||
982 | { | ||
983 | // Create or update texture to be used with this data | ||
984 | GLenum error; | ||
985 | error = glGetError(); | ||
986 | } | ||
987 | |||
988 | /////////////////////////////////////////////////////////////// | ||
989 | // | ||
990 | // LLGLState | ||
991 | // | ||
992 | |||
993 | // Static members | ||
994 | std::map<LLGLenum, LLGLboolean> LLGLState::sStateMap; | ||
995 | |||
996 | GLboolean LLGLDepthTest::sDepthEnabled = GL_FALSE; // OpenGL default | ||
997 | GLenum LLGLDepthTest::sDepthFunc = GL_LESS; // OpenGL default | ||
998 | GLboolean LLGLDepthTest::sWriteEnabled = GL_TRUE; // OpenGL default | ||
999 | |||
1000 | //static | ||
1001 | void LLGLState::initClass() | ||
1002 | { | ||
1003 | sStateMap[GL_DITHER] = GL_TRUE; | ||
1004 | sStateMap[GL_TEXTURE_2D] = GL_TRUE; | ||
1005 | |||
1006 | //make sure multisample defaults to disabled | ||
1007 | sStateMap[GL_MULTISAMPLE_ARB] = GL_FALSE; | ||
1008 | glDisable(GL_MULTISAMPLE_ARB); | ||
1009 | |||
1010 | //default vertex arrays to enabled. | ||
1011 | glEnableClientState(GL_VERTEX_ARRAY); | ||
1012 | } | ||
1013 | |||
1014 | //static | ||
1015 | void LLGLState::restoreGL() | ||
1016 | { | ||
1017 | sStateMap.clear(); | ||
1018 | initClass(); | ||
1019 | } | ||
1020 | |||
1021 | //static | ||
1022 | // Really shouldn't be needed, but seems we sometimes do. | ||
1023 | void LLGLState::resetTextureStates() | ||
1024 | { | ||
1025 | gGL.flush(); | ||
1026 | GLint maxTextureUnits; | ||
1027 | |||
1028 | glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &maxTextureUnits); | ||
1029 | for (S32 j = maxTextureUnits-1; j >=0; j--) | ||
1030 | { | ||
1031 | gGL.getTexUnit(j)->activate(); | ||
1032 | glClientActiveTextureARB(GL_TEXTURE0_ARB+j); | ||
1033 | j == 0 ? glEnable(GL_TEXTURE_2D) : glDisable(GL_TEXTURE_2D); | ||
1034 | } | ||
1035 | } | ||
1036 | |||
1037 | void LLGLState::dumpStates() | ||
1038 | { | ||
1039 | LL_INFOS("RenderState") << "GL States:" << LL_ENDL; | ||
1040 | for (std::map<LLGLenum, LLGLboolean>::iterator iter = sStateMap.begin(); | ||
1041 | iter != sStateMap.end(); ++iter) | ||
1042 | { | ||
1043 | LL_INFOS("RenderState") << llformat(" 0x%04x : %s",(S32)iter->first,iter->second?"TRUE":"FALSE") << LL_ENDL; | ||
1044 | } | ||
1045 | } | ||
1046 | |||
1047 | void LLGLState::checkStates(const std::string& msg) | ||
1048 | { | ||
1049 | if (!gDebugGL) | ||
1050 | { | ||
1051 | return; | ||
1052 | } | ||
1053 | |||
1054 | stop_glerror(); | ||
1055 | |||
1056 | GLint activeTexture; | ||
1057 | glGetIntegerv(GL_ACTIVE_TEXTURE_ARB, &activeTexture); | ||
1058 | |||
1059 | if (activeTexture != GL_TEXTURE0_ARB) | ||
1060 | { | ||
1061 | LL_GL_ERRS << "Texture channel corrupted. " << LL_ENDL; | ||
1062 | } | ||
1063 | |||
1064 | GLint src; | ||
1065 | GLint dst; | ||
1066 | glGetIntegerv(GL_BLEND_SRC, &src); | ||
1067 | glGetIntegerv(GL_BLEND_DST, &dst); | ||
1068 | |||
1069 | if (src != GL_SRC_ALPHA || dst != GL_ONE_MINUS_SRC_ALPHA) | ||
1070 | { | ||
1071 | LL_GL_ERRS << "Blend function corrupted: " << std::hex << src << " " << std::hex << dst << " " << msg << LL_ENDL; | ||
1072 | } | ||
1073 | |||
1074 | for (std::map<LLGLenum, LLGLboolean>::iterator iter = sStateMap.begin(); | ||
1075 | iter != sStateMap.end(); ++iter) | ||
1076 | { | ||
1077 | LLGLenum state = iter->first; | ||
1078 | LLGLboolean cur_state = iter->second; | ||
1079 | LLGLboolean gl_state = glIsEnabled(state); | ||
1080 | if(cur_state != gl_state) | ||
1081 | { | ||
1082 | dumpStates(); | ||
1083 | LL_GL_ERRS << llformat("LLGLState error. State: 0x%04x",state) << LL_ENDL; | ||
1084 | } | ||
1085 | } | ||
1086 | |||
1087 | stop_glerror(); | ||
1088 | } | ||
1089 | |||
1090 | void LLGLState::checkTextureChannels(const std::string& msg) | ||
1091 | { | ||
1092 | if (!gDebugGL) | ||
1093 | { | ||
1094 | return; | ||
1095 | } | ||
1096 | |||
1097 | GLint activeTexture; | ||
1098 | glGetIntegerv(GL_ACTIVE_TEXTURE_ARB, &activeTexture); | ||
1099 | |||
1100 | BOOL error = FALSE; | ||
1101 | |||
1102 | if (activeTexture != GL_TEXTURE0_ARB) | ||
1103 | { | ||
1104 | error = TRUE; | ||
1105 | LL_WARNS("RenderState") << "Active texture channel corrupted. " << LL_ENDL; | ||
1106 | } | ||
1107 | else if (!glIsEnabled(GL_TEXTURE_2D)) | ||
1108 | { | ||
1109 | error = TRUE; | ||
1110 | LL_WARNS("RenderState") << "GL_TEXTURE_2D not enabled on texture channel 0." << LL_ENDL; | ||
1111 | } | ||
1112 | else | ||
1113 | { | ||
1114 | GLint tex_env_mode = 0; | ||
1115 | |||
1116 | glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &tex_env_mode); | ||
1117 | if (tex_env_mode != GL_MODULATE) | ||
1118 | { | ||
1119 | error = TRUE; | ||
1120 | LL_WARNS("RenderState") << "GL_TEXTURE_ENV_MODE invalid: " << std::hex << tex_env_mode << LL_ENDL; | ||
1121 | } | ||
1122 | } | ||
1123 | |||
1124 | GLint maxTextureUnits; | ||
1125 | glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &maxTextureUnits); | ||
1126 | |||
1127 | static const char* label[] = | ||
1128 | { | ||
1129 | "GL_TEXTURE_2D", | ||
1130 | "GL_TEXTURE_COORD_ARRAY", | ||
1131 | "GL_TEXTURE_1D", | ||
1132 | "GL_TEXTURE_CUBE_MAP_ARB", | ||
1133 | "GL_TEXTURE_GEN_S", | ||
1134 | "GL_TEXTURE_GEN_T", | ||
1135 | "GL_TEXTURE_GEN_Q", | ||
1136 | "GL_TEXTURE_GEN_R" | ||
1137 | }; | ||
1138 | |||
1139 | static GLint value[] = | ||
1140 | { | ||
1141 | GL_TEXTURE_2D, | ||
1142 | GL_TEXTURE_COORD_ARRAY, | ||
1143 | GL_TEXTURE_1D, | ||
1144 | GL_TEXTURE_CUBE_MAP_ARB, | ||
1145 | GL_TEXTURE_GEN_S, | ||
1146 | GL_TEXTURE_GEN_T, | ||
1147 | GL_TEXTURE_GEN_Q, | ||
1148 | GL_TEXTURE_GEN_R | ||
1149 | }; | ||
1150 | |||
1151 | GLint stackDepth = 0; | ||
1152 | LLMatrix4 identity; | ||
1153 | LLMatrix4 matrix; | ||
1154 | |||
1155 | for (GLint i = 0; i < maxTextureUnits; i++) | ||
1156 | { | ||
1157 | gGL.getTexUnit(i)->activate(); | ||
1158 | glClientActiveTextureARB(GL_TEXTURE0_ARB+i); | ||
1159 | |||
1160 | glGetIntegerv(GL_TEXTURE_STACK_DEPTH, &stackDepth); | ||
1161 | |||
1162 | if (stackDepth != 1) | ||
1163 | { | ||
1164 | error = TRUE; | ||
1165 | LL_WARNS("RenderState") << "Texture matrix stack corrupted." << LL_ENDL; | ||
1166 | } | ||
1167 | |||
1168 | glGetFloatv(GL_TEXTURE_MATRIX, (GLfloat*) matrix.mMatrix); | ||
1169 | |||
1170 | if (matrix != identity) | ||
1171 | { | ||
1172 | error = TRUE; | ||
1173 | LL_WARNS("RenderState") << "Texture matrix in channel " << i << " corrupt." << LL_ENDL; | ||
1174 | } | ||
1175 | |||
1176 | for (S32 j = (i == 0 ? 1 : 0); j < 8; j++) | ||
1177 | { | ||
1178 | if (glIsEnabled(value[j])) | ||
1179 | { | ||
1180 | error = TRUE; | ||
1181 | LL_WARNS("RenderState") << "Texture channel " << i << " still has " << label[j] << " enabled." << LL_ENDL; | ||
1182 | } | ||
1183 | } | ||
1184 | } | ||
1185 | |||
1186 | gGL.getTexUnit(0)->activate(); | ||
1187 | glClientActiveTextureARB(GL_TEXTURE0_ARB); | ||
1188 | |||
1189 | if (error) | ||
1190 | { | ||
1191 | LL_GL_ERRS << "GL texture state corruption detected. " << msg << LL_ENDL; | ||
1192 | } | ||
1193 | } | ||
1194 | |||
1195 | void LLGLState::checkClientArrays(const std::string& msg, U32 data_mask) | ||
1196 | { | ||
1197 | if (!gDebugGL) | ||
1198 | { | ||
1199 | return; | ||
1200 | } | ||
1201 | |||
1202 | stop_glerror(); | ||
1203 | BOOL error = FALSE; | ||
1204 | |||
1205 | GLint active_texture; | ||
1206 | glGetIntegerv(GL_CLIENT_ACTIVE_TEXTURE_ARB, &active_texture); | ||
1207 | |||
1208 | if (active_texture != GL_TEXTURE0_ARB) | ||
1209 | { | ||
1210 | llwarns << "Client active texture corrupted: " << active_texture << llendl; | ||
1211 | error = TRUE; | ||
1212 | } | ||
1213 | |||
1214 | glGetIntegerv(GL_ACTIVE_TEXTURE_ARB, &active_texture); | ||
1215 | if (active_texture != GL_TEXTURE0_ARB) | ||
1216 | { | ||
1217 | llwarns << "Active texture corrupted: " << active_texture << llendl; | ||
1218 | error = TRUE; | ||
1219 | } | ||
1220 | |||
1221 | static const char* label[] = | ||
1222 | { | ||
1223 | "GL_VERTEX_ARRAY", | ||
1224 | "GL_NORMAL_ARRAY", | ||
1225 | "GL_COLOR_ARRAY", | ||
1226 | "GL_TEXTURE_COORD_ARRAY" | ||
1227 | }; | ||
1228 | |||
1229 | static GLint value[] = | ||
1230 | { | ||
1231 | GL_VERTEX_ARRAY, | ||
1232 | GL_NORMAL_ARRAY, | ||
1233 | GL_COLOR_ARRAY, | ||
1234 | GL_TEXTURE_COORD_ARRAY | ||
1235 | }; | ||
1236 | |||
1237 | U32 mask[] = | ||
1238 | { //copied from llvertexbuffer.h | ||
1239 | 0x0001, //MAP_VERTEX, | ||
1240 | 0x0002, //MAP_NORMAL, | ||
1241 | 0x0010, //MAP_COLOR, | ||
1242 | 0x0004, //MAP_TEXCOORD | ||
1243 | }; | ||
1244 | |||
1245 | |||
1246 | for (S32 j = 0; j < 4; j++) | ||
1247 | { | ||
1248 | if (glIsEnabled(value[j])) | ||
1249 | { | ||
1250 | if (!(mask[j] & data_mask)) | ||
1251 | { | ||
1252 | error = TRUE; | ||
1253 | LL_WARNS("RenderState") << "GL still has " << label[j] << " enabled." << LL_ENDL; | ||
1254 | } | ||
1255 | } | ||
1256 | else | ||
1257 | { | ||
1258 | if (mask[j] & data_mask) | ||
1259 | { | ||
1260 | error = TRUE; | ||
1261 | LL_WARNS("RenderState") << "GL does not have " << label[j] << " enabled." << LL_ENDL; | ||
1262 | } | ||
1263 | } | ||
1264 | } | ||
1265 | |||
1266 | glClientActiveTextureARB(GL_TEXTURE1_ARB); | ||
1267 | gGL.getTexUnit(1)->activate(); | ||
1268 | if (glIsEnabled(GL_TEXTURE_COORD_ARRAY)) | ||
1269 | { | ||
1270 | if (!(data_mask & 0x0008)) | ||
1271 | { | ||
1272 | error = TRUE; | ||
1273 | LL_WARNS("RenderState") << "GL still has GL_TEXTURE_COORD_ARRAY enabled on channel 1." << LL_ENDL; | ||
1274 | } | ||
1275 | } | ||
1276 | else | ||
1277 | { | ||
1278 | if (data_mask & 0x0008) | ||
1279 | { | ||
1280 | error = TRUE; | ||
1281 | LL_WARNS("RenderState") << "GL does not have GL_TEXTURE_COORD_ARRAY enabled on channel 1." << LL_ENDL; | ||
1282 | } | ||
1283 | } | ||
1284 | |||
1285 | if (glIsEnabled(GL_TEXTURE_2D)) | ||
1286 | { | ||
1287 | if (!(data_mask & 0x0008)) | ||
1288 | { | ||
1289 | error = TRUE; | ||
1290 | LL_WARNS("RenderState") << "GL still has GL_TEXTURE_2D enabled on channel 1." << LL_ENDL; | ||
1291 | } | ||
1292 | } | ||
1293 | else | ||
1294 | { | ||
1295 | if (data_mask & 0x0008) | ||
1296 | { | ||
1297 | error = TRUE; | ||
1298 | LL_WARNS("RenderState") << "GL does not have GL_TEXTURE_2D enabled on channel 1." << LL_ENDL; | ||
1299 | } | ||
1300 | } | ||
1301 | |||
1302 | glClientActiveTextureARB(GL_TEXTURE0_ARB); | ||
1303 | gGL.getTexUnit(0)->activate(); | ||
1304 | |||
1305 | if (error) | ||
1306 | { | ||
1307 | LL_GL_ERRS << "GL client array corruption detected. " << msg << LL_ENDL; | ||
1308 | } | ||
1309 | } | ||
1310 | |||
1311 | /////////////////////////////////////////////////////////////////////// | ||
1312 | |||
1313 | LLGLState::LLGLState(LLGLenum state, S32 enabled) : | ||
1314 | mState(state), mWasEnabled(FALSE), mIsEnabled(FALSE) | ||
1315 | { | ||
1316 | stop_glerror(); | ||
1317 | if (state) | ||
1318 | { | ||
1319 | mWasEnabled = sStateMap[state]; | ||
1320 | llassert(mWasEnabled == glIsEnabled(state)); | ||
1321 | setEnabled(enabled); | ||
1322 | stop_glerror(); | ||
1323 | } | ||
1324 | } | ||
1325 | |||
1326 | void LLGLState::setEnabled(S32 enabled) | ||
1327 | { | ||
1328 | if (!mState) | ||
1329 | { | ||
1330 | return; | ||
1331 | } | ||
1332 | if (enabled == CURRENT_STATE) | ||
1333 | { | ||
1334 | enabled = sStateMap[mState] == GL_TRUE ? TRUE : FALSE; | ||
1335 | } | ||
1336 | else if (enabled == TRUE && sStateMap[mState] != GL_TRUE) | ||
1337 | { | ||
1338 | gGL.flush(); | ||
1339 | glEnable(mState); | ||
1340 | sStateMap[mState] = GL_TRUE; | ||
1341 | } | ||
1342 | else if (enabled == FALSE && sStateMap[mState] != GL_FALSE) | ||
1343 | { | ||
1344 | gGL.flush(); | ||
1345 | glDisable(mState); | ||
1346 | sStateMap[mState] = GL_FALSE; | ||
1347 | } | ||
1348 | mIsEnabled = enabled; | ||
1349 | } | ||
1350 | |||
1351 | LLGLState::~LLGLState() | ||
1352 | { | ||
1353 | stop_glerror(); | ||
1354 | if (mState) | ||
1355 | { | ||
1356 | if (gDebugGL) | ||
1357 | { | ||
1358 | llassert_always(sStateMap[mState] == glIsEnabled(mState)); | ||
1359 | } | ||
1360 | |||
1361 | if (mIsEnabled != mWasEnabled) | ||
1362 | { | ||
1363 | gGL.flush(); | ||
1364 | if (mWasEnabled) | ||
1365 | { | ||
1366 | glEnable(mState); | ||
1367 | sStateMap[mState] = GL_TRUE; | ||
1368 | } | ||
1369 | else | ||
1370 | { | ||
1371 | glDisable(mState); | ||
1372 | sStateMap[mState] = GL_FALSE; | ||
1373 | } | ||
1374 | } | ||
1375 | } | ||
1376 | stop_glerror(); | ||
1377 | } | ||
1378 | |||
1379 | //////////////////////////////////////////////////////////////////////////////// | ||
1380 | |||
1381 | void LLGLManager::initGLStates() | ||
1382 | { | ||
1383 | //gl states moved to classes in llglstates.h | ||
1384 | LLGLState::initClass(); | ||
1385 | } | ||
1386 | |||
1387 | //////////////////////////////////////////////////////////////////////////////// | ||
1388 | |||
1389 | void enable_vertex_weighting(const S32 index) | ||
1390 | { | ||
1391 | #if GL_ARB_vertex_program | ||
1392 | if (index > 0) glEnableVertexAttribArrayARB(index); // vertex weights | ||
1393 | #endif | ||
1394 | } | ||
1395 | |||
1396 | void disable_vertex_weighting(const S32 index) | ||
1397 | { | ||
1398 | #if GL_ARB_vertex_program | ||
1399 | if (index > 0) glDisableVertexAttribArrayARB(index); // vertex weights | ||
1400 | #endif | ||
1401 | } | ||
1402 | |||
1403 | void enable_binormals(const S32 index) | ||
1404 | { | ||
1405 | #if GL_ARB_vertex_program | ||
1406 | if (index > 0) | ||
1407 | { | ||
1408 | glEnableVertexAttribArrayARB(index); // binormals | ||
1409 | } | ||
1410 | #endif | ||
1411 | } | ||
1412 | |||
1413 | void disable_binormals(const S32 index) | ||
1414 | { | ||
1415 | #if GL_ARB_vertex_program | ||
1416 | if (index > 0) | ||
1417 | { | ||
1418 | glDisableVertexAttribArrayARB(index); // binormals | ||
1419 | } | ||
1420 | #endif | ||
1421 | } | ||
1422 | |||
1423 | |||
1424 | void enable_cloth_weights(const S32 index) | ||
1425 | { | ||
1426 | #if GL_ARB_vertex_program | ||
1427 | if (index > 0) glEnableVertexAttribArrayARB(index); | ||
1428 | #endif | ||
1429 | } | ||
1430 | |||
1431 | void disable_cloth_weights(const S32 index) | ||
1432 | { | ||
1433 | #if GL_ARB_vertex_program | ||
1434 | if (index > 0) glDisableVertexAttribArrayARB(index); | ||
1435 | #endif | ||
1436 | } | ||
1437 | |||
1438 | void set_vertex_weights(const S32 index, const U32 stride, const F32 *weights) | ||
1439 | { | ||
1440 | #if GL_ARB_vertex_program | ||
1441 | if (index > 0) glVertexAttribPointerARB(index, 1, GL_FLOAT, FALSE, stride, weights); | ||
1442 | stop_glerror(); | ||
1443 | #endif | ||
1444 | } | ||
1445 | |||
1446 | void set_vertex_clothing_weights(const S32 index, const U32 stride, const LLVector4 *weights) | ||
1447 | { | ||
1448 | #if GL_ARB_vertex_program | ||
1449 | if (index > 0) glVertexAttribPointerARB(index, 4, GL_FLOAT, TRUE, stride, weights); | ||
1450 | stop_glerror(); | ||
1451 | #endif | ||
1452 | } | ||
1453 | |||
1454 | void set_binormals(const S32 index, const U32 stride,const LLVector3 *binormals) | ||
1455 | { | ||
1456 | #if GL_ARB_vertex_program | ||
1457 | if (index > 0) glVertexAttribPointerARB(index, 3, GL_FLOAT, FALSE, stride, binormals); | ||
1458 | stop_glerror(); | ||
1459 | #endif | ||
1460 | } | ||
1461 | |||
1462 | |||
1463 | void set_palette(U8 *palette_data) | ||
1464 | { | ||
1465 | if (gGLManager.mHasPalettedTextures) | ||
1466 | { | ||
1467 | glColorTableEXT(GL_TEXTURE_2D, GL_RGBA8, 256, GL_RGBA, GL_UNSIGNED_BYTE, palette_data); | ||
1468 | } | ||
1469 | } | ||
1470 | |||
1471 | |||
1472 | void parse_gl_version( S32* major, S32* minor, S32* release, std::string* vendor_specific ) | ||
1473 | { | ||
1474 | // GL_VERSION returns a null-terminated string with the format: | ||
1475 | // <major>.<minor>[.<release>] [<vendor specific>] | ||
1476 | |||
1477 | const char* version = (const char*) glGetString(GL_VERSION); | ||
1478 | *major = 0; | ||
1479 | *minor = 0; | ||
1480 | *release = 0; | ||
1481 | vendor_specific->assign(""); | ||
1482 | |||
1483 | if( !version ) | ||
1484 | { | ||
1485 | return; | ||
1486 | } | ||
1487 | |||
1488 | std::string ver_copy( version ); | ||
1489 | S32 len = (S32)strlen( version ); /* Flawfinder: ignore */ | ||
1490 | S32 i = 0; | ||
1491 | S32 start; | ||
1492 | // Find the major version | ||
1493 | start = i; | ||
1494 | for( ; i < len; i++ ) | ||
1495 | { | ||
1496 | if( '.' == version[i] ) | ||
1497 | { | ||
1498 | break; | ||
1499 | } | ||
1500 | } | ||
1501 | std::string major_str = ver_copy.substr(start,i-start); | ||
1502 | LLStringUtil::convertToS32(major_str, *major); | ||
1503 | |||
1504 | if( '.' == version[i] ) | ||
1505 | { | ||
1506 | i++; | ||
1507 | } | ||
1508 | |||
1509 | // Find the minor version | ||
1510 | start = i; | ||
1511 | for( ; i < len; i++ ) | ||
1512 | { | ||
1513 | if( ('.' == version[i]) || isspace(version[i]) ) | ||
1514 | { | ||
1515 | break; | ||
1516 | } | ||
1517 | } | ||
1518 | std::string minor_str = ver_copy.substr(start,i-start); | ||
1519 | LLStringUtil::convertToS32(minor_str, *minor); | ||
1520 | |||
1521 | // Find the release number (optional) | ||
1522 | if( '.' == version[i] ) | ||
1523 | { | ||
1524 | i++; | ||
1525 | |||
1526 | start = i; | ||
1527 | for( ; i < len; i++ ) | ||
1528 | { | ||
1529 | if( isspace(version[i]) ) | ||
1530 | { | ||
1531 | break; | ||
1532 | } | ||
1533 | } | ||
1534 | |||
1535 | std::string release_str = ver_copy.substr(start,i-start); | ||
1536 | LLStringUtil::convertToS32(release_str, *release); | ||
1537 | } | ||
1538 | |||
1539 | // Skip over any white space | ||
1540 | while( version[i] && isspace( version[i] ) ) | ||
1541 | { | ||
1542 | i++; | ||
1543 | } | ||
1544 | |||
1545 | // Copy the vendor-specific string (optional) | ||
1546 | if( version[i] ) | ||
1547 | { | ||
1548 | vendor_specific->assign( version + i ); | ||
1549 | } | ||
1550 | } | ||
1551 | |||
1552 | LLGLUserClipPlane::LLGLUserClipPlane(const LLPlane& p, const glh::matrix4f& modelview, const glh::matrix4f& projection) | ||
1553 | { | ||
1554 | mModelview = modelview; | ||
1555 | mProjection = projection; | ||
1556 | |||
1557 | setPlane(p.mV[0], p.mV[1], p.mV[2], p.mV[3]); | ||
1558 | } | ||
1559 | |||
1560 | void LLGLUserClipPlane::setPlane(F32 a, F32 b, F32 c, F32 d) | ||
1561 | { | ||
1562 | glh::matrix4f& P = mProjection; | ||
1563 | glh::matrix4f& M = mModelview; | ||
1564 | |||
1565 | glh::matrix4f invtrans_MVP = (P * M).inverse().transpose(); | ||
1566 | glh::vec4f oplane(a,b,c,d); | ||
1567 | glh::vec4f cplane; | ||
1568 | invtrans_MVP.mult_matrix_vec(oplane, cplane); | ||
1569 | |||
1570 | cplane /= fabs(cplane[2]); // normalize such that depth is not scaled | ||
1571 | cplane[3] -= 1; | ||
1572 | |||
1573 | if(cplane[2] < 0) | ||
1574 | cplane *= -1; | ||
1575 | |||
1576 | glh::matrix4f suffix; | ||
1577 | suffix.set_row(2, cplane); | ||
1578 | glh::matrix4f newP = suffix * P; | ||
1579 | glMatrixMode(GL_PROJECTION); | ||
1580 | glPushMatrix(); | ||
1581 | glLoadMatrixf(newP.m); | ||
1582 | gGLObliqueProjectionInverse = LLMatrix4(newP.inverse().transpose().m); | ||
1583 | glMatrixMode(GL_MODELVIEW); | ||
1584 | } | ||
1585 | |||
1586 | LLGLUserClipPlane::~LLGLUserClipPlane() | ||
1587 | { | ||
1588 | glMatrixMode(GL_PROJECTION); | ||
1589 | glPopMatrix(); | ||
1590 | glMatrixMode(GL_MODELVIEW); | ||
1591 | } | ||
1592 | |||
1593 | LLGLNamePool::LLGLNamePool() | ||
1594 | { | ||
1595 | } | ||
1596 | |||
1597 | void LLGLNamePool::registerPool(LLGLNamePool* pool) | ||
1598 | { | ||
1599 | pool_list_t::iterator iter = std::find(sInstances.begin(), sInstances.end(), pool); | ||
1600 | if (iter == sInstances.end()) | ||
1601 | { | ||
1602 | sInstances.push_back(pool); | ||
1603 | } | ||
1604 | } | ||
1605 | |||
1606 | LLGLNamePool::~LLGLNamePool() | ||
1607 | { | ||
1608 | pool_list_t::iterator iter = std::find(sInstances.begin(), sInstances.end(), this); | ||
1609 | if (iter != sInstances.end()) | ||
1610 | { | ||
1611 | sInstances.erase(iter); | ||
1612 | } | ||
1613 | } | ||
1614 | |||
1615 | void LLGLNamePool::upkeep() | ||
1616 | { | ||
1617 | std::sort(mNameList.begin(), mNameList.end(), CompareUsed()); | ||
1618 | } | ||
1619 | |||
1620 | void LLGLNamePool::cleanup() | ||
1621 | { | ||
1622 | for (name_list_t::iterator iter = mNameList.begin(); iter != mNameList.end(); ++iter) | ||
1623 | { | ||
1624 | releaseName(iter->name); | ||
1625 | } | ||
1626 | |||
1627 | mNameList.clear(); | ||
1628 | } | ||
1629 | |||
1630 | GLuint LLGLNamePool::allocate() | ||
1631 | { | ||
1632 | #if LL_GL_NAME_POOLING | ||
1633 | for (name_list_t::iterator iter = mNameList.begin(); iter != mNameList.end(); ++iter) | ||
1634 | { | ||
1635 | if (!iter->used) | ||
1636 | { | ||
1637 | iter->used = TRUE; | ||
1638 | return iter->name; | ||
1639 | } | ||
1640 | } | ||
1641 | |||
1642 | NameEntry entry; | ||
1643 | entry.name = allocateName(); | ||
1644 | entry.used = TRUE; | ||
1645 | mNameList.push_back(entry); | ||
1646 | |||
1647 | return entry.name; | ||
1648 | #else | ||
1649 | return allocateName(); | ||
1650 | #endif | ||
1651 | } | ||
1652 | |||
1653 | void LLGLNamePool::release(GLuint name) | ||
1654 | { | ||
1655 | #if LL_GL_NAME_POOLING | ||
1656 | for (name_list_t::iterator iter = mNameList.begin(); iter != mNameList.end(); ++iter) | ||
1657 | { | ||
1658 | if (iter->name == name) | ||
1659 | { | ||
1660 | if (iter->used) | ||
1661 | { | ||
1662 | iter->used = FALSE; | ||
1663 | return; | ||
1664 | } | ||
1665 | else | ||
1666 | { | ||
1667 | llerrs << "Attempted to release a pooled name that is not in use!" << llendl; | ||
1668 | } | ||
1669 | } | ||
1670 | } | ||
1671 | llerrs << "Attempted to release a non pooled name!" << llendl; | ||
1672 | #else | ||
1673 | releaseName(name); | ||
1674 | #endif | ||
1675 | } | ||
1676 | |||
1677 | //static | ||
1678 | void LLGLNamePool::upkeepPools() | ||
1679 | { | ||
1680 | for (pool_list_t::iterator iter = sInstances.begin(); iter != sInstances.end(); ++iter) | ||
1681 | { | ||
1682 | LLGLNamePool* pool = *iter; | ||
1683 | pool->upkeep(); | ||
1684 | } | ||
1685 | } | ||
1686 | |||
1687 | //static | ||
1688 | void LLGLNamePool::cleanupPools() | ||
1689 | { | ||
1690 | for (pool_list_t::iterator iter = sInstances.begin(); iter != sInstances.end(); ++iter) | ||
1691 | { | ||
1692 | LLGLNamePool* pool = *iter; | ||
1693 | pool->cleanup(); | ||
1694 | } | ||
1695 | } | ||
1696 | |||
1697 | LLGLDepthTest::LLGLDepthTest(GLboolean depth_enabled, GLboolean write_enabled, GLenum depth_func) | ||
1698 | : mPrevDepthEnabled(sDepthEnabled), mPrevDepthFunc(sDepthFunc), mPrevWriteEnabled(sWriteEnabled) | ||
1699 | { | ||
1700 | if (depth_enabled != sDepthEnabled) | ||
1701 | { | ||
1702 | gGL.flush(); | ||
1703 | if (depth_enabled) glEnable(GL_DEPTH_TEST); | ||
1704 | else glDisable(GL_DEPTH_TEST); | ||
1705 | sDepthEnabled = depth_enabled; | ||
1706 | } | ||
1707 | if (depth_func != sDepthFunc) | ||
1708 | { | ||
1709 | gGL.flush(); | ||
1710 | glDepthFunc(depth_func); | ||
1711 | sDepthFunc = depth_func; | ||
1712 | } | ||
1713 | if (write_enabled != sWriteEnabled) | ||
1714 | { | ||
1715 | gGL.flush(); | ||
1716 | glDepthMask(write_enabled); | ||
1717 | sWriteEnabled = write_enabled; | ||
1718 | } | ||
1719 | } | ||
1720 | |||
1721 | LLGLDepthTest::~LLGLDepthTest() | ||
1722 | { | ||
1723 | if (sDepthEnabled != mPrevDepthEnabled ) | ||
1724 | { | ||
1725 | gGL.flush(); | ||
1726 | if (mPrevDepthEnabled) glEnable(GL_DEPTH_TEST); | ||
1727 | else glDisable(GL_DEPTH_TEST); | ||
1728 | sDepthEnabled = mPrevDepthEnabled; | ||
1729 | } | ||
1730 | if (sDepthFunc != mPrevDepthFunc) | ||
1731 | { | ||
1732 | gGL.flush(); | ||
1733 | glDepthFunc(mPrevDepthFunc); | ||
1734 | sDepthFunc = mPrevDepthFunc; | ||
1735 | } | ||
1736 | if (sWriteEnabled != mPrevWriteEnabled ) | ||
1737 | { | ||
1738 | gGL.flush(); | ||
1739 | glDepthMask(mPrevWriteEnabled); | ||
1740 | sWriteEnabled = mPrevWriteEnabled; | ||
1741 | } | ||
1742 | } | ||
1743 | |||
1744 | LLGLClampToFarClip::LLGLClampToFarClip(glh::matrix4f P) | ||
1745 | { | ||
1746 | for (U32 i = 0; i < 4; i++) | ||
1747 | { | ||
1748 | P.element(2, i) = P.element(3, i) * 0.99999f; | ||
1749 | } | ||
1750 | |||
1751 | glMatrixMode(GL_PROJECTION); | ||
1752 | glPushMatrix(); | ||
1753 | glLoadMatrixf(P.m); | ||
1754 | glMatrixMode(GL_MODELVIEW); | ||
1755 | } | ||
1756 | |||
1757 | LLGLClampToFarClip::~LLGLClampToFarClip() | ||
1758 | { | ||
1759 | glMatrixMode(GL_PROJECTION); | ||
1760 | glPopMatrix(); | ||
1761 | glMatrixMode(GL_MODELVIEW); | ||
1762 | } | ||
1763 | |||
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 | ||
diff --git a/linden/indra/llrender/llgldbg.cpp b/linden/indra/llrender/llgldbg.cpp index 953ba3a..526215b 100644 --- a/linden/indra/llrender/llgldbg.cpp +++ b/linden/indra/llrender/llgldbg.cpp | |||
@@ -43,7 +43,7 @@ | |||
43 | //------------------------------------------------------------------------ | 43 | //------------------------------------------------------------------------ |
44 | // cmstr() | 44 | // cmstr() |
45 | //------------------------------------------------------------------------ | 45 | //------------------------------------------------------------------------ |
46 | char *cmstr(int i) | 46 | const char *cmstr(int i) |
47 | { | 47 | { |
48 | switch( i ) | 48 | switch( i ) |
49 | { | 49 | { |
@@ -59,7 +59,7 @@ char *cmstr(int i) | |||
59 | //------------------------------------------------------------------------ | 59 | //------------------------------------------------------------------------ |
60 | // facestr() | 60 | // facestr() |
61 | //------------------------------------------------------------------------ | 61 | //------------------------------------------------------------------------ |
62 | char *facestr(int i) | 62 | const char *facestr(int i) |
63 | { | 63 | { |
64 | switch( i ) | 64 | switch( i ) |
65 | { | 65 | { |
@@ -81,7 +81,7 @@ const char *boolstr(int b) | |||
81 | //------------------------------------------------------------------------ | 81 | //------------------------------------------------------------------------ |
82 | // fv4() | 82 | // fv4() |
83 | //------------------------------------------------------------------------ | 83 | //------------------------------------------------------------------------ |
84 | char *fv4(F32 *f) | 84 | const char *fv4(F32 *f) |
85 | { | 85 | { |
86 | static char str[128]; | 86 | static char str[128]; |
87 | sprintf(str, "%8.3f %8.3f %8.3f %8.3f", f[0], f[1], f[2], f[3]); | 87 | sprintf(str, "%8.3f %8.3f %8.3f %8.3f", f[0], f[1], f[2], f[3]); |
@@ -91,7 +91,7 @@ char *fv4(F32 *f) | |||
91 | //------------------------------------------------------------------------ | 91 | //------------------------------------------------------------------------ |
92 | // fv3() | 92 | // fv3() |
93 | //------------------------------------------------------------------------ | 93 | //------------------------------------------------------------------------ |
94 | char *fv3(F32 *f) | 94 | const char *fv3(F32 *f) |
95 | { | 95 | { |
96 | static char str[128]; /* Flawfinder: ignore */ | 96 | static char str[128]; /* Flawfinder: ignore */ |
97 | snprintf(str, sizeof(str), "%8.3f, %8.3f, %8.3f", f[0], f[1], f[2]); /* Flawfinder: ignore */ | 97 | snprintf(str, sizeof(str), "%8.3f, %8.3f, %8.3f", f[0], f[1], f[2]); /* Flawfinder: ignore */ |
@@ -101,7 +101,7 @@ char *fv3(F32 *f) | |||
101 | //------------------------------------------------------------------------ | 101 | //------------------------------------------------------------------------ |
102 | // fv1() | 102 | // fv1() |
103 | //------------------------------------------------------------------------ | 103 | //------------------------------------------------------------------------ |
104 | char *fv1(F32 *f) | 104 | const char *fv1(F32 *f) |
105 | { | 105 | { |
106 | static char str[128]; /* Flawfinder: ignore */ | 106 | static char str[128]; /* Flawfinder: ignore */ |
107 | snprintf(str, sizeof(str), "%8.3f", f[0]); /* Flawfinder: ignore */ | 107 | snprintf(str, sizeof(str), "%8.3f", f[0]); /* Flawfinder: ignore */ |
diff --git a/linden/indra/llrender/llglheaders.h b/linden/indra/llrender/llglheaders.h new file mode 100644 index 0000000..f047262 --- /dev/null +++ b/linden/indra/llrender/llglheaders.h | |||
@@ -0,0 +1,588 @@ | |||
1 | /** | ||
2 | * @file llglheaders.h | ||
3 | * @brief LLGL 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 | #ifndef LL_LLGLHEADERS_H | ||
33 | #define LL_LLGLHEADERS_H | ||
34 | |||
35 | #if LL_MESA | ||
36 | //---------------------------------------------------------------------------- | ||
37 | // MESA headers | ||
38 | // quotes so we get libraries/.../GL/ version | ||
39 | #define GL_GLEXT_PROTOTYPES | ||
40 | #include "GL/gl.h" | ||
41 | #include "GL/glext.h" | ||
42 | #include "GL/glu.h" | ||
43 | |||
44 | // The __APPLE__ kludge is to make glh_extensions.h not symbol-clash horribly | ||
45 | # define __APPLE__ | ||
46 | # include "GL/glh_extensions.h" | ||
47 | # undef __APPLE__ | ||
48 | |||
49 | #elif LL_LINUX | ||
50 | //---------------------------------------------------------------------------- | ||
51 | // Linux, MESA headers, but not necessarily assuming MESA runtime. | ||
52 | // quotes so we get libraries/.../GL/ version | ||
53 | #include "GL/gl.h" | ||
54 | #include "GL/glext.h" | ||
55 | #include "GL/glu.h" | ||
56 | |||
57 | |||
58 | #if LL_LINUX && !LL_MESA_HEADLESS | ||
59 | // The __APPLE__ kludge is to make glh_extensions.h not symbol-clash horribly | ||
60 | # define __APPLE__ | ||
61 | # include "GL/glh_extensions.h" | ||
62 | # undef __APPLE__ | ||
63 | |||
64 | /* Although SDL very likely ends up calling glXGetProcAddress() itself, | ||
65 | if we use SDL_GL_GetProcAddress() then we get bogus addresses back on | ||
66 | some systems. Weird. */ | ||
67 | /*# include "SDL/SDL.h" | ||
68 | # define GLH_EXT_GET_PROC_ADDRESS(p) SDL_GL_GetProcAddress(p) */ | ||
69 | #define GLX_GLXEXT_PROTOTYPES 1 | ||
70 | # include "GL/glx.h" | ||
71 | # include "GL/glxext.h" | ||
72 | // Use glXGetProcAddressARB instead of glXGetProcAddress - the ARB symbol | ||
73 | // is considered 'legacy' but works on more machines. | ||
74 | # define GLH_EXT_GET_PROC_ADDRESS(p) glXGetProcAddressARB((const GLubyte*)(p)) | ||
75 | // Whee, the X headers define 'Status'. Undefine to avoid confusion. | ||
76 | #undef Status | ||
77 | #endif // LL_LINUX && !LL_MESA_HEADLESS | ||
78 | |||
79 | |||
80 | // GL_ARB_vertex_buffer_object | ||
81 | extern PFNGLBINDBUFFERARBPROC glBindBufferARB; | ||
82 | extern PFNGLDELETEBUFFERSARBPROC glDeleteBuffersARB; | ||
83 | extern PFNGLGENBUFFERSARBPROC glGenBuffersARB; | ||
84 | extern PFNGLISBUFFERARBPROC glIsBufferARB; | ||
85 | extern PFNGLBUFFERDATAARBPROC glBufferDataARB; | ||
86 | extern PFNGLBUFFERSUBDATAARBPROC glBufferSubDataARB; | ||
87 | extern PFNGLGETBUFFERSUBDATAARBPROC glGetBufferSubDataARB; | ||
88 | extern PFNGLMAPBUFFERARBPROC glMapBufferARB; | ||
89 | extern PFNGLUNMAPBUFFERARBPROC glUnmapBufferARB; | ||
90 | extern PFNGLGETBUFFERPARAMETERIVARBPROC glGetBufferParameterivARB; | ||
91 | extern PFNGLGETBUFFERPOINTERVARBPROC glGetBufferPointervARB; | ||
92 | |||
93 | // GL_ATI_vertex_array_object | ||
94 | extern PFNGLNEWOBJECTBUFFERATIPROC glNewObjectBufferATI; | ||
95 | extern PFNGLISOBJECTBUFFERATIPROC glIsObjectBufferATI; | ||
96 | extern PFNGLUPDATEOBJECTBUFFERATIPROC glUpdateObjectBufferATI; | ||
97 | extern PFNGLGETOBJECTBUFFERFVATIPROC glGetObjectBufferfvATI; | ||
98 | extern PFNGLGETOBJECTBUFFERIVATIPROC glGetObjectBufferivATI; | ||
99 | extern PFNGLFREEOBJECTBUFFERATIPROC glFreeObjectBufferATI; | ||
100 | extern PFNGLARRAYOBJECTATIPROC glArrayObjectATI; | ||
101 | extern PFNGLVERTEXATTRIBARRAYOBJECTATIPROC glVertexAttribArrayObjectATI; | ||
102 | extern PFNGLGETARRAYOBJECTFVATIPROC glGetArrayObjectfvATI; | ||
103 | extern PFNGLGETARRAYOBJECTIVATIPROC glGetArrayObjectivATI; | ||
104 | extern PFNGLVARIANTARRAYOBJECTATIPROC glVariantObjectArrayATI; | ||
105 | extern PFNGLGETVARIANTARRAYOBJECTFVATIPROC glGetVariantArrayObjectfvATI; | ||
106 | extern PFNGLGETVARIANTARRAYOBJECTIVATIPROC glGetVariantArrayObjectivATI; | ||
107 | |||
108 | // GL_ARB_occlusion_query | ||
109 | extern PFNGLGENQUERIESARBPROC glGenQueriesARB; | ||
110 | extern PFNGLDELETEQUERIESARBPROC glDeleteQueriesARB; | ||
111 | extern PFNGLISQUERYARBPROC glIsQueryARB; | ||
112 | extern PFNGLBEGINQUERYARBPROC glBeginQueryARB; | ||
113 | extern PFNGLENDQUERYARBPROC glEndQueryARB; | ||
114 | extern PFNGLGETQUERYIVARBPROC glGetQueryivARB; | ||
115 | extern PFNGLGETQUERYOBJECTIVARBPROC glGetQueryObjectivARB; | ||
116 | extern PFNGLGETQUERYOBJECTUIVARBPROC glGetQueryObjectuivARB; | ||
117 | |||
118 | // GL_ARB_point_parameters | ||
119 | extern PFNGLPOINTPARAMETERFARBPROC glPointParameterfARB; | ||
120 | extern PFNGLPOINTPARAMETERFVARBPROC glPointParameterfvARB; | ||
121 | |||
122 | // GL_ARB_shader_objects | ||
123 | extern PFNGLDELETEOBJECTARBPROC glDeleteObjectARB; | ||
124 | extern PFNGLGETHANDLEARBPROC glGetHandleARB; | ||
125 | extern PFNGLDETACHOBJECTARBPROC glDetachObjectARB; | ||
126 | extern PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB; | ||
127 | extern PFNGLSHADERSOURCEARBPROC glShaderSourceARB; | ||
128 | extern PFNGLCOMPILESHADERARBPROC glCompileShaderARB; | ||
129 | extern PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB; | ||
130 | extern PFNGLATTACHOBJECTARBPROC glAttachObjectARB; | ||
131 | extern PFNGLLINKPROGRAMARBPROC glLinkProgramARB; | ||
132 | extern PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB; | ||
133 | extern PFNGLVALIDATEPROGRAMARBPROC glValidateProgramARB; | ||
134 | extern PFNGLUNIFORM1FARBPROC glUniform1fARB; | ||
135 | extern PFNGLUNIFORM2FARBPROC glUniform2fARB; | ||
136 | extern PFNGLUNIFORM3FARBPROC glUniform3fARB; | ||
137 | extern PFNGLUNIFORM4FARBPROC glUniform4fARB; | ||
138 | extern PFNGLUNIFORM1IARBPROC glUniform1iARB; | ||
139 | extern PFNGLUNIFORM2IARBPROC glUniform2iARB; | ||
140 | extern PFNGLUNIFORM3IARBPROC glUniform3iARB; | ||
141 | extern PFNGLUNIFORM4IARBPROC glUniform4iARB; | ||
142 | extern PFNGLUNIFORM1FVARBPROC glUniform1fvARB; | ||
143 | extern PFNGLUNIFORM2FVARBPROC glUniform2fvARB; | ||
144 | extern PFNGLUNIFORM3FVARBPROC glUniform3fvARB; | ||
145 | extern PFNGLUNIFORM4FVARBPROC glUniform4fvARB; | ||
146 | extern PFNGLUNIFORM1IVARBPROC glUniform1ivARB; | ||
147 | extern PFNGLUNIFORM2IVARBPROC glUniform2ivARB; | ||
148 | extern PFNGLUNIFORM3IVARBPROC glUniform3ivARB; | ||
149 | extern PFNGLUNIFORM4IVARBPROC glUniform4ivARB; | ||
150 | extern PFNGLUNIFORMMATRIX2FVARBPROC glUniformMatrix2fvARB; | ||
151 | extern PFNGLUNIFORMMATRIX3FVARBPROC glUniformMatrix3fvARB; | ||
152 | extern PFNGLUNIFORMMATRIX4FVARBPROC glUniformMatrix4fvARB; | ||
153 | extern PFNGLGETOBJECTPARAMETERFVARBPROC glGetObjectParameterfvARB; | ||
154 | extern PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB; | ||
155 | extern PFNGLGETINFOLOGARBPROC glGetInfoLogARB; | ||
156 | extern PFNGLGETATTACHEDOBJECTSARBPROC glGetAttachedObjectsARB; | ||
157 | extern PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB; | ||
158 | extern PFNGLGETACTIVEUNIFORMARBPROC glGetActiveUniformARB; | ||
159 | extern PFNGLGETUNIFORMFVARBPROC glGetUniformfvARB; | ||
160 | extern PFNGLGETUNIFORMIVARBPROC glGetUniformivARB; | ||
161 | extern PFNGLGETSHADERSOURCEARBPROC glGetShaderSourceARB; | ||
162 | |||
163 | // GL_ARB_vertex_shader | ||
164 | extern PFNGLVERTEXATTRIB1DARBPROC glVertexAttrib1dARB; | ||
165 | extern PFNGLVERTEXATTRIB1DVARBPROC glVertexAttrib1dvARB; | ||
166 | extern PFNGLVERTEXATTRIB1FARBPROC glVertexAttrib1fARB; | ||
167 | extern PFNGLVERTEXATTRIB1FVARBPROC glVertexAttrib1fvARB; | ||
168 | extern PFNGLVERTEXATTRIB1SARBPROC glVertexAttrib1sARB; | ||
169 | extern PFNGLVERTEXATTRIB1SVARBPROC glVertexAttrib1svARB; | ||
170 | extern PFNGLVERTEXATTRIB2DARBPROC glVertexAttrib2dARB; | ||
171 | extern PFNGLVERTEXATTRIB2DVARBPROC glVertexAttrib2dvARB; | ||
172 | extern PFNGLVERTEXATTRIB2FARBPROC glVertexAttrib2fARB; | ||
173 | extern PFNGLVERTEXATTRIB2FVARBPROC glVertexAttrib2fvARB; | ||
174 | extern PFNGLVERTEXATTRIB2SARBPROC glVertexAttrib2sARB; | ||
175 | extern PFNGLVERTEXATTRIB2SVARBPROC glVertexAttrib2svARB; | ||
176 | extern PFNGLVERTEXATTRIB3DARBPROC glVertexAttrib3dARB; | ||
177 | extern PFNGLVERTEXATTRIB3DVARBPROC glVertexAttrib3dvARB; | ||
178 | extern PFNGLVERTEXATTRIB3FARBPROC glVertexAttrib3fARB; | ||
179 | extern PFNGLVERTEXATTRIB3FVARBPROC glVertexAttrib3fvARB; | ||
180 | extern PFNGLVERTEXATTRIB3SARBPROC glVertexAttrib3sARB; | ||
181 | extern PFNGLVERTEXATTRIB3SVARBPROC glVertexAttrib3svARB; | ||
182 | extern PFNGLVERTEXATTRIB4NBVARBPROC glVertexAttrib4nbvARB; | ||
183 | extern PFNGLVERTEXATTRIB4NIVARBPROC glVertexAttrib4nivARB; | ||
184 | extern PFNGLVERTEXATTRIB4NSVARBPROC glVertexAttrib4nsvARB; | ||
185 | extern PFNGLVERTEXATTRIB4NUBARBPROC glVertexAttrib4nubARB; | ||
186 | extern PFNGLVERTEXATTRIB4NUBVARBPROC glVertexAttrib4nubvARB; | ||
187 | extern PFNGLVERTEXATTRIB4NUIVARBPROC glVertexAttrib4nuivARB; | ||
188 | extern PFNGLVERTEXATTRIB4NUSVARBPROC glVertexAttrib4nusvARB; | ||
189 | extern PFNGLVERTEXATTRIB4BVARBPROC glVertexAttrib4bvARB; | ||
190 | extern PFNGLVERTEXATTRIB4DARBPROC glVertexAttrib4dARB; | ||
191 | extern PFNGLVERTEXATTRIB4DVARBPROC glVertexAttrib4dvARB; | ||
192 | extern PFNGLVERTEXATTRIB4FARBPROC glVertexAttrib4fARB; | ||
193 | extern PFNGLVERTEXATTRIB4FVARBPROC glVertexAttrib4fvARB; | ||
194 | extern PFNGLVERTEXATTRIB4IVARBPROC glVertexAttrib4ivARB; | ||
195 | extern PFNGLVERTEXATTRIB4SARBPROC glVertexAttrib4sARB; | ||
196 | extern PFNGLVERTEXATTRIB4SVARBPROC glVertexAttrib4svARB; | ||
197 | extern PFNGLVERTEXATTRIB4UBVARBPROC glVertexAttrib4ubvARB; | ||
198 | extern PFNGLVERTEXATTRIB4UIVARBPROC glVertexAttrib4uivARB; | ||
199 | extern PFNGLVERTEXATTRIB4USVARBPROC glVertexAttrib4usvARB; | ||
200 | extern PFNGLVERTEXATTRIBPOINTERARBPROC glVertexAttribPointerARB; | ||
201 | extern PFNGLENABLEVERTEXATTRIBARRAYARBPROC glEnableVertexAttribArrayARB; | ||
202 | extern PFNGLDISABLEVERTEXATTRIBARRAYARBPROC glDisableVertexAttribArrayARB; | ||
203 | extern PFNGLPROGRAMSTRINGARBPROC glProgramStringARB; | ||
204 | extern PFNGLBINDPROGRAMARBPROC glBindProgramARB; | ||
205 | extern PFNGLDELETEPROGRAMSARBPROC glDeleteProgramsARB; | ||
206 | extern PFNGLGENPROGRAMSARBPROC glGenProgramsARB; | ||
207 | extern PFNGLPROGRAMENVPARAMETER4DARBPROC glProgramEnvParameter4dARB; | ||
208 | extern PFNGLPROGRAMENVPARAMETER4DVARBPROC glProgramEnvParameter4dvARB; | ||
209 | extern PFNGLPROGRAMENVPARAMETER4FARBPROC glProgramEnvParameter4fARB; | ||
210 | extern PFNGLPROGRAMENVPARAMETER4FVARBPROC glProgramEnvParameter4fvARB; | ||
211 | extern PFNGLPROGRAMLOCALPARAMETER4DARBPROC glProgramLocalParameter4dARB; | ||
212 | extern PFNGLPROGRAMLOCALPARAMETER4DVARBPROC glProgramLocalParameter4dvARB; | ||
213 | extern PFNGLPROGRAMLOCALPARAMETER4FARBPROC glProgramLocalParameter4fARB; | ||
214 | extern PFNGLPROGRAMLOCALPARAMETER4FVARBPROC glProgramLocalParameter4fvARB; | ||
215 | extern PFNGLGETPROGRAMENVPARAMETERDVARBPROC glGetProgramEnvParameterdvARB; | ||
216 | extern PFNGLGETPROGRAMENVPARAMETERFVARBPROC glGetProgramEnvParameterfvARB; | ||
217 | extern PFNGLGETPROGRAMLOCALPARAMETERDVARBPROC glGetProgramLocalParameterdvARB; | ||
218 | extern PFNGLGETPROGRAMLOCALPARAMETERFVARBPROC glGetProgramLocalParameterfvARB; | ||
219 | extern PFNGLGETPROGRAMIVARBPROC glGetProgramivARB; | ||
220 | extern PFNGLGETPROGRAMSTRINGARBPROC glGetProgramStringARB; | ||
221 | extern PFNGLGETVERTEXATTRIBDVARBPROC glGetVertexAttribdvARB; | ||
222 | extern PFNGLGETVERTEXATTRIBFVARBPROC glGetVertexAttribfvARB; | ||
223 | extern PFNGLGETVERTEXATTRIBIVARBPROC glGetVertexAttribivARB; | ||
224 | extern PFNGLGETVERTEXATTRIBPOINTERVARBPROC glGetVertexAttribPointervARB; | ||
225 | extern PFNGLISPROGRAMARBPROC glIsProgramARB; | ||
226 | extern PFNGLBINDATTRIBLOCATIONARBPROC glBindAttribLocationARB; | ||
227 | extern PFNGLGETACTIVEATTRIBARBPROC glGetActiveAttribARB; | ||
228 | extern PFNGLGETATTRIBLOCATIONARBPROC glGetAttribLocationARB; | ||
229 | |||
230 | extern PFNGLCOMPRESSEDTEXIMAGE2DARBPROC glCompressedTexImage2DARB; | ||
231 | extern PFNGLGETCOMPRESSEDTEXIMAGEARBPROC glGetCompressedTexImageARB; | ||
232 | |||
233 | extern PFNGLCOLORTABLEEXTPROC glColorTableEXT; | ||
234 | |||
235 | //GL_EXT_framebuffer_object | ||
236 | extern PFNGLISRENDERBUFFEREXTPROC glIsRenderbufferEXT; | ||
237 | extern PFNGLBINDRENDERBUFFEREXTPROC glBindRenderbufferEXT; | ||
238 | extern PFNGLDELETERENDERBUFFERSEXTPROC glDeleteRenderbuffersEXT; | ||
239 | extern PFNGLGENRENDERBUFFERSEXTPROC glGenRenderbuffersEXT; | ||
240 | extern PFNGLRENDERBUFFERSTORAGEEXTPROC glRenderbufferStorageEXT; | ||
241 | extern PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC glGetRenderbufferParameterivEXT; | ||
242 | extern PFNGLISFRAMEBUFFEREXTPROC glIsFramebufferEXT; | ||
243 | extern PFNGLBINDFRAMEBUFFEREXTPROC glBindFramebufferEXT; | ||
244 | extern PFNGLDELETEFRAMEBUFFERSEXTPROC glDeleteFramebuffersEXT; | ||
245 | extern PFNGLGENFRAMEBUFFERSEXTPROC glGenFramebuffersEXT; | ||
246 | extern PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC glCheckFramebufferStatusEXT; | ||
247 | extern PFNGLFRAMEBUFFERTEXTURE1DEXTPROC glFramebufferTexture1DEXT; | ||
248 | extern PFNGLFRAMEBUFFERTEXTURE2DEXTPROC glFramebufferTexture2DEXT; | ||
249 | extern PFNGLFRAMEBUFFERTEXTURE3DEXTPROC glFramebufferTexture3DEXT; | ||
250 | extern PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC glFramebufferRenderbufferEXT; | ||
251 | extern PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC glGetFramebufferAttachmentParameterivEXT; | ||
252 | extern PFNGLGENERATEMIPMAPEXTPROC glGenerateMipmapEXT; | ||
253 | |||
254 | |||
255 | #elif LL_WINDOWS | ||
256 | |||
257 | // windows gl headers depend on things like APIENTRY, so include windows. | ||
258 | #define WIN32_LEAN_AND_MEAN | ||
259 | #include <winsock2.h> | ||
260 | #include <windows.h> | ||
261 | |||
262 | //---------------------------------------------------------------------------- | ||
263 | #include <GL/gl.h> | ||
264 | #include <GL/glu.h> | ||
265 | |||
266 | // quotes so we get libraries/.../GL/ version | ||
267 | #include "GL/glext.h" | ||
268 | #include "GL/glh_extensions.h" | ||
269 | |||
270 | |||
271 | // GL_ARB_vertex_buffer_object | ||
272 | extern PFNGLBINDBUFFERARBPROC glBindBufferARB; | ||
273 | extern PFNGLDELETEBUFFERSARBPROC glDeleteBuffersARB; | ||
274 | extern PFNGLGENBUFFERSARBPROC glGenBuffersARB; | ||
275 | extern PFNGLISBUFFERARBPROC glIsBufferARB; | ||
276 | extern PFNGLBUFFERDATAARBPROC glBufferDataARB; | ||
277 | extern PFNGLBUFFERSUBDATAARBPROC glBufferSubDataARB; | ||
278 | extern PFNGLGETBUFFERSUBDATAARBPROC glGetBufferSubDataARB; | ||
279 | extern PFNGLMAPBUFFERARBPROC glMapBufferARB; | ||
280 | extern PFNGLUNMAPBUFFERARBPROC glUnmapBufferARB; | ||
281 | extern PFNGLGETBUFFERPARAMETERIVARBPROC glGetBufferParameterivARB; | ||
282 | extern PFNGLGETBUFFERPOINTERVARBPROC glGetBufferPointervARB; | ||
283 | |||
284 | // GL_ATI_vertex_array_object | ||
285 | extern PFNGLNEWOBJECTBUFFERATIPROC glNewObjectBufferATI; | ||
286 | extern PFNGLISOBJECTBUFFERATIPROC glIsObjectBufferATI; | ||
287 | extern PFNGLUPDATEOBJECTBUFFERATIPROC glUpdateObjectBufferATI; | ||
288 | extern PFNGLGETOBJECTBUFFERFVATIPROC glGetObjectBufferfvATI; | ||
289 | extern PFNGLGETOBJECTBUFFERIVATIPROC glGetObjectBufferivATI; | ||
290 | extern PFNGLFREEOBJECTBUFFERATIPROC glFreeObjectBufferATI; | ||
291 | extern PFNGLARRAYOBJECTATIPROC glArrayObjectATI; | ||
292 | extern PFNGLVERTEXATTRIBARRAYOBJECTATIPROC glVertexAttribArrayObjectATI; | ||
293 | extern PFNGLGETARRAYOBJECTFVATIPROC glGetArrayObjectfvATI; | ||
294 | extern PFNGLGETARRAYOBJECTIVATIPROC glGetArrayObjectivATI; | ||
295 | extern PFNGLVARIANTARRAYOBJECTATIPROC glVariantObjectArrayATI; | ||
296 | extern PFNGLGETVARIANTARRAYOBJECTFVATIPROC glGetVariantArrayObjectfvATI; | ||
297 | extern PFNGLGETVARIANTARRAYOBJECTIVATIPROC glGetVariantArrayObjectivATI; | ||
298 | |||
299 | extern PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT; | ||
300 | |||
301 | // GL_ARB_occlusion_query | ||
302 | extern PFNGLGENQUERIESARBPROC glGenQueriesARB; | ||
303 | extern PFNGLDELETEQUERIESARBPROC glDeleteQueriesARB; | ||
304 | extern PFNGLISQUERYARBPROC glIsQueryARB; | ||
305 | extern PFNGLBEGINQUERYARBPROC glBeginQueryARB; | ||
306 | extern PFNGLENDQUERYARBPROC glEndQueryARB; | ||
307 | extern PFNGLGETQUERYIVARBPROC glGetQueryivARB; | ||
308 | extern PFNGLGETQUERYOBJECTIVARBPROC glGetQueryObjectivARB; | ||
309 | extern PFNGLGETQUERYOBJECTUIVARBPROC glGetQueryObjectuivARB; | ||
310 | |||
311 | // GL_ARB_point_parameters | ||
312 | extern PFNGLPOINTPARAMETERFARBPROC glPointParameterfARB; | ||
313 | extern PFNGLPOINTPARAMETERFVARBPROC glPointParameterfvARB; | ||
314 | |||
315 | // GL_ARB_shader_objects | ||
316 | extern PFNGLDELETEOBJECTARBPROC glDeleteObjectARB; | ||
317 | extern PFNGLGETHANDLEARBPROC glGetHandleARB; | ||
318 | extern PFNGLDETACHOBJECTARBPROC glDetachObjectARB; | ||
319 | extern PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB; | ||
320 | extern PFNGLSHADERSOURCEARBPROC glShaderSourceARB; | ||
321 | extern PFNGLCOMPILESHADERARBPROC glCompileShaderARB; | ||
322 | extern PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB; | ||
323 | extern PFNGLATTACHOBJECTARBPROC glAttachObjectARB; | ||
324 | extern PFNGLLINKPROGRAMARBPROC glLinkProgramARB; | ||
325 | extern PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB; | ||
326 | extern PFNGLVALIDATEPROGRAMARBPROC glValidateProgramARB; | ||
327 | extern PFNGLUNIFORM1FARBPROC glUniform1fARB; | ||
328 | extern PFNGLUNIFORM2FARBPROC glUniform2fARB; | ||
329 | extern PFNGLUNIFORM3FARBPROC glUniform3fARB; | ||
330 | extern PFNGLUNIFORM4FARBPROC glUniform4fARB; | ||
331 | extern PFNGLUNIFORM1IARBPROC glUniform1iARB; | ||
332 | extern PFNGLUNIFORM2IARBPROC glUniform2iARB; | ||
333 | extern PFNGLUNIFORM3IARBPROC glUniform3iARB; | ||
334 | extern PFNGLUNIFORM4IARBPROC glUniform4iARB; | ||
335 | extern PFNGLUNIFORM1FVARBPROC glUniform1fvARB; | ||
336 | extern PFNGLUNIFORM2FVARBPROC glUniform2fvARB; | ||
337 | extern PFNGLUNIFORM3FVARBPROC glUniform3fvARB; | ||
338 | extern PFNGLUNIFORM4FVARBPROC glUniform4fvARB; | ||
339 | extern PFNGLUNIFORM1IVARBPROC glUniform1ivARB; | ||
340 | extern PFNGLUNIFORM2IVARBPROC glUniform2ivARB; | ||
341 | extern PFNGLUNIFORM3IVARBPROC glUniform3ivARB; | ||
342 | extern PFNGLUNIFORM4IVARBPROC glUniform4ivARB; | ||
343 | extern PFNGLUNIFORMMATRIX2FVARBPROC glUniformMatrix2fvARB; | ||
344 | extern PFNGLUNIFORMMATRIX3FVARBPROC glUniformMatrix3fvARB; | ||
345 | extern PFNGLUNIFORMMATRIX4FVARBPROC glUniformMatrix4fvARB; | ||
346 | extern PFNGLGETOBJECTPARAMETERFVARBPROC glGetObjectParameterfvARB; | ||
347 | extern PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB; | ||
348 | extern PFNGLGETINFOLOGARBPROC glGetInfoLogARB; | ||
349 | extern PFNGLGETATTACHEDOBJECTSARBPROC glGetAttachedObjectsARB; | ||
350 | extern PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB; | ||
351 | extern PFNGLGETACTIVEUNIFORMARBPROC glGetActiveUniformARB; | ||
352 | extern PFNGLGETUNIFORMFVARBPROC glGetUniformfvARB; | ||
353 | extern PFNGLGETUNIFORMIVARBPROC glGetUniformivARB; | ||
354 | extern PFNGLGETSHADERSOURCEARBPROC glGetShaderSourceARB; | ||
355 | |||
356 | // GL_ARB_vertex_shader | ||
357 | extern PFNGLVERTEXATTRIB1DARBPROC glVertexAttrib1dARB; | ||
358 | extern PFNGLVERTEXATTRIB1DVARBPROC glVertexAttrib1dvARB; | ||
359 | extern PFNGLVERTEXATTRIB1FARBPROC glVertexAttrib1fARB; | ||
360 | extern PFNGLVERTEXATTRIB1FVARBPROC glVertexAttrib1fvARB; | ||
361 | extern PFNGLVERTEXATTRIB1SARBPROC glVertexAttrib1sARB; | ||
362 | extern PFNGLVERTEXATTRIB1SVARBPROC glVertexAttrib1svARB; | ||
363 | extern PFNGLVERTEXATTRIB2DARBPROC glVertexAttrib2dARB; | ||
364 | extern PFNGLVERTEXATTRIB2DVARBPROC glVertexAttrib2dvARB; | ||
365 | extern PFNGLVERTEXATTRIB2FARBPROC glVertexAttrib2fARB; | ||
366 | extern PFNGLVERTEXATTRIB2FVARBPROC glVertexAttrib2fvARB; | ||
367 | extern PFNGLVERTEXATTRIB2SARBPROC glVertexAttrib2sARB; | ||
368 | extern PFNGLVERTEXATTRIB2SVARBPROC glVertexAttrib2svARB; | ||
369 | extern PFNGLVERTEXATTRIB3DARBPROC glVertexAttrib3dARB; | ||
370 | extern PFNGLVERTEXATTRIB3DVARBPROC glVertexAttrib3dvARB; | ||
371 | extern PFNGLVERTEXATTRIB3FARBPROC glVertexAttrib3fARB; | ||
372 | extern PFNGLVERTEXATTRIB3FVARBPROC glVertexAttrib3fvARB; | ||
373 | extern PFNGLVERTEXATTRIB3SARBPROC glVertexAttrib3sARB; | ||
374 | extern PFNGLVERTEXATTRIB3SVARBPROC glVertexAttrib3svARB; | ||
375 | extern PFNGLVERTEXATTRIB4NBVARBPROC glVertexAttrib4nbvARB; | ||
376 | extern PFNGLVERTEXATTRIB4NIVARBPROC glVertexAttrib4nivARB; | ||
377 | extern PFNGLVERTEXATTRIB4NSVARBPROC glVertexAttrib4nsvARB; | ||
378 | extern PFNGLVERTEXATTRIB4NUBARBPROC glVertexAttrib4nubARB; | ||
379 | extern PFNGLVERTEXATTRIB4NUBVARBPROC glVertexAttrib4nubvARB; | ||
380 | extern PFNGLVERTEXATTRIB4NUIVARBPROC glVertexAttrib4nuivARB; | ||
381 | extern PFNGLVERTEXATTRIB4NUSVARBPROC glVertexAttrib4nusvARB; | ||
382 | extern PFNGLVERTEXATTRIB4BVARBPROC glVertexAttrib4bvARB; | ||
383 | extern PFNGLVERTEXATTRIB4DARBPROC glVertexAttrib4dARB; | ||
384 | extern PFNGLVERTEXATTRIB4DVARBPROC glVertexAttrib4dvARB; | ||
385 | extern PFNGLVERTEXATTRIB4FARBPROC glVertexAttrib4fARB; | ||
386 | extern PFNGLVERTEXATTRIB4FVARBPROC glVertexAttrib4fvARB; | ||
387 | extern PFNGLVERTEXATTRIB4IVARBPROC glVertexAttrib4ivARB; | ||
388 | extern PFNGLVERTEXATTRIB4SARBPROC glVertexAttrib4sARB; | ||
389 | extern PFNGLVERTEXATTRIB4SVARBPROC glVertexAttrib4svARB; | ||
390 | extern PFNGLVERTEXATTRIB4UBVARBPROC glVertexAttrib4ubvARB; | ||
391 | extern PFNGLVERTEXATTRIB4UIVARBPROC glVertexAttrib4uivARB; | ||
392 | extern PFNGLVERTEXATTRIB4USVARBPROC glVertexAttrib4usvARB; | ||
393 | extern PFNGLVERTEXATTRIBPOINTERARBPROC glVertexAttribPointerARB; | ||
394 | extern PFNGLENABLEVERTEXATTRIBARRAYARBPROC glEnableVertexAttribArrayARB; | ||
395 | extern PFNGLDISABLEVERTEXATTRIBARRAYARBPROC glDisableVertexAttribArrayARB; | ||
396 | extern PFNGLPROGRAMSTRINGARBPROC glProgramStringARB; | ||
397 | extern PFNGLBINDPROGRAMARBPROC glBindProgramARB; | ||
398 | extern PFNGLDELETEPROGRAMSARBPROC glDeleteProgramsARB; | ||
399 | extern PFNGLGENPROGRAMSARBPROC glGenProgramsARB; | ||
400 | extern PFNGLPROGRAMENVPARAMETER4DARBPROC glProgramEnvParameter4dARB; | ||
401 | extern PFNGLPROGRAMENVPARAMETER4DVARBPROC glProgramEnvParameter4dvARB; | ||
402 | extern PFNGLPROGRAMENVPARAMETER4FARBPROC glProgramEnvParameter4fARB; | ||
403 | extern PFNGLPROGRAMENVPARAMETER4FVARBPROC glProgramEnvParameter4fvARB; | ||
404 | extern PFNGLPROGRAMLOCALPARAMETER4DARBPROC glProgramLocalParameter4dARB; | ||
405 | extern PFNGLPROGRAMLOCALPARAMETER4DVARBPROC glProgramLocalParameter4dvARB; | ||
406 | extern PFNGLPROGRAMLOCALPARAMETER4FARBPROC glProgramLocalParameter4fARB; | ||
407 | extern PFNGLPROGRAMLOCALPARAMETER4FVARBPROC glProgramLocalParameter4fvARB; | ||
408 | extern PFNGLGETPROGRAMENVPARAMETERDVARBPROC glGetProgramEnvParameterdvARB; | ||
409 | extern PFNGLGETPROGRAMENVPARAMETERFVARBPROC glGetProgramEnvParameterfvARB; | ||
410 | extern PFNGLGETPROGRAMLOCALPARAMETERDVARBPROC glGetProgramLocalParameterdvARB; | ||
411 | extern PFNGLGETPROGRAMLOCALPARAMETERFVARBPROC glGetProgramLocalParameterfvARB; | ||
412 | extern PFNGLGETPROGRAMIVARBPROC glGetProgramivARB; | ||
413 | extern PFNGLGETPROGRAMSTRINGARBPROC glGetProgramStringARB; | ||
414 | extern PFNGLGETVERTEXATTRIBDVARBPROC glGetVertexAttribdvARB; | ||
415 | extern PFNGLGETVERTEXATTRIBFVARBPROC glGetVertexAttribfvARB; | ||
416 | extern PFNGLGETVERTEXATTRIBIVARBPROC glGetVertexAttribivARB; | ||
417 | extern PFNGLGETVERTEXATTRIBPOINTERVARBPROC glGetVertexAttribPointervARB; | ||
418 | extern PFNGLISPROGRAMARBPROC glIsProgramARB; | ||
419 | extern PFNGLBINDATTRIBLOCATIONARBPROC glBindAttribLocationARB; | ||
420 | extern PFNGLGETACTIVEATTRIBARBPROC glGetActiveAttribARB; | ||
421 | extern PFNGLGETATTRIBLOCATIONARBPROC glGetAttribLocationARB; | ||
422 | |||
423 | //GL_EXT_framebuffer_object | ||
424 | extern PFNGLISRENDERBUFFEREXTPROC glIsRenderbufferEXT; | ||
425 | extern PFNGLBINDRENDERBUFFEREXTPROC glBindRenderbufferEXT; | ||
426 | extern PFNGLDELETERENDERBUFFERSEXTPROC glDeleteRenderbuffersEXT; | ||
427 | extern PFNGLGENRENDERBUFFERSEXTPROC glGenRenderbuffersEXT; | ||
428 | extern PFNGLRENDERBUFFERSTORAGEEXTPROC glRenderbufferStorageEXT; | ||
429 | extern PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC glGetRenderbufferParameterivEXT; | ||
430 | extern PFNGLISFRAMEBUFFEREXTPROC glIsFramebufferEXT; | ||
431 | extern PFNGLBINDFRAMEBUFFEREXTPROC glBindFramebufferEXT; | ||
432 | extern PFNGLDELETEFRAMEBUFFERSEXTPROC glDeleteFramebuffersEXT; | ||
433 | extern PFNGLGENFRAMEBUFFERSEXTPROC glGenFramebuffersEXT; | ||
434 | extern PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC glCheckFramebufferStatusEXT; | ||
435 | extern PFNGLFRAMEBUFFERTEXTURE1DEXTPROC glFramebufferTexture1DEXT; | ||
436 | extern PFNGLFRAMEBUFFERTEXTURE2DEXTPROC glFramebufferTexture2DEXT; | ||
437 | extern PFNGLFRAMEBUFFERTEXTURE3DEXTPROC glFramebufferTexture3DEXT; | ||
438 | extern PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC glFramebufferRenderbufferEXT; | ||
439 | extern PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC glGetFramebufferAttachmentParameterivEXT; | ||
440 | extern PFNGLGENERATEMIPMAPEXTPROC glGenerateMipmapEXT; | ||
441 | |||
442 | |||
443 | #elif LL_DARWIN | ||
444 | //---------------------------------------------------------------------------- | ||
445 | // LL_DARWIN | ||
446 | |||
447 | #include <OpenGL/gl.h> | ||
448 | #include <OpenGL/glu.h> | ||
449 | |||
450 | #define GL_EXT_separate_specular_color 1 | ||
451 | #include <OpenGL/glext.h> | ||
452 | |||
453 | #include "GL/glh_extensions.h" | ||
454 | |||
455 | // These symbols don't exist on 10.3.9, so they have to be declared weak. Redeclaring them here fixes the problem. | ||
456 | // Note that they also must not be called on 10.3.9. This should be taken care of by a runtime check for the existence of the GL extension. | ||
457 | #include <AvailabilityMacros.h> | ||
458 | |||
459 | // GL_EXT_framebuffer_object | ||
460 | extern GLboolean glIsRenderbufferEXT(GLuint renderbuffer) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; | ||
461 | extern void glBindRenderbufferEXT(GLenum target, GLuint renderbuffer) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; | ||
462 | extern void glDeleteRenderbuffersEXT(GLsizei n, const GLuint *renderbuffers) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; | ||
463 | extern void glGenRenderbuffersEXT(GLsizei n, GLuint *renderbuffers) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; | ||
464 | extern void glRenderbufferStorageEXT(GLenum target, GLenum internalformat, GLsizei width, GLsizei height) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; | ||
465 | extern void glGetRenderbufferParameterivEXT(GLenum target, GLenum pname, GLint *params) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; | ||
466 | extern GLboolean glIsFramebufferEXT(GLuint framebuffer) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; | ||
467 | extern void glBindFramebufferEXT(GLenum target, GLuint framebuffer) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; | ||
468 | extern void glDeleteFramebuffersEXT(GLsizei n, const GLuint *framebuffers) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; | ||
469 | extern void glGenFramebuffersEXT(GLsizei n, GLuint *framebuffers) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; | ||
470 | extern GLenum glCheckFramebufferStatusEXT(GLenum target) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; | ||
471 | extern void glFramebufferTexture1DEXT(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; | ||
472 | extern void glFramebufferTexture2DEXT(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; | ||
473 | extern void glFramebufferTexture3DEXT(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; | ||
474 | extern void glFramebufferRenderbufferEXT(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; | ||
475 | extern void glGetFramebufferAttachmentParameterivEXT(GLenum target, GLenum attachment, GLenum pname, GLint *params) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; | ||
476 | extern void glGenerateMipmapEXT(GLenum target) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; | ||
477 | |||
478 | |||
479 | #ifdef __cplusplus | ||
480 | extern "C" { | ||
481 | #endif | ||
482 | // | ||
483 | // Define vertex buffer object headers on Mac | ||
484 | // | ||
485 | #ifndef GL_ARB_vertex_buffer_object | ||
486 | #define GL_BUFFER_SIZE_ARB 0x8764 | ||
487 | #define GL_BUFFER_USAGE_ARB 0x8765 | ||
488 | #define GL_ARRAY_BUFFER_ARB 0x8892 | ||
489 | #define GL_ELEMENT_ARRAY_BUFFER_ARB 0x8893 | ||
490 | #define GL_ARRAY_BUFFER_BINDING_ARB 0x8894 | ||
491 | #define GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB 0x8895 | ||
492 | #define GL_VERTEX_ARRAY_BUFFER_BINDING_ARB 0x8896 | ||
493 | #define GL_NORMAL_ARRAY_BUFFER_BINDING_ARB 0x8897 | ||
494 | #define GL_COLOR_ARRAY_BUFFER_BINDING_ARB 0x8898 | ||
495 | #define GL_INDEX_ARRAY_BUFFER_BINDING_ARB 0x8899 | ||
496 | #define GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB 0x889A | ||
497 | #define GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB 0x889B | ||
498 | #define GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB 0x889C | ||
499 | #define GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB 0x889D | ||
500 | #define GL_WEIGHT_ARRAY_BUFFER_BINDING_ARB 0x889E | ||
501 | #define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB 0x889F | ||
502 | #define GL_READ_ONLY_ARB 0x88B8 | ||
503 | #define GL_WRITE_ONLY_ARB 0x88B9 | ||
504 | #define GL_READ_WRITE_ARB 0x88BA | ||
505 | #define GL_BUFFER_ACCESS_ARB 0x88BB | ||
506 | #define GL_BUFFER_MAPPED_ARB 0x88BC | ||
507 | #define GL_BUFFER_MAP_POINTER_ARB 0x88BD | ||
508 | #define GL_STREAM_DRAW_ARB 0x88E0 | ||
509 | #define GL_STREAM_READ_ARB 0x88E1 | ||
510 | #define GL_STREAM_COPY_ARB 0x88E2 | ||
511 | #define GL_STATIC_DRAW_ARB 0x88E4 | ||
512 | #define GL_STATIC_READ_ARB 0x88E5 | ||
513 | #define GL_STATIC_COPY_ARB 0x88E6 | ||
514 | #define GL_DYNAMIC_DRAW_ARB 0x88E8 | ||
515 | #define GL_DYNAMIC_READ_ARB 0x88E9 | ||
516 | #define GL_DYNAMIC_COPY_ARB 0x88EA | ||
517 | #endif | ||
518 | |||
519 | |||
520 | |||
521 | #ifndef GL_ARB_vertex_buffer_object | ||
522 | /* GL types for handling large vertex buffer objects */ | ||
523 | typedef intptr_t GLintptrARB; | ||
524 | typedef intptr_t GLsizeiptrARB; | ||
525 | #endif | ||
526 | |||
527 | |||
528 | #ifndef GL_ARB_vertex_buffer_object | ||
529 | #define GL_ARB_vertex_buffer_object 1 | ||
530 | #ifdef GL_GLEXT_FUNCTION_POINTERS | ||
531 | typedef void (* glBindBufferARBProcPtr) (GLenum target, GLuint buffer); | ||
532 | typedef void (* glDeleteBufferARBProcPtr) (GLsizei n, const GLuint *buffers); | ||
533 | typedef void (* glGenBuffersARBProcPtr) (GLsizei n, GLuint *buffers); | ||
534 | typedef GLboolean (* glIsBufferARBProcPtr) (GLuint buffer); | ||
535 | typedef void (* glBufferDataARBProcPtr) (GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage); | ||
536 | typedef void (* glBufferSubDataARBProcPtr) (GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid *data); | ||
537 | typedef void (* glGetBufferSubDataARBProcPtr) (GLenum target, GLintptrARB offset, GLsizeiptrARB size, GLvoid *data); | ||
538 | typedef GLvoid* (* glMapBufferARBProcPtr) (GLenum target, GLenum access); /* Flawfinder: ignore */ | ||
539 | typedef GLboolean (* glUnmapBufferARBProcPtr) (GLenum target); | ||
540 | typedef void (* glGetBufferParameterivARBProcPtr) (GLenum target, GLenum pname, GLint *params); | ||
541 | typedef void (* glGetBufferPointervARBProcPtr) (GLenum target, GLenum pname, GLvoid* *params); | ||
542 | #else | ||
543 | extern void glBindBufferARB (GLenum, GLuint); | ||
544 | extern void glDeleteBuffersARB (GLsizei, const GLuint *); | ||
545 | extern void glGenBuffersARB (GLsizei, GLuint *); | ||
546 | extern GLboolean glIsBufferARB (GLuint); | ||
547 | extern void glBufferDataARB (GLenum, GLsizeiptrARB, const GLvoid *, GLenum); | ||
548 | extern void glBufferSubDataARB (GLenum, GLintptrARB, GLsizeiptrARB, const GLvoid *); | ||
549 | extern void glGetBufferSubDataARB (GLenum, GLintptrARB, GLsizeiptrARB, GLvoid *); | ||
550 | extern GLvoid* glMapBufferARB (GLenum, GLenum); | ||
551 | extern GLboolean glUnmapBufferARB (GLenum); | ||
552 | extern void glGetBufferParameterivARB (GLenum, GLenum, GLint *); | ||
553 | extern void glGetBufferPointervARB (GLenum, GLenum, GLvoid* *); | ||
554 | #endif /* GL_GLEXT_FUNCTION_POINTERS */ | ||
555 | #endif | ||
556 | |||
557 | // May be needed for DARWIN... | ||
558 | // #ifndef GL_ARB_compressed_tex_image | ||
559 | // #define GL_ARB_compressed_tex_image 1 | ||
560 | // #ifdef GL_GLEXT_FUNCTION_POINTERS | ||
561 | // typedef void (* glCompressedTexImage1D) (GLenum, GLint, GLenum, GLsizei, GLint, GLsizei, const GLvoid*); | ||
562 | // typedef void (* glCompressedTexImage2D) (GLenum, GLint, GLenum, GLsizei, GLsizei, GLint, GLsizei, const GLvoid*); | ||
563 | // typedef void (* glCompressedTexImage3D) (GLenum, GLint, GLenum, GLsizei, GLsizei, GLsizei, GLint, GLsizei, const GLvoid*); | ||
564 | // typedef void (* glCompressedTexSubImage1D) (GLenum, GLint, GLint, GLsizei, GLenum, GLsizei, const GLvoid*); | ||
565 | // typedef void (* glCompressedTexSubImage2D) (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLsizei, const GLvoid*); | ||
566 | // typedef void (* glCompressedTexSubImage3D) (GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLsizei, const GLvoid*); | ||
567 | // typedef void (* glGetCompressedTexImage) (GLenum, GLint, GLvoid*); | ||
568 | // #else | ||
569 | // extern void glCompressedTexImage1D (GLenum, GLint, GLenum, GLsizei, GLint, GLsizei, const GLvoid*); | ||
570 | // extern void glCompressedTexImage2D (GLenum, GLint, GLenum, GLsizei, GLsizei, GLint, GLsizei, const GLvoid*); | ||
571 | // extern void glCompressedTexImage3D (GLenum, GLint, GLenum, GLsizei, GLsizei, GLsizei, GLint, GLsizei, const GLvoid*); | ||
572 | // extern void glCompressedTexSubImage1D (GLenum, GLint, GLint, GLsizei, GLenum, GLsizei, const GLvoid*); | ||
573 | // extern void glCompressedTexSubImage2D (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLsizei, const GLvoid*); | ||
574 | // extern void glCompressedTexSubImage3D (GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLsizei, const GLvoid*); | ||
575 | // extern void glGetCompressedTexImage (GLenum, GLint, GLvoid*); | ||
576 | // #endif /* GL_GLEXT_FUNCTION_POINTERS */ | ||
577 | // #endif | ||
578 | |||
579 | #ifdef __cplusplus | ||
580 | } | ||
581 | #endif | ||
582 | |||
583 | #include <AGL/gl.h> | ||
584 | |||
585 | #endif // LL_MESA / LL_WINDOWS / LL_DARWIN | ||
586 | |||
587 | |||
588 | #endif // LL_LLGLHEADERS_H | ||
diff --git a/linden/indra/llrender/llglimmediate.cpp b/linden/indra/llrender/llglimmediate.cpp index 17c2182..9b60e49 100644 --- a/linden/indra/llrender/llglimmediate.cpp +++ b/linden/indra/llrender/llglimmediate.cpp | |||
@@ -1 +1,265 @@ | |||
1 | <<<<<<< .working | ||
1 | #error This file has been renamed llrender.cpp | 2 | #error This file has been renamed llrender.cpp |
3 | ======= | ||
4 | /** | ||
5 | * @file llglimmediate.cpp | ||
6 | * @brief LLGLImmediate implementation | ||
7 | * | ||
8 | * $LicenseInfo:firstyear=2001&license=viewergpl$ | ||
9 | * | ||
10 | * Copyright (c) 2001-2008, Linden Research, Inc. | ||
11 | * | ||
12 | * Second Life Viewer Source Code | ||
13 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
14 | * to you under the terms of the GNU General Public License, version 2.0 | ||
15 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
16 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
17 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
18 | * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 | ||
19 | * | ||
20 | * There are special exceptions to the terms and conditions of the GPL as | ||
21 | * it is applied to this Source Code. View the full text of the exception | ||
22 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
23 | * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
24 | * | ||
25 | * By copying, modifying or distributing this software, you acknowledge | ||
26 | * that you have read and understood your obligations described above, | ||
27 | * and agree to abide by those obligations. | ||
28 | * | ||
29 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
30 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
31 | * COMPLETENESS OR PERFORMANCE. | ||
32 | * $/LicenseInfo$ | ||
33 | */ | ||
34 | |||
35 | #include "linden_common.h" | ||
36 | |||
37 | #include "llglimmediate.h" | ||
38 | #include "llvertexbuffer.h" | ||
39 | |||
40 | LLGLImmediate gGL; | ||
41 | |||
42 | const U32 immediate_mask = LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_COLOR | LLVertexBuffer::MAP_TEXCOORD; | ||
43 | |||
44 | LLGLImmediate::LLGLImmediate() | ||
45 | { | ||
46 | mCount = 0; | ||
47 | mMode = LLVertexBuffer::TRIANGLES; | ||
48 | mBuffer = new LLVertexBuffer(immediate_mask, 0); | ||
49 | mBuffer->allocateBuffer(4096, 0, TRUE); | ||
50 | mBuffer->getVertexStrider(mVerticesp); | ||
51 | mBuffer->getTexCoordStrider(mTexcoordsp); | ||
52 | mBuffer->getColorStrider(mColorsp); | ||
53 | } | ||
54 | |||
55 | void LLGLImmediate::translatef(const GLfloat& x, const GLfloat& y, const GLfloat& z) | ||
56 | { | ||
57 | flush(); | ||
58 | glTranslatef(x,y,z); | ||
59 | } | ||
60 | |||
61 | void LLGLImmediate::scalef(const GLfloat& x, const GLfloat& y, const GLfloat& z) | ||
62 | { | ||
63 | flush(); | ||
64 | glScalef(x,y,z); | ||
65 | } | ||
66 | |||
67 | void LLGLImmediate::pushMatrix() | ||
68 | { | ||
69 | flush(); | ||
70 | glPushMatrix(); | ||
71 | } | ||
72 | |||
73 | void LLGLImmediate::popMatrix() | ||
74 | { | ||
75 | flush(); | ||
76 | glPopMatrix(); | ||
77 | } | ||
78 | |||
79 | void LLGLImmediate::blendFunc(GLenum sfactor, GLenum dfactor) | ||
80 | { | ||
81 | flush(); | ||
82 | glBlendFunc(sfactor, dfactor); | ||
83 | } | ||
84 | |||
85 | void LLGLImmediate::begin(const GLuint& mode) | ||
86 | { | ||
87 | if (mode != mMode) | ||
88 | { | ||
89 | if (mMode == LLVertexBuffer::QUADS || | ||
90 | mMode == LLVertexBuffer::LINES || | ||
91 | mMode == LLVertexBuffer::TRIANGLES || | ||
92 | mMode == LLVertexBuffer::POINTS) | ||
93 | { | ||
94 | flush(); | ||
95 | } | ||
96 | else if (mCount != 0) | ||
97 | { | ||
98 | llerrs << "gGL.begin() called redundantly." << llendl; | ||
99 | } | ||
100 | |||
101 | mMode = mode; | ||
102 | } | ||
103 | } | ||
104 | |||
105 | void LLGLImmediate::end() | ||
106 | { | ||
107 | if (mCount == 0) | ||
108 | { | ||
109 | return; | ||
110 | //IMM_ERRS << "GL begin and end called with no vertices specified." << llendl; | ||
111 | } | ||
112 | |||
113 | if ((mMode != LLVertexBuffer::QUADS && | ||
114 | mMode != LLVertexBuffer::LINES && | ||
115 | mMode != LLVertexBuffer::TRIANGLES && | ||
116 | mMode != LLVertexBuffer::POINTS) || | ||
117 | mCount > 2048) | ||
118 | { | ||
119 | flush(); | ||
120 | } | ||
121 | } | ||
122 | |||
123 | void LLGLImmediate::flush() | ||
124 | { | ||
125 | if (mCount > 0) | ||
126 | { | ||
127 | #if 0 | ||
128 | if (!glIsEnabled(GL_VERTEX_ARRAY)) | ||
129 | { | ||
130 | llerrs << "foo 1" << llendl; | ||
131 | } | ||
132 | |||
133 | if (!glIsEnabled(GL_COLOR_ARRAY)) | ||
134 | { | ||
135 | llerrs << "foo 2" << llendl; | ||
136 | } | ||
137 | |||
138 | if (!glIsEnabled(GL_TEXTURE_COORD_ARRAY)) | ||
139 | { | ||
140 | llerrs << "foo 3" << llendl; | ||
141 | } | ||
142 | |||
143 | if (glIsEnabled(GL_NORMAL_ARRAY)) | ||
144 | { | ||
145 | llerrs << "foo 7" << llendl; | ||
146 | } | ||
147 | |||
148 | GLvoid* pointer; | ||
149 | |||
150 | glGetPointerv(GL_VERTEX_ARRAY_POINTER, &pointer); | ||
151 | if (pointer != &(mBuffer[0].v)) | ||
152 | { | ||
153 | llerrs << "foo 4" << llendl; | ||
154 | } | ||
155 | |||
156 | glGetPointerv(GL_COLOR_ARRAY_POINTER, &pointer); | ||
157 | if (pointer != &(mBuffer[0].c)) | ||
158 | { | ||
159 | llerrs << "foo 5" << llendl; | ||
160 | } | ||
161 | |||
162 | glGetPointerv(GL_TEXTURE_COORD_ARRAY_POINTER, &pointer); | ||
163 | if (pointer != &(mBuffer[0].uv)) | ||
164 | { | ||
165 | llerrs << "foo 6" << llendl; | ||
166 | } | ||
167 | #endif | ||
168 | |||
169 | mBuffer->setBuffer(immediate_mask); | ||
170 | mBuffer->drawArrays(mMode, 0, mCount); | ||
171 | |||
172 | mVerticesp[0] = mVerticesp[mCount]; | ||
173 | mTexcoordsp[0] = mTexcoordsp[mCount]; | ||
174 | mColorsp[0] = mColorsp[mCount]; | ||
175 | mCount = 0; | ||
176 | } | ||
177 | } | ||
178 | |||
179 | void LLGLImmediate::vertex3f(const GLfloat& x, const GLfloat& y, const GLfloat& z) | ||
180 | { | ||
181 | if (mCount >= 4096) | ||
182 | { | ||
183 | // llwarns << "GL immediate mode overflow. Some geometry not drawn." << llendl; | ||
184 | return; | ||
185 | } | ||
186 | |||
187 | mVerticesp[mCount] = LLVector3(x,y,z); | ||
188 | mCount++; | ||
189 | if (mCount < 4096) | ||
190 | { | ||
191 | mVerticesp[mCount] = mVerticesp[mCount-1]; | ||
192 | mColorsp[mCount] = mColorsp[mCount-1]; | ||
193 | mTexcoordsp[mCount] = mTexcoordsp[mCount-1]; | ||
194 | } | ||
195 | } | ||
196 | |||
197 | void LLGLImmediate::vertex2i(const GLint& x, const GLint& y) | ||
198 | { | ||
199 | vertex3f((GLfloat) x, (GLfloat) y, 0); | ||
200 | } | ||
201 | |||
202 | void LLGLImmediate::vertex2f(const GLfloat& x, const GLfloat& y) | ||
203 | { | ||
204 | vertex3f(x,y,0); | ||
205 | } | ||
206 | |||
207 | void LLGLImmediate::vertex2fv(const GLfloat* v) | ||
208 | { | ||
209 | vertex3f(v[0], v[1], 0); | ||
210 | } | ||
211 | |||
212 | void LLGLImmediate::vertex3fv(const GLfloat* v) | ||
213 | { | ||
214 | vertex3f(v[0], v[1], v[2]); | ||
215 | } | ||
216 | |||
217 | void LLGLImmediate::texCoord2f(const GLfloat& x, const GLfloat& y) | ||
218 | { | ||
219 | mTexcoordsp[mCount] = LLVector2(x,y); | ||
220 | } | ||
221 | |||
222 | void LLGLImmediate::texCoord2i(const GLint& x, const GLint& y) | ||
223 | { | ||
224 | texCoord2f((GLfloat) x, (GLfloat) y); | ||
225 | } | ||
226 | |||
227 | void LLGLImmediate::texCoord2fv(const GLfloat* tc) | ||
228 | { | ||
229 | texCoord2f(tc[0], tc[1]); | ||
230 | } | ||
231 | |||
232 | void LLGLImmediate::color4ub(const GLubyte& r, const GLubyte& g, const GLubyte& b, const GLubyte& a) | ||
233 | { | ||
234 | mColorsp[mCount] = LLColor4U(r,g,b,a); | ||
235 | } | ||
236 | |||
237 | void LLGLImmediate::color4ubv(const GLubyte* c) | ||
238 | { | ||
239 | color4ub(c[0], c[1], c[2], c[3]); | ||
240 | } | ||
241 | |||
242 | void LLGLImmediate::color4f(const GLfloat& r, const GLfloat& g, const GLfloat& b, const GLfloat& a) | ||
243 | { | ||
244 | color4ub((GLubyte) (llclamp(r, 0.f, 1.f)*255), | ||
245 | (GLubyte) (llclamp(g, 0.f, 1.f)*255), | ||
246 | (GLubyte) (llclamp(b, 0.f, 1.f)*255), | ||
247 | (GLubyte) (llclamp(a, 0.f, 1.f)*255)); | ||
248 | } | ||
249 | |||
250 | void LLGLImmediate::color4fv(const GLfloat* c) | ||
251 | { | ||
252 | color4f(c[0],c[1],c[2],c[3]); | ||
253 | } | ||
254 | |||
255 | void LLGLImmediate::color3f(const GLfloat& r, const GLfloat& g, const GLfloat& b) | ||
256 | { | ||
257 | color4f(r,g,b,1); | ||
258 | } | ||
259 | |||
260 | void LLGLImmediate::color3fv(const GLfloat* c) | ||
261 | { | ||
262 | color4f(c[0],c[1],c[2],1); | ||
263 | } | ||
264 | |||
265 | >>>>>>> .merge-right.r88690 | ||
diff --git a/linden/indra/llrender/llglimmediate.h b/linden/indra/llrender/llglimmediate.h index 4a7a0eb..2d7d768 100644 --- a/linden/indra/llrender/llglimmediate.h +++ b/linden/indra/llrender/llglimmediate.h | |||
@@ -1 +1,98 @@ | |||
1 | <<<<<<< .working | ||
1 | #error This file has been renamed llrender.h | 2 | #error This file has been renamed llrender.h |
3 | ======= | ||
4 | /** | ||
5 | * @file llglimmediate.h | ||
6 | * @brief LLGLImmediate definition | ||
7 | * | ||
8 | * This class acts as a wrapper for OpenGL immediate calls concerning glBegin and glEnd. | ||
9 | * The goal of this class is to minimize the number of api calls due to legacy rendering | ||
10 | * code, and to define an interface for a multiple rendering API abstraction of the UI | ||
11 | * rendering. | ||
12 | * | ||
13 | * $LicenseInfo:firstyear=2001&license=viewergpl$ | ||
14 | * | ||
15 | * Copyright (c) 2001-2008, Linden Research, Inc. | ||
16 | * | ||
17 | * Second Life Viewer Source Code | ||
18 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
19 | * to you under the terms of the GNU General Public License, version 2.0 | ||
20 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
21 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
22 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
23 | * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 | ||
24 | * | ||
25 | * There are special exceptions to the terms and conditions of the GPL as | ||
26 | * it is applied to this Source Code. View the full text of the exception | ||
27 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
28 | * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
29 | * | ||
30 | * By copying, modifying or distributing this software, you acknowledge | ||
31 | * that you have read and understood your obligations described above, | ||
32 | * and agree to abide by those obligations. | ||
33 | * | ||
34 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
35 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
36 | * COMPLETENESS OR PERFORMANCE. | ||
37 | * $/LicenseInfo$ | ||
38 | */ | ||
39 | |||
40 | #ifndef LL_LLGLIMMEDIATE_H | ||
41 | #define LL_LLGLIMMEDIATE_H | ||
42 | |||
43 | #include "stdtypes.h" | ||
44 | #include "llgltypes.h" | ||
45 | #include "llglheaders.h" | ||
46 | #include "llvertexbuffer.h" | ||
47 | |||
48 | class LLGLImmediate | ||
49 | { | ||
50 | public: | ||
51 | LLGLImmediate(); | ||
52 | |||
53 | void translatef(const GLfloat& x, const GLfloat& y, const GLfloat& z); | ||
54 | void scalef(const GLfloat& x, const GLfloat& y, const GLfloat& z); | ||
55 | void pushMatrix(); | ||
56 | void popMatrix(); | ||
57 | void blendFunc(GLenum sfactor, GLenum dfactor); | ||
58 | void flush(); | ||
59 | |||
60 | void begin(const GLuint& mode); | ||
61 | void end(); | ||
62 | void vertex2i(const GLint& x, const GLint& y); | ||
63 | void vertex2f(const GLfloat& x, const GLfloat& y); | ||
64 | void vertex3f(const GLfloat& x, const GLfloat& y, const GLfloat& z); | ||
65 | void vertex2fv(const GLfloat* v); | ||
66 | void vertex3fv(const GLfloat* v); | ||
67 | |||
68 | void texCoord2i(const GLint& x, const GLint& y); | ||
69 | void texCoord2f(const GLfloat& x, const GLfloat& y); | ||
70 | void texCoord2fv(const GLfloat* tc); | ||
71 | |||
72 | void color4ub(const GLubyte& r, const GLubyte& g, const GLubyte& b, const GLubyte& a); | ||
73 | void color4f(const GLfloat& r, const GLfloat& g, const GLfloat& b, const GLfloat& a); | ||
74 | void color4fv(const GLfloat* c); | ||
75 | void color3f(const GLfloat& r, const GLfloat& g, const GLfloat& b); | ||
76 | void color3fv(const GLfloat* c); | ||
77 | void color4ubv(const GLubyte* c); | ||
78 | |||
79 | typedef struct Vertex | ||
80 | { | ||
81 | GLfloat v[3]; | ||
82 | GLubyte c[4]; | ||
83 | GLfloat uv[2]; | ||
84 | }; | ||
85 | |||
86 | private: | ||
87 | U32 mCount; | ||
88 | U32 mMode; | ||
89 | LLPointer<LLVertexBuffer> mBuffer; | ||
90 | LLStrider<LLVector3> mVerticesp; | ||
91 | LLStrider<LLVector2> mTexcoordsp; | ||
92 | LLStrider<LLColor4U> mColorsp; | ||
93 | }; | ||
94 | |||
95 | extern LLGLImmediate gGL; | ||
96 | |||
97 | #endif | ||
98 | >>>>>>> .merge-right.r88690 | ||
diff --git a/linden/indra/llrender/llglslshader.cpp b/linden/indra/llrender/llglslshader.cpp new file mode 100644 index 0000000..26984e1 --- /dev/null +++ b/linden/indra/llrender/llglslshader.cpp | |||
@@ -0,0 +1,823 @@ | |||
1 | /** | ||
2 | * @file llglslshader.cpp | ||
3 | * @brief GLSL helper functions and state. | ||
4 | * | ||
5 | * $LicenseInfo:firstyear=2005&license=viewergpl$ | ||
6 | * | ||
7 | * Copyright (c) 2005-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 | #include "linden_common.h" | ||
33 | |||
34 | #include "llglslshader.h" | ||
35 | |||
36 | #include "llshadermgr.h" | ||
37 | #include "llfile.h" | ||
38 | #include "llrender.h" | ||
39 | |||
40 | #if LL_DARWIN | ||
41 | #include "OpenGL/OpenGL.h" | ||
42 | #endif | ||
43 | |||
44 | #ifdef LL_RELEASE_FOR_DOWNLOAD | ||
45 | #define UNIFORM_ERRS LL_WARNS_ONCE("Shader") | ||
46 | #else | ||
47 | #define UNIFORM_ERRS LL_ERRS("Shader") | ||
48 | #endif | ||
49 | |||
50 | // Lots of STL stuff in here, using namespace std to keep things more readable | ||
51 | using std::vector; | ||
52 | using std::pair; | ||
53 | using std::make_pair; | ||
54 | using std::string; | ||
55 | |||
56 | BOOL shouldChange(const LLVector4& v1, const LLVector4& v2) | ||
57 | { | ||
58 | return v1 != v2; | ||
59 | } | ||
60 | |||
61 | LLShaderFeatures::LLShaderFeatures() | ||
62 | : calculatesLighting(false), isShiny(false), isFullbright(false), hasWaterFog(false), | ||
63 | hasTransport(false), hasSkinning(false), hasAtmospherics(false), isSpecular(false), | ||
64 | hasGamma(false), hasLighting(false), calculatesAtmospherics(false) | ||
65 | { | ||
66 | } | ||
67 | |||
68 | //=============================== | ||
69 | // LLGLSL Shader implementation | ||
70 | //=============================== | ||
71 | LLGLSLShader::LLGLSLShader() | ||
72 | : mProgramObject(0), mShaderLevel(0), mShaderGroup(SG_DEFAULT) | ||
73 | { | ||
74 | } | ||
75 | |||
76 | void LLGLSLShader::unload() | ||
77 | { | ||
78 | stop_glerror(); | ||
79 | mAttribute.clear(); | ||
80 | mTexture.clear(); | ||
81 | mUniform.clear(); | ||
82 | mShaderFiles.clear(); | ||
83 | |||
84 | if (mProgramObject) | ||
85 | { | ||
86 | GLhandleARB obj[1024]; | ||
87 | GLsizei count; | ||
88 | |||
89 | glGetAttachedObjectsARB(mProgramObject, 1024, &count, obj); | ||
90 | for (GLsizei i = 0; i < count; i++) | ||
91 | { | ||
92 | glDeleteObjectARB(obj[i]); | ||
93 | } | ||
94 | |||
95 | glDeleteObjectARB(mProgramObject); | ||
96 | |||
97 | mProgramObject = 0; | ||
98 | } | ||
99 | |||
100 | //hack to make apple not complain | ||
101 | glGetError(); | ||
102 | |||
103 | stop_glerror(); | ||
104 | } | ||
105 | |||
106 | BOOL LLGLSLShader::createShader(vector<string> * attributes, | ||
107 | vector<string> * uniforms) | ||
108 | { | ||
109 | llassert_always(!mShaderFiles.empty()); | ||
110 | BOOL success = TRUE; | ||
111 | |||
112 | // Create program | ||
113 | mProgramObject = glCreateProgramObjectARB(); | ||
114 | |||
115 | // Attach existing objects | ||
116 | if (!LLShaderMgr::instance()->attachShaderFeatures(this)) | ||
117 | { | ||
118 | return FALSE; | ||
119 | } | ||
120 | |||
121 | vector< pair<string,GLenum> >::iterator fileIter = mShaderFiles.begin(); | ||
122 | for ( ; fileIter != mShaderFiles.end(); fileIter++ ) | ||
123 | { | ||
124 | GLhandleARB shaderhandle = LLShaderMgr::instance()->loadShaderFile((*fileIter).first, mShaderLevel, (*fileIter).second); | ||
125 | LL_DEBUGS("ShaderLoading") << "SHADER FILE: " << (*fileIter).first << " mShaderLevel=" << mShaderLevel << LL_ENDL; | ||
126 | if (mShaderLevel > 0) | ||
127 | { | ||
128 | attachObject(shaderhandle); | ||
129 | } | ||
130 | else | ||
131 | { | ||
132 | success = FALSE; | ||
133 | } | ||
134 | } | ||
135 | |||
136 | // Map attributes and uniforms | ||
137 | if (success) | ||
138 | { | ||
139 | success = mapAttributes(attributes); | ||
140 | } | ||
141 | if (success) | ||
142 | { | ||
143 | success = mapUniforms(uniforms); | ||
144 | } | ||
145 | if( !success ) | ||
146 | { | ||
147 | LL_WARNS("ShaderLoading") << "Failed to link shader: " << mName << LL_ENDL; | ||
148 | |||
149 | // Try again using a lower shader level; | ||
150 | if (mShaderLevel > 0) | ||
151 | { | ||
152 | LL_WARNS("ShaderLoading") << "Failed to link using shader level " << mShaderLevel << " trying again using shader level " << (mShaderLevel - 1) << LL_ENDL; | ||
153 | mShaderLevel--; | ||
154 | return createShader(attributes,uniforms); | ||
155 | } | ||
156 | } | ||
157 | return success; | ||
158 | } | ||
159 | |||
160 | BOOL LLGLSLShader::attachObject(std::string object) | ||
161 | { | ||
162 | if (LLShaderMgr::instance()->mShaderObjects.count(object) > 0) | ||
163 | { | ||
164 | stop_glerror(); | ||
165 | glAttachObjectARB(mProgramObject, LLShaderMgr::instance()->mShaderObjects[object]); | ||
166 | stop_glerror(); | ||
167 | return TRUE; | ||
168 | } | ||
169 | else | ||
170 | { | ||
171 | LL_WARNS("ShaderLoading") << "Attempting to attach shader object that hasn't been compiled: " << object << LL_ENDL; | ||
172 | return FALSE; | ||
173 | } | ||
174 | } | ||
175 | |||
176 | void LLGLSLShader::attachObject(GLhandleARB object) | ||
177 | { | ||
178 | if (object != 0) | ||
179 | { | ||
180 | stop_glerror(); | ||
181 | glAttachObjectARB(mProgramObject, object); | ||
182 | stop_glerror(); | ||
183 | } | ||
184 | else | ||
185 | { | ||
186 | LL_WARNS("ShaderLoading") << "Attempting to attach non existing shader object. " << LL_ENDL; | ||
187 | } | ||
188 | } | ||
189 | |||
190 | void LLGLSLShader::attachObjects(GLhandleARB* objects, S32 count) | ||
191 | { | ||
192 | for (S32 i = 0; i < count; i++) | ||
193 | { | ||
194 | attachObject(objects[i]); | ||
195 | } | ||
196 | } | ||
197 | |||
198 | BOOL LLGLSLShader::mapAttributes(const vector<string> * attributes) | ||
199 | { | ||
200 | //link the program | ||
201 | BOOL res = link(); | ||
202 | |||
203 | mAttribute.clear(); | ||
204 | U32 numAttributes = (attributes == NULL) ? 0 : attributes->size(); | ||
205 | mAttribute.resize(LLShaderMgr::instance()->mReservedAttribs.size() + numAttributes, -1); | ||
206 | |||
207 | if (res) | ||
208 | { //read back channel locations | ||
209 | |||
210 | //read back reserved channels first | ||
211 | for (U32 i = 0; i < (S32) LLShaderMgr::instance()->mReservedAttribs.size(); i++) | ||
212 | { | ||
213 | const char* name = LLShaderMgr::instance()->mReservedAttribs[i].c_str(); | ||
214 | S32 index = glGetAttribLocationARB(mProgramObject, (const GLcharARB *)name); | ||
215 | if (index != -1) | ||
216 | { | ||
217 | mAttribute[i] = index; | ||
218 | LL_DEBUGS("ShaderLoading") << "Attribute " << name << " assigned to channel " << index << LL_ENDL; | ||
219 | } | ||
220 | } | ||
221 | if (attributes != NULL) | ||
222 | { | ||
223 | for (U32 i = 0; i < numAttributes; i++) | ||
224 | { | ||
225 | const char* name = (*attributes)[i].c_str(); | ||
226 | S32 index = glGetAttribLocationARB(mProgramObject, name); | ||
227 | if (index != -1) | ||
228 | { | ||
229 | mAttribute[LLShaderMgr::instance()->mReservedAttribs.size() + i] = index; | ||
230 | LL_DEBUGS("ShaderLoading") << "Attribute " << name << " assigned to channel " << index << LL_ENDL; | ||
231 | } | ||
232 | } | ||
233 | } | ||
234 | |||
235 | return TRUE; | ||
236 | } | ||
237 | |||
238 | return FALSE; | ||
239 | } | ||
240 | |||
241 | void LLGLSLShader::mapUniform(GLint index, const vector<string> * uniforms) | ||
242 | { | ||
243 | if (index == -1) | ||
244 | { | ||
245 | return; | ||
246 | } | ||
247 | |||
248 | GLenum type; | ||
249 | GLsizei length; | ||
250 | GLint size; | ||
251 | char name[1024]; /* Flawfinder: ignore */ | ||
252 | name[0] = 0; | ||
253 | |||
254 | glGetActiveUniformARB(mProgramObject, index, 1024, &length, &size, &type, (GLcharARB *)name); | ||
255 | S32 location = glGetUniformLocationARB(mProgramObject, name); | ||
256 | if (location != -1) | ||
257 | { | ||
258 | mUniformMap[name] = location; | ||
259 | LL_DEBUGS("ShaderLoading") << "Uniform " << name << " is at location " << location << LL_ENDL; | ||
260 | |||
261 | //find the index of this uniform | ||
262 | for (S32 i = 0; i < (S32) LLShaderMgr::instance()->mReservedUniforms.size(); i++) | ||
263 | { | ||
264 | if ( (mUniform[i] == -1) | ||
265 | && (LLShaderMgr::instance()->mReservedUniforms[i].compare(0, length, name, LLShaderMgr::instance()->mReservedUniforms[i].length()) == 0)) | ||
266 | { | ||
267 | //found it | ||
268 | mUniform[i] = location; | ||
269 | mTexture[i] = mapUniformTextureChannel(location, type); | ||
270 | return; | ||
271 | } | ||
272 | } | ||
273 | |||
274 | if (uniforms != NULL) | ||
275 | { | ||
276 | for (U32 i = 0; i < uniforms->size(); i++) | ||
277 | { | ||
278 | if ( (mUniform[i+LLShaderMgr::instance()->mReservedUniforms.size()] == -1) | ||
279 | && ((*uniforms)[i].compare(0, length, name, (*uniforms)[i].length()) == 0)) | ||
280 | { | ||
281 | //found it | ||
282 | mUniform[i+LLShaderMgr::instance()->mReservedUniforms.size()] = location; | ||
283 | mTexture[i+LLShaderMgr::instance()->mReservedUniforms.size()] = mapUniformTextureChannel(location, type); | ||
284 | return; | ||
285 | } | ||
286 | } | ||
287 | } | ||
288 | } | ||
289 | } | ||
290 | |||
291 | GLint LLGLSLShader::mapUniformTextureChannel(GLint location, GLenum type) | ||
292 | { | ||
293 | if (type >= GL_SAMPLER_1D_ARB && type <= GL_SAMPLER_2D_RECT_SHADOW_ARB) | ||
294 | { //this here is a texture | ||
295 | glUniform1iARB(location, mActiveTextureChannels); | ||
296 | LL_DEBUGS("ShaderLoading") << "Assigned to texture channel " << mActiveTextureChannels << LL_ENDL; | ||
297 | return mActiveTextureChannels++; | ||
298 | } | ||
299 | return -1; | ||
300 | } | ||
301 | |||
302 | BOOL LLGLSLShader::mapUniforms(const vector<string> * uniforms) | ||
303 | { | ||
304 | BOOL res = TRUE; | ||
305 | |||
306 | mActiveTextureChannels = 0; | ||
307 | mUniform.clear(); | ||
308 | mUniformMap.clear(); | ||
309 | mTexture.clear(); | ||
310 | mValue.clear(); | ||
311 | //initialize arrays | ||
312 | U32 numUniforms = (uniforms == NULL) ? 0 : uniforms->size(); | ||
313 | mUniform.resize(numUniforms + LLShaderMgr::instance()->mReservedUniforms.size(), -1); | ||
314 | mTexture.resize(numUniforms + LLShaderMgr::instance()->mReservedUniforms.size(), -1); | ||
315 | |||
316 | bind(); | ||
317 | |||
318 | //get the number of active uniforms | ||
319 | GLint activeCount; | ||
320 | glGetObjectParameterivARB(mProgramObject, GL_OBJECT_ACTIVE_UNIFORMS_ARB, &activeCount); | ||
321 | |||
322 | for (S32 i = 0; i < activeCount; i++) | ||
323 | { | ||
324 | mapUniform(i, uniforms); | ||
325 | } | ||
326 | |||
327 | unbind(); | ||
328 | |||
329 | return res; | ||
330 | } | ||
331 | |||
332 | BOOL LLGLSLShader::link(BOOL suppress_errors) | ||
333 | { | ||
334 | return LLShaderMgr::instance()->linkProgramObject(mProgramObject, suppress_errors); | ||
335 | } | ||
336 | |||
337 | void LLGLSLShader::bind() | ||
338 | { | ||
339 | if (gGLManager.mHasShaderObjects) | ||
340 | { | ||
341 | glUseProgramObjectARB(mProgramObject); | ||
342 | |||
343 | if (mUniformsDirty) | ||
344 | { | ||
345 | LLShaderMgr::instance()->updateShaderUniforms(this); | ||
346 | mUniformsDirty = FALSE; | ||
347 | } | ||
348 | } | ||
349 | } | ||
350 | |||
351 | void LLGLSLShader::unbind() | ||
352 | { | ||
353 | if (gGLManager.mHasShaderObjects) | ||
354 | { | ||
355 | for (U32 i = 0; i < mAttribute.size(); ++i) | ||
356 | { | ||
357 | vertexAttrib4f(i, 0,0,0,1); | ||
358 | } | ||
359 | glUseProgramObjectARB(0); | ||
360 | } | ||
361 | } | ||
362 | |||
363 | void LLGLSLShader::bindNoShader(void) | ||
364 | { | ||
365 | glUseProgramObjectARB(0); | ||
366 | } | ||
367 | |||
368 | S32 LLGLSLShader::enableTexture(S32 uniform, S32 mode) | ||
369 | { | ||
370 | if (uniform < 0 || uniform >= (S32)mTexture.size()) | ||
371 | { | ||
372 | UNIFORM_ERRS << "Uniform out of range: " << uniform << LL_ENDL; | ||
373 | return -1; | ||
374 | } | ||
375 | S32 index = mTexture[uniform]; | ||
376 | if (index != -1) | ||
377 | { | ||
378 | gGL.getTexUnit(index)->activate(); | ||
379 | glEnable(mode); | ||
380 | } | ||
381 | return index; | ||
382 | } | ||
383 | |||
384 | S32 LLGLSLShader::disableTexture(S32 uniform, S32 mode) | ||
385 | { | ||
386 | if (uniform < 0 || uniform >= (S32)mTexture.size()) | ||
387 | { | ||
388 | UNIFORM_ERRS << "Uniform out of range: " << uniform << LL_ENDL; | ||
389 | return -1; | ||
390 | } | ||
391 | S32 index = mTexture[uniform]; | ||
392 | if (index != -1) | ||
393 | { | ||
394 | gGL.getTexUnit(index)->activate(); | ||
395 | glDisable(mode); | ||
396 | } | ||
397 | return index; | ||
398 | } | ||
399 | |||
400 | void LLGLSLShader::uniform1f(U32 index, GLfloat x) | ||
401 | { | ||
402 | if (mProgramObject > 0) | ||
403 | { | ||
404 | if (mUniform.size() <= index) | ||
405 | { | ||
406 | UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; | ||
407 | return; | ||
408 | } | ||
409 | |||
410 | if (mUniform[index] >= 0) | ||
411 | { | ||
412 | std::map<GLint, LLVector4>::iterator iter = mValue.find(mUniform[index]); | ||
413 | if (iter == mValue.end() || iter->second.mV[0] != x) | ||
414 | { | ||
415 | glUniform1fARB(mUniform[index], x); | ||
416 | mValue[mUniform[index]] = LLVector4(x,0.f,0.f,0.f); | ||
417 | } | ||
418 | } | ||
419 | } | ||
420 | } | ||
421 | |||
422 | void LLGLSLShader::uniform2f(U32 index, GLfloat x, GLfloat y) | ||
423 | { | ||
424 | if (mProgramObject > 0) | ||
425 | { | ||
426 | if (mUniform.size() <= index) | ||
427 | { | ||
428 | UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; | ||
429 | return; | ||
430 | } | ||
431 | |||
432 | if (mUniform[index] >= 0) | ||
433 | { | ||
434 | std::map<GLint, LLVector4>::iterator iter = mValue.find(mUniform[index]); | ||
435 | LLVector4 vec(x,y,0.f,0.f); | ||
436 | if (iter == mValue.end() || shouldChange(iter->second,vec)) | ||
437 | { | ||
438 | glUniform2fARB(mUniform[index], x, y); | ||
439 | mValue[mUniform[index]] = vec; | ||
440 | } | ||
441 | } | ||
442 | } | ||
443 | } | ||
444 | |||
445 | void LLGLSLShader::uniform3f(U32 index, GLfloat x, GLfloat y, GLfloat z) | ||
446 | { | ||
447 | if (mProgramObject > 0) | ||
448 | { | ||
449 | if (mUniform.size() <= index) | ||
450 | { | ||
451 | UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; | ||
452 | return; | ||
453 | } | ||
454 | |||
455 | if (mUniform[index] >= 0) | ||
456 | { | ||
457 | std::map<GLint, LLVector4>::iterator iter = mValue.find(mUniform[index]); | ||
458 | LLVector4 vec(x,y,z,0.f); | ||
459 | if (iter == mValue.end() || shouldChange(iter->second,vec)) | ||
460 | { | ||
461 | glUniform3fARB(mUniform[index], x, y, z); | ||
462 | mValue[mUniform[index]] = vec; | ||
463 | } | ||
464 | } | ||
465 | } | ||
466 | } | ||
467 | |||
468 | void LLGLSLShader::uniform4f(U32 index, GLfloat x, GLfloat y, GLfloat z, GLfloat w) | ||
469 | { | ||
470 | if (mProgramObject > 0) | ||
471 | { | ||
472 | if (mUniform.size() <= index) | ||
473 | { | ||
474 | UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; | ||
475 | return; | ||
476 | } | ||
477 | |||
478 | if (mUniform[index] >= 0) | ||
479 | { | ||
480 | std::map<GLint, LLVector4>::iterator iter = mValue.find(mUniform[index]); | ||
481 | LLVector4 vec(x,y,z,w); | ||
482 | if (iter == mValue.end() || shouldChange(iter->second,vec)) | ||
483 | { | ||
484 | glUniform4fARB(mUniform[index], x, y, z, w); | ||
485 | mValue[mUniform[index]] = vec; | ||
486 | } | ||
487 | } | ||
488 | } | ||
489 | } | ||
490 | |||
491 | void LLGLSLShader::uniform1fv(U32 index, U32 count, const GLfloat* v) | ||
492 | { | ||
493 | if (mProgramObject > 0) | ||
494 | { | ||
495 | if (mUniform.size() <= index) | ||
496 | { | ||
497 | UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; | ||
498 | return; | ||
499 | } | ||
500 | |||
501 | if (mUniform[index] >= 0) | ||
502 | { | ||
503 | std::map<GLint, LLVector4>::iterator iter = mValue.find(mUniform[index]); | ||
504 | LLVector4 vec(v[0],0.f,0.f,0.f); | ||
505 | if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1) | ||
506 | { | ||
507 | glUniform1fvARB(mUniform[index], count, v); | ||
508 | mValue[mUniform[index]] = vec; | ||
509 | } | ||
510 | } | ||
511 | } | ||
512 | } | ||
513 | |||
514 | void LLGLSLShader::uniform2fv(U32 index, U32 count, const GLfloat* v) | ||
515 | { | ||
516 | if (mProgramObject > 0) | ||
517 | { | ||
518 | if (mUniform.size() <= index) | ||
519 | { | ||
520 | UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; | ||
521 | return; | ||
522 | } | ||
523 | |||
524 | if (mUniform[index] >= 0) | ||
525 | { | ||
526 | std::map<GLint, LLVector4>::iterator iter = mValue.find(mUniform[index]); | ||
527 | LLVector4 vec(v[0],v[1],0.f,0.f); | ||
528 | if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1) | ||
529 | { | ||
530 | glUniform2fvARB(mUniform[index], count, v); | ||
531 | mValue[mUniform[index]] = vec; | ||
532 | } | ||
533 | } | ||
534 | } | ||
535 | } | ||
536 | |||
537 | void LLGLSLShader::uniform3fv(U32 index, U32 count, const GLfloat* v) | ||
538 | { | ||
539 | if (mProgramObject > 0) | ||
540 | { | ||
541 | if (mUniform.size() <= index) | ||
542 | { | ||
543 | UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; | ||
544 | return; | ||
545 | } | ||
546 | |||
547 | if (mUniform[index] >= 0) | ||
548 | { | ||
549 | std::map<GLint, LLVector4>::iterator iter = mValue.find(mUniform[index]); | ||
550 | LLVector4 vec(v[0],v[1],v[2],0.f); | ||
551 | if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1) | ||
552 | { | ||
553 | glUniform3fvARB(mUniform[index], count, v); | ||
554 | mValue[mUniform[index]] = vec; | ||
555 | } | ||
556 | } | ||
557 | } | ||
558 | } | ||
559 | |||
560 | void LLGLSLShader::uniform4fv(U32 index, U32 count, const GLfloat* v) | ||
561 | { | ||
562 | if (mProgramObject > 0) | ||
563 | { | ||
564 | if (mUniform.size() <= index) | ||
565 | { | ||
566 | UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; | ||
567 | return; | ||
568 | } | ||
569 | |||
570 | if (mUniform[index] >= 0) | ||
571 | { | ||
572 | std::map<GLint, LLVector4>::iterator iter = mValue.find(mUniform[index]); | ||
573 | LLVector4 vec(v[0],v[1],v[2],v[3]); | ||
574 | if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1) | ||
575 | { | ||
576 | glUniform4fvARB(mUniform[index], count, v); | ||
577 | mValue[mUniform[index]] = vec; | ||
578 | } | ||
579 | } | ||
580 | } | ||
581 | } | ||
582 | |||
583 | void LLGLSLShader::uniformMatrix2fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v) | ||
584 | { | ||
585 | if (mProgramObject > 0) | ||
586 | { | ||
587 | if (mUniform.size() <= index) | ||
588 | { | ||
589 | UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; | ||
590 | return; | ||
591 | } | ||
592 | |||
593 | if (mUniform[index] >= 0) | ||
594 | { | ||
595 | glUniformMatrix2fvARB(mUniform[index], count, transpose, v); | ||
596 | } | ||
597 | } | ||
598 | } | ||
599 | |||
600 | void LLGLSLShader::uniformMatrix3fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v) | ||
601 | { | ||
602 | if (mProgramObject > 0) | ||
603 | { | ||
604 | if (mUniform.size() <= index) | ||
605 | { | ||
606 | UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; | ||
607 | return; | ||
608 | } | ||
609 | |||
610 | if (mUniform[index] >= 0) | ||
611 | { | ||
612 | glUniformMatrix3fvARB(mUniform[index], count, transpose, v); | ||
613 | } | ||
614 | } | ||
615 | } | ||
616 | |||
617 | void LLGLSLShader::uniformMatrix4fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v) | ||
618 | { | ||
619 | if (mProgramObject > 0) | ||
620 | { | ||
621 | if (mUniform.size() <= index) | ||
622 | { | ||
623 | UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; | ||
624 | return; | ||
625 | } | ||
626 | |||
627 | if (mUniform[index] >= 0) | ||
628 | { | ||
629 | glUniformMatrix4fvARB(mUniform[index], count, transpose, v); | ||
630 | } | ||
631 | } | ||
632 | } | ||
633 | |||
634 | GLint LLGLSLShader::getUniformLocation(const string& uniform) | ||
635 | { | ||
636 | if (mProgramObject > 0) | ||
637 | { | ||
638 | std::map<string, GLint>::iterator iter = mUniformMap.find(uniform); | ||
639 | if (iter != mUniformMap.end()) | ||
640 | { | ||
641 | llassert(iter->second == glGetUniformLocationARB(mProgramObject, uniform.c_str())); | ||
642 | return iter->second; | ||
643 | } | ||
644 | } | ||
645 | |||
646 | return -1; | ||
647 | } | ||
648 | |||
649 | void LLGLSLShader::uniform1f(const string& uniform, GLfloat v) | ||
650 | { | ||
651 | GLint location = getUniformLocation(uniform); | ||
652 | |||
653 | if (location >= 0) | ||
654 | { | ||
655 | std::map<GLint, LLVector4>::iterator iter = mValue.find(location); | ||
656 | LLVector4 vec(v,0.f,0.f,0.f); | ||
657 | if (iter == mValue.end() || shouldChange(iter->second,vec)) | ||
658 | { | ||
659 | glUniform1fARB(location, v); | ||
660 | mValue[location] = vec; | ||
661 | } | ||
662 | } | ||
663 | } | ||
664 | |||
665 | void LLGLSLShader::uniform2f(const string& uniform, GLfloat x, GLfloat y) | ||
666 | { | ||
667 | GLint location = getUniformLocation(uniform); | ||
668 | |||
669 | if (location >= 0) | ||
670 | { | ||
671 | std::map<GLint, LLVector4>::iterator iter = mValue.find(location); | ||
672 | LLVector4 vec(x,y,0.f,0.f); | ||
673 | if (iter == mValue.end() || shouldChange(iter->second,vec)) | ||
674 | { | ||
675 | glUniform2fARB(location, x,y); | ||
676 | mValue[location] = vec; | ||
677 | } | ||
678 | } | ||
679 | |||
680 | } | ||
681 | |||
682 | void LLGLSLShader::uniform3f(const string& uniform, GLfloat x, GLfloat y, GLfloat z) | ||
683 | { | ||
684 | GLint location = getUniformLocation(uniform); | ||
685 | |||
686 | if (location >= 0) | ||
687 | { | ||
688 | std::map<GLint, LLVector4>::iterator iter = mValue.find(location); | ||
689 | LLVector4 vec(x,y,z,0.f); | ||
690 | if (iter == mValue.end() || shouldChange(iter->second,vec)) | ||
691 | { | ||
692 | glUniform3fARB(location, x,y,z); | ||
693 | mValue[location] = vec; | ||
694 | } | ||
695 | } | ||
696 | } | ||
697 | |||
698 | void LLGLSLShader::uniform4f(const string& uniform, GLfloat x, GLfloat y, GLfloat z, GLfloat w) | ||
699 | { | ||
700 | GLint location = getUniformLocation(uniform); | ||
701 | |||
702 | if (location >= 0) | ||
703 | { | ||
704 | std::map<GLint, LLVector4>::iterator iter = mValue.find(location); | ||
705 | LLVector4 vec(x,y,z,w); | ||
706 | if (iter == mValue.end() || shouldChange(iter->second,vec)) | ||
707 | { | ||
708 | glUniform4fARB(location, x,y,z,w); | ||
709 | mValue[location] = vec; | ||
710 | } | ||
711 | } | ||
712 | } | ||
713 | |||
714 | void LLGLSLShader::uniform1fv(const string& uniform, U32 count, const GLfloat* v) | ||
715 | { | ||
716 | GLint location = getUniformLocation(uniform); | ||
717 | |||
718 | if (location >= 0) | ||
719 | { | ||
720 | std::map<GLint, LLVector4>::iterator iter = mValue.find(location); | ||
721 | LLVector4 vec(v[0],0.f,0.f,0.f); | ||
722 | if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1) | ||
723 | { | ||
724 | glUniform1fvARB(location, count, v); | ||
725 | mValue[location] = vec; | ||
726 | } | ||
727 | } | ||
728 | } | ||
729 | |||
730 | void LLGLSLShader::uniform2fv(const string& uniform, U32 count, const GLfloat* v) | ||
731 | { | ||
732 | GLint location = getUniformLocation(uniform); | ||
733 | |||
734 | if (location >= 0) | ||
735 | { | ||
736 | std::map<GLint, LLVector4>::iterator iter = mValue.find(location); | ||
737 | LLVector4 vec(v[0],v[1],0.f,0.f); | ||
738 | if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1) | ||
739 | { | ||
740 | glUniform2fvARB(location, count, v); | ||
741 | mValue[location] = vec; | ||
742 | } | ||
743 | } | ||
744 | } | ||
745 | |||
746 | void LLGLSLShader::uniform3fv(const string& uniform, U32 count, const GLfloat* v) | ||
747 | { | ||
748 | GLint location = getUniformLocation(uniform); | ||
749 | |||
750 | if (location >= 0) | ||
751 | { | ||
752 | std::map<GLint, LLVector4>::iterator iter = mValue.find(location); | ||
753 | LLVector4 vec(v[0],v[1],v[2],0.f); | ||
754 | if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1) | ||
755 | { | ||
756 | glUniform3fvARB(location, count, v); | ||
757 | mValue[location] = vec; | ||
758 | } | ||
759 | } | ||
760 | } | ||
761 | |||
762 | void LLGLSLShader::uniform4fv(const string& uniform, U32 count, const GLfloat* v) | ||
763 | { | ||
764 | GLint location = getUniformLocation(uniform); | ||
765 | |||
766 | if (location >= 0) | ||
767 | { | ||
768 | LLVector4 vec(v); | ||
769 | std::map<GLint, LLVector4>::iterator iter = mValue.find(location); | ||
770 | if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1) | ||
771 | { | ||
772 | glUniform4fvARB(location, count, v); | ||
773 | mValue[location] = vec; | ||
774 | } | ||
775 | } | ||
776 | } | ||
777 | |||
778 | void LLGLSLShader::uniformMatrix2fv(const string& uniform, U32 count, GLboolean transpose, const GLfloat* v) | ||
779 | { | ||
780 | GLint location = getUniformLocation(uniform); | ||
781 | |||
782 | if (location >= 0) | ||
783 | { | ||
784 | glUniformMatrix2fvARB(location, count, transpose, v); | ||
785 | } | ||
786 | } | ||
787 | |||
788 | void LLGLSLShader::uniformMatrix3fv(const string& uniform, U32 count, GLboolean transpose, const GLfloat* v) | ||
789 | { | ||
790 | GLint location = getUniformLocation(uniform); | ||
791 | |||
792 | if (location >= 0) | ||
793 | { | ||
794 | glUniformMatrix3fvARB(location, count, transpose, v); | ||
795 | } | ||
796 | } | ||
797 | |||
798 | void LLGLSLShader::uniformMatrix4fv(const string& uniform, U32 count, GLboolean transpose, const GLfloat* v) | ||
799 | { | ||
800 | GLint location = getUniformLocation(uniform); | ||
801 | |||
802 | if (location >= 0) | ||
803 | { | ||
804 | glUniformMatrix4fvARB(location, count, transpose, v); | ||
805 | } | ||
806 | } | ||
807 | |||
808 | |||
809 | void LLGLSLShader::vertexAttrib4f(U32 index, GLfloat x, GLfloat y, GLfloat z, GLfloat w) | ||
810 | { | ||
811 | if (mAttribute[index] > 0) | ||
812 | { | ||
813 | glVertexAttrib4fARB(mAttribute[index], x, y, z, w); | ||
814 | } | ||
815 | } | ||
816 | |||
817 | void LLGLSLShader::vertexAttrib4fv(U32 index, GLfloat* v) | ||
818 | { | ||
819 | if (mAttribute[index] > 0) | ||
820 | { | ||
821 | glVertexAttrib4fvARB(mAttribute[index], v); | ||
822 | } | ||
823 | } | ||
diff --git a/linden/indra/llrender/llglslshader.h b/linden/indra/llrender/llglslshader.h new file mode 100644 index 0000000..0fa8e41 --- /dev/null +++ b/linden/indra/llrender/llglslshader.h | |||
@@ -0,0 +1,139 @@ | |||
1 | /** | ||
2 | * @file llglslshader.h | ||
3 | * @brief GLSL shader wrappers | ||
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_LLGLSLSHADER_H | ||
33 | #define LL_LLGLSLSHADER_H | ||
34 | |||
35 | #include "llgl.h" | ||
36 | |||
37 | class LLShaderFeatures | ||
38 | { | ||
39 | public: | ||
40 | bool calculatesLighting; | ||
41 | bool calculatesAtmospherics; | ||
42 | bool hasLighting; // implies no transport (it's possible to have neither though) | ||
43 | bool isShiny; | ||
44 | bool isFullbright; // implies no lighting | ||
45 | bool isSpecular; | ||
46 | bool hasWaterFog; // implies no gamma | ||
47 | bool hasTransport; // implies no lighting (it's possible to have neither though) | ||
48 | bool hasSkinning; | ||
49 | bool hasAtmospherics; | ||
50 | bool hasGamma; | ||
51 | |||
52 | // char numLights; | ||
53 | |||
54 | LLShaderFeatures(); | ||
55 | }; | ||
56 | |||
57 | class LLGLSLShader | ||
58 | { | ||
59 | public: | ||
60 | |||
61 | enum | ||
62 | { | ||
63 | SG_DEFAULT = 0, | ||
64 | SG_SKY, | ||
65 | SG_WATER | ||
66 | }; | ||
67 | |||
68 | LLGLSLShader(); | ||
69 | |||
70 | void unload(); | ||
71 | BOOL createShader(std::vector<std::string> * attributes, | ||
72 | std::vector<std::string> * uniforms); | ||
73 | BOOL attachObject(std::string object); | ||
74 | void attachObject(GLhandleARB object); | ||
75 | void attachObjects(GLhandleARB* objects = NULL, S32 count = 0); | ||
76 | BOOL mapAttributes(const std::vector<std::string> * attributes); | ||
77 | BOOL mapUniforms(const std::vector<std::string> * uniforms); | ||
78 | void mapUniform(GLint index, const std::vector<std::string> * uniforms); | ||
79 | void uniform1f(U32 index, GLfloat v); | ||
80 | void uniform2f(U32 index, GLfloat x, GLfloat y); | ||
81 | void uniform3f(U32 index, GLfloat x, GLfloat y, GLfloat z); | ||
82 | void uniform4f(U32 index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); | ||
83 | void uniform1fv(U32 index, U32 count, const GLfloat* v); | ||
84 | void uniform2fv(U32 index, U32 count, const GLfloat* v); | ||
85 | void uniform3fv(U32 index, U32 count, const GLfloat* v); | ||
86 | void uniform4fv(U32 index, U32 count, const GLfloat* v); | ||
87 | void uniform1f(const std::string& uniform, GLfloat v); | ||
88 | void uniform2f(const std::string& uniform, GLfloat x, GLfloat y); | ||
89 | void uniform3f(const std::string& uniform, GLfloat x, GLfloat y, GLfloat z); | ||
90 | void uniform4f(const std::string& uniform, GLfloat x, GLfloat y, GLfloat z, GLfloat w); | ||
91 | void uniform1fv(const std::string& uniform, U32 count, const GLfloat* v); | ||
92 | void uniform2fv(const std::string& uniform, U32 count, const GLfloat* v); | ||
93 | void uniform3fv(const std::string& uniform, U32 count, const GLfloat* v); | ||
94 | void uniform4fv(const std::string& uniform, U32 count, const GLfloat* v); | ||
95 | void uniformMatrix2fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v); | ||
96 | void uniformMatrix3fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v); | ||
97 | void uniformMatrix4fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v); | ||
98 | void uniformMatrix2fv(const std::string& uniform, U32 count, GLboolean transpose, const GLfloat *v); | ||
99 | void uniformMatrix3fv(const std::string& uniform, U32 count, GLboolean transpose, const GLfloat *v); | ||
100 | void uniformMatrix4fv(const std::string& uniform, U32 count, GLboolean transpose, const GLfloat *v); | ||
101 | |||
102 | void vertexAttrib4f(U32 index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); | ||
103 | void vertexAttrib4fv(U32 index, GLfloat* v); | ||
104 | |||
105 | GLint getUniformLocation(const std::string& uniform); | ||
106 | |||
107 | GLint mapUniformTextureChannel(GLint location, GLenum type); | ||
108 | |||
109 | |||
110 | //enable/disable texture channel for specified uniform | ||
111 | //if given texture uniform is active in the shader, | ||
112 | //the corresponding channel will be active upon return | ||
113 | //returns channel texture is enabled in from [0-MAX) | ||
114 | S32 enableTexture(S32 uniform, S32 mode = GL_TEXTURE_2D); | ||
115 | S32 disableTexture(S32 uniform, S32 mode = GL_TEXTURE_2D); | ||
116 | |||
117 | BOOL link(BOOL suppress_errors = FALSE); | ||
118 | void bind(); | ||
119 | void unbind(); | ||
120 | |||
121 | // Unbinds any previously bound shader by explicitly binding no shader. | ||
122 | static void bindNoShader(void); | ||
123 | |||
124 | GLhandleARB mProgramObject; | ||
125 | std::vector<GLint> mAttribute; //lookup table of attribute enum to attribute channel | ||
126 | std::vector<GLint> mUniform; //lookup table of uniform enum to uniform location | ||
127 | std::map<std::string, GLint> mUniformMap; //lookup map of uniform name to uniform location | ||
128 | std::map<GLint, LLVector4> mValue; //lookup map of uniform location to last known value | ||
129 | std::vector<GLint> mTexture; | ||
130 | S32 mActiveTextureChannels; | ||
131 | S32 mShaderLevel; | ||
132 | S32 mShaderGroup; | ||
133 | BOOL mUniformsDirty; | ||
134 | LLShaderFeatures mFeatures; | ||
135 | std::vector< std::pair< std::string, GLenum > > mShaderFiles; | ||
136 | std::string mName; | ||
137 | }; | ||
138 | |||
139 | #endif | ||
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 | |||
40 | class LLGLDepthTest | ||
41 | { | ||
42 | // Enabled by default | ||
43 | public: | ||
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; | ||
51 | private: | ||
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 | |||
59 | class LLGLSDefault | ||
60 | { | ||
61 | protected: | ||
62 | LLGLEnable mColorMaterial; | ||
63 | LLGLDisable mAlphaTest, mBlend, mCullFace, mDither, mFog, | ||
64 | mLineSmooth, mLineStipple, mNormalize, mPolygonSmooth, | ||
65 | mTextureGenQ, mTextureGenR, mTextureGenS, mTextureGenT, | ||
66 | mGLMultisample; | ||
67 | public: | ||
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 | |||
90 | class LLGLSNoTexture | ||
91 | { | ||
92 | public: | ||
93 | LLGLSNoTexture() | ||
94 | { LLImageGL::unbindTexture(0); } | ||
95 | }; | ||
96 | |||
97 | class LLGLSObjectSelect | ||
98 | { | ||
99 | protected: | ||
100 | LLGLDisable mBlend, mFog, mAlphaTest; | ||
101 | LLGLEnable mCullFace; | ||
102 | public: | ||
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 | |||
110 | class LLGLSObjectSelectAlpha | ||
111 | { | ||
112 | protected: | ||
113 | LLGLEnable mAlphaTest; | ||
114 | public: | ||
115 | LLGLSObjectSelectAlpha() | ||
116 | : mAlphaTest(GL_ALPHA_TEST) | ||
117 | {} | ||
118 | }; | ||
119 | |||
120 | //---------------------------------------------------------------------------- | ||
121 | |||
122 | class LLGLSUIDefault | ||
123 | { | ||
124 | protected: | ||
125 | LLGLEnable mBlend, mAlphaTest; | ||
126 | LLGLDisable mCullFace; | ||
127 | LLGLDepthTest mDepthTest; | ||
128 | public: | ||
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 | |||
136 | class LLGLSNoAlphaTest // : public LLGLSUIDefault | ||
137 | { | ||
138 | protected: | ||
139 | LLGLDisable mAlphaTest; | ||
140 | public: | ||
141 | LLGLSNoAlphaTest() | ||
142 | : mAlphaTest(GL_ALPHA_TEST) | ||
143 | {} | ||
144 | }; | ||
145 | |||
146 | class LLGLSNoTextureNoAlphaTest // : public LLGLSUIDefault | ||
147 | { | ||
148 | protected: | ||
149 | LLGLDisable mAlphaTest; | ||
150 | public: | ||
151 | LLGLSNoTextureNoAlphaTest() | ||
152 | : mAlphaTest(GL_ALPHA_TEST) | ||
153 | |||
154 | { LLImageGL::unbindTexture(0); } | ||
155 | }; | ||
156 | |||
157 | //---------------------------------------------------------------------------- | ||
158 | |||
159 | class LLGLSFog | ||
160 | { | ||
161 | protected: | ||
162 | LLGLEnable mFog; | ||
163 | public: | ||
164 | LLGLSFog() | ||
165 | : mFog(GL_FOG) | ||
166 | {} | ||
167 | }; | ||
168 | |||
169 | class LLGLSNoFog | ||
170 | { | ||
171 | protected: | ||
172 | LLGLDisable mFog; | ||
173 | public: | ||
174 | LLGLSNoFog() | ||
175 | : mFog(GL_FOG) | ||
176 | {} | ||
177 | }; | ||
178 | |||
179 | //---------------------------------------------------------------------------- | ||
180 | |||
181 | class LLGLSPipeline | ||
182 | { | ||
183 | protected: | ||
184 | LLGLEnable mCullFace; | ||
185 | LLGLDepthTest mDepthTest; | ||
186 | public: | ||
187 | LLGLSPipeline() | ||
188 | : mCullFace(GL_CULL_FACE), | ||
189 | mDepthTest(GL_TRUE, GL_TRUE, GL_LEQUAL) | ||
190 | { } | ||
191 | }; | ||
192 | |||
193 | class LLGLSPipelineAlpha // : public LLGLSPipeline | ||
194 | { | ||
195 | protected: | ||
196 | LLGLEnable mBlend, mAlphaTest; | ||
197 | public: | ||
198 | LLGLSPipelineAlpha() | ||
199 | : mBlend(GL_BLEND), | ||
200 | mAlphaTest(GL_ALPHA_TEST) | ||
201 | { } | ||
202 | }; | ||
203 | |||
204 | class LLGLSPipelineEmbossBump | ||
205 | { | ||
206 | protected: | ||
207 | LLGLDisable mFog; | ||
208 | public: | ||
209 | LLGLSPipelineEmbossBump() | ||
210 | : mFog(GL_FOG) | ||
211 | { } | ||
212 | }; | ||
213 | |||
214 | class LLGLSPipelineSelection | ||
215 | { | ||
216 | protected: | ||
217 | LLGLDisable mCullFace; | ||
218 | public: | ||
219 | LLGLSPipelineSelection() | ||
220 | : mCullFace(GL_CULL_FACE) | ||
221 | {} | ||
222 | }; | ||
223 | |||
224 | class LLGLSPipelineAvatar | ||
225 | { | ||
226 | protected: | ||
227 | LLGLEnable mNormalize; | ||
228 | public: | ||
229 | LLGLSPipelineAvatar() | ||
230 | : mNormalize(GL_NORMALIZE) | ||
231 | {} | ||
232 | }; | ||
233 | |||
234 | class LLGLSPipelineSkyBox | ||
235 | { | ||
236 | protected: | ||
237 | LLGLDisable mAlphaTest, mCullFace, mFog; | ||
238 | public: | ||
239 | LLGLSPipelineSkyBox() | ||
240 | : mAlphaTest(GL_ALPHA_TEST), mCullFace(GL_CULL_FACE), mFog(GL_FOG) | ||
241 | { } | ||
242 | }; | ||
243 | |||
244 | class LLGLSTracker | ||
245 | { | ||
246 | protected: | ||
247 | LLGLEnable mCullFace, mBlend, mAlphaTest; | ||
248 | public: | ||
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 | |||
259 | class LLGLSSpecular | ||
260 | { | ||
261 | public: | ||
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 | |||
282 | class LLGLSBlendFunc : public LLGLSPipeline { | ||
283 | protected: | ||
284 | GLint mSavedSrc, mSavedDst; | ||
285 | LLGLEnable mBlend; | ||
286 | |||
287 | public: | ||
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 | ||
diff --git a/linden/indra/llrender/llgltypes.h b/linden/indra/llrender/llgltypes.h new file mode 100644 index 0000000..d22d5fa --- /dev/null +++ b/linden/indra/llrender/llgltypes.h | |||
@@ -0,0 +1,44 @@ | |||
1 | /** | ||
2 | * @file llgltypes.h | ||
3 | * @brief LLGL definition | ||
4 | * | ||
5 | * $LicenseInfo:firstyear=2006&license=viewergpl$ | ||
6 | * | ||
7 | * Copyright (c) 2006-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 LLGLTYPES_H | ||
33 | #define LLGLTYPES_H | ||
34 | |||
35 | #define MAX_GL_TEXTURE_UNITS 16 | ||
36 | |||
37 | typedef U32 LLGLenum; | ||
38 | typedef U32 LLGLuint; | ||
39 | typedef S32 LLGLint; | ||
40 | typedef F32 LLGLfloat; | ||
41 | typedef F64 LLGLdouble; | ||
42 | typedef U8 LLGLboolean; | ||
43 | |||
44 | #endif | ||
diff --git a/linden/indra/llrender/llimagegl.cpp b/linden/indra/llrender/llimagegl.cpp index a402814..a871758 100644 --- a/linden/indra/llrender/llimagegl.cpp +++ b/linden/indra/llrender/llimagegl.cpp | |||
@@ -836,7 +836,7 @@ BOOL LLImageGL::createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S | |||
836 | llwarns << "Trying to create a texture while GL is disabled!" << llendl; | 836 | llwarns << "Trying to create a texture while GL is disabled!" << llendl; |
837 | return FALSE; | 837 | return FALSE; |
838 | } | 838 | } |
839 | llassert(gGLManager.mInited || gNoRender); | 839 | llassert(gGLManager.mInited); |
840 | stop_glerror(); | 840 | stop_glerror(); |
841 | 841 | ||
842 | if (discard_level < 0) | 842 | if (discard_level < 0) |
diff --git a/linden/indra/llrender/llpostprocess.cpp b/linden/indra/llrender/llpostprocess.cpp new file mode 100644 index 0000000..c884951 --- /dev/null +++ b/linden/indra/llrender/llpostprocess.cpp | |||
@@ -0,0 +1,574 @@ | |||
1 | /** | ||
2 | * @file llpostprocess.cpp | ||
3 | * @brief LLPostProcess class implementation | ||
4 | * | ||
5 | * $LicenseInfo:firstyear=2007&license=viewergpl$ | ||
6 | * | ||
7 | * Copyright (c) 2007-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 | #include "linden_common.h" | ||
33 | |||
34 | #include "llpostprocess.h" | ||
35 | #include "llglslshader.h" | ||
36 | #include "llsdserialize.h" | ||
37 | #include "llrender.h" | ||
38 | |||
39 | |||
40 | LLPostProcess * gPostProcess = NULL; | ||
41 | |||
42 | |||
43 | static const unsigned int NOISE_SIZE = 512; | ||
44 | |||
45 | /// CALCULATING LUMINANCE (Using NTSC lum weights) | ||
46 | /// http://en.wikipedia.org/wiki/Luma_%28video%29 | ||
47 | static const float LUMINANCE_R = 0.299f; | ||
48 | static const float LUMINANCE_G = 0.587f; | ||
49 | static const float LUMINANCE_B = 0.114f; | ||
50 | |||
51 | static const char * const XML_FILENAME = "postprocesseffects.xml"; | ||
52 | |||
53 | LLPostProcess::LLPostProcess(void) : | ||
54 | sceneRenderTexture(0), noiseTexture(0), | ||
55 | tempBloomTexture(0), | ||
56 | initialized(false), | ||
57 | mAllEffects(LLSD::emptyMap()), | ||
58 | screenW(1), screenH(1) | ||
59 | { | ||
60 | /* Do nothing. Needs to be updated to use our current shader system, and to work with the move into llrender. | ||
61 | std::string pathName(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "windlight", XML_FILENAME)); | ||
62 | LL_DEBUGS2("AppInit", "Shaders") << "Loading PostProcess Effects settings from " << pathName << LL_ENDL; | ||
63 | |||
64 | llifstream effectsXML(pathName); | ||
65 | |||
66 | if (effectsXML) | ||
67 | { | ||
68 | LLPointer<LLSDParser> parser = new LLSDXMLParser(); | ||
69 | |||
70 | parser->parse(effectsXML, mAllEffects, LLSDSerialize::SIZE_UNLIMITED); | ||
71 | } | ||
72 | |||
73 | if (!mAllEffects.has("default")) | ||
74 | { | ||
75 | LLSD & defaultEffect = (mAllEffects["default"] = LLSD::emptyMap()); | ||
76 | |||
77 | defaultEffect["enable_night_vision"] = LLSD::Boolean(false); | ||
78 | defaultEffect["enable_bloom"] = LLSD::Boolean(false); | ||
79 | defaultEffect["enable_color_filter"] = LLSD::Boolean(false); | ||
80 | |||
81 | /// NVG Defaults | ||
82 | defaultEffect["brightness_multiplier"] = 3.0; | ||
83 | defaultEffect["noise_size"] = 25.0; | ||
84 | defaultEffect["noise_strength"] = 0.4; | ||
85 | |||
86 | // TODO BTest potentially add this to tweaks? | ||
87 | noiseTextureScale = 1.0f; | ||
88 | |||
89 | /// Bloom Defaults | ||
90 | defaultEffect["extract_low"] = 0.95; | ||
91 | defaultEffect["extract_high"] = 1.0; | ||
92 | defaultEffect["bloom_width"] = 2.25; | ||
93 | defaultEffect["bloom_strength"] = 1.5; | ||
94 | |||
95 | /// Color Filter Defaults | ||
96 | defaultEffect["brightness"] = 1.0; | ||
97 | defaultEffect["contrast"] = 1.0; | ||
98 | defaultEffect["saturation"] = 1.0; | ||
99 | |||
100 | LLSD& contrastBase = (defaultEffect["contrast_base"] = LLSD::emptyArray()); | ||
101 | contrastBase.append(1.0); | ||
102 | contrastBase.append(1.0); | ||
103 | contrastBase.append(1.0); | ||
104 | contrastBase.append(0.5); | ||
105 | } | ||
106 | |||
107 | setSelectedEffect("default"); | ||
108 | */ | ||
109 | } | ||
110 | |||
111 | LLPostProcess::~LLPostProcess(void) | ||
112 | { | ||
113 | glDeleteTextures(1, &sceneRenderTexture); | ||
114 | glDeleteTextures(1, &noiseTexture); | ||
115 | glDeleteTextures(1, &tempBloomTexture); | ||
116 | } | ||
117 | |||
118 | // static | ||
119 | void LLPostProcess::initClass(void) | ||
120 | { | ||
121 | //this will cause system to crash at second time login | ||
122 | //if first time login fails due to network connection --- bao | ||
123 | //***llassert_always(gPostProcess == NULL); | ||
124 | //replaced by the following line: | ||
125 | if(gPostProcess) | ||
126 | return ; | ||
127 | |||
128 | |||
129 | gPostProcess = new LLPostProcess(); | ||
130 | } | ||
131 | |||
132 | // static | ||
133 | void LLPostProcess::cleanupClass() | ||
134 | { | ||
135 | delete gPostProcess; | ||
136 | gPostProcess = NULL; | ||
137 | } | ||
138 | |||
139 | void LLPostProcess::setSelectedEffect(std::string const & effectName) | ||
140 | { | ||
141 | mSelectedEffectName = effectName; | ||
142 | static_cast<LLSD &>(tweaks) = mAllEffects[effectName]; | ||
143 | } | ||
144 | |||
145 | void LLPostProcess::saveEffect(std::string const & effectName) | ||
146 | { | ||
147 | /* Do nothing. Needs to be updated to use our current shader system, and to work with the move into llrender. | ||
148 | mAllEffects[effectName] = tweaks; | ||
149 | |||
150 | std::string pathName(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "windlight", XML_FILENAME)); | ||
151 | //llinfos << "Saving PostProcess Effects settings to " << pathName << llendl; | ||
152 | |||
153 | llofstream effectsXML(pathName); | ||
154 | |||
155 | LLPointer<LLSDFormatter> formatter = new LLSDXMLFormatter(); | ||
156 | |||
157 | formatter->format(mAllEffects, effectsXML); | ||
158 | */ | ||
159 | } | ||
160 | |||
161 | void LLPostProcess::apply(unsigned int width, unsigned int height) | ||
162 | { | ||
163 | if (!initialized || width != screenW || height != screenH){ | ||
164 | initialize(width, height); | ||
165 | } | ||
166 | if (shadersEnabled()){ | ||
167 | doEffects(); | ||
168 | } | ||
169 | } | ||
170 | |||
171 | void LLPostProcess::initialize(unsigned int width, unsigned int height) | ||
172 | { | ||
173 | screenW = width; | ||
174 | screenH = height; | ||
175 | createTexture(sceneRenderTexture, screenW, screenH); | ||
176 | initialized = true; | ||
177 | |||
178 | checkError(); | ||
179 | createNightVisionShader(); | ||
180 | createBloomShader(); | ||
181 | createColorFilterShader(); | ||
182 | checkError(); | ||
183 | } | ||
184 | |||
185 | inline bool LLPostProcess::shadersEnabled(void) | ||
186 | { | ||
187 | return (tweaks.useColorFilter().asBoolean() || | ||
188 | tweaks.useNightVisionShader().asBoolean() || | ||
189 | tweaks.useBloomShader().asBoolean() ); | ||
190 | |||
191 | } | ||
192 | |||
193 | void LLPostProcess::applyShaders(void) | ||
194 | { | ||
195 | if (tweaks.useColorFilter()){ | ||
196 | applyColorFilterShader(); | ||
197 | checkError(); | ||
198 | } | ||
199 | if (tweaks.useNightVisionShader()){ | ||
200 | /// If any of the above shaders have been called update the frame buffer; | ||
201 | if (tweaks.useColorFilter()){ | ||
202 | copyFrameBuffer(sceneRenderTexture, screenW, screenH); | ||
203 | } | ||
204 | applyNightVisionShader(); | ||
205 | checkError(); | ||
206 | } | ||
207 | if (tweaks.useBloomShader()){ | ||
208 | /// If any of the above shaders have been called update the frame buffer; | ||
209 | if (tweaks.useColorFilter().asBoolean() || tweaks.useNightVisionShader().asBoolean()){ | ||
210 | copyFrameBuffer(sceneRenderTexture, screenW, screenH); | ||
211 | } | ||
212 | applyBloomShader(); | ||
213 | checkError(); | ||
214 | } | ||
215 | } | ||
216 | |||
217 | void LLPostProcess::applyColorFilterShader(void) | ||
218 | { | ||
219 | /* Do nothing. Needs to be updated to use our current shader system, and to work with the move into llrender. | ||
220 | gPostColorFilterProgram.bind(); | ||
221 | |||
222 | gGL.getTexUnit(0)->activate(); | ||
223 | glEnable(GL_TEXTURE_RECTANGLE_ARB); | ||
224 | |||
225 | glBindTexture(GL_TEXTURE_RECTANGLE_ARB, sceneRenderTexture); | ||
226 | |||
227 | getShaderUniforms(colorFilterUniforms, gPostColorFilterProgram.mProgramObject); | ||
228 | glUniform1iARB(colorFilterUniforms["RenderTexture"], 0); | ||
229 | glUniform1fARB(colorFilterUniforms["brightness"], tweaks.getBrightness()); | ||
230 | glUniform1fARB(colorFilterUniforms["contrast"], tweaks.getContrast()); | ||
231 | float baseI = (tweaks.getContrastBaseR() + tweaks.getContrastBaseG() + tweaks.getContrastBaseB()) / 3.0f; | ||
232 | baseI = tweaks.getContrastBaseIntensity() / ((baseI < 0.001f) ? 0.001f : baseI); | ||
233 | float baseR = tweaks.getContrastBaseR() * baseI; | ||
234 | float baseG = tweaks.getContrastBaseG() * baseI; | ||
235 | float baseB = tweaks.getContrastBaseB() * baseI; | ||
236 | glUniform3fARB(colorFilterUniforms["contrastBase"], baseR, baseG, baseB); | ||
237 | glUniform1fARB(colorFilterUniforms["saturation"], tweaks.getSaturation()); | ||
238 | glUniform3fARB(colorFilterUniforms["lumWeights"], LUMINANCE_R, LUMINANCE_G, LUMINANCE_B); | ||
239 | |||
240 | LLGLEnable blend(GL_BLEND); | ||
241 | gGL.setSceneBlendType(LLRender::BT_REPLACE); | ||
242 | LLGLDepthTest depth(GL_FALSE); | ||
243 | |||
244 | /// Draw a screen space quad | ||
245 | drawOrthoQuad(screenW, screenH, QUAD_NORMAL); | ||
246 | gPostColorFilterProgram.unbind(); | ||
247 | */ | ||
248 | } | ||
249 | |||
250 | void LLPostProcess::createColorFilterShader(void) | ||
251 | { | ||
252 | /// Define uniform names | ||
253 | colorFilterUniforms["RenderTexture"] = 0; | ||
254 | colorFilterUniforms["brightness"] = 0; | ||
255 | colorFilterUniforms["contrast"] = 0; | ||
256 | colorFilterUniforms["contrastBase"] = 0; | ||
257 | colorFilterUniforms["saturation"] = 0; | ||
258 | colorFilterUniforms["lumWeights"] = 0; | ||
259 | } | ||
260 | |||
261 | void LLPostProcess::applyNightVisionShader(void) | ||
262 | { | ||
263 | /* Do nothing. Needs to be updated to use our current shader system, and to work with the move into llrender. | ||
264 | gPostNightVisionProgram.bind(); | ||
265 | |||
266 | gGL.getTexUnit(0)->activate(); | ||
267 | glEnable(GL_TEXTURE_RECTANGLE_ARB); | ||
268 | |||
269 | getShaderUniforms(nightVisionUniforms, gPostNightVisionProgram.mProgramObject); | ||
270 | glBindTexture(GL_TEXTURE_RECTANGLE_ARB, sceneRenderTexture); | ||
271 | glUniform1iARB(nightVisionUniforms["RenderTexture"], 0); | ||
272 | |||
273 | gGL.getTexUnit(1)->activate(); | ||
274 | glEnable(GL_TEXTURE_2D); | ||
275 | |||
276 | glBindTexture(GL_TEXTURE_2D, noiseTexture); | ||
277 | glUniform1iARB(nightVisionUniforms["NoiseTexture"], 1); | ||
278 | |||
279 | |||
280 | glUniform1fARB(nightVisionUniforms["brightMult"], tweaks.getBrightMult()); | ||
281 | glUniform1fARB(nightVisionUniforms["noiseStrength"], tweaks.getNoiseStrength()); | ||
282 | noiseTextureScale = 0.01f + ((101.f - tweaks.getNoiseSize()) / 100.f); | ||
283 | noiseTextureScale *= (screenH / NOISE_SIZE); | ||
284 | |||
285 | |||
286 | glUniform3fARB(nightVisionUniforms["lumWeights"], LUMINANCE_R, LUMINANCE_G, LUMINANCE_B); | ||
287 | |||
288 | LLGLEnable blend(GL_BLEND); | ||
289 | gGL.setSceneBlendType(LLRender::BT_REPLACE); | ||
290 | LLGLDepthTest depth(GL_FALSE); | ||
291 | |||
292 | /// Draw a screen space quad | ||
293 | drawOrthoQuad(screenW, screenH, QUAD_NOISE); | ||
294 | gPostNightVisionProgram.unbind(); | ||
295 | gGL.getTexUnit(0)->activate(); | ||
296 | */ | ||
297 | } | ||
298 | |||
299 | void LLPostProcess::createNightVisionShader(void) | ||
300 | { | ||
301 | /// Define uniform names | ||
302 | nightVisionUniforms["RenderTexture"] = 0; | ||
303 | nightVisionUniforms["NoiseTexture"] = 0; | ||
304 | nightVisionUniforms["brightMult"] = 0; | ||
305 | nightVisionUniforms["noiseStrength"] = 0; | ||
306 | nightVisionUniforms["lumWeights"] = 0; | ||
307 | |||
308 | createNoiseTexture(noiseTexture); | ||
309 | } | ||
310 | |||
311 | void LLPostProcess::applyBloomShader(void) | ||
312 | { | ||
313 | |||
314 | } | ||
315 | |||
316 | void LLPostProcess::createBloomShader(void) | ||
317 | { | ||
318 | createTexture(tempBloomTexture, unsigned(screenW * 0.5), unsigned(screenH * 0.5)); | ||
319 | |||
320 | /// Create Bloom Extract Shader | ||
321 | bloomExtractUniforms["RenderTexture"] = 0; | ||
322 | bloomExtractUniforms["extractLow"] = 0; | ||
323 | bloomExtractUniforms["extractHigh"] = 0; | ||
324 | bloomExtractUniforms["lumWeights"] = 0; | ||
325 | |||
326 | /// Create Bloom Blur Shader | ||
327 | bloomBlurUniforms["RenderTexture"] = 0; | ||
328 | bloomBlurUniforms["bloomStrength"] = 0; | ||
329 | bloomBlurUniforms["texelSize"] = 0; | ||
330 | bloomBlurUniforms["blurDirection"] = 0; | ||
331 | bloomBlurUniforms["blurWidth"] = 0; | ||
332 | } | ||
333 | |||
334 | void LLPostProcess::getShaderUniforms(glslUniforms & uniforms, GLhandleARB & prog) | ||
335 | { | ||
336 | /// Find uniform locations and insert into map | ||
337 | std::map<const char *, GLuint>::iterator i; | ||
338 | for (i = uniforms.begin(); i != uniforms.end(); ++i){ | ||
339 | i->second = glGetUniformLocationARB(prog, i->first); | ||
340 | } | ||
341 | } | ||
342 | |||
343 | void LLPostProcess::doEffects(void) | ||
344 | { | ||
345 | /// Save GL State | ||
346 | glPushAttrib(GL_ALL_ATTRIB_BITS); | ||
347 | glPushClientAttrib(GL_ALL_ATTRIB_BITS); | ||
348 | |||
349 | /// Copy the screen buffer to the render texture | ||
350 | copyFrameBuffer(sceneRenderTexture, screenW, screenH); | ||
351 | |||
352 | /// Clear the frame buffer. | ||
353 | glClearColor(0.0f, 0.0f, 0.0f, 1.0f); | ||
354 | glClear(GL_COLOR_BUFFER_BIT); | ||
355 | |||
356 | /// Change to an orthogonal view | ||
357 | viewOrthogonal(screenW, screenH); | ||
358 | |||
359 | checkError(); | ||
360 | applyShaders(); | ||
361 | |||
362 | LLGLSLShader::bindNoShader(); | ||
363 | checkError(); | ||
364 | |||
365 | /// Change to a perspective view | ||
366 | viewPerspective(); | ||
367 | |||
368 | /// Reset GL State | ||
369 | glPopClientAttrib(); | ||
370 | glPopAttrib(); | ||
371 | checkError(); | ||
372 | } | ||
373 | |||
374 | void LLPostProcess::copyFrameBuffer(GLuint & texture, unsigned int width, unsigned int height) | ||
375 | { | ||
376 | glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture); | ||
377 | glCopyTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, 0, 0, width, height, 0); | ||
378 | } | ||
379 | |||
380 | void LLPostProcess::drawOrthoQuad(unsigned int width, unsigned int height, QuadType type) | ||
381 | { | ||
382 | #if 0 | ||
383 | float noiseX = 0.f; | ||
384 | float noiseY = 0.f; | ||
385 | float screenRatio = 1.0f; | ||
386 | |||
387 | if (type == QUAD_NOISE){ | ||
388 | noiseX = ((float) rand() / (float) RAND_MAX); | ||
389 | noiseY = ((float) rand() / (float) RAND_MAX); | ||
390 | screenRatio = (float) width / (float) height; | ||
391 | } | ||
392 | |||
393 | |||
394 | glBegin(GL_QUADS); | ||
395 | if (type != QUAD_BLOOM_EXTRACT){ | ||
396 | glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.f, (GLfloat) height); | ||
397 | } else { | ||
398 | glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.f, (GLfloat) height * 2.0f); | ||
399 | } | ||
400 | if (type == QUAD_NOISE){ | ||
401 | glMultiTexCoord2fARB(GL_TEXTURE1_ARB, | ||
402 | noiseX, | ||
403 | noiseTextureScale + noiseY); | ||
404 | } else if (type == QUAD_BLOOM_COMBINE){ | ||
405 | glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.f, (GLfloat) height * 0.5f); | ||
406 | } | ||
407 | glVertex2f(0.f, (GLfloat) screenH - height); | ||
408 | |||
409 | if (type != QUAD_BLOOM_EXTRACT){ | ||
410 | glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.f, 0.f); | ||
411 | } else { | ||
412 | glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.f, 0.f); | ||
413 | } | ||
414 | if (type == QUAD_NOISE){ | ||
415 | glMultiTexCoord2fARB(GL_TEXTURE1_ARB, | ||
416 | noiseX, | ||
417 | noiseY); | ||
418 | } else if (type == QUAD_BLOOM_COMBINE){ | ||
419 | glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.f, 0.f); | ||
420 | } | ||
421 | glVertex2f(0.f, (GLfloat) height + (screenH - height)); | ||
422 | |||
423 | |||
424 | if (type != QUAD_BLOOM_EXTRACT){ | ||
425 | glMultiTexCoord2fARB(GL_TEXTURE0_ARB, (GLfloat) width, 0.f); | ||
426 | } else { | ||
427 | glMultiTexCoord2fARB(GL_TEXTURE0_ARB, (GLfloat) width * 2.0f, 0.f); | ||
428 | } | ||
429 | if (type == QUAD_NOISE){ | ||
430 | glMultiTexCoord2fARB(GL_TEXTURE1_ARB, | ||
431 | screenRatio * noiseTextureScale + noiseX, | ||
432 | noiseY); | ||
433 | } else if (type == QUAD_BLOOM_COMBINE){ | ||
434 | glMultiTexCoord2fARB(GL_TEXTURE1_ARB, (GLfloat) width * 0.5f, 0.f); | ||
435 | } | ||
436 | glVertex2f((GLfloat) width, (GLfloat) height + (screenH - height)); | ||
437 | |||
438 | |||
439 | if (type != QUAD_BLOOM_EXTRACT){ | ||
440 | glMultiTexCoord2fARB(GL_TEXTURE0_ARB, (GLfloat) width, (GLfloat) height); | ||
441 | } else { | ||
442 | glMultiTexCoord2fARB(GL_TEXTURE0_ARB, (GLfloat) width * 2.0f, (GLfloat) height * 2.0f); | ||
443 | } | ||
444 | if (type == QUAD_NOISE){ | ||
445 | glMultiTexCoord2fARB(GL_TEXTURE1_ARB, | ||
446 | screenRatio * noiseTextureScale + noiseX, | ||
447 | noiseTextureScale + noiseY); | ||
448 | } else if (type == QUAD_BLOOM_COMBINE){ | ||
449 | glMultiTexCoord2fARB(GL_TEXTURE1_ARB, (GLfloat) width * 0.5f, (GLfloat) height * 0.5f); | ||
450 | } | ||
451 | glVertex2f((GLfloat) width, (GLfloat) screenH - height); | ||
452 | glEnd(); | ||
453 | #endif | ||
454 | } | ||
455 | |||
456 | void LLPostProcess::viewOrthogonal(unsigned int width, unsigned int height) | ||
457 | { | ||
458 | glMatrixMode(GL_PROJECTION); | ||
459 | glPushMatrix(); | ||
460 | glLoadIdentity(); | ||
461 | glOrtho( 0.f, (GLdouble) width , (GLdouble) height , 0.f, -1.f, 1.f ); | ||
462 | glMatrixMode(GL_MODELVIEW); | ||
463 | glPushMatrix(); | ||
464 | glLoadIdentity(); | ||
465 | } | ||
466 | |||
467 | void LLPostProcess::viewPerspective(void) | ||
468 | { | ||
469 | glMatrixMode( GL_PROJECTION ); | ||
470 | glPopMatrix(); | ||
471 | glMatrixMode( GL_MODELVIEW ); | ||
472 | glPopMatrix(); | ||
473 | } | ||
474 | |||
475 | void LLPostProcess::changeOrthogonal(unsigned int width, unsigned int height) | ||
476 | { | ||
477 | viewPerspective(); | ||
478 | viewOrthogonal(width, height); | ||
479 | } | ||
480 | |||
481 | void LLPostProcess::createTexture(GLuint & texture, unsigned int width, unsigned int height) | ||
482 | { | ||
483 | if (texture != 0){ | ||
484 | glDeleteTextures(1, &texture); | ||
485 | } | ||
486 | |||
487 | std::vector<GLubyte> data(width * height * 4, 0); | ||
488 | |||
489 | glGenTextures(1, &texture); | ||
490 | glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture); | ||
491 | glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, 4, width, height, 0, | ||
492 | GL_RGBA, GL_UNSIGNED_BYTE, &data[0]); | ||
493 | glTexParameteri(GL_TEXTURE_RECTANGLE_ARB,GL_TEXTURE_MIN_FILTER,GL_LINEAR); | ||
494 | glTexParameteri(GL_TEXTURE_RECTANGLE_ARB,GL_TEXTURE_MAG_FILTER,GL_LINEAR); | ||
495 | glTexParameteri(GL_TEXTURE_RECTANGLE_ARB,GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | ||
496 | glTexParameteri(GL_TEXTURE_RECTANGLE_ARB,GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | ||
497 | } | ||
498 | |||
499 | void LLPostProcess::createNoiseTexture(GLuint & texture) | ||
500 | { | ||
501 | if (texture != 0){ | ||
502 | glDeleteTextures(1, &texture); | ||
503 | } | ||
504 | glGenTextures(1, &texture); | ||
505 | |||
506 | std::vector<GLubyte> buffer(NOISE_SIZE * NOISE_SIZE); | ||
507 | for (unsigned int i = 0; i < NOISE_SIZE; i++){ | ||
508 | for (unsigned int k = 0; k < NOISE_SIZE; k++){ | ||
509 | buffer[(i * NOISE_SIZE) + k] = (GLubyte)((double) rand() / ((double) RAND_MAX + 1.f) * 255.f); | ||
510 | } | ||
511 | } | ||
512 | glBindTexture(GL_TEXTURE_2D, texture); | ||
513 | glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, NOISE_SIZE, NOISE_SIZE, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, &buffer[0]); | ||
514 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); | ||
515 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR); | ||
516 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); | ||
517 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); | ||
518 | } | ||
519 | |||
520 | bool LLPostProcess::checkError(void) | ||
521 | { | ||
522 | GLenum glErr; | ||
523 | bool retCode = false; | ||
524 | |||
525 | glErr = glGetError(); | ||
526 | while (glErr != GL_NO_ERROR) | ||
527 | { | ||
528 | // shaderErrorLog << (const char *) gluErrorString(glErr) << std::endl; | ||
529 | char const * err_str_raw = (const char *) gluErrorString(glErr); | ||
530 | |||
531 | if(err_str_raw == NULL) | ||
532 | { | ||
533 | std::ostringstream err_builder; | ||
534 | err_builder << "unknown error number " << glErr; | ||
535 | mShaderErrorString = err_builder.str(); | ||
536 | } | ||
537 | else | ||
538 | { | ||
539 | mShaderErrorString = err_str_raw; | ||
540 | } | ||
541 | |||
542 | retCode = true; | ||
543 | glErr = glGetError(); | ||
544 | } | ||
545 | return retCode; | ||
546 | } | ||
547 | |||
548 | void LLPostProcess::checkShaderError(GLhandleARB shader) | ||
549 | { | ||
550 | GLint infologLength = 0; | ||
551 | GLint charsWritten = 0; | ||
552 | GLchar *infoLog; | ||
553 | |||
554 | checkError(); // Check for OpenGL errors | ||
555 | |||
556 | glGetObjectParameterivARB(shader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &infologLength); | ||
557 | |||
558 | checkError(); // Check for OpenGL errors | ||
559 | |||
560 | if (infologLength > 0) | ||
561 | { | ||
562 | infoLog = (GLchar *)malloc(infologLength); | ||
563 | if (infoLog == NULL) | ||
564 | { | ||
565 | /// Could not allocate infolog buffer | ||
566 | return; | ||
567 | } | ||
568 | glGetInfoLogARB(shader, infologLength, &charsWritten, infoLog); | ||
569 | // shaderErrorLog << (char *) infoLog << std::endl; | ||
570 | mShaderErrorString = (char *) infoLog; | ||
571 | free(infoLog); | ||
572 | } | ||
573 | checkError(); // Check for OpenGL errors | ||
574 | } | ||
diff --git a/linden/indra/llrender/llpostprocess.h b/linden/indra/llrender/llpostprocess.h new file mode 100644 index 0000000..cd9f477 --- /dev/null +++ b/linden/indra/llrender/llpostprocess.h | |||
@@ -0,0 +1,268 @@ | |||
1 | /** | ||
2 | * @file llpostprocess.h | ||
3 | * @brief LLPostProcess class definition | ||
4 | * | ||
5 | * $LicenseInfo:firstyear=2007&license=viewergpl$ | ||
6 | * | ||
7 | * Copyright (c) 2007-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_POSTPROCESS_H | ||
33 | #define LL_POSTPROCESS_H | ||
34 | |||
35 | #include <map> | ||
36 | #include <fstream> | ||
37 | #include "llgl.h" | ||
38 | #include "llglheaders.h" | ||
39 | |||
40 | class LLPostProcess | ||
41 | { | ||
42 | public: | ||
43 | |||
44 | typedef enum _QuadType { | ||
45 | QUAD_NORMAL, | ||
46 | QUAD_NOISE, | ||
47 | QUAD_BLOOM_EXTRACT, | ||
48 | QUAD_BLOOM_COMBINE | ||
49 | } QuadType; | ||
50 | |||
51 | /// GLSL Shader Encapsulation Struct | ||
52 | typedef std::map<const char *, GLuint> glslUniforms; | ||
53 | |||
54 | struct PostProcessTweaks : public LLSD { | ||
55 | inline PostProcessTweaks() : LLSD(LLSD::emptyMap()) | ||
56 | { | ||
57 | } | ||
58 | |||
59 | inline LLSD & brightMult() { | ||
60 | return (*this)["brightness_multiplier"]; | ||
61 | } | ||
62 | |||
63 | inline LLSD & noiseStrength() { | ||
64 | return (*this)["noise_strength"]; | ||
65 | } | ||
66 | |||
67 | inline LLSD & noiseSize() { | ||
68 | return (*this)["noise_size"]; | ||
69 | } | ||
70 | |||
71 | inline LLSD & extractLow() { | ||
72 | return (*this)["extract_low"]; | ||
73 | } | ||
74 | |||
75 | inline LLSD & extractHigh() { | ||
76 | return (*this)["extract_high"]; | ||
77 | } | ||
78 | |||
79 | inline LLSD & bloomWidth() { | ||
80 | return (*this)["bloom_width"]; | ||
81 | } | ||
82 | |||
83 | inline LLSD & bloomStrength() { | ||
84 | return (*this)["bloom_strength"]; | ||
85 | } | ||
86 | |||
87 | inline LLSD & brightness() { | ||
88 | return (*this)["brightness"]; | ||
89 | } | ||
90 | |||
91 | inline LLSD & contrast() { | ||
92 | return (*this)["contrast"]; | ||
93 | } | ||
94 | |||
95 | inline LLSD & contrastBaseR() { | ||
96 | return (*this)["contrast_base"][0]; | ||
97 | } | ||
98 | |||
99 | inline LLSD & contrastBaseG() { | ||
100 | return (*this)["contrast_base"][1]; | ||
101 | } | ||
102 | |||
103 | inline LLSD & contrastBaseB() { | ||
104 | return (*this)["contrast_base"][2]; | ||
105 | } | ||
106 | |||
107 | inline LLSD & contrastBaseIntensity() { | ||
108 | return (*this)["contrast_base"][3]; | ||
109 | } | ||
110 | |||
111 | inline LLSD & saturation() { | ||
112 | return (*this)["saturation"]; | ||
113 | } | ||
114 | |||
115 | inline LLSD & useNightVisionShader() { | ||
116 | return (*this)["enable_night_vision"]; | ||
117 | } | ||
118 | |||
119 | inline LLSD & useBloomShader() { | ||
120 | return (*this)["enable_bloom"]; | ||
121 | } | ||
122 | |||
123 | inline LLSD & useColorFilter() { | ||
124 | return (*this)["enable_color_filter"]; | ||
125 | } | ||
126 | |||
127 | |||
128 | inline F32 getBrightMult() const { | ||
129 | return F32((*this)["brightness_multiplier"].asReal()); | ||
130 | } | ||
131 | |||
132 | inline F32 getNoiseStrength() const { | ||
133 | return F32((*this)["noise_strength"].asReal()); | ||
134 | } | ||
135 | |||
136 | inline F32 getNoiseSize() const { | ||
137 | return F32((*this)["noise_size"].asReal()); | ||
138 | } | ||
139 | |||
140 | inline F32 getExtractLow() const { | ||
141 | return F32((*this)["extract_low"].asReal()); | ||
142 | } | ||
143 | |||
144 | inline F32 getExtractHigh() const { | ||
145 | return F32((*this)["extract_high"].asReal()); | ||
146 | } | ||
147 | |||
148 | inline F32 getBloomWidth() const { | ||
149 | return F32((*this)["bloom_width"].asReal()); | ||
150 | } | ||
151 | |||
152 | inline F32 getBloomStrength() const { | ||
153 | return F32((*this)["bloom_strength"].asReal()); | ||
154 | } | ||
155 | |||
156 | inline F32 getBrightness() const { | ||
157 | return F32((*this)["brightness"].asReal()); | ||
158 | } | ||
159 | |||
160 | inline F32 getContrast() const { | ||
161 | return F32((*this)["contrast"].asReal()); | ||
162 | } | ||
163 | |||
164 | inline F32 getContrastBaseR() const { | ||
165 | return F32((*this)["contrast_base"][0].asReal()); | ||
166 | } | ||
167 | |||
168 | inline F32 getContrastBaseG() const { | ||
169 | return F32((*this)["contrast_base"][1].asReal()); | ||
170 | } | ||
171 | |||
172 | inline F32 getContrastBaseB() const { | ||
173 | return F32((*this)["contrast_base"][2].asReal()); | ||
174 | } | ||
175 | |||
176 | inline F32 getContrastBaseIntensity() const { | ||
177 | return F32((*this)["contrast_base"][3].asReal()); | ||
178 | } | ||
179 | |||
180 | inline F32 getSaturation() const { | ||
181 | return F32((*this)["saturation"].asReal()); | ||
182 | } | ||
183 | |||
184 | }; | ||
185 | |||
186 | GLuint sceneRenderTexture; | ||
187 | GLuint noiseTexture; | ||
188 | GLuint tempBloomTexture; | ||
189 | bool initialized; | ||
190 | PostProcessTweaks tweaks; | ||
191 | |||
192 | // the map of all availible effects | ||
193 | LLSD mAllEffects; | ||
194 | |||
195 | public: | ||
196 | LLPostProcess(void); | ||
197 | |||
198 | ~LLPostProcess(void); | ||
199 | |||
200 | void apply(unsigned int width, unsigned int height); | ||
201 | |||
202 | /// Perform global initialization for this class. | ||
203 | static void initClass(void); | ||
204 | |||
205 | // Cleanup of global data that's only inited once per class. | ||
206 | static void cleanupClass(); | ||
207 | |||
208 | void setSelectedEffect(std::string const & effectName); | ||
209 | |||
210 | inline std::string const & getSelectedEffect(void) const { | ||
211 | return mSelectedEffectName; | ||
212 | } | ||
213 | |||
214 | void saveEffect(std::string const & effectName); | ||
215 | |||
216 | private: | ||
217 | /// read in from file | ||
218 | std::string mShaderErrorString; | ||
219 | unsigned int screenW; | ||
220 | unsigned int screenH; | ||
221 | |||
222 | float noiseTextureScale; | ||
223 | |||
224 | /// Shader Uniforms | ||
225 | glslUniforms nightVisionUniforms; | ||
226 | glslUniforms bloomExtractUniforms; | ||
227 | glslUniforms bloomBlurUniforms; | ||
228 | glslUniforms colorFilterUniforms; | ||
229 | |||
230 | // the name of currently selected effect in mAllEffects | ||
231 | // invariant: tweaks == mAllEffects[mSelectedEffectName] | ||
232 | std::string mSelectedEffectName; | ||
233 | |||
234 | /// General functions | ||
235 | void initialize(unsigned int width, unsigned int height); | ||
236 | void doEffects(void); | ||
237 | void applyShaders(void); | ||
238 | bool shadersEnabled(void); | ||
239 | |||
240 | /// Night Vision Functions | ||
241 | void createNightVisionShader(void); | ||
242 | void applyNightVisionShader(void); | ||
243 | |||
244 | /// Bloom Functions | ||
245 | void createBloomShader(void); | ||
246 | void applyBloomShader(void); | ||
247 | |||
248 | /// Color Filter Functions | ||
249 | void createColorFilterShader(void); | ||
250 | void applyColorFilterShader(void); | ||
251 | |||
252 | /// OpenGL Helper Functions | ||
253 | void getShaderUniforms(glslUniforms & uniforms, GLhandleARB & prog); | ||
254 | void createTexture(GLuint & texture, unsigned int width, unsigned int height); | ||
255 | void copyFrameBuffer(GLuint & texture, unsigned int width, unsigned int height); | ||
256 | void createNoiseTexture(GLuint & texture); | ||
257 | bool checkError(void); | ||
258 | void checkShaderError(GLhandleARB shader); | ||
259 | void drawOrthoQuad(unsigned int width, unsigned int height, QuadType type); | ||
260 | void viewOrthogonal(unsigned int width, unsigned int height); | ||
261 | void changeOrthogonal(unsigned int width, unsigned int height); | ||
262 | void viewPerspective(void); | ||
263 | }; | ||
264 | |||
265 | extern LLPostProcess * gPostProcess; | ||
266 | |||
267 | |||
268 | #endif // LL_POSTPROCESS_H | ||
diff --git a/linden/indra/llrender/llrender.cpp b/linden/indra/llrender/llrender.cpp index e9c1227..13edf8a 100644 --- a/linden/indra/llrender/llrender.cpp +++ b/linden/indra/llrender/llrender.cpp | |||
@@ -36,6 +36,12 @@ | |||
36 | 36 | ||
37 | LLRender gGL; | 37 | LLRender gGL; |
38 | 38 | ||
39 | // Handy copies of last good GL matrices | ||
40 | F64 gGLModelView[16]; | ||
41 | F64 gGLLastModelView[16]; | ||
42 | F64 gGLProjection[16]; | ||
43 | S32 gGLViewport[4]; | ||
44 | |||
39 | static const U32 LL_NUM_TEXTURE_LAYERS = 8; | 45 | static const U32 LL_NUM_TEXTURE_LAYERS = 8; |
40 | 46 | ||
41 | static GLenum sGLCompareFunc[] = | 47 | static GLenum sGLCompareFunc[] = |
@@ -445,6 +451,12 @@ void LLRender::translatef(const GLfloat& x, const GLfloat& y, const GLfloat& z) | |||
445 | glTranslatef(x,y,z); | 451 | glTranslatef(x,y,z); |
446 | } | 452 | } |
447 | 453 | ||
454 | void LLRender::scalef(const GLfloat& x, const GLfloat& y, const GLfloat& z) | ||
455 | { | ||
456 | flush(); | ||
457 | glScalef(x,y,z); | ||
458 | } | ||
459 | |||
448 | void LLRender::pushMatrix() | 460 | void LLRender::pushMatrix() |
449 | { | 461 | { |
450 | flush(); | 462 | flush(); |
diff --git a/linden/indra/llrender/llrender.h b/linden/indra/llrender/llrender.h index 03280fe..edf46ff 100644 --- a/linden/indra/llrender/llrender.h +++ b/linden/indra/llrender/llrender.h | |||
@@ -178,6 +178,7 @@ public: | |||
178 | ~LLRender(); | 178 | ~LLRender(); |
179 | 179 | ||
180 | void translatef(const GLfloat& x, const GLfloat& y, const GLfloat& z); | 180 | void translatef(const GLfloat& x, const GLfloat& y, const GLfloat& z); |
181 | void scalef(const GLfloat& x, const GLfloat& y, const GLfloat& z); | ||
181 | void pushMatrix(); | 182 | void pushMatrix(); |
182 | void popMatrix(); | 183 | void popMatrix(); |
183 | 184 | ||
@@ -232,7 +233,10 @@ private: | |||
232 | std::vector<LLTexUnit*> mTexUnits; | 233 | std::vector<LLTexUnit*> mTexUnits; |
233 | }; | 234 | }; |
234 | 235 | ||
235 | 236 | extern F64 gGLModelView[16]; | |
237 | extern F64 gGLLastModelView[16]; | ||
238 | extern F64 gGLProjection[16]; | ||
239 | extern S32 gGLViewport[4]; | ||
236 | 240 | ||
237 | extern LLRender gGL; | 241 | extern LLRender gGL; |
238 | 242 | ||
diff --git a/linden/indra/llrender/llrender.vcproj b/linden/indra/llrender/llrender.vcproj deleted file mode 100644 index d9144cb..0000000 --- a/linden/indra/llrender/llrender.vcproj +++ /dev/null | |||
@@ -1,232 +0,0 @@ | |||
1 | <?xml version="1.0" encoding="Windows-1252"?> | ||
2 | <VisualStudioProject | ||
3 | ProjectType="Visual C++" | ||
4 | Version="7.10" | ||
5 | Name="llrender" | ||
6 | ProjectGUID="{2ADE3C14-94C4-40BF-B033-70F3C954EE90}" | ||
7 | Keyword="Win32Proj"> | ||
8 | <Platforms> | ||
9 | <Platform | ||
10 | Name="Win32"/> | ||
11 | </Platforms> | ||
12 | <Configurations> | ||
13 | <Configuration | ||
14 | Name="Debug|Win32" | ||
15 | OutputDirectory="../lib_$(ConfigurationName)/i686-win32" | ||
16 | IntermediateDirectory="Debug" | ||
17 | ConfigurationType="4" | ||
18 | CharacterSet="1"> | ||
19 | <Tool | ||
20 | Name="VCCLCompilerTool" | ||
21 | Optimization="0" | ||
22 | AdditionalIncludeDirectories="..\llcommon;..\llmath;..\llvfs;..\llmessage;..\llimage;..\llwindow;..\..\libraries\i686-win32\include;..\..\libraries\include\" | ||
23 | PreprocessorDefinitions="WIN32;_DEBUG;_LIB;LL_WINDOWS;LL_DEBUG" | ||
24 | MinimalRebuild="TRUE" | ||
25 | BasicRuntimeChecks="3" | ||
26 | RuntimeLibrary="1" | ||
27 | StructMemberAlignment="4" | ||
28 | ForceConformanceInForLoopScope="TRUE" | ||
29 | UsePrecompiledHeader="0" | ||
30 | WarningLevel="3" | ||
31 | WarnAsError="TRUE" | ||
32 | Detect64BitPortabilityProblems="FALSE" | ||
33 | DebugInformationFormat="4"/> | ||
34 | <Tool | ||
35 | Name="VCCustomBuildTool"/> | ||
36 | <Tool | ||
37 | Name="VCLibrarianTool" | ||
38 | OutputFile="$(OutDir)/llrender.lib"/> | ||
39 | <Tool | ||
40 | Name="VCMIDLTool"/> | ||
41 | <Tool | ||
42 | Name="VCPostBuildEventTool"/> | ||
43 | <Tool | ||
44 | Name="VCPreBuildEventTool"/> | ||
45 | <Tool | ||
46 | Name="VCPreLinkEventTool"/> | ||
47 | <Tool | ||
48 | Name="VCResourceCompilerTool"/> | ||
49 | <Tool | ||
50 | Name="VCWebServiceProxyGeneratorTool"/> | ||
51 | <Tool | ||
52 | Name="VCXMLDataGeneratorTool"/> | ||
53 | <Tool | ||
54 | Name="VCManagedWrapperGeneratorTool"/> | ||
55 | <Tool | ||
56 | Name="VCAuxiliaryManagedWrapperGeneratorTool"/> | ||
57 | </Configuration> | ||
58 | <Configuration | ||
59 | Name="Release|Win32" | ||
60 | OutputDirectory="../lib_$(ConfigurationName)/i686-win32" | ||
61 | IntermediateDirectory="Release" | ||
62 | ConfigurationType="4" | ||
63 | CharacterSet="1"> | ||
64 | <Tool | ||
65 | Name="VCCLCompilerTool" | ||
66 | AdditionalOptions="/Oy-" | ||
67 | GlobalOptimizations="TRUE" | ||
68 | InlineFunctionExpansion="2" | ||
69 | EnableIntrinsicFunctions="TRUE" | ||
70 | OptimizeForProcessor="3" | ||
71 | OptimizeForWindowsApplication="TRUE" | ||
72 | AdditionalIncludeDirectories="..\llcommon;..\llmath;..\llvfs;..\llmessage;..\llimage;..\llwindow;..\..\libraries\i686-win32\include;..\..\libraries\include\" | ||
73 | PreprocessorDefinitions="WIN32;NDEBUG;_LIB;LL_WINDOWS;LL_RELEASE" | ||
74 | RuntimeLibrary="0" | ||
75 | StructMemberAlignment="0" | ||
76 | ForceConformanceInForLoopScope="TRUE" | ||
77 | UsePrecompiledHeader="0" | ||
78 | WarningLevel="3" | ||
79 | WarnAsError="TRUE" | ||
80 | Detect64BitPortabilityProblems="FALSE" | ||
81 | DebugInformationFormat="3"/> | ||
82 | <Tool | ||
83 | Name="VCCustomBuildTool"/> | ||
84 | <Tool | ||
85 | Name="VCLibrarianTool" | ||
86 | OutputFile="$(OutDir)/llrender.lib"/> | ||
87 | <Tool | ||
88 | Name="VCMIDLTool"/> | ||
89 | <Tool | ||
90 | Name="VCPostBuildEventTool"/> | ||
91 | <Tool | ||
92 | Name="VCPreBuildEventTool"/> | ||
93 | <Tool | ||
94 | Name="VCPreLinkEventTool"/> | ||
95 | <Tool | ||
96 | Name="VCResourceCompilerTool"/> | ||
97 | <Tool | ||
98 | Name="VCWebServiceProxyGeneratorTool"/> | ||
99 | <Tool | ||
100 | Name="VCXMLDataGeneratorTool"/> | ||
101 | <Tool | ||
102 | Name="VCManagedWrapperGeneratorTool"/> | ||
103 | <Tool | ||
104 | Name="VCAuxiliaryManagedWrapperGeneratorTool"/> | ||
105 | </Configuration> | ||
106 | <Configuration | ||
107 | Name="ReleaseNoOpt|Win32" | ||
108 | OutputDirectory="../lib_$(ConfigurationName)/i686-win32" | ||
109 | IntermediateDirectory="$(ConfigurationName)" | ||
110 | ConfigurationType="4" | ||
111 | CharacterSet="1"> | ||
112 | <Tool | ||
113 | Name="VCCLCompilerTool" | ||
114 | AdditionalOptions="/Oy-" | ||
115 | Optimization="0" | ||
116 | AdditionalIncludeDirectories="..\llcommon;..\llmath;..\llvfs;..\llmessage;..\llimage;..\llwindow;..\..\libraries\i686-win32\include;..\..\libraries\include\" | ||
117 | PreprocessorDefinitions="WIN32;NDEBUG;_LIB;LL_WINDOWS;LL_RELEASE" | ||
118 | RuntimeLibrary="0" | ||
119 | StructMemberAlignment="0" | ||
120 | ForceConformanceInForLoopScope="TRUE" | ||
121 | UsePrecompiledHeader="0" | ||
122 | WarningLevel="3" | ||
123 | WarnAsError="TRUE" | ||
124 | Detect64BitPortabilityProblems="FALSE" | ||
125 | DebugInformationFormat="3"/> | ||
126 | <Tool | ||
127 | Name="VCCustomBuildTool"/> | ||
128 | <Tool | ||
129 | Name="VCLibrarianTool" | ||
130 | OutputFile="$(OutDir)/llrender.lib"/> | ||
131 | <Tool | ||
132 | Name="VCMIDLTool"/> | ||
133 | <Tool | ||
134 | Name="VCPostBuildEventTool"/> | ||
135 | <Tool | ||
136 | Name="VCPreBuildEventTool"/> | ||
137 | <Tool | ||
138 | Name="VCPreLinkEventTool"/> | ||
139 | <Tool | ||
140 | Name="VCResourceCompilerTool"/> | ||
141 | <Tool | ||
142 | Name="VCWebServiceProxyGeneratorTool"/> | ||
143 | <Tool | ||
144 | Name="VCXMLDataGeneratorTool"/> | ||
145 | <Tool | ||
146 | Name="VCManagedWrapperGeneratorTool"/> | ||
147 | <Tool | ||
148 | Name="VCAuxiliaryManagedWrapperGeneratorTool"/> | ||
149 | </Configuration> | ||
150 | </Configurations> | ||
151 | <References> | ||
152 | </References> | ||
153 | <Files> | ||
154 | <Filter | ||
155 | Name="Source Files" | ||
156 | Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" | ||
157 | UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"> | ||
158 | <File | ||
159 | RelativePath=".\llfont.cpp"> | ||
160 | </File> | ||
161 | <File | ||
162 | RelativePath=".\llfontgl.cpp"> | ||
163 | </File> | ||
164 | <File | ||
165 | RelativePath=".\llgldbg.cpp"> | ||
166 | </File> | ||
167 | <File | ||
168 | RelativePath=".\llrender.cpp"> | ||
169 | </File> | ||
170 | <File | ||
171 | RelativePath=".\llimagegl.cpp"> | ||
172 | </File> | ||
173 | <File | ||
174 | RelativePath=".\llrendertarget.cpp"> | ||
175 | </File> | ||
176 | <File | ||
177 | RelativePath=".\llvertexbuffer.cpp"> | ||
178 | </File> | ||
179 | </Filter> | ||
180 | <Filter | ||
181 | Name="Header Files" | ||
182 | Filter="h;hpp;hxx;hm;inl;inc;xsd" | ||
183 | UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"> | ||
184 | <File | ||
185 | RelativePath=".\glext.h"> | ||
186 | </File> | ||
187 | <File | ||
188 | RelativePath=".\llagpmempool.h"> | ||
189 | </File> | ||
190 | <File | ||
191 | RelativePath=".\llagpmempoolarb.h"> | ||
192 | </File> | ||
193 | <File | ||
194 | RelativePath=".\llagpmempoolati.h"> | ||
195 | </File> | ||
196 | <File | ||
197 | RelativePath=".\llagpmempoolnv.h"> | ||
198 | </File> | ||
199 | <File | ||
200 | RelativePath=".\llfont.h"> | ||
201 | </File> | ||
202 | <File | ||
203 | RelativePath=".\llfontgl.h"> | ||
204 | </File> | ||
205 | <File | ||
206 | RelativePath=".\llgldbg.h"> | ||
207 | </File> | ||
208 | <File | ||
209 | RelativePath=".\llrender.h"> | ||
210 | </File> | ||
211 | <File | ||
212 | RelativePath=".\llimagegl.h"> | ||
213 | </File> | ||
214 | <File | ||
215 | RelativePath=".\llrendertarget.h"> | ||
216 | </File> | ||
217 | <File | ||
218 | RelativePath=".\llvertexbuffer.h"> | ||
219 | </File> | ||
220 | <File | ||
221 | RelativePath=".\llvertexprogramgl.h"> | ||
222 | </File> | ||
223 | </Filter> | ||
224 | <Filter | ||
225 | Name="Resource Files" | ||
226 | Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx" | ||
227 | UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"> | ||
228 | </Filter> | ||
229 | </Files> | ||
230 | <Globals> | ||
231 | </Globals> | ||
232 | </VisualStudioProject> | ||
diff --git a/linden/indra/llrender/llrender_vc8.vcproj b/linden/indra/llrender/llrender_vc8.vcproj deleted file mode 100644 index 2147cec..0000000 --- a/linden/indra/llrender/llrender_vc8.vcproj +++ /dev/null | |||
@@ -1,329 +0,0 @@ | |||
1 | <?xml version="1.0" encoding="Windows-1252"?> | ||
2 | <VisualStudioProject | ||
3 | ProjectType="Visual C++" | ||
4 | Version="8.00" | ||
5 | Name="llrender" | ||
6 | ProjectGUID="{2ADE3C14-94C4-40BF-B033-70F3C954EE90}" | ||
7 | RootNamespace="llrender" | ||
8 | Keyword="Win32Proj" | ||
9 | > | ||
10 | <Platforms> | ||
11 | <Platform | ||
12 | Name="Win32" | ||
13 | /> | ||
14 | </Platforms> | ||
15 | <ToolFiles> | ||
16 | </ToolFiles> | ||
17 | <Configurations> | ||
18 | <Configuration | ||
19 | Name="Debug|Win32" | ||
20 | OutputDirectory="../lib_$(ConfigurationName)/i686-win32" | ||
21 | IntermediateDirectory="Debug" | ||
22 | ConfigurationType="4" | ||
23 | InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" | ||
24 | CharacterSet="1" | ||
25 | > | ||
26 | <Tool | ||
27 | Name="VCPreBuildEventTool" | ||
28 | /> | ||
29 | <Tool | ||
30 | Name="VCCustomBuildTool" | ||
31 | /> | ||
32 | <Tool | ||
33 | Name="VCXMLDataGeneratorTool" | ||
34 | /> | ||
35 | <Tool | ||
36 | Name="VCWebServiceProxyGeneratorTool" | ||
37 | /> | ||
38 | <Tool | ||
39 | Name="VCMIDLTool" | ||
40 | /> | ||
41 | <Tool | ||
42 | Name="VCCLCompilerTool" | ||
43 | Optimization="0" | ||
44 | AdditionalIncludeDirectories="..\llcommon;..\llmath;..\llvfs;..\llmessage;..\llimage;..\llwindow;..\..\libraries\i686-win32\include;..\..\libraries\include\" | ||
45 | PreprocessorDefinitions="WIN32;_DEBUG;_LIB;LL_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_USE_32BIT_TIME_T;LL_DEBUG" | ||
46 | MinimalRebuild="true" | ||
47 | BasicRuntimeChecks="3" | ||
48 | RuntimeLibrary="1" | ||
49 | StructMemberAlignment="4" | ||
50 | TreatWChar_tAsBuiltInType="false" | ||
51 | ForceConformanceInForLoopScope="true" | ||
52 | UsePrecompiledHeader="0" | ||
53 | WarningLevel="3" | ||
54 | WarnAsError="true" | ||
55 | Detect64BitPortabilityProblems="false" | ||
56 | DebugInformationFormat="4" | ||
57 | /> | ||
58 | <Tool | ||
59 | Name="VCManagedResourceCompilerTool" | ||
60 | /> | ||
61 | <Tool | ||
62 | Name="VCResourceCompilerTool" | ||
63 | /> | ||
64 | <Tool | ||
65 | Name="VCPreLinkEventTool" | ||
66 | /> | ||
67 | <Tool | ||
68 | Name="VCLibrarianTool" | ||
69 | OutputFile="$(OutDir)/llrender.lib" | ||
70 | /> | ||
71 | <Tool | ||
72 | Name="VCALinkTool" | ||
73 | /> | ||
74 | <Tool | ||
75 | Name="VCXDCMakeTool" | ||
76 | /> | ||
77 | <Tool | ||
78 | Name="VCBscMakeTool" | ||
79 | /> | ||
80 | <Tool | ||
81 | Name="VCFxCopTool" | ||
82 | /> | ||
83 | <Tool | ||
84 | Name="VCPostBuildEventTool" | ||
85 | /> | ||
86 | </Configuration> | ||
87 | <Configuration | ||
88 | Name="Release|Win32" | ||
89 | OutputDirectory="../lib_$(ConfigurationName)/i686-win32" | ||
90 | IntermediateDirectory="Release" | ||
91 | ConfigurationType="4" | ||
92 | InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" | ||
93 | CharacterSet="1" | ||
94 | > | ||
95 | <Tool | ||
96 | Name="VCPreBuildEventTool" | ||
97 | /> | ||
98 | <Tool | ||
99 | Name="VCCustomBuildTool" | ||
100 | /> | ||
101 | <Tool | ||
102 | Name="VCXMLDataGeneratorTool" | ||
103 | /> | ||
104 | <Tool | ||
105 | Name="VCWebServiceProxyGeneratorTool" | ||
106 | /> | ||
107 | <Tool | ||
108 | Name="VCMIDLTool" | ||
109 | /> | ||
110 | <Tool | ||
111 | Name="VCCLCompilerTool" | ||
112 | AdditionalOptions="/Oy-" | ||
113 | InlineFunctionExpansion="2" | ||
114 | EnableIntrinsicFunctions="true" | ||
115 | AdditionalIncludeDirectories="..\llcommon;..\llmath;..\llvfs;..\llmessage;..\llimage;..\llwindow;..\..\libraries\i686-win32\include;..\..\libraries\include\" | ||
116 | PreprocessorDefinitions="WIN32;NDEBUG;_LIB;LL_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_USE_32BIT_TIME_T;LL_RELEASE" | ||
117 | RuntimeLibrary="0" | ||
118 | StructMemberAlignment="0" | ||
119 | TreatWChar_tAsBuiltInType="false" | ||
120 | ForceConformanceInForLoopScope="true" | ||
121 | UsePrecompiledHeader="0" | ||
122 | WarningLevel="3" | ||
123 | WarnAsError="true" | ||
124 | Detect64BitPortabilityProblems="false" | ||
125 | DebugInformationFormat="3" | ||
126 | /> | ||
127 | <Tool | ||
128 | Name="VCManagedResourceCompilerTool" | ||
129 | /> | ||
130 | <Tool | ||
131 | Name="VCResourceCompilerTool" | ||
132 | /> | ||
133 | <Tool | ||
134 | Name="VCPreLinkEventTool" | ||
135 | /> | ||
136 | <Tool | ||
137 | Name="VCLibrarianTool" | ||
138 | OutputFile="$(OutDir)/llrender.lib" | ||
139 | /> | ||
140 | <Tool | ||
141 | Name="VCALinkTool" | ||
142 | /> | ||
143 | <Tool | ||
144 | Name="VCXDCMakeTool" | ||
145 | /> | ||
146 | <Tool | ||
147 | Name="VCBscMakeTool" | ||
148 | /> | ||
149 | <Tool | ||
150 | Name="VCFxCopTool" | ||
151 | /> | ||
152 | <Tool | ||
153 | Name="VCPostBuildEventTool" | ||
154 | /> | ||
155 | </Configuration> | ||
156 | <Configuration | ||
157 | Name="ReleaseNoOpt|Win32" | ||
158 | OutputDirectory="../lib_$(ConfigurationName)/i686-win32" | ||
159 | IntermediateDirectory="$(ConfigurationName)" | ||
160 | ConfigurationType="4" | ||
161 | InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" | ||
162 | CharacterSet="1" | ||
163 | > | ||
164 | <Tool | ||
165 | Name="VCPreBuildEventTool" | ||
166 | /> | ||
167 | <Tool | ||
168 | Name="VCCustomBuildTool" | ||
169 | /> | ||
170 | <Tool | ||
171 | Name="VCXMLDataGeneratorTool" | ||
172 | /> | ||
173 | <Tool | ||
174 | Name="VCWebServiceProxyGeneratorTool" | ||
175 | /> | ||
176 | <Tool | ||
177 | Name="VCMIDLTool" | ||
178 | /> | ||
179 | <Tool | ||
180 | Name="VCCLCompilerTool" | ||
181 | AdditionalOptions="/Oy-" | ||
182 | Optimization="0" | ||
183 | AdditionalIncludeDirectories="..\llcommon;..\llmath;..\llvfs;..\llmessage;..\llimage;..\llwindow;..\..\libraries\i686-win32\include;..\..\libraries\include\" | ||
184 | PreprocessorDefinitions="WIN32;NDEBUG;_LIB;LL_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_USE_32BIT_TIME_T;LL_RELEASE" | ||
185 | RuntimeLibrary="0" | ||
186 | StructMemberAlignment="0" | ||
187 | TreatWChar_tAsBuiltInType="false" | ||
188 | ForceConformanceInForLoopScope="true" | ||
189 | UsePrecompiledHeader="0" | ||
190 | WarningLevel="3" | ||
191 | WarnAsError="true" | ||
192 | Detect64BitPortabilityProblems="false" | ||
193 | DebugInformationFormat="3" | ||
194 | /> | ||
195 | <Tool | ||
196 | Name="VCManagedResourceCompilerTool" | ||
197 | /> | ||
198 | <Tool | ||
199 | Name="VCResourceCompilerTool" | ||
200 | /> | ||
201 | <Tool | ||
202 | Name="VCPreLinkEventTool" | ||
203 | /> | ||
204 | <Tool | ||
205 | Name="VCLibrarianTool" | ||
206 | OutputFile="$(OutDir)/llrender.lib" | ||
207 | /> | ||
208 | <Tool | ||
209 | Name="VCALinkTool" | ||
210 | /> | ||
211 | <Tool | ||
212 | Name="VCXDCMakeTool" | ||
213 | /> | ||
214 | <Tool | ||
215 | Name="VCBscMakeTool" | ||
216 | /> | ||
217 | <Tool | ||
218 | Name="VCFxCopTool" | ||
219 | /> | ||
220 | <Tool | ||
221 | Name="VCPostBuildEventTool" | ||
222 | /> | ||
223 | </Configuration> | ||
224 | </Configurations> | ||
225 | <References> | ||
226 | </References> | ||
227 | <Files> | ||
228 | <Filter | ||
229 | Name="Source Files" | ||
230 | Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" | ||
231 | UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" | ||
232 | > | ||
233 | <File | ||
234 | RelativePath=".\llfont.cpp" | ||
235 | > | ||
236 | </File> | ||
237 | <File | ||
238 | RelativePath=".\llfontgl.cpp" | ||
239 | > | ||
240 | </File> | ||
241 | <File | ||
242 | RelativePath=".\llgldbg.cpp" | ||
243 | > | ||
244 | </File> | ||
245 | <File | ||
246 | RelativePath=".\llimagegl.cpp" | ||
247 | > | ||
248 | </File> | ||
249 | <File | ||
250 | RelativePath=".\llrender.cpp" | ||
251 | > | ||
252 | </File> | ||
253 | <File | ||
254 | RelativePath=".\llrendertarget.cpp" | ||
255 | > | ||
256 | </File> | ||
257 | <File | ||
258 | RelativePath=".\llvertexbuffer.cpp" | ||
259 | > | ||
260 | </File> | ||
261 | </Filter> | ||
262 | <Filter | ||
263 | Name="Header Files" | ||
264 | Filter="h;hpp;hxx;hm;inl;inc;xsd" | ||
265 | UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" | ||
266 | > | ||
267 | <File | ||
268 | RelativePath=".\glext.h" | ||
269 | > | ||
270 | </File> | ||
271 | <File | ||
272 | RelativePath=".\llagpmempool.h" | ||
273 | > | ||
274 | </File> | ||
275 | <File | ||
276 | RelativePath=".\llagpmempoolarb.h" | ||
277 | > | ||
278 | </File> | ||
279 | <File | ||
280 | RelativePath=".\llagpmempoolati.h" | ||
281 | > | ||
282 | </File> | ||
283 | <File | ||
284 | RelativePath=".\llagpmempoolnv.h" | ||
285 | > | ||
286 | </File> | ||
287 | <File | ||
288 | RelativePath=".\llfont.h" | ||
289 | > | ||
290 | </File> | ||
291 | <File | ||
292 | RelativePath=".\llfontgl.h" | ||
293 | > | ||
294 | </File> | ||
295 | <File | ||
296 | RelativePath=".\llgldbg.h" | ||
297 | > | ||
298 | </File> | ||
299 | <File | ||
300 | RelativePath=".\llimagegl.h" | ||
301 | > | ||
302 | </File> | ||
303 | <File | ||
304 | RelativePath=".\llrender.h" | ||
305 | > | ||
306 | </File> | ||
307 | <File | ||
308 | RelativePath=".\llrendertarget.h" | ||
309 | > | ||
310 | </File> | ||
311 | <File | ||
312 | RelativePath=".\llvertexbuffer.h" | ||
313 | > | ||
314 | </File> | ||
315 | <File | ||
316 | RelativePath=".\llvertexprogramgl.h" | ||
317 | > | ||
318 | </File> | ||
319 | </Filter> | ||
320 | <Filter | ||
321 | Name="Resource Files" | ||
322 | Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx" | ||
323 | UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}" | ||
324 | > | ||
325 | </Filter> | ||
326 | </Files> | ||
327 | <Globals> | ||
328 | </Globals> | ||
329 | </VisualStudioProject> | ||
diff --git a/linden/indra/llrender/llrender_vc9.vcproj b/linden/indra/llrender/llrender_vc9.vcproj deleted file mode 100644 index 67385e6..0000000 --- a/linden/indra/llrender/llrender_vc9.vcproj +++ /dev/null | |||
@@ -1,330 +0,0 @@ | |||
1 | <?xml version="1.0" encoding="Windows-1252"?> | ||
2 | <VisualStudioProject | ||
3 | ProjectType="Visual C++" | ||
4 | Version="9.00" | ||
5 | Name="llrender" | ||
6 | ProjectGUID="{2ADE3C14-94C4-40BF-B033-70F3C954EE90}" | ||
7 | RootNamespace="llrender" | ||
8 | Keyword="Win32Proj" | ||
9 | TargetFrameworkVersion="131072" | ||
10 | > | ||
11 | <Platforms> | ||
12 | <Platform | ||
13 | Name="Win32" | ||
14 | /> | ||
15 | </Platforms> | ||
16 | <ToolFiles> | ||
17 | </ToolFiles> | ||
18 | <Configurations> | ||
19 | <Configuration | ||
20 | Name="Debug|Win32" | ||
21 | OutputDirectory="../lib_$(ConfigurationName)/i686-win32" | ||
22 | IntermediateDirectory="Debug" | ||
23 | ConfigurationType="4" | ||
24 | InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" | ||
25 | CharacterSet="1" | ||
26 | > | ||
27 | <Tool | ||
28 | Name="VCPreBuildEventTool" | ||
29 | /> | ||
30 | <Tool | ||
31 | Name="VCCustomBuildTool" | ||
32 | /> | ||
33 | <Tool | ||
34 | Name="VCXMLDataGeneratorTool" | ||
35 | /> | ||
36 | <Tool | ||
37 | Name="VCWebServiceProxyGeneratorTool" | ||
38 | /> | ||
39 | <Tool | ||
40 | Name="VCMIDLTool" | ||
41 | /> | ||
42 | <Tool | ||
43 | Name="VCCLCompilerTool" | ||
44 | Optimization="0" | ||
45 | AdditionalIncludeDirectories="..\llcommon;..\llmath;..\llvfs;..\llmessage;..\llimage;..\llwindow;..\..\libraries\i686-win32\include;..\..\libraries\include\" | ||
46 | PreprocessorDefinitions="WIN32;_DEBUG;_LIB;LL_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_USE_32BIT_TIME_T;LL_DEBUG" | ||
47 | MinimalRebuild="true" | ||
48 | BasicRuntimeChecks="3" | ||
49 | RuntimeLibrary="1" | ||
50 | StructMemberAlignment="4" | ||
51 | TreatWChar_tAsBuiltInType="false" | ||
52 | ForceConformanceInForLoopScope="true" | ||
53 | UsePrecompiledHeader="0" | ||
54 | WarningLevel="3" | ||
55 | WarnAsError="true" | ||
56 | Detect64BitPortabilityProblems="false" | ||
57 | DebugInformationFormat="4" | ||
58 | /> | ||
59 | <Tool | ||
60 | Name="VCManagedResourceCompilerTool" | ||
61 | /> | ||
62 | <Tool | ||
63 | Name="VCResourceCompilerTool" | ||
64 | /> | ||
65 | <Tool | ||
66 | Name="VCPreLinkEventTool" | ||
67 | /> | ||
68 | <Tool | ||
69 | Name="VCLibrarianTool" | ||
70 | OutputFile="$(OutDir)/llrender.lib" | ||
71 | /> | ||
72 | <Tool | ||
73 | Name="VCALinkTool" | ||
74 | /> | ||
75 | <Tool | ||
76 | Name="VCXDCMakeTool" | ||
77 | /> | ||
78 | <Tool | ||
79 | Name="VCBscMakeTool" | ||
80 | /> | ||
81 | <Tool | ||
82 | Name="VCFxCopTool" | ||
83 | /> | ||
84 | <Tool | ||
85 | Name="VCPostBuildEventTool" | ||
86 | /> | ||
87 | </Configuration> | ||
88 | <Configuration | ||
89 | Name="Release|Win32" | ||
90 | OutputDirectory="../lib_$(ConfigurationName)/i686-win32" | ||
91 | IntermediateDirectory="Release" | ||
92 | ConfigurationType="4" | ||
93 | InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" | ||
94 | CharacterSet="1" | ||
95 | > | ||
96 | <Tool | ||
97 | Name="VCPreBuildEventTool" | ||
98 | /> | ||
99 | <Tool | ||
100 | Name="VCCustomBuildTool" | ||
101 | /> | ||
102 | <Tool | ||
103 | Name="VCXMLDataGeneratorTool" | ||
104 | /> | ||
105 | <Tool | ||
106 | Name="VCWebServiceProxyGeneratorTool" | ||
107 | /> | ||
108 | <Tool | ||
109 | Name="VCMIDLTool" | ||
110 | /> | ||
111 | <Tool | ||
112 | Name="VCCLCompilerTool" | ||
113 | AdditionalOptions="/Oy-" | ||
114 | InlineFunctionExpansion="2" | ||
115 | EnableIntrinsicFunctions="true" | ||
116 | AdditionalIncludeDirectories="..\llcommon;..\llmath;..\llvfs;..\llmessage;..\llimage;..\llwindow;..\..\libraries\i686-win32\include;..\..\libraries\include\" | ||
117 | PreprocessorDefinitions="WIN32;NDEBUG;_LIB;LL_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_USE_32BIT_TIME_T;LL_RELEASE" | ||
118 | RuntimeLibrary="0" | ||
119 | StructMemberAlignment="0" | ||
120 | TreatWChar_tAsBuiltInType="false" | ||
121 | ForceConformanceInForLoopScope="true" | ||
122 | UsePrecompiledHeader="0" | ||
123 | WarningLevel="3" | ||
124 | WarnAsError="true" | ||
125 | Detect64BitPortabilityProblems="false" | ||
126 | DebugInformationFormat="3" | ||
127 | /> | ||
128 | <Tool | ||
129 | Name="VCManagedResourceCompilerTool" | ||
130 | /> | ||
131 | <Tool | ||
132 | Name="VCResourceCompilerTool" | ||
133 | /> | ||
134 | <Tool | ||
135 | Name="VCPreLinkEventTool" | ||
136 | /> | ||
137 | <Tool | ||
138 | Name="VCLibrarianTool" | ||
139 | OutputFile="$(OutDir)/llrender.lib" | ||
140 | /> | ||
141 | <Tool | ||
142 | Name="VCALinkTool" | ||
143 | /> | ||
144 | <Tool | ||
145 | Name="VCXDCMakeTool" | ||
146 | /> | ||
147 | <Tool | ||
148 | Name="VCBscMakeTool" | ||
149 | /> | ||
150 | <Tool | ||
151 | Name="VCFxCopTool" | ||
152 | /> | ||
153 | <Tool | ||
154 | Name="VCPostBuildEventTool" | ||
155 | /> | ||
156 | </Configuration> | ||
157 | <Configuration | ||
158 | Name="ReleaseNoOpt|Win32" | ||
159 | OutputDirectory="../lib_$(ConfigurationName)/i686-win32" | ||
160 | IntermediateDirectory="$(ConfigurationName)" | ||
161 | ConfigurationType="4" | ||
162 | InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" | ||
163 | CharacterSet="1" | ||
164 | > | ||
165 | <Tool | ||
166 | Name="VCPreBuildEventTool" | ||
167 | /> | ||
168 | <Tool | ||
169 | Name="VCCustomBuildTool" | ||
170 | /> | ||
171 | <Tool | ||
172 | Name="VCXMLDataGeneratorTool" | ||
173 | /> | ||
174 | <Tool | ||
175 | Name="VCWebServiceProxyGeneratorTool" | ||
176 | /> | ||
177 | <Tool | ||
178 | Name="VCMIDLTool" | ||
179 | /> | ||
180 | <Tool | ||
181 | Name="VCCLCompilerTool" | ||
182 | AdditionalOptions="/Oy-" | ||
183 | Optimization="0" | ||
184 | AdditionalIncludeDirectories="..\llcommon;..\llmath;..\llvfs;..\llmessage;..\llimage;..\llwindow;..\..\libraries\i686-win32\include;..\..\libraries\include\" | ||
185 | PreprocessorDefinitions="WIN32;NDEBUG;_LIB;LL_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_USE_32BIT_TIME_T;LL_RELEASE" | ||
186 | RuntimeLibrary="0" | ||
187 | StructMemberAlignment="0" | ||
188 | TreatWChar_tAsBuiltInType="false" | ||
189 | ForceConformanceInForLoopScope="true" | ||
190 | UsePrecompiledHeader="0" | ||
191 | WarningLevel="3" | ||
192 | WarnAsError="true" | ||
193 | Detect64BitPortabilityProblems="false" | ||
194 | DebugInformationFormat="3" | ||
195 | /> | ||
196 | <Tool | ||
197 | Name="VCManagedResourceCompilerTool" | ||
198 | /> | ||
199 | <Tool | ||
200 | Name="VCResourceCompilerTool" | ||
201 | /> | ||
202 | <Tool | ||
203 | Name="VCPreLinkEventTool" | ||
204 | /> | ||
205 | <Tool | ||
206 | Name="VCLibrarianTool" | ||
207 | OutputFile="$(OutDir)/llrender.lib" | ||
208 | /> | ||
209 | <Tool | ||
210 | Name="VCALinkTool" | ||
211 | /> | ||
212 | <Tool | ||
213 | Name="VCXDCMakeTool" | ||
214 | /> | ||
215 | <Tool | ||
216 | Name="VCBscMakeTool" | ||
217 | /> | ||
218 | <Tool | ||
219 | Name="VCFxCopTool" | ||
220 | /> | ||
221 | <Tool | ||
222 | Name="VCPostBuildEventTool" | ||
223 | /> | ||
224 | </Configuration> | ||
225 | </Configurations> | ||
226 | <References> | ||
227 | </References> | ||
228 | <Files> | ||
229 | <Filter | ||
230 | Name="Source Files" | ||
231 | Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" | ||
232 | UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" | ||
233 | > | ||
234 | <File | ||
235 | RelativePath=".\llfont.cpp" | ||
236 | > | ||
237 | </File> | ||
238 | <File | ||
239 | RelativePath=".\llfontgl.cpp" | ||
240 | > | ||
241 | </File> | ||
242 | <File | ||
243 | RelativePath=".\llgldbg.cpp" | ||
244 | > | ||
245 | </File> | ||
246 | <File | ||
247 | RelativePath=".\llrender.cpp" | ||
248 | > | ||
249 | </File> | ||
250 | <File | ||
251 | RelativePath=".\llimagegl.cpp" | ||
252 | > | ||
253 | </File> | ||
254 | <File | ||
255 | RelativePath=".\llrendertarget.cpp" | ||
256 | > | ||
257 | </File> | ||
258 | <File | ||
259 | RelativePath=".\llvertexbuffer.cpp" | ||
260 | > | ||
261 | </File> | ||
262 | </Filter> | ||
263 | <Filter | ||
264 | Name="Header Files" | ||
265 | Filter="h;hpp;hxx;hm;inl;inc;xsd" | ||
266 | UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" | ||
267 | > | ||
268 | <File | ||
269 | RelativePath=".\glext.h" | ||
270 | > | ||
271 | </File> | ||
272 | <File | ||
273 | RelativePath=".\llagpmempool.h" | ||
274 | > | ||
275 | </File> | ||
276 | <File | ||
277 | RelativePath=".\llagpmempoolarb.h" | ||
278 | > | ||
279 | </File> | ||
280 | <File | ||
281 | RelativePath=".\llagpmempoolati.h" | ||
282 | > | ||
283 | </File> | ||
284 | <File | ||
285 | RelativePath=".\llagpmempoolnv.h" | ||
286 | > | ||
287 | </File> | ||
288 | <File | ||
289 | RelativePath=".\llfont.h" | ||
290 | > | ||
291 | </File> | ||
292 | <File | ||
293 | RelativePath=".\llfontgl.h" | ||
294 | > | ||
295 | </File> | ||
296 | <File | ||
297 | RelativePath=".\llgldbg.h" | ||
298 | > | ||
299 | </File> | ||
300 | <File | ||
301 | RelativePath=".\llrender.h" | ||
302 | > | ||
303 | </File> | ||
304 | <File | ||
305 | RelativePath=".\llimagegl.h" | ||
306 | > | ||
307 | </File> | ||
308 | <File | ||
309 | RelativePath=".\llrendertarget.h" | ||
310 | > | ||
311 | </File> | ||
312 | <File | ||
313 | RelativePath=".\llvertexbuffer.h" | ||
314 | > | ||
315 | </File> | ||
316 | <File | ||
317 | RelativePath=".\llvertexprogramgl.h" | ||
318 | > | ||
319 | </File> | ||
320 | </Filter> | ||
321 | <Filter | ||
322 | Name="Resource Files" | ||
323 | Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx" | ||
324 | UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}" | ||
325 | > | ||
326 | </Filter> | ||
327 | </Files> | ||
328 | <Globals> | ||
329 | </Globals> | ||
330 | </VisualStudioProject> | ||
diff --git a/linden/indra/llrender/llrendersphere.cpp b/linden/indra/llrender/llrendersphere.cpp new file mode 100644 index 0000000..0c3cd19 --- /dev/null +++ b/linden/indra/llrender/llrendersphere.cpp | |||
@@ -0,0 +1,182 @@ | |||
1 | /** | ||
2 | * @file llrendersphere.cpp | ||
3 | * @brief implementation of the LLRenderSphere class. | ||
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 | // Sphere creates a set of display lists that can then be called to create | ||
33 | // a lit sphere at different LOD levels. You only need one instance of sphere | ||
34 | // per viewer - then call the appropriate list. | ||
35 | |||
36 | #include "linden_common.h" | ||
37 | |||
38 | #include "llrendersphere.h" | ||
39 | #include "llerror.h" | ||
40 | |||
41 | #include "llglheaders.h" | ||
42 | |||
43 | GLUquadricObj *gQuadObj2 = NULL; | ||
44 | LLRenderSphere gSphere; | ||
45 | |||
46 | void drawSolidSphere(GLdouble radius, GLint slices, GLint stacks); | ||
47 | |||
48 | void drawSolidSphere(GLdouble radius, GLint slices, GLint stacks) | ||
49 | { | ||
50 | if (!gQuadObj2) | ||
51 | { | ||
52 | gQuadObj2 = gluNewQuadric(); | ||
53 | if (!gQuadObj2) | ||
54 | { | ||
55 | llwarns << "drawSolidSphere couldn't allocate quadric" << llendl; | ||
56 | return; | ||
57 | } | ||
58 | } | ||
59 | |||
60 | gluQuadricDrawStyle(gQuadObj2, GLU_FILL); | ||
61 | gluQuadricNormals(gQuadObj2, GLU_SMOOTH); | ||
62 | // If we ever changed/used the texture or orientation state | ||
63 | // of quadObj, we'd need to change it to the defaults here | ||
64 | // with gluQuadricTexture and/or gluQuadricOrientation. | ||
65 | gluQuadricTexture(gQuadObj2, GL_TRUE); | ||
66 | gluSphere(gQuadObj2, radius, slices, stacks); | ||
67 | } | ||
68 | |||
69 | |||
70 | // lat = 0 is Z-axis | ||
71 | // lon = 0, lat = 90 at X-axis | ||
72 | void lat2xyz(LLVector3 * result, F32 lat, F32 lon) | ||
73 | { | ||
74 | // Convert a latitude and longitude to x,y,z on a normal sphere and return it in result | ||
75 | F32 r; | ||
76 | result->mV[VX] = (F32) (cos(lon * DEG_TO_RAD) * sin(lat * DEG_TO_RAD)); | ||
77 | result->mV[VY] = (F32) (sin(lon * DEG_TO_RAD) * sin(lat * DEG_TO_RAD)); | ||
78 | r = (F32) pow(result->mV[VX] * result->mV[VX] + result->mV[VY] * result->mV[VY], 0.5f); | ||
79 | if (r == 1.0f) | ||
80 | { | ||
81 | result->mV[VZ] = 0.0f; | ||
82 | } | ||
83 | else | ||
84 | { | ||
85 | result->mV[VZ] = (F32) pow(1 - r*r, 0.5f); | ||
86 | if (lat > 90.01) | ||
87 | { | ||
88 | result->mV[VZ] *= -1.0; | ||
89 | } | ||
90 | } | ||
91 | } | ||
92 | |||
93 | void lat2xyz_rad(LLVector3 * result, F32 lat, F32 lon) | ||
94 | { | ||
95 | // Convert a latitude and longitude to x,y,z on a normal sphere and return it in result | ||
96 | F32 r; | ||
97 | result->mV[VX] = (F32) (cos(lon) * sin(lat)); | ||
98 | result->mV[VY] = (F32) (sin(lon) * sin(lat)); | ||
99 | r = (F32) pow(result->mV[VX] * result->mV[VX] + result->mV[VY] * result->mV[VY], 0.5f); | ||
100 | if (r == 1.0f) | ||
101 | result->mV[VZ] = 0.0f; | ||
102 | else | ||
103 | { | ||
104 | result->mV[VZ] = (F32) pow(1 - r*r, 0.5f); | ||
105 | if (lat > F_PI_BY_TWO) result->mV[VZ] *= -1.0; | ||
106 | } | ||
107 | } | ||
108 | |||
109 | // A couple thoughts on sphere drawing: | ||
110 | // 1) You need more slices than stacks, but little less than 2:1 | ||
111 | // 2) At low LOD, setting stacks to an odd number avoids a "band" around the equator, making things look smoother | ||
112 | void LLRenderSphere::prerender() | ||
113 | { | ||
114 | // Create a series of display lists for different LODs | ||
115 | mDList[0] = glGenLists(1); | ||
116 | glNewList(mDList[0], GL_COMPILE); | ||
117 | drawSolidSphere(1.0, 30, 20); | ||
118 | glEndList(); | ||
119 | |||
120 | mDList[1] = glGenLists(1); | ||
121 | glNewList(mDList[1], GL_COMPILE); | ||
122 | drawSolidSphere(1.0, 20, 15); | ||
123 | glEndList(); | ||
124 | |||
125 | mDList[2] = glGenLists(1); | ||
126 | glNewList(mDList[2], GL_COMPILE); | ||
127 | drawSolidSphere(1.0, 12, 8); | ||
128 | glEndList(); | ||
129 | |||
130 | mDList[3] = glGenLists(1); | ||
131 | glNewList(mDList[3], GL_COMPILE); | ||
132 | drawSolidSphere(1.0, 8, 5); | ||
133 | glEndList(); | ||
134 | } | ||
135 | |||
136 | void LLRenderSphere::cleanupGL() | ||
137 | { | ||
138 | for (S32 detail = 0; detail < 4; detail++) | ||
139 | { | ||
140 | glDeleteLists(mDList[detail], 1); | ||
141 | mDList[detail] = 0; | ||
142 | } | ||
143 | |||
144 | if (gQuadObj2) | ||
145 | { | ||
146 | gluDeleteQuadric(gQuadObj2); | ||
147 | gQuadObj2 = NULL; | ||
148 | } | ||
149 | } | ||
150 | |||
151 | // Constants here are empirically derived from my eyeballs, JNC | ||
152 | // | ||
153 | // The toughest adjustment is the cutoff for the lowest LOD | ||
154 | // Maybe we should have more LODs at the low end? | ||
155 | void LLRenderSphere::render(F32 pixel_area) | ||
156 | { | ||
157 | S32 level_of_detail; | ||
158 | |||
159 | if (pixel_area > 10000.f) | ||
160 | { | ||
161 | level_of_detail = 0; | ||
162 | } | ||
163 | else if (pixel_area > 800.f) | ||
164 | { | ||
165 | level_of_detail = 1; | ||
166 | } | ||
167 | else if (pixel_area > 100.f) | ||
168 | { | ||
169 | level_of_detail = 2; | ||
170 | } | ||
171 | else | ||
172 | { | ||
173 | level_of_detail = 3; | ||
174 | } | ||
175 | glCallList(mDList[level_of_detail]); | ||
176 | } | ||
177 | |||
178 | |||
179 | void LLRenderSphere::render() | ||
180 | { | ||
181 | glCallList(mDList[0]); | ||
182 | } | ||
diff --git a/linden/indra/llrender/llrendersphere.h b/linden/indra/llrender/llrendersphere.h new file mode 100644 index 0000000..ace57e4 --- /dev/null +++ b/linden/indra/llrender/llrendersphere.h | |||
@@ -0,0 +1,47 @@ | |||
1 | /** | ||
2 | * @file llrendersphere.h | ||
3 | * @brief interface for the LLRenderSphere class. | ||
4 | * | ||
5 | * $LicenseInfo:firstyear=2001&license=internal$ | ||
6 | * | ||
7 | * Copyright (c) 2001-2008, Linden Research, Inc. | ||
8 | * | ||
9 | * The following source code is PROPRIETARY AND CONFIDENTIAL. Use of | ||
10 | * this source code is governed by the Linden Lab Source Code Disclosure | ||
11 | * Agreement ("Agreement") previously entered between you and Linden | ||
12 | * Lab. By accessing, using, copying, modifying or distributing this | ||
13 | * software, you acknowledge that you have been informed of your | ||
14 | * obligations under the Agreement and agree to abide by those obligations. | ||
15 | * | ||
16 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
17 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
18 | * COMPLETENESS OR PERFORMANCE. | ||
19 | * $/LicenseInfo$ | ||
20 | */ | ||
21 | |||
22 | #ifndef LL_LLRENDERSPHERE_H | ||
23 | #define LL_LLRENDERSPHERE_H | ||
24 | |||
25 | #include "llmath.h" | ||
26 | #include "v3math.h" | ||
27 | #include "v4math.h" | ||
28 | #include "m3math.h" | ||
29 | #include "m4math.h" | ||
30 | #include "v4color.h" | ||
31 | #include "llgl.h" | ||
32 | |||
33 | void lat2xyz(LLVector3 * result, F32 lat, F32 lon); // utility routine | ||
34 | |||
35 | class LLRenderSphere | ||
36 | { | ||
37 | public: | ||
38 | LLGLuint mDList[5]; | ||
39 | |||
40 | void prerender(); | ||
41 | void cleanupGL(); | ||
42 | void render(F32 pixel_area); // of a box of size 1.0 at that position | ||
43 | void render(); // render at highest LOD | ||
44 | }; | ||
45 | |||
46 | extern LLRenderSphere gSphere; | ||
47 | #endif | ||
diff --git a/linden/indra/llrender/llrendertarget.cpp b/linden/indra/llrender/llrendertarget.cpp index 708c582..e18ec56 100644 --- a/linden/indra/llrender/llrendertarget.cpp +++ b/linden/indra/llrender/llrendertarget.cpp | |||
@@ -99,11 +99,16 @@ void LLRenderTarget::allocate(U32 resx, U32 resy, U32 color_fmt, BOOL depth, U32 | |||
99 | 99 | ||
100 | glGenFramebuffersEXT(1, (GLuint *) &mFBO); | 100 | glGenFramebuffersEXT(1, (GLuint *) &mFBO); |
101 | 101 | ||
102 | stop_glerror(); | ||
103 | |||
102 | glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mFBO); | 104 | glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mFBO); |
103 | 105 | ||
106 | stop_glerror(); | ||
107 | |||
104 | if (mDepth) | 108 | if (mDepth) |
105 | { | 109 | { |
106 | glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, mUsage, mDepth, 0); | 110 | glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, mUsage, mDepth, 0); |
111 | stop_glerror(); | ||
107 | glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, mUsage, mDepth, 0); | 112 | glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, mUsage, mDepth, 0); |
108 | stop_glerror(); | 113 | stop_glerror(); |
109 | } | 114 | } |
diff --git a/linden/indra/llrender/llshadermgr.cpp b/linden/indra/llrender/llshadermgr.cpp new file mode 100644 index 0000000..4416775 --- /dev/null +++ b/linden/indra/llrender/llshadermgr.cpp | |||
@@ -0,0 +1,513 @@ | |||
1 | /** | ||
2 | * @file llshadermgr.cpp | ||
3 | * @brief Shader manager implementation. | ||
4 | * | ||
5 | * $LicenseInfo:firstyear=2005&license=viewergpl$ | ||
6 | * | ||
7 | * Copyright (c) 2005-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 | #include "linden_common.h" | ||
33 | |||
34 | #include "llshadermgr.h" | ||
35 | |||
36 | #include "llfile.h" | ||
37 | #include "llrender.h" | ||
38 | |||
39 | #if LL_DARWIN | ||
40 | #include "OpenGL/OpenGL.h" | ||
41 | #endif | ||
42 | |||
43 | #ifdef LL_RELEASE_FOR_DOWNLOAD | ||
44 | #define UNIFORM_ERRS LL_WARNS_ONCE("Shader") | ||
45 | #else | ||
46 | #define UNIFORM_ERRS LL_ERRS("Shader") | ||
47 | #endif | ||
48 | |||
49 | // Lots of STL stuff in here, using namespace std to keep things more readable | ||
50 | using std::vector; | ||
51 | using std::pair; | ||
52 | using std::make_pair; | ||
53 | using std::string; | ||
54 | |||
55 | LLShaderMgr * LLShaderMgr::sInstance = NULL; | ||
56 | |||
57 | LLShaderMgr::LLShaderMgr() | ||
58 | { | ||
59 | } | ||
60 | |||
61 | |||
62 | LLShaderMgr::~LLShaderMgr() | ||
63 | { | ||
64 | } | ||
65 | |||
66 | // static | ||
67 | LLShaderMgr * LLShaderMgr::instance() | ||
68 | { | ||
69 | if(NULL == sInstance) | ||
70 | { | ||
71 | LL_ERRS("Shaders") << "LLShaderMgr should already have been instantiated by the application!" << LL_ENDL; | ||
72 | } | ||
73 | |||
74 | return sInstance; | ||
75 | } | ||
76 | |||
77 | BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) | ||
78 | { | ||
79 | llassert_always(shader != NULL); | ||
80 | LLShaderFeatures *features = & shader->mFeatures; | ||
81 | |||
82 | ////////////////////////////////////// | ||
83 | // Attach Vertex Shader Features First | ||
84 | ////////////////////////////////////// | ||
85 | |||
86 | // NOTE order of shader object attaching is VERY IMPORTANT!!! | ||
87 | if (features->calculatesAtmospherics) | ||
88 | { | ||
89 | if (!shader->attachObject("windlight/atmosphericsVarsV.glsl")) | ||
90 | { | ||
91 | return FALSE; | ||
92 | } | ||
93 | } | ||
94 | |||
95 | if (features->calculatesLighting) | ||
96 | { | ||
97 | if (!shader->attachObject("windlight/atmosphericsHelpersV.glsl")) | ||
98 | { | ||
99 | return FALSE; | ||
100 | } | ||
101 | |||
102 | if (features->isSpecular) | ||
103 | { | ||
104 | if (!shader->attachObject("lighting/lightFuncSpecularV.glsl")) | ||
105 | { | ||
106 | return FALSE; | ||
107 | } | ||
108 | |||
109 | if (!shader->attachObject("lighting/sumLightsSpecularV.glsl")) | ||
110 | { | ||
111 | return FALSE; | ||
112 | } | ||
113 | |||
114 | if (!shader->attachObject("lighting/lightSpecularV.glsl")) | ||
115 | { | ||
116 | return FALSE; | ||
117 | } | ||
118 | } | ||
119 | else | ||
120 | { | ||
121 | if (!shader->attachObject("lighting/lightFuncV.glsl")) | ||
122 | { | ||
123 | return FALSE; | ||
124 | } | ||
125 | |||
126 | if (!shader->attachObject("lighting/sumLightsV.glsl")) | ||
127 | { | ||
128 | return FALSE; | ||
129 | } | ||
130 | |||
131 | if (!shader->attachObject("lighting/lightV.glsl")) | ||
132 | { | ||
133 | return FALSE; | ||
134 | } | ||
135 | } | ||
136 | } | ||
137 | |||
138 | // NOTE order of shader object attaching is VERY IMPORTANT!!! | ||
139 | if (features->calculatesAtmospherics) | ||
140 | { | ||
141 | if (!shader->attachObject("windlight/atmosphericsV.glsl")) | ||
142 | { | ||
143 | return FALSE; | ||
144 | } | ||
145 | } | ||
146 | |||
147 | if (features->hasSkinning) | ||
148 | { | ||
149 | if (!shader->attachObject("avatar/avatarSkinV.glsl")) | ||
150 | { | ||
151 | return FALSE; | ||
152 | } | ||
153 | } | ||
154 | |||
155 | /////////////////////////////////////// | ||
156 | // Attach Fragment Shader Features Next | ||
157 | /////////////////////////////////////// | ||
158 | |||
159 | if(features->calculatesAtmospherics) | ||
160 | { | ||
161 | if (!shader->attachObject("windlight/atmosphericsVarsF.glsl")) | ||
162 | { | ||
163 | return FALSE; | ||
164 | } | ||
165 | } | ||
166 | |||
167 | // NOTE order of shader object attaching is VERY IMPORTANT!!! | ||
168 | if (features->hasGamma) | ||
169 | { | ||
170 | if (!shader->attachObject("windlight/gammaF.glsl")) | ||
171 | { | ||
172 | return FALSE; | ||
173 | } | ||
174 | } | ||
175 | |||
176 | if (features->hasAtmospherics) | ||
177 | { | ||
178 | if (!shader->attachObject("windlight/atmosphericsF.glsl")) | ||
179 | { | ||
180 | return FALSE; | ||
181 | } | ||
182 | } | ||
183 | |||
184 | if (features->hasTransport) | ||
185 | { | ||
186 | if (!shader->attachObject("windlight/transportF.glsl")) | ||
187 | { | ||
188 | return FALSE; | ||
189 | } | ||
190 | |||
191 | // Test hasFullbright and hasShiny and attach fullbright and | ||
192 | // fullbright shiny atmos transport if we split them out. | ||
193 | } | ||
194 | |||
195 | // NOTE order of shader object attaching is VERY IMPORTANT!!! | ||
196 | if (features->hasWaterFog) | ||
197 | { | ||
198 | if (!shader->attachObject("environment/waterFogF.glsl")) | ||
199 | { | ||
200 | return FALSE; | ||
201 | } | ||
202 | } | ||
203 | |||
204 | if (features->hasLighting) | ||
205 | { | ||
206 | |||
207 | if (features->hasWaterFog) | ||
208 | { | ||
209 | if (!shader->attachObject("lighting/lightWaterF.glsl")) | ||
210 | { | ||
211 | return FALSE; | ||
212 | } | ||
213 | } | ||
214 | |||
215 | else | ||
216 | { | ||
217 | if (!shader->attachObject("lighting/lightF.glsl")) | ||
218 | { | ||
219 | return FALSE; | ||
220 | } | ||
221 | } | ||
222 | } | ||
223 | |||
224 | // NOTE order of shader object attaching is VERY IMPORTANT!!! | ||
225 | else if (features->isFullbright) | ||
226 | { | ||
227 | |||
228 | if (features->hasWaterFog) | ||
229 | { | ||
230 | if (!shader->attachObject("lighting/lightFullbrightWaterF.glsl")) | ||
231 | { | ||
232 | return FALSE; | ||
233 | } | ||
234 | } | ||
235 | |||
236 | else if (features->isShiny) | ||
237 | { | ||
238 | if (!shader->attachObject("lighting/lightFullbrightShinyF.glsl")) | ||
239 | { | ||
240 | return FALSE; | ||
241 | } | ||
242 | } | ||
243 | |||
244 | else | ||
245 | { | ||
246 | if (!shader->attachObject("lighting/lightFullbrightF.glsl")) | ||
247 | { | ||
248 | return FALSE; | ||
249 | } | ||
250 | } | ||
251 | } | ||
252 | |||
253 | // NOTE order of shader object attaching is VERY IMPORTANT!!! | ||
254 | else if (features->isShiny) | ||
255 | { | ||
256 | |||
257 | if (features->hasWaterFog) | ||
258 | { | ||
259 | if (!shader->attachObject("lighting/lightShinyWaterF.glsl")) | ||
260 | { | ||
261 | return FALSE; | ||
262 | } | ||
263 | } | ||
264 | |||
265 | else | ||
266 | { | ||
267 | if (!shader->attachObject("lighting/lightShinyF.glsl")) | ||
268 | { | ||
269 | return FALSE; | ||
270 | } | ||
271 | } | ||
272 | } | ||
273 | return TRUE; | ||
274 | } | ||
275 | |||
276 | //============================================================================ | ||
277 | // Load Shader | ||
278 | |||
279 | static std::string get_object_log(GLhandleARB ret) | ||
280 | { | ||
281 | std::string res; | ||
282 | |||
283 | //get log length | ||
284 | GLint length; | ||
285 | glGetObjectParameterivARB(ret, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length); | ||
286 | if (length > 0) | ||
287 | { | ||
288 | //the log could be any size, so allocate appropriately | ||
289 | GLcharARB* log = new GLcharARB[length]; | ||
290 | glGetInfoLogARB(ret, length, &length, log); | ||
291 | res = std::string((char *)log); | ||
292 | delete[] log; | ||
293 | } | ||
294 | return res; | ||
295 | } | ||
296 | |||
297 | void LLShaderMgr::dumpObjectLog(GLhandleARB ret, BOOL warns) | ||
298 | { | ||
299 | std::string log = get_object_log(ret); | ||
300 | if ( log.length() > 0 ) | ||
301 | { | ||
302 | if (warns) | ||
303 | { | ||
304 | LL_WARNS("ShaderLoading") << log << LL_ENDL; | ||
305 | } | ||
306 | else | ||
307 | { | ||
308 | LL_DEBUGS("ShaderLoading") << log << LL_ENDL; | ||
309 | } | ||
310 | } | ||
311 | } | ||
312 | |||
313 | GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shader_level, GLenum type) | ||
314 | { | ||
315 | GLenum error; | ||
316 | error = glGetError(); | ||
317 | if (error != GL_NO_ERROR) | ||
318 | { | ||
319 | LL_WARNS("ShaderLoading") << "GL ERROR entering loadShaderFile(): " << error << LL_ENDL; | ||
320 | } | ||
321 | |||
322 | LL_DEBUGS("ShaderLoading") << "Loading shader file: " << filename << " class " << shader_level << LL_ENDL; | ||
323 | |||
324 | if (filename.empty()) | ||
325 | { | ||
326 | return 0; | ||
327 | } | ||
328 | |||
329 | |||
330 | //read in from file | ||
331 | LLFILE* file = NULL; | ||
332 | |||
333 | S32 try_gpu_class = shader_level; | ||
334 | S32 gpu_class; | ||
335 | |||
336 | //find the most relevant file | ||
337 | for (gpu_class = try_gpu_class; gpu_class > 0; gpu_class--) | ||
338 | { //search from the current gpu class down to class 1 to find the most relevant shader | ||
339 | std::stringstream fname; | ||
340 | fname << getShaderDirPrefix(); | ||
341 | fname << gpu_class << "/" << filename; | ||
342 | |||
343 | LL_DEBUGS("ShaderLoading") << "Looking in " << fname.str() << LL_ENDL; | ||
344 | file = LLFile::fopen(fname.str(), "r"); /* Flawfinder: ignore */ | ||
345 | if (file) | ||
346 | { | ||
347 | LL_INFOS("ShaderLoading") << "Loading file: shaders/class" << gpu_class << "/" << filename << " (Want class " << gpu_class << ")" << LL_ENDL; | ||
348 | break; // done | ||
349 | } | ||
350 | } | ||
351 | |||
352 | if (file == NULL) | ||
353 | { | ||
354 | LL_WARNS("ShaderLoading") << "GLSL Shader file not found: " << filename << LL_ENDL; | ||
355 | return 0; | ||
356 | } | ||
357 | |||
358 | //we can't have any lines longer than 1024 characters | ||
359 | //or any shaders longer than 1024 lines... deal - DaveP | ||
360 | GLcharARB buff[1024]; | ||
361 | GLcharARB* text[1024]; | ||
362 | GLuint count = 0; | ||
363 | |||
364 | |||
365 | //copy file into memory | ||
366 | while(fgets((char *)buff, 1024, file) != NULL && count < (sizeof(buff)/sizeof(buff[0]))) | ||
367 | { | ||
368 | text[count++] = (GLcharARB *)strdup((char *)buff); | ||
369 | } | ||
370 | fclose(file); | ||
371 | |||
372 | //create shader object | ||
373 | GLhandleARB ret = glCreateShaderObjectARB(type); | ||
374 | error = glGetError(); | ||
375 | if (error != GL_NO_ERROR) | ||
376 | { | ||
377 | LL_WARNS("ShaderLoading") << "GL ERROR in glCreateShaderObjectARB: " << error << LL_ENDL; | ||
378 | } | ||
379 | else | ||
380 | { | ||
381 | //load source | ||
382 | glShaderSourceARB(ret, count, (const GLcharARB**) text, NULL); | ||
383 | error = glGetError(); | ||
384 | if (error != GL_NO_ERROR) | ||
385 | { | ||
386 | LL_WARNS("ShaderLoading") << "GL ERROR in glShaderSourceARB: " << error << LL_ENDL; | ||
387 | } | ||
388 | else | ||
389 | { | ||
390 | //compile source | ||
391 | glCompileShaderARB(ret); | ||
392 | error = glGetError(); | ||
393 | if (error != GL_NO_ERROR) | ||
394 | { | ||
395 | LL_WARNS("ShaderLoading") << "GL ERROR in glCompileShaderARB: " << error << LL_ENDL; | ||
396 | } | ||
397 | } | ||
398 | } | ||
399 | //free memory | ||
400 | for (GLuint i = 0; i < count; i++) | ||
401 | { | ||
402 | free(text[i]); | ||
403 | } | ||
404 | if (error == GL_NO_ERROR) | ||
405 | { | ||
406 | //check for errors | ||
407 | GLint success = GL_TRUE; | ||
408 | glGetObjectParameterivARB(ret, GL_OBJECT_COMPILE_STATUS_ARB, &success); | ||
409 | error = glGetError(); | ||
410 | if (error != GL_NO_ERROR || success == GL_FALSE) | ||
411 | { | ||
412 | //an error occured, print log | ||
413 | LL_WARNS("ShaderLoading") << "GLSL Compilation Error: (" << error << ") in " << filename << LL_ENDL; | ||
414 | dumpObjectLog(ret); | ||
415 | ret = 0; | ||
416 | } | ||
417 | } | ||
418 | else | ||
419 | { | ||
420 | ret = 0; | ||
421 | } | ||
422 | stop_glerror(); | ||
423 | |||
424 | //successfully loaded, save results | ||
425 | if (ret) | ||
426 | { | ||
427 | // Add shader file to map | ||
428 | mShaderObjects[filename] = ret; | ||
429 | shader_level = try_gpu_class; | ||
430 | } | ||
431 | else | ||
432 | { | ||
433 | if (shader_level > 1) | ||
434 | { | ||
435 | shader_level--; | ||
436 | return loadShaderFile(filename,shader_level,type); | ||
437 | } | ||
438 | LL_WARNS("ShaderLoading") << "Failed to load " << filename << LL_ENDL; | ||
439 | } | ||
440 | return ret; | ||
441 | } | ||
442 | |||
443 | BOOL LLShaderMgr::linkProgramObject(GLhandleARB obj, BOOL suppress_errors) | ||
444 | { | ||
445 | //check for errors | ||
446 | glLinkProgramARB(obj); | ||
447 | GLint success = GL_TRUE; | ||
448 | glGetObjectParameterivARB(obj, GL_OBJECT_LINK_STATUS_ARB, &success); | ||
449 | if (!suppress_errors && success == GL_FALSE) | ||
450 | { | ||
451 | //an error occured, print log | ||
452 | LL_WARNS("ShaderLoading") << "GLSL Linker Error:" << LL_ENDL; | ||
453 | } | ||
454 | |||
455 | // NOTE: Removing LL_DARWIN block as it doesn't seem to actually give the correct answer, | ||
456 | // but want it for reference once I move it. | ||
457 | #if 0 | ||
458 | // Force an evaluation of the gl state so the driver can tell if the shader will run in hardware or software | ||
459 | // per Apple's suggestion | ||
460 | glBegin(gGL.mMode); | ||
461 | glEnd(); | ||
462 | |||
463 | // Query whether the shader can or cannot run in hardware | ||
464 | // http://developer.apple.com/qa/qa2007/qa1502.html | ||
465 | long vertexGPUProcessing; | ||
466 | CGLContextObj ctx = CGLGetCurrentContext(); | ||
467 | CGLGetParameter (ctx, kCGLCPGPUVertexProcessing, &vertexGPUProcessing); | ||
468 | long fragmentGPUProcessing; | ||
469 | CGLGetParameter (ctx, kCGLCPGPUFragmentProcessing, &fragmentGPUProcessing); | ||
470 | if (!fragmentGPUProcessing || !vertexGPUProcessing) | ||
471 | { | ||
472 | LL_WARNS("ShaderLoading") << "GLSL Linker: Running in Software:" << LL_ENDL; | ||
473 | success = GL_FALSE; | ||
474 | suppress_errors = FALSE; | ||
475 | } | ||
476 | |||
477 | #else | ||
478 | std::string log = get_object_log(obj); | ||
479 | LLStringUtil::toLower(log); | ||
480 | if (log.find("software") != std::string::npos) | ||
481 | { | ||
482 | LL_WARNS("ShaderLoading") << "GLSL Linker: Running in Software:" << LL_ENDL; | ||
483 | success = GL_FALSE; | ||
484 | suppress_errors = FALSE; | ||
485 | } | ||
486 | #endif | ||
487 | if (!suppress_errors) | ||
488 | { | ||
489 | dumpObjectLog(obj, !success); | ||
490 | } | ||
491 | |||
492 | return success; | ||
493 | } | ||
494 | |||
495 | BOOL LLShaderMgr::validateProgramObject(GLhandleARB obj) | ||
496 | { | ||
497 | //check program validity against current GL | ||
498 | glValidateProgramARB(obj); | ||
499 | GLint success = GL_TRUE; | ||
500 | glGetObjectParameterivARB(obj, GL_OBJECT_VALIDATE_STATUS_ARB, &success); | ||
501 | if (success == GL_FALSE) | ||
502 | { | ||
503 | LL_WARNS("ShaderLoading") << "GLSL program not valid: " << LL_ENDL; | ||
504 | dumpObjectLog(obj); | ||
505 | } | ||
506 | else | ||
507 | { | ||
508 | dumpObjectLog(obj, FALSE); | ||
509 | } | ||
510 | |||
511 | return success; | ||
512 | } | ||
513 | |||
diff --git a/linden/indra/llrender/llshadermgr.h b/linden/indra/llrender/llshadermgr.h new file mode 100644 index 0000000..8918416 --- /dev/null +++ b/linden/indra/llrender/llshadermgr.h | |||
@@ -0,0 +1,75 @@ | |||
1 | /** | ||
2 | * @file llshadermgr.h | ||
3 | * @brief Shader Manager | ||
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_SHADERMGR_H | ||
33 | #define LL_SHADERMGR_H | ||
34 | |||
35 | #include "llgl.h" | ||
36 | #include "llglslshader.h" | ||
37 | |||
38 | class LLShaderMgr | ||
39 | { | ||
40 | public: | ||
41 | LLShaderMgr(); | ||
42 | virtual ~LLShaderMgr(); | ||
43 | |||
44 | // singleton pattern implementation | ||
45 | static LLShaderMgr * instance(); | ||
46 | |||
47 | BOOL attachShaderFeatures(LLGLSLShader * shader); | ||
48 | void dumpObjectLog(GLhandleARB ret, BOOL warns = TRUE); | ||
49 | BOOL linkProgramObject(GLhandleARB obj, BOOL suppress_errors = FALSE); | ||
50 | BOOL validateProgramObject(GLhandleARB obj); | ||
51 | GLhandleARB loadShaderFile(const std::string& filename, S32 & shader_level, GLenum type); | ||
52 | |||
53 | // Implemented in the application to actually point to the shader directory. | ||
54 | virtual std::string getShaderDirPrefix(void) = 0; // Pure Virtual | ||
55 | |||
56 | // Implemented in the application to actually update out of date uniforms for a particular shader | ||
57 | virtual void updateShaderUniforms(LLGLSLShader * shader) = 0; // Pure Virtual | ||
58 | |||
59 | public: | ||
60 | // Map of shader names to compiled | ||
61 | std::map<std::string, GLhandleARB> mShaderObjects; | ||
62 | |||
63 | //global (reserved slot) shader parameters | ||
64 | std::vector<std::string> mReservedAttribs; | ||
65 | |||
66 | std::vector<std::string> mReservedUniforms; | ||
67 | |||
68 | protected: | ||
69 | |||
70 | // our parameter manager singleton instance | ||
71 | static LLShaderMgr * sInstance; | ||
72 | |||
73 | }; //LLShaderMgr | ||
74 | |||
75 | #endif | ||
diff --git a/linden/indra/llrender/llvertexbuffer.cpp b/linden/indra/llrender/llvertexbuffer.cpp index 9635ae3..547663b 100644 --- a/linden/indra/llrender/llvertexbuffer.cpp +++ b/linden/indra/llrender/llvertexbuffer.cpp | |||
@@ -190,10 +190,12 @@ void LLVertexBuffer::drawRange(U32 mode, U32 start, U32 end, U32 count, U32 indi | |||
190 | if (mode > NUM_MODES) | 190 | if (mode > NUM_MODES) |
191 | { | 191 | { |
192 | llerrs << "Invalid draw mode: " << mode << llendl; | 192 | llerrs << "Invalid draw mode: " << mode << llendl; |
193 | return; | ||
193 | } | 194 | } |
194 | 195 | ||
195 | glDrawRangeElements(sGLMode[mode], start, end, count, GL_UNSIGNED_SHORT, | 196 | glDrawRangeElements(sGLMode[mode], start, end, count, GL_UNSIGNED_SHORT, |
196 | ((U16*) getIndicesPointer()) + indices_offset); | 197 | ((U16*) getIndicesPointer()) + indices_offset); |
198 | stop_glerror(); | ||
197 | } | 199 | } |
198 | 200 | ||
199 | void LLVertexBuffer::draw(U32 mode, U32 count, U32 indices_offset) const | 201 | void LLVertexBuffer::draw(U32 mode, U32 count, U32 indices_offset) const |
@@ -217,6 +219,7 @@ void LLVertexBuffer::draw(U32 mode, U32 count, U32 indices_offset) const | |||
217 | if (mode > NUM_MODES) | 219 | if (mode > NUM_MODES) |
218 | { | 220 | { |
219 | llerrs << "Invalid draw mode: " << mode << llendl; | 221 | llerrs << "Invalid draw mode: " << mode << llendl; |
222 | return; | ||
220 | } | 223 | } |
221 | 224 | ||
222 | glDrawElements(sGLMode[mode], count, GL_UNSIGNED_SHORT, | 225 | glDrawElements(sGLMode[mode], count, GL_UNSIGNED_SHORT, |
@@ -240,9 +243,11 @@ void LLVertexBuffer::drawArrays(U32 mode, U32 first, U32 count) const | |||
240 | if (mode > NUM_MODES) | 243 | if (mode > NUM_MODES) |
241 | { | 244 | { |
242 | llerrs << "Invalid draw mode: " << mode << llendl; | 245 | llerrs << "Invalid draw mode: " << mode << llendl; |
246 | return; | ||
243 | } | 247 | } |
244 | 248 | ||
245 | glDrawArrays(sGLMode[mode], first, count); | 249 | glDrawArrays(sGLMode[mode], first, count); |
250 | stop_glerror(); | ||
246 | } | 251 | } |
247 | 252 | ||
248 | //static | 253 | //static |
diff --git a/linden/indra/llrender/llvertexbuffer.h b/linden/indra/llrender/llvertexbuffer.h index 64a6f60..8edcf69 100644 --- a/linden/indra/llrender/llvertexbuffer.h +++ b/linden/indra/llrender/llvertexbuffer.h | |||
@@ -41,6 +41,7 @@ | |||
41 | #include "llmemory.h" | 41 | #include "llmemory.h" |
42 | #include <set> | 42 | #include <set> |
43 | #include <vector> | 43 | #include <vector> |
44 | #include <list> | ||
44 | 45 | ||
45 | //============================================================================ | 46 | //============================================================================ |
46 | // NOTES | 47 | // NOTES |