Work on Qt version of example.

This commit is contained in:
David Williams 2009-03-28 00:21:13 +00:00
parent e50699ab63
commit dc39415eb8
2 changed files with 33 additions and 23 deletions

View File

@ -10,30 +10,32 @@ OpenGLWidget::OpenGLWidget(QWidget *parent)
{ {
g_bUseOpenGLVertexBufferObjects = true; g_bUseOpenGLVertexBufferObjects = true;
m_volData = new Volume<uint8>(g_uVolumeSideLength);
g_volData = new Volume<uint8>(g_uVolumeSideLength);
//Make our volume contain a sphere in the center. //Make our volume contain a sphere in the center.
uint16 minPos = 0; uint16 minPos = 0;
uint16 midPos = g_volData->getSideLength() / 2; uint16 midPos = m_volData->getSideLength() / 2;
uint16 maxPos = g_volData->getSideLength() - 1; uint16 maxPos = m_volData->getSideLength() - 1;
createCubeInVolume(*g_volData, Vector3DUint16(minPos, minPos, minPos), Vector3DUint16(maxPos, maxPos, maxPos), 0); createCubeInVolume(*m_volData, Vector3DUint16(minPos, minPos, minPos), Vector3DUint16(maxPos, maxPos, maxPos), 0);
createSphereInVolume(*g_volData, 50.0f, 5); createSphereInVolume(*m_volData, 50.0f, 5);
createSphereInVolume(*g_volData, 40.0f, 4); createSphereInVolume(*m_volData, 40.0f, 4);
createSphereInVolume(*g_volData, 30.0f, 3); createSphereInVolume(*m_volData, 30.0f, 3);
createSphereInVolume(*g_volData, 20.0f, 2); createSphereInVolume(*m_volData, 20.0f, 2);
createSphereInVolume(*g_volData, 10.0f, 1); createSphereInVolume(*m_volData, 10.0f, 1);
createCubeInVolume(*g_volData, Vector3DUint16(minPos, minPos, minPos), Vector3DUint16(midPos-1, midPos-1, midPos-1), 0); createCubeInVolume(*m_volData, Vector3DUint16(minPos, minPos, minPos), Vector3DUint16(midPos-1, midPos-1, midPos-1), 0);
createCubeInVolume(*g_volData, Vector3DUint16(midPos+1, midPos+1, minPos), Vector3DUint16(maxPos, maxPos, midPos-1), 0); createCubeInVolume(*m_volData, Vector3DUint16(midPos+1, midPos+1, minPos), Vector3DUint16(maxPos, maxPos, midPos-1), 0);
createCubeInVolume(*g_volData, Vector3DUint16(midPos+1, minPos, midPos+1), Vector3DUint16(maxPos, midPos-1, maxPos), 0); createCubeInVolume(*m_volData, Vector3DUint16(midPos+1, minPos, midPos+1), Vector3DUint16(maxPos, midPos-1, maxPos), 0);
createCubeInVolume(*g_volData, Vector3DUint16(minPos, midPos+1, midPos+1), Vector3DUint16(midPos-1, maxPos, maxPos), 0); createCubeInVolume(*m_volData, Vector3DUint16(minPos, midPos+1, midPos+1), Vector3DUint16(midPos-1, maxPos, maxPos), 0);
} }
void OpenGLWidget::setVolume(PolyVox::Volume<PolyVox::uint8>* volData)
{
}
void OpenGLWidget::initializeGL() void OpenGLWidget::initializeGL()
{ {
if(g_bUseOpenGLVertexBufferObjects) if(g_bUseOpenGLVertexBufferObjects)
@ -89,16 +91,21 @@ void OpenGLWidget::initializeGL()
Vector3DInt32 regUpperCorner(regionEndX, regionEndY, regionEndZ); Vector3DInt32 regUpperCorner(regionEndX, regionEndY, regionEndZ);
//Extract the surface for this region //Extract the surface for this region
extractReferenceSurface(g_volData, Region(regLowerCorner, regUpperCorner), ispCurrent); extractReferenceSurface(m_volData, Region(regLowerCorner, regUpperCorner), ispCurrent);
Vector3DUint8 v3dRegPos(uRegionX,uRegionY,uRegionZ);
if(g_bUseOpenGLVertexBufferObjects) if(g_bUseOpenGLVertexBufferObjects)
{ {
g_openGLSurfacePatches[uRegionX][uRegionY][uRegionZ] = BuildOpenGLSurfacePatch(*ispCurrent); //g_openGLSurfacePatches[uRegionX][uRegionY][uRegionZ] = BuildOpenGLSurfacePatch(*ispCurrent);
OpenGLSurfacePatch openGLSurfacePatch = BuildOpenGLSurfacePatch(*ispCurrent);
m_mapOpenGLSurfacePatches.insert(make_pair(v3dRegPos, openGLSurfacePatch));
} }
else else
{ {
g_indexedSurfacePatches[uRegionX][uRegionY][uRegionZ] = ispCurrent; //g_indexedSurfacePatches[uRegionX][uRegionY][uRegionZ] = ispCurrent;
//m_volIndexedSurfacePatches->setVoxelAt(uRegionX,uRegionY,uRegionZ,ispCurrent);
m_mapIndexedSurfacePatches.insert(make_pair(v3dRegPos, ispCurrent));
} }
//delete ispCurrent; //delete ispCurrent;
} }
@ -142,13 +149,14 @@ void OpenGLWidget::paintGL()
{ {
for(uint16 uRegionX = 0; uRegionX < g_uVolumeSideLengthInRegions; ++uRegionX) for(uint16 uRegionX = 0; uRegionX < g_uVolumeSideLengthInRegions; ++uRegionX)
{ {
Vector3DUint8 v3dRegPos(uRegionX,uRegionY,uRegionZ);
if(g_bUseOpenGLVertexBufferObjects) if(g_bUseOpenGLVertexBufferObjects)
{ {
renderRegionVertexBufferObject(g_openGLSurfacePatches[uRegionX][uRegionY][uRegionZ]); renderRegionVertexBufferObject(m_mapOpenGLSurfacePatches[v3dRegPos]);
} }
else else
{ {
IndexedSurfacePatch* ispCurrent = g_indexedSurfacePatches[uRegionX][uRegionY][uRegionZ]; IndexedSurfacePatch* ispCurrent = m_mapIndexedSurfacePatches[v3dRegPos];
renderRegionImmediateMode(*ispCurrent); renderRegionImmediateMode(*ispCurrent);
} }

View File

@ -28,6 +28,8 @@ class OpenGLWidget : public QGLWidget
public: public:
OpenGLWidget(QWidget *parent); OpenGLWidget(QWidget *parent);
void setVolume(PolyVox::Volume<PolyVox::uint8>* volData);
protected: protected:
void initializeGL(); void initializeGL();
void resizeGL(int w, int h); void resizeGL(int w, int h);
@ -38,11 +40,11 @@ class OpenGLWidget : public QGLWidget
bool g_bUseOpenGLVertexBufferObjects; bool g_bUseOpenGLVertexBufferObjects;
//Creates a volume 128x128x128 //Creates a volume 128x128x128
PolyVox::Volume<PolyVox::uint8>* g_volData; PolyVox::Volume<PolyVox::uint8>* m_volData;
//Rather than storing one big mesh, the volume is broken into regions and a mesh is stored for each region //Rather than storing one big mesh, the volume is broken into regions and a mesh is stored for each region
OpenGLSurfacePatch g_openGLSurfacePatches[g_uVolumeSideLengthInRegions][g_uVolumeSideLengthInRegions][g_uVolumeSideLengthInRegions]; std::map<PolyVox::Vector3DUint8, OpenGLSurfacePatch> m_mapOpenGLSurfacePatches;
PolyVox::IndexedSurfacePatch* g_indexedSurfacePatches[g_uVolumeSideLengthInRegions][g_uVolumeSideLengthInRegions][g_uVolumeSideLengthInRegions]; std::map<PolyVox::Vector3DUint8, PolyVox::IndexedSurfacePatch*> m_mapIndexedSurfacePatches;
}; };
#endif //__PolyVox_OpenGLWidget_H__ #endif //__PolyVox_OpenGLWidget_H__