![](/img/trans.png)
[英]OpenGl ES 3.0 Context not created on iPad (works in Simulator)
[英]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.