glBindTexture函数的理解

简单的说opengl的设计思想,实现较早,并不是基于对象,所以API操作, 总是以奇怪的enum枚举类型来作为操作对象。形成的编程范式就是先bind绑定到一个named obj(其实是个整数)并在内部创建一个该target类型对象structure,设置gc->current_target[target]=new texure_obj。然后调用api对当然bind的对象以enum枚举类型进行操作。

具体一个例子如下:

glGenTextures(1, &id);

glBindTexture(GL_TEXTURE_2D, id); //相当create 2d texture_obj对象,并设置了gc->cur_texture_2d=id;

glTexImage2D(GL_TEXTURE_2D,0,...); //对gc->cur_texture_2d的texture_obj进行具体的设置。

glTexParameteri(GL_TEXTURE_2D,...);

glBindTexture(GL_TEXTURE_2D, id_other);//切换gc->cur_texture_2d=id_other;切换对象了

一种可能的实现:

__bindTexture(target, id){

new target texture_obj(id);

gc->target[target]=id;

gc->cur_texobj=gc->texobj->named_id[id]

}

官方参考:

phttps://registry.khronos.org/OpenGL-Refpages/gl4/html/glBindTexture.xhtmlicon-default.png?t=N7T8https://registry.khronos.org/OpenGL-Refpages/gl4/html/glBindTexture.xhtml

Name

glBindTexture — bind a named texture to a texturing target

C Specification

void glBindTexture(GLenum target,
GLuint texture);

Parameters

target

Specifies the target to which the texture is bound. Must be one of GL_TEXTURE_1DGL_TEXTURE_2DGL_TEXTURE_3DGL_TEXTURE_1D_ARRAYGL_TEXTURE_2D_ARRAYGL_TEXTURE_RECTANGLEGL_TEXTURE_CUBE_MAPGL_TEXTURE_CUBE_MAP_ARRAYGL_TEXTURE_BUFFERGL_TEXTURE_2D_MULTISAMPLE or GL_TEXTURE_2D_MULTISAMPLE_ARRAY.

texture

Specifies the name of a texture.

Description

glBindTexture lets you create or use a named texture. Calling glBindTexture with target set to GL_TEXTURE_1DGL_TEXTURE_2DGL_TEXTURE_3DGL_TEXTURE_1D_ARRAYGL_TEXTURE_2D_ARRAYGL_TEXTURE_RECTANGLEGL_TEXTURE_CUBE_MAPGL_TEXTURE_CUBE_MAP_ARRAYGL_TEXTURE_BUFFERGL_TEXTURE_2D_MULTISAMPLE or GL_TEXTURE_2D_MULTISAMPLE_ARRAY and texture set to the name of the new texture binds the texture name to the target. When a texture is bound to a target, the previous binding for that target is automatically broken.

Texture names are unsigned integers. The value zero is reserved to represent the default texture for each texture target. Texture names and the corresponding texture contents are local to the shared object space of the current GL rendering context; two rendering contexts share texture names only if they explicitly enable sharing between contexts through the appropriate GL windows interfaces functions.

You must use glGenTextures to generate a set of new texture names.

When a texture is first bound, it assumes the specified target: A texture first bound to GL_TEXTURE_1D becomes one-dimensional texture, a texture first bound to GL_TEXTURE_2D becomes two-dimensional texture, a texture first bound to GL_TEXTURE_3D becomes three-dimensional texture, a texture first bound to GL_TEXTURE_1D_ARRAY becomes one-dimensional array texture, a texture first bound to GL_TEXTURE_2D_ARRAY becomes two-dimensional array texture, a texture first bound to GL_TEXTURE_RECTANGLE becomes rectangle texture, a texture first bound to GL_TEXTURE_CUBE_MAP becomes a cube-mapped texture, a texture first bound to GL_TEXTURE_CUBE_MAP_ARRAY becomes a cube-mapped array texture, a texture first bound to GL_TEXTURE_BUFFER becomes a buffer texture, a texture first bound to GL_TEXTURE_2D_MULTISAMPLE becomes a two-dimensional multisampled texture, and a texture first bound to GL_TEXTURE_2D_MULTISAMPLE_ARRAY becomes a two-dimensional multisampled array texture. The state of a one-dimensional texture immediately after it is first bound is equivalent to the state of the default GL_TEXTURE_1D at GL initialization, and similarly for the other texture types.

While a texture is bound, GL operations on the target to which it is bound affect the bound texture, and queries of the target to which it is bound return state from the bound texture. In effect, the texture targets become aliases for the textures currently bound to them, and the texture name zero refers to the default textures that were bound to them at initialization.

A texture binding created with glBindTexture remains active until a different texture is bound to the same target, or until the bound texture is deleted with glDeleteTextures.

Once created, a named texture may be re-bound to its same original target as often as needed. It is usually much faster to use glBindTexture to bind an existing named texture to one of the texture targets than it is to reload the texture image using glTexImage1DglTexImage2DglTexImage3D or another similar function.

Notes

The GL_TEXTURE_2D_MULTISAMPLE and GL_TEXTURE_2D_MULTISAMPLE_ARRAY targets are available only if the GL version is 3.2 or higher.

Errors

GL_INVALID_ENUM is generated if target is not one of the allowable values.

GL_INVALID_VALUE is generated if texture is not a name returned from a previous call to glGenTextures.

GL_INVALID_OPERATION is generated if texture was previously created with a target that doesn't match that of target.

Associated Gets

glGet with argument GL_TEXTURE_BINDING_1DGL_TEXTURE_BINDING_2DGL_TEXTURE_BINDING_3DGL_TEXTURE_BINDING_1D_ARRAYGL_TEXTURE_BINDING_2D_ARRAYGL_TEXTURE_BINDING_RECTANGLEGL_TEXTURE_BINDING_BUFFERGL_TEXTURE_BINDING_CUBE_MAPGL_TEXTURE_BINDING_CUBE_MAP_ARRAYGL_TEXTURE_BINDING_2D_MULTISAMPLE, or GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY.

Version Support

  • 29
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值