OpenGL顶点数组/缓冲区对象 [英] OpenGL Vertex Array/Buffer Objects
问题描述
问题1
在某个VAO下创建的顶点缓冲对象是否会被删除?
Do vertex buffer objects created under a certain VAO deleted once that VAO is deleted?
一个例子:
glGenBuffers(1, &bufferObject);
glGenVertexArrays(1, &VAO);
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, bufferObject);
glBufferData(GL_ARRAY_BUFFER, sizeof(someVertices), someVertices,
GL_STATIC_DRAW);
glEnableVertexAttribArray(positionAttrib);
glVertexAttribPointer(positionAttrib, 3, GL_FLOAT, GL_FALSE, 0, NULL);
稍后调用glDeleteVertexArrays(1, &VAO);
时,bufferObject
也将被删除吗?
When later calling glDeleteVertexArrays(1, &VAO);
, will bufferObject
be deleted as well?
我问的原因是,我在网络上看到了一些没有删除这些缓冲区对象的示例.
The reason I'm asking is that I saw a few examples over the web that didn't delete those buffer objects.
问题2
我可以为缓冲区对象分配的最大内存量是多少?当然,它必须依赖于系统,但是我似乎找不到对此的估计.当视频RAM不够大时会发生什么?我怎么知道?
What is the maximum amount of memory that I can allocate for buffer objects? It must be system dependent of course, but I can't seem find an estimation for it. What happens when video RAM isn't big enough? How would I know?
推荐答案
答案1
这取决于.如果您以前调用过glDeleteBuffers
,则在删除VAO时将其删除.如果没有,它不会. VAO拥有对VBO的引用,调用glGenBuffers
后,您的应用程序也是如此.删除VBO之前,必须先释放两个引用.
It depends. If you called glDeleteBuffers
before, it will be deleted when you delete the VAO. If not, it won't. The VAO holds a reference to the VBO, and so does your application after calling glGenBuffers
. Both references need to be released before the VBO is deleted.
答案2
(afaik)无法查询您可以分配的最大金额.但是,根据参考文档,glBufferData
将发出GL_OUT_OF_MEMORY
如果不能分配缓冲区.
There's (afaik) no way to query the maximum amount you can allocate. However, according to the reference documentation, glBufferData
will emit GL_OUT_OF_MEMORY
if a buffer can not be allocated.
这篇关于OpenGL顶点数组/缓冲区对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!