switch GL_DYNAMIC_DRAW to GL_STATIC_DRAW at runtime?

I created a buffer using:


can I switch the ‘usage’ of this buffer to GL_STATIC_DRAW at runtime?
If yes, how?

You cannot change the usage hint of a buffer object. That being said, since these are just hints the implementations tend to ignore them and instead look at how your code actually uses the buffer object to determine which memory pool to place the buffer in.
In contrast the flags passed to glBufferStorage are not just hints, they are promises that certain operations (e.g. reads/writes) will not occur on the buffer object.
At least on Nvidia drivers on a debug context with GL_DEBUG_OUTPUT enabled the implementation tells you where it allocates a buffer object or when it decides to migrate one between memory pools.

Thank you for your helpful reply.

My application shows the OpenGL debug output, which is:

message: Buffer detailed info: Buffer object 511 (bound to GL_TEXTURE_BUFFER, usage hint is GL_DYNAMIC_DRAW) has been mapped WRITE_ONLY in SYSTEM HEAP memory (fast).
type: OTHER
id: 131185

I was given the information that GL_DYNAMIC_DRAW would slow down accessing the buffer, as it uses the SYSTEM HEAP.
Is SYSTEM HEAP slow? What’s SYSTEM HEAP at all, is it in the normal RAM, or is it in the video card’s VRAM?

Is there a way to speed up the buffer access in this case? The buffer is written to some few times and mostly read.

In the following I am assuming that by “mostly read” what you really mean is that the buffer is mostly used for drawing; i.e it’s the GPU that’s reading the buffer, not your own program code. If it is the latter (i.e your own program is doing the reading) then there is no fast case and your best approach is to duplicate the data in system memory via a malloc call.

I would create the buffer with GL_STATIC_DRAW.

Best case: the driver honours the hint, you get the buffer created in memory that’s fast for drawing from, and the occcasional write doesn’t trip up the driver’s heuristics by causing it to relocate the buffer to slower memory.

Worst case: the buffer relocates to slower memory and you’re no worse off than you currently are.

I’ll try out GL_STATIC_DRAW… thank you both for your help!