Commit 8f5a1f6f authored by hybrid's avatar hybrid

Change shadow node to use core::array

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3208 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 20c762c5
...@@ -34,9 +34,6 @@ CShadowVolumeSceneNode::~CShadowVolumeSceneNode() ...@@ -34,9 +34,6 @@ CShadowVolumeSceneNode::~CShadowVolumeSceneNode()
{ {
if (ShadowMesh) if (ShadowMesh)
ShadowMesh->drop(); ShadowMesh->drop();
for (u32 i=0; i<ShadowVolumes.size(); ++i)
delete [] ShadowVolumes[i].vertices;
} }
...@@ -50,30 +47,15 @@ void CShadowVolumeSceneNode::createShadowVolume(const core::vector3df& light) ...@@ -50,30 +47,15 @@ void CShadowVolumeSceneNode::createShadowVolume(const core::vector3df& light)
{ {
// get the next unused buffer // get the next unused buffer
svp = &ShadowVolumes[ShadowVolumesUsed]; svp = &ShadowVolumes[ShadowVolumesUsed];
if (svp->size >= IndexCount*5) svp->set_used(0);
svp->count = 0;
else
{
svp->size = IndexCount*5;
svp->count = 0;
delete [] svp->vertices;
svp->vertices = new core::vector3df[svp->size];
}
++ShadowVolumesUsed;
} }
else else
{ {
// add a buffer ShadowVolumes.push_back(SShadowVolume());
SShadowVolume tmp; svp = &ShadowVolumes.getLast();
// lets make a rather large shadowbuffer
tmp.size = IndexCount*5;
tmp.count = 0;
tmp.vertices = new core::vector3df[tmp.size];
ShadowVolumes.push_back(tmp);
svp = &ShadowVolumes[ShadowVolumes.size()-1];
++ShadowVolumesUsed;
} }
svp->reallocate(IndexCount*5);
++ShadowVolumesUsed;
const u32 faceCount = IndexCount / 3; const u32 faceCount = IndexCount / 3;
...@@ -101,15 +83,15 @@ void CShadowVolumeSceneNode::createShadowVolume(const core::vector3df& light) ...@@ -101,15 +83,15 @@ void CShadowVolumeSceneNode::createShadowVolume(const core::vector3df& light)
core::vector3df v4(v2 - ls); core::vector3df v4(v2 - ls);
// Add a quad (two triangles) to the vertex list // Add a quad (two triangles) to the vertex list
if (svp->vertices && svp->count < svp->size-5) if (svp->size() < svp->allocated_size()-5)
{ {
svp->vertices[svp->count++] = v1; svp->push_back(v1);
svp->vertices[svp->count++] = v2; svp->push_back(v2);
svp->vertices[svp->count++] = v3; svp->push_back(v3);
svp->vertices[svp->count++] = v2; svp->push_back(v2);
svp->vertices[svp->count++] = v4; svp->push_back(v4);
svp->vertices[svp->count++] = v3; svp->push_back(v3);
} }
} }
} }
...@@ -137,17 +119,17 @@ void CShadowVolumeSceneNode::createZFailVolume(s32 faceCount, u32& numEdges, ...@@ -137,17 +119,17 @@ void CShadowVolumeSceneNode::createZFailVolume(s32 faceCount, u32& numEdges,
{ {
FaceData[i] = false; // it's a back facing face FaceData[i] = false; // it's a back facing face
if (svp->vertices && svp->count < svp->size-5) if (svp->size() < svp->allocated_size()-5)
{ {
// add front cap // add front cap
svp->vertices[svp->count++] = v0; svp->push_back(v0);
svp->vertices[svp->count++] = v2; svp->push_back(v2);
svp->vertices[svp->count++] = v1; svp->push_back(v1);
// add back cap // add back cap
svp->vertices[svp->count++] = v0 - ls; svp->push_back(v0-ls);
svp->vertices[svp->count++] = v1 - ls; svp->push_back(v1-ls);
svp->vertices[svp->count++] = v2 - ls; svp->push_back(v2-ls);
} }
} }
else else
...@@ -223,15 +205,15 @@ void CShadowVolumeSceneNode::createZPassVolume(s32 faceCount, ...@@ -223,15 +205,15 @@ void CShadowVolumeSceneNode::createZPassVolume(s32 faceCount,
Edges[2*numEdges+1] = wFace0; Edges[2*numEdges+1] = wFace0;
++numEdges; ++numEdges;
if (caps && svp->vertices && svp->count < svp->size-5) if (caps && svp->size() < svp->allocated_size()-5)
{ {
svp->vertices[svp->count++] = Vertices[wFace0]; svp->push_back(Vertices[wFace0]);
svp->vertices[svp->count++] = Vertices[wFace2]; svp->push_back(Vertices[wFace2]);
svp->vertices[svp->count++] = Vertices[wFace1]; svp->push_back(Vertices[wFace1]);
svp->vertices[svp->count++] = Vertices[wFace0] - light; svp->push_back(Vertices[wFace0] - light);
svp->vertices[svp->count++] = Vertices[wFace1] - light; svp->push_back(Vertices[wFace1] - light);
svp->vertices[svp->count++] = Vertices[wFace2] - light; svp->push_back(Vertices[wFace2] - light);
} }
} }
} }
...@@ -356,8 +338,8 @@ void CShadowVolumeSceneNode::render() ...@@ -356,8 +338,8 @@ void CShadowVolumeSceneNode::render()
driver->setTransform(video::ETS_WORLD, Parent->getAbsoluteTransformation()); driver->setTransform(video::ETS_WORLD, Parent->getAbsoluteTransformation());
for (u32 i=0; i<ShadowVolumesUsed; ++i) for (u32 i=0; i<ShadowVolumesUsed; ++i)
driver->drawStencilShadowVolume(ShadowVolumes[i].vertices, driver->drawStencilShadowVolume(ShadowVolumes[i].pointer(),
ShadowVolumes[i].count, UseZFailMethod); ShadowVolumes[i].size(), UseZFailMethod);
if ( DebugDataVisible & scene::EDS_MESH_WIRE_OVERLAY ) if ( DebugDataVisible & scene::EDS_MESH_WIRE_OVERLAY )
{ {
...@@ -369,8 +351,8 @@ void CShadowVolumeSceneNode::render() ...@@ -369,8 +351,8 @@ void CShadowVolumeSceneNode::render()
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix); driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
for (u32 i=0; i<ShadowVolumesUsed; ++i) for (u32 i=0; i<ShadowVolumesUsed; ++i)
driver->drawVertexPrimitiveList(ShadowVolumes[i].vertices, driver->drawVertexPrimitiveList(ShadowVolumes[i].pointer(),
ShadowVolumes[i].count,0,0,video::EVT_STANDARD,scene::EPT_LINES); ShadowVolumes[i].size(),0,0);
} }
} }
...@@ -383,12 +365,10 @@ const core::aabbox3d<f32>& CShadowVolumeSceneNode::getBoundingBox() const ...@@ -383,12 +365,10 @@ const core::aabbox3d<f32>& CShadowVolumeSceneNode::getBoundingBox() const
//! Generates adjacency information based on mesh indices. //! Generates adjacency information based on mesh indices.
void CShadowVolumeSceneNode::calculateAdjacency(f32 epsilon) void CShadowVolumeSceneNode::calculateAdjacency()
{ {
Adjacency.set_used(IndexCount); Adjacency.set_used(IndexCount);
epsilon *= epsilon;
// go through all faces and fetch their three neighbours // go through all faces and fetch their three neighbours
for (u32 f=0; f<IndexCount; f+=3) for (u32 f=0; f<IndexCount; f+=3)
{ {
...@@ -428,7 +408,7 @@ void CShadowVolumeSceneNode::calculateAdjacency(f32 epsilon) ...@@ -428,7 +408,7 @@ void CShadowVolumeSceneNode::calculateAdjacency(f32 epsilon)
if (of == IndexCount) if (of == IndexCount)
Adjacency[f + edge] = f; Adjacency[f + edge] = f;
else else
Adjacency[f + edge] = of / 3; Adjacency[f + edge] = of/3;
} }
} }
} }
......
...@@ -46,19 +46,14 @@ namespace scene ...@@ -46,19 +46,14 @@ namespace scene
private: private:
struct SShadowVolume typedef core::array<core::vector3df> SShadowVolume;
{
core::vector3df* vertices;
u32 count;
u32 size;
};
void createShadowVolume(const core::vector3df& pos); void createShadowVolume(const core::vector3df& pos);
void createZPassVolume(s32 faceCount, u32& numEdges, core::vector3df light, SShadowVolume* svp, bool caps); void createZPassVolume(s32 faceCount, u32& numEdges, core::vector3df light, SShadowVolume* svp, bool caps);
void createZFailVolume(s32 faceCount, u32& numEdges, const core::vector3df& light, SShadowVolume* svp); void createZFailVolume(s32 faceCount, u32& numEdges, const core::vector3df& light, SShadowVolume* svp);
//! Generates adjacency information based on mesh indices. //! Generates adjacency information based on mesh indices.
void calculateAdjacency(f32 epsilon=0.0001f); void calculateAdjacency();
core::aabbox3d<f32> Box; core::aabbox3d<f32> Box;
...@@ -88,4 +83,3 @@ namespace scene ...@@ -88,4 +83,3 @@ namespace scene
} // end namespace irr } // end namespace irr
#endif #endif
Tests finished. 54 tests of 54 passed. Tests finished. 54 tests of 54 passed.
Compiled as DEBUG Compiled as DEBUG
Test suite pass at GMT Sun Feb 07 12:13:48 2010 Test suite pass at GMT Sun Feb 07 14:44:37 2010
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment