0
votes

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?

1
Iirc, the reference says that a VAO stores the VBOs' ids bound to it, but nothing should prevent you to bind a VBO to several VAO for instance. The point of using VAOs is to avoid all the boiler plate code needed normally to setup the bindings for a given rendering pipeline.didierc
there you go.didierc
By "reference", I meant the opengl specs.didierc

1 Answers

2
votes

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.