I have some SSBO to be accessed in the shader. Lets say its something like
layout(std430, binding = 2) readonly buffer MyBuffer
{
int myData[];
};
When is the appropriate time to call glBindBufferBase?
Right now I do something like
glBindBuffer(GL_SHADER_STORAGE_BUFFER, name)
glBufferData(...)
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, name)
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0)
I do not know if this sets some global state whereby index 2 is set for every single shader I bind and unbind.
Can you tell me if there's any flaws with this idea:
Create, Bind SSBO, upload data, unbind for the SSBO
Bind shader
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, name)
Draw arrays
Unbind shader
Is this the expected way to use it? I only bind the SSBO once, upload, and then I never bind it again. This seems to work but I have no idea if it "just works" because my GPU tries to be smart for me, or if I'm violating the spec (which I went through but couldn't find the answer to this question). I've been burned before where I do something that will work on my GPU and then fail on another one, and that makes me hesitant of what I'm doing.
Ideally I'd like to make a single function call to swap in my SSBO into some binding, and then draw. I'm unsure if I can do this before binding the shader, or if the shader has to be bound. If there's a better way to do this, please advise.
In short, the end goal is the minimal way to get some SSBO bound on some index after it is ready to be used from uploading data.