glGenBuffers 与 glGenTextures

glGenBuffers vs glGenTextures

glGenBuffersglGenTextures到底有什么区别?我注意到当我尝试生成纹理时两者都工作得很好:

int texture1 = GL30.glGenBuffers();
GL30.glBindTexture(GL30.GL_TEXTURE_2D,texture1);

int texture2 = GL30.glGenTextures();
GL30.glBindTexture(GL30.GL_TEXTURE_2D,texture2);

这两个对我来说似乎完全一样。使用 glGenTexturesglGenBuffers 有什么优势吗?如果不是,为什么 glGenTextures 甚至可以用 glGenBuffers 代替?

glGenTexturesglGenBuffers 不创建任何对象或缓冲区,它们只是将对象名称标记为已使用。这意味着他们保留对象名称。
虽然 glGenTextures 保留纹理名称,glGenBuffers 保留缓冲区名称,但 glGenTextures 编辑的名称可能与 return 编辑的名称相同14=].
glGenTextures 仅保证 returned 的名称不用于纹理目的。
glGenBuffers 保证 returned 的名称不用于缓冲区的目的。

注意,缓冲区对象和纹理对象可能具有相同的值,但是有2个完全不同的对象。 return 由 glGenBuffers 编辑的名称未标记为用作(或保留)用作纹理对象,但保留用作缓冲区对象。

OpenGL ES 3.2 Specification - 8.1 Texture Objects; page 140

The command

void GenTextures( sizei n, uint *textures );

returns n previously unused texture names in textures. These names are marked as used, for the purposes of GenTextures only, but they acquire texture state and a dimensionality only when they are first bound, just as if they were unused.

OpenGL ES 3.2 Specification - 6 Buffer Objects; page 50

The command

void GenBuffers( sizei n, uint *buffers );

returns n previously unused buffer object names in buffers. These names are marked as used, for the purposes of GenBuffers only, but they acquire buffer state only when they are first bound with BindBuffer (see below), just as if they were unused.


请注意,此处的 OpenGL ES 规范不同于(桌面)OpenGL 核心配置文件规范。 在(桌面)OpenGL 核心配置文件中,将值传递给 glBindTexture 是无效的,它不是 glGenTexture 的 return。

参见 OpenGL 4.6 API Core Profile Specification - 8.1 Texture Objects; page 180

The binding is effected by calling

void BindTexture( enum target, uint texture );

[...]

Errors
[...]
An INVALID_OPERATION error is generated if texture is not zero or a name returned from a previous call to GenTextures, or if such a name has since been deleted.