I’m currently using an SSBO to send matrix information to the GPU in order to use in the Vertex and Fragment shader to appy on the instaces being rendered by glDrawElementsInstanced.
My question is, what is the best way to reupdate the SSBO buffer size correctly?
I don’t think the question is detailed enough, so I’ll explain the scenario:
I have a central SSBO object which is used to render all sets of instanced of the application, and each time the buffer data is passsed on the SSBO, I check if the size is the same, if not, I reupdate the size and send the buffer, and so on, every glBufferData call I make. Let me add the scheme here:
Setup:
ssbo = glGenBuffers();
size = 20;
glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo);
glBufferData(GL_SHADER_STORAGE_BUFFER, size, GL_STREAM_DRAW);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, ssbo);
RenderFrame:
- Clear FBO
-
glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo); if(bufferSize > size) { this.size = bufferSize; glBufferData(GL_SHADER_STORAGE_BUFFER, size, GL_STREAM_DRAW); } glBufferSubData(GL_SHADER_STORAGE_BUFFER, 0, buffer); glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
-
glDrawElementsInstanced(GL_TRIANGLES, indicesCount, GL_UNSIGNED_INT, 0, count);
- Repeat
My concern is, am I doing it right by calling glBufferData(GL_SHADER_STORAGE_BUFFER, size, GL_STREAM_DRAW);
to update the buffer size?
And am I using the GL_STREAM_DRAW correctly or should it be GL_STATIC_DRAW?
I’ve read about it and tried to search regarding this matter, but I still get some confusion on what to use and why.
This is just for the sake of controlling each instance transformation (Pos, Dir, Scale, etc…)
Note: this code works fairly well on machines with good hardware cards, but has weird results on low-end ones