This commit is contained in:
Shyotl
2012-07-18 00:54:52 -05:00
parent cc5ffafd7c
commit a56ad597d4
13 changed files with 208 additions and 96 deletions

View File

@@ -89,9 +89,9 @@ public:
typedef LLOctreeTraveler<T> oct_traveler; typedef LLOctreeTraveler<T> oct_traveler;
typedef LLTreeTraveler<T> tree_traveler; typedef LLTreeTraveler<T> tree_traveler;
typedef typename std::set<LLPointer<T> > element_list; typedef LLPointer<T>* element_list;
typedef typename element_list::iterator element_iter; typedef LLPointer<T>* element_iter;
typedef typename element_list::const_iterator const_element_iter; typedef const LLPointer<T>* const_element_iter;
typedef typename std::vector<LLTreeListener<T>*>::iterator tree_listener_iter; typedef typename std::vector<LLTreeListener<T>*>::iterator tree_listener_iter;
typedef typename std::vector<LLOctreeNode<T>* > child_list; typedef typename std::vector<LLOctreeNode<T>* > child_list;
typedef LLTreeNode<T> BaseType; typedef LLTreeNode<T> BaseType;
@@ -115,6 +115,9 @@ public:
: mParent((oct_node*)parent), : mParent((oct_node*)parent),
mOctant(octant) mOctant(octant)
{ {
mData = NULL;
mDataEnd = NULL;
mCenter = center; mCenter = center;
mSize = size; mSize = size;
@@ -133,6 +136,16 @@ public:
{ {
BaseType::destroyListeners(); BaseType::destroyListeners();
for (U32 i = 0; i < mElementCount; ++i)
{
mData[i]->setBinIndex(-1);
mData[i] = NULL;
}
free(mData);
mData = NULL;
mDataEnd = NULL;
for (U32 i = 0; i < getChildCount(); i++) for (U32 i = 0; i < getChildCount(); i++)
{ {
delete getChild(i); delete getChild(i);
@@ -232,9 +245,14 @@ public:
virtual bool isLeaf() const { return mChild.empty(); } virtual bool isLeaf() const { return mChild.empty(); }
U32 getElementCount() const { return mElementCount; } U32 getElementCount() const { return mElementCount; }
bool isEmpty() const { return mElementCount == 0; }
element_list& getData() { return mData; } element_list& getData() { return mData; }
const element_list& getData() const { return mData; } const element_list& getData() const { return mData; }
element_iter getDataBegin() { return mData; }
element_iter getDataEnd() { return mDataEnd; }
const_element_iter getDataBegin() const { return mData; }
const_element_iter getDataEnd() const { return mDataEnd; }
U32 getChildCount() const { return mChildCount; } U32 getChildCount() const { return mChildCount; }
oct_node* getChild(U32 index) { return mChild[index]; } oct_node* getChild(U32 index) { return mChild[index]; }
const oct_node* getChild(U32 index) const { return mChild[index]; } const oct_node* getChild(U32 index) const { return mChild[index]; }
@@ -299,7 +317,7 @@ public:
virtual bool insert(T* data) virtual bool insert(T* data)
{ {
if (data == NULL) if (data == NULL || data->getBinIndex() != -1)
{ {
OCT_ERRS << "!!! INVALID ELEMENT ADDED TO OCTREE BRANCH !!!" << llendl; OCT_ERRS << "!!! INVALID ELEMENT ADDED TO OCTREE BRANCH !!!" << llendl;
return false; return false;
@@ -309,22 +327,19 @@ public:
//is it here? //is it here?
if (isInside(data->getPositionGroup())) if (isInside(data->getPositionGroup()))
{ {
if (((getElementCount() < gOctreeMaxCapacity && contains(data->getBinRadius())) || if ((getElementCount() < gOctreeMaxCapacity && contains(data->getBinRadius()) ||
(data->getBinRadius() > getSize()[0] && parent && parent->getElementCount() >= gOctreeMaxCapacity))) (data->getBinRadius() > getSize()[0] && parent && parent->getElementCount() >= gOctreeMaxCapacity)))
{ //it belongs here { //it belongs here
#if LL_OCTREE_PARANOIA_CHECK mElementCount++;
//if this is a redundant insertion, error out (should never happen) mData = (element_list) realloc(mData, sizeof(LLPointer<T>)*mElementCount);
if (mData.find(data) != mData.end())
{
llwarns << "Redundant octree insertion detected. " << data << llendl;
return false;
}
#endif
mData.insert(data); //avoid unref on uninitialized memory
memset(mData+mElementCount-1, 0, sizeof(LLPointer<T>));
mData[mElementCount-1] = data;
mDataEnd = mData + mElementCount;
data->setBinIndex(mElementCount-1);
BaseType::insert(data); BaseType::insert(data);
mElementCount = mData.size();
return true; return true;
} }
else else
@@ -358,10 +373,16 @@ public:
if( lt == 0x7 ) if( lt == 0x7 )
{ {
mData.insert(data); mElementCount++;
BaseType::insert(data); mData = (element_list) realloc(mData, sizeof(LLPointer<T>)*mElementCount);
mElementCount = mData.size(); //avoid unref on uninitialized memory
memset(mData+mElementCount-1, 0, sizeof(LLPointer<T>));
mData[mElementCount-1] = data;
mDataEnd = mData + mElementCount;
data->setBinIndex(mElementCount-1);
BaseType::insert(data);
return true; return true;
} }
@@ -410,23 +431,59 @@ public:
return false; return false;
} }
void _remove(T* data, S32 i)
{ //precondition -- mElementCount > 0, idx is in range [0, mElementCount)
mElementCount--;
data->setBinIndex(-1);
if (mElementCount > 0)
{
if (mElementCount != i)
{
mData[i] = mData[mElementCount]; //might unref data, do not access data after this point
mData[i]->setBinIndex(i);
}
mData[mElementCount] = NULL; //needed for unref
mData = (element_list) realloc(mData, sizeof(LLPointer<T>)*mElementCount);
mDataEnd = mData+mElementCount;
}
else
{
mData[0] = NULL; //needed for unref
free(mData);
mData = NULL;
mDataEnd = NULL;
}
notifyRemoval(data);
checkAlive();
}
bool remove(T* data) bool remove(T* data)
{ {
if (mData.find(data) != mData.end()) S32 i = data->getBinIndex();
{ //we have data
mData.erase(data); if (i >= 0 && i < (S32)mElementCount)
mElementCount = mData.size(); {
this->notifyRemoval(data); if (mData[i] == data)
checkAlive(); { //found it
return true; _remove(data, i);
llassert(data->getBinIndex() == -1);
return true;
}
} }
else if (isInside(data))
if (isInside(data))
{ {
oct_node* dest = getNodeAt(data); oct_node* dest = getNodeAt(data);
if (dest != this) if (dest != this)
{ {
return dest->remove(data); bool ret = dest->remove(data);
llassert(data->getBinIndex() == -1);
return ret;
} }
} }
@@ -445,19 +502,20 @@ public:
//node is now root //node is now root
llwarns << "!!! OCTREE REMOVING FACE BY ADDRESS, SEVERE PERFORMANCE PENALTY |||" << llendl; llwarns << "!!! OCTREE REMOVING FACE BY ADDRESS, SEVERE PERFORMANCE PENALTY |||" << llendl;
node->removeByAddress(data); node->removeByAddress(data);
llassert(data->getBinIndex() == -1);
return true; return true;
} }
void removeByAddress(T* data) void removeByAddress(T* data)
{ {
if (mData.find(data) != mData.end()) for (U32 i = 0; i < mElementCount; ++i)
{ {
mData.erase(data); if (mData[i] == data)
mElementCount = mData.size(); { //we have data
this->notifyRemoval(data); _remove(data, i);
llwarns << "FOUND!" << llendl; llwarns << "FOUND!" << llendl;
checkAlive(); return;
return; }
} }
for (U32 i = 0; i < getChildCount(); i++) for (U32 i = 0; i < getChildCount(); i++)
@@ -624,6 +682,7 @@ protected:
U32 mChildCount; U32 mChildCount;
element_list mData; element_list mData;
element_iter mDataEnd;
U32 mElementCount; U32 mElementCount;
}; };

View File

@@ -324,16 +324,16 @@ public:
LLVector4a& min = node->mExtents[0]; LLVector4a& min = node->mExtents[0];
LLVector4a& max = node->mExtents[1]; LLVector4a& max = node->mExtents[1];
if (!branch->getData().empty()) if (!branch->isEmpty())
{ //node has data, find AABB that binds data set { //node has data, find AABB that binds data set
const LLVolumeTriangle* tri = *(branch->getData().begin()); const LLVolumeTriangle* tri = *(branch->getDataBegin());
//initialize min/max to first available vertex //initialize min/max to first available vertex
min = *(tri->mV[0]); min = *(tri->mV[0]);
max = *(tri->mV[0]); max = *(tri->mV[0]);
for (LLOctreeNode<LLVolumeTriangle>::const_element_iter iter = for (LLOctreeNode<LLVolumeTriangle>::const_element_iter iter =
branch->getData().begin(); iter != branch->getData().end(); ++iter) branch->getDataBegin(); iter != branch->getDataEnd(); ++iter)
{ //for each triangle in node { //for each triangle in node
//stretch by triangles in node //stretch by triangles in node

View File

@@ -131,7 +131,7 @@ void LLOctreeTriangleRayIntersect::traverse(const LLOctreeNode<LLVolumeTriangle>
void LLOctreeTriangleRayIntersect::visit(const LLOctreeNode<LLVolumeTriangle>* node) void LLOctreeTriangleRayIntersect::visit(const LLOctreeNode<LLVolumeTriangle>* node)
{ {
for (LLOctreeNode<LLVolumeTriangle>::const_element_iter iter = for (LLOctreeNode<LLVolumeTriangle>::const_element_iter iter =
node->getData().begin(); iter != node->getData().end(); ++iter) node->getDataBegin(); iter != node->getDataEnd(); ++iter)
{ {
const LLVolumeTriangle* tri = *iter; const LLVolumeTriangle* tri = *iter;
@@ -236,8 +236,8 @@ void LLVolumeOctreeValidate::visit(const LLOctreeNode<LLVolumeTriangle>* branch)
} }
//children fit, check data //children fit, check data
for (LLOctreeNode<LLVolumeTriangle>::const_element_iter iter = branch->getData().begin(); for (LLOctreeNode<LLVolumeTriangle>::const_element_iter iter = branch->getDataBegin();
iter != branch->getData().end(); ++iter) iter != branch->getDataEnd(); ++iter)
{ {
const LLVolumeTriangle* tri = *iter; const LLVolumeTriangle* tri = *iter;

View File

@@ -39,7 +39,7 @@ class LLVolumeTriangle : public LLRefCount
public: public:
LLVolumeTriangle() LLVolumeTriangle()
{ {
mBinIndex = -1;
} }
LLVolumeTriangle(const LLVolumeTriangle& rhs) LLVolumeTriangle(const LLVolumeTriangle& rhs)
@@ -64,9 +64,14 @@ public:
U16 mIndex[3]; U16 mIndex[3];
F32 mRadius; F32 mRadius;
mutable S32 mBinIndex;
virtual const LLVector4a& getPositionGroup() const; virtual const LLVector4a& getPositionGroup() const;
virtual const F32& getBinRadius() const; virtual const F32& getBinRadius() const;
S32 getBinIndex() const { return mBinIndex; }
void setBinIndex(S32 idx) const { mBinIndex = idx; }
}; };
class LLVolumeOctreeListener : public LLOctreeListener<LLVolumeTriangle> class LLVolumeOctreeListener : public LLOctreeListener<LLVolumeTriangle>

View File

@@ -113,6 +113,7 @@ void LLDrawable::init()
mGeneration = -1; mGeneration = -1;
mBinRadius = 1.f; mBinRadius = 1.f;
mBinIndex = -1;
mSpatialBridge = NULL; mSpatialBridge = NULL;
} }
@@ -963,6 +964,12 @@ void LLDrawable::updateUVMinMax()
{ {
} }
LLSpatialGroup* LLDrawable::getSpatialGroup() const
{
llassert((mSpatialGroupp == NULL) ? getBinIndex() == -1 : getBinIndex() != -1);
return mSpatialGroupp;
}
void LLDrawable::setSpatialGroup(LLSpatialGroup *groupp) void LLDrawable::setSpatialGroup(LLSpatialGroup *groupp)
{ {
/*if (mSpatialGroupp && (groupp != mSpatialGroupp)) /*if (mSpatialGroupp && (groupp != mSpatialGroupp))
@@ -985,6 +992,8 @@ void LLDrawable::setSpatialGroup(LLSpatialGroup *groupp)
} }
mSpatialGroupp = groupp; mSpatialGroupp = groupp;
llassert((mSpatialGroupp == NULL) ? getBinIndex() == -1 : getBinIndex() != -1);
} }
LLSpatialPartition* LLDrawable::getSpatialPartition() LLSpatialPartition* LLDrawable::getSpatialPartition()
@@ -1107,6 +1116,8 @@ LLSpatialBridge::LLSpatialBridge(LLDrawable* root, BOOL render_by_group, U32 dat
mDrawable = root; mDrawable = root;
root->setSpatialBridge(this); root->setSpatialBridge(this);
mBinIndex = -1;
mRenderType = mDrawable->mRenderType; mRenderType = mDrawable->mRenderType;
mDrawableType = mDrawable->mRenderType; mDrawableType = mDrawable->mRenderType;
@@ -1500,7 +1511,13 @@ void LLSpatialBridge::cleanupReferences()
LLDrawable::cleanupReferences(); LLDrawable::cleanupReferences();
if (mDrawable) if (mDrawable)
{ {
mDrawable->setSpatialGroup(NULL); LLSpatialGroup* group = mDrawable->getSpatialGroup();
if (group)
{
group->mOctreeNode->remove(mDrawable);
mDrawable->setSpatialGroup(NULL);
}
if (mDrawable->getVObj()) if (mDrawable->getVObj())
{ {
LLViewerObject::const_child_list_t& child_list = mDrawable->getVObj()->getChildren(); LLViewerObject::const_child_list_t& child_list = mDrawable->getVObj()->getChildren();
@@ -1511,7 +1528,12 @@ void LLSpatialBridge::cleanupReferences()
LLDrawable* drawable = child->mDrawable; LLDrawable* drawable = child->mDrawable;
if (drawable) if (drawable)
{ {
drawable->setSpatialGroup(NULL); LLSpatialGroup* group = drawable->getSpatialGroup();
if (group)
{
group->mOctreeNode->remove(drawable);
drawable->setSpatialGroup(NULL);
}
} }
} }
} }

View File

@@ -115,6 +115,9 @@ public:
F32 getIntensity() const { return llmin(mXform.getScale().mV[0], 4.f); } F32 getIntensity() const { return llmin(mXform.getScale().mV[0], 4.f); }
S32 getLOD() const { return mVObjp ? mVObjp->getLOD() : 1; } S32 getLOD() const { return mVObjp ? mVObjp->getLOD() : 1; }
F32 getBinRadius() const { return mBinRadius; } F32 getBinRadius() const { return mBinRadius; }
S32 getBinIndex() const { return mBinIndex; }
void setBinIndex(S32 index) const { mBinIndex = index; }
void getMinMax(LLVector3& min,LLVector3& max) const { mXform.getMinMax(min,max); } void getMinMax(LLVector3& min,LLVector3& max) const { mXform.getMinMax(min,max); }
LLXformMatrix* getXform() { return &mXform; } LLXformMatrix* getXform() { return &mXform; }
@@ -200,7 +203,7 @@ public:
S32 findReferences(LLDrawable *drawablep); // Not const because of @#$! iterators... S32 findReferences(LLDrawable *drawablep); // Not const because of @#$! iterators...
void setSpatialGroup(LLSpatialGroup *groupp); void setSpatialGroup(LLSpatialGroup *groupp);
LLSpatialGroup *getSpatialGroup() const { return mSpatialGroupp; } LLSpatialGroup *getSpatialGroup() const;
LLSpatialPartition* getSpatialPartition(); LLSpatialPartition* getSpatialPartition();
// Statics // Statics
@@ -321,6 +324,7 @@ private:
mutable U32 mVisible; mutable U32 mVisible;
F32 mRadius; F32 mRadius;
F32 mBinRadius; F32 mBinRadius;
mutable S32 mBinIndex;
S32 mGeneration; S32 mGeneration;
LLVector3 mCurrentScale; LLVector3 mCurrentScale;

View File

@@ -1209,19 +1209,25 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume,
{ {
if (num_indices + (S32) mIndicesIndex > mVertexBuffer->getNumIndices()) if (num_indices + (S32) mIndicesIndex > mVertexBuffer->getNumIndices())
{ {
llwarns << "Index buffer overflow!" << llendl; if (gDebugGL)
llwarns << "Indices Count: " << mIndicesCount {
<< " VF Num Indices: " << num_indices llwarns << "Index buffer overflow!" << llendl;
<< " Indices Index: " << mIndicesIndex llwarns << "Indices Count: " << mIndicesCount
<< " VB Num Indices: " << mVertexBuffer->getNumIndices() << llendl; << " VF Num Indices: " << num_indices
llwarns << " Face Index: " << f << " Indices Index: " << mIndicesIndex
<< " Pool Type: " << mPoolType << llendl; << " VB Num Indices: " << mVertexBuffer->getNumIndices() << llendl;
llwarns << " Face Index: " << f
<< " Pool Type: " << mPoolType << llendl;
}
return FALSE; return FALSE;
} }
if (num_vertices + mGeomIndex > mVertexBuffer->getNumVerts()) if (num_vertices + mGeomIndex > mVertexBuffer->getNumVerts())
{ {
llwarns << "Vertex buffer overflow!" << llendl; if (gDebugGL)
{
llwarns << "Vertex buffer overflow!" << llendl;
}
return FALSE; return FALSE;
} }
} }

View File

@@ -424,7 +424,7 @@ void LLSpatialGroup::validate()
validateDrawMap(); validateDrawMap();
for (element_iter i = getData().begin(); i != getData().end(); ++i) for (element_iter i = getDataBegin(); i != getDataEnd(); ++i)
{ {
LLDrawable* drawable = *i; LLDrawable* drawable = *i;
sg_assert(drawable->getSpatialGroup() == this); sg_assert(drawable->getSpatialGroup() == this);
@@ -640,7 +640,7 @@ BOOL LLSpatialGroup::boundObjects(BOOL empty, LLVector4a& minOut, LLVector4a& ma
{ {
const OctreeNode* node = mOctreeNode; const OctreeNode* node = mOctreeNode;
if (node->getData().empty()) if (node->isEmpty())
{ //don't do anything if there are no objects { //don't do anything if there are no objects
if (empty && mOctreeNode->getParent()) if (empty && mOctreeNode->getParent())
{ //only root is allowed to be empty { //only root is allowed to be empty
@@ -657,14 +657,14 @@ BOOL LLSpatialGroup::boundObjects(BOOL empty, LLVector4a& minOut, LLVector4a& ma
clearState(OBJECT_DIRTY); clearState(OBJECT_DIRTY);
//initialize bounding box to first element //initialize bounding box to first element
OctreeNode::const_element_iter i = node->getData().begin(); OctreeNode::const_element_iter i = node->getDataBegin();
LLDrawable* drawablep = *i; LLDrawable* drawablep = *i;
const LLVector4a* minMax = drawablep->getSpatialExtents(); const LLVector4a* minMax = drawablep->getSpatialExtents();
newMin = minMax[0]; newMin = minMax[0];
newMax = minMax[1]; newMax = minMax[1];
for (++i; i != node->getData().end(); ++i) for (++i; i != node->getDataEnd(); ++i)
{ {
drawablep = *i; drawablep = *i;
minMax = drawablep->getSpatialExtents(); minMax = drawablep->getSpatialExtents();
@@ -1124,7 +1124,7 @@ void LLSpatialGroup::updateDistance(LLCamera &camera)
llerrs << "Spatial group dirty on distance update." << llendl; llerrs << "Spatial group dirty on distance update." << llendl;
} }
#endif #endif
if (!getData().empty() /*&& !LLSpatialPartition::sFreezeState*/) if (!isEmpty() /*&& !LLSpatialPartition::sFreezeState*/)
{ {
mRadius = mSpatialPartition->mRenderByGroup ? mObjectBounds[1].getLength3().getF32() : mRadius = mSpatialPartition->mRenderByGroup ? mObjectBounds[1].getLength3().getF32() :
(F32) mOctreeNode->getSize().getLength3().getF32(); (F32) mOctreeNode->getSize().getLength3().getF32();
@@ -1276,7 +1276,7 @@ void LLSpatialGroup::handleDestruction(const TreeNode* node)
LLMemType mt(LLMemType::MTYPE_SPACE_PARTITION); LLMemType mt(LLMemType::MTYPE_SPACE_PARTITION);
setState(DEAD); setState(DEAD);
for (element_iter i = getData().begin(); i != getData().end(); ++i) for (element_iter i = getDataBegin(); i != getDataEnd(); ++i)
{ {
LLDrawable* drawable = *i; LLDrawable* drawable = *i;
if (drawable->getSpatialGroup() == this) if (drawable->getSpatialGroup() == this)
@@ -1363,7 +1363,7 @@ void LLSpatialGroup::destroyGL(bool keep_occlusion)
} }
for (LLSpatialGroup::element_iter i = getData().begin(); i != getData().end(); ++i) for (LLSpatialGroup::element_iter i = getDataBegin(); i != getDataEnd(); ++i)
{ {
LLDrawable* drawable = *i; LLDrawable* drawable = *i;
for (S32 j = 0; j < drawable->getNumFaces(); j++) for (S32 j = 0; j < drawable->getNumFaces(); j++)
@@ -1720,12 +1720,14 @@ BOOL LLSpatialPartition::remove(LLDrawable *drawablep, LLSpatialGroup *curp)
{ {
LLMemType mt(LLMemType::MTYPE_SPACE_PARTITION); LLMemType mt(LLMemType::MTYPE_SPACE_PARTITION);
drawablep->setSpatialGroup(NULL);
if (!curp->removeObject(drawablep)) if (!curp->removeObject(drawablep))
{ {
OCT_ERRS << "Failed to remove drawable from octree!" << llendl; OCT_ERRS << "Failed to remove drawable from octree!" << llendl;
} }
else
{
drawablep->setSpatialGroup(NULL);
}
assert_octree_valid(mOctree); assert_octree_valid(mOctree);
@@ -1996,7 +1998,7 @@ public:
virtual void processGroup(LLSpatialGroup* group) virtual void processGroup(LLSpatialGroup* group)
{ {
llassert(!group->isState(LLSpatialGroup::DIRTY) && !group->getData().empty()) llassert(!group->isState(LLSpatialGroup::DIRTY) && !group->isEmpty())
if (mRes < 2) if (mRes < 2)
{ {
@@ -2063,7 +2065,7 @@ public:
{ {
LLSpatialGroup::OctreeNode* branch = group->mOctreeNode; LLSpatialGroup::OctreeNode* branch = group->mOctreeNode;
for (LLSpatialGroup::OctreeNode::const_element_iter i = branch->getData().begin(); i != branch->getData().end(); ++i) for (LLSpatialGroup::OctreeNode::const_element_iter i = branch->getDataBegin(); i != branch->getDataEnd(); ++i)
{ {
LLDrawable* drawable = *i; LLDrawable* drawable = *i;
@@ -2187,7 +2189,7 @@ public:
LLSpatialGroup* group = (LLSpatialGroup*) state->getListener(0); LLSpatialGroup* group = (LLSpatialGroup*) state->getListener(0);
group->destroyGL(); group->destroyGL();
for (LLSpatialGroup::element_iter i = group->getData().begin(); i != group->getData().end(); ++i) for (LLSpatialGroup::element_iter i = group->getDataBegin(); i != group->getDataEnd(); ++i)
{ {
LLDrawable* drawable = *i; LLDrawable* drawable = *i;
if (drawable->getVObj().notNull() && !group->mSpatialPartition->mRenderByGroup) if (drawable->getVObj().notNull() && !group->mSpatialPartition->mRenderByGroup)
@@ -2500,7 +2502,7 @@ void renderOctree(LLSpatialGroup* group)
gGL.flush(); gGL.flush();
glLineWidth(1.f); glLineWidth(1.f);
gGL.flush(); gGL.flush();
for (LLSpatialGroup::element_iter i = group->getData().begin(); i != group->getData().end(); ++i) for (LLSpatialGroup::element_iter i = group->getDataBegin(); i != group->getDataEnd(); ++i)
{ {
LLDrawable* drawable = *i; LLDrawable* drawable = *i;
if (!group->mSpatialPartition->isBridge()) if (!group->mSpatialPartition->isBridge())
@@ -2546,7 +2548,7 @@ void renderOctree(LLSpatialGroup* group)
} }
else else
{ {
if (group->mBufferUsage == GL_STATIC_DRAW_ARB && !group->getData().empty() if (group->mBufferUsage == GL_STATIC_DRAW_ARB && !group->isEmpty()
&& group->mSpatialPartition->mRenderByGroup) && group->mSpatialPartition->mRenderByGroup)
{ {
col.setVec(0.8f, 0.4f, 0.1f, 0.1f); col.setVec(0.8f, 0.4f, 0.1f, 0.1f);
@@ -2614,7 +2616,7 @@ void renderVisibility(LLSpatialGroup* group, LLCamera* camera)
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
BOOL render_objects = (!LLPipeline::sUseOcclusion || !group->isOcclusionState(LLSpatialGroup::OCCLUDED)) && group->isVisible() && BOOL render_objects = (!LLPipeline::sUseOcclusion || !group->isOcclusionState(LLSpatialGroup::OCCLUDED)) && group->isVisible() &&
!group->getData().empty(); !group->isEmpty();
if (render_objects) if (render_objects)
{ {
@@ -3356,7 +3358,7 @@ void renderPhysicsShape(LLDrawable* drawable, LLVOVolume* volume)
void renderPhysicsShapes(LLSpatialGroup* group) void renderPhysicsShapes(LLSpatialGroup* group)
{ {
for (LLSpatialGroup::OctreeNode::const_element_iter i = group->getData().begin(); i != group->getData().end(); ++i) for (LLSpatialGroup::OctreeNode::const_element_iter i = group->getDataBegin(); i != group->getDataEnd(); ++i)
{ {
LLDrawable* drawable = *i; LLDrawable* drawable = *i;
LLVOVolume* volume = drawable->getVOVolume(); LLVOVolume* volume = drawable->getVOVolume();
@@ -3601,7 +3603,7 @@ public:
LLVector3 center, size; LLVector3 center, size;
if (branch->getData().empty()) if (branch->isEmpty())
{ {
gGL.diffuseColor3f(1.f,0.2f,0.f); gGL.diffuseColor3f(1.f,0.2f,0.f);
center.set(branch->getCenter().getF32ptr()); center.set(branch->getCenter().getF32ptr());
@@ -3637,8 +3639,8 @@ public:
} }
gGL.begin(LLRender::TRIANGLES); gGL.begin(LLRender::TRIANGLES);
for (LLOctreeNode<LLVolumeTriangle>::const_element_iter iter = branch->getData().begin(); for (LLOctreeNode<LLVolumeTriangle>::const_element_iter iter = branch->getDataBegin();
iter != branch->getData().end(); iter != branch->getDataEnd();
++iter) ++iter)
{ {
const LLVolumeTriangle* tri = *iter; const LLVolumeTriangle* tri = *iter;
@@ -3875,7 +3877,7 @@ public:
if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_BBOXES)) if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_BBOXES))
{ {
if (!group->getData().empty()) if (!group->isEmpty())
{ {
gGL.diffuseColor3f(0,0,1); gGL.diffuseColor3f(0,0,1);
drawBoxOutline(group->mObjectBounds[0], drawBoxOutline(group->mObjectBounds[0],
@@ -3883,7 +3885,7 @@ public:
} }
} }
for (LLSpatialGroup::OctreeNode::const_element_iter i = branch->getData().begin(); i != branch->getData().end(); ++i) for (LLSpatialGroup::OctreeNode::const_element_iter i = branch->getDataBegin(); i != branch->getDataEnd(); ++i)
{ {
LLDrawable* drawable = *i; LLDrawable* drawable = *i;
@@ -4068,7 +4070,7 @@ public:
return; return;
} }
for (LLSpatialGroup::OctreeNode::const_element_iter i = branch->getData().begin(); i != branch->getData().end(); ++i) for (LLSpatialGroup::OctreeNode::const_element_iter i = branch->getDataBegin(); i != branch->getDataEnd(); ++i)
{ {
LLDrawable* drawable = *i; LLDrawable* drawable = *i;
@@ -4291,7 +4293,7 @@ public:
virtual void visit(const LLSpatialGroup::OctreeNode* branch) virtual void visit(const LLSpatialGroup::OctreeNode* branch)
{ {
for (LLSpatialGroup::OctreeNode::const_element_iter i = branch->getData().begin(); i != branch->getData().end(); ++i) for (LLSpatialGroup::OctreeNode::const_element_iter i = branch->getDataBegin(); i != branch->getDataEnd(); ++i)
{ {
check(*i); check(*i);
} }

View File

@@ -330,8 +330,13 @@ public:
void dirtyGeom() { setState(GEOM_DIRTY); } void dirtyGeom() { setState(GEOM_DIRTY); }
void dirtyMesh() { setState(MESH_DIRTY); } void dirtyMesh() { setState(MESH_DIRTY); }
//octree wrappers to make code more readable
element_list& getData() { return mOctreeNode->getData(); } element_list& getData() { return mOctreeNode->getData(); }
element_iter getDataBegin() { return mOctreeNode->getDataBegin(); }
element_iter getDataEnd() { return mOctreeNode->getDataEnd(); }
U32 getElementCount() const { return mOctreeNode->getElementCount(); } U32 getElementCount() const { return mOctreeNode->getElementCount(); }
bool isEmpty() const { return mOctreeNode->isEmpty(); }
void drawObjectBox(LLColor4 col); void drawObjectBox(LLColor4 col);

View File

@@ -645,7 +645,7 @@ void LLGrassPartition::addGeometryCount(LLSpatialGroup* group, U32& vertex_count
mFaceList.clear(); mFaceList.clear();
LLViewerCamera* camera = LLViewerCamera::getInstance(); LLViewerCamera* camera = LLViewerCamera::getInstance();
for (LLSpatialGroup::element_iter i = group->getData().begin(); i != group->getData().end(); ++i) for (LLSpatialGroup::element_iter i = group->getDataBegin(); i != group->getDataEnd(); ++i)
{ {
LLDrawable* drawablep = *i; LLDrawable* drawablep = *i;

View File

@@ -582,7 +582,7 @@ void LLParticlePartition::addGeometryCount(LLSpatialGroup* group, U32& vertex_co
mFaceList.clear(); mFaceList.clear();
LLViewerCamera* camera = LLViewerCamera::getInstance(); LLViewerCamera* camera = LLViewerCamera::getInstance();
for (LLSpatialGroup::element_iter i = group->getData().begin(); i != group->getData().end(); ++i) for (LLSpatialGroup::element_iter i = group->getDataBegin(); i != group->getDataEnd(); ++i)
{ {
LLDrawable* drawablep = *i; LLDrawable* drawablep = *i;

View File

@@ -2390,7 +2390,7 @@ U32 LLVOVolume::getRenderCost(texture_cost_t &textures) const
produces_light = 1; produces_light = 1;
} }
for (S32 i = 0; i < num_faces; ++i) for (S32 i = 0; i < (S32)num_faces; ++i)
{ {
const LLFace* face = drawablep->getFace(i); const LLFace* face = drawablep->getFace(i);
if (!face) continue; if (!face) continue;
@@ -3481,7 +3481,7 @@ void LLVolumeGeometryManager::rebuildGeom(LLSpatialGroup* group)
LLFastTimer t(FTM_REBUILD_VOLUME_FACE_LIST); LLFastTimer t(FTM_REBUILD_VOLUME_FACE_LIST);
//get all the faces into a list //get all the faces into a list
for (LLSpatialGroup::element_iter drawable_iter = group->getData().begin(); drawable_iter != group->getData().end(); ++drawable_iter) for (LLSpatialGroup::element_iter drawable_iter = group->getDataBegin(); drawable_iter != group->getDataEnd(); ++drawable_iter)
{ {
LLDrawable* drawablep = *drawable_iter; LLDrawable* drawablep = *drawable_iter;
@@ -3887,7 +3887,7 @@ void LLVolumeGeometryManager::rebuildGeom(LLSpatialGroup* group)
if (!LLPipeline::sDelayVBUpdate) if (!LLPipeline::sDelayVBUpdate)
{ {
//drawables have been rebuilt, clear rebuild status //drawables have been rebuilt, clear rebuild status
for (LLSpatialGroup::element_iter drawable_iter = group->getData().begin(); drawable_iter != group->getData().end(); ++drawable_iter) for (LLSpatialGroup::element_iter drawable_iter = group->getDataBegin(); drawable_iter != group->getDataEnd(); ++drawable_iter)
{ {
LLDrawable* drawablep = *drawable_iter; LLDrawable* drawablep = *drawable_iter;
drawablep->clearState(LLDrawable::REBUILD_ALL); drawablep->clearState(LLDrawable::REBUILD_ALL);
@@ -3927,7 +3927,7 @@ void LLVolumeGeometryManager::rebuildMesh(LLSpatialGroup* group)
std::set<LLVertexBuffer*> mapped_buffers; std::set<LLVertexBuffer*> mapped_buffers;
for (LLSpatialGroup::element_iter drawable_iter = group->getData().begin(); drawable_iter != group->getData().end(); ++drawable_iter) for (LLSpatialGroup::element_iter drawable_iter = group->getDataBegin(); drawable_iter != group->getDataEnd(); ++drawable_iter)
{ {
LLDrawable* drawablep = *drawable_iter; LLDrawable* drawablep = *drawable_iter;
@@ -3951,8 +3951,14 @@ void LLVolumeGeometryManager::rebuildMesh(LLSpatialGroup* group)
if (buff) if (buff)
{ {
llassert(!face->isState(LLFace::RIGGED)); llassert(!face->isState(LLFace::RIGGED));
face->getGeometryVolume(*volume, face->getTEOffset(),
vobj->getRelativeXform(), vobj->getRelativeXformInvTrans(), face->getGeomIndex()); if (!face->getGeometryVolume(*volume, face->getTEOffset(),
vobj->getRelativeXform(), vobj->getRelativeXformInvTrans(), face->getGeomIndex()))
{ //something's gone wrong with the vertex buffer accounting, rebuild this group
group->dirtyGeom();
gPipeline.markRebuild(group, TRUE);
}
if (buff->isLocked()) if (buff->isLocked())
{ {
@@ -3993,7 +3999,7 @@ void LLVolumeGeometryManager::rebuildMesh(LLSpatialGroup* group)
llwarns << "Not all mapped vertex buffers are unmapped!" << llendl ; llwarns << "Not all mapped vertex buffers are unmapped!" << llendl ;
warningsCount = 1; warningsCount = 1;
} }
for (LLSpatialGroup::element_iter drawable_iter = group->getData().begin(); drawable_iter != group->getData().end(); ++drawable_iter) for (LLSpatialGroup::element_iter drawable_iter = group->getDataBegin(); drawable_iter != group->getDataEnd(); ++drawable_iter)
{ {
LLDrawable* drawablep = *drawable_iter; LLDrawable* drawablep = *drawable_iter;
for (S32 i = 0; i < drawablep->getNumFaces(); ++i) for (S32 i = 0; i < drawablep->getNumFaces(); ++i)
@@ -4294,8 +4300,11 @@ void LLVolumeGeometryManager::genDrawInfo(LLSpatialGroup* group, U32 mask, std::
llassert(!facep->isState(LLFace::RIGGED)); llassert(!facep->isState(LLFace::RIGGED));
facep->getGeometryVolume(*volume, te_idx, if (!facep->getGeometryVolume(*volume, te_idx,
vobj->getRelativeXform(), vobj->getRelativeXformInvTrans(), index_offset,true); vobj->getRelativeXform(), vobj->getRelativeXformInvTrans(), index_offset,true))
{
llwarns << "Failed to get geometry for face!" << llendl;
}
if (drawablep->isState(LLDrawable::ANIMATED_CHILD)) if (drawablep->isState(LLDrawable::ANIMATED_CHILD))
{ {
@@ -4464,7 +4473,7 @@ void LLGeometryManager::addGeometryCount(LLSpatialGroup* group, U32 &vertex_coun
//for each drawable //for each drawable
for (LLSpatialGroup::element_iter drawable_iter = group->getData().begin(); drawable_iter != group->getData().end(); ++drawable_iter) for (LLSpatialGroup::element_iter drawable_iter = group->getDataBegin(); drawable_iter != group->getDataEnd(); ++drawable_iter)
{ {
LLDrawable* drawablep = *drawable_iter; LLDrawable* drawablep = *drawable_iter;

View File

@@ -1174,7 +1174,7 @@ public:
{ {
LLSpatialGroup* group = (LLSpatialGroup*) node->getListener(0); LLSpatialGroup* group = (LLSpatialGroup*) node->getListener(0);
if (!group->isState(LLSpatialGroup::GEOM_DIRTY) && !group->getData().empty()) if (!group->isState(LLSpatialGroup::GEOM_DIRTY) && !group->isEmpty())
{ {
for (LLSpatialGroup::draw_map_t::iterator i = group->mDrawMap.begin(); i != group->mDrawMap.end(); ++i) for (LLSpatialGroup::draw_map_t::iterator i = group->mDrawMap.begin(); i != group->mDrawMap.end(); ++i)
{ {
@@ -1781,7 +1781,7 @@ void LLPipeline::clearReferences()
void check_references(LLSpatialGroup* group, LLDrawable* drawable) void check_references(LLSpatialGroup* group, LLDrawable* drawable)
{ {
for (LLSpatialGroup::element_iter i = group->getData().begin(); i != group->getData().end(); ++i) for (LLSpatialGroup::element_iter i = group->getDataBegin(); i != group->getDataEnd(); ++i)
{ {
if (drawable == *i) if (drawable == *i)
{ {
@@ -1803,7 +1803,7 @@ void check_references(LLDrawable* drawable, LLFace* face)
void check_references(LLSpatialGroup* group, LLFace* face) void check_references(LLSpatialGroup* group, LLFace* face)
{ {
for (LLSpatialGroup::element_iter i = group->getData().begin(); i != group->getData().end(); ++i) for (LLSpatialGroup::element_iter i = group->getDataBegin(); i != group->getDataEnd(); ++i)
{ {
LLDrawable* drawable = *i; LLDrawable* drawable = *i;
check_references(drawable, face); check_references(drawable, face);
@@ -2179,7 +2179,7 @@ void LLPipeline::updateCull(LLCamera& camera, LLCullResult& result, S32 water_cl
void LLPipeline::markNotCulled(LLSpatialGroup* group, LLCamera& camera) void LLPipeline::markNotCulled(LLSpatialGroup* group, LLCamera& camera)
{ {
if (group->getData().empty()) if (group->isEmpty())
{ {
return; return;
} }
@@ -2827,7 +2827,7 @@ void LLPipeline::stateSort(LLCamera& camera, LLCullResult &result)
else else
{ {
group->setVisible(); group->setVisible();
for (LLSpatialGroup::element_iter i = group->getData().begin(); i != group->getData().end(); ++i) for (LLSpatialGroup::element_iter i = group->getDataBegin(); i != group->getDataEnd(); ++i)
{ {
markVisible(*i, camera); markVisible(*i, camera);
} }
@@ -2915,7 +2915,7 @@ void LLPipeline::stateSort(LLSpatialGroup* group, LLCamera& camera)
LLMemType mt(LLMemType::MTYPE_PIPELINE_STATE_SORT); LLMemType mt(LLMemType::MTYPE_PIPELINE_STATE_SORT);
if (!sSkipUpdate && group->changeLOD()) if (!sSkipUpdate && group->changeLOD())
{ {
for (LLSpatialGroup::element_iter i = group->getData().begin(); i != group->getData().end(); ++i) for (LLSpatialGroup::element_iter i = group->getDataBegin(); i != group->getDataEnd(); ++i)
{ {
LLDrawable* drawablep = *i; LLDrawable* drawablep = *i;
stateSort(drawablep, camera); stateSort(drawablep, camera);
@@ -3051,7 +3051,7 @@ void forAllDrawables(LLCullResult::sg_iterator begin,
{ {
for (LLCullResult::sg_iterator i = begin; i != end; ++i) for (LLCullResult::sg_iterator i = begin; i != end; ++i)
{ {
for (LLSpatialGroup::element_iter j = (*i)->getData().begin(); j != (*i)->getData().end(); ++j) for (LLSpatialGroup::element_iter j = (*i)->getDataBegin(); j != (*i)->getDataEnd(); ++j)
{ {
func(*j); func(*j);
} }