Can one bind the same buffer object to different targets at differnt times?
So for example, let’s say I create a buffer
glBufferData(GL_ARRAY_BUFFER, 2048, data, GL_DYNAMIC_COPY); //data is my data array
Let’s say I use this to do certain things.
Now I want to use the same buffer as a GL_SHADER_STORAGE_BUFFER, can I simply go ahead and use the sae buffer without having to recreate another buffer?
For some reason, I had stumbled on this question earlier, but I cannot remember what I had learned from it.
Yes, you can do this.
However, buffer objects have their origins in the GL_ARB_vertex_buffer_object extension, and that notes:
Note that it is expected that implementations may have different memory type requirements for efficient storage of indices and vertices. For example, some systems may prefer indices in AGP memory and vertices in video memory, or vice versa; or, on systems where DMA of index data is not supported, index data must be stored in (cacheable) system memory for acceptable performance. As a result, applications are strongly urged to put their models’ vertex and index data in separate buffers, to assist drivers in choosing the most efficient locations.
I’m not sure how much of this is relevant to more modern hardware, but if so, it can be expected to be generalized to any buffer object type. So the standard advice is that GL may make assumptions about how (and where) best to store the buffer based on the binding-point used when it’s first bound, but that these assumptions may not yield the best performance for other binding-points. On the other hand if it saves you a memory copy then that may not be such a big deal, so I’d encourage you to experiment with both approaches (never forgetting that what runs good on Vendor A may run poor on Vendor B, or vice-versa).
The only real difference I know about is the buffer location. Meaning Vram or System Memory. (In case of APUs there is only System memory)
Modern drivers most likely also ignore your usage hint (GL_DYNAMIC_COPY) and decide on your usage patterns where to move/leave the buffer later on.