[英]QOpenGLWidget cannot use more than one sampler2D
我创建了一个非常基本的着色器:
static const char *frag_showImage =
"#version 150\n"
"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 150\n"
"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);
请注意,如果我将glMaskTexture绑定到第一个着色器,则可以正常工作,因此问题不在该QOpenGlTexture上。
任何想法? 先感谢您!
哥布林:将maskSampler重命名为可以正常工作的其他名称,我不知道为什么会这样,因为代码的任何其他部分均未使用“ maskSampler”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.