簡體   English   中英

QOpenGLWidget不能使用多個sampler2D

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM