为什么QOpenGLShaderProgram :: uniformLocation返回-1?

时间:2017-09-05 12:00:44

标签: qt vertex-shader

为什么uniformLocation返回-1?如果我在bind()之后调用该函数,它仍然返回-1。 attributLocation调用返回有效数字。

void X::afterRendering() {

    shader = new QOpenGLShaderProgram();

    shader->addShaderFromSourceCode(
       QOpenGLShader::Vertex,
       "attribute highp vec4 vertices;"
       "attribute highp vec3 vertColor;"
       "uniform highp mat4 mWorld;"
       "uniform highp mat4 mProj;"
       "uniform highp mat4 mView;"
       "varying highp vec3 fragColor;"
       "void main() {"
       "    fragColor = vertColor;"
       "    gl_Position = vertices;"
       "}"
       );

    shader->addShaderFromSourceCode(
       QOpenGLShader::Fragment,
       "varying highp vec3 fragColor;"
       "void main() {"
       "    gl_FragColor = vec4(fragColor, 1.0);"
       "}"
       );

     shader->link();

    vertexLocation = shader->attributeLocation("vertices");   // 0
    colorLocation = shader->attributeLocation("vertColor");   // 1


    matWorldUniformLocation = shader->uniformLocation("mWorld");  // returns -1 here <<<<<<<<

0 个答案:

没有答案