Hello Everyone,
I want to process a vertex buffer for now I just want to keep it simple so I am just adding .20 to the y value of each vertex. That way I could see the mesh move up. But I ran into a little issue. It seems that the array containing the vertexes isn't aligned properly. Instead of all vertexes moving on the y axis the some seems to move on the x axis, some on the y axis and some on the z axis. I am confused about this.
My vertexes are just basic points with floating point x,y,z components.
Buffer initiation code:
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, vertexCount * 3 * sizeof(float), vertexData, GL_STATIC_DRAW);
Render code:
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glVertexAttribPointer(vertexAttributeLocation, 3, GL_FLOAT, GL_FALSE, 0, (GLubyte*)NULL);
glEnableVertexAttribArray(vertexAttributeLocation);
glDrawArrays(GL_TRIANGLES, 0, vertexCount);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glDisableVertexAttribArray(vertexAttributeLocation);
Compute shader invocation:
glUseProgram(compute_shader_program);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, vbo);
glDispatchCompute(vertexCount, 1, 1);
Compute shader:
#version 430 compatibility
#extension GL_ARB_compute_shader : enable
#extension GL_ARB_shader_storage_buffer_object : enable
layout( std140, binding=3 ) buffer Vertexes {
vec3 Positions[ ];
};
layout( local_size_x = 1, local_size_y = 1, local_size_z = 1 ) in;
void main() {
uint globalId = gl_GlobalInvocationID.x;
vec3 p = Positions[ globalId ];
p.y += 0.20;
Positions[ globalId ] = p;
}
Greetz Jaap