iPad Opengl ES程序在模拟器上运行良好,但不适用于设备 [英] iPad Opengl ES program works fine on simulator but not device
问题描述
对于设备,我的所有着色器都加载正常,除了一个。对于这个着色器程序,我得到片段程序无法使用当前上下文状态编译错误,当我调用glGetProgramInfoLog(...)时,顶点着色器出现类似错误;
For the device, all of my shaders load fine except one. For this shader program I get "Fragment program failed to compile with current context state" error, followed by a similar error for the vertex shader when I make a call to 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)链接程序时,我检查了每个着色器的编译状态,并且它们都检查完好。有任何想法吗?
I am not sure what is going on, especially since I have a similar program that is exactly as above with the addition of texture coordinates. Also, I checked the compile status of each shader when I linked the programs using glGetShaderiv(theShader, GL_COMPILE_STATUS, &result) and they all checked out fine. Any ideas?
推荐答案
更改行
gl_FragColor = vec4((color + specularCoefficient*MaterialSpecular).rgb, 1.0);
gl_FragColor = vec4((1.0*color + specularCoefficient*MaterialSpecular).rgb, 1.0);
解决了这个问题。我怀疑它与变化的变量颜色相关的精度有关,用于将行重新排序为
fixes the problem. I suspect it has something to do with precision related to the varying variable color, for a reordering of the line to
gl_FragColor = vec4((MaterialSpecular + specularCoefficient*color).rgb, 1.0);
同样适用。
这篇关于iPad Opengl ES程序在模拟器上运行良好,但不适用于设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!