More work on Smooth LOD.
This commit is contained in:
@ -34,6 +34,28 @@ void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PositionMat
|
||||
m_uEndIndex = vecIndices.size();
|
||||
}
|
||||
|
||||
void OpenGLWidget::setSurfaceMeshToRenderLowLOD(const PolyVox::SurfaceMesh<PositionMaterialNormal>& surfaceMesh)
|
||||
{
|
||||
//Convienient access to the vertices and indices
|
||||
const vector<uint32_t>& vecIndices = surfaceMesh.getIndices();
|
||||
const vector<PositionMaterialNormal>& vecVertices = surfaceMesh.getVertices();
|
||||
|
||||
//Build an OpenGL index buffer
|
||||
glGenBuffers(1, &indexBufferLow);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferLow);
|
||||
const GLvoid* pIndices = static_cast<const GLvoid*>(&(vecIndices[0]));
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, vecIndices.size() * sizeof(uint32_t), pIndices, GL_STATIC_DRAW);
|
||||
|
||||
//Build an OpenGL vertex buffer
|
||||
glGenBuffers(1, &vertexBufferLow);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vertexBufferLow);
|
||||
const GLvoid* pVertices = static_cast<const GLvoid*>(&(vecVertices[0]));
|
||||
glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(PositionMaterialNormal), pVertices, GL_STATIC_DRAW);
|
||||
|
||||
m_uBeginIndexLow = 0;
|
||||
m_uEndIndexLow = vecIndices.size();
|
||||
}
|
||||
|
||||
void OpenGLWidget::initializeGL()
|
||||
{
|
||||
//We need GLEW to access recent OpenGL functionality
|
||||
@ -125,6 +147,16 @@ void OpenGLWidget::paintGL()
|
||||
glNormalPointer(GL_FLOAT, sizeof(PositionMaterialNormal), (GLvoid*)12);
|
||||
|
||||
glDrawRangeElements(GL_TRIANGLES, m_uBeginIndex, m_uEndIndex-1, m_uEndIndex - m_uBeginIndex, GL_UNSIGNED_INT, 0);
|
||||
|
||||
//Bind the index buffer
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferLow);
|
||||
|
||||
//Bind the vertex buffer
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vertexBufferLow);
|
||||
glVertexPointer(3, GL_FLOAT, sizeof(PositionMaterialNormal), 0);
|
||||
glNormalPointer(GL_FLOAT, sizeof(PositionMaterialNormal), (GLvoid*)12);
|
||||
|
||||
glDrawRangeElements(GL_TRIANGLES, m_uBeginIndexLow, m_uEndIndexLow-1, m_uEndIndexLow - m_uBeginIndexLow, GL_UNSIGNED_INT, 0);
|
||||
|
||||
GLenum errCode = glGetError();
|
||||
if(errCode != GL_NO_ERROR)
|
||||
|
@ -42,6 +42,7 @@ public:
|
||||
|
||||
//Convert a SrfaceMesh to OpenGL index/vertex buffers
|
||||
void setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal>& surfaceMesh);
|
||||
void setSurfaceMeshToRenderLowLOD(const PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal>& surfaceMesh);
|
||||
|
||||
protected:
|
||||
//Qt OpenGL functions
|
||||
@ -53,10 +54,16 @@ private:
|
||||
//Index/vertex buffer data
|
||||
GLuint m_uBeginIndex;
|
||||
GLuint m_uEndIndex;
|
||||
GLuint noOfIndices;
|
||||
//GLuint noOfIndices;
|
||||
GLuint indexBuffer;
|
||||
GLuint vertexBuffer;
|
||||
|
||||
GLuint m_uBeginIndexLow;
|
||||
GLuint m_uEndIndexLow;
|
||||
//GLuint noOfIndicesLow;
|
||||
GLuint indexBufferLow;
|
||||
GLuint vertexBufferLow;
|
||||
|
||||
//Mouse data
|
||||
QPoint m_LastFrameMousePos;
|
||||
QPoint m_CurrentMousePos;
|
||||
|
@ -91,20 +91,26 @@ int main(int argc, char *argv[])
|
||||
smoothRegion<SimpleVolume, Density8>(volData, volData.getEnclosingRegion());
|
||||
smoothRegion<SimpleVolume, Density8>(volData, volData.getEnclosingRegion());
|
||||
|
||||
RawVolume<Density8> volDataLowLOD(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(31, 31, 31)));
|
||||
RawVolume<Density8> volDataLowLOD(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(15, 31, 31)));
|
||||
|
||||
VolumeResampler<SimpleVolume, RawVolume, Density8> volumeResampler(&volData, volData.getEnclosingRegion(), &volDataLowLOD, volDataLowLOD.getEnclosingRegion());
|
||||
VolumeResampler<SimpleVolume, RawVolume, Density8> volumeResampler(&volData, PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(31, 63, 63)), &volDataLowLOD, volDataLowLOD.getEnclosingRegion());
|
||||
volumeResampler.execute();
|
||||
|
||||
//Extract the surface
|
||||
SurfaceMesh<PositionMaterialNormal> mesh;
|
||||
SurfaceExtractor<RawVolume, Density8 > surfaceExtractor(&volDataLowLOD, volDataLowLOD.getEnclosingRegion(), &mesh);
|
||||
SurfaceMesh<PositionMaterialNormal> meshLowLOD;
|
||||
SurfaceExtractor<RawVolume, Density8 > surfaceExtractor(&volDataLowLOD, volDataLowLOD.getEnclosingRegion(), &meshLowLOD);
|
||||
surfaceExtractor.execute();
|
||||
meshLowLOD.scaleVertices(2.0f);
|
||||
|
||||
mesh.scaleVertices(2.0f);
|
||||
//Extract the surface
|
||||
SurfaceMesh<PositionMaterialNormal> meshHighLOD;
|
||||
SurfaceExtractor<SimpleVolume, Density8 > surfaceExtractorHigh(&volData, PolyVox::Region(Vector3DInt32(32,0,0), Vector3DInt32(63, 63, 63)), &meshHighLOD);
|
||||
surfaceExtractorHigh.execute();
|
||||
meshHighLOD.translateVertices(Vector3DFloat(32, 0, 0));
|
||||
|
||||
//Pass the surface to the OpenGL window
|
||||
openGLWidget.setSurfaceMeshToRender(mesh);
|
||||
openGLWidget.setSurfaceMeshToRender(meshHighLOD);
|
||||
openGLWidget.setSurfaceMeshToRenderLowLOD(meshLowLOD);
|
||||
|
||||
//Run the message pump.
|
||||
return app.exec();
|
||||
|
Reference in New Issue
Block a user