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:
David Williams
2014-05-07 23:47:18 +02:00
parent 4c2aea3db1
commit b0a8ca8a64
29 changed files with 898 additions and 882 deletions

View File

@ -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);