Hello
I need a help.
I try to copy data from one buffer to another buffer in compute shader and then bind it to GL_ARRAY_BUFFER for render.
Simple example with two triangles works and example with many points not.
Compute shader code:
#version 430
layout (local_size_x = 1) in;
layout (std430, binding = 1) buffer InBuf
{
vec3 input[];
};
layout (std430, binding = 2) buffer OutBuf
{
vec3 output[];
};
void main()
{
uint pos = gl_GlobalInvocationID.x;
output[pos] = input[pos];
}
Application code:
glGenBuffers(1, &depthPixelBuf);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, inputBuf);
glBufferData(GL_SHADER_STORAGE_BUFFER, bufferSize, points.data(), GL_STATIC_COPY);
glGenBuffers(1, &depthPointBuf);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, outputBuf);
glBufferData(GL_SHADER_STORAGE_BUFFER, bufferSize, NULL, GL_DYNAMIC_DRAW);
glUseProgram(computeProgram);
glDispatchCompute(points.size(), 1, 1);
glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
glUseProgram(program);
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, outputBuf);
glVertexAttribPointer(vertexAttribute, 3, GL_FLOAT, GL_FALSE, 0, 0);
glDrawArrays(GL_POINTS, 0, points.size());
This example works with about 50000 points from camera. If I do like this:
glBindBuffer(GL_ARRAY_BUFFER, inputBuf);
rendering is OK. So I don’t understand what a problem.