2

In my base program (C++/OpenGL 4.5) I have copied the content of the Vertex Buffer to an Shader Storage Buffer (SSBO):

float* buffer = (float*) glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, ssbo[2]);

glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(GLfloat)*size,buffer, GL_DYNAMIC_DRAW);

glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, 0);
glUnmapBuffer(GL_ARRAY_BUFFER);

In the Vertex Shader this data is bound to an array:

#version 430
#extension GL_ARB_shader_storage_buffer_object : require

layout(shared, binding = 3) buffer storage
{
    float array[];
}

But when I'm trying to overwrite an array entry in the main function like this:

array[index_in_bounds] = 4.2;

nothing happens.

What am I doing wrong? Can I change the buffer from within the Vertex Shader? Is this only possible in a Geometry Shader? Do I have to do this with Transform Feedback (that I have never used before)?

edit: I'm mapping the buffers for test purposes in my main program, just to see if the data changes:

float* buffer = (float*) glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY);
float* ssbo = (float*) glMapNamedBuffer(3, GL_READ_ONLY);

for(int i = 0; i < SIZE_OF_BUFFERS; i++)
    printf("% 5f | % 5f\n", ssbo[i], buffer[i]);

glUnmapNamedBuffer(3);
glUnmapBuffer(GL_ARRAY_BUFFER);
3
  • Define "nothing happens." Show the code where you detect whether something has or has not happened. Commented Aug 31, 2016 at 14:43
  • It's obvious as I'm using the array for transformations. I've added my debug output code. Commented Aug 31, 2016 at 14:54
  • Please post an minimal reproducible example. Commented Aug 31, 2016 at 15:04

1 Answer 1

3

Okay, I have found the problem using the red book. I have not bound the buffer correctly and binding the buffer base has to happen after buffering the data:

float* buffer = (float*) glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, &ssbo); // bind buffer

// switched these two:
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(GLfloat)*size,buffer, GL_DYNAMIC_DRAW);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, &ssbo);

glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); // unbind buffer
glUnmapBuffer(GL_ARRAY_BUFFER);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.