Commit 84b5aebf by Philipp Adolf

Return result from runShader

parent af72c003
...@@ -56,7 +56,8 @@ Mesh *Subdivision::subdivide(Mesh *mesh) { ...@@ -56,7 +56,8 @@ Mesh *Subdivision::subdivide(Mesh *mesh) {
input.index_buffer = current_mesh->getIndexBuffer(); input.index_buffer = current_mesh->getIndexBuffer();
Tables tables = precomputeTables(input); Tables tables = precomputeTables(input);
runShader(input, tables); Result result = runShader(input, tables);
return NULL; return NULL;
} }
...@@ -317,9 +318,11 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) { ...@@ -317,9 +318,11 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
return tables; return tables;
} }
void Subdivision::runShader(Input input, Tables &tables) { Subdivision::Result Subdivision::runShader(Input input, Tables &tables) {
qDebug()<<"Running compute shader"; qDebug()<<"Running compute shader";
Result result;
// Create an input buffer for the vertex indices // Create an input buffer for the vertex indices
GLuint vertex_indices_handle; GLuint vertex_indices_handle;
f->glGenBuffers(1, &vertex_indices_handle); f->glGenBuffers(1, &vertex_indices_handle);
...@@ -343,6 +346,7 @@ void Subdivision::runShader(Input input, Tables &tables) { ...@@ -343,6 +346,7 @@ void Subdivision::runShader(Input input, Tables &tables) {
f->glGenBuffers(1, &output_handle); f->glGenBuffers(1, &output_handle);
f->glBindBuffer(GL_SHADER_STORAGE_BUFFER, output_handle); f->glBindBuffer(GL_SHADER_STORAGE_BUFFER, output_handle);
f->glBufferData(GL_SHADER_STORAGE_BUFFER, (input.vertex_buffer.size() + tables.edge_indices.size() / 4) * sizeof(Vertex), NULL, GL_DYNAMIC_DRAW); f->glBufferData(GL_SHADER_STORAGE_BUFFER, (input.vertex_buffer.size() + tables.edge_indices.size() / 4) * sizeof(Vertex), NULL, GL_DYNAMIC_DRAW);
result.vb_handle = output_handle;
f->glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); f->glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
...@@ -357,10 +361,12 @@ void Subdivision::runShader(Input input, Tables &tables) { ...@@ -357,10 +361,12 @@ void Subdivision::runShader(Input input, Tables &tables) {
qDebug() << "New vertices:"; qDebug() << "New vertices:";
for (int i = 0; i < input.vertex_buffer.size(); i++) { for (int i = 0; i < input.vertex_buffer.size(); i++) {
qDebug() << ptr[i].pos; qDebug() << ptr[i].pos;
result.vertex_buffer.push_back(ptr[i]);
} }
qDebug() << "New edge points:"; qDebug() << "New edge points:";
for (int i = 0; i < tables.edge_indices.size() / 4; i++) { for (int i = 0; i < tables.edge_indices.size() / 4; i++) {
qDebug() << ptr[edgeOffset + i].pos; qDebug() << ptr[edgeOffset + i].pos;
result.vertex_buffer.push_back(ptr[edgeOffset + i]);
} }
f->glUnmapBuffer(GL_SHADER_STORAGE_BUFFER); f->glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
...@@ -368,7 +374,8 @@ void Subdivision::runShader(Input input, Tables &tables) { ...@@ -368,7 +374,8 @@ void Subdivision::runShader(Input input, Tables &tables) {
f->glDeleteBuffers(1, &vertex_indices_handle); f->glDeleteBuffers(1, &vertex_indices_handle);
f->glDeleteBuffers(1, &vertex_offsets_handle); f->glDeleteBuffers(1, &vertex_offsets_handle);
f->glDeleteBuffers(1, &edge_indices_handle); f->glDeleteBuffers(1, &edge_indices_handle);
f->glDeleteBuffers(1, &output_handle);
return result;
} }
void Subdivision::runVertexShader(GLuint size, GLuint vb_handle, GLuint vertex_indices_handle, GLuint vertex_offsets_handle, GLuint output_handle) { void Subdivision::runVertexShader(GLuint size, GLuint vb_handle, GLuint vertex_indices_handle, GLuint vertex_offsets_handle, GLuint output_handle) {
......
...@@ -31,13 +31,19 @@ private: ...@@ -31,13 +31,19 @@ private:
QVector<GLuint> index_buffer; QVector<GLuint> index_buffer;
}; };
struct Result
{
GLuint vb_handle;
QVector<Vertex> vertex_buffer;
};
QOpenGLFunctions_4_3_Core *f; QOpenGLFunctions_4_3_Core *f;
QOpenGLShaderProgram *edgeShader; QOpenGLShaderProgram *edgeShader;
QOpenGLShaderProgram *vertexShader; QOpenGLShaderProgram *vertexShader;
QOpenGLShaderProgram *initComputeShaderProgram(QString &source); QOpenGLShaderProgram *initComputeShaderProgram(QString &source);
Tables precomputeTables(Input input); Tables precomputeTables(Input input);
void runShader(Input input, Tables &tables); Result runShader(Input input, Tables &tables);
void runVertexShader(GLuint size, GLuint vb_handle, GLuint vertex_indices_handle, GLuint vertex_offsets_handle, GLuint output_handle); void runVertexShader(GLuint size, GLuint vb_handle, GLuint vertex_indices_handle, GLuint vertex_offsets_handle, GLuint output_handle);
void runEdgeShader(GLuint size, GLuint vb_handle, GLuint edge_indices_handle, GLuint output_handle, GLuint offset); void runEdgeShader(GLuint size, GLuint vb_handle, GLuint edge_indices_handle, GLuint output_handle, GLuint offset);
}; };
......
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