aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llface.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:50 -0500
committerJacek Antonelli2008-08-15 23:44:50 -0500
commit89fe5dab825a62a0e3fd8d248cbc91c65eb2a426 (patch)
treebcff14b7888d04a2fec799c59369f6095224bd08 /linden/indra/newview/llface.cpp
parentSecond Life viewer sources 1.13.3.2 (diff)
downloadmeta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.zip
meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.gz
meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.bz2
meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.xz
Second Life viewer sources 1.14.0.0
Diffstat (limited to 'linden/indra/newview/llface.cpp')
-rw-r--r--linden/indra/newview/llface.cpp1460
1 files changed, 519 insertions, 941 deletions
diff --git a/linden/indra/newview/llface.cpp b/linden/indra/newview/llface.cpp
index a6de94b..e46fcd3 100644
--- a/linden/indra/newview/llface.cpp
+++ b/linden/indra/newview/llface.cpp
@@ -29,13 +29,13 @@
29 29
30#include "lldrawable.h" // lldrawable needs to be included before llface 30#include "lldrawable.h" // lldrawable needs to be included before llface
31#include "llface.h" 31#include "llface.h"
32#include "llviewertextureanim.h"
32 33
33#include "llviewercontrol.h" 34#include "llviewercontrol.h"
34#include "llvolume.h" 35#include "llvolume.h"
35#include "m3math.h" 36#include "m3math.h"
36#include "v3color.h" 37#include "v3color.h"
37 38
38#include "llagparray.h"
39#include "lldrawpoolsimple.h" 39#include "lldrawpoolsimple.h"
40#include "lldrawpoolbump.h" 40#include "lldrawpoolbump.h"
41#include "llgl.h" 41#include "llgl.h"
@@ -47,8 +47,6 @@
47#include "llvovolume.h" 47#include "llvovolume.h"
48#include "pipeline.h" 48#include "pipeline.h"
49 49
50#include "llagparray.inl"
51
52#define LL_MAX_INDICES_COUNT 1000000 50#define LL_MAX_INDICES_COUNT 1000000
53 51
54extern BOOL gPickFaces; 52extern BOOL gPickFaces;
@@ -137,25 +135,23 @@ void cylindricalProjection(LLVector2 &tc, const LLVolumeFace::VertexData &vd, co
137 135
138void LLFace::init(LLDrawable* drawablep, LLViewerObject* objp) 136void LLFace::init(LLDrawable* drawablep, LLViewerObject* objp)
139{ 137{
140 mGeneration = DIRTY; 138 mLastUpdateTime = gFrameTimeSeconds;
139 mVSize = 0.f;
140 mPixelArea = 1024.f;
141 mState = GLOBAL; 141 mState = GLOBAL;
142 mDrawPoolp = NULL; 142 mDrawPoolp = NULL;
143 mPoolType = 0;
143 mGeomIndex = -1; 144 mGeomIndex = -1;
144 mSkipRender = FALSE;
145 mNextFace = NULL;
146 // mCenterLocal 145 // mCenterLocal
147 // mCenterAgent 146 // mCenterAgent
148 mDistance = 0.f; 147 mDistance = 0.f;
149 148
150 mPrimType = LLTriangles;
151 mGeomCount = 0; 149 mGeomCount = 0;
152 mIndicesCount = 0; 150 mIndicesCount = 0;
153 mIndicesIndex = -1; 151 mIndicesIndex = -1;
154 mTexture = NULL; 152 mTexture = NULL;
155 mTEOffset = -1; 153 mTEOffset = -1;
156 154
157 mBackupMem = NULL;
158
159 setDrawable(drawablep); 155 setDrawable(drawablep);
160 mVObjp = objp; 156 mVObjp = objp;
161 157
@@ -163,6 +159,12 @@ void LLFace::init(LLDrawable* drawablep, LLViewerObject* objp)
163 mAlphaFade = 0.f; 159 mAlphaFade = 0.f;
164 160
165 mFaceColor = LLColor4(1,0,0,1); 161 mFaceColor = LLColor4(1,0,0,1);
162
163 mLastVertexBuffer = mVertexBuffer;
164 mLastGeomCount = mGeomCount;
165 mLastGeomIndex = mGeomIndex;
166 mLastIndicesCount = mIndicesCount;
167 mLastIndicesIndex = mIndicesIndex;
166} 168}
167 169
168 170
@@ -176,11 +178,6 @@ void LLFace::destroy()
176 mDrawPoolp->removeFace(this); 178 mDrawPoolp->removeFace(this);
177 mDrawPoolp = NULL; 179 mDrawPoolp = NULL;
178 } 180 }
179
180 // Remove light and blocker list references
181
182 delete[] mBackupMem;
183 mBackupMem = NULL;
184} 181}
185 182
186 183
@@ -194,13 +191,7 @@ void LLFace::setWorldMatrix(const LLMatrix4 &mat)
194 llerrs << "Faces on this drawable are not independently modifiable\n" << llendl; 191 llerrs << "Faces on this drawable are not independently modifiable\n" << llendl;
195} 192}
196 193
197 194void LLFace::setPool(LLFacePool* new_pool, LLViewerImage *texturep)
198void LLFace::setDirty()
199{
200 mGeneration = DIRTY;
201}
202
203void LLFace::setPool(LLDrawPool* new_pool, LLViewerImage *texturep)
204{ 195{
205 LLMemType mt1(LLMemType::MTYPE_DRAWABLE); 196 LLMemType mt1(LLMemType::MTYPE_DRAWABLE);
206 197
@@ -215,22 +206,12 @@ void LLFace::setPool(LLDrawPool* new_pool, LLViewerImage *texturep)
215 if (mDrawPoolp) 206 if (mDrawPoolp)
216 { 207 {
217 mDrawPoolp->removeFace(this); 208 mDrawPoolp->removeFace(this);
218 mSkipRender = FALSE;
219 mNextFace = NULL;
220 209
221 // Invalidate geometry (will get rebuilt next frame)
222 setDirty();
223 if (mDrawablep) 210 if (mDrawablep)
224 { 211 {
225 gPipeline.markRebuild(mDrawablep, LLDrawable::REBUILD_ALL, TRUE); 212 gPipeline.markRebuild(mDrawablep, LLDrawable::REBUILD_ALL, TRUE);
226 } 213 }
227 } 214 }
228 if (isState(BACKLIST))
229 {
230 delete[] mBackupMem;
231 mBackupMem = NULL;
232 clearState(BACKLIST);
233 }
234 mGeomIndex = -1; 215 mGeomIndex = -1;
235 216
236 // Add to new pool 217 // Add to new pool
@@ -239,7 +220,6 @@ void LLFace::setPool(LLDrawPool* new_pool, LLViewerImage *texturep)
239 new_pool->addFace(this); 220 new_pool->addFace(this);
240 } 221 }
241 mDrawPoolp = new_pool; 222 mDrawPoolp = new_pool;
242
243 } 223 }
244 mTexture = texturep; 224 mTexture = texturep;
245} 225}
@@ -268,91 +248,12 @@ void LLFace::setDrawable(LLDrawable *drawable)
268 mXform = &drawable->mXform; 248 mXform = &drawable->mXform;
269} 249}
270 250
271S32 LLFace::allocBackupMem()
272{
273 LLMemType mt1(LLMemType::MTYPE_DRAWABLE);
274
275 S32 size = 0;
276 size += mIndicesCount * 4;
277 size += mGeomCount * mDrawPoolp->getStride();
278
279 if (mDrawPoolp->mDataMaskNIL & LLDrawPool::DATA_VERTEX_WEIGHTS_MASK)
280 {
281 size += mGeomCount * mDrawPoolp->sDataSizes[LLDrawPool::DATA_VERTEX_WEIGHTS];
282 }
283
284 if (mDrawPoolp->mDataMaskNIL & LLDrawPool::DATA_CLOTHING_WEIGHTS_MASK)
285 {
286 size += mGeomCount * mDrawPoolp->sDataSizes[LLDrawPool::DATA_CLOTHING_WEIGHTS];
287 }
288
289 delete[] mBackupMem;
290 mBackupMem = new U8[size];
291 return size;
292}
293
294
295void LLFace::setSize(const S32 num_vertices, const S32 num_indices) 251void LLFace::setSize(const S32 num_vertices, const S32 num_indices)
296{ 252{
297 LLMemType mt1(LLMemType::MTYPE_DRAWABLE); 253 LLMemType mt1(LLMemType::MTYPE_DRAWABLE);
298 254
299 if (getState() & SHARED_GEOM) 255 mGeomCount = num_vertices;
300 { 256 mIndicesCount = num_indices;
301 mGeomCount = num_vertices;
302 mIndicesCount = num_indices;
303 return; // Shared, don't allocate or do anything with memory
304 }
305 if (num_vertices != (S32)mGeomCount || num_indices != (S32)mIndicesCount)
306 {
307 setDirty();
308
309 delete[] mBackupMem;
310 mBackupMem = NULL;
311 clearState(BACKLIST);
312
313 mGeomCount = num_vertices;
314 mIndicesCount = num_indices;
315 }
316
317}
318
319BOOL LLFace::reserveIfNeeded()
320{
321 LLMemType mt1(LLMemType::MTYPE_DRAWABLE);
322
323 if (getDirty())
324 {
325 if (isState(BACKLIST))
326 {
327 llwarns << "Reserve on backlisted object!" << llendl;
328 }
329
330 if (0 == mGeomCount)
331 {
332 //llwarns << "Reserving zero bytes for face!" << llendl;
333 mGeomCount = 0;
334 mIndicesCount = 0;
335 return FALSE;
336 }
337
338 mGeomIndex = mDrawPoolp->reserveGeom(mGeomCount);
339 // (reserveGeom() always returns a valid index)
340 mIndicesIndex = mDrawPoolp->reserveInd (mIndicesCount);
341 mGeneration = mDrawPoolp->mGeneration;
342 }
343
344 return TRUE;
345}
346
347void LLFace::unReserve()
348{
349 LLMemType mt1(LLMemType::MTYPE_DRAWABLE);
350
351 if (!(isState(SHARED_GEOM)))
352 {
353 mGeomIndex = mDrawPoolp->unReserveGeom(mGeomIndex, mGeomCount);
354 mIndicesIndex = mDrawPoolp->unReserveInd(mIndicesIndex, mIndicesCount);
355 }
356} 257}
357 258
358//============================================================================ 259//============================================================================
@@ -366,55 +267,22 @@ S32 LLFace::getGeometryAvatar(
366 LLStrider<LLVector4> &clothing_weights) 267 LLStrider<LLVector4> &clothing_weights)
367{ 268{
368 LLMemType mt1(LLMemType::MTYPE_DRAWABLE); 269 LLMemType mt1(LLMemType::MTYPE_DRAWABLE);
369
370 if (mGeomCount <= 0)
371 {
372 return -1;
373 }
374
375 if (isState(BACKLIST))
376 {
377 if (!mBackupMem)
378 {
379 llerrs << "No backup memory for backlist" << llendl;
380 }
381 270
382 vertices = (LLVector3*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_VERTICES]); 271 if (mVertexBuffer.notNull())
383 normals = (LLVector3*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_NORMALS]); 272 {
384 binormals = (LLVector3*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_BINORMALS]); 273 mVertexBuffer->getVertexStrider (vertices, mGeomIndex);
385 tex_coords = (LLVector2*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_TEX_COORDS0]); 274 mVertexBuffer->getNormalStrider (normals, mGeomIndex);
386 clothing_weights = (LLVector4*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_CLOTHING_WEIGHTS]); 275 mVertexBuffer->getBinormalStrider (binormals, mGeomIndex);
387 vertex_weights = (F32*)(mBackupMem + (4 * mIndicesCount) + (mGeomCount * mDrawPoolp->getStride())); 276 mVertexBuffer->getTexCoordStrider (tex_coords, mGeomIndex);
388 tex_coords.setStride( mDrawPoolp->getStride()); 277 mVertexBuffer->getWeightStrider(vertex_weights, mGeomIndex);
389 vertices.setStride( mDrawPoolp->getStride()); 278 mVertexBuffer->getClothWeightStrider(clothing_weights, mGeomIndex);
390 normals.setStride( mDrawPoolp->getStride());
391 binormals.setStride( mDrawPoolp->getStride());
392 clothing_weights.setStride( mDrawPoolp->getStride());
393
394 return 0;
395 } 279 }
396 else 280 else
397 { 281 {
398 if (!reserveIfNeeded()) 282 mGeomIndex = -1;
399 {
400 return -1;
401 }
402
403 llassert(mGeomIndex >= 0);
404 llassert(mIndicesIndex >= 0);
405
406 mDrawPoolp->getVertexStrider (vertices, mGeomIndex);
407 mDrawPoolp->getNormalStrider (normals, mGeomIndex);
408 mDrawPoolp->getBinormalStrider (binormals, mGeomIndex);
409 mDrawPoolp->getTexCoordStrider (tex_coords, mGeomIndex);
410 mDrawPoolp->getVertexWeightStrider(vertex_weights, mGeomIndex);
411 mDrawPoolp->getClothingWeightStrider(clothing_weights, mGeomIndex);
412
413 mDrawPoolp->setDirty();
414
415 llassert(mGeomIndex >= 0);
416 return mGeomIndex;
417 } 283 }
284
285 return mGeomIndex;
418} 286}
419 287
420S32 LLFace::getGeometryTerrain( 288S32 LLFace::getGeometryTerrain(
@@ -423,64 +291,29 @@ S32 LLFace::getGeometryTerrain(
423 LLStrider<LLColor4U> &colors, 291 LLStrider<LLColor4U> &colors,
424 LLStrider<LLVector2> &texcoords0, 292 LLStrider<LLVector2> &texcoords0,
425 LLStrider<LLVector2> &texcoords1, 293 LLStrider<LLVector2> &texcoords1,
426 U32 *&indicesp) 294 LLStrider<U32> &indicesp)
427{ 295{
428 LLMemType mt1(LLMemType::MTYPE_DRAWABLE); 296 LLMemType mt1(LLMemType::MTYPE_DRAWABLE);
429 297
430 if (mGeomCount <= 0) 298 if (mVertexBuffer.notNull())
431 { 299 {
432 return -1; 300 mVertexBuffer->getVertexStrider(vertices, mGeomIndex);
433 } 301 mVertexBuffer->getNormalStrider(normals, mGeomIndex);
434 302 mVertexBuffer->getColorStrider(colors, mGeomIndex);
435 if (isState(BACKLIST)) 303 mVertexBuffer->getTexCoordStrider(texcoords0, mGeomIndex);
436 { 304 mVertexBuffer->getTexCoord2Strider(texcoords1, mGeomIndex);
437 if (!mBackupMem) 305 mVertexBuffer->getIndexStrider(indicesp, mIndicesIndex);
438 {
439 printDebugInfo();
440 llerrs << "No backup memory for face" << llendl;
441 }
442 vertices = (LLVector3*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_VERTICES]);
443 normals = (LLVector3*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_NORMALS]);
444 colors = (LLColor4U*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_COLORS]);
445 texcoords0= (LLVector2*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_TEX_COORDS0]);
446 texcoords1= (LLVector2*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_TEX_COORDS1]);
447 texcoords0.setStride(mDrawPoolp->getStride());
448 texcoords1.setStride(mDrawPoolp->getStride());
449 vertices.setStride( mDrawPoolp->getStride());
450 normals.setStride( mDrawPoolp->getStride());
451 colors.setStride( mDrawPoolp->getStride());
452 indicesp = (U32*)mBackupMem;
453
454 return 0;
455 } 306 }
456 else 307 else
457 { 308 {
458 if (!reserveIfNeeded()) 309 mGeomIndex = -1;
459 {
460 llinfos << "Get geometry failed!" << llendl;
461 return -1;
462 }
463
464 llassert(mGeomIndex >= 0);
465 llassert(mIndicesIndex >= 0);
466
467 mDrawPoolp->getVertexStrider(vertices, mGeomIndex);
468 mDrawPoolp->getNormalStrider(normals, mGeomIndex);
469 mDrawPoolp->getColorStrider(colors, mGeomIndex);
470 mDrawPoolp->getTexCoordStrider(texcoords0, mGeomIndex, 0);
471 mDrawPoolp->getTexCoordStrider(texcoords1, mGeomIndex, 1);
472
473 indicesp = mDrawPoolp->getIndices(mIndicesIndex);
474
475 mDrawPoolp->setDirty();
476
477 llassert(mGeomIndex >= 0);
478 return mGeomIndex;
479 } 310 }
311
312 return mGeomIndex;
480} 313}
481 314
482S32 LLFace::getGeometry(LLStrider<LLVector3> &vertices, LLStrider<LLVector3> &normals, 315S32 LLFace::getGeometry(LLStrider<LLVector3> &vertices, LLStrider<LLVector3> &normals,
483 LLStrider<LLVector2> &tex_coords, U32 *&indicesp) 316 LLStrider<LLVector2> &tex_coords, LLStrider<U32> &indicesp)
484{ 317{
485 LLMemType mt1(LLMemType::MTYPE_DRAWABLE); 318 LLMemType mt1(LLMemType::MTYPE_DRAWABLE);
486 319
@@ -489,55 +322,31 @@ S32 LLFace::getGeometry(LLStrider<LLVector3> &vertices, LLStrider<LLVector3> &no
489 return -1; 322 return -1;
490 } 323 }
491 324
492 if (isState(BACKLIST)) 325 if (mVertexBuffer.notNull())
493 { 326 {
494 if (!mBackupMem) 327 mVertexBuffer->getVertexStrider(vertices, mGeomIndex);
328 if (mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_NORMAL))
329 {
330 mVertexBuffer->getNormalStrider(normals, mGeomIndex);
331 }
332 if (mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_TEXCOORD))
495 { 333 {
496 printDebugInfo(); 334 mVertexBuffer->getTexCoordStrider(tex_coords, mGeomIndex);
497 llerrs << "No backup memory for face" << llendl;
498 } 335 }
499 vertices = (LLVector3*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_VERTICES]);
500 normals = (LLVector3*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_NORMALS]);
501 tex_coords= (LLVector2*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_TEX_COORDS0]);
502 tex_coords.setStride(mDrawPoolp->getStride());
503 vertices.setStride( mDrawPoolp->getStride());
504 normals.setStride( mDrawPoolp->getStride());
505 indicesp = (U32*)mBackupMem;
506 336
507 return 0; 337 mVertexBuffer->getIndexStrider(indicesp, mIndicesIndex);
508 } 338 }
509 else 339 else
510 { 340 {
511 if (!reserveIfNeeded()) 341 mGeomIndex = -1;
512 {
513 return -1;
514 }
515
516 llassert(mGeomIndex >= 0);
517 llassert(mIndicesIndex >= 0);
518
519 mDrawPoolp->getVertexStrider(vertices, mGeomIndex);
520 if (mDrawPoolp->mDataMaskIL & LLDrawPool::DATA_NORMALS_MASK)
521 {
522 mDrawPoolp->getNormalStrider(normals, mGeomIndex);
523 }
524 if (mDrawPoolp->mDataMaskIL & LLDrawPool::DATA_TEX_COORDS0_MASK)
525 {
526 mDrawPoolp->getTexCoordStrider(tex_coords, mGeomIndex);
527 }
528
529 indicesp =mDrawPoolp->getIndices (mIndicesIndex);
530
531 mDrawPoolp->setDirty();
532
533 llassert(mGeomIndex >= 0);
534 return mGeomIndex;
535 } 342 }
343
344 return mGeomIndex;
536} 345}
537 346
538S32 LLFace::getGeometryColors(LLStrider<LLVector3> &vertices, LLStrider<LLVector3> &normals, 347S32 LLFace::getGeometryColors(LLStrider<LLVector3> &vertices, LLStrider<LLVector3> &normals,
539 LLStrider<LLVector2> &tex_coords, LLStrider<LLColor4U> &colors, 348 LLStrider<LLVector2> &tex_coords, LLStrider<LLColor4U> &colors,
540 U32 *&indicesp) 349 LLStrider<U32> &indicesp)
541{ 350{
542 S32 res = getGeometry(vertices, normals, tex_coords, indicesp); 351 S32 res = getGeometry(vertices, normals, tex_coords, indicesp);
543 if (res >= 0) 352 if (res >= 0)
@@ -547,95 +356,25 @@ S32 LLFace::getGeometryColors(LLStrider<LLVector3> &vertices, LLStrider<LLVector
547 return res; 356 return res;
548} 357}
549 358
550S32 LLFace::getGeometryMultiTexture( 359void LLFace::updateCenterAgent()
551 LLStrider<LLVector3> &vertices,
552 LLStrider<LLVector3> &normals,
553 LLStrider<LLVector3> &binormals,
554 LLStrider<LLVector2> &tex_coords0,
555 LLStrider<LLVector2> &tex_coords1,
556 U32 *&indicesp)
557{ 360{
558 LLMemType mt1(LLMemType::MTYPE_DRAWABLE); 361 if (mDrawablep->isActive())
559
560 if (mGeomCount <= 0)
561 { 362 {
562 return -1; 363 mCenterAgent = mCenterLocal * getRenderMatrix();
563 }
564
565 if (isState(BACKLIST))
566 {
567 if (!mBackupMem)
568 {
569 printDebugInfo();
570 llerrs << "No backup memory for face" << llendl;
571 }
572 vertices = (LLVector3*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_VERTICES]);
573 normals = (LLVector3*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_NORMALS]);
574 tex_coords0 = (LLVector2*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_TEX_COORDS0]);
575 tex_coords0.setStride( mDrawPoolp->getStride() );
576 vertices.setStride( mDrawPoolp->getStride() );
577 normals.setStride( mDrawPoolp->getStride() );
578 if (mDrawPoolp->mDataMaskIL & LLDrawPool::DATA_BINORMALS_MASK)
579 {
580 binormals = (LLVector3*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_BINORMALS]);
581 binormals.setStride( mDrawPoolp->getStride() );
582 }
583 if (mDrawPoolp->mDataMaskIL & LLDrawPool::DATA_TEX_COORDS1_MASK)
584 {
585 tex_coords1 = (LLVector2*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_TEX_COORDS1]);
586 tex_coords1.setStride( mDrawPoolp->getStride() );
587 }
588 indicesp = (U32*)mBackupMem;
589
590 return 0;
591 } 364 }
592 else 365 else
593 { 366 {
594 if (!reserveIfNeeded()) 367 mCenterAgent = mCenterLocal;
595 {
596 return -1;
597 }
598
599 llassert(mGeomIndex >= 0);
600 llassert(mIndicesIndex >= 0);
601
602 mDrawPoolp->getVertexStrider(vertices, mGeomIndex);
603 if (mDrawPoolp->mDataMaskIL & LLDrawPool::DATA_NORMALS_MASK)
604 {
605 mDrawPoolp->getNormalStrider(normals, mGeomIndex);
606 }
607 if (mDrawPoolp->mDataMaskIL & LLDrawPool::DATA_TEX_COORDS0_MASK)
608 {
609 mDrawPoolp->getTexCoordStrider(tex_coords0, mGeomIndex);
610 }
611 if (mDrawPoolp->mDataMaskIL & LLDrawPool::DATA_BINORMALS_MASK)
612 {
613 mDrawPoolp->getBinormalStrider(binormals, mGeomIndex);
614 }
615 if (mDrawPoolp->mDataMaskIL & LLDrawPool::DATA_TEX_COORDS1_MASK)
616 {
617 mDrawPoolp->getTexCoordStrider(tex_coords1, mGeomIndex, 1);
618 }
619 indicesp = mDrawPoolp->getIndices(mIndicesIndex);
620
621 mDrawPoolp->setDirty();
622
623 llassert(mGeomIndex >= 0);
624 return mGeomIndex;
625 } 368 }
626} 369}
627 370
628void LLFace::updateCenterAgent() 371void LLFace::renderForSelect(U32 data_mask)
629{
630 mCenterAgent = mCenterLocal * getRenderMatrix();
631}
632
633void LLFace::renderForSelect() const
634{ 372{
635 if(mGeomIndex < 0 || mDrawablep.isNull()) 373 if(mGeomIndex < 0 || mDrawablep.isNull() || mVertexBuffer.isNull())
636 { 374 {
637 return; 375 return;
638 } 376 }
377
639 if (mVObjp->mGLName) 378 if (mVObjp->mGLName)
640 { 379 {
641 S32 name = mVObjp->mGLName; 380 S32 name = mVObjp->mGLName;
@@ -649,47 +388,25 @@ void LLFace::renderForSelect() const
649#endif 388#endif
650 glColor4ubv(color.mV); 389 glColor4ubv(color.mV);
651 390
652 if (mVObjp->getPCode() == LL_PCODE_VOLUME) 391 if (!getPool())
653 { 392 {
654 LLVOVolume *volp; 393 switch (getPoolType())
655 volp = (LLVOVolume *)(LLViewerObject*)mVObjp;
656 if (volp->getNumFaces() == 1 && !volp->getVolumeChanged())
657 { 394 {
658 // We need to special case the coalesced face model. 395 case LLDrawPool::POOL_ALPHA:
659 S32 num_vfs = volp->getVolume()->getNumFaces(); 396 getTexture()->bind();
660 S32 offset = 0; 397 break;
661 S32 i; 398 default:
662 399 LLImageGL::unbindTexture(0);
663 for (i = 0; i < num_vfs; i++) 400 break;
664 {
665 if (gPickFaces)
666 {
667 // mask off high 4 bits (16 total possible faces)
668 color.mV[0] &= 0x0f;
669 color.mV[0] |= (i & 0x0f) << 4;
670 glColor4ubv(color.mV);
671 }
672 S32 count = volp->getVolume()->getVolumeFace(i).mIndices.size();
673 if (isState(GLOBAL))
674 {
675 glDrawElements(mPrimType, count, GL_UNSIGNED_INT, getRawIndices() + offset);
676 }
677 else
678 {
679 glPushMatrix();
680 glMultMatrixf((float*)getRenderMatrix().mMatrix);
681 glDrawElements(mPrimType, count, GL_UNSIGNED_INT, getRawIndices() + offset);
682 glPopMatrix();
683 }
684 offset += count;
685 }
686 // We're done, return.
687 return;
688 } 401 }
689
690 // We don't have coalesced faces, do this the normal way.
691 } 402 }
692 403
404 mVertexBuffer->setBuffer(data_mask);
405#if !LL_RELEASE_FOR_DOWNLOAD
406 LLGLState::checkClientArrays(data_mask);
407#endif
408 U32* indicesp = (U32*) mVertexBuffer->getIndicesPointer() + mIndicesIndex;
409
693 if (gPickFaces && mTEOffset != -1) 410 if (gPickFaces && mTEOffset != -1)
694 { 411 {
695 // mask off high 4 bits (16 total possible faces) 412 // mask off high 4 bits (16 total possible faces)
@@ -702,13 +419,13 @@ void LLFace::renderForSelect() const
702 { 419 {
703 if (isState(GLOBAL)) 420 if (isState(GLOBAL))
704 { 421 {
705 glDrawElements(mPrimType, mIndicesCount, GL_UNSIGNED_INT, getRawIndices()); 422 glDrawElements(GL_TRIANGLES, mIndicesCount, GL_UNSIGNED_INT, indicesp);
706 } 423 }
707 else 424 else
708 { 425 {
709 glPushMatrix(); 426 glPushMatrix();
710 glMultMatrixf((float*)getRenderMatrix().mMatrix); 427 glMultMatrixf((float*)getRenderMatrix().mMatrix);
711 glDrawElements(mPrimType, mIndicesCount, GL_UNSIGNED_INT, getRawIndices()); 428 glDrawElements(GL_TRIANGLES, mIndicesCount, GL_UNSIGNED_INT, indicesp);
712 glPopMatrix(); 429 glPopMatrix();
713 } 430 }
714 } 431 }
@@ -716,13 +433,13 @@ void LLFace::renderForSelect() const
716 { 433 {
717 if (isState(GLOBAL)) 434 if (isState(GLOBAL))
718 { 435 {
719 glDrawArrays(mPrimType, mGeomIndex, mGeomCount); 436 glDrawArrays(GL_TRIANGLES, mGeomIndex, mGeomCount);
720 } 437 }
721 else 438 else
722 { 439 {
723 glPushMatrix(); 440 glPushMatrix();
724 glMultMatrixf((float*)getRenderMatrix().mMatrix); 441 glMultMatrixf((float*)getRenderMatrix().mMatrix);
725 glDrawArrays(mPrimType, mGeomIndex, mGeomCount); 442 glDrawArrays(GL_TRIANGLES, mGeomIndex, mGeomCount);
726 glPopMatrix(); 443 glPopMatrix();
727 } 444 }
728 } 445 }
@@ -731,11 +448,12 @@ void LLFace::renderForSelect() const
731 448
732void LLFace::renderSelected(LLImageGL *imagep, const LLColor4& color, const S32 offset, const S32 count) 449void LLFace::renderSelected(LLImageGL *imagep, const LLColor4& color, const S32 offset, const S32 count)
733{ 450{
734 if(mGeomIndex < 0 || mDrawablep.isNull()) 451 if(mGeomIndex < 0 || mDrawablep.isNull() || mVertexBuffer.isNull())
735 { 452 {
736 return; 453 return;
737 } 454 }
738 if (mGeomCount > 0) 455
456 if (mGeomCount > 0 && mIndicesCount > 0)
739 { 457 {
740 LLGLSPipelineAlpha gls_pipeline_alpha; 458 LLGLSPipelineAlpha gls_pipeline_alpha;
741 glColor4fv(color.mV); 459 glColor4fv(color.mV);
@@ -748,110 +466,27 @@ void LLFace::renderSelected(LLImageGL *imagep, const LLColor4& color, const S32
748 glMultMatrixf((float*)getRenderMatrix().mMatrix); 466 glMultMatrixf((float*)getRenderMatrix().mMatrix);
749 } 467 }
750 468
751 if (sSafeRenderSelect) 469 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
752 { 470 glEnableClientState(GL_VERTEX_ARRAY);
753 glBegin(mPrimType); 471 glEnableClientState(GL_NORMAL_ARRAY);
754 if (count)
755 {
756 for (S32 i = offset; i < offset + count; i++)
757 {
758 LLVector2 tc = mDrawPoolp->getTexCoord(mDrawPoolp->getIndex(getIndicesStart() + i), 0);
759 glTexCoord2fv(tc.mV);
760 LLVector3 normal = mDrawPoolp->getNormal(mDrawPoolp->getIndex(getIndicesStart() + i));
761 glNormal3fv(normal.mV);
762 LLVector3 vertex = mDrawPoolp->getVertex(mDrawPoolp->getIndex(getIndicesStart() + i));
763 glVertex3fv(vertex.mV);
764 }
765 }
766 else
767 {
768 for (U32 i = 0; i < getIndicesCount(); i++)
769 {
770 LLVector2 tc = mDrawPoolp->getTexCoord(mDrawPoolp->getIndex(getIndicesStart() + i), 0);
771 glTexCoord2fv(tc.mV);
772 LLVector3 normal = mDrawPoolp->getNormal(mDrawPoolp->getIndex(getIndicesStart() + i));
773 glNormal3fv(normal.mV);
774 LLVector3 vertex = mDrawPoolp->getVertex(mDrawPoolp->getIndex(getIndicesStart() + i));
775 glVertex3fv(vertex.mV);
776 }
777 }
778 glEnd();
779
780 if( gSavedSettings.getBOOL("ShowTangentBasis") )
781 {
782 S32 start;
783 S32 end;
784 if (count)
785 {
786 start = offset;
787 end = offset + count;
788 }
789 else
790 {
791 start = 0;
792 end = getIndicesCount();
793 }
794 472
795 LLGLSNoTexture gls_no_texture; 473 mVertexBuffer->setBuffer(LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL | LLVertexBuffer::MAP_TEXCOORD);
796 glColor4f(1, 1, 1, 1); 474#if !LL_RELEASE_FOR_DOWNLOAD
797 glBegin(GL_LINES); 475 LLGLState::checkClientArrays(LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL | LLVertexBuffer::MAP_TEXCOORD);
798 for (S32 i = start; i < end; i++) 476#endif
799 { 477 U32* indicesp = ((U32*) mVertexBuffer->getIndicesPointer()) + mIndicesIndex;
800 LLVector3 vertex = mDrawPoolp->getVertex(mDrawPoolp->getIndex(getIndicesStart() + i));
801 glVertex3fv(vertex.mV);
802 LLVector3 normal = mDrawPoolp->getNormal(mDrawPoolp->getIndex(getIndicesStart() + i));
803 glVertex3fv( (vertex + normal * 0.1f).mV );
804 }
805 glEnd();
806 478
807 if (mDrawPoolp->mDataMaskIL & LLDrawPool::DATA_BINORMALS_MASK) 479 if (count)
808 { 480 {
809 glColor4f(0, 1, 0, 1); 481 glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_INT, indicesp + offset);
810 glBegin(GL_LINES);
811 for (S32 i = start; i < end; i++)
812 {
813 LLVector3 vertex = mDrawPoolp->getVertex(mDrawPoolp->getIndex(getIndicesStart() + i));
814 glVertex3fv(vertex.mV);
815 LLVector3 binormal = mDrawPoolp->getBinormal(mDrawPoolp->getIndex(getIndicesStart() + i));
816 glVertex3fv( (vertex + binormal * 0.1f).mV );
817 }
818 glEnd();
819 }
820 }
821 } 482 }
822 else 483 else
823 { 484 {
824 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 485 glDrawElements(GL_TRIANGLES, mIndicesCount, GL_UNSIGNED_INT, indicesp);
825 glEnableClientState(GL_VERTEX_ARRAY);
826 glEnableClientState(GL_NORMAL_ARRAY);
827 if (count)
828 {
829 if (mIndicesCount > 0)
830 {
831 glDrawElements(mPrimType, count, GL_UNSIGNED_INT, getRawIndices() + offset);
832 }
833 else
834 {
835 llerrs << "Rendering non-indexed volume face!" << llendl;
836 glDrawArrays(mPrimType, mGeomIndex, mGeomCount);
837 }
838 }
839 else
840 {
841 if (mIndicesCount > 0)
842 {
843 glDrawElements(mPrimType, mIndicesCount, GL_UNSIGNED_INT, getRawIndices());
844 }
845 else
846 {
847 glDrawArrays(mPrimType, mGeomIndex, mGeomCount);
848 }
849 }
850 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
851 glDisableClientState(GL_VERTEX_ARRAY);
852 glDisableClientState(GL_NORMAL_ARRAY);
853 } 486 }
854 487 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
488 glDisableClientState(GL_NORMAL_ARRAY);
489
855 if (!isState(GLOBAL)) 490 if (!isState(GLOBAL))
856 { 491 {
857 // Restore the tranform for non-global objects 492 // Restore the tranform for non-global objects
@@ -862,6 +497,7 @@ void LLFace::renderSelected(LLImageGL *imagep, const LLColor4& color, const S32
862 497
863void LLFace::renderSelectedUV(const S32 offset, const S32 count) 498void LLFace::renderSelectedUV(const S32 offset, const S32 count)
864{ 499{
500#if 0
865 LLUUID uv_img_red_blue_id(gViewerArt.getString("uv_test1.tga")); 501 LLUUID uv_img_red_blue_id(gViewerArt.getString("uv_test1.tga"));
866 LLUUID uv_img_green_id(gViewerArt.getString("uv_test2.tga")); 502 LLUUID uv_img_green_id(gViewerArt.getString("uv_test2.tga"));
867 LLViewerImage* red_blue_imagep = gImageList.getImage(uv_img_red_blue_id, TRUE, TRUE); 503 LLViewerImage* red_blue_imagep = gImageList.getImage(uv_img_red_blue_id, TRUE, TRUE);
@@ -911,7 +547,7 @@ void LLFace::renderSelectedUV(const S32 offset, const S32 count)
911 glPolygonOffset(factor, bias); 547 glPolygonOffset(factor, bias);
912 if (sSafeRenderSelect) 548 if (sSafeRenderSelect)
913 { 549 {
914 glBegin(mPrimType); 550 glBegin(GL_TRIANGLES);
915 if (count) 551 if (count)
916 { 552 {
917 for (S32 i = offset; i < offset + count; i++) 553 for (S32 i = offset; i < offset + count; i++)
@@ -943,7 +579,7 @@ void LLFace::renderSelectedUV(const S32 offset, const S32 count)
943 { 579 {
944 if (mIndicesCount > 0) 580 if (mIndicesCount > 0)
945 { 581 {
946 glDrawElements(mPrimType, count, GL_UNSIGNED_INT, getRawIndices() + offset); 582 glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_INT, getRawIndices() + offset);
947 } 583 }
948 else 584 else
949 { 585 {
@@ -955,15 +591,14 @@ void LLFace::renderSelectedUV(const S32 offset, const S32 count)
955 { 591 {
956 if (mIndicesCount > 0) 592 if (mIndicesCount > 0)
957 { 593 {
958 glDrawElements(mPrimType, mIndicesCount, GL_UNSIGNED_INT, getRawIndices()); 594 glDrawElements(GL_TRIANGLES, mIndicesCount, GL_UNSIGNED_INT, getRawIndices());
959 } 595 }
960 else 596 else
961 { 597 {
962 glDrawArrays(mPrimType, mGeomIndex, mGeomCount); 598 glDrawArrays(GL_TRIANGLES, mGeomIndex, mGeomCount);
963 } 599 }
964 } 600 }
965 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 601 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
966 glDisableClientState(GL_VERTEX_ARRAY);
967 } 602 }
968 603
969 glDisable(GL_POLYGON_OFFSET_FILL); 604 glDisable(GL_POLYGON_OFFSET_FILL);
@@ -984,12 +619,13 @@ void LLFace::renderSelectedUV(const S32 offset, const S32 count)
984 619
985 //restore blend func 620 //restore blend func
986 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 621 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
622#endif
987} 623}
988 624
989 625
990void LLFace::printDebugInfo() const 626void LLFace::printDebugInfo() const
991{ 627{
992 LLDrawPool *poolp = getPool(); 628 LLFacePool *poolp = getPool();
993 llinfos << "Object: " << getViewerObject()->mID << llendl; 629 llinfos << "Object: " << getViewerObject()->mID << llendl;
994 if (getDrawable()) 630 if (getDrawable())
995 { 631 {
@@ -1005,10 +641,6 @@ void LLFace::printDebugInfo() const
1005 } 641 }
1006 642
1007 llinfos << "Face: " << this << llendl; 643 llinfos << "Face: " << this << llendl;
1008 if (isState(BACKLIST))
1009 {
1010 llinfos << "Backlisted!" << llendl;
1011 }
1012 llinfos << "State: " << getState() << llendl; 644 llinfos << "State: " << getState() << llendl;
1013 llinfos << "Geom Index Data:" << llendl; 645 llinfos << "Geom Index Data:" << llendl;
1014 llinfos << "--------------------" << llendl; 646 llinfos << "--------------------" << llendl;
@@ -1037,7 +669,7 @@ void LLFace::printDebugInfo() const
1037 llinfos << "Incorrect number of pool references!" << llendl; 669 llinfos << "Incorrect number of pool references!" << llendl;
1038 } 670 }
1039 671
1040 672#if 0
1041 llinfos << "Indices:" << llendl; 673 llinfos << "Indices:" << llendl;
1042 llinfos << "--------------------" << llendl; 674 llinfos << "--------------------" << llendl;
1043 675
@@ -1058,149 +690,7 @@ void LLFace::printDebugInfo() const
1058 llinfos << mGeomIndex + i << ":" << poolp->getVertex(mGeomIndex + i) << llendl; 690 llinfos << mGeomIndex + i << ":" << poolp->getVertex(mGeomIndex + i) << llendl;
1059 } 691 }
1060 llinfos << llendl; 692 llinfos << llendl;
1061}
1062
1063S32 LLFace::backup()
1064{
1065 LLMemType mt1(LLMemType::MTYPE_DRAWABLE);
1066
1067 if (isState(BACKLIST))
1068 {
1069 llwarns << "Face is already backed up in LLFace::backup!" << llendl;
1070 return mGeomCount;
1071 }
1072 if (mGeomIndex < 0)
1073 {
1074 // flexible objects can cause this
1075 //llwarns << "No geometry to back-up" << llendl;
1076 return 0;
1077 }
1078
1079 S32 size = 0;
1080 if (!mBackupMem)
1081 {
1082 size = allocBackupMem();
1083 }
1084 else
1085 {
1086 llerrs << "Memory already backed up!" << llendl;
1087 }
1088
1089 // Need to flag this, because we can allocate a non-zero backup mem if we have indices and no geometry.
1090
1091 if (mGeomCount || mIndicesCount)
1092 {
1093 setState(BACKLIST);
1094#if !RELEASE_FOR_DOWNLOAD
1095 if (mGeomIndex < 0 || mIndicesIndex < 0)
1096 {
1097 llerrs << "LLFace::backup" << llendl;
1098 }
1099#endif 693#endif
1100
1101 U32 *backup = (U32*)mBackupMem;
1102 S32 stride = mDrawPoolp->getStride();
1103
1104 U32 *index = mDrawPoolp->getIndices(mIndicesIndex);
1105 for (U32 i=0;i<mIndicesCount;i++)
1106 {
1107 *backup++ = index[i] - mGeomIndex;
1108 index[i] = 0;
1109 }
1110
1111 if (!mGeomCount)
1112 {
1113 return mGeomCount;
1114 }
1115 //
1116 // Don't change the order of these unles you change the corresponding getGeometry calls that read out of
1117 // backup memory, and also the other of the backup/restore pair!
1118 //
1119 memcpy(backup, (mDrawPoolp->mMemory.getMem() + mGeomIndex * stride), mGeomCount * stride);
1120 backup += mGeomCount * stride / 4;
1121
1122 if (mDrawPoolp->mDataMaskNIL & LLDrawPool::DATA_CLOTHING_WEIGHTS_MASK)
1123 {
1124 memcpy(backup, &mDrawPoolp->getClothingWeight(mGeomIndex), mGeomCount * sizeof(LLVector4));
1125 backup += mGeomCount*4;
1126 }
1127
1128 if (mDrawPoolp->mDataMaskNIL & LLDrawPool::DATA_VERTEX_WEIGHTS_MASK)
1129 {
1130 memcpy(backup, &mDrawPoolp->getVertexWeight(mGeomIndex), mGeomCount * sizeof(F32));
1131 backup += mGeomCount;
1132 }
1133
1134 llassert((U8*)backup - mBackupMem == size);
1135
1136 unReserve();
1137 }
1138 return mGeomCount;
1139}
1140
1141void LLFace::restore()
1142{
1143 LLMemType mt1(LLMemType::MTYPE_DRAWABLE);
1144
1145 if (!isState(BACKLIST))
1146 {
1147 // flexible objects can cause this
1148// printDebugInfo();
1149// llwarns << "not backlisted for restore" << llendl;
1150 return;
1151 }
1152 if (!mGeomCount || !mBackupMem)
1153 {
1154 if (!mBackupMem)
1155 {
1156 printDebugInfo();
1157 llwarns << "no backmem for restore" << llendl;
1158 }
1159
1160 clearState(BACKLIST);
1161 return;
1162 }
1163
1164 S32 stride = mDrawPoolp->getStride();
1165 mGeomIndex = mDrawPoolp->reserveGeom(mGeomCount);
1166 mIndicesIndex = mDrawPoolp->reserveInd (mIndicesCount);
1167 mGeneration = mDrawPoolp->mGeneration;
1168
1169 llassert(mGeomIndex >= 0);
1170 llassert(mIndicesIndex >= 0);
1171
1172 U32 *backup = (U32*)mBackupMem;
1173 U32 *index = mDrawPoolp->getIndices(mIndicesIndex);
1174
1175 for (U32 i=0;i<mIndicesCount;i++)
1176 {
1177 S32 ind = mGeomIndex + *backup;
1178 index[i] = ind;
1179 backup++;
1180 }
1181
1182 mDrawPoolp->mMemory.copyToMem(mGeomIndex * stride, (U8 *)backup, mGeomCount * stride);
1183 backup += mGeomCount * stride / 4;
1184
1185 //
1186 // Don't change the order of these unles you change the corresponding getGeometry calls that read out of
1187 // backup memory, and also the other of the backup/restore pair!
1188 //
1189 if (mDrawPoolp->mDataMaskNIL & LLDrawPool::DATA_CLOTHING_WEIGHTS_MASK)
1190 {
1191 mDrawPoolp->mClothingWeights.copyToMem(mGeomIndex, (U8 *)backup, mGeomCount);
1192 backup += mGeomCount*4;
1193 }
1194
1195 if (mDrawPoolp->mDataMaskNIL & LLDrawPool::DATA_VERTEX_WEIGHTS_MASK)
1196 {
1197 mDrawPoolp->mWeights.copyToMem(mGeomIndex, (U8 *)backup, mGeomCount);
1198 backup += mGeomCount;
1199 }
1200
1201 delete[] mBackupMem;
1202 mBackupMem = NULL;
1203 clearState(BACKLIST);
1204} 694}
1205 695
1206// Transform the texture coordinates for this face. 696// Transform the texture coordinates for this face.
@@ -1232,48 +722,199 @@ static void xform(LLVector2 &tex_coord, F32 cosAng, F32 sinAng, F32 offS, F32 of
1232} 722}
1233 723
1234 724
1235BOOL LLFace::genVolumeTriangles(const LLVolume &volume, S32 f, 725BOOL LLFace::genVolumeBBoxes(const LLVolume &volume, S32 f,
1236 const LLMatrix4& mat, const LLMatrix3& inv_trans_mat, BOOL global_volume) 726 const LLMatrix4& mat_vert, const LLMatrix3& mat_normal, BOOL global_volume)
727{
728 LLMemType mt1(LLMemType::MTYPE_DRAWABLE);
729
730 const LLVolumeFace &face = volume.getVolumeFace(f);
731
732 //get bounding box
733 if (mDrawablep->isState(LLDrawable::REBUILD_VOLUME | LLDrawable::REBUILD_POSITION))
734 {
735 if (mDrawablep->isState(LLDrawable::REBUILD_VOLUME))
736 { //vertex buffer no longer valid
737 mVertexBuffer = NULL;
738 mLastVertexBuffer = NULL;
739 }
740
741 LLVector3 min,max;
742
743 min = face.mExtents[0];
744 max = face.mExtents[1];
745
746 //min, max are in volume space, convert to drawable render space
747 LLVector3 center = ((min + max) * 0.5f)*mat_vert;
748 LLVector3 size = ((max-min) * 0.5f);
749 if (!global_volume)
750 {
751 size.scaleVec(mDrawablep->getVObj()->getScale());
752 }
753 LLQuaternion rotation = LLQuaternion(mat_normal);
754
755 LLVector3 v[4];
756 //get 4 corners of bounding box
757 v[0] = (size * rotation);
758 v[1] = (LLVector3(-size.mV[0], -size.mV[1], size.mV[2]) * rotation);
759 v[2] = (LLVector3(size.mV[0], -size.mV[1], -size.mV[2]) * rotation);
760 v[3] = (LLVector3(-size.mV[0], size.mV[1], -size.mV[2]) * rotation);
761
762 LLVector3& newMin = mExtents[0];
763 LLVector3& newMax = mExtents[1];
764
765 newMin = newMax = center;
766
767 for (U32 i = 0; i < 4; i++)
768 {
769 for (U32 j = 0; j < 3; j++)
770 {
771 F32 delta = fabsf(v[i].mV[j]);
772 F32 min = center.mV[j] - delta;
773 F32 max = center.mV[j] + delta;
774
775 if (min < newMin.mV[j])
776 {
777 newMin.mV[j] = min;
778 }
779
780 if (max > newMax.mV[j])
781 {
782 newMax.mV[j] = max;
783 }
784 }
785 }
786
787 mCenterLocal = (newMin+newMax)*0.5f;
788 updateCenterAgent();
789 }
790
791 return TRUE;
792}
793
794
795BOOL LLFace::getGeometryVolume(const LLVolume& volume,
796 S32 f,
797 LLStrider<LLVector3>& vertices,
798 LLStrider<LLVector3>& normals,
799 LLStrider<LLVector2>& tex_coords,
800 LLStrider<LLVector2>& tex_coords2,
801 LLStrider<LLColor4U>& colors,
802 LLStrider<U32>& indicesp,
803 const LLMatrix4& mat_vert, const LLMatrix3& mat_normal,
804 U32& index_offset)
1237{ 805{
1238 const LLVolumeFace &vf = volume.getVolumeFace(f); 806 const LLVolumeFace &vf = volume.getVolumeFace(f);
1239 S32 num_vertices = (S32)vf.mVertices.size(); 807 S32 num_vertices = (S32)vf.mVertices.size();
1240 S32 num_indices = (S32)vf.mIndices.size(); 808 S32 num_indices = (S32)vf.mIndices.size();
1241 setSize(num_vertices, num_indices);
1242 809
1243 return genVolumeTriangles(volume, f, f, mat, inv_trans_mat, global_volume); 810 LLStrider<LLVector3> old_verts;
1244} 811 LLStrider<LLVector2> old_texcoords;
812 LLStrider<LLVector2> old_texcoords2;
813 LLStrider<LLVector3> old_normals;
814 LLStrider<LLColor4U> old_colors;
1245 815
1246BOOL LLFace::genVolumeTriangles(const LLVolume &volume, S32 fstart, S32 fend, 816 BOOL full_rebuild = mDrawablep->isState(LLDrawable::REBUILD_VOLUME);
1247 const LLMatrix4& mat_vert, const LLMatrix3& mat_normal, const BOOL global_volume) 817 BOOL moved = TRUE;
1248{
1249 LLMemType mt1(LLMemType::MTYPE_DRAWABLE);
1250 818
1251 if (!mDrawablep) 819 BOOL global_volume = mDrawablep->getVOVolume()->isVolumeGlobal();
820 LLVector3 scale;
821 if (global_volume)
1252 { 822 {
1253 return TRUE; 823 scale.setVec(1,1,1);
824 }
825 else
826 {
827 scale = mVObjp->getScale();
1254 } 828 }
1255 829
1256 S32 index_offset; 830 if (!full_rebuild)
1257 F32 r, os, ot, ms, mt, cos_ang, sin_ang; 831 {
1258 LLStrider<LLVector3> vertices; 832 if (mLastVertexBuffer == mVertexBuffer &&
1259 LLStrider<LLVector3> normals; 833 !mVertexBuffer->isEmpty())
1260 LLStrider<LLVector3> binormals; 834 { //this face really doesn't need to be regenerated, try real hard not to do so
1261 LLStrider<LLVector2> tex_coords; 835 if (mLastGeomCount == mGeomCount &&
1262 LLStrider<LLVector2> tex_coords2; 836 mLastGeomIndex == mGeomIndex &&
1263 U32 *indicesp = NULL; 837 mLastIndicesCount == mIndicesCount &&
838 mLastIndicesIndex == mIndicesIndex)
839 { //data is in same location in vertex buffer
840 moved = FALSE;
841 }
1264 842
1265 BOOL bump = mDrawPoolp && (mDrawPoolp->mDataMaskIL & LLDrawPool::DATA_BINORMALS_MASK); 843 if (!moved && !mDrawablep->isState(LLDrawable::REBUILD_ALL))
1266 BOOL is_static = mDrawablep->isStatic(); 844 { //nothing needs to be done
1267 BOOL is_global = is_static; 845 vertices += mGeomCount;
1268 846 normals += mGeomCount;
1269 if (bump) 847 tex_coords += mGeomCount;
1270 { 848 colors += mGeomCount;
1271 index_offset = getGeometryMultiTexture(vertices, normals, binormals, tex_coords, tex_coords2, indicesp); 849 tex_coords2 += mGeomCount;
850 index_offset += mGeomCount;
851 indicesp += mIndicesCount;
852 return FALSE;
853 }
854
855 if (mLastGeomCount == mGeomCount)
856 {
857 if (mLastGeomIndex >= mGeomIndex &&
858 mLastGeomIndex + mGeomCount+1 < mVertexBuffer->getNumVerts())
859 {
860 //copy from further down the buffer
861 mVertexBuffer->getVertexStrider(old_verts, mLastGeomIndex);
862 mVertexBuffer->getTexCoordStrider(old_texcoords, mLastGeomIndex);
863 mVertexBuffer->getTexCoord2Strider(old_texcoords2, mLastGeomIndex);
864 mVertexBuffer->getNormalStrider(old_normals, mLastGeomIndex);
865 mVertexBuffer->getColorStrider(old_colors, mLastGeomIndex);
866
867 if (!mDrawablep->isState(LLDrawable::REBUILD_ALL))
868 {
869 //quick copy
870 for (S32 i = 0; i < mGeomCount; i++)
871 {
872 *vertices++ = *old_verts++;
873 *tex_coords++ = *old_texcoords++;
874 *tex_coords2++ = *old_texcoords2++;
875 *colors++ = *old_colors++;
876 *normals++ = *old_normals++;
877 }
878
879 for (U32 i = 0; i < mIndicesCount; i++)
880 {
881 *indicesp++ = vf.mIndices[i] + index_offset;
882 }
883
884 index_offset += mGeomCount;
885 mLastGeomIndex = mGeomIndex;
886 mLastIndicesCount = mIndicesCount;
887 mLastIndicesIndex = mIndicesIndex;
888
889 return TRUE;
890 }
891 }
892 else
893 {
894 full_rebuild = TRUE;
895 }
896 }
897 }
898 else
899 {
900 full_rebuild = TRUE;
901 }
1272 } 902 }
1273 else 903 else
1274 { 904 {
1275 index_offset = getGeometry(vertices, normals, tex_coords, indicesp); 905 mLastUpdateTime = gFrameTimeSeconds;
1276 } 906 }
907
908
909 BOOL rebuild_pos = full_rebuild || mDrawablep->isState(LLDrawable::REBUILD_POSITION);
910 BOOL rebuild_color = full_rebuild || mDrawablep->isState(LLDrawable::REBUILD_COLOR);
911 BOOL rebuild_tcoord = full_rebuild || mDrawablep->isState(LLDrawable::REBUILD_TCOORD);
912
913 F32 r = 0, os = 0, ot = 0, ms = 0, mt = 0, cos_ang = 0, sin_ang = 0;
914
915 BOOL is_static = mDrawablep->isStatic();
916 BOOL is_global = is_static;
917
1277 if (-1 == index_offset) 918 if (-1 == index_offset)
1278 { 919 {
1279 return TRUE; 920 return TRUE;
@@ -1281,16 +922,6 @@ BOOL LLFace::genVolumeTriangles(const LLVolume &volume, S32 fstart, S32 fend,
1281 922
1282 LLVector3 center_sum(0.f, 0.f, 0.f); 923 LLVector3 center_sum(0.f, 0.f, 0.f);
1283 924
1284 LLVector3 render_pos;
1285
1286 if (mDrawablep->isState(LLDrawable::REBUILD_TCOORD) &&
1287 global_volume)
1288 {
1289 render_pos = mVObjp->getRenderPosition();
1290 }
1291
1292 setPrimType(LLTriangles);
1293
1294 if (is_global) 925 if (is_global)
1295 { 926 {
1296 setState(GLOBAL); 927 setState(GLOBAL);
@@ -1299,26 +930,16 @@ BOOL LLFace::genVolumeTriangles(const LLVolume &volume, S32 fstart, S32 fend,
1299 { 930 {
1300 clearState(GLOBAL); 931 clearState(GLOBAL);
1301 } 932 }
1302 933
1303 LLVector3 min, max;
1304 LLVector2 tmin, tmax; 934 LLVector2 tmin, tmax;
1305 935
1306 BOOL grab_first_vert = TRUE; 936 const LLTextureEntry *tep = mVObjp->getTE(f);
1307 BOOL grab_first_tcoord = TRUE; 937 U8 bump_code = tep ? bump_code = tep->getBumpmap() : 0;
1308 938
1309 for (S32 vol_face = fstart; vol_face <= fend; vol_face++) 939 if (rebuild_tcoord)
1310 { 940 {
1311 const LLVolumeFace &vf = volume.getVolumeFace(vol_face);
1312 S32 num_vertices = (S32)vf.mVertices.size();
1313 S32 num_indices = (S32)vf.mIndices.size();
1314 llassert(num_indices > 0);
1315
1316 U8 bump_code;
1317 const LLTextureEntry *tep = mVObjp->getTE(vol_face);
1318
1319 if (tep) 941 if (tep)
1320 { 942 {
1321 bump_code = tep->getBumpmap();
1322 r = tep->getRotation(); 943 r = tep->getRotation();
1323 os = tep->mOffsetS; 944 os = tep->mOffsetS;
1324 ot = tep->mOffsetT; 945 ot = tep->mOffsetT;
@@ -1329,7 +950,6 @@ BOOL LLFace::genVolumeTriangles(const LLVolume &volume, S32 fstart, S32 fend,
1329 } 950 }
1330 else 951 else
1331 { 952 {
1332 bump_code = 0;
1333 cos_ang = 1.0f; 953 cos_ang = 1.0f;
1334 sin_ang = 0.0f; 954 sin_ang = 0.0f;
1335 os = 0.0f; 955 os = 0.0f;
@@ -1337,209 +957,235 @@ BOOL LLFace::genVolumeTriangles(const LLVolume &volume, S32 fstart, S32 fend,
1337 ms = 1.0f; 957 ms = 1.0f;
1338 mt = 1.0f; 958 mt = 1.0f;
1339 } 959 }
960 }
1340 961
1341 if (mDrawablep->isState(LLDrawable::REBUILD_VOLUME)) 962 if (isState(TEXTURE_ANIM))
963 {
964 LLVOVolume* vobj = (LLVOVolume*) (LLViewerObject*) mVObjp;
965 U8 mode = vobj->mTexAnimMode;
966 if (!mode)
1342 { 967 {
1343 // VERTICES & NORMALS 968 clearState(TEXTURE_ANIM);
1344 for (S32 i = 0; i < num_vertices; i++) 969 }
970 else
971 {
972 //if (mode & LLViewerTextureAnim::TRANSLATE)
1345 { 973 {
1346 LLVector3 v; 974 os = ot = 0.f;
1347 v = vf.mVertices[i].mPosition * mat_vert;
1348
1349 LLVector3 normal = vf.mVertices[i].mNormal * mat_normal;
1350 normal.normVec();
1351 *normals++ = normal;
1352
1353 *vertices++ = v;
1354
1355 if (grab_first_vert)
1356 {
1357 grab_first_vert = FALSE;
1358 min = max = v;
1359 }
1360 else
1361 {
1362 for (U32 j = 0; j < 3; j++)
1363 {
1364 if (v.mV[j] < min.mV[j])
1365 {
1366 min.mV[j] = v.mV[j];
1367 }
1368 if (v.mV[j] > max.mV[j])
1369 {
1370 max.mV[j] = v.mV[j];
1371 }
1372 }
1373 }
1374 } 975 }
1375 for (S32 i = 0; i < num_indices; i++) 976 //if (mode & LLViewerTextureAnim::ROTATE)
1376 { 977 {
1377 S32 index = vf.mIndices[i] + index_offset; 978 r = 0.f;
1378 llassert(index >= 0 && (i != 1 || *(indicesp-1)!=(U32)index)); 979 cos_ang = 1.f;
1379 *indicesp++ = index; 980 sin_ang = 0.f;
981 }
982 //if (mode & LLViewerTextureAnim::SCALE)
983 {
984 ms = mt = 1.f;
1380 } 985 }
1381 } 986 }
987 }
988
989 LLColor4U color = tep->getColor();
1382 990
1383 if ((mDrawablep->isState(LLDrawable::REBUILD_TCOORD)) || 991 if (rebuild_color)
1384 ((bump || getTextureEntry()->getTexGen() != 0) && mDrawablep->isState(LLDrawable::REBUILD_VOLUME))) 992 {
993 GLfloat alpha[4] =
1385 { 994 {
1386 // TEX COORDS AND BINORMALS 995 0.00f,
1387 LLVector3 binormal_dir( -sin_ang, cos_ang, 0 ); 996 0.25f,
1388 LLVector3 bump_s_primary_light_ray; 997 0.5f,
1389 LLVector3 bump_t_primary_light_ray; 998 0.75f
1390 if (bump) 999 };
1391 {
1392 F32 offset_multiple;
1393 switch( bump_code )
1394 {
1395 case BE_NO_BUMP:
1396 offset_multiple = 0.f;
1397 break;
1398 case BE_BRIGHTNESS:
1399 case BE_DARKNESS:
1400 if( mTexture.notNull() && mTexture->getHasGLTexture())
1401 {
1402 // Offset by approximately one texel
1403 S32 cur_discard = mTexture->getDiscardLevel();
1404 S32 max_size = llmax( mTexture->getWidth(), mTexture->getHeight() );
1405 max_size <<= cur_discard;
1406 const F32 ARTIFICIAL_OFFSET = 2.f;
1407 offset_multiple = ARTIFICIAL_OFFSET / (F32)max_size;
1408 }
1409 else
1410 {
1411 offset_multiple = 1.f/256;
1412 }
1413 break;
1414 1000
1415 default: // Standard bumpmap textures. Assumed to be 256x256 1001 if (gPipeline.getPoolTypeFromTE(tep, getTexture()) == LLDrawPool::POOL_BUMP)
1416 offset_multiple = 1.f / 256; 1002 {
1417 break; 1003 color.mV[3] = U8 (alpha[tep->getShiny()] * 255);
1418 } 1004 }
1005 }
1419 1006
1420 F32 s_scale = 1.f; 1007 // INDICES
1421 F32 t_scale = 1.f; 1008 if (full_rebuild || moved)
1422 if( tep ) 1009 {
1423 { 1010 for (S32 i = 0; i < num_indices; i++)
1424 tep->getScale( &s_scale, &t_scale ); 1011 {
1425 } 1012 *indicesp++ = vf.mIndices[i] + index_offset;
1426 LLVector3 sun_ray = gSky.getSunDirection(); 1013 }
1427 LLVector3 moon_ray = gSky.getMoonDirection(); 1014 }
1428 LLVector3& primary_light_ray = (sun_ray.mV[VZ] > 0) ? sun_ray : moon_ray; 1015 else
1429 bump_s_primary_light_ray = offset_multiple * s_scale * primary_light_ray; 1016 {
1430 bump_t_primary_light_ray = offset_multiple * t_scale * primary_light_ray; 1017 indicesp += num_indices;
1018 }
1019
1020 //bump setup
1021 LLVector3 binormal_dir( -sin_ang, cos_ang, 0 );
1022 LLVector3 bump_s_primary_light_ray;
1023 LLVector3 bump_t_primary_light_ray;
1024
1025 if (bump_code)
1026 {
1027 F32 offset_multiple;
1028 switch( bump_code )
1029 {
1030 case BE_NO_BUMP:
1031 offset_multiple = 0.f;
1032 break;
1033 case BE_BRIGHTNESS:
1034 case BE_DARKNESS:
1035 if( mTexture.notNull() && mTexture->getHasGLTexture())
1036 {
1037 // Offset by approximately one texel
1038 S32 cur_discard = mTexture->getDiscardLevel();
1039 S32 max_size = llmax( mTexture->getWidth(), mTexture->getHeight() );
1040 max_size <<= cur_discard;
1041 const F32 ARTIFICIAL_OFFSET = 2.f;
1042 offset_multiple = ARTIFICIAL_OFFSET / (F32)max_size;
1431 } 1043 }
1432 1044 else
1433 for (S32 i = 0; i < num_vertices; i++)
1434 { 1045 {
1435 LLVector2 tc = vf.mVertices[i].mTexCoord; 1046 offset_multiple = 1.f/256;
1047 }
1048 break;
1436 1049
1437 U8 texgen = getTextureEntry()->getTexGen(); 1050 default: // Standard bumpmap textures. Assumed to be 256x256
1438 if (texgen != LLTextureEntry::TEX_GEN_DEFAULT) 1051 offset_multiple = 1.f / 256;
1439 { 1052 break;
1053 }
1440 1054
1441 LLVector3 vec = vf.mVertices[i].mPosition; //-vf.mCenter; 1055 F32 s_scale = 1.f;
1442 1056 F32 t_scale = 1.f;
1443 if (global_volume) 1057 if( tep )
1444 { 1058 {
1445 vec -= render_pos; 1059 tep->getScale( &s_scale, &t_scale );
1446 } 1060 }
1447 else 1061 LLVector3 sun_ray = gSky.getSunDirection();
1448 { 1062 LLVector3 moon_ray = gSky.getMoonDirection();
1449 vec.scaleVec(mVObjp->getScale()); 1063 LLVector3& primary_light_ray = (sun_ray.mV[VZ] > 0) ? sun_ray : moon_ray;
1450 } 1064 bump_s_primary_light_ray = offset_multiple * s_scale * primary_light_ray;
1065 bump_t_primary_light_ray = offset_multiple * t_scale * primary_light_ray;
1066 }
1067
1068 U8 texgen = getTextureEntry()->getTexGen();
1451 1069
1452 switch (texgen) 1070 for (S32 i = 0; i < num_vertices; i++)
1453 { 1071 {
1454 case LLTextureEntry::TEX_GEN_PLANAR: 1072 if (rebuild_tcoord)
1455 planarProjection(tc, vf.mVertices[i], vf.mCenter, vec); 1073 {
1456 break; 1074 LLVector2 tc = vf.mVertices[i].mTexCoord;
1457 case LLTextureEntry::TEX_GEN_SPHERICAL: 1075
1458 sphericalProjection(tc, vf.mVertices[i], vf.mCenter, vec); 1076 if (texgen != LLTextureEntry::TEX_GEN_DEFAULT)
1459 break; 1077 {
1460 case LLTextureEntry::TEX_GEN_CYLINDRICAL: 1078 LLVector3 vec = vf.mVertices[i].mPosition;
1461 cylindricalProjection(tc, vf.mVertices[i], vf.mCenter, vec); 1079
1462 break; 1080 vec.scaleVec(scale);
1463 default: 1081
1464 break; 1082 switch (texgen)
1465 }
1466 }
1467 xform(tc, cos_ang, sin_ang, os, ot, ms, mt);
1468 *tex_coords++ = tc;
1469 if (grab_first_tcoord)
1470 {
1471 grab_first_tcoord = FALSE;
1472 tmin = tmax = tc;
1473 }
1474 else
1475 {
1476 for (U32 j = 0; j < 2; j++)
1477 {
1478 if (tmin.mV[j] > tc.mV[j])
1479 {
1480 tmin.mV[j] = tc.mV[j];
1481 }
1482 else if (tmax.mV[j] < tc.mV[j])
1483 {
1484 tmax.mV[j] = tc.mV[j];
1485 }
1486 }
1487 }
1488 if (bump)
1489 { 1083 {
1490 LLVector3 tangent = vf.mVertices[i].mBinormal % vf.mVertices[i].mNormal; 1084 case LLTextureEntry::TEX_GEN_PLANAR:
1491 LLMatrix3 tangent_to_object; 1085 planarProjection(tc, vf.mVertices[i], vf.mCenter, vec);
1492 tangent_to_object.setRows(tangent, vf.mVertices[i].mBinormal, vf.mVertices[i].mNormal); 1086 break;
1493 LLVector3 binormal = binormal_dir * tangent_to_object; 1087 case LLTextureEntry::TEX_GEN_SPHERICAL:
1088 sphericalProjection(tc, vf.mVertices[i], vf.mCenter, vec);
1089 break;
1090 case LLTextureEntry::TEX_GEN_CYLINDRICAL:
1091 cylindricalProjection(tc, vf.mVertices[i], vf.mCenter, vec);
1092 break;
1093 default:
1094 break;
1095 }
1096 }
1494 1097
1495 if (!global_volume) 1098 xform(tc, cos_ang, sin_ang, os, ot, ms, mt);
1496 { 1099 *tex_coords++ = tc;
1497 binormal = binormal * mat_normal; 1100
1498 } 1101 if (bump_code)
1499 binormal.normVec(); 1102 {
1500 tangent.normVec(); 1103 LLVector3 tangent = vf.mVertices[i].mBinormal % vf.mVertices[i].mNormal;
1501 1104 LLMatrix3 tangent_to_object;
1502 tc += LLVector2( bump_s_primary_light_ray * tangent, bump_t_primary_light_ray * binormal ); 1105 tangent_to_object.setRows(tangent, vf.mVertices[i].mBinormal, vf.mVertices[i].mNormal);
1503 *tex_coords2++ = tc; 1106 LLVector3 binormal = binormal_dir * tangent_to_object;
1504 1107
1505 *binormals++ = binormal; 1108 binormal = binormal * mat_normal;
1506 } 1109 binormal.normVec();
1110
1111 tc += LLVector2( bump_s_primary_light_ray * tangent, bump_t_primary_light_ray * binormal );
1112 *tex_coords2++ = tc;
1113 }
1114 }
1115 else if (moved)
1116 {
1117 *tex_coords++ = *old_texcoords++;
1118 if (bump_code)
1119 {
1120 *tex_coords2++ = *old_texcoords2++;
1507 } 1121 }
1508 } 1122 }
1123
1124 if (rebuild_pos)
1125 {
1126 *vertices++ = vf.mVertices[i].mPosition * mat_vert;
1509 1127
1510 index_offset += num_vertices; 1128 LLVector3 normal = vf.mVertices[i].mNormal * mat_normal;
1129 normal.normVec();
1130
1131 *normals++ = normal;
1132 }
1133 else if (moved)
1134 {
1135 *normals++ = *old_normals++;
1136 *vertices++ = *old_verts++;
1137 }
1511 1138
1512 center_sum += vf.mCenter * mat_vert; 1139 if (rebuild_color)
1140 {
1141 *colors++ = color;
1142 }
1143 else if (moved)
1144 {
1145 *colors++ = *old_colors++;
1146 }
1513 } 1147 }
1514 1148
1515 center_sum /= (F32)(fend-fstart+1); 1149 if (!rebuild_pos && !moved)
1516
1517 if (is_static)
1518 { 1150 {
1519 mCenterAgent = center_sum; 1151 vertices += num_vertices;
1520 mCenterLocal = mCenterAgent - mDrawablep->getPositionAgent();
1521 } 1152 }
1522 else 1153
1154 if (!rebuild_tcoord && !moved)
1523 { 1155 {
1524 mCenterLocal = center_sum; 1156 tex_coords2 += num_vertices;
1525 updateCenterAgent(); 1157 tex_coords += num_vertices;
1526 } 1158 }
1527 1159 else if (!bump_code)
1528 if (!grab_first_vert && mDrawablep->isState(LLDrawable::REBUILD_VOLUME))
1529 { 1160 {
1530 mExtents[0] = min; 1161 tex_coords2 += num_vertices;
1531 mExtents[1] = max;
1532 } 1162 }
1533 1163
1534 if (!grab_first_tcoord && mDrawablep->isState(LLDrawable::REBUILD_TCOORD)) 1164 if (!rebuild_color && !moved)
1535 { 1165 {
1536 mTexExtents[0] = tmin; 1166 colors += num_vertices;
1537 mTexExtents[1] = tmax;
1538 } 1167 }
1539 1168
1169 if (rebuild_tcoord)
1170 {
1171 mTexExtents[0].setVec(0,0);
1172 mTexExtents[1].setVec(1,1);
1173 xform(mTexExtents[0], cos_ang, sin_ang, os, ot, ms, mt);
1174 xform(mTexExtents[1], cos_ang, sin_ang, os, ot, ms, mt);
1175 }
1176
1177 index_offset += num_vertices;
1178
1179 mLastVertexBuffer = mVertexBuffer;
1180 mLastGeomCount = mGeomCount;
1181 mLastGeomIndex = mGeomIndex;
1182 mLastIndicesCount = mIndicesCount;
1183 mLastIndicesIndex = mIndicesIndex;
1184
1540 return TRUE; 1185 return TRUE;
1541} 1186}
1542 1187
1188#if 0
1543BOOL LLFace::genLighting(const LLVolume* volume, const LLDrawable* drawablep, S32 fstart, S32 fend, 1189BOOL LLFace::genLighting(const LLVolume* volume, const LLDrawable* drawablep, S32 fstart, S32 fend,
1544 const LLMatrix4& mat_vert, const LLMatrix3& mat_normal, BOOL do_lighting) 1190 const LLMatrix4& mat_vert, const LLMatrix3& mat_normal, BOOL do_lighting)
1545{ 1191{
@@ -1662,21 +1308,20 @@ BOOL LLFace::genShadows(const LLVolume* volume, const LLDrawable* drawablep, S32
1662 } 1308 }
1663 return TRUE; 1309 return TRUE;
1664} 1310}
1311#endif
1665 1312
1666BOOL LLFace::verify(const U32* indices_array) const 1313BOOL LLFace::verify(const U32* indices_array) const
1667{ 1314{
1668 BOOL ok = TRUE; 1315 BOOL ok = TRUE;
1669 // First, check whether the face data fits within the pool's range. 1316 // First, check whether the face data fits within the pool's range.
1670 if ((mGeomIndex < 0) || (mGeomIndex + mGeomCount) > (S32)getPool()->getVertexCount()) 1317 if ((mGeomIndex < 0) || (mGeomIndex + mGeomCount) > mVertexBuffer->getNumVerts())
1671 { 1318 {
1672 ok = FALSE; 1319 ok = FALSE;
1673 llinfos << "Face not within pool range!" << llendl; 1320 llinfos << "Face not within pool range!" << llendl;
1674 } 1321 }
1675 1322
1676 S32 indices_count = (S32)getIndicesCount(); 1323 S32 indices_count = (S32)getIndicesCount();
1677 S32 geom_start = getGeomStart(); 1324
1678 S32 geom_count = mGeomCount;
1679
1680 if (!indices_count) 1325 if (!indices_count)
1681 { 1326 {
1682 return TRUE; 1327 return TRUE;
@@ -1688,6 +1333,10 @@ BOOL LLFace::verify(const U32* indices_array) const
1688 llinfos << "Face has bogus indices count" << llendl; 1333 llinfos << "Face has bogus indices count" << llendl;
1689 } 1334 }
1690 1335
1336#if 0
1337 S32 geom_start = getGeomStart();
1338 S32 geom_count = mGeomCount;
1339
1691 const U32 *indicesp = indices_array ? indices_array + mIndicesIndex : getRawIndices(); 1340 const U32 *indicesp = indices_array ? indices_array + mIndicesIndex : getRawIndices();
1692 1341
1693 for (S32 i = 0; i < indices_count; i++) 1342 for (S32 i = 0; i < indices_count; i++)
@@ -1706,6 +1355,7 @@ BOOL LLFace::verify(const U32* indices_array) const
1706 ok = FALSE; 1355 ok = FALSE;
1707 } 1356 }
1708 } 1357 }
1358#endif
1709 1359
1710 if (!ok) 1360 if (!ok)
1711 { 1361 {
@@ -1756,7 +1406,7 @@ const LLColor4& LLFace::getRenderColor() const
1756 1406
1757void LLFace::renderSetColor() const 1407void LLFace::renderSetColor() const
1758{ 1408{
1759 if (!LLDrawPool::LLOverrideFaceColor::sOverrideFaceColor) 1409 if (!LLFacePool::LLOverrideFaceColor::sOverrideFaceColor)
1760 { 1410 {
1761 const LLColor4* color = &(getRenderColor()); 1411 const LLColor4* color = &(getRenderColor());
1762 1412
@@ -1773,61 +1423,21 @@ void LLFace::renderSetColor() const
1773 1423
1774S32 LLFace::pushVertices(const U32* index_array) const 1424S32 LLFace::pushVertices(const U32* index_array) const
1775{ 1425{
1776 U32 indices_count = mIndicesCount; 1426 if (mIndicesCount)
1777 S32 ret = 0;
1778#if ENABLE_FACE_LINKING
1779 LLFace* next = mNextFace;
1780#endif
1781
1782 if (mGeomCount < gGLManager.mGLMaxVertexRange && (S32) indices_count < gGLManager.mGLMaxIndexRange)
1783 { 1427 {
1784 LLFace* current = (LLFace*) this; 1428 if (mGeomCount <= gGLManager.mGLMaxVertexRange &&
1785 S32 geom_count = mGeomCount; 1429 mIndicesCount <= (U32) gGLManager.mGLMaxIndexRange)
1786#if ENABLE_FACE_LINKING
1787 while (current)
1788 { 1430 {
1789 //chop up batch into implementation recommended sizes 1431 glDrawRangeElements(GL_TRIANGLES, mGeomIndex, mGeomIndex + mGeomCount-1, mIndicesCount,
1790 while (next && 1432 GL_UNSIGNED_INT, index_array + mIndicesIndex);
1791 (current == next ||
1792 ((S32) (indices_count + next->mIndicesCount) < gGLManager.mGLMaxIndexRange &&
1793 geom_count + next->mGeomCount < gGLManager.mGLMaxVertexRange)))
1794 {
1795 indices_count += next->mIndicesCount;
1796 geom_count += next->mGeomCount;
1797 next = next->mNextFace;
1798 }
1799#endif
1800 if (indices_count)
1801 {
1802 glDrawRangeElements(mPrimType, current->mGeomIndex, current->mGeomIndex + geom_count, indices_count,
1803 GL_UNSIGNED_INT, index_array + current->mIndicesIndex);
1804 }
1805 ret += (S32) indices_count;
1806 indices_count = 0;
1807 geom_count = 0;
1808#if ENABLE_FACE_LINKING
1809 current = next;
1810 } 1433 }
1811#endif 1434 else
1812 }
1813 else
1814 {
1815#if ENABLE_FACE_LINKING
1816 while (next)
1817 {
1818 indices_count += next->mIndicesCount;
1819 next = next->mNextFace;
1820 }
1821#endif
1822 if (indices_count)
1823 { 1435 {
1824 glDrawElements(mPrimType, indices_count, GL_UNSIGNED_INT, index_array + mIndicesIndex); 1436 glDrawElements(GL_TRIANGLES, mIndicesCount, GL_UNSIGNED_INT, index_array+mIndicesIndex);
1825 } 1437 }
1826 ret += (S32) indices_count;
1827 } 1438 }
1828 1439
1829 return ret; 1440 return mIndicesCount;
1830
1831} 1441}
1832 1442
1833const LLMatrix4& LLFace::getRenderMatrix() const 1443const LLMatrix4& LLFace::getRenderMatrix() const
@@ -1854,19 +1464,25 @@ S32 LLFace::renderElements(const U32 *index_array) const
1854 return ret; 1464 return ret;
1855} 1465}
1856 1466
1857S32 LLFace::renderIndexed(const U32 *index_array) const 1467S32 LLFace::renderIndexed()
1858{ 1468{
1859 if (mSkipRender) 1469 if(mGeomIndex < 0 || mDrawablep.isNull() || mDrawPoolp == NULL)
1860 { 1470 {
1861 return 0; 1471 return 0;
1862 } 1472 }
1473
1474 return renderIndexed(mDrawPoolp->getVertexDataMask());
1475}
1863 1476
1864 if(mGeomIndex < 0 || mDrawablep.isNull()) 1477S32 LLFace::renderIndexed(U32 mask)
1478{
1479 if (mVertexBuffer.isNull())
1865 { 1480 {
1866 return 0; 1481 return 0;
1867 } 1482 }
1868 1483
1869 renderSetColor(); 1484 mVertexBuffer->setBuffer(mask);
1485 U32* index_array = (U32*) mVertexBuffer->getIndicesPointer();
1870 return renderElements(index_array); 1486 return renderElements(index_array);
1871} 1487}
1872 1488
@@ -1879,26 +1495,13 @@ S32 LLFace::getVertices(LLStrider<LLVector3> &vertices)
1879 { 1495 {
1880 return -1; 1496 return -1;
1881 } 1497 }
1882 if (isState(BACKLIST)) 1498
1883 { 1499 if (mGeomIndex >= 0) // flexible objects may not have geometry
1884 if (!mBackupMem)
1885 {
1886 printDebugInfo();
1887 llerrs << "No backup memory for face" << llendl;
1888 }
1889 vertices = (LLVector3*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_VERTICES]);
1890 vertices.setStride( mDrawPoolp->getStride());
1891 return 0;
1892 }
1893 else
1894 { 1500 {
1895 if (mGeomIndex >= 0) // flexible objects may not have geometry 1501 mVertexBuffer->getVertexStrider(vertices, mGeomIndex);
1896 { 1502
1897 mDrawPoolp->getVertexStrider(vertices, mGeomIndex);
1898 mDrawPoolp->setDirty();
1899 }
1900 return mGeomIndex;
1901 } 1503 }
1504 return mGeomIndex;
1902} 1505}
1903 1506
1904S32 LLFace::getColors(LLStrider<LLColor4U> &colors) 1507S32 LLFace::getColors(LLStrider<LLColor4U> &colors)
@@ -1907,42 +1510,17 @@ S32 LLFace::getColors(LLStrider<LLColor4U> &colors)
1907 { 1510 {
1908 return -1; 1511 return -1;
1909 } 1512 }
1910 if (isState(BACKLIST)) 1513
1911 { 1514 llassert(mGeomIndex >= 0);
1912 llassert(mBackupMem); 1515 mVertexBuffer->getColorStrider(colors, mGeomIndex);
1913 colors = (LLColor4U*)(mBackupMem + (4 * mIndicesCount) + mDrawPoolp->mDataOffsets[LLDrawPool::DATA_COLORS]); 1516 return mGeomIndex;
1914 colors.setStride( mDrawPoolp->getStride());
1915 return 0;
1916 }
1917 else
1918 {
1919 llassert(mGeomIndex >= 0);
1920 mDrawPoolp->getColorStrider(colors, mGeomIndex);
1921 return mGeomIndex;
1922 }
1923}
1924
1925S32 LLFace::getIndices(U32* &indicesp)
1926{
1927 if (isState(BACKLIST))
1928 {
1929 indicesp = (U32*)mBackupMem;
1930 return 0;
1931 }
1932 else
1933 {
1934 indicesp = mDrawPoolp->getIndices(mIndicesIndex);
1935 llassert(mGeomIndex >= 0 && indicesp[0] != indicesp[1]);
1936 return mGeomIndex;
1937 }
1938} 1517}
1939 1518
1940void LLFace::link(LLFace* facep) 1519S32 LLFace::getIndices(LLStrider<U32> &indicesp)
1941{ 1520{
1942#if ENABLE_FACE_LINKING 1521 mVertexBuffer->getIndexStrider(indicesp, mIndicesIndex);
1943 mNextFace = facep; 1522 llassert(mGeomIndex >= 0 && indicesp[0] != indicesp[1]);
1944 facep->mSkipRender = TRUE; 1523 return mIndicesIndex;
1945#endif
1946} 1524}
1947 1525
1948LLVector3 LLFace::getPositionAgent() const 1526LLVector3 LLFace::getPositionAgent() const