openGL ES着色器错误的制服位置

时间:2014-04-14 10:48:39

标签: opengl-es location uniform

顶点着色器看起来像这样:

uniform mat4 projectionMatrix;
uniform mat4 modelMatrix;
uniform mat4 viewMatrix;

attribute vec4 vPosition;
attribute vec4 vColor;

varying vec4 vDestinationColor;

void main(void)
{
    gl_Position         = projectionMatrix * modelMatrix * viewMatrix * vPosition;
    vDestinationColor   = vColor;
}

Objective-C代码:

_projectionMatrixSlot   = glGetUniformLocation(_programHandle, "projectionMatrix");
_modelMatrixSlot        = glGetUniformLocation(_programHandle, "modelMatrix");
_viewMatrixSlot         = glGetUniformLocation(_programHandle, "viewMatrix");

_positionAttribSlot     = glGetAttribLocation(_programHandle, "vPosition");
_colorAttribSlot        = glGetAttribLocation(_programHandle, "vColor");

这里_projectionMatrixSlot _viewMatrixSlot _modelMatrixSlot等于4294967295 虽然_positionAttribSlot和_colorAttribSlot很好

1 个答案:

答案 0 :(得分:0)

编译器可以自由地丢弃代码中未使用的变量。因此,即使在着色器中声明了一个uniform,只要它不被使用,它的报告位置可以是-1或max int或unsigned int。

您可能附加了错误的顶点着色器,而不是您在此处发布的那个。