glActiveTexture default behavior not as anticipated
我只想澄清一下OpenGL的行为。据我了解,默认的活动纹理单位为0(
我之所以这样问,是因为我的行为举止我无法解释且存在问题。加载纹理并将其绑定到
当我尝试使用更多纹理,而我不得不显式设置每个
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glActiveTexture.xhtml
这是开车兜风吗?在此先感谢您的任何建议。
Dell Precision M6800,nV K2200M,GL 4.1
必须设置为纹理采样器统一的值是纹理单位的索引,而不是纹理对象的索引。
像这样更改您的代码:
1 2 3 4 5 6 7 | gl_->glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, calibrationTexture_); // this is wrong //SetUniform("quadTexture", calibrationTexture_); SetUniform("quadTexture", 1 ); // 1 because of GL_TEXTURE1 |
请参阅OpenGL 4.6 API兼容性配置文件规范; 7.10采样器第154页:
Samplers are special uniforms used in the OpenGL Shading Language to identify
the texture object used for each texture lookup. The value of a sampler indicates the texture image unit being accessed. Setting a samplera€?s value toi selects texture image unit numberi .
注意,纹理对象的"名称"由
生成
1 | glGenTextures(1, &calibrationTexture_); |
此"名称"(整数)取决于硬件和驱动程序。
但是,由于您的代码中仅生成1个纹理对象,因此名称的值很有可能为1。
这意味着,当您设置
1 | gl_->glActiveTexture(GL_TEXTURE1); |
您的代码有效,因为