0

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?

4

1 回答 1

2

VAO 引用缓冲区对象,因此如果您更改其内容或重新分配其存储空间,缓冲区对象的任何使用都会看到这一点。

但是,您不应该这样做。ARB上个月发布了一个扩展/核心功能,其主要目的是让这成为不可能。这不是扩展的唯一作用,但它基本上是使其余部分工作的原因。

这就是 ARB 和 IHV 对您重新分配缓冲区对象的存储的看法。所以不要这样做。如果您需要一个缓冲区来将数据流式传输到中,那就太好了。只需分配一个相当大的并流入其中。您可以使用glBufferData(..., NULL)使缓冲区无效(假设您无法将其映射为无效或使用glInvalidateBufferData)。但是当你这样做时,你永远不应该改变缓冲区的大小。

于 2013-08-06T21:44:21.700 回答