gpt4 book ai didi

opengl - 重用顶点属性缓冲区作为索引缓冲区?

转载 作者:行者123 更新时间:2023-12-03 09:17:53 26 4
gpt4 key购买 nike

我可以使用像这样初始化的VBO吗:

GLuint bufferID;
glGenBuffers(1,&BufferID);
glBindBuffer(GL_ARRAY_BUFFER,bufferID);
glBufferData(GL_ARRAY_BUFFER,nBytes,indexData,GL_DYNAMIC_DRAW);

作为索引缓冲区,如下所示:

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,bufferID);
/* ... set up vertex attributes, NOT using bufferID in the process ... */
glDrawElements(...);

我想主要将该缓冲区用作属性缓冲区,偶尔用作索引缓冲区(但绝不会同时使用)。

最佳答案

GL 中没有任何内容可以阻止您执行此类操作,上面的代码是合法的 GL。您可以将每个缓冲区绑定(bind)到每个缓冲区绑定(bind)目标(甚至可以将同一缓冲区同时绑定(bind)到不同的目标,因此如果属性和索引数据来自同一缓冲区也是可以的)。但是,GL 实现可能会根据观察到的应用程序行为进行一些优化,因此,如果您突然使用这种方法更改现有缓冲区对象的使用,或者将其用于两件事,则最终可能会获得次优性能立刻。

更新

ARB_vertex_buffer_object extension spec向 OpenGL 引入了缓冲区对象的概念,在“问题”部分提到了这个主题:

Should this extension include support for allowing vertex indices to be stored in buffer objects?

RESOLVED: YES. It is easily and cleanly added with just the addition of a binding point for the index buffer object. Since our approach of overloading pointers works for any pointer in GL, no additional APIs need be defined, unlike in the various *_element_array extensions.

Note that it is expected that implementations may have different memory type requirements for efficient storage of indices and vertices. For example, some systems may prefer indices in AGP memory and vertices in video memory, or vice versa; or, on systems where DMA of index data is not supported, index data must be stored in (cacheable) system memory for acceptable performance. As a result, applications are strongly urged to put their models' vertex and index data in separate buffers, to assist drivers in choosing the most efficient locations.

不过,某些实现可能更愿意将索引缓冲区保留在系统 RAM 中的推理似乎已经过时了。

关于opengl - 重用顶点属性缓冲区作为索引缓冲区?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35821387/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com