简体   繁体   English

带有iPhone的OpenGL ES 2.0-无法找到统一的Vertex Shader

[英]OpenGL ES 2.0 with iPhone - Vertex Shader uniform cannot be located

I have the following vertex shader : 我有以下顶点着色器

uniform mediump mat4 projMx;

attribute vec2 a_position;      
attribute vec4 a_color;     
attribute float a_radius;       
varying vec4 v_color;
void main()
{
    vec4 position = vec4(100.0,600.0,1.0,1.0);
    gl_Position = projMx * position;
    gl_PointSize = a_radius*2.0;
    v_color = a_color;
}

..and the following fragment shader : ..以及以下片段着色器

#ifdef GL_FRAGMENT_PRECISION_HIGH
    precision highp float;
#else
    precision mediump float;
#endif

varying vec4 v_color;
void main()
{
    gl_FragColor = v_color;
}

..and the following Obj-C code : ..以及以下Obj-C代码

    //..shaders have been created..
program = glCreateProgram();
glAttachShader(program, shaders[0]);
glAttachShader(program, shaders[1]);

GLfloat projMx[16] = {2/screenWidth,0,0,-1,0,2/-screenHeight,0,1,0,0,-2,-1,0,0,0,1};

projMxId = glGetUniformLocation(program, "projMx");
NSLog(@"uniform location:%i",projMxId);

The uniform location of 'projMx' is -1 (ie 'projMxId == -1' is true). “ projMx”统一位置为-1 (即“ projMxId == -1”为真)。 Could someone please explain why this is the case? 有人可以解释为什么会这样吗?

You can only retrieve uniform locations after linking the program (what you don't do), as these are per-program state and known in every shader of the program. 链接程序后,您只能检索统一的位置(不执行操作),因为这些位置是每个程序的状态,并且在程序的每个着色器中都是已知的。 The GLSL compiler can optimize unused uniforms away during linking, so their locations should only be known after linking, which is also the moment when all attributes not explicitly bound get their locations. GLSL编译器可以在链接期间优化未使用的制服,因此只有在链接之后才知道它们的位置,这也是所有未明确绑定的属性都获得其位置的时刻。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM