Templatised SurfaceMesh class on vertex type.

Replaced 'SurfaceVertex' with PositionMaterial and PositionMaterialNormal classes.
Different surface extractors can now work with different vertex types.
This commit is contained in:
David Williams
2010-10-17 21:13:46 +00:00
parent 56ec37f5e2
commit 9e1de4ba72
28 changed files with 460 additions and 176 deletions

View File

@ -29,9 +29,9 @@ freely, subject to the following restrictions:
using namespace PolyVox;
using namespace std;
void renderRegionImmediateMode(PolyVox::SurfaceMesh& mesh, unsigned int uLodLevel)
void renderRegionImmediateMode(PolyVox::SurfaceMesh<PositionMaterialNormal>& mesh, unsigned int uLodLevel)
{
const vector<SurfaceVertex>& vecVertices = mesh.getVertices();
const vector<PositionMaterialNormal>& vecVertices = mesh.getVertices();
const vector<uint32_t>& vecIndices = mesh.getIndices();
int beginIndex = mesh.m_vecLodRecords[uLodLevel].beginIndex;
@ -41,7 +41,7 @@ void renderRegionImmediateMode(PolyVox::SurfaceMesh& mesh, unsigned int uLodLeve
//for(vector<PolyVox::uint32_t>::const_iterator iterIndex = vecIndices.begin(); iterIndex != vecIndices.end(); ++iterIndex)
for(int index = beginIndex; index < endIndex; ++index)
{
const SurfaceVertex& vertex = vecVertices[vecIndices[index]];
const PositionMaterialNormal& vertex = vecVertices[vecIndices[index]];
const Vector3DFloat& v3dVertexPos = vertex.getPosition();
//const Vector3DFloat v3dRegionOffset(uRegionX * g_uRegionSideLength, uRegionY * g_uRegionSideLength, uRegionZ * g_uRegionSideLength);
const Vector3DFloat v3dFinalVertexPos = v3dVertexPos + static_cast<Vector3DFloat>(mesh.m_Region.getLowerCorner());

View File

@ -28,6 +28,6 @@ freely, subject to the following restrictions:
#include "glew/glew.h"
void renderRegionImmediateMode(PolyVox::SurfaceMesh& mesh, unsigned int uLodLevel);
void renderRegionImmediateMode(PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal>& mesh, unsigned int uLodLevel);
#endif //__OpenGLExample_OpenGLImmediateModeSupport_H__

View File

@ -29,7 +29,7 @@ freely, subject to the following restrictions:
using namespace PolyVox;
using namespace std;
OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const SurfaceMesh& mesh)
OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const SurfaceMesh<PositionMaterialNormal>& mesh)
{
//Represents our filled in OpenGL vertex and index buffer objects.
OpenGLSurfaceMesh result;
@ -38,7 +38,7 @@ OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const SurfaceMesh& mesh)
result.sourceMesh = &mesh;
//Convienient access to the vertices and indices
const vector<SurfaceVertex>& vecVertices = mesh.getVertices();
const vector<PositionMaterialNormal>& vecVertices = mesh.getVertices();
const vector<uint32_t>& vecIndices = mesh.getIndices();
//If we have any indices...
@ -62,9 +62,9 @@ OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const SurfaceMesh& mesh)
glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(GLfloat) * 9, 0, GL_STATIC_DRAW);
GLfloat* ptr = (GLfloat*)glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
for(vector<SurfaceVertex>::const_iterator iterVertex = vecVertices.begin(); iterVertex != vecVertices.end(); ++iterVertex)
for(vector<PositionMaterialNormal>::const_iterator iterVertex = vecVertices.begin(); iterVertex != vecVertices.end(); ++iterVertex)
{
const SurfaceVertex& vertex = *iterVertex;
const PositionMaterialNormal& vertex = *iterVertex;
const Vector3DFloat& v3dVertexPos = vertex.getPosition();
//const Vector3DFloat v3dRegionOffset(uRegionX * g_uRegionSideLength, uRegionY * g_uRegionSideLength, uRegionZ * g_uRegionSideLength);
const Vector3DFloat v3dFinalVertexPos = v3dVertexPos + static_cast<Vector3DFloat>(mesh.m_Region.getLowerCorner());

View File

@ -33,10 +33,10 @@ struct OpenGLSurfaceMesh
GLulong noOfIndices;
GLuint indexBuffer;
GLuint vertexBuffer;
const PolyVox::SurfaceMesh* sourceMesh;
const PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal>* sourceMesh;
};
OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const PolyVox::SurfaceMesh& mesh);
OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal>& mesh);
void renderRegionVertexBufferObject(const OpenGLSurfaceMesh& openGLSurfaceMesh, unsigned int uLodLevel);
#endif //__OpenGLExample_OpenGLVertexBufferObjectSupport_H__

View File

@ -89,7 +89,7 @@ void OpenGLWidget::setVolume(PolyVox::Volume<MaterialDensityPair44>* volData)
//Extract the surface for this region
//extractSurface(m_volData, 0, PolyVox::Region(regLowerCorner, regUpperCorner), meshCurrent);
polyvox_shared_ptr<SurfaceMesh> mesh(new SurfaceMesh);
polyvox_shared_ptr< SurfaceMesh<PositionMaterialNormal> > mesh(new SurfaceMesh<PositionMaterialNormal>);
SurfaceExtractor<MaterialDensityPair44> surfaceExtractor(volData, PolyVox::Region(regLowerCorner, regUpperCorner), mesh.get());
surfaceExtractor.execute();
@ -229,7 +229,7 @@ void OpenGLWidget::paintGL()
Vector3DUint8 v3dRegPos(uRegionX,uRegionY,uRegionZ);
if(m_mapSurfaceMeshes.find(v3dRegPos) != m_mapSurfaceMeshes.end())
{
polyvox_shared_ptr<SurfaceMesh> meshCurrent = m_mapSurfaceMeshes[v3dRegPos];
polyvox_shared_ptr< SurfaceMesh<PositionMaterialNormal> > meshCurrent = m_mapSurfaceMeshes[v3dRegPos];
unsigned int uLodLevel = 0; //meshCurrent->m_vecLodRecords.size() - 1;
if(m_bUseOpenGLVertexBufferObjects)
{

View File

@ -73,7 +73,7 @@ class OpenGLWidget : public QGLWidget
//Rather than storing one big mesh, the volume is broken into regions and a mesh is stored for each region
std::map<PolyVox::Vector3DUint8, OpenGLSurfaceMesh> m_mapOpenGLSurfaceMeshes;
std::map<PolyVox::Vector3DUint8, polyvox_shared_ptr<PolyVox::SurfaceMesh> > m_mapSurfaceMeshes;
std::map<PolyVox::Vector3DUint8, polyvox_shared_ptr<PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal> > > m_mapSurfaceMeshes;
unsigned int m_uRegionSideLength;
unsigned int m_uVolumeWidthInRegions;