OpenGL 顶点数组/缓冲对象 [英] OpenGL Vertex Array/Buffer Objects

查看:33
本文介绍了OpenGL 顶点数组/缓冲对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题 1

在某个 VAO 下创建的顶点缓冲对象会在该 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<如果无法分配缓冲区,/code> 将发出 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆