aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/lldrawpoolavatar.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/newview/lldrawpoolavatar.cpp')
-rw-r--r--linden/indra/newview/lldrawpoolavatar.cpp631
1 files changed, 320 insertions, 311 deletions
diff --git a/linden/indra/newview/lldrawpoolavatar.cpp b/linden/indra/newview/lldrawpoolavatar.cpp
index abf154c..fc4f64b 100644
--- a/linden/indra/newview/lldrawpoolavatar.cpp
+++ b/linden/indra/newview/lldrawpoolavatar.cpp
@@ -32,7 +32,6 @@
32#include "llvoavatar.h" 32#include "llvoavatar.h"
33#include "m3math.h" 33#include "m3math.h"
34 34
35#include "llagparray.h"
36#include "llagent.h" 35#include "llagent.h"
37#include "lldrawable.h" 36#include "lldrawable.h"
38#include "llface.h" 37#include "llface.h"
@@ -42,6 +41,11 @@
42#include "noise.h" 41#include "noise.h"
43#include "pipeline.h" 42#include "pipeline.h"
44 43
44static U32 sDataMask = LLDrawPoolAvatar::VERTEX_DATA_MASK;
45static U32 sBufferUsage = GL_STREAM_DRAW_ARB;
46static U32 sShaderLevel = 0;
47static LLGLSLShader* sVertexProgram = NULL;
48
45extern F32 gFrameDTClamped; 49extern F32 gFrameDTClamped;
46extern BOOL gUseGLPick; 50extern BOOL gUseGLPick;
47 51
@@ -75,53 +79,13 @@ S32 AVATAR_VERTEX_BYTES = 48;
75 79
76 80
77BOOL gAvatarEmbossBumpMap = FALSE; 81BOOL gAvatarEmbossBumpMap = FALSE;
82static BOOL sRenderingSkinned = FALSE;
78 83
79LLDrawPoolAvatar::LLDrawPoolAvatar() : 84LLDrawPoolAvatar::LLDrawPoolAvatar() :
80LLDrawPool(POOL_AVATAR, 85LLFacePool(POOL_AVATAR)
81 DATA_SIMPLE_IL_MASK,
82 DATA_VERTEX_WEIGHTS_MASK | DATA_CLOTHING_WEIGHTS_MASK )
83{ 86{
84 mCleanupUnused = FALSE;
85
86 // Overide the data layout
87 mDataMaskIL = 0;
88 mStride = 0;
89 for (S32 i = 0; i < DATA_MAX_TYPES; i++)
90 {
91 mDataOffsets[i] = 0;
92 }
93
94 // Note: padding is to speed up SSE code
95 mDataMaskIL |= DATA_VERTICES_MASK;
96 mDataOffsets[DATA_VERTICES] = mStride;
97 mStride += sDataSizes[DATA_VERTICES];
98
99 mStride += 4;
100
101 mDataMaskIL |= DATA_NORMALS_MASK;
102 mDataOffsets[DATA_NORMALS] = mStride;
103 mStride += sDataSizes[DATA_NORMALS];
104
105 mStride += 4;
106
107 // Note: binormals are stripped off in software blending
108 mDataMaskIL |= DATA_BINORMALS_MASK;
109 mDataOffsets[DATA_BINORMALS] = mStride;
110 mStride += sDataSizes[DATA_BINORMALS];
111
112 mStride += 4; // To keep the structure 16-byte aligned (for SSE happiness)
113
114 mDataMaskIL |= DATA_TEX_COORDS0_MASK;
115 mDataOffsets[DATA_TEX_COORDS0] = mStride;
116 mStride += sDataSizes[DATA_TEX_COORDS0];
117
118 mDataMaskIL |= DATA_TEX_COORDS1_MASK;
119 mDataOffsets[DATA_TEX_COORDS1] = mStride;
120 mStride += sDataSizes[DATA_TEX_COORDS1];
121
122 //LLDebugVarMessageBox::show("acceleration", &CLOTHING_ACCEL_FORCE_FACTOR, 10.f, 0.1f); 87 //LLDebugVarMessageBox::show("acceleration", &CLOTHING_ACCEL_FORCE_FACTOR, 10.f, 0.1f);
123 //LLDebugVarMessageBox::show("gravity", &CLOTHING_GRAVITY_EFFECT, 10.f, 0.1f); 88 //LLDebugVarMessageBox::show("gravity", &CLOTHING_GRAVITY_EFFECT, 10.f, 0.1f);
124
125} 89}
126 90
127//----------------------------------------------------------------------------- 91//-----------------------------------------------------------------------------
@@ -132,41 +96,194 @@ LLDrawPool *LLDrawPoolAvatar::instancePool()
132 return new LLDrawPoolAvatar(); 96 return new LLDrawPoolAvatar();
133} 97}
134 98
99BOOL gRenderAvatar = TRUE;
100static LLMatrix4 sModelViewMatrix = LLMatrix4();
135 101
136S32 LLDrawPoolAvatar::rebuild() 102S32 LLDrawPoolAvatar::getVertexShaderLevel() const
137{ 103{
138 mRebuildTime++; 104 return (S32) gPipeline.getVertexShaderLevel(LLPipeline::SHADER_AVATAR);
139 if (mRebuildTime > mRebuildFreq)
140 {
141 flushAGP();
142
143 mRebuildTime = 0;
144 }
145
146 return 0;
147} 105}
148 106
149BOOL gRenderAvatar = TRUE;
150
151void LLDrawPoolAvatar::prerender() 107void LLDrawPoolAvatar::prerender()
152{ 108{
153 mVertexShaderLevel = gPipeline.getVertexShaderLevel(LLPipeline::SHADER_AVATAR); 109 mVertexShaderLevel = gPipeline.getVertexShaderLevel(LLPipeline::SHADER_AVATAR);
110 sShaderLevel = mVertexShaderLevel;
111
112 if (sShaderLevel > 0)
113 {
114 sBufferUsage = GL_STATIC_DRAW_ARB;
115 }
116 else
117 {
118 sBufferUsage = GL_STREAM_DRAW_ARB;
119 }
120}
121
122LLMatrix4& LLDrawPoolAvatar::getModelView()
123{
124 return sModelViewMatrix;
154} 125}
155 126
156//----------------------------------------------------------------------------- 127//-----------------------------------------------------------------------------
157// render() 128// render()
158//----------------------------------------------------------------------------- 129//-----------------------------------------------------------------------------
130
131S32 LLDrawPoolAvatar::getNumPasses()
132{
133 return 3;
134}
135
159void LLDrawPoolAvatar::render(S32 pass) 136void LLDrawPoolAvatar::render(S32 pass)
160{ 137{
161 LLFastTimer t(LLFastTimer::FTM_RENDER_CHARACTERS); 138 LLFastTimer t(LLFastTimer::FTM_RENDER_CHARACTERS);
162 renderAvatars(NULL); // render all avatars 139 renderAvatars(NULL, pass); // render all avatars
140}
141
142void LLDrawPoolAvatar::beginRenderPass(S32 pass)
143{
144 //reset vertex buffer mappings
145 LLVertexBuffer::unbind();
146
147 switch (pass)
148 {
149 case 0:
150 beginFootShadow();
151 break;
152 case 1:
153 glGetFloatv(GL_MODELVIEW_MATRIX, (F32*) sModelViewMatrix.mMatrix);
154 beginRigid();
155 break;
156 case 2:
157 beginSkinned();
158 break;
159 }
160}
161
162void LLDrawPoolAvatar::endRenderPass(S32 pass)
163{
164 switch (pass)
165 {
166 case 0:
167 endFootShadow();
168 break;
169 case 1:
170 endRigid();
171 break;
172 case 2:
173 endSkinned();
174 }
175}
176
177void LLDrawPoolAvatar::beginFootShadow()
178{
179 glDepthMask(GL_FALSE);
180 gPipeline.enableLightsFullbright(LLColor4(1,1,1,1));
181 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
182}
183
184void LLDrawPoolAvatar::endFootShadow()
185{
186 gPipeline.enableLightsDynamic(1.f);
187 glDepthMask(GL_TRUE);
188 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
189}
190
191void LLDrawPoolAvatar::beginRigid()
192{
193 sVertexProgram = &gPipeline.mAvatarEyeballProgram;
194 glEnableClientState(GL_NORMAL_ARRAY);
195 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
196
197 if (sShaderLevel > 0)
198 { //eyeballs render with the specular shader
199 gPipeline.mAvatarEyeballProgram.bind();
200 gPipeline.mMaterialIndex = gPipeline.mAvatarEyeballProgram.mAttribute[LLPipeline::GLSL_MATERIAL_COLOR];
201 gPipeline.mSpecularIndex = gPipeline.mAvatarEyeballProgram.mAttribute[LLPipeline::GLSL_SPECULAR_COLOR];
202 }
203}
204
205void LLDrawPoolAvatar::endRigid()
206{
207 glDisableClientState(GL_NORMAL_ARRAY);
208 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
209}
210
211void LLDrawPoolAvatar::beginSkinned()
212{
213 glEnableClientState(GL_NORMAL_ARRAY);
214 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
215
216 sVertexProgram = &gPipeline.mAvatarProgram;
217
218 if (sShaderLevel > 0) // for hardware blending
219 {
220 sRenderingSkinned = TRUE;
221 glClientActiveTextureARB(GL_TEXTURE1_ARB);
222 if (sShaderLevel >= SHADER_LEVEL_BUMP)
223 {
224 gPipeline.mMaterialIndex = sVertexProgram->mAttribute[LLPipeline::GLSL_MATERIAL_COLOR];
225 gPipeline.mSpecularIndex = sVertexProgram->mAttribute[LLPipeline::GLSL_SPECULAR_COLOR];
226 }
227 sVertexProgram->bind();
228 if (sShaderLevel >= SHADER_LEVEL_CLOTH)
229 {
230 enable_cloth_weights(sVertexProgram->mAttribute[LLPipeline::GLSL_AVATAR_CLOTHING]);
231 }
232 enable_vertex_weighting(sVertexProgram->mAttribute[LLPipeline::GLSL_AVATAR_WEIGHT]);
233
234 if (sShaderLevel >= SHADER_LEVEL_BUMP)
235 {
236 enable_binormals(sVertexProgram->mAttribute[LLPipeline::GLSL_BINORMAL]);
237 }
238
239 sVertexProgram->enableTexture(LLPipeline::GLSL_BUMP_MAP);
240 glActiveTextureARB(GL_TEXTURE0_ARB);
241 }
163} 242}
164 243
165void LLDrawPoolAvatar::renderAvatars(LLVOAvatar* single_avatar, BOOL no_shaders) 244void LLDrawPoolAvatar::endSkinned()
166{ 245{
167 if (no_shaders) 246 // if we're in software-blending, remember to set the fence _after_ we draw so we wait till this rendering is done
247 if (sShaderLevel > 0)
168 { 248 {
169 mVertexShaderLevel = 0; 249 sRenderingSkinned = FALSE;
250 sVertexProgram->disableTexture(LLPipeline::GLSL_BUMP_MAP);
251 glActiveTextureARB(GL_TEXTURE0_ARB);
252 glClientActiveTextureARB(GL_TEXTURE0_ARB);
253 disable_vertex_weighting(sVertexProgram->mAttribute[LLPipeline::GLSL_AVATAR_WEIGHT]);
254 if (sShaderLevel >= SHADER_LEVEL_BUMP)
255 {
256 disable_binormals(sVertexProgram->mAttribute[LLPipeline::GLSL_BINORMAL]);
257 }
258 if ((sShaderLevel >= SHADER_LEVEL_CLOTH))
259 {
260 disable_cloth_weights(sVertexProgram->mAttribute[LLPipeline::GLSL_AVATAR_CLOTHING]);
261 }
262
263 sVertexProgram->unbind();
264 }
265
266 glActiveTextureARB(GL_TEXTURE0_ARB);
267 glClientActiveTextureARB(GL_TEXTURE0_ARB);
268
269 glDisableClientState(GL_NORMAL_ARRAY);
270 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
271}
272
273
274void LLDrawPoolAvatar::renderAvatars(LLVOAvatar* single_avatar, S32 pass)
275{
276 if (pass == -1)
277 {
278 for (S32 i = 1; i < getNumPasses(); i++)
279 { //skip foot shadows
280 prerender();
281 beginRenderPass(i);
282 renderAvatars(single_avatar, i);
283 endRenderPass(i);
284 }
285
286 return;
170 } 287 }
171 288
172 if (!gRenderAvatar) 289 if (!gRenderAvatar)
@@ -195,13 +312,95 @@ void LLDrawPoolAvatar::renderAvatars(LLVOAvatar* single_avatar, BOOL no_shaders)
195 avatarp = (LLVOAvatar *)(facep->getDrawable()->getVObj()); 312 avatarp = (LLVOAvatar *)(facep->getDrawable()->getVObj());
196 } 313 }
197 314
198 if (avatarp->isDead() || avatarp->mDrawable.isNull()) 315 if (avatarp->isDead() || avatarp->mDrawable.isNull())
199 { 316 {
200 return; 317 return;
201 } 318 }
202 319
203 LLOverrideFaceColor color(this, 1.0f, 1.0f, 1.0f, 1.0f); 320 LLOverrideFaceColor color(this, 1.0f, 1.0f, 1.0f, 1.0f);
204 321
322 if (pass == 0)
323 {
324 if (gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_FOOT_SHADOWS))
325 {
326 mIndicesDrawn += avatarp->renderFootShadows();
327 }
328 return;
329 }
330
331 if (avatarp->mSpecialRenderMode == 0) // normal
332 {
333 gPipeline.enableLightsAvatar(avatarp->mDrawable->getSunShadowFactor());
334 }
335 else if (avatarp->mSpecialRenderMode == 1) // anim preview
336 {
337 gPipeline.enableLightsAvatarEdit(LLColor4(0.7f, 0.6f, 0.3f, 1.f));
338 }
339 else // 2=image preview, 3=morph view
340 {
341 gPipeline.enableLightsAvatarEdit(LLColor4(.5f, .5f, .5f, 1.f));
342 }
343
344 if (pass == 1)
345 {
346 // render rigid meshes (eyeballs) first
347 mIndicesDrawn += avatarp->renderRigid();
348
349 if (!gRenderForSelect && avatarp->mIsSelf && LLVOAvatar::sAvatarLoadTest)
350 {
351 LLVector3 orig_pos_root = avatarp->mRoot.getPosition();
352 LLVector3 next_pos_root = orig_pos_root;
353 for (S32 i = 0; i < NUM_TEST_AVATARS; i++)
354 {
355 next_pos_root.mV[VX] += 1.f;
356 if (i % 5 == 0)
357 {
358 next_pos_root.mV[VY] += 1.f;
359 next_pos_root.mV[VX] = orig_pos_root.mV[VX];
360 }
361
362 avatarp->mRoot.setPosition(next_pos_root); // avatar load test
363 avatarp->mRoot.updateWorldMatrixChildren(); // avatar load test
364
365 mIndicesDrawn += avatarp->renderRigid();
366 }
367 avatarp->mRoot.setPosition(orig_pos_root); // avatar load test
368 avatarp->mRoot.updateWorldMatrixChildren(); // avatar load test
369 }
370 return;
371 }
372
373
374 if (sShaderLevel > 0)
375 {
376 gPipeline.mAvatarMatrixParam = sVertexProgram->mUniform[LLPipeline::GLSL_AVATAR_MATRIX];
377 }
378
379 if ((sShaderLevel >= SHADER_LEVEL_CLOTH))
380 {
381 LLMatrix4 rot_mat;
382 gCamera->getMatrixToLocal(rot_mat);
383 LLMatrix4 cfr(OGL_TO_CFR_ROTATION);
384 rot_mat *= cfr;
385
386 LLVector4 wind;
387 wind.setVec(avatarp->mWindVec);
388 wind.mV[VW] = 0;
389 wind = wind * rot_mat;
390 wind.mV[VW] = avatarp->mWindVec.mV[VW];
391
392 sVertexProgram->vertexAttrib4fv(LLPipeline::GLSL_AVATAR_WIND, wind.mV);
393 F32 phase = -1.f * (avatarp->mRipplePhase);
394
395 F32 freq = 7.f + (noise1(avatarp->mRipplePhase) * 2.f);
396 LLVector4 sin_params(freq, freq, freq, phase);
397 sVertexProgram->vertexAttrib4fv(LLPipeline::GLSL_AVATAR_SINWAVE, sin_params.mV);
398
399 LLVector4 gravity(0.f, 0.f, -CLOTHING_GRAVITY_EFFECT, 0.f);
400 gravity = gravity * rot_mat;
401 sVertexProgram->vertexAttrib4fv(LLPipeline::GLSL_AVATAR_GRAVITY, gravity.mV);
402 }
403
205 if( !single_avatar || (avatarp == single_avatar) ) 404 if( !single_avatar || (avatarp == single_avatar) )
206 { 405 {
207 if (LLVOAvatar::sShowCollisionVolumes) 406 if (LLVOAvatar::sShowCollisionVolumes)
@@ -210,8 +409,6 @@ void LLDrawPoolAvatar::renderAvatars(LLVOAvatar* single_avatar, BOOL no_shaders)
210 avatarp->renderCollisionVolumes(); 409 avatarp->renderCollisionVolumes();
211 } 410 }
212 411
213 LLGLEnable normalize(GL_NORMALIZE);
214
215 if (avatarp->mIsSelf && LLAgent::sDebugDisplayTarget) 412 if (avatarp->mIsSelf && LLAgent::sDebugDisplayTarget)
216 { 413 {
217 LLGLSNoTexture gls_no_texture; 414 LLGLSNoTexture gls_no_texture;
@@ -267,171 +464,8 @@ void LLDrawPoolAvatar::renderAvatars(LLVOAvatar* single_avatar, BOOL no_shaders)
267 color.setColor(1.0f, 1.0f, 1.0f, 1.0f); 464 color.setColor(1.0f, 1.0f, 1.0f, 1.0f);
268 } 465 }
269 466
270 glEnableClientState(GL_VERTEX_ARRAY);
271 glEnableClientState(GL_NORMAL_ARRAY);
272 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
273
274 LLGLSLShader* vertex_program = &gPipeline.mAvatarProgram;
275 if (mVertexShaderLevel > 0)
276 {
277 gPipeline.mAvatarMatrixParam = vertex_program->mUniform[LLPipeline::GLSL_AVATAR_MATRIX];
278 }
279
280 //--------------------------------------------------------------------------------
281 // this is where we first hit the software blending path
282 // if enabled, we need to set up the proper buffers and avoid setting other state
283 //--------------------------------------------------------------------------------
284 if (!(mVertexShaderLevel > 0))
285 {
286
287 // performance could be increased by better utilizing the buffers, for example, only using 1k buffers for lo-res
288 // avatars. But the only problem with using fewer buffers is that we're more likely to wait for a fence to complete
289
290 // vertex format:
291 // vertices 12
292 // texcoords 8
293 // normals 12
294 // binormals 12
295 // padding 4
296 // total 48
297
298 // Rotate to the next buffer, round-robin.
299 gPipeline.bufferRotate();
300
301 // Wait until the hardware is done reading the last set of vertices from the buffer before writing the next set.
302 gPipeline.bufferWaitFence();
303
304 // Need to do this because we may be rendering without AGP even in AGP mode
305 U8* buffer_offset_start = gPipeline.bufferGetScratchMemory();
306 glVertexPointer( 3, GL_FLOAT, AVATAR_VERTEX_BYTES, buffer_offset_start + AVATAR_OFFSET_POS);
307 glTexCoordPointer(2, GL_FLOAT, AVATAR_VERTEX_BYTES, buffer_offset_start + AVATAR_OFFSET_TEX0);
308 glNormalPointer( GL_FLOAT, AVATAR_VERTEX_BYTES, buffer_offset_start + AVATAR_OFFSET_NORMAL);
309
310 }
311
312 if ((mVertexShaderLevel > 0)) // for hardware blending
313 {
314 bindGLVertexPointer();
315 bindGLNormalPointer();
316 bindGLTexCoordPointer(0);
317 }
318
319 if ((mVertexShaderLevel > 0))
320 { //eyeballs render with the specular shader
321 gPipeline.mAvatarEyeballProgram.bind();
322 gPipeline.mMaterialIndex = gPipeline.mAvatarEyeballProgram.mAttribute[LLPipeline::GLSL_MATERIAL_COLOR];
323 gPipeline.mSpecularIndex = gPipeline.mAvatarEyeballProgram.mAttribute[LLPipeline::GLSL_SPECULAR_COLOR];
324
325 S32 index = gPipeline.mAvatarEyeballProgram.enableTexture(LLPipeline::GLSL_SCATTER_MAP);
326 gSky.mVOSkyp->getScatterMap()->bind(index);
327
328 glActiveTextureARB(GL_TEXTURE0_ARB);
329 }
330
331 if (avatarp->mSpecialRenderMode == 0) // normal
332 {
333 gPipeline.enableLightsAvatar(avatarp->mDrawable->getSunShadowFactor());
334 }
335 else if (avatarp->mSpecialRenderMode == 1) // anim preview
336 {
337 gPipeline.enableLightsAvatarEdit(LLColor4(0.7f, 0.6f, 0.3f, 1.f));
338 }
339 else // 2=image preview, 3=morph view
340 {
341 gPipeline.enableLightsAvatarEdit(LLColor4(.5f, .5f, .5f, 1.f));
342 }
343
344 // render rigid meshes (eyeballs) first
345 mIndicesDrawn += avatarp->renderRigid();
346
347 if ((mVertexShaderLevel > 0))
348 {
349 gPipeline.mAvatarEyeballProgram.disableTexture(LLPipeline::GLSL_SCATTER_MAP);
350 glActiveTextureARB(GL_TEXTURE0_ARB);
351 }
352
353 if (!gRenderForSelect && avatarp->mIsSelf && LLVOAvatar::sAvatarLoadTest)
354 {
355 LLVector3 orig_pos_root = avatarp->mRoot.getPosition();
356 LLVector3 next_pos_root = orig_pos_root;
357 for (S32 i = 0; i < NUM_TEST_AVATARS; i++)
358 {
359 next_pos_root.mV[VX] += 1.f;
360 if (i % 5 == 0)
361 {
362 next_pos_root.mV[VY] += 1.f;
363 next_pos_root.mV[VX] = orig_pos_root.mV[VX];
364 }
365
366 avatarp->mRoot.setPosition(next_pos_root); // avatar load test
367 avatarp->mRoot.updateWorldMatrixChildren(); // avatar load test
368
369 mIndicesDrawn += avatarp->renderRigid();
370 }
371 avatarp->mRoot.setPosition(orig_pos_root); // avatar load test
372 avatarp->mRoot.updateWorldMatrixChildren(); // avatar load test
373 }
374
375 if ((mVertexShaderLevel > 0)) // for hardware blending
376 {
377 glClientActiveTextureARB(GL_TEXTURE1_ARB);
378 if ((mVertexShaderLevel >= SHADER_LEVEL_BUMP))
379 {
380 bindGLTexCoordPointer(1);
381
382 bindGLBinormalPointer(vertex_program->mAttribute[LLPipeline::GLSL_BINORMAL]);
383 gPipeline.mMaterialIndex = vertex_program->mAttribute[LLPipeline::GLSL_MATERIAL_COLOR];
384 gPipeline.mSpecularIndex = vertex_program->mAttribute[LLPipeline::GLSL_SPECULAR_COLOR];
385 }
386 glClientActiveTextureARB(GL_TEXTURE0_ARB);
387 bindGLTexCoordPointer(0);
388 vertex_program->bind();
389 bindGLVertexWeightPointer(vertex_program->mAttribute[LLPipeline::GLSL_AVATAR_WEIGHT]);
390 if ((mVertexShaderLevel >= SHADER_LEVEL_CLOTH))
391 {
392 bindGLVertexClothingWeightPointer(vertex_program->mAttribute[LLPipeline::GLSL_AVATAR_CLOTHING]);
393 enable_cloth_weights(vertex_program->mAttribute[LLPipeline::GLSL_AVATAR_CLOTHING]);
394 }
395 enable_vertex_weighting(vertex_program->mAttribute[LLPipeline::GLSL_AVATAR_WEIGHT]);
396
397 if ((mVertexShaderLevel >= SHADER_LEVEL_BUMP))
398 {
399 enable_binormals(vertex_program->mAttribute[LLPipeline::GLSL_BINORMAL]);
400 }
401
402 vertex_program->enableTexture(LLPipeline::GLSL_BUMP_MAP);
403 S32 index = vertex_program->enableTexture(LLPipeline::GLSL_SCATTER_MAP);
404 gSky.mVOSkyp->getScatterMap()->bind(index);
405 glActiveTextureARB(GL_TEXTURE0_ARB);
406 }
407
408 if ((mVertexShaderLevel >= SHADER_LEVEL_CLOTH))
409 {
410 LLMatrix4 rot_mat;
411 gCamera->getMatrixToLocal(rot_mat);
412 LLMatrix4 cfr(OGL_TO_CFR_ROTATION);
413 rot_mat *= cfr;
414
415 LLVector4 wind;
416 wind.setVec(avatarp->mWindVec);
417 wind.mV[VW] = 0;
418 wind = wind * rot_mat;
419 wind.mV[VW] = avatarp->mWindVec.mV[VW];
420
421 vertex_program->vertexAttrib4fv(LLPipeline::GLSL_AVATAR_WIND, wind.mV);
422 F32 phase = -1.f * (avatarp->mRipplePhase);
423
424 F32 freq = 7.f + (noise1(avatarp->mRipplePhase) * 2.f);
425 LLVector4 sin_params(freq, freq, freq, phase);
426 vertex_program->vertexAttrib4fv(LLPipeline::GLSL_AVATAR_SINWAVE, sin_params.mV);
427
428 LLVector4 gravity(0.f, 0.f, -CLOTHING_GRAVITY_EFFECT, 0.f);
429 gravity = gravity * rot_mat;
430 vertex_program->vertexAttrib4fv(LLPipeline::GLSL_AVATAR_GRAVITY, gravity.mV);
431 }
432
433 mIndicesDrawn += avatarp->renderSkinned(AVATAR_RENDER_PASS_SINGLE); 467 mIndicesDrawn += avatarp->renderSkinned(AVATAR_RENDER_PASS_SINGLE);
434 468
435 if (!gRenderForSelect && avatarp->mIsSelf && LLVOAvatar::sAvatarLoadTest) 469 if (!gRenderForSelect && avatarp->mIsSelf && LLVOAvatar::sAvatarLoadTest)
436 { 470 {
437 LLVector3 orig_pos_root = avatarp->mRoot.getPosition(); 471 LLVector3 orig_pos_root = avatarp->mRoot.getPosition();
@@ -453,31 +487,6 @@ void LLDrawPoolAvatar::renderAvatars(LLVOAvatar* single_avatar, BOOL no_shaders)
453 avatarp->mRoot.setPosition(orig_pos_root); // avatar load test 487 avatarp->mRoot.setPosition(orig_pos_root); // avatar load test
454 avatarp->mRoot.updateWorldMatrixChildren(); // avatar load test 488 avatarp->mRoot.updateWorldMatrixChildren(); // avatar load test
455 } 489 }
456
457 // if we're in software-blending, remember to set the fence _after_ we draw so we wait till this rendering is done
458 if (!(mVertexShaderLevel > 0))
459 {
460 // want for the previously bound fence to finish
461 gPipeline.bufferSendFence();
462 }
463 else
464 {
465 vertex_program->disableTexture(LLPipeline::GLSL_BUMP_MAP);
466 vertex_program->disableTexture(LLPipeline::GLSL_SCATTER_MAP);
467 glActiveTextureARB(GL_TEXTURE0_ARB);
468 glClientActiveTextureARB(GL_TEXTURE0_ARB);
469 disable_vertex_weighting(vertex_program->mAttribute[LLPipeline::GLSL_AVATAR_WEIGHT]);
470 if ((mVertexShaderLevel >= SHADER_LEVEL_BUMP))
471 {
472 disable_binormals(vertex_program->mAttribute[LLPipeline::GLSL_BINORMAL]);
473 }
474 if ((mVertexShaderLevel >= SHADER_LEVEL_CLOTH))
475 {
476 disable_cloth_weights(vertex_program->mAttribute[LLPipeline::GLSL_AVATAR_CLOTHING]);
477 }
478
479 vertex_program->unbind();
480 }
481 } 490 }
482} 491}
483 492
@@ -490,14 +499,13 @@ void LLDrawPoolAvatar::renderForSelect()
490 { 499 {
491 return; 500 return;
492 } 501 }
493 //gGLSObjectSelectDepthAlpha.set(); 502
494
495 if (!gRenderAvatar) 503 if (!gRenderAvatar)
496 { 504 {
497 return; 505 return;
498 } 506 }
499 507
500 if (mDrawFace.empty() || !mMemory.count()) 508 if (mDrawFace.empty())
501 { 509 {
502 return; 510 return;
503 } 511 }
@@ -517,80 +525,38 @@ void LLDrawPoolAvatar::renderForSelect()
517 glEnableClientState(GL_VERTEX_ARRAY); 525 glEnableClientState(GL_VERTEX_ARRAY);
518 glEnableClientState(GL_NORMAL_ARRAY); 526 glEnableClientState(GL_NORMAL_ARRAY);
519 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 527 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
520 528 glGetFloatv(GL_MODELVIEW_MATRIX, (F32*) sModelViewMatrix.mMatrix);
521 LLGLSLShader* vertex_program = &gPipeline.mAvatarPickProgram; 529 sVertexProgram = &gPipeline.mAvatarPickProgram;
522 if (mVertexShaderLevel > 0) 530 if (sShaderLevel > 0)
523 { 531 {
524 gPipeline.mAvatarMatrixParam = vertex_program->mUniform[LLPipeline::GLSL_AVATAR_MATRIX]; 532 gPipeline.mAvatarMatrixParam = sVertexProgram->mUniform[LLPipeline::GLSL_AVATAR_MATRIX];
525 } 533 }
526 glAlphaFunc(GL_GEQUAL, 0.2f); 534 glAlphaFunc(GL_GEQUAL, 0.2f);
527 glBlendFunc(GL_ONE, GL_ZERO); 535 glBlendFunc(GL_ONE, GL_ZERO);
528 536
529 //--------------------------------------------------------------------------------
530 // this is where we first hit the software blending path
531 // if enabled, we need to set up the proper buffers and avoid setting other state
532 //--------------------------------------------------------------------------------
533 if (!(mVertexShaderLevel > 0) || gUseGLPick)
534 {
535
536 // Rotate to the next buffer, round-robin.
537 gPipeline.bufferRotate();
538
539 // Wait until the hardware is done reading the last set of vertices from the buffer before writing the next set.
540 gPipeline.bufferWaitFence();
541
542 // Need to do this because we may be rendering without AGP even in AGP mode
543 U8* buffer_offset_start = gPipeline.bufferGetScratchMemory();
544 glVertexPointer( 3, GL_FLOAT, AVATAR_VERTEX_BYTES, buffer_offset_start + AVATAR_OFFSET_POS);
545 glTexCoordPointer(2, GL_FLOAT, AVATAR_VERTEX_BYTES, buffer_offset_start + AVATAR_OFFSET_TEX0);
546 glNormalPointer( GL_FLOAT, AVATAR_VERTEX_BYTES, buffer_offset_start + AVATAR_OFFSET_NORMAL);
547 }
548
549 S32 name = avatarp->mDrawable->getVObj()->mGLName; 537 S32 name = avatarp->mDrawable->getVObj()->mGLName;
550 LLColor4U color((U8)(name >> 16), (U8)(name >> 8), (U8)name); 538 LLColor4U color((U8)(name >> 16), (U8)(name >> 8), (U8)name);
551 glColor4ubv(color.mV); 539 glColor4ubv(color.mV);
552 540
553 if ((mVertexShaderLevel > 0) && !gUseGLPick) // for hardware blending
554 {
555 bindGLVertexPointer();
556 bindGLNormalPointer();
557 bindGLTexCoordPointer(0);
558 }
559
560 // render rigid meshes (eyeballs) first 541 // render rigid meshes (eyeballs) first
561 mIndicesDrawn += avatarp->renderRigid(); 542 //mIndicesDrawn += avatarp->renderRigid();
562 543
563 if ((mVertexShaderLevel > 0) && !gUseGLPick) // for hardware blending 544 if ((sShaderLevel > 0) && !gUseGLPick) // for hardware blending
564 { 545 {
565 glClientActiveTextureARB(GL_TEXTURE0_ARB); 546 glClientActiveTextureARB(GL_TEXTURE0_ARB);
566 bindGLTexCoordPointer(0); 547 sRenderingSkinned = TRUE;
567 vertex_program->bind(); 548 sVertexProgram->bind();
568 bindGLVertexWeightPointer(vertex_program->mAttribute[LLPipeline::GLSL_AVATAR_WEIGHT]); 549 enable_vertex_weighting(sVertexProgram->mAttribute[LLPipeline::GLSL_AVATAR_WEIGHT]);
569 /*if ((mVertexShaderLevel >= SHADER_LEVEL_CLOTH))
570 {
571 bindGLVertexClothingWeightPointer();
572 enable_cloth_weights();
573 }*/
574 enable_vertex_weighting(vertex_program->mAttribute[LLPipeline::GLSL_AVATAR_WEIGHT]);
575 } 550 }
576 551
577 mIndicesDrawn += avatarp->renderSkinned(AVATAR_RENDER_PASS_SINGLE); 552 mIndicesDrawn += avatarp->renderSkinned(AVATAR_RENDER_PASS_SINGLE);
578 553
579 // if we're in software-blending, remember to set the fence _after_ we draw so we wait till this rendering is done 554 // if we're in software-blending, remember to set the fence _after_ we draw so we wait till this rendering is done
580 if (!(mVertexShaderLevel > 0) || gUseGLPick) 555 if ((sShaderLevel > 0) && !gUseGLPick)
581 { 556 {
582 // want for the previously bound fence to finish 557 sRenderingSkinned = FALSE;
583 gPipeline.bufferSendFence(); 558 sVertexProgram->unbind();
584 } 559 disable_vertex_weighting(sVertexProgram->mAttribute[LLPipeline::GLSL_AVATAR_WEIGHT]);
585 else
586 {
587 vertex_program->unbind();
588 disable_vertex_weighting(vertex_program->mAttribute[LLPipeline::GLSL_AVATAR_WEIGHT]);
589
590 /*if ((mVertexShaderLevel >= SHADER_LEVEL_CLOTH))
591 {
592 disable_cloth_weights();
593 }*/
594 } 560 }
595 561
596 glAlphaFunc(GL_GREATER, 0.01f); 562 glAlphaFunc(GL_GREATER, 0.01f);
@@ -627,3 +593,46 @@ LLColor3 LLDrawPoolAvatar::getDebugColor() const
627{ 593{
628 return LLColor3(0.f, 1.f, 0.f); 594 return LLColor3(0.f, 1.f, 0.f);
629} 595}
596
597LLVertexBufferAvatar::LLVertexBufferAvatar()
598: LLVertexBuffer(sDataMask,
599 gPipeline.getVertexShaderLevel(LLPipeline::SHADER_AVATAR) > 0 ?
600 GL_STATIC_DRAW_ARB :
601 GL_STREAM_DRAW_ARB)
602{
603
604}
605
606
607void LLVertexBufferAvatar::setupVertexBuffer(U32 data_mask) const
608{
609 if (sRenderingSkinned)
610 {
611 U8* base = useVBOs() ? NULL : mMappedData;
612
613 glVertexPointer(3,GL_FLOAT, mStride, (void*)(base + 0));
614 glNormalPointer(GL_FLOAT, mStride, (void*)(base + mOffsets[TYPE_NORMAL]));
615
616 glClientActiveTextureARB(GL_TEXTURE1_ARB);
617 glTexCoordPointer(2,GL_FLOAT, mStride, (void*)(base + mOffsets[TYPE_TEXCOORD2]));
618 glClientActiveTextureARB(GL_TEXTURE0_ARB);
619 glTexCoordPointer(2,GL_FLOAT, mStride, (void*)(base + mOffsets[TYPE_TEXCOORD]));
620
621 set_vertex_weights(sVertexProgram->mAttribute[LLPipeline::GLSL_AVATAR_WEIGHT], mStride, (F32*)(base + mOffsets[TYPE_WEIGHT]));
622
623 if (sShaderLevel >= LLDrawPoolAvatar::SHADER_LEVEL_BUMP)
624 {
625 set_binormals(sVertexProgram->mAttribute[LLPipeline::GLSL_BINORMAL], mStride, (LLVector3*)(base + mOffsets[TYPE_BINORMAL]));
626 }
627
628 if (sShaderLevel >= LLDrawPoolAvatar::SHADER_LEVEL_CLOTH)
629 {
630 set_vertex_clothing_weights(sVertexProgram->mAttribute[LLPipeline::GLSL_AVATAR_CLOTHING], mStride, (LLVector4*)(base + mOffsets[TYPE_CLOTHWEIGHT]));
631 }
632 }
633 else
634 {
635 LLVertexBuffer::setupVertexBuffer(data_mask);
636 }
637}
638