glError为glUniform *返回INVALID_OPERATION

时间:2014-01-22 05:19:52

标签: android opengl-es-2.0

我正在调用glUniformMatrix4fv& glUniform4f和我都得到一个INVALID_OPERATION的错误。 glGetUniformLocation为mvp和color返回0,原因我没想到。

该计划有效。

    glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);

Shader* shader = Root::getInstance()->getRenderSystem()->getShader("Test");
shader->bind();

glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);

kmMat4 mvp;
kmMat4 mv;
kmMat4Multiply(&mv, &model, &view);
kmMat4Multiply(&mvp, &perspective, &mv);

GLint uMvp = shader->getUniformLocation("mvp");
LOG("%i", uMvp);

glUniformMatrix4fv(uMvp, 1, GL_FALSE, mvp.mat);
checkGlErro("uniform matrix");

GLint uColor = shader->getUniformLocation("color");
LOG("%i", uColor);

glUniform4f(uColor, 0, 0, 1, 1);
checkGlErro("uniform");

glDrawArrays(GL_LINES, 0, 2);

glDisableVertexAttribArray(0);
shader->unbind();
glBindBuffer(GL_ARRAY_BUFFER, 0);

着色器:

const std::string testShader_vert =
"uniform mat4 mvp; \n"
"attribute vec4 position; \n"
"void main() { \n"
"   gl_Position = mvp * position; \n"
"}";


const std::string testShader_frag =
"precision mediump float; \n"
"uniform vec4 color; \n"
"void main() { \n"
"   gl_FragColor = color; \n"
"}";

0 个答案:

没有答案