diff options
author | Jacek Antonelli | 2008-08-15 23:44:50 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:50 -0500 |
commit | 89fe5dab825a62a0e3fd8d248cbc91c65eb2a426 (patch) | |
tree | bcff14b7888d04a2fec799c59369f6095224bd08 /linden/indra/newview/llvotree.cpp | |
parent | Second Life viewer sources 1.13.3.2 (diff) | |
download | meta-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/llvotree.cpp')
-rw-r--r-- | linden/indra/newview/llvotree.cpp | 106 |
1 files changed, 64 insertions, 42 deletions
diff --git a/linden/indra/newview/llvotree.cpp b/linden/indra/newview/llvotree.cpp index 9808a02..382f9a6 100644 --- a/linden/indra/newview/llvotree.cpp +++ b/linden/indra/newview/llvotree.cpp | |||
@@ -29,6 +29,8 @@ | |||
29 | 29 | ||
30 | #include "llvotree.h" | 30 | #include "llvotree.h" |
31 | 31 | ||
32 | #include "lldrawpooltree.h" | ||
33 | |||
32 | #include "llviewercontrol.h" | 34 | #include "llviewercontrol.h" |
33 | #include "lldir.h" | 35 | #include "lldir.h" |
34 | #include "llprimitive.h" | 36 | #include "llprimitive.h" |
@@ -38,7 +40,6 @@ | |||
38 | #include "object_flags.h" | 40 | #include "object_flags.h" |
39 | 41 | ||
40 | #include "llagent.h" | 42 | #include "llagent.h" |
41 | #include "llagparray.h" | ||
42 | #include "llcylinder.h" | 43 | #include "llcylinder.h" |
43 | #include "lldrawable.h" | 44 | #include "lldrawable.h" |
44 | #include "llface.h" | 45 | #include "llface.h" |
@@ -231,13 +232,13 @@ void LLVOTree::initClass() | |||
231 | 232 | ||
232 | BOOL have_all_trees = TRUE; | 233 | BOOL have_all_trees = TRUE; |
233 | LLString err; | 234 | LLString err; |
234 | char buffer[10]; | 235 | char buffer[10]; /* Flawfinder: ignore */ |
235 | 236 | ||
236 | for (S32 i=0;i<sMaxTreeSpecies;++i) | 237 | for (S32 i=0;i<sMaxTreeSpecies;++i) |
237 | { | 238 | { |
238 | if (!sSpeciesTable.count(i)) | 239 | if (!sSpeciesTable.count(i)) |
239 | { | 240 | { |
240 | snprintf(buffer,10," %d",i); | 241 | snprintf(buffer,10," %d",i); /* Flawfinder: ignore */ |
241 | err.append(buffer); | 242 | err.append(buffer); |
242 | have_all_trees = FALSE; | 243 | have_all_trees = FALSE; |
243 | } | 244 | } |
@@ -408,6 +409,10 @@ void LLVOTree::updateTextures(LLAgent &agent) | |||
408 | F32 cos_angle = 1.f; | 409 | F32 cos_angle = 1.f; |
409 | if (mTreeImagep) | 410 | if (mTreeImagep) |
410 | { | 411 | { |
412 | if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_TEXTURE_AREA)) | ||
413 | { | ||
414 | setDebugText(llformat("%4.0f", fsqrtf(mPixelArea))); | ||
415 | } | ||
411 | mTreeImagep->addTextureStats(mPixelArea, texel_area_ratio, cos_angle); | 416 | mTreeImagep->addTextureStats(mPixelArea, texel_area_ratio, cos_angle); |
412 | } | 417 | } |
413 | 418 | ||
@@ -421,14 +426,12 @@ LLDrawable* LLVOTree::createDrawable(LLPipeline *pipeline) | |||
421 | 426 | ||
422 | mDrawable->setRenderType(LLPipeline::RENDER_TYPE_TREE); | 427 | mDrawable->setRenderType(LLPipeline::RENDER_TYPE_TREE); |
423 | 428 | ||
424 | LLDrawPool *poolp = gPipeline.getPool(LLDrawPool::POOL_TREE, mTreeImagep); | 429 | LLDrawPoolTree *poolp = (LLDrawPoolTree*) gPipeline.getPool(LLDrawPool::POOL_TREE, mTreeImagep); |
425 | 430 | ||
426 | // Just a placeholder for an actual object... | 431 | // Just a placeholder for an actual object... |
427 | LLFace *facep = mDrawable->addFace(poolp, mTreeImagep, TRUE); | 432 | LLFace *facep = mDrawable->addFace(poolp, mTreeImagep); |
428 | facep->setSize(1, 3); | 433 | facep->setSize(1, 3); |
429 | 434 | ||
430 | gPipeline.markMaterialed(mDrawable); | ||
431 | |||
432 | updateRadius(); | 435 | updateRadius(); |
433 | 436 | ||
434 | return mDrawable; | 437 | return mDrawable; |
@@ -441,6 +444,7 @@ const S32 LEAF_VERTICES = 16; | |||
441 | 444 | ||
442 | BOOL LLVOTree::updateGeometry(LLDrawable *drawable) | 445 | BOOL LLVOTree::updateGeometry(LLDrawable *drawable) |
443 | { | 446 | { |
447 | LLFastTimer ftm(LLFastTimer::FTM_UPDATE_TREE); | ||
444 | U32 i, j; | 448 | U32 i, j; |
445 | const S32 MAX_SLICES = 32; | 449 | const S32 MAX_SLICES = 32; |
446 | 450 | ||
@@ -463,20 +467,6 @@ BOOL LLVOTree::updateGeometry(LLDrawable *drawable) | |||
463 | face->mCenterAgent = getPositionAgent(); | 467 | face->mCenterAgent = getPositionAgent(); |
464 | face->mCenterLocal = face->mCenterAgent; | 468 | face->mCenterLocal = face->mCenterAgent; |
465 | 469 | ||
466 | LLDrawPool *poolp = face->getPool(); | ||
467 | |||
468 | if (poolp->getVertexCount()) | ||
469 | { | ||
470 | return TRUE; | ||
471 | } | ||
472 | |||
473 | if (!face->getDirty()) | ||
474 | { | ||
475 | return FALSE; | ||
476 | } | ||
477 | |||
478 | poolp->setDirty(); | ||
479 | |||
480 | for (lod = 0; lod < 4; lod++) | 470 | for (lod = 0; lod < 4; lod++) |
481 | { | 471 | { |
482 | slices = sLODSlices[lod]; | 472 | slices = sLODSlices[lod]; |
@@ -491,10 +481,17 @@ BOOL LLVOTree::updateGeometry(LLDrawable *drawable) | |||
491 | LLStrider<LLVector3> vertices; | 481 | LLStrider<LLVector3> vertices; |
492 | LLStrider<LLVector3> normals; | 482 | LLStrider<LLVector3> normals; |
493 | LLStrider<LLVector2> tex_coords; | 483 | LLStrider<LLVector2> tex_coords; |
494 | U32 *indicesp; | 484 | LLStrider<U32> indicesp; |
495 | 485 | ||
496 | face->setSize(max_vertices, max_indices); | 486 | face->setSize(max_vertices, max_indices); |
487 | |||
488 | face->mVertexBuffer = new LLVertexBuffer(LLDrawPoolTree::VERTEX_DATA_MASK, GL_STATIC_DRAW_ARB); | ||
489 | face->mVertexBuffer->allocateBuffer(max_vertices, max_indices, TRUE); | ||
490 | face->setGeomIndex(0); | ||
491 | face->setIndicesIndex(0); | ||
492 | |||
497 | face->getGeometry(vertices, normals, tex_coords, indicesp); | 493 | face->getGeometry(vertices, normals, tex_coords, indicesp); |
494 | |||
498 | 495 | ||
499 | S32 vertex_count = 0; | 496 | S32 vertex_count = 0; |
500 | S32 index_count = 0; | 497 | S32 index_count = 0; |
@@ -793,17 +790,13 @@ BOOL LLVOTree::updateGeometry(LLDrawable *drawable) | |||
793 | return TRUE; | 790 | return TRUE; |
794 | } | 791 | } |
795 | 792 | ||
796 | void LLVOTree::drawBranchPipeline(LLDrawPool *draw_pool, S32 trunk_LOD, S32 stop_level, U16 depth, U16 trunk_depth, F32 scale, F32 twist, F32 droop, F32 branches, F32 alpha) | 793 | U32 LLVOTree::drawBranchPipeline(U32* indicesp, S32 trunk_LOD, S32 stop_level, U16 depth, U16 trunk_depth, F32 scale, F32 twist, F32 droop, F32 branches, F32 alpha) |
797 | { | 794 | { |
795 | U32 ret = 0; | ||
798 | // | 796 | // |
799 | // Draws a tree by recursing, drawing branches and then a 'leaf' texture. | 797 | // Draws a tree by recursing, drawing branches and then a 'leaf' texture. |
800 | // If stop_level = -1, simply draws the whole tree as a billboarded texture | 798 | // If stop_level = -1, simply draws the whole tree as a billboarded texture |
801 | // | 799 | // |
802 | |||
803 | if (!draw_pool->getIndexCount()) | ||
804 | { | ||
805 | return; // safety net | ||
806 | } | ||
807 | 800 | ||
808 | static F32 constant_twist; | 801 | static F32 constant_twist; |
809 | static F32 width = 0; | 802 | static F32 width = 0; |
@@ -827,15 +820,15 @@ void LLVOTree::drawBranchPipeline(LLDrawPool *draw_pool, S32 trunk_LOD, S32 stop | |||
827 | width = scale * length * aspect; | 820 | width = scale * length * aspect; |
828 | glPushMatrix(); | 821 | glPushMatrix(); |
829 | glScalef(width,width,scale * length); | 822 | glScalef(width,width,scale * length); |
830 | //glDrawElements(GL_TRIANGLES, sLODIndexCount[trunk_LOD], GL_UNSIGNED_INT, draw_pool.getRawIndices() + sLODIndexOffset[trunk_LOD]); | 823 | glDrawElements(GL_TRIANGLES, sLODIndexCount[trunk_LOD], GL_UNSIGNED_INT, indicesp + sLODIndexOffset[trunk_LOD]); |
831 | glDrawRangeElements(GL_TRIANGLES, | 824 | /*glDrawRangeElements(GL_TRIANGLES, |
832 | sLODVertexOffset[trunk_LOD], | 825 | sLODVertexOffset[trunk_LOD], |
833 | sLODVertexOffset[trunk_LOD] + sLODVertexCount[trunk_LOD]-1, | 826 | sLODVertexOffset[trunk_LOD] + sLODVertexCount[trunk_LOD]-1, |
834 | sLODIndexCount[trunk_LOD], | 827 | sLODIndexCount[trunk_LOD], |
835 | GL_UNSIGNED_INT, | 828 | GL_UNSIGNED_INT, |
836 | draw_pool->getRawIndices() + sLODIndexOffset[trunk_LOD]); | 829 | indicesp + sLODIndexOffset[trunk_LOD]);*/ |
837 | stop_glerror(); | 830 | stop_glerror(); |
838 | draw_pool->addIndicesDrawn(sLODIndexCount[trunk_LOD]); | 831 | ret += sLODIndexCount[trunk_LOD]; |
839 | glPopMatrix(); | 832 | glPopMatrix(); |
840 | } | 833 | } |
841 | 834 | ||
@@ -847,7 +840,7 @@ void LLVOTree::drawBranchPipeline(LLDrawPool *draw_pool, S32 trunk_LOD, S32 stop | |||
847 | glRotatef((constant_twist + ((i%2==0)?twist:-twist))*i, 0.f, 0.f, 1.f); | 840 | glRotatef((constant_twist + ((i%2==0)?twist:-twist))*i, 0.f, 0.f, 1.f); |
848 | glRotatef(droop, 0.f, 1.f, 0.f); | 841 | glRotatef(droop, 0.f, 1.f, 0.f); |
849 | glRotatef(20.f, 0.f, 0.f, 1.f); // rotate 20deg about axis of new branch to add some random variation | 842 | glRotatef(20.f, 0.f, 0.f, 1.f); // rotate 20deg about axis of new branch to add some random variation |
850 | drawBranchPipeline(draw_pool, trunk_LOD, stop_level, depth - 1, 0, scale*mScaleStep, twist, droop, branches, alpha); | 843 | ret += drawBranchPipeline(indicesp, trunk_LOD, stop_level, depth - 1, 0, scale*mScaleStep, twist, droop, branches, alpha); |
851 | glPopMatrix(); | 844 | glPopMatrix(); |
852 | } | 845 | } |
853 | // Recurse to continue trunk | 846 | // Recurse to continue trunk |
@@ -856,7 +849,7 @@ void LLVOTree::drawBranchPipeline(LLDrawPool *draw_pool, S32 trunk_LOD, S32 stop | |||
856 | glPushMatrix(); | 849 | glPushMatrix(); |
857 | glTranslatef(0.f, 0.f, scale * length); | 850 | glTranslatef(0.f, 0.f, scale * length); |
858 | glRotatef(70.5f, 0.f, 0.f, 1.f); // rotate a bit around Z when ascending | 851 | glRotatef(70.5f, 0.f, 0.f, 1.f); // rotate a bit around Z when ascending |
859 | drawBranchPipeline(draw_pool, trunk_LOD, stop_level, depth, trunk_depth-1, scale*mScaleStep, twist, droop, branches, alpha); | 852 | ret += drawBranchPipeline(indicesp, trunk_LOD, stop_level, depth, trunk_depth-1, scale*mScaleStep, twist, droop, branches, alpha); |
860 | glPopMatrix(); | 853 | glPopMatrix(); |
861 | } | 854 | } |
862 | } | 855 | } |
@@ -871,15 +864,15 @@ void LLVOTree::drawBranchPipeline(LLDrawPool *draw_pool, S32 trunk_LOD, S32 stop | |||
871 | //width = scale * (TREE_BRANCH_ASPECT + TREE_LEAF_ASPECT); | 864 | //width = scale * (TREE_BRANCH_ASPECT + TREE_LEAF_ASPECT); |
872 | glScalef(scale*mLeafScale, scale*mLeafScale, scale*mLeafScale); | 865 | glScalef(scale*mLeafScale, scale*mLeafScale, scale*mLeafScale); |
873 | //glScalef(1.5f*width*mLeafScale,1,1.5f*scale*mLeafScale); | 866 | //glScalef(1.5f*width*mLeafScale,1,1.5f*scale*mLeafScale); |
874 | // glDrawElements(GL_TRIANGLES, LEAF_INDICES, GL_UNSIGNED_INT, draw_pool.getRawIndices()); | 867 | glDrawElements(GL_TRIANGLES, LEAF_INDICES, GL_UNSIGNED_INT, indicesp); |
875 | glDrawRangeElements(GL_TRIANGLES, | 868 | /*glDrawRangeElements(GL_TRIANGLES, |
876 | 0, | 869 | 0, |
877 | LEAF_VERTICES-1, | 870 | LEAF_VERTICES-1, |
878 | LEAF_INDICES, | 871 | LEAF_INDICES, |
879 | GL_UNSIGNED_INT, | 872 | GL_UNSIGNED_INT, |
880 | draw_pool->getRawIndices()); | 873 | indicesp);*/ |
881 | stop_glerror(); | 874 | stop_glerror(); |
882 | draw_pool->addIndicesDrawn(LEAF_INDICES); | 875 | ret += LEAF_INDICES; |
883 | glPopMatrix(); | 876 | glPopMatrix(); |
884 | } | 877 | } |
885 | } | 878 | } |
@@ -897,21 +890,23 @@ void LLVOTree::drawBranchPipeline(LLDrawPool *draw_pool, S32 trunk_LOD, S32 stop | |||
897 | { | 890 | { |
898 | glPushMatrix(); | 891 | glPushMatrix(); |
899 | glScalef(mBillboardScale*mBillboardRatio, mBillboardScale*mBillboardRatio, mBillboardScale); | 892 | glScalef(mBillboardScale*mBillboardRatio, mBillboardScale*mBillboardRatio, mBillboardScale); |
900 | // glDrawElements(GL_TRIANGLES, LEAF_INDICES, GL_UNSIGNED_INT, draw_pool.getRawIndices()); | 893 | glDrawElements(GL_TRIANGLES, LEAF_INDICES, GL_UNSIGNED_INT, indicesp); |
901 | glDrawRangeElements(GL_TRIANGLES, | 894 | /* glDrawRangeElements(GL_TRIANGLES, |
902 | 0, | 895 | 0, |
903 | LEAF_VERTICES-1, | 896 | LEAF_VERTICES-1, |
904 | LEAF_INDICES, | 897 | LEAF_INDICES, |
905 | GL_UNSIGNED_INT, | 898 | GL_UNSIGNED_INT, |
906 | draw_pool->getRawIndices()); | 899 | indicesp);*/ |
907 | stop_glerror(); | 900 | stop_glerror(); |
908 | draw_pool->addIndicesDrawn(LEAF_INDICES); | 901 | ret += LEAF_INDICES; |
909 | glPopMatrix(); | 902 | glPopMatrix(); |
910 | } | 903 | } |
911 | glMatrixMode(GL_TEXTURE); | 904 | glMatrixMode(GL_TEXTURE); |
912 | glPopMatrix(); | 905 | glPopMatrix(); |
913 | glMatrixMode(GL_MODELVIEW); | 906 | glMatrixMode(GL_MODELVIEW); |
914 | } | 907 | } |
908 | |||
909 | return ret; | ||
915 | } | 910 | } |
916 | 911 | ||
917 | void LLVOTree::updateRadius() | 912 | void LLVOTree::updateRadius() |
@@ -923,3 +918,30 @@ void LLVOTree::updateRadius() | |||
923 | 918 | ||
924 | mDrawable->setRadius(32.0f); | 919 | mDrawable->setRadius(32.0f); |
925 | } | 920 | } |
921 | |||
922 | void LLVOTree::updateSpatialExtents(LLVector3& newMin, LLVector3& newMax) | ||
923 | { | ||
924 | LLVector3 center = getRenderPosition(); | ||
925 | LLVector3 size = getScale(); | ||
926 | center.mV[2] += size.mV[2]; | ||
927 | |||
928 | newMin.setVec(center-size); | ||
929 | newMax.setVec(center+size); | ||
930 | mDrawable->setPositionGroup((newMin + newMax) * 0.5f); | ||
931 | } | ||
932 | |||
933 | U32 LLVOTree::getPartitionType() const | ||
934 | { | ||
935 | return LLPipeline::PARTITION_TREE; | ||
936 | } | ||
937 | |||
938 | LLTreePartition::LLTreePartition() | ||
939 | : LLSpatialPartition(0) | ||
940 | { | ||
941 | mRenderByGroup = FALSE; | ||
942 | mDrawableType = LLPipeline::RENDER_TYPE_TREE; | ||
943 | mPartitionType = LLPipeline::PARTITION_TREE; | ||
944 | mSlopRatio = 0.f; | ||
945 | mLODPeriod = 1; | ||
946 | } | ||
947 | |||