Commit 1221b6c9 by Philipp Adolf

Move edge shader code into new function

parent badac240
...@@ -298,14 +298,31 @@ void Subdivision::runShader(Input input, Tables &tables) { ...@@ -298,14 +298,31 @@ void Subdivision::runShader(Input input, Tables &tables) {
f->glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); f->glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
runEdgeShader(tables.edge_indices.size() / 4, input.vb_handle, edge_indices_handle, output_handle);
// Map the output buffer so we can read the results
f->glBindBuffer(GL_SHADER_STORAGE_BUFFER, output_handle);
Vertex *ptr;
ptr = (Vertex *) f->glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_WRITE_ONLY);
for (int i = 0; i < tables.edge_indices.size() / 4; i++) {
qDebug() << ptr[i].pos;
}
f->glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
// Delete the buffers the free the resources
f->glDeleteBuffers(1, &edge_indices_handle);
f->glDeleteBuffers(1, &output_handle);
}
void Subdivision::runEdgeShader(GLuint size, GLuint vb_handle, GLuint edge_indices_handle, GLuint output_handle) {
edgeShader->bind(); edgeShader->bind();
f->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, input.vb_handle); f->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, vb_handle);
f->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, edge_indices_handle); f->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, edge_indices_handle);
f->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, output_handle); f->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, output_handle);
// Run the shader // Run the shader
f->glDispatchCompute(tables.edge_indices.size() / 4, 1, 1); f->glDispatchCompute(size, 1, 1);
// Wait for the shader to complete and the data to be written back to the global memory // Wait for the shader to complete and the data to be written back to the global memory
f->glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT); f->glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
...@@ -316,17 +333,4 @@ void Subdivision::runShader(Input input, Tables &tables) { ...@@ -316,17 +333,4 @@ void Subdivision::runShader(Input input, Tables &tables) {
f->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, 0); f->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, 0);
edgeShader->release(); edgeShader->release();
// Map the output buffer so we can read the results
f->glBindBuffer(GL_SHADER_STORAGE_BUFFER, output_handle);
Vertex *ptr;
ptr = (Vertex *) f->glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_WRITE_ONLY);
for (int i = 0; i < tables.edge_indices.size() / 4; i++) {
qDebug() << ptr[i].pos;
}
f->glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
// Delete the buffers the free the resources
f->glDeleteBuffers(1, &edge_indices_handle);
f->glDeleteBuffers(1, &output_handle);
} }
...@@ -36,6 +36,7 @@ private: ...@@ -36,6 +36,7 @@ private:
QOpenGLShaderProgram *initComputeShaderProgram(QString &source); QOpenGLShaderProgram *initComputeShaderProgram(QString &source);
Tables precomputeTables(Input input); Tables precomputeTables(Input input);
void runShader(Input input, Tables &tables); void runShader(Input input, Tables &tables);
void runEdgeShader(GLuint size, GLuint vb_handle, GLuint edge_indices_handle, GLuint output_handle);
}; };
#endif #endif
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