Commit 817044b4 by Philipp Adolf

Implement edge vertex computation

parent 44d0a2d5
......@@ -17,9 +17,12 @@ layout(std430, binding=1) readonly buffer EdgeIndices {
};
layout(std430, binding=2) writeonly buffer Output {
float data[];
Vertex edges[];
};
void main(){
data[gl_GlobalInvocationID.x] = vertices[gl_GlobalInvocationID.x].pos.x;
edges[gl_GlobalInvocationID.x].norm = vec3(0.0, 0.0, 0.0);
edges[gl_GlobalInvocationID.x].uv = vec2(0.0, 0.0);
edges[gl_GlobalInvocationID.x].pos = 3.0/8.0 * (vertices[indices[gl_GlobalInvocationID.x][0]].pos + vertices[indices[gl_GlobalInvocationID.x][1]].pos) + 1.0/8.0 * (vertices[indices[gl_GlobalInvocationID.x][2]].pos + vertices[indices[gl_GlobalInvocationID.y][3]].pos);
}
......@@ -303,10 +303,10 @@ void Subdivision::runShader(Mesh *mesh, QVector<QVector<unsigned int> > &edgeInd
GLuint bufferID;
f->glGenBuffers(1, &bufferID);
f->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, bufferID);
f->glBufferData(GL_SHADER_STORAGE_BUFFER, vb.size() * sizeof(GLfloat), NULL, GL_DYNAMIC_DRAW);
f->glBufferData(GL_SHADER_STORAGE_BUFFER, edgeIndices.size() * sizeof(Vertex), NULL, GL_DYNAMIC_DRAW);
// Run the shader
f->glDispatchCompute(vb.size(), 1, 1);
f->glDispatchCompute(edgeIndices.size(), 1, 1);
// Wait for the shader to complete and the data to be written back to the global memory
f->glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
......@@ -318,10 +318,10 @@ void Subdivision::runShader(Mesh *mesh, QVector<QVector<unsigned int> > &edgeInd
// Map the output buffer so we can read the results
f->glBindBuffer(GL_SHADER_STORAGE_BUFFER, bufferID);
GLfloat *ptr;
ptr = (GLfloat *) f->glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_WRITE_ONLY);
for (int i = 0; i < vb.size(); i++) {
qDebug() << ptr[i] << vb[i].pos.x();
Vertex *ptr;
ptr = (Vertex *) f->glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_WRITE_ONLY);
for (int i = 0; i < edgeIndices.size(); i++) {
qDebug() << ptr[i].pos;
}
f->glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
......
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