Started refactoring examples and got DecodeOnGPUExample working.
This commit is contained in:
parent
92daf9a0c0
commit
3f849e19a4
@ -67,7 +67,7 @@ IF(ENABLE_EXAMPLES AND Qt5OpenGL_FOUND)
|
|||||||
ADD_SUBDIRECTORY(examples/Paging)
|
ADD_SUBDIRECTORY(examples/Paging)
|
||||||
ADD_SUBDIRECTORY(examples/OpenGL)
|
ADD_SUBDIRECTORY(examples/OpenGL)
|
||||||
ADD_SUBDIRECTORY(examples/SmoothLOD)
|
ADD_SUBDIRECTORY(examples/SmoothLOD)
|
||||||
#ADD_SUBDIRECTORY(examples/DecodeOnGPU)
|
ADD_SUBDIRECTORY(examples/DecodeOnGPU)
|
||||||
ADD_SUBDIRECTORY(examples/Python)
|
ADD_SUBDIRECTORY(examples/Python)
|
||||||
SET(BUILD_EXAMPLES ON)
|
SET(BUILD_EXAMPLES ON)
|
||||||
ELSE()
|
ELSE()
|
||||||
|
@ -66,13 +66,18 @@ void createSphereInVolume(PagedVolume<uint8_t>& volData, float fRadius)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
class BasicExample : public OpenGLWidget
|
||||||
{
|
{
|
||||||
//Create and show the Qt OpenGL window
|
public:
|
||||||
QApplication app(argc, argv);
|
BasicExample(QWidget *parent)
|
||||||
OpenGLWidget openGLWidget(0);
|
:OpenGLWidget(parent)
|
||||||
openGLWidget.show();
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void initialize() override
|
||||||
|
{
|
||||||
//Create an empty volume and then place a sphere in it
|
//Create an empty volume and then place a sphere in it
|
||||||
PagedVolume<uint8_t> volData(PolyVox::Region(Vector3DInt32(0, 0, 0), Vector3DInt32(63, 63, 63)));
|
PagedVolume<uint8_t> volData(PolyVox::Region(Vector3DInt32(0, 0, 0), Vector3DInt32(63, 63, 63)));
|
||||||
createSphereInVolume(volData, 30);
|
createSphereInVolume(volData, 30);
|
||||||
@ -86,9 +91,18 @@ int main(int argc, char *argv[])
|
|||||||
auto decodedMesh = decodeMesh(mesh);
|
auto decodedMesh = decodeMesh(mesh);
|
||||||
|
|
||||||
//Pass the surface to the OpenGL window
|
//Pass the surface to the OpenGL window
|
||||||
openGLWidget.addMesh(decodedMesh);
|
addMesh(decodedMesh);
|
||||||
//openGLWidget.addMesh(mesh2);
|
//openGLWidget.addMesh(mesh2);
|
||||||
openGLWidget.setViewableRegion(volData.getEnclosingRegion());
|
setViewableRegion(volData.getEnclosingRegion());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
//Create and show the Qt OpenGL window
|
||||||
|
QApplication app(argc, argv);
|
||||||
|
BasicExample openGLWidget(0);
|
||||||
|
openGLWidget.show();
|
||||||
|
|
||||||
//Run the message pump.
|
//Run the message pump.
|
||||||
return app.exec();
|
return app.exec();
|
||||||
|
@ -66,6 +66,54 @@ void createSphereInVolume(PagedVolume<uint8_t>& volData, float fRadius)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class DecodeOnGPUExample : public OpenGLWidget
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DecodeOnGPUExample(QWidget *parent)
|
||||||
|
:OpenGLWidget(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void initialize() override
|
||||||
|
{
|
||||||
|
QSharedPointer<QGLShaderProgram> shader(new QGLShaderProgram);
|
||||||
|
|
||||||
|
if (!shader->addShaderFromSourceFile(QGLShader::Vertex, ":/decode.vert"))
|
||||||
|
{
|
||||||
|
std::cerr << shader->log().toStdString() << std::endl;
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!shader->addShaderFromSourceFile(QGLShader::Fragment, ":/decode.frag"))
|
||||||
|
{
|
||||||
|
std::cerr << shader->log().toStdString() << std::endl;
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
setShader(shader);
|
||||||
|
|
||||||
|
//Create an empty volume and then place a sphere in it
|
||||||
|
PagedVolume<uint8_t> volData(PolyVox::Region(Vector3DInt32(0, 0, 0), Vector3DInt32(63, 63, 63)));
|
||||||
|
createSphereInVolume(volData, 30);
|
||||||
|
|
||||||
|
// Extract the surface for the specified region of the volume. Uncomment the line for the kind of surface extraction you want to see.
|
||||||
|
//auto mesh = extractCubicMesh(&volData, volData.getEnclosingRegion());
|
||||||
|
auto mesh = extractMarchingCubesMesh(&volData, volData.getEnclosingRegion());
|
||||||
|
|
||||||
|
// The surface extractor outputs the mesh in an efficient compressed format which is not directly suitable for rendering. The easiest approach is to
|
||||||
|
// decode this on the CPU as shown below, though more advanced applications can upload the compressed mesh to the GPU and decompress in shader code.
|
||||||
|
//auto decodedMesh = decodeMesh(mesh);
|
||||||
|
|
||||||
|
//Pass the surface to the OpenGL window
|
||||||
|
OpenGLMeshData meshData = buildOpenGLMeshData(mesh);
|
||||||
|
addMeshData(meshData);
|
||||||
|
|
||||||
|
setViewableRegion(volData.getEnclosingRegion());
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
OpenGLMeshData buildOpenGLMeshData(const PolyVox::Mesh< PolyVox::MarchingCubesVertex< uint8_t > >& surfaceMesh, const PolyVox::Vector3DInt32& translation = PolyVox::Vector3DInt32(0, 0, 0), float scale = 1.0f)
|
OpenGLMeshData buildOpenGLMeshData(const PolyVox::Mesh< PolyVox::MarchingCubesVertex< uint8_t > >& surfaceMesh, const PolyVox::Vector3DInt32& translation = PolyVox::Vector3DInt32(0, 0, 0), float scale = 1.0f)
|
||||||
{
|
{
|
||||||
// Convienient access to the vertices and indices
|
// Convienient access to the vertices and indices
|
||||||
@ -120,48 +168,15 @@ OpenGLMeshData buildOpenGLMeshData(const PolyVox::Mesh< PolyVox::MarchingCubesVe
|
|||||||
|
|
||||||
return meshData;
|
return meshData;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
//Create and show the Qt OpenGL window
|
//Create and show the Qt OpenGL window
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
OpenGLWidget openGLWidget(0);
|
DecodeOnGPUExample openGLWidget(0);
|
||||||
openGLWidget.show();
|
openGLWidget.show();
|
||||||
|
|
||||||
QSharedPointer<QGLShaderProgram> shader(new QGLShaderProgram);
|
|
||||||
|
|
||||||
if (!shader->addShaderFromSourceFile(QGLShader::Vertex, ":/decode.vert"))
|
|
||||||
{
|
|
||||||
std::cerr << shader->log().toStdString() << std::endl;
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!shader->addShaderFromSourceFile(QGLShader::Fragment, ":/decode.frag"))
|
|
||||||
{
|
|
||||||
std::cerr << shader->log().toStdString() << std::endl;
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
openGLWidget.setShader(shader);
|
|
||||||
|
|
||||||
//Create an empty volume and then place a sphere in it
|
|
||||||
PagedVolume<uint8_t> volData(PolyVox::Region(Vector3DInt32(0, 0, 0), Vector3DInt32(63, 63, 63)));
|
|
||||||
createSphereInVolume(volData, 30);
|
|
||||||
|
|
||||||
// Extract the surface for the specified region of the volume. Uncomment the line for the kind of surface extraction you want to see.
|
|
||||||
//auto mesh = extractCubicMesh(&volData, volData.getEnclosingRegion());
|
|
||||||
auto mesh = extractMarchingCubesMesh(&volData, volData.getEnclosingRegion());
|
|
||||||
|
|
||||||
// The surface extractor outputs the mesh in an efficient compressed format which is not directly suitable for rendering. The easiest approach is to
|
|
||||||
// decode this on the CPU as shown below, though more advanced applications can upload the compressed mesh to the GPU and decompress in shader code.
|
|
||||||
//auto decodedMesh = decodeMesh(mesh);
|
|
||||||
|
|
||||||
//Pass the surface to the OpenGL window
|
|
||||||
OpenGLMeshData meshData = buildOpenGLMeshData(mesh);
|
|
||||||
openGLWidget.addMeshData(meshData);
|
|
||||||
|
|
||||||
openGLWidget.setViewableRegion(volData.getEnclosingRegion());
|
|
||||||
|
|
||||||
//Run the message pump.
|
//Run the message pump.
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
@ -121,6 +121,8 @@ void OpenGLWidget::initializeGL()
|
|||||||
|
|
||||||
// Initial setup of camera.
|
// Initial setup of camera.
|
||||||
setupWorldToCameraMatrix();
|
setupWorldToCameraMatrix();
|
||||||
|
|
||||||
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGLWidget::resizeGL(int w, int h)
|
void OpenGLWidget::resizeGL(int w, int h)
|
||||||
|
@ -136,6 +136,10 @@ protected:
|
|||||||
void resizeGL(int w, int h);
|
void resizeGL(int w, int h);
|
||||||
void paintGL();
|
void paintGL();
|
||||||
|
|
||||||
|
virtual void initialize()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void setupWorldToCameraMatrix();
|
void setupWorldToCameraMatrix();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user