aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/lldrawpoolalpha.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:45:34 -0500
committerJacek Antonelli2008-08-15 23:45:34 -0500
commitcd17687f01420952712a500107e0f93e7ab8d5f8 (patch)
treece48c2b706f2c1176290e39fb555fbdf6648ce01 /linden/indra/newview/lldrawpoolalpha.cpp
parentSecond Life viewer sources 1.19.0.5 (diff)
downloadmeta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.zip
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.gz
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.bz2
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.xz
Second Life viewer sources 1.19.1.0
Diffstat (limited to 'linden/indra/newview/lldrawpoolalpha.cpp')
-rw-r--r--linden/indra/newview/lldrawpoolalpha.cpp288
1 files changed, 126 insertions, 162 deletions
diff --git a/linden/indra/newview/lldrawpoolalpha.cpp b/linden/indra/newview/lldrawpoolalpha.cpp
index 24cf8e7..1ad7132 100644
--- a/linden/indra/newview/lldrawpoolalpha.cpp
+++ b/linden/indra/newview/lldrawpoolalpha.cpp
@@ -48,20 +48,20 @@
48#include "llviewerobjectlist.h" // For debugging 48#include "llviewerobjectlist.h" // For debugging
49#include "llviewerwindow.h" 49#include "llviewerwindow.h"
50#include "pipeline.h" 50#include "pipeline.h"
51#include "llviewerregion.h"
52#include "llglslshader.h" 51#include "llglslshader.h"
52#include "llviewerregion.h"
53#include "lldrawpoolwater.h"
54#include "llspatialpartition.h"
53 55
54BOOL LLDrawPoolAlpha::sShowDebugAlpha = FALSE; 56BOOL LLDrawPoolAlpha::sShowDebugAlpha = FALSE;
55 57
56LLDrawPoolAlpha::LLDrawPoolAlpha(U32 type) :
57 LLRenderPass(type)
58{
59 58
60}
61 59
62LLDrawPoolAlphaPostWater::LLDrawPoolAlphaPostWater() 60LLDrawPoolAlpha::LLDrawPoolAlpha(U32 type) :
63: LLDrawPoolAlpha(POOL_ALPHA_POST_WATER) 61 LLRenderPass(type), current_shader(NULL), target_shader(NULL),
62 simple_shader(NULL), fullbright_shader(NULL)
64{ 63{
64
65} 65}
66 66
67LLDrawPoolAlpha::~LLDrawPoolAlpha() 67LLDrawPoolAlpha::~LLDrawPoolAlpha()
@@ -76,61 +76,58 @@ void LLDrawPoolAlpha::prerender()
76 76
77void LLDrawPoolAlpha::beginRenderPass(S32 pass) 77void LLDrawPoolAlpha::beginRenderPass(S32 pass)
78{ 78{
79 LLFastTimer t(LLFastTimer::FTM_RENDER_ALPHA);
79 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 80 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
80 glEnableClientState(GL_NORMAL_ARRAY); 81 glEnableClientState(GL_NORMAL_ARRAY);
81 glEnableClientState(GL_COLOR_ARRAY); 82 glEnableClientState(GL_COLOR_ARRAY);
82}
83
84void setup_clip_plane(BOOL pre_water)
85{
86 F32 height = gAgent.getRegion()->getWaterHeight();
87 BOOL above = gCamera->getOrigin().mV[2] > height ? TRUE : FALSE;
88 83
89 F64 plane[4]; 84 if (LLPipeline::sUnderWaterRender)
90
91 plane[0] = 0;
92 plane[1] = 0;
93 plane[2] = above == pre_water ? -1.0 : 1.0;
94 plane[3] = -plane[2] * height;
95
96 glClipPlane(GL_CLIP_PLANE0, plane);
97}
98
99void LLDrawPoolAlphaPostWater::render(S32 pass)
100{
101 LLFastTimer t(LLFastTimer::FTM_RENDER_ALPHA);
102
103 if (gPipeline.hasRenderType(LLDrawPool::POOL_ALPHA))
104 { 85 {
105 LLGLEnable clip(GL_CLIP_PLANE0); 86 simple_shader = &gObjectSimpleWaterProgram;
106 setup_clip_plane(FALSE); 87 fullbright_shader = &gObjectFullbrightWaterProgram;
107 LLDrawPoolAlpha::render(gPipeline.mAlphaGroupsPostWater);
108 } 88 }
109 else 89 else
110 { 90 {
111 LLDrawPoolAlpha::render(gPipeline.mAlphaGroupsPostWater); 91 simple_shader = &gObjectSimpleProgram;
92 fullbright_shader = &gObjectFullbrightProgram;
112 } 93 }
94
95 if (mVertexShaderLevel > 0)
96 {
97 // Start out with no shaders.
98 current_shader = target_shader = NULL;
99 glUseProgramObjectARB(0);
100 }
101 gPipeline.enableLightsDynamic();
113} 102}
114 103
115void LLDrawPoolAlpha::render(S32 pass) 104void LLDrawPoolAlpha::endRenderPass( S32 pass )
116{ 105{
117 LLFastTimer t(LLFastTimer::FTM_RENDER_ALPHA); 106 LLFastTimer t(LLFastTimer::FTM_RENDER_ALPHA);
118 107 LLRenderPass::endRenderPass(pass);
119 LLGLEnable clip(GL_CLIP_PLANE0); 108
120 setup_clip_plane(TRUE); 109 if(gPipeline.canUseWindLightShaders())
121 render(gPipeline.mAlphaGroups); 110 {
111 glUseProgramObjectARB(0);
112 }
122} 113}
123 114
124void LLDrawPoolAlpha::render(std::vector<LLSpatialGroup*>& groups) 115void LLDrawPoolAlpha::render(S32 pass)
125{ 116{
126 LLGLDepthTest gls_depth(GL_TRUE); 117 LLFastTimer t(LLFastTimer::FTM_RENDER_ALPHA);
127 LLGLSPipelineAlpha gls_pipeline_alpha;
128 118
129 gPipeline.enableLightsDynamic(1.f); 119 LLGLDepthTest depth(GL_TRUE, LLDrawPoolWater::sSkipScreenCopy ? GL_TRUE : GL_FALSE);
130 renderAlpha(getVertexDataMask(), groups); 120
121 LLGLSPipelineAlpha gls_pipeline_alpha;
122
123 renderAlpha(getVertexDataMask());
131 124
132 if (sShowDebugAlpha) 125 if (sShowDebugAlpha)
133 { 126 {
127 if(gPipeline.canUseWindLightShaders())
128 {
129 glUseProgramObjectARB(0);
130 }
134 glDisableClientState(GL_NORMAL_ARRAY); 131 glDisableClientState(GL_NORMAL_ARRAY);
135 glDisableClientState(GL_COLOR_ARRAY); 132 glDisableClientState(GL_COLOR_ARRAY);
136 gPipeline.enableLightsFullbright(LLColor4(1,1,1,1)); 133 gPipeline.enableLightsFullbright(LLColor4(1,1,1,1));
@@ -138,90 +135,39 @@ void LLDrawPoolAlpha::render(std::vector<LLSpatialGroup*>& groups)
138 LLViewerImage::sSmokeImagep->addTextureStats(1024.f*1024.f); 135 LLViewerImage::sSmokeImagep->addTextureStats(1024.f*1024.f);
139 LLViewerImage::sSmokeImagep->bind(); 136 LLViewerImage::sSmokeImagep->bind();
140 renderAlphaHighlight(LLVertexBuffer::MAP_VERTEX | 137 renderAlphaHighlight(LLVertexBuffer::MAP_VERTEX |
141 LLVertexBuffer::MAP_TEXCOORD, groups); 138 LLVertexBuffer::MAP_TEXCOORD);
142 } 139 }
143} 140}
144 141
145void LLDrawPoolAlpha::renderAlpha(U32 mask, std::vector<LLSpatialGroup*>& groups) 142void LLDrawPoolAlpha::renderAlpha(U32 mask)
146{ 143{
147#if !LL_RELEASE_FOR_DOWNLOAD 144#if !LL_RELEASE_FOR_DOWNLOAD
148 LLGLState::checkClientArrays(mask); 145 LLGLState::checkClientArrays(mask);
149#endif 146#endif
150 147
151 LLSpatialBridge* last_bridge = NULL; 148 for (LLCullResult::sg_list_t::iterator i = gPipeline.beginAlphaGroups(); i != gPipeline.endAlphaGroups(); ++i)
152 LLSpatialPartition* last_part = NULL;
153 glPushMatrix();
154 LLGLDepthTest depth(GL_TRUE, GL_FALSE);
155
156 for (std::vector<LLSpatialGroup*>::iterator i = groups.begin(); i != groups.end(); ++i)
157 { 149 {
158 LLSpatialGroup* group = *i; 150 LLSpatialGroup* group = *i;
159 if (group->mSpatialPartition->mRenderByGroup && 151 if (group->mSpatialPartition->mRenderByGroup &&
160 !group->isDead()) 152 !group->isDead())
161 { 153 {
162 LLSpatialPartition* part = group->mSpatialPartition;
163 if (part != last_part)
164 {
165 LLSpatialBridge* bridge = part->asBridge();
166 if (bridge != last_bridge)
167 {
168 glPopMatrix();
169 glPushMatrix();
170 if (bridge)
171 {
172 glMultMatrixf((F32*) bridge->mDrawable->getRenderMatrix().mMatrix);
173 }
174 last_bridge = bridge;
175 }
176
177// if (!last_part || part->mDepthMask != last_part->mDepthMask)
178// {
179// glDepthMask(part->mDepthMask);
180// }
181 last_part = part;
182 }
183
184 renderGroupAlpha(group,LLRenderPass::PASS_ALPHA,mask,TRUE); 154 renderGroupAlpha(group,LLRenderPass::PASS_ALPHA,mask,TRUE);
185 } 155 }
186 } 156 }
187
188 glPopMatrix();
189} 157}
190 158
191void LLDrawPoolAlpha::renderAlphaHighlight(U32 mask, std::vector<LLSpatialGroup*>& groups) 159void LLDrawPoolAlpha::renderAlphaHighlight(U32 mask)
192{ 160{
193#if !LL_RELEASE_FOR_DOWNLOAD 161#if !LL_RELEASE_FOR_DOWNLOAD
194 LLGLState::checkClientArrays(mask); 162 LLGLState::checkClientArrays(mask);
195#endif 163#endif
196 164
197 LLSpatialBridge* last_bridge = NULL; 165 for (LLCullResult::sg_list_t::iterator i = gPipeline.beginAlphaGroups(); i != gPipeline.endAlphaGroups(); ++i)
198 LLSpatialPartition* last_part = NULL;
199 glPushMatrix();
200
201 for (std::vector<LLSpatialGroup*>::iterator i = groups.begin(); i != groups.end(); ++i)
202 { 166 {
203 LLSpatialGroup* group = *i; 167 LLSpatialGroup* group = *i;
204 if (group->mSpatialPartition->mRenderByGroup && 168 if (group->mSpatialPartition->mRenderByGroup &&
205 !group->isDead()) 169 !group->isDead())
206 { 170 {
207 LLSpatialPartition* part = group->mSpatialPartition;
208 if (part != last_part)
209 {
210 LLSpatialBridge* bridge = part->asBridge();
211 if (bridge != last_bridge)
212 {
213 glPopMatrix();
214 glPushMatrix();
215 if (bridge)
216 {
217 glMultMatrixf((F32*) bridge->mDrawable->getRenderMatrix().mMatrix);
218 }
219 last_bridge = bridge;
220 }
221
222 last_part = part;
223 }
224
225 LLSpatialGroup::drawmap_elem_t& draw_info = group->mDrawMap[LLRenderPass::PASS_ALPHA]; 171 LLSpatialGroup::drawmap_elem_t& draw_info = group->mDrawMap[LLRenderPass::PASS_ALPHA];
226 172
227 for (LLSpatialGroup::drawmap_elem_t::iterator k = draw_info.begin(); k != draw_info.end(); ++k) 173 for (LLSpatialGroup::drawmap_elem_t::iterator k = draw_info.begin(); k != draw_info.end(); ++k)
@@ -232,104 +178,135 @@ void LLDrawPoolAlpha::renderAlphaHighlight(U32 mask, std::vector<LLSpatialGroup*
232 { 178 {
233 continue; 179 continue;
234 } 180 }
181
182 LLRenderPass::applyModelMatrix(params);
183
235 params.mVertexBuffer->setBuffer(mask); 184 params.mVertexBuffer->setBuffer(mask);
236 U32* indices_pointer = (U32*) params.mVertexBuffer->getIndicesPointer(); 185 U16* indices_pointer = (U16*) params.mVertexBuffer->getIndicesPointer();
237 glDrawRangeElements(GL_TRIANGLES, params.mStart, params.mEnd, params.mCount, 186 glDrawRangeElements(GL_TRIANGLES, params.mStart, params.mEnd, params.mCount,
238 GL_UNSIGNED_INT, indices_pointer+params.mOffset); 187 GL_UNSIGNED_SHORT, indices_pointer+params.mOffset);
239 188 gPipeline.addTrianglesDrawn(params.mCount/3);
240 addIndicesDrawn(params.mCount);
241 } 189 }
242 } 190 }
243 } 191 }
244 glPopMatrix();
245} 192}
246 193
247void LLDrawPoolAlpha::renderGroupAlpha(LLSpatialGroup* group, U32 type, U32 mask, BOOL texture) 194void LLDrawPoolAlpha::renderGroupAlpha(LLSpatialGroup* group, U32 type, U32 mask, BOOL texture)
248{ 195{
196 BOOL initialized_lighting = FALSE;
249 BOOL light_enabled = TRUE; 197 BOOL light_enabled = TRUE;
250 198 BOOL is_particle = FALSE;
251 LLSpatialGroup::drawmap_elem_t& draw_info = group->mDrawMap[type]; 199 BOOL use_shaders = (LLPipeline::sUnderWaterRender && gPipeline.canUseVertexShaders())
200 || gPipeline.canUseWindLightShadersOnObjects();
201 F32 dist;
202
203 // check to see if it's a particle and if it's "close"
204 is_particle = !LLPipeline::sUnderWaterRender && (group->mSpatialPartition->mDrawableType == LLPipeline::RENDER_TYPE_PARTICLES);
205 dist = group->mDistance;
252 206
253 U32 prim_type = GL_TRIANGLES; 207 // don't use shader if debug setting is off and it's close or if it's a particle
208 // and it's close
209 if(is_particle && !gSavedSettings.getBOOL("RenderUseShaderNearParticles"))
210 {
211 if((dist < gCamera->getFar() * gSavedSettings.getF32("RenderShaderParticleThreshold")))
212 {
213 use_shaders = FALSE;
214 }
215 }
254 216
255 //F32 width = (F32) gViewerWindow->getWindowDisplayWidth(); 217 LLSpatialGroup::drawmap_elem_t& draw_info = group->mDrawMap[type];
256 218
257 //F32 view = gCamera->getView();
258
259 if (group->mSpatialPartition->mDrawableType == LLPipeline::RENDER_TYPE_CLOUDS) 219 if (group->mSpatialPartition->mDrawableType == LLPipeline::RENDER_TYPE_CLOUDS)
260 { 220 {
221 if (!gSavedSettings.getBOOL("SkyUseClassicClouds"))
222 {
223 return;
224 }
225 // *TODO - Uhhh, we should always be doing some type of alpha rejection. These should probably both be 0.01f
261 glAlphaFunc(GL_GREATER, 0.f); 226 glAlphaFunc(GL_GREATER, 0.f);
262 } 227 }
263 else 228 else
264 { 229 {
265 glAlphaFunc(GL_GREATER, 0.01f); 230 if (LLPipeline::sImpostorRender)
231 {
232 glAlphaFunc(GL_GREATER, 0.5f);
233 }
234 else
235 {
236 glAlphaFunc(GL_GREATER, 0.01f);
237 }
266 } 238 }
267 239
268 /*LLGLEnable point_sprite(GL_POINT_SPRITE_ARB);
269
270 if (gGLManager.mHasPointParameters)
271 {
272 glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, TRUE);
273 glPointParameterfARB(GL_POINT_SIZE_MIN_ARB, 0.f);
274 glPointParameterfARB(GL_POINT_SIZE_MAX_ARB, width*16.f);
275 glPointSize(width/(view*view));
276 }*/
277
278 for (LLSpatialGroup::drawmap_elem_t::iterator k = draw_info.begin(); k != draw_info.end(); ++k) 240 for (LLSpatialGroup::drawmap_elem_t::iterator k = draw_info.begin(); k != draw_info.end(); ++k)
279 { 241 {
280 LLDrawInfo& params = **k; 242 LLDrawInfo& params = **k;
243
244 LLRenderPass::applyModelMatrix(params);
245
281 if (texture && params.mTexture.notNull()) 246 if (texture && params.mTexture.notNull())
282 { 247 {
248 glActiveTextureARB(GL_TEXTURE0_ARB);
283 params.mTexture->bind(); 249 params.mTexture->bind();
284 params.mTexture->addTextureStats(params.mVSize); 250 params.mTexture->addTextureStats(params.mVSize);
285 if (params.mTextureMatrix) 251 if (params.mTextureMatrix)
286 { 252 {
287 glMatrixMode(GL_TEXTURE); 253 glMatrixMode(GL_TEXTURE);
288 glLoadMatrixf((GLfloat*) params.mTextureMatrix->mMatrix); 254 glLoadMatrixf((GLfloat*) params.mTextureMatrix->mMatrix);
255 gPipeline.mTextureMatrixOps++;
289 } 256 }
290 } 257 }
291 258
292 if (params.mFullbright) 259 if (params.mFullbright)
293 { 260 {
294 if (light_enabled) 261 // Turn off lighting if it hasn't already been so.
262 if (light_enabled || !initialized_lighting)
295 { 263 {
296 gPipeline.enableLightsFullbright(LLColor4(1,1,1,1)); 264 initialized_lighting = TRUE;
297 light_enabled = FALSE; 265 if (use_shaders)
298 if (LLPipeline::sRenderGlow)
299 { 266 {
300 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 267 target_shader = fullbright_shader;
301 } 268 }
269 else
270 {
271 gPipeline.enableLightsFullbright(LLColor4(1,1,1,1));
272 }
273 light_enabled = FALSE;
302 } 274 }
303 } 275 }
304 else if (!light_enabled) 276 // Turn on lighting if it isn't already.
277 else if (!light_enabled || !initialized_lighting)
305 { 278 {
306 gPipeline.enableLightsDynamic(1.f); 279 initialized_lighting = TRUE;
307 light_enabled = TRUE; 280 if (use_shaders)
308 if (LLPipeline::sRenderGlow) 281 {
282 target_shader = simple_shader;
283 }
284 else
309 { 285 {
310 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE); 286 gPipeline.enableLightsDynamic();
311 } 287 }
288 light_enabled = TRUE;
312 } 289 }
313 290
314 /*if (params.mParticle) 291 // If we need shaders, and we're not ALREADY using the proper shader, then bind it
292 // (this way we won't rebind shaders unnecessarily).
293 if(use_shaders && (current_shader != target_shader))
315 { 294 {
316 F32 size = params.mPartSize; 295 llassert(target_shader != NULL);
317 size *= size; 296 current_shader = target_shader;
318 float param[] = { 0, 0, 0.01f/size*view*view }; 297 current_shader->bind();
319 prim_type = GL_POINTS;
320 glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB, param);
321 } 298 }
322 else*/ 299 else if (!use_shaders && current_shader != NULL)
323 { 300 {
324 prim_type = GL_TRIANGLES; 301 glUseProgramObjectARB(0);
302 current_shader = NULL;
325 } 303 }
326 304
327 params.mVertexBuffer->setBuffer(mask); 305 params.mVertexBuffer->setBuffer(mask);
328 U32* indices_pointer = (U32*) params.mVertexBuffer->getIndicesPointer(); 306 U16* indices_pointer = (U16*) params.mVertexBuffer->getIndicesPointer();
329 glDrawRangeElements(prim_type, params.mStart, params.mEnd, params.mCount, 307 glDrawRangeElements(GL_TRIANGLES, params.mStart, params.mEnd, params.mCount,
330 GL_UNSIGNED_INT, indices_pointer+params.mOffset); 308 GL_UNSIGNED_SHORT, indices_pointer+params.mOffset);
331 309 gPipeline.addTrianglesDrawn(params.mCount/3);
332 addIndicesDrawn(params.mCount);
333 310
334 if (params.mTextureMatrix && texture && params.mTexture.notNull()) 311 if (params.mTextureMatrix && texture && params.mTexture.notNull())
335 { 312 {
@@ -340,19 +317,6 @@ void LLDrawPoolAlpha::renderGroupAlpha(LLSpatialGroup* group, U32 type, U32 mask
340 317
341 if (!light_enabled) 318 if (!light_enabled)
342 { 319 {
343 gPipeline.enableLightsDynamic(1.f); 320 gPipeline.enableLightsDynamic();
344
345 if (LLPipeline::sRenderGlow)
346 {
347 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);
348 }
349 } 321 }
350 322}
351 /*glPointSize(1.f);
352
353 if (gGLManager.mHasPointParameters)
354 {
355 float param[] = {1, 0, 0 };
356 glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB, param);
357 }*/
358}