glGenTextures产生的是一个比较小的整数id(纹理单元名),glActiveTexture激活的是纹理单元号(GL_TEXTUREi),它们二者的关系为GL_TEXTUREi=GL_TEXTURE0+id。glBindTexture使用的是纹理单元名。(一派胡言,glGenTextures产生的是纹理对象(简称纹理),纹理单元数量在GPU上确定的,不需要创建,glBindTexture将纹理对象绑定到当前纹理单元的的目标类型上(一个纹理单元可以有多个类型1D、2D等,一个纹理对象能够绑定到多个目标类型上),一个纹理对象可以绑定到多个纹理单元上,一个纹理单元上只能有一个同种纹理类型(如果有多个采样会无所适从))。
是否产生即激活了,如果不是osg有问题。应该不会自动激活产生的纹理单元。
glTexImage2D specifies the two-dimensional texture for the current texture unit, specified with glActiveTexture.OpenGL 4 Reference Pageshttps://www.khronos.org/registry/OpenGL-Refpages/gl4/
以下是osg使用纹理的过程,中间缺少glActiveTexture使用纹理单元的过程。
1、创建纹理
osg::ref_ptr<osg::Texture> tex = new osg::Texture2D(ImageUtils::createEmptyImage(1, 1));
terrainSS->addUniform(new osg::Uniform(b.samplerName().c_str(), b.unit()));
terrainSS->setTextureAttribute(b.unit(), tex.get());
2、创建纹理单元
GLuint id;
glGenTextures( 1L, &id );
3、上传纹理数据
glTexImage2D( target, 0, _internalFormat,
inwidth, inheight, _borderWidth,
(GLenum)image->getPixelFormat(),
(GLenum)image->getDataType(),
dataPtr);