gpt4 book ai didi

c++ - 你怎么 "free"一个纹理单元?

转载 作者:太空狗 更新时间:2023-10-29 20:01:53 25 4
gpt4 key购买 nike

为了使用纹理单元,我们通常像这样将它绑定(bind)到当前进程:

glUseProgram(program);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textureID);

GLint loc = glGetUniformLocation(program, "uniform");
//error check

glUniform1i(loc,0);

如何“释放”纹理单元。换句话说,如何从当前程序中的纹理单元绑定(bind)点分离纹理?

最佳答案

How do you "free" the texture unit. In other words how do you detach the texture from the texture unit binding point in the current program?


您不能“释放”纹理单元,但可以将默认纹理对象绑定(bind)到纹理单元。

See OpenGL 4.6 API Compatibility Profile Specification; 8.1 Texture Objects; page 178:

Textures in GL are represented by named objects. The name space for texture objects is the unsigned integers, with zero reserved by the GL to represent the default texture object.

...

The binding is effected by calling

void BindTexture( enum target, uint texture );

with target set to the desired texture target and texture set to the unused name.

这意味着

GLuint defaultTextureObjectID = 0;
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, defaultTextureObjectID);

将默认纹理对象绑定(bind)到纹理单元 0。


从 OpenGL 4.5 开始可以使用 glBindTextureUnit

The command

void BindTextureUnit( uint unit, uint texture );

binds an existing texture object to the texture unit numbered unit. texture must be zero or the name of an existing texture object. When texture is the name of an existing texture object, that object is bound to the target, in the corresponding texture unit, that was specified when the object was created.

因此您也可以使用以下内容:

glBindTextureUnit( 0, 0 ); // texture unit 0, default texture object (0)

关于c++ - 你怎么 "free"一个纹理单元?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50113147/

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