繁体   English   中英

iPad Opengl ES程序可以在模拟器上正常运行,但不能在设备上运行

[英]iPad Opengl ES program works fine on simulator but not device

对于该设备,除一个外,我所有的着色器都可以正常加载。 对于此着色器程序,我得到“片段程序无法用当前上下文状态编译失败”错误,当我调用glGetProgramInfoLog(...)时,顶点着色器也出现类似错误;

顶点着色器:

#version 100

uniform mat4 Projection;
uniform mat4 Modelview;
uniform mat4 Rotation;
uniform vec3 Translation;

uniform vec4 LightDirection;
uniform vec4 MaterialDiffuse;
uniform float MaterialShininess;

attribute vec3 position;
attribute vec3 normal;

varying vec4 color;
varying float specularCoefficient;

void main() {
    vec3 _normal = normalize(mat3(Modelview[0].xyz, Modelview[1].xyz, Modelview[2].xyz)*normal); 
    // There is an easier way to do the above using typecast, but is apparently broken

    float NdotL = dot(-_normal, normalize(vec3(LightDirection)));
    if(NdotL < 0.0){
        NdotL = 0.0;
    }
    color = NdotL * MaterialDiffuse;
    float NdotO = dot(-_normal, vec3(0.0, 0.0, -1.0));
    if(NdotO < 0.0){
        NdotO = 0.0;
    }
    specularCoefficient = pow(NdotO, MaterialShininess);

    vec3 p = position + Translation;
    gl_Position = Projection*Modelview*vec4(p, 1.0);
}

片段着色器:

#version 100
precision mediump float;

varying vec4 color;
varying float specularCoefficient;
uniform vec4 MaterialSpecular;

void main(){
    gl_FragColor = vec4((color + specularCoefficient*MaterialSpecular).rgb, 1.0);
}

我不确定发生了什么,特别是因为我有一个类似的程序,它与上面的程序完全一样,只是添加了纹理坐标。 另外,当我使用glGetShaderiv(theShader,GL_COMPILE_STATUS,&result)链接程序时,我检查了每个着色器的编译状态,并且它们都检查正常。 有任何想法吗?

换线

gl_FragColor = vec4((color + specularCoefficient*MaterialSpecular).rgb, 1.0);

在片段着色器中

gl_FragColor = vec4((1.0*color + specularCoefficient*MaterialSpecular).rgb, 1.0);

解决问题。 我怀疑这与变化的可变颜色有关的精度有关,以便将行重新排序为

gl_FragColor = vec4((MaterialSpecular + specularCoefficient*color).rgb, 1.0);

也可以。

暂无
暂无

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

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