OpenGL - 链接两个纹理不起作用

OpenGL - Linking two textures doesn't work

本文关键字:两个 纹理 不起作用 链接 OpenGL      更新时间:2023-10-16

我正在尝试将FBO的深度纹理和颜色纹理链接到GLSL Shader(4.0版)

问题是,同时只有一个链接,这很奇怪,因为其他纹理可以很好地链接在一起(例如:漫反射、法线和镜面反射贴图)

这是我的绑定RT代码:

void RenderTexture::BindRead(GLuint locationColor,GLuint locationDepth,unsigned int unit,unsigned int dUnit)
{
    colorUnit = unit;
    this->depthUnit = dUnit;
    assert(unit >= 0 && unit <= 31);
    glActiveTexture(GL_TEXTURE0 + unit);
    glBindTexture(GL_TEXTURE_2D,m_rt);
    if (hasDepth)
    {
        assert(depthUnit >= 0 && depthUnit <= 31);
        glActiveTexture(GL_TEXTURE0 + dUnit);
        glBindTexture(GL_TEXTURE_2D,m_depth);
        glUniform1i(locationDepth,dUnit);
    }
    glUniform1i(locationColor,unit);
}

我真的不知道这里出了什么问题。。。

终于找到了解决方案问题是我在设置值之后绑定了程序,应该在之前,这也修复了我遇到的许多其他错误。