Question

I am trying to write functions that can draw generic shapes without textures. This includes a system for primitive polygon shapes, but as an example I will use show my rectangle function:

void Rectangle(float x1, float y1, float x2, float y2);

I am not sure how to best handle this given that all of my rendering uses VAOs. My current line of thought is to use one VAO with a single VBO attached to it and edit this VBO every time one of these functions is called. So for the rectangle example I will simply bind the buffer and call glBufferData passing in an array with the parameters for the points of the rectangle, then pass the vertex array onto the rest of my rendering system.

What I can't find information about is whether the VAO stores a reference to the buffer or makes an internal copy of the data based on the buffer and format. Is it ok to edit the buffer every time I am about to draw with it's VAO and if so do I have to call glVertexAttribPointer every time?

Was it helpful?

Solution

VAOs reference the buffer object, so if you change its contents or reallocate its storage, any uses of the buffer object will see this.

However, you should not do this. The ARB released an extension/core feature last month who's main purpose is making this impossible. That's not the only thing that extension does, but it basically is what makes the rest of it work.

That's how much the ARB and IHVs think about you reallocating the storage of buffer objects willy nilly. So don't do it. If you need a buffer to stream data into, that's great. Just allocate a reasonably large one and do streaming into that. You can use glBufferData(..., NULL) to invalidate the buffer (assuming that you can't map it for invalidation or use glInvalidateBufferData). But you should never be changing the buffer's size when you do this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top