aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/lldrawpoolterrain.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/lldrawpoolterrain.cpp
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/newview/lldrawpoolterrain.cpp')
-rw-r--r--linden/indra/newview/lldrawpoolterrain.cpp1110
1 files changed, 1110 insertions, 0 deletions
diff --git a/linden/indra/newview/lldrawpoolterrain.cpp b/linden/indra/newview/lldrawpoolterrain.cpp
new file mode 100644
index 0000000..1390fc9
--- /dev/null
+++ b/linden/indra/newview/lldrawpoolterrain.cpp
@@ -0,0 +1,1110 @@
1/**
2 * @file lldrawpoolterrain.cpp
3 * @brief LLDrawPoolTerrain class implementation
4 *
5 * Copyright (c) 2002-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28#include "llviewerprecompiledheaders.h"
29
30#include "lldrawpoolterrain.h"
31
32#include "llfasttimer.h"
33
34#include "llagent.h"
35#include "llagparray.h"
36#include "llviewercontrol.h"
37#include "lldrawable.h"
38#include "llface.h"
39#include "llsky.h"
40#include "llsurface.h"
41#include "llsurfacepatch.h"
42#include "llviewerregion.h"
43#include "llvlcomposition.h"
44#include "llviewerparcelmgr.h" // for gRenderParcelOwnership
45#include "llviewerparceloverlay.h"
46#include "llvosurfacepatch.h"
47#include "llviewercamera.h"
48#include "llviewerimagelist.h" // To get alpha gradients
49#include "llworld.h"
50#include "pipeline.h"
51
52const F32 DETAIL_SCALE = 1.f/16.f;
53int DebugDetailMap = 0;
54
55S32 LLDrawPoolTerrain::sDetailMode = 1;
56F32 LLDrawPoolTerrain::sDetailScale = DETAIL_SCALE;
57
58LLDrawPoolTerrain::LLDrawPoolTerrain(LLViewerImage *texturep) :
59 LLDrawPool(POOL_TERRAIN, DATA_SIMPLE_IL_MASK | DATA_COLORS_MASK | DATA_TEX_COORDS1_MASK, DATA_SIMPLE_NIL_MASK),
60 mTexturep(texturep)
61{
62 // Hack!
63 sDetailScale = 1.f/gSavedSettings.getF32("RenderTerrainScale");
64 sDetailMode = gSavedSettings.getS32("RenderTerrainDetail");
65 mAlphaRampImagep = gImageList.getImageFromUUID(LLUUID(gViewerArt.getString("alpha_gradient.tga")),
66 TRUE, TRUE, GL_ALPHA8, GL_ALPHA);
67 mAlphaRampImagep->bind(0);
68 mAlphaRampImagep->setClamp(TRUE, TRUE);
69
70 m2DAlphaRampImagep = gImageList.getImageFromUUID(LLUUID(gViewerArt.getString("alpha_gradient_2d.tga")),
71 TRUE, TRUE, GL_ALPHA8, GL_ALPHA);
72 m2DAlphaRampImagep->bind(0);
73 m2DAlphaRampImagep->setClamp(TRUE, TRUE);
74
75 mTexturep->setBoostLevel(LLViewerImage::BOOST_TERRAIN);
76
77 LLImageGL::unbindTexture(0, GL_TEXTURE_2D);
78}
79
80LLDrawPoolTerrain::~LLDrawPoolTerrain()
81{
82 llassert( gPipeline.findPool( getType(), getTexture() ) == NULL );
83}
84
85
86LLDrawPool *LLDrawPoolTerrain::instancePool()
87{
88 return new LLDrawPoolTerrain(mTexturep);
89}
90
91
92void LLDrawPoolTerrain::prerender()
93{
94#if 0 // 1.9.2
95 mVertexShaderLevel = gPipeline.getVertexShaderLevel(LLPipeline::SHADER_ENVIRONMENT);
96#endif
97}
98
99void LLDrawPoolTerrain::render(S32 pass)
100{
101 LLFastTimer t(LLFastTimer::FTM_RENDER_TERRAIN);
102
103 if (mDrawFace.empty())
104 {
105 return;
106 }
107
108 if (!gGLManager.mHasMultitexture)
109 {
110 // No mulititexture, render simple land.
111 renderSimple(); // Render without multitexture
112 return;
113 }
114 // Render simplified land if video card can't do sufficient multitexturing
115 if (!gGLManager.mHasARBEnvCombine || (gGLManager.mNumTextureUnits < 2))
116 {
117 renderSimple(); // Render without multitexture
118 return;
119 }
120
121 LLGLSPipeline gls;
122 LLOverrideFaceColor override(this, 1.f, 1.f, 1.f, 1.f);
123
124 if (mVertexShaderLevel > 0)
125 {
126 gPipeline.enableLightsDynamic(1.f);
127 renderFull4TUShader();
128 }
129 else
130 {
131 gPipeline.enableLightsStatic(1.f);
132 switch (sDetailMode)
133 {
134 case 0:
135 renderSimple();
136 break;
137 default:
138 if (gGLManager.mNumTextureUnits < 4)
139 {
140 renderFull2TU();
141 }
142 else
143 {
144 renderFull4TU();
145 }
146 break;
147 }
148 }
149
150 // Special-case for land ownership feedback
151 if (gSavedSettings.getBOOL("ShowParcelOwners"))
152 {
153 gPipeline.disableLights();
154 if ((mVertexShaderLevel > 0))
155 {
156 gPipeline.mHighlightProgram.bind();
157 gPipeline.mHighlightProgram.vertexAttrib4f(LLPipeline::GLSL_MATERIAL_COLOR,1,1,1,1);
158 renderOwnership();
159 gPipeline.mTerrainProgram.bind();
160 }
161 else
162 {
163 renderOwnership();
164 }
165 }
166}
167
168
169void LLDrawPoolTerrain::renderFull4TUShader()
170{
171 glEnableClientState(GL_VERTEX_ARRAY);
172 glEnableClientState(GL_NORMAL_ARRAY);
173
174 bindGLVertexPointer();
175 bindGLNormalPointer();
176 if (gPipeline.getLightingDetail() >= 2)
177 {
178 glEnableClientState(GL_COLOR_ARRAY);
179 bindGLColorPointer();
180 }
181
182 glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA);
183
184 // Hack! Get the region that this draw pool is rendering from!
185 LLViewerRegion *regionp = mDrawFace[0]->getDrawable()->getVObj()->getRegion();
186 LLVLComposition *compp = regionp->getComposition();
187 for (S32 i = 0; i < 4; i++)
188 {
189 compp->mDetailTextures[i]->setBoostLevel(LLViewerImage::BOOST_TERRAIN);
190 compp->mDetailTextures[i]->addTextureStats(1024.f*1024.f); // assume large pixel area
191 }
192
193 LLViewerImage *detail_texture0p = compp->mDetailTextures[0];
194 LLViewerImage *detail_texture1p = compp->mDetailTextures[1];
195 LLViewerImage *detail_texture2p = compp->mDetailTextures[2];
196 LLViewerImage *detail_texture3p = compp->mDetailTextures[3];
197
198 static F32 dp = 0.f;
199 static LLFrameTimer timer;
200 dp += timer.getElapsedTimeAndResetF32();
201
202 LLVector3d region_origin_global = gAgent.getRegion()->getOriginGlobal();
203
204 F32 offset_x = (F32)fmod(region_origin_global.mdV[VX], 1.0/(F64)sDetailScale)*sDetailScale;
205 F32 offset_y = (F32)fmod(region_origin_global.mdV[VY], 1.0/(F64)sDetailScale)*sDetailScale;
206
207 LLVector4 tp0, tp1;
208
209 tp0.setVec(sDetailScale, 0.0f, 0.0f, offset_x);
210 tp1.setVec(0.0f, sDetailScale, 0.0f, offset_y);
211
212 //----------------------------------------------------------------------------
213 // Pass 1/1
214
215 //
216 // Stage 0: detail texture 0
217 //
218
219 S32 detailTex0 = gPipeline.mTerrainProgram.enableTexture(LLPipeline::GLSL_TERRAIN_DETAIL0);
220 S32 detailTex1 = gPipeline.mTerrainProgram.enableTexture(LLPipeline::GLSL_TERRAIN_DETAIL1);
221 S32 rampTex = gPipeline.mTerrainProgram.enableTexture(LLPipeline::GLSL_TERRAIN_ALPHARAMP);
222 S32 scatterTex = gPipeline.mTerrainProgram.enableTexture(LLPipeline::GLSL_SCATTER_MAP);
223
224 LLViewerImage::bindTexture(detail_texture0p,detailTex0);
225
226 glClientActiveTextureARB(GL_TEXTURE0_ARB);
227 glActiveTextureARB(GL_TEXTURE0_ARB);
228 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
229 glEnable(GL_TEXTURE_GEN_S);
230 glEnable(GL_TEXTURE_GEN_T);
231 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
232 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
233
234 glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV);
235 glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV);
236
237 //
238 // Stage 1: Generate alpha ramp for detail0/detail1 transition
239 //
240 LLViewerImage::bindTexture(m2DAlphaRampImagep,rampTex);
241
242 glClientActiveTextureARB(GL_TEXTURE1_ARB);
243 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
244 bindGLTexCoordPointer(1);
245
246 //
247 // Stage 2: Interpolate detail1 with existing based on ramp
248 //
249 LLViewerImage::bindTexture(detail_texture1p,detailTex1);
250
251 glClientActiveTextureARB(GL_TEXTURE2_ARB);
252 glActiveTextureARB(GL_TEXTURE2_ARB);
253 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
254 glEnable(GL_TEXTURE_GEN_S);
255 glEnable(GL_TEXTURE_GEN_T);
256 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
257 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
258 glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV);
259 glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV);
260
261 // Stage 4: Haze
262 LLViewerImage::bindTexture(gSky.mVOSkyp->getScatterMap(), scatterTex);
263
264 //
265 // Stage 3: Modulate with primary color for lighting
266 //
267 //LLViewerImage::bindTexture(detail_texture1p,3); // bind any texture
268 //glEnable(GL_TEXTURE_2D); // Texture unit 3
269 glClientActiveTextureARB(GL_TEXTURE3_ARB);
270 glActiveTextureARB(GL_TEXTURE3_ARB);
271 // GL_BLEND disabled by default
272 drawLoop();
273
274 //----------------------------------------------------------------------------
275 // Second pass
276
277 //
278 // Stage 0: Write detail3 into base
279 //
280 LLViewerImage::bindTexture(detail_texture2p,detailTex0);
281
282 glClientActiveTextureARB(GL_TEXTURE0_ARB);
283 glActiveTextureARB(GL_TEXTURE0_ARB);
284 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
285 glEnable(GL_TEXTURE_GEN_S);
286 glEnable(GL_TEXTURE_GEN_T);
287 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
288 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
289 glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV);
290 glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV);
291
292 //
293 // Stage 1: Generate alpha ramp for detail2/detail3 transition
294 //
295 LLViewerImage::bindTexture(m2DAlphaRampImagep,rampTex);
296
297 glClientActiveTextureARB(GL_TEXTURE1_ARB);
298 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
299 glActiveTextureARB(GL_TEXTURE1_ARB);
300 bindGLTexCoordPointer(1);
301
302 // Set the texture matrix
303 glMatrixMode(GL_TEXTURE);
304 glLoadIdentity();
305 glTranslatef(-2.f, 0.f, 0.f);
306
307 //
308 // Stage 2: Interpolate detail2 with existing based on ramp
309 //
310 LLViewerImage::bindTexture(detail_texture3p,detailTex1);
311
312 glClientActiveTextureARB(GL_TEXTURE2_ARB);
313 glActiveTextureARB(GL_TEXTURE2_ARB);
314 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
315 glEnable(GL_TEXTURE_GEN_S);
316 glEnable(GL_TEXTURE_GEN_T);
317 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
318 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
319 glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV);
320 glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV);
321
322 //
323 // Stage 3: Generate alpha ramp for detail1/detail2 transition
324 //
325 //LLViewerImage::bindTexture(m2DAlphaRampImagep,3);
326
327 //glEnable(GL_TEXTURE_2D); // Texture unit 3
328
329 glClientActiveTextureARB(GL_TEXTURE3_ARB);
330 glActiveTextureARB(GL_TEXTURE3_ARB);
331 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
332 bindGLTexCoordPointer(1);
333
334 // Set the texture matrix
335 glMatrixMode(GL_TEXTURE);
336 glLoadIdentity();
337 glTranslatef(-1.f, 0.f, 0.f);
338
339 {
340 LLGLEnable blend(GL_BLEND);
341 drawLoop();
342 }
343
344 // Disable multitexture
345 gPipeline.mTerrainProgram.disableTexture(LLPipeline::GLSL_SCATTER_MAP);
346 gPipeline.mTerrainProgram.disableTexture(LLPipeline::GLSL_TERRAIN_ALPHARAMP);
347 gPipeline.mTerrainProgram.disableTexture(LLPipeline::GLSL_TERRAIN_DETAIL0);
348 gPipeline.mTerrainProgram.disableTexture(LLPipeline::GLSL_TERRAIN_DETAIL1);
349
350 glClientActiveTextureARB(GL_TEXTURE3_ARB);
351 glActiveTextureARB(GL_TEXTURE3_ARB);
352 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
353 glMatrixMode(GL_TEXTURE);
354 glLoadIdentity();
355 glMatrixMode(GL_MODELVIEW);
356
357 glClientActiveTextureARB(GL_TEXTURE2_ARB);
358 glActiveTextureARB(GL_TEXTURE2_ARB);
359 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
360 glDisable(GL_TEXTURE_GEN_S);
361 glDisable(GL_TEXTURE_GEN_T);
362 glMatrixMode(GL_TEXTURE);
363 glLoadIdentity();
364 glMatrixMode(GL_MODELVIEW);
365
366 glClientActiveTextureARB(GL_TEXTURE1_ARB);
367 glActiveTextureARB(GL_TEXTURE1_ARB);
368 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
369 glMatrixMode(GL_TEXTURE);
370 glLoadIdentity();
371 glMatrixMode(GL_MODELVIEW);
372
373 // Restore blend state
374 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
375
376 //----------------------------------------------------------------------------
377 // Restore Texture Unit 0 defaults
378
379 glClientActiveTextureARB(GL_TEXTURE0_ARB);
380 glActiveTextureARB(GL_TEXTURE0_ARB);
381 glDisable(GL_TEXTURE_GEN_S);
382 glDisable(GL_TEXTURE_GEN_T);
383 glEnable(GL_TEXTURE_2D);
384 glMatrixMode(GL_TEXTURE);
385 glLoadIdentity();
386 glMatrixMode(GL_MODELVIEW);
387
388 // Restore non Texture Unit specific defaults
389 glDisableClientState(GL_NORMAL_ARRAY);
390 glDisableClientState(GL_COLOR_ARRAY);
391 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
392}
393
394void LLDrawPoolTerrain::renderFull4TU()
395{
396 glEnableClientState(GL_VERTEX_ARRAY);
397 glEnableClientState(GL_NORMAL_ARRAY);
398
399 bindGLVertexPointer();
400 bindGLNormalPointer();
401
402 // Hack! Get the region that this draw pool is rendering from!
403 LLViewerRegion *regionp = mDrawFace[0]->getDrawable()->getVObj()->getRegion();
404 LLVLComposition *compp = regionp->getComposition();
405 for (S32 i = 0; i < 4; i++)
406 {
407 compp->mDetailTextures[i]->setBoostLevel(LLViewerImage::BOOST_TERRAIN);
408 compp->mDetailTextures[i]->addTextureStats(1024.f*1024.f); // assume large pixel area
409 }
410
411 LLViewerImage *detail_texture0p = compp->mDetailTextures[0];
412 LLViewerImage *detail_texture1p = compp->mDetailTextures[1];
413 LLViewerImage *detail_texture2p = compp->mDetailTextures[2];
414 LLViewerImage *detail_texture3p = compp->mDetailTextures[3];
415
416 LLVector3d region_origin_global = gAgent.getRegion()->getOriginGlobal();
417 F32 offset_x = (F32)fmod(region_origin_global.mdV[VX], 1.0/(F64)sDetailScale)*sDetailScale;
418 F32 offset_y = (F32)fmod(region_origin_global.mdV[VY], 1.0/(F64)sDetailScale)*sDetailScale;
419
420 LLVector4 tp0, tp1;
421
422 tp0.setVec(sDetailScale, 0.0f, 0.0f, offset_x);
423 tp1.setVec(0.0f, sDetailScale, 0.0f, offset_y);
424
425 glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA);
426
427 //----------------------------------------------------------------------------
428 // Pass 1/1
429
430 //
431 // Stage 0: detail texture 0
432 //
433 LLViewerImage::bindTexture(detail_texture0p,0);
434 glClientActiveTextureARB(GL_TEXTURE0_ARB);
435
436 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
437 glEnable(GL_TEXTURE_GEN_S);
438 glEnable(GL_TEXTURE_GEN_T);
439 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
440 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
441
442 glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV);
443 glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV);
444
445 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
446 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE);
447
448 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
449 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
450
451 //
452 // Stage 1: Generate alpha ramp for detail0/detail1 transition
453 //
454 LLViewerImage::bindTexture(m2DAlphaRampImagep,1);
455
456 glEnable(GL_TEXTURE_2D); // Texture unit 1
457 glClientActiveTextureARB(GL_TEXTURE1_ARB);
458 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
459 bindGLTexCoordPointer(1);
460
461 // Care about alpha only
462 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
463 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE);
464 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
465
466 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS);
467 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
468 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);
469 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
470
471 //
472 // Stage 2: Interpolate detail1 with existing based on ramp
473 //
474 LLViewerImage::bindTexture(detail_texture1p,2);
475 glEnable(GL_TEXTURE_2D); // Texture unit 2
476 glClientActiveTextureARB(GL_TEXTURE2_ARB);
477
478 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
479 glEnable(GL_TEXTURE_GEN_S);
480 glEnable(GL_TEXTURE_GEN_T);
481 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
482 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
483 glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV);
484 glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV);
485
486 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
487 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_INTERPOLATE);
488
489 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
490 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
491 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
492 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
493 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, GL_PREVIOUS_ARB);
494 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_SRC_ALPHA);
495
496 //
497 // Stage 3: Modulate with primary (vertex) color for lighting
498 //
499 LLViewerImage::bindTexture(detail_texture1p,3); // bind any texture
500 glEnable(GL_TEXTURE_2D); // Texture unit 3
501 glClientActiveTextureARB(GL_TEXTURE3_ARB);
502
503 // Set alpha texture and do lighting modulation
504 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
505 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
506
507 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS);
508 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
509 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PRIMARY_COLOR_ARB);
510 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
511
512 // GL_BLEND disabled by default
513 drawLoop();
514
515 //----------------------------------------------------------------------------
516 // Second pass
517
518 // Stage 0: Write detail3 into base
519 //
520 LLViewerImage::bindTexture(detail_texture3p,0);
521 glClientActiveTextureARB(GL_TEXTURE0_ARB);
522
523 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
524 glEnable(GL_TEXTURE_GEN_S);
525 glEnable(GL_TEXTURE_GEN_T);
526 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
527 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
528 glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV);
529 glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV);
530
531 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
532 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE);
533
534 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
535 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
536
537
538 //
539 // Stage 1: Generate alpha ramp for detail2/detail3 transition
540 //
541 LLViewerImage::bindTexture(m2DAlphaRampImagep,1);
542
543 glEnable(GL_TEXTURE_2D); // Texture unit 1
544 glClientActiveTextureARB(GL_TEXTURE1_ARB);
545
546 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
547 bindGLTexCoordPointer(1);
548
549
550 // Set the texture matrix
551 glMatrixMode(GL_TEXTURE);
552 glLoadIdentity();
553 glTranslatef(-2.f, 0.f, 0.f);
554
555 // Care about alpha only
556 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
557 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE);
558 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
559
560 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS);
561 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
562 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);
563 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
564
565
566 //
567 // Stage 2: Interpolate detail2 with existing based on ramp
568 //
569 LLViewerImage::bindTexture(detail_texture2p,2);
570 glEnable(GL_TEXTURE_2D); // Texture unit 2
571 glClientActiveTextureARB(GL_TEXTURE2_ARB);
572
573 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
574 glEnable(GL_TEXTURE_GEN_S);
575 glEnable(GL_TEXTURE_GEN_T);
576 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
577 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
578 glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV);
579 glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV);
580
581 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
582 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_INTERPOLATE);
583
584 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
585 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
586 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
587 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
588 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, GL_PREVIOUS_ARB);
589 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_ONE_MINUS_SRC_ALPHA);
590
591
592 //
593 // Stage 3: Generate alpha ramp for detail1/detail2 transition
594 //
595 LLViewerImage::bindTexture(m2DAlphaRampImagep,3);
596
597 glEnable(GL_TEXTURE_2D); // Texture unit 3
598 glClientActiveTextureARB(GL_TEXTURE3_ARB);
599
600 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
601 bindGLTexCoordPointer(1);
602
603 // Set the texture matrix
604 glMatrixMode(GL_TEXTURE);
605 glLoadIdentity();
606 glTranslatef(-1.f, 0.f, 0.f);
607
608 // Set alpha texture and do lighting modulation
609 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
610 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
611 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
612
613 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS);
614 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
615 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PRIMARY_COLOR_ARB);
616 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
617 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);
618 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
619
620
621 {
622 LLGLEnable blend(GL_BLEND);
623 drawLoop();
624 }
625
626 // Disable multitexture
627 LLImageGL::unbindTexture(3, GL_TEXTURE_2D);
628 glClientActiveTextureARB(GL_TEXTURE3_ARB);
629 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
630 glDisable(GL_TEXTURE_2D); // Texture unit 3
631 glMatrixMode(GL_TEXTURE);
632 glLoadIdentity();
633 glMatrixMode(GL_MODELVIEW);
634
635 LLImageGL::unbindTexture(2, GL_TEXTURE_2D);
636 glClientActiveTextureARB(GL_TEXTURE2_ARB);
637 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
638 glDisable(GL_TEXTURE_2D); // Texture unit 2
639 glDisable(GL_TEXTURE_GEN_S);
640 glDisable(GL_TEXTURE_GEN_T);
641 glMatrixMode(GL_TEXTURE);
642 glLoadIdentity();
643 glMatrixMode(GL_MODELVIEW);
644
645 LLImageGL::unbindTexture(1, GL_TEXTURE_2D);
646 glClientActiveTextureARB(GL_TEXTURE1_ARB);
647 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
648 glDisable(GL_TEXTURE_2D); // Texture unit 1
649 glMatrixMode(GL_TEXTURE);
650 glLoadIdentity();
651 glMatrixMode(GL_MODELVIEW);
652
653 // Restore blend state
654 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
655
656 //----------------------------------------------------------------------------
657 // Restore Texture Unit 0 defaults
658
659 LLImageGL::unbindTexture(0, GL_TEXTURE_2D);
660 glClientActiveTextureARB(GL_TEXTURE0_ARB);
661 glActiveTextureARB(GL_TEXTURE0_ARB);
662 glDisable(GL_TEXTURE_GEN_S);
663 glDisable(GL_TEXTURE_GEN_T);
664 glMatrixMode(GL_TEXTURE);
665 glLoadIdentity();
666 glMatrixMode(GL_MODELVIEW);
667
668 // Restore non Texture Unit specific defaults
669 glDisableClientState(GL_NORMAL_ARRAY);
670 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
671}
672
673void LLDrawPoolTerrain::renderFull2TU()
674{
675 glEnableClientState(GL_VERTEX_ARRAY);
676 glEnableClientState(GL_NORMAL_ARRAY);
677
678 bindGLVertexPointer();
679 bindGLNormalPointer();
680
681 // Hack! Get the region that this draw pool is rendering from!
682 LLViewerRegion *regionp = mDrawFace[0]->getDrawable()->getVObj()->getRegion();
683 LLVLComposition *compp = regionp->getComposition();
684 for (S32 i = 0; i < 4; i++)
685 {
686 compp->mDetailTextures[i]->setBoostLevel(LLViewerImage::BOOST_TERRAIN);
687 compp->mDetailTextures[i]->addTextureStats(1024.f*1024.f); // assume large pixel area
688 }
689
690 LLViewerImage *detail_texture0p = compp->mDetailTextures[0];
691 LLViewerImage *detail_texture1p = compp->mDetailTextures[1];
692 LLViewerImage *detail_texture2p = compp->mDetailTextures[2];
693 LLViewerImage *detail_texture3p = compp->mDetailTextures[3];
694
695 LLVector3d region_origin_global = gAgent.getRegion()->getOriginGlobal();
696 F32 offset_x = (F32)fmod(region_origin_global.mdV[VX], 1.0/(F64)sDetailScale)*sDetailScale;
697 F32 offset_y = (F32)fmod(region_origin_global.mdV[VY], 1.0/(F64)sDetailScale)*sDetailScale;
698
699 LLVector4 tp0, tp1;
700
701 tp0.setVec(sDetailScale, 0.0f, 0.0f, offset_x);
702 tp1.setVec(0.0f, sDetailScale, 0.0f, offset_y);
703
704 glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA);
705
706 //----------------------------------------------------------------------------
707 // Pass 1/4
708
709 //
710 // Stage 0: Render detail 0 into base
711 //
712 LLViewerImage::bindTexture(detail_texture0p,0);
713 glClientActiveTextureARB(GL_TEXTURE0_ARB);
714
715 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
716 glEnable(GL_TEXTURE_GEN_S);
717 glEnable(GL_TEXTURE_GEN_T);
718 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
719 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
720
721 glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV);
722 glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV);
723
724 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
725 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
726
727 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
728 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
729 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PRIMARY_COLOR_ARB);
730 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
731
732 drawLoop();
733
734 //----------------------------------------------------------------------------
735 // Pass 2/4
736
737 //
738 // Stage 0: Generate alpha ramp for detail0/detail1 transition
739 //
740 LLViewerImage::bindTexture(m2DAlphaRampImagep,0);
741 glClientActiveTextureARB(GL_TEXTURE0_ARB);
742
743 glDisable(GL_TEXTURE_GEN_S);
744 glDisable(GL_TEXTURE_GEN_T);
745 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
746 bindGLTexCoordPointer(1);
747
748 // Care about alpha only
749 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
750 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE);
751 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
752
753 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS);
754 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
755 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);
756 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
757
758
759 //
760 // Stage 1: Write detail1
761 //
762 LLViewerImage::bindTexture(detail_texture1p,1); // Texture unit 1
763 glEnable(GL_TEXTURE_2D); // Texture unit 1
764 glClientActiveTextureARB(GL_TEXTURE1_ARB);
765
766 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
767 glEnable(GL_TEXTURE_GEN_S);
768 glEnable(GL_TEXTURE_GEN_T);
769 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
770 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
771 glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV);
772 glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV);
773
774 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
775 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
776 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
777
778 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
779 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
780 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PRIMARY_COLOR_ARB);
781 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
782 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PREVIOUS);
783 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
784
785 {
786 LLGLEnable blend(GL_BLEND);
787 drawLoop();
788 }
789 //----------------------------------------------------------------------------
790 // Pass 3/4
791
792 //
793 // Stage 0: Generate alpha ramp for detail1/detail2 transition
794 //
795 LLViewerImage::bindTexture(m2DAlphaRampImagep,0);
796 glClientActiveTextureARB(GL_TEXTURE0_ARB);
797 // Set the texture matrix
798 glMatrixMode(GL_TEXTURE);
799 glLoadIdentity();
800 glTranslatef(-1.f, 0.f, 0.f);
801
802 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
803 bindGLTexCoordPointer(1);
804
805 // Care about alpha only
806 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
807 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE);
808 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
809
810 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS);
811 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
812 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);
813 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
814
815 //
816 // Stage 1: Write detail2
817 //
818
819 LLViewerImage::bindTexture(detail_texture2p,1);
820 glEnable(GL_TEXTURE_2D); // Texture unit 1
821 glClientActiveTextureARB(GL_TEXTURE1_ARB);
822
823 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
824 glEnable(GL_TEXTURE_GEN_S);
825 glEnable(GL_TEXTURE_GEN_T);
826 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
827 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
828 glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV);
829 glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV);
830
831 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
832 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
833 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
834
835 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
836 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
837 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PRIMARY_COLOR_ARB);
838 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
839 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PREVIOUS);
840 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
841
842 {
843 LLGLEnable blend(GL_BLEND);
844 drawLoop();
845 }
846
847 //----------------------------------------------------------------------------
848 // Pass 4/4
849
850 //
851 // Stage 0: Generate alpha ramp for detail2/detail3 transition
852 //
853 LLViewerImage::bindTexture(m2DAlphaRampImagep,0);
854 glClientActiveTextureARB(GL_TEXTURE0_ARB);
855 // Set the texture matrix
856 glMatrixMode(GL_TEXTURE);
857 glLoadIdentity();
858 glTranslatef(-2.f, 0.f, 0.f);
859
860 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
861 bindGLTexCoordPointer(1);
862
863 // Care about alpha only
864 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
865 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE);
866 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
867
868 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS);
869 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
870 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);
871 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
872
873 // Stage 1: Write detail3
874
875 LLViewerImage::bindTexture(detail_texture3p,1);
876 glEnable(GL_TEXTURE_2D); // Texture unit 1
877 glClientActiveTextureARB(GL_TEXTURE1_ARB);
878
879 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
880 glEnable(GL_TEXTURE_GEN_S);
881 glEnable(GL_TEXTURE_GEN_T);
882 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
883 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
884 glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV);
885 glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV);
886
887 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
888 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
889 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
890
891 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
892 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
893 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PRIMARY_COLOR_ARB);
894 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
895 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PREVIOUS);
896 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
897
898 {
899 LLGLEnable blend(GL_BLEND);
900 drawLoop();
901 }
902
903 // Restore blend state
904 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
905
906 // Disable multitexture
907 LLImageGL::unbindTexture(1, GL_TEXTURE_2D);
908 glClientActiveTextureARB(GL_TEXTURE1_ARB);
909 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
910 glDisable(GL_TEXTURE_2D); // Texture unit 1
911 glDisable(GL_TEXTURE_GEN_S);
912 glDisable(GL_TEXTURE_GEN_T);
913 glMatrixMode(GL_TEXTURE);
914 glLoadIdentity();
915 glMatrixMode(GL_MODELVIEW);
916
917 //----------------------------------------------------------------------------
918 // Restore Texture Unit 0 defaults
919
920 LLImageGL::unbindTexture(0, GL_TEXTURE_2D);
921
922 glClientActiveTextureARB(GL_TEXTURE0_ARB);
923 glActiveTextureARB(GL_TEXTURE0_ARB);
924 glDisable(GL_TEXTURE_GEN_S);
925 glDisable(GL_TEXTURE_GEN_T);
926 glMatrixMode(GL_TEXTURE);
927 glLoadIdentity();
928 glMatrixMode(GL_MODELVIEW);
929
930 // Restore non Texture Unit specific defaults
931 glDisableClientState(GL_NORMAL_ARRAY);
932 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
933}
934
935
936void LLDrawPoolTerrain::renderSimple()
937{
938 glEnableClientState(GL_VERTEX_ARRAY);
939 glEnableClientState(GL_NORMAL_ARRAY);
940
941 bindGLVertexPointer();
942 bindGLNormalPointer();
943
944 LLVector4 tp0, tp1;
945
946 //----------------------------------------------------------------------------
947 // Pass 1/1
948
949 // Stage 0: Base terrain texture pass
950 mTexturep->addTextureStats(1024.f*1024.f);
951 mTexturep->bind(0);
952
953 glActiveTextureARB(GL_TEXTURE0_ARB);
954 glEnable(GL_TEXTURE_2D); // Texture unit 2
955 glClientActiveTextureARB(GL_TEXTURE0_ARB);
956
957 LLVector3 origin_agent = mDrawFace[0]->getDrawable()->getVObj()->getRegion()->getOriginAgent();
958 F32 tscale = 1.f/256.f;
959 tp0.setVec(tscale, 0.f, 0.0f, -1.f*(origin_agent.mV[0]/256.f));
960 tp1.setVec(0.f, tscale, 0.0f, -1.f*(origin_agent.mV[1]/256.f));
961
962 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
963 glEnable(GL_TEXTURE_GEN_S);
964 glEnable(GL_TEXTURE_GEN_T);
965 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
966 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
967 glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV);
968 glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV);
969
970 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
971 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
972
973 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
974 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
975 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PRIMARY_COLOR_ARB);
976 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
977
978 drawLoop();
979
980 //----------------------------------------------------------------------------
981 // Restore Texture Unit 0 defaults
982
983 LLImageGL::unbindTexture(0, GL_TEXTURE_2D);
984 glClientActiveTextureARB(GL_TEXTURE0_ARB);
985 glActiveTextureARB(GL_TEXTURE0_ARB);
986 glDisable(GL_TEXTURE_GEN_S);
987 glDisable(GL_TEXTURE_GEN_T);
988 glMatrixMode(GL_TEXTURE);
989 glLoadIdentity();
990 glMatrixMode(GL_MODELVIEW);
991
992 // Restore non Texture Unit specific defaults
993 glDisableClientState(GL_NORMAL_ARRAY);
994 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
995}
996
997//============================================================================
998
999void LLDrawPoolTerrain::renderOwnership()
1000{
1001 LLGLSPipelineAlpha gls_pipeline_alpha;
1002
1003 llassert(!mDrawFace.empty());
1004
1005 // Each terrain pool is associated with a single region.
1006 // We need to peek back into the viewer's data to find out
1007 // which ownership overlay texture to use.
1008 LLFace *facep = mDrawFace[0];
1009 LLDrawable *drawablep = facep->getDrawable();
1010 const LLViewerObject *objectp = drawablep->getVObj();
1011 const LLVOSurfacePatch *vo_surface_patchp = (LLVOSurfacePatch *)objectp;
1012 LLSurfacePatch *surface_patchp = vo_surface_patchp->getPatch();
1013 LLSurface *surfacep = surface_patchp->getSurface();
1014 LLViewerRegion *regionp = surfacep->getRegion();
1015 LLViewerParcelOverlay *overlayp = regionp->getParcelOverlay();
1016 LLImageGL *texturep = overlayp->getTexture();
1017
1018 glEnableClientState(GL_VERTEX_ARRAY);
1019 glDisableClientState(GL_NORMAL_ARRAY);
1020
1021 bindGLVertexPointer();
1022 bindGLTexCoordPointer(0);
1023
1024 LLViewerImage::bindTexture(texturep);
1025
1026 glClientActiveTextureARB(GL_TEXTURE0_ARB);
1027 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
1028
1029 // *NOTE: Because the region is 256 meters wide, but has 257 pixels, the
1030 // texture coordinates for pixel 256x256 is not 1,1. This makes the
1031 // ownership map not line up with the selection. We address this with
1032 // a texture matrix multiply.
1033 glMatrixMode(GL_TEXTURE);
1034 glPushMatrix();
1035
1036 const F32 TEXTURE_FUDGE = 257.f / 256.f;
1037 glScalef( TEXTURE_FUDGE, TEXTURE_FUDGE, 1.f );
1038
1039 const U32* index_array = getRawIndices();
1040 for (std::vector<LLFace*>::iterator iter = mDrawFace.begin();
1041 iter != mDrawFace.end(); iter++)
1042 {
1043 LLFace *facep = *iter;
1044 facep->renderIndexed(index_array);
1045 }
1046
1047 glMatrixMode(GL_TEXTURE);
1048 glPopMatrix();
1049 glMatrixMode(GL_MODELVIEW);
1050
1051 // Restore non Texture Unit specific defaults
1052 glDisableClientState(GL_NORMAL_ARRAY);
1053}
1054
1055
1056void LLDrawPoolTerrain::renderForSelect()
1057{
1058 if (mDrawFace.empty() || !mMemory.count())
1059 {
1060 return;
1061 }
1062
1063 glEnableClientState ( GL_VERTEX_ARRAY );
1064
1065 bindGLVertexPointer();
1066
1067 for (std::vector<LLFace*>::iterator iter = mDrawFace.begin();
1068 iter != mDrawFace.end(); iter++)
1069 {
1070 LLFace *facep = *iter;
1071 if (!facep->getDrawable()->isDead() && (facep->getDrawable()->getVObj()->mGLName))
1072 {
1073 facep->renderForSelect();
1074 }
1075 }
1076}
1077
1078void LLDrawPoolTerrain::dirtyTexture(const LLViewerImage *texturep)
1079{
1080 if (mTexturep == texturep)
1081 {
1082 for (std::vector<LLFace*>::iterator iter = mReferences.begin();
1083 iter != mReferences.end(); iter++)
1084 {
1085 LLFace *facep = *iter;
1086 gPipeline.markTextured(facep->getDrawable());
1087 }
1088 }
1089}
1090
1091LLViewerImage *LLDrawPoolTerrain::getTexture()
1092{
1093 return mTexturep;
1094}
1095
1096LLViewerImage *LLDrawPoolTerrain::getDebugTexture()
1097{
1098 return mTexturep;
1099}
1100
1101
1102LLColor3 LLDrawPoolTerrain::getDebugColor() const
1103{
1104 return LLColor3(0.f, 0.f, 1.f);
1105}
1106
1107S32 LLDrawPoolTerrain::getMaterialAttribIndex()
1108{
1109 return gPipeline.mTerrainProgram.mAttribute[LLPipeline::GLSL_MATERIAL_COLOR];
1110}