Commit 84b5aebf by Philipp Adolf

Return result from runShader

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