From a0bcd6b214e1800a16fd8584696d74ac344cd02f Mon Sep 17 00:00:00 2001 From: David Williams Date: Thu, 17 Jan 2008 21:44:16 +0000 Subject: [PATCH] Working on excessive batch count bug. --- include/IndexedSurfacePatch.h | 8 ++++++-- source/IndexedSurfacePatch.cpp | 17 +++++++++++++++++ source/PolyVoxSceneManager.cpp | 30 +++++++++++++++++++++--------- 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/include/IndexedSurfacePatch.h b/include/IndexedSurfacePatch.h index e2411fbc..963540d9 100644 --- a/include/IndexedSurfacePatch.h +++ b/include/IndexedSurfacePatch.h @@ -1,8 +1,8 @@ #ifndef __IndexedSurfacePatch_H__ #define __IndexedSurfacePatch_H__ -#include -#include +//#include +//#include #include "Constants.h" #include "IntegralVector3.h" @@ -28,6 +28,10 @@ namespace Ogre long int vertexIndices[OGRE_REGION_SIDE_LENGTH*2+1][OGRE_REGION_SIDE_LENGTH*2+1][OGRE_REGION_SIDE_LENGTH*2+1]; + static long int noOfVerticesSubmitted; + static long int noOfVerticesAccepted; + static long int noOfTrianglesSubmitted; + private: bool m_AllowDuplicateVertices; }; diff --git a/source/IndexedSurfacePatch.cpp b/source/IndexedSurfacePatch.cpp index b3a1280b..7ea4bdf2 100644 --- a/source/IndexedSurfacePatch.cpp +++ b/source/IndexedSurfacePatch.cpp @@ -2,6 +2,10 @@ namespace Ogre { + long int IndexedSurfacePatch::noOfVerticesSubmitted = 0; + long int IndexedSurfacePatch::noOfVerticesAccepted = 0; + long int IndexedSurfacePatch::noOfTrianglesSubmitted = 0; + IndexedSurfacePatch::IndexedSurfacePatch(bool allowDuplicateVertices) :m_AllowDuplicateVertices(allowDuplicateVertices) { @@ -14,6 +18,8 @@ namespace Ogre void IndexedSurfacePatch::addTriangle(const SurfaceVertex& v0,const SurfaceVertex& v1,const SurfaceVertex& v2) { + noOfTrianglesSubmitted++; + noOfVerticesSubmitted += 3; if(!m_AllowDuplicateVertices) { long int index = vertexIndices[long int(v0.getPosition().x +0.5)][long int(v0.getPosition().y +0.5)][long int(v0.getPosition().z +0.5)]; @@ -21,6 +27,9 @@ namespace Ogre { m_vecVertices.push_back(v0); m_vecTriangleIndices.push_back(m_vecVertices.size()-1); + vertexIndices[long int(v0.getPosition().x +0.5)][long int(v0.getPosition().y +0.5)][long int(v0.getPosition().z +0.5)] = m_vecVertices.size()-1; + + noOfVerticesAccepted++; } else { @@ -32,6 +41,9 @@ namespace Ogre { m_vecVertices.push_back(v1); m_vecTriangleIndices.push_back(m_vecVertices.size()-1); + vertexIndices[long int(v1.getPosition().x +0.5)][long int(v1.getPosition().y +0.5)][long int(v1.getPosition().z +0.5)] = m_vecVertices.size()-1; + + noOfVerticesAccepted++; } else { @@ -43,6 +55,9 @@ namespace Ogre { m_vecVertices.push_back(v2); m_vecTriangleIndices.push_back(m_vecVertices.size()-1); + vertexIndices[long int(v2.getPosition().x +0.5)][long int(v2.getPosition().y +0.5)][long int(v2.getPosition().z +0.5)] = m_vecVertices.size()-1; + + noOfVerticesAccepted++; } else { @@ -57,6 +72,8 @@ namespace Ogre m_vecTriangleIndices.push_back(m_vecVertices.size()-1); m_vecVertices.push_back(v2); m_vecTriangleIndices.push_back(m_vecVertices.size()-1); + + noOfVerticesAccepted += 3; } } diff --git a/source/PolyVoxSceneManager.cpp b/source/PolyVoxSceneManager.cpp index bf2a4b32..485a813f 100644 --- a/source/PolyVoxSceneManager.cpp +++ b/source/PolyVoxSceneManager.cpp @@ -144,13 +144,21 @@ namespace Ogre if(surfaceUpToDate[regionX][regionY][regionZ] == false) { //Generate the surface - //std::vector< std::vector > vertexData; - //std::vector< std::vector > indexData; IndexedSurfacePatch* singleMaterialPatch = new IndexedSurfacePatch(false); IndexedSurfacePatch* multiMaterialPatch = new IndexedSurfacePatch(true); generateMeshDataForRegion(regionX,regionY,regionZ, singleMaterialPatch, multiMaterialPatch); + /*if((singleMaterialPatch->m_vecVertices.size == 0) && (singleMaterialPatch->m_vecTriangleIndices.size == 0)) + { + //No geometry exists. We can delete the scene node if it exists (it might, if the region has only just become empty) + std::map::iterator iterSceneNode = sceneNodes.find(UIntVector3(regionX,regionY,regionZ)); + if(iterSceneNode != sceneNodes.end()) + { + getRootSceneNode()->removeChild + } + }*/ + //If a SceneNode doesn't exist in this position then create one. std::map::iterator iterSceneNode = sceneNodes.find(UIntVector3(regionX,regionY,regionZ)); SceneNode* sceneNode; @@ -175,21 +183,21 @@ namespace Ogre triangleCounter += iterSurfacePatch->second.getNoOfTriangles();*/ SurfacePatchRenderable* singleMaterialSurfacePatchRenderable = m_singleMaterialSurfaces[regionX][regionY][regionZ]; - SurfacePatchRenderable* multiMaterialSurfacePatchRenderable = m_multiMaterialSurfaces[regionX][regionY][regionZ]; + //SurfacePatchRenderable* multiMaterialSurfacePatchRenderable = m_multiMaterialSurfaces[regionX][regionY][regionZ]; if(singleMaterialSurfacePatchRenderable == 0) //if single is null then multi should also be null { //We have to create the surfaces singleMaterialSurfacePatchRenderable = new SurfacePatchRenderable(singleMaterialPatch,materialMap->getMaterialAtIndex(1)); - multiMaterialSurfacePatchRenderable = new SurfacePatchRenderable(multiMaterialPatch,materialMap->getMaterialAtIndex(2)); + //multiMaterialSurfacePatchRenderable = new SurfacePatchRenderable(multiMaterialPatch,materialMap->getMaterialAtIndex(2)); - multiMaterialSurfacePatchRenderable->setRenderQueueGroup(RENDER_QUEUE_3); + //multiMaterialSurfacePatchRenderable->setRenderQueueGroup(RENDER_QUEUE_3); singleMaterialSurfacePatchRenderable->setRenderQueueGroup(RENDER_QUEUE_4); m_singleMaterialSurfaces[regionX][regionY][regionZ] = singleMaterialSurfacePatchRenderable; sceneNode->attachObject(singleMaterialSurfacePatchRenderable); - m_multiMaterialSurfaces[regionX][regionY][regionZ] = multiMaterialSurfacePatchRenderable; - sceneNode->attachObject(multiMaterialSurfacePatchRenderable); + //m_multiMaterialSurfaces[regionX][regionY][regionZ] = multiMaterialSurfacePatchRenderable; + //sceneNode->attachObject(multiMaterialSurfacePatchRenderable); } else { @@ -197,8 +205,8 @@ namespace Ogre singleMaterialSurfacePatchRenderable->updateWithNewSurfacePatch(singleMaterialPatch); sceneNode->attachObject(singleMaterialSurfacePatchRenderable); - multiMaterialSurfacePatchRenderable->updateWithNewSurfacePatch(multiMaterialPatch); - sceneNode->attachObject(multiMaterialSurfacePatchRenderable); + //multiMaterialSurfacePatchRenderable->updateWithNewSurfacePatch(multiMaterialPatch); + //sceneNode->attachObject(multiMaterialSurfacePatchRenderable); } } //sceneNode->showBoundingBox(true); @@ -213,6 +221,10 @@ namespace Ogre //Now call the base class to do the actual visibility determination... SceneManager::_findVisibleObjects(cam, visibleBounds, onlyShadowCasters); + + LogManager::getSingleton().logMessage("\nNo of triangles = " + StringConverter::toString(IndexedSurfacePatch::noOfTrianglesSubmitted)); + LogManager::getSingleton().logMessage("No of vertices submitted = " + StringConverter::toString(IndexedSurfacePatch::noOfVerticesSubmitted)); + LogManager::getSingleton().logMessage("No of vertices accepted = " + StringConverter::toString(IndexedSurfacePatch::noOfVerticesAccepted)); } void PolyVoxSceneManager::setAllUpToDateFalse(void)