Qopenglwidget不能使用超过一个Sampler2d

QOpenGLWidget cannot use more than one sampler2D

本文关键字:一个 Sampler2d 不能 Qopenglwidget      更新时间:2023-10-16

我已经创建了一个非常基本的着色器:

static const char *frag_showImage =
"#version 150n"
"uniform sampler2D textureSampler;n"
"in mediump vec2 texc;n"
"out highp vec4 fragColor;n"
"void main() {n"
"   fragColor = texture2D(textureSampler, texc.st);n"
"}n";

它可以按预期工作,现在更复杂:

"#version 150n"
"uniform sampler2D textureSampler;n"
"uniform sampler2D maskSampler;n"
"in mediump vec2 texc;n"
"out highp vec4 fragColor;n"
"void main() {n"
"   fragColor = texture2D(textureSampler, texc.st);n"
"   fragColor.x = texture2D(maskSampler, texc.st).x;n"
"   fragColor.y =0;n"
"}n";

它行不通,但没有任何警告:

在这两种情况下,我都将第一个纹理绑定为:

QOpenGLFunctions *f =this->context()->functions();
f->glActiveTexture(GL_TEXTURE0);
glBaseTexture->bind();
m_program->setUniformValue("textureSampler", 0);

,第二个纹理的曲线为:

f->glActiveTexture(GL_TEXTURE1);    
glMaskTexture->bind();
m_program->setUniformValue("maskSampler", 1);

请注意,如果我绑定第一个着色器的glmaskTextul

有什么想法吗?预先感谢您!

goblins:将maskSampler重命名为其他名称,我不知道为什么在代码的任何其他部分都没有使用" maskSampler"。