Commit 1c7fdb0d by Philipp Adolf

Add offset into output buffer for edge shader

parent ffaac38b
...@@ -334,14 +334,15 @@ void Subdivision::runShader(Input input, Tables &tables) { ...@@ -334,14 +334,15 @@ 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); int edgeOffset = input.vertex_buffer.size();
runEdgeShader(tables.edge_indices.size() / 4, input.vb_handle, edge_indices_handle, output_handle, edgeOffset);
// Map the output buffer so we can read the results // Map the output buffer so we can read the results
f->glBindBuffer(GL_SHADER_STORAGE_BUFFER, output_handle); f->glBindBuffer(GL_SHADER_STORAGE_BUFFER, output_handle);
Vertex *ptr; Vertex *ptr;
ptr = (Vertex *) f->glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_WRITE_ONLY); ptr = (Vertex *) f->glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_WRITE_ONLY);
for (int i = 0; i < tables.edge_indices.size() / 4; i++) { for (int i = 0; i < tables.edge_indices.size() / 4; i++) {
qDebug() << ptr[i].pos; qDebug() << ptr[edgeOffset + i].pos;
} }
f->glUnmapBuffer(GL_SHADER_STORAGE_BUFFER); f->glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
...@@ -350,12 +351,12 @@ void Subdivision::runShader(Input input, Tables &tables) { ...@@ -350,12 +351,12 @@ void Subdivision::runShader(Input input, Tables &tables) {
f->glDeleteBuffers(1, &output_handle); f->glDeleteBuffers(1, &output_handle);
} }
void Subdivision::runEdgeShader(GLuint size, GLuint vb_handle, GLuint edge_indices_handle, GLuint output_handle) { void Subdivision::runEdgeShader(GLuint size, GLuint vb_handle, GLuint edge_indices_handle, GLuint output_handle, GLuint offset) {
edgeShader->bind(); edgeShader->bind();
f->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, 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->glBindBufferRange(GL_SHADER_STORAGE_BUFFER, 2, output_handle, offset * sizeof(Vertex), size * sizeof(Vertex));
// Run the shader // Run the shader
f->glDispatchCompute(size, 1, 1); f->glDispatchCompute(size, 1, 1);
......
...@@ -38,7 +38,7 @@ private: ...@@ -38,7 +38,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); void runEdgeShader(GLuint size, GLuint vb_handle, GLuint edge_indices_handle, GLuint output_handle, GLuint offset);
}; };
#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