Commit 2aaf8beb by Philipp Adolf

Load compute shader

parent 4eaf0e47
...@@ -107,6 +107,7 @@ void MainWidget::initializeGL(){ ...@@ -107,6 +107,7 @@ void MainWidget::initializeGL(){
// Shader // Shader
subdevisionShader = initShaderProgram(); subdevisionShader = initShaderProgram();
subdivision->init();
//loadNewMesh( "../Models/demon_head.3ds"); //loadNewMesh( "../Models/demon_head.3ds");
loadNewMesh( "../Models/box.obj"); loadNewMesh( "../Models/box.obj");
} }
......
...@@ -5,5 +5,6 @@ ...@@ -5,5 +5,6 @@
<file>subdivide.tcs</file> <file>subdivide.tcs</file>
<file>subdivide.tes</file> <file>subdivide.tes</file>
<file>subdivide.vert</file> <file>subdivide.vert</file>
<file>subdivision.compute</file>
</qresource> </qresource>
</RCC> </RCC>
#version 430
layout (local_size_x = 1) in;
void main() {
}
...@@ -7,6 +7,34 @@ Subdivision::Subdivision(QOpenGLFunctions_4_3_Core *f) ...@@ -7,6 +7,34 @@ Subdivision::Subdivision(QOpenGLFunctions_4_3_Core *f)
Subdivision::~Subdivision() Subdivision::~Subdivision()
{ {
delete shader;
}
void Subdivision::init() {
shader = initComputeShaderProgram();
}
QOpenGLShaderProgram *Subdivision::initComputeShaderProgram(){
QString source = QLatin1String(":/subdivision.compute");
qDebug()<<"Compiling compute shader ...";
QOpenGLShader *computeShader = new QOpenGLShader(QOpenGLShader::Compute);
if(!computeShader->compileSourceFile(source)){
qCritical()<<"Compute Shader"<<source<<"failed"<<computeShader->log();
exit(5);
}
qDebug()<<"Adding compute shader ...";
QOpenGLShaderProgram *shader = new QOpenGLShaderProgram();
shader->addShader(computeShader);
qDebug()<<"Linking compute shader ...";
if(!shader->link()){
qCritical()<<"Linking compute shader failed:"<<shader->log();
exit(5);
}
qDebug()<<"Linking compute shader done";
return shader;
} }
Mesh *Subdivision::subdivide(Mesh *mesh) { Mesh *Subdivision::subdivide(Mesh *mesh) {
......
...@@ -12,11 +12,14 @@ public: ...@@ -12,11 +12,14 @@ public:
Subdivision(QOpenGLFunctions_4_3_Core *f); Subdivision(QOpenGLFunctions_4_3_Core *f);
~Subdivision(); ~Subdivision();
void init();
Mesh *subdivide(Mesh *mesh); Mesh *subdivide(Mesh *mesh);
private: private:
QOpenGLFunctions_4_3_Core *f; QOpenGLFunctions_4_3_Core *f;
QOpenGLShaderProgram *shader;
QOpenGLShaderProgram *initComputeShaderProgram();
void precomputeTables(Mesh *mesh); void precomputeTables(Mesh *mesh);
void runShader(Mesh *mesh); void runShader(Mesh *mesh);
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment