This commit templatizes the vertex classes on voxel types. This was the main change which was made for Cubiquity and it's very messy at the moment. However, this will improve when we make more use of 'auto' to hide the template madness.
This commit is contained in:
@ -29,9 +29,9 @@ freely, subject to the following restrictions:
|
||||
using namespace PolyVox;
|
||||
using namespace std;
|
||||
|
||||
void renderRegionImmediateMode(PolyVox::SurfaceMesh<PositionMaterialNormal>& mesh, unsigned int uLodLevel)
|
||||
void renderRegionImmediateMode(PolyVox::SurfaceMesh<PositionMaterialNormal<MaterialDensityPair44> >& mesh, unsigned int uLodLevel)
|
||||
{
|
||||
const vector<PositionMaterialNormal>& vecVertices = mesh.getVertices();
|
||||
const vector<PositionMaterialNormal<MaterialDensityPair44> >& 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<PositionMaterialNormal>& mes
|
||||
//for(vector<PolyVox::uint32_t>::const_iterator iterIndex = vecIndices.begin(); iterIndex != vecIndices.end(); ++iterIndex)
|
||||
for(int index = beginIndex; index < endIndex; ++index)
|
||||
{
|
||||
const PositionMaterialNormal& vertex = vecVertices[vecIndices[index]];
|
||||
const PositionMaterialNormal<MaterialDensityPair44> & 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());
|
||||
@ -49,7 +49,9 @@ void renderRegionImmediateMode(PolyVox::SurfaceMesh<PositionMaterialNormal>& mes
|
||||
|
||||
|
||||
|
||||
uint8_t material = static_cast<uint8_t>(vertex.getMaterial() + 0.5);
|
||||
//uint8_t material = static_cast<uint8_t>(static_cast<double>(vertex.getMaterial()) + 0.5);
|
||||
uint8_t material = 1;
|
||||
|
||||
|
||||
OpenGLColour colour = convertMaterialIDToColour(material);
|
||||
|
||||
|
@ -24,10 +24,11 @@ freely, subject to the following restrictions:
|
||||
#ifndef __OpenGLExample_OpenGLImmediateModeSupport_H__
|
||||
#define __OpenGLExample_OpenGLImmediateModeSupport_H__
|
||||
|
||||
#include "PolyVoxCore/MaterialDensityPair.h"
|
||||
#include "PolyVoxCore/PolyVoxForwardDeclarations.h"
|
||||
|
||||
#include "glew/glew.h"
|
||||
|
||||
void renderRegionImmediateMode(PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal>& mesh, unsigned int uLodLevel);
|
||||
void renderRegionImmediateMode(PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal<PolyVox::MaterialDensityPair44> >& mesh, unsigned int uLodLevel);
|
||||
|
||||
#endif //__OpenGLExample_OpenGLImmediateModeSupport_H__
|
||||
|
@ -24,12 +24,13 @@ freely, subject to the following restrictions:
|
||||
#include "OpenGLSupport.h"
|
||||
#include "OpenGLVertexBufferObjectSupport.h"
|
||||
|
||||
#include "PolyVoxCore/MaterialDensityPair.h"
|
||||
#include "PolyVoxCore/SurfaceMesh.h"
|
||||
|
||||
using namespace PolyVox;
|
||||
using namespace std;
|
||||
|
||||
OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const SurfaceMesh<PositionMaterialNormal>& mesh)
|
||||
OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const SurfaceMesh<PositionMaterialNormal<MaterialDensityPair44> >& mesh)
|
||||
{
|
||||
//Represents our filled in OpenGL vertex and index buffer objects.
|
||||
OpenGLSurfaceMesh result;
|
||||
@ -38,7 +39,7 @@ OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const SurfaceMesh<PositionMaterialNorma
|
||||
result.sourceMesh = &mesh;
|
||||
|
||||
//Convienient access to the vertices and indices
|
||||
const vector<PositionMaterialNormal>& vecVertices = mesh.getVertices();
|
||||
const vector<PositionMaterialNormal<MaterialDensityPair44> >& vecVertices = mesh.getVertices();
|
||||
const vector<uint32_t>& vecIndices = mesh.getIndices();
|
||||
|
||||
//If we have any indices...
|
||||
@ -62,9 +63,9 @@ OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const SurfaceMesh<PositionMaterialNorma
|
||||
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<PositionMaterialNormal>::const_iterator iterVertex = vecVertices.begin(); iterVertex != vecVertices.end(); ++iterVertex)
|
||||
for (vector<PositionMaterialNormal<MaterialDensityPair44> >::const_iterator iterVertex = vecVertices.begin(); iterVertex != vecVertices.end(); ++iterVertex)
|
||||
{
|
||||
const PositionMaterialNormal& vertex = *iterVertex;
|
||||
const PositionMaterialNormal<MaterialDensityPair44> & 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());
|
||||
@ -83,7 +84,8 @@ OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const SurfaceMesh<PositionMaterialNorma
|
||||
*ptr = vertex.getNormal().getZ();
|
||||
ptr++;
|
||||
|
||||
uint8_t material = static_cast<uint8_t>(vertex.getMaterial() + 0.5);
|
||||
//uint8_t material = static_cast<uint8_t>(vertex.getMaterial() + 0.5);
|
||||
uint8_t material = 1;
|
||||
|
||||
OpenGLColour colour = convertMaterialIDToColour(material);
|
||||
|
||||
|
@ -33,10 +33,10 @@ struct OpenGLSurfaceMesh
|
||||
GLulong noOfIndices;
|
||||
GLuint indexBuffer;
|
||||
GLuint vertexBuffer;
|
||||
const PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal>* sourceMesh;
|
||||
const PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal<PolyVox::MaterialDensityPair44> >* sourceMesh;
|
||||
};
|
||||
|
||||
OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal>& mesh);
|
||||
OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal<PolyVox::MaterialDensityPair44> >& mesh);
|
||||
void renderRegionVertexBufferObject(const OpenGLSurfaceMesh& openGLSurfaceMesh, unsigned int uLodLevel);
|
||||
|
||||
#endif //__OpenGLExample_OpenGLVertexBufferObjectSupport_H__
|
||||
|
@ -87,7 +87,7 @@ void OpenGLWidget::setVolume(PolyVox::LargeVolume<MaterialDensityPair44>* volDat
|
||||
//Extract the surface for this region
|
||||
//extractSurface(m_volData, 0, PolyVox::Region(regLowerCorner, regUpperCorner), meshCurrent);
|
||||
|
||||
std::shared_ptr< SurfaceMesh<PositionMaterialNormal> > mesh(new SurfaceMesh<PositionMaterialNormal>);
|
||||
std::shared_ptr< SurfaceMesh<PositionMaterialNormal<MaterialDensityPair44> > > mesh(new SurfaceMesh<PositionMaterialNormal<MaterialDensityPair44> >);
|
||||
MarchingCubesSurfaceExtractor< LargeVolume<MaterialDensityPair44> > surfaceExtractor(volData, PolyVox::Region(regLowerCorner, regUpperCorner), mesh.get());
|
||||
surfaceExtractor.execute();
|
||||
|
||||
@ -193,7 +193,7 @@ void OpenGLWidget::paintGL()
|
||||
Vector3DUint8 v3dRegPos(uRegionX,uRegionY,uRegionZ);
|
||||
if(m_mapSurfaceMeshes.find(v3dRegPos) != m_mapSurfaceMeshes.end())
|
||||
{
|
||||
std::shared_ptr< SurfaceMesh<PositionMaterialNormal> > meshCurrent = m_mapSurfaceMeshes[v3dRegPos];
|
||||
std::shared_ptr< SurfaceMesh<PositionMaterialNormal<MaterialDensityPair44> > > meshCurrent = m_mapSurfaceMeshes[v3dRegPos];
|
||||
unsigned int uLodLevel = 0; //meshCurrent->m_vecLodRecords.size() - 1;
|
||||
if(m_bUseOpenGLVertexBufferObjects)
|
||||
{
|
||||
|
@ -88,7 +88,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, Vector3DUint8Compare> m_mapOpenGLSurfaceMeshes;
|
||||
std::map<PolyVox::Vector3DUint8, std::shared_ptr<PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal> >, Vector3DUint8Compare> m_mapSurfaceMeshes;
|
||||
std::map<PolyVox::Vector3DUint8, std::shared_ptr<PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal<PolyVox::MaterialDensityPair44> > >, Vector3DUint8Compare> m_mapSurfaceMeshes;
|
||||
|
||||
unsigned int m_uRegionSideLength;
|
||||
unsigned int m_uVolumeWidthInRegions;
|
||||
|
Reference in New Issue
Block a user