在Vivante GC1000 GPU上编译/链接着色器(Galaxy Tab 3)

时间:2014-03-25 21:24:55

标签: android opengl-es cocos2d-x

我正在尝试在Galaxy Tab 3上使用我的自定义着色器,但它们无法编译或链接。这是代码。 这是顶点着色器

attribute vec4 a_position;
attribute vec2 a_texCoord;

uniform sampler2D   u_texture;
varying vec2        blurs[8];
uniform vec2        blurSize;

#ifdef GL_ES
varying lowp vec2 v_texCoord;                    
#else                    
varying vec2 v_texCoord;
#endif

void main() 
{
    gl_Position = CC_MVPMatrix * a_position;
    v_texCoord = a_texCoord;

    blurs[0] = v_texCoord + vec2(-0.016, 0.0) * blurSize;
    blurs[1] = v_texCoord + vec2(-0.012, 0.0) * blurSize;
    blurs[2] = v_texCoord + vec2(-0.008, 0.0) * blurSize;
    blurs[3] = v_texCoord + vec2(-0.004, 0.0) * blurSize;
    blurs[4] = v_texCoord + vec2( 0.004, 0.0) * blurSize;
    blurs[5] = v_texCoord + vec2( 0.008, 0.0) * blurSize;
    blurs[6] = v_texCoord + vec2( 0.012, 0.0) * blurSize;
    blurs[7] = v_texCoord + vec2( 0.016, 0.0) * blurSize;
}

这是片段着色器

#ifdef GL_ES
precision lowp float;
#endif

varying vec2 v_texCoord;
varying vec2 blurs[8];
uniform sampler2D u_texture;

//uniform vec2 blurSize;
uniform vec4 substract;

void main() {
    gl_FragColor = vec4(0.0);
    gl_FragColor += texture2D(u_texture, blurs[0])*0.0443;
    gl_FragColor += texture2D(u_texture, blurs[1])*0.0776;
    gl_FragColor += texture2D(u_texture, blurs[2])*0.1158;
    gl_FragColor += texture2D(u_texture, blurs[3])*0.1473;
    gl_FragColor += texture2D(u_texture, v_texCoord         )*0.1595;
    gl_FragColor += texture2D(u_texture, blurs[4])*0.1473;
    gl_FragColor += texture2D(u_texture, blurs[5])*0.1158;
    gl_FragColor += texture2D(u_texture, blurs[6])*0.0776;
    gl_FragColor += texture2D(u_texture, blurs[7])*0.0443;
}

在ipad,nexus设备和galaxy s3 / s4以及note 3中,它运行正常。但在galaxy tab 3(与vivante gc1000 gpu)无法编译或链接;我不确定哪一个失败了。 以下是logcat的错误:

03-25 20:59:36.328 D/v_gal   (3167): [tid=3179] gcmONERROR: status=-10(gcvSTATUS_TOO_COMPLEX) @ _GenerateStates(10194)
03-25 20:59:36.328 D/v_gal   (3167): [tid=3179] gcmONERROR: status=-10(gcvSTATUS_TOO_COMPLEX) @ gcLINKTREE_GenerateStates(11342)
03-25 20:59:36.328 D/v_gal   (3167): [tid=3179] gcmERR_BREAK: status=-10(gcvSTATUS_TOO_COMPLEX) @ gcLinkShaders(7831)
03-25 20:59:36.328 D/cocos2d-x debug info(3167): cocos2d: ERROR: Failed to link program: 25
03-25 20:59:36.328 D/cocos2d-x debug info(3167): cocos2d: ERROR LOG PROGRAM: (null)
03-25 20:59:36.328 D/v_gal   (3167): [tid=3179] gl2mERROR: result=0x0501 @ glGetShaderiv(886)
03-25 20:59:36.328 D/cocos2d-x debug info(3167): cocos2d: ERROR LOG VERTEX: (null)
03-25 20:59:36.328 D/v_gal   (3167): [tid=3179] gl2mERROR: result=0x0501 @ glGetShaderiv(886)
03-25 20:59:36.328 D/cocos2d-x debug info(3167): cocos2d: ERROR LOG FRAG: (null)

ERROR LOG PROGRAM,ERROR LOG VERTEX,ERROR LOG FRAG是对glGetProgramInfoLog和glGetShaderInfoLog的调用。它们都返回null

1 个答案:

答案 0 :(得分:2)

Vivante GC1000最多有8个不同的向量,由glGetIntegerv(GL_MAX_VARYING_VECTORS)返回。很多ES设备都具有相同的最大值。您着色器当前使用9个不同的向量(v_texCoord + 8个模糊坐标),这就是着色器编译器告诉您输入过于复杂的原因。要解决您的问题,您可以使用vec2vec4组件作为原始{{1},将8个模糊坐标.xy组合为4 .zw个}偏移,例如

在VS中:

vec2

可以成为

varying vec2 blurs[8];
…
blurs[0] = v_texCoord + vec2(-0.016, 0.0) * blurSize;
blurs[1] = v_texCoord + vec2(-0.012, 0.0) * blurSize;

在PS中:

varying vec4 blurs[4];
...
blurs[0] = v_texCoord.xyxy + vec4(-0.016, 0.0, -0.012, 0.0) * blurSize;

变为:

varying vec2 blurs[8];
…
gl_FragColor += texture2D(u_texture, blurs[0])*0.0443;
gl_FragColor += texture2D(u_texture, blurs[1])*0.0776;

希望有所帮助!