fix opengl resource error

This commit is contained in:
jianglong0156 2015-05-26 14:26:45 +08:00
parent 95e8212727
commit ae4c8d9798
22 changed files with 451 additions and 33 deletions

View File

@ -0,0 +1,27 @@
// Shader taken from: http://webglsamples.googlecode.com/hg/electricflower/electricflower.html
#ifdef GL_ES
precision mediump float;
#endif
varying vec4 v_fragmentColor;
varying vec2 v_texCoord;
uniform vec2 blurSize;
uniform vec4 substract;
void main() {
vec4 sum = vec4(0.0);
sum += texture2D(CC_Texture0, v_texCoord - 4.0 * blurSize) * 0.05;
sum += texture2D(CC_Texture0, v_texCoord - 3.0 * blurSize) * 0.09;
sum += texture2D(CC_Texture0, v_texCoord - 2.0 * blurSize) * 0.12;
sum += texture2D(CC_Texture0, v_texCoord - 1.0 * blurSize) * 0.15;
sum += texture2D(CC_Texture0, v_texCoord ) * 0.16;
sum += texture2D(CC_Texture0, v_texCoord + 1.0 * blurSize) * 0.15;
sum += texture2D(CC_Texture0, v_texCoord + 2.0 * blurSize) * 0.12;
sum += texture2D(CC_Texture0, v_texCoord + 3.0 * blurSize) * 0.09;
sum += texture2D(CC_Texture0, v_texCoord + 4.0 * blurSize) * 0.05;
gl_FragColor = (sum - substract) * v_fragmentColor;
}

View File

@ -0,0 +1,43 @@
// http://www.cocos2d-iphone.org
#ifdef GL_ES
precision lowp float;
#endif
varying vec2 v_texCoord;
vec4 getColorByCoord(int y){
if(y < 5){
if(y == 0){
return vec4(1,0,0,1);
} else if(y == 1){
return vec4(0,1,0,1);
} else if(y == 2){
return vec4(0,0,1,1);
} else if(y == 3){
return vec4(0,1,1,1);
} else{
return vec4(1,0,1,1);
}
} else {
if(y == 5){
return vec4(1,1,0,1);
} else if(y == 6){
return vec4(1,1,1,1);
} else if(y == 7){
return vec4(1,0.5,0,1);
} else if(y == 8){
return vec4(1,0.5,0.5,1);
}else {
return vec4(0.5,0.5,1,1);
}
}
}
void main(void) {
// inline to prevent "float" loss and keep using lowp
//int y = int( mod(( (gl_FragCoord.y+gl_FragCoord.x)*mod(CC_Time[0],5.0)) / 10.0, 10.0 ) );
//int y = int( mod( CC_Time[3] + (gl_FragCoord.y + gl_FragCoord.x) / 10.0, 10.0 ) );
int y = int( mod(gl_FragCoord.y / 10.0, 10.0 ) );
gl_FragColor = getColorByCoord(y) * texture2D(CC_Texture0, v_texCoord);
}

View File

@ -0,0 +1,18 @@
// http://www.cocos2d-iphone.org
attribute vec4 a_position;
attribute vec2 a_texCoord;
#ifdef GL_ES
varying mediump vec2 v_texCoord;
#else
varying vec2 v_texCoord;
#endif
void main()
{
//gl_Position = CC_MVPMatrix * a_position;
gl_Position = (CC_PMatrix * CC_MVMatrix) * a_position;
v_texCoord = a_texCoord;
}

View File

@ -0,0 +1,34 @@
// Shader from http://www.iquilezles.org/apps/shadertoy/
#ifdef GL_ES
precision highp float;
#endif
uniform vec2 center;
uniform vec2 resolution;
//float u( float x ) { return 0.5+0.5*sign(x); }
float u( float x ) { return (x>0.0)?1.0:0.0; }
//float u( float x ) { return abs(x)/x; }
void main(void)
{
float time = CC_Time[1];
vec2 p = 2.0 * (gl_FragCoord.xy - center.xy) / resolution.xy;
float a = atan(p.x,p.y);
float r = length(p)*.75;
float w = cos(3.1415927*time-r*2.0);
float h = 0.5+0.5*cos(12.0*a-w*7.0+r*8.0);
float d = 0.25+0.75*pow(h,1.0*r)*(0.7+0.3*w);
float col = u( d-r ) * sqrt(1.0-r/d)*r*2.5;
col *= 1.25+0.25*cos((12.0*a-w*7.0+r*8.0)/2.0);
col *= 1.0 - 0.35*(0.5+0.5*sin(r*30.0))*(0.5+0.5*cos(12.0*a-w*7.0+r*8.0));
gl_FragColor = vec4(
col,
col-h*0.5+r*.2 + 0.35*h*(1.0-r),
col-h*r + 0.1*h*(1.0-r),
1.0);
}

View File

@ -0,0 +1,8 @@
// http://www.cocos2d-iphone.org
attribute vec4 a_position;
void main()
{
gl_Position = CC_MVPMatrix * a_position;
}

View File

@ -0,0 +1,33 @@
// Shader from http://www.iquilezles.org/apps/shadertoy/
#ifdef GL_ES
precision highp float;
#endif
uniform vec2 center;
uniform vec2 resolution;
void main(void)
{
float time = CC_Time[1];
vec2 p = 2.0 * (gl_FragCoord.xy - center.xy) / resolution.xy;
// animate
float tt = mod(time,2.0)/2.0;
float ss = pow(tt,.2)*0.5 + 0.5;
ss -= ss*0.2*sin(tt*6.2831*5.0)*exp(-tt*6.0);
p *= vec2(0.5,1.5) + ss*vec2(0.5,-0.5);
float a = atan(p.x,p.y)/3.141593;
float r = length(p);
// shape
float h = abs(a);
float d = (13.0*h - 22.0*h*h + 10.0*h*h*h)/(6.0-5.0*h);
// color
float f = step(r,d) * pow(1.0-r/d,0.25);
gl_FragColor = vec4(f,0.0,0.0,f);
}

View File

@ -0,0 +1,8 @@
// http://www.cocos2d-iphone.org
attribute vec4 a_position;
void main()
{
gl_Position = CC_MVPMatrix * a_position;
}

View File

@ -0,0 +1,29 @@
// Shader from http://www.iquilezles.org/apps/shadertoy/
#ifdef GL_ES
precision highp float;
#endif
uniform vec2 center;
uniform vec2 resolution;
void main(void)
{
float time = CC_Time[1];
vec2 p = 2.0 * (gl_FragCoord.xy - center.xy) / resolution.xy;
vec2 cc = vec2( cos(.25*time), sin(.25*time*1.423) );
float dmin = 1000.0;
vec2 z = p*vec2(1.33,1.0);
for( int i=0; i<64; i++ )
{
z = cc + vec2( z.x*z.x - z.y*z.y, 2.0*z.x*z.y );
float m2 = dot(z,z);
if( m2>100.0 ) break;
dmin=min(dmin,m2);
}
float color = sqrt(sqrt(dmin))*0.7;
gl_FragColor = vec4(color,color,color,1.0);
}

View File

@ -0,0 +1,8 @@
// http://www.cocos2d-iphone.org
attribute vec4 a_position;
void main()
{
gl_Position = CC_MVPMatrix * a_position;
}

View File

@ -0,0 +1,41 @@
// Shader from http://www.iquilezles.org/apps/shadertoy/
#ifdef GL_ES
precision highp float;
#endif
uniform vec2 center;
uniform vec2 resolution;
void main(void)
{
vec2 p = 2.0 * (gl_FragCoord.xy - center.xy) / resolution.xy;
p.x *= resolution.x/resolution.y;
float zoo = .62+.38*sin(.1*CC_Time[1]);
float coa = cos( 0.1*(1.0-zoo)*CC_Time[1] );
float sia = sin( 0.1*(1.0-zoo)*CC_Time[1] );
zoo = pow( zoo,8.0);
vec2 xy = vec2( p.x*coa-p.y*sia, p.x*sia+p.y*coa);
vec2 cc = vec2(-.745,.186) + xy*zoo;
vec2 z = vec2(0.0);
vec2 z2 = z*z;
float m2;
float co = 0.0;
for( int i=0; i<256; i++ )
{
z = cc + vec2( z.x*z.x - z.y*z.y, 2.0*z.x*z.y );
m2 = dot(z,z);
if( m2>1024.0 ) break;
co += 1.0;
}
co = co + 1.0 - log2(.5*log2(m2));
co = sqrt(co/256.0);
gl_FragColor = vec4( .5+.5*cos(6.2831*co+0.0),
.5+.5*cos(6.2831*co+0.4),
.5+.5*cos(6.2831*co+0.7),
1.0 );
}

View File

@ -0,0 +1,8 @@
// http://www.cocos2d-iphone.org
attribute vec4 a_position;
void main()
{
gl_Position = CC_MVPMatrix * a_position;
}

View File

@ -0,0 +1,35 @@
// Shader from http://www.iquilezles.org/apps/shadertoy/
#ifdef GL_ES
precision highp float;
#endif
uniform vec2 center;
uniform vec2 resolution;
void main(void)
{
vec2 p = 2.0 * (gl_FragCoord.xy - center.xy) / resolution.xy;
float a = CC_Time[1]*40.0;
float d,e,f,g=1.0/40.0,h,i,r,q;
e=400.0*(p.x*0.5+0.5);
f=400.0*(p.y*0.5+0.5);
i=200.0+sin(e*g+a/150.0)*20.0;
d=200.0+cos(f*g/2.0)*18.0+cos(e*g)*7.0;
r=sqrt(pow(i-e,2.0)+pow(d-f,2.0));
q=f/r;
e=(r*cos(q))-a/2.0;f=(r*sin(q))-a/2.0;
d=sin(e*g)*176.0+sin(e*g)*164.0+r;
h=((f+d)+a/2.0)*g;
i=cos(h+r*p.x/1.3)*(e+e+a)+cos(q*g*6.0)*(r+h/3.0);
h=sin(f*g)*144.0-sin(e*g)*212.0*p.x;
h=(h+(f-e)*q+sin(r-(a+h)/7.0)*10.0+i/4.0)*g;
i+=cos(h*2.3*sin(a/350.0-q))*184.0*sin(q-(r*4.3+a/12.0)*g)+tan(r*g+h)*184.0*cos(r*g+h);
i=mod(i/5.6,256.0)/64.0;
if(i<0.0) i+=4.0;
if(i>=2.0) i=4.0-i;
d=r/350.0;
d+=sin(d*d*8.0)*0.52;
f=(sin(a*g)+1.0)/2.0;
gl_FragColor=vec4(vec3(f*i/1.6,i/2.0+d/13.0,i)*d*p.x+vec3(i/1.3+d/8.0,i/2.0+d/18.0,i)*d*(1.0-p.x),1.0);
}

View File

@ -0,0 +1,8 @@
// http://www.cocos2d-iphone.org
attribute vec4 a_position;
void main()
{
gl_Position = CC_MVPMatrix * a_position;
}

View File

@ -0,0 +1,27 @@
varying vec2 v_texCoord;
varying vec4 v_fragmentColor;
uniform vec3 u_outlineColor;
uniform float u_threshold;
uniform float u_radius;
void main()
{
float radius = u_radius;
vec4 accum = vec4(0.0);
vec4 normal = vec4(0.0);
normal = texture2D(CC_Texture0, vec2(v_texCoord.x, v_texCoord.y));
accum += texture2D(CC_Texture0, vec2(v_texCoord.x - radius, v_texCoord.y - radius));
accum += texture2D(CC_Texture0, vec2(v_texCoord.x + radius, v_texCoord.y - radius));
accum += texture2D(CC_Texture0, vec2(v_texCoord.x + radius, v_texCoord.y + radius));
accum += texture2D(CC_Texture0, vec2(v_texCoord.x - radius, v_texCoord.y + radius));
accum *= u_threshold;
accum.rgb = u_outlineColor * accum.a;
normal = ( accum * (1.0 - normal.a)) + (normal * normal.a);
gl_FragColor = v_fragmentColor * normal;
}

View File

@ -0,0 +1,13 @@
attribute vec4 a_position;
attribute vec2 a_texCoord;
attribute vec4 a_color;
varying vec4 v_fragmentColor;
varying vec2 v_texCoord;
void main()
{
gl_Position = CC_PMatrix * CC_MVMatrix * a_position;
v_fragmentColor = a_color;
v_texCoord = a_texCoord;
}

View File

@ -0,0 +1,13 @@
attribute vec4 a_position;
attribute vec2 a_texCoord;
attribute vec4 a_color;
varying vec4 v_fragmentColor;
varying vec2 v_texCoord;
void main()
{
gl_Position = CC_PMatrix * a_position;
v_fragmentColor = a_color;
v_texCoord = a_texCoord;
}

View File

@ -0,0 +1,22 @@
// Shader from http://www.iquilezles.org/apps/shadertoy/
#ifdef GL_ES
precision highp float;
#endif
uniform vec2 center;
uniform vec2 resolution;
void main(void)
{
float time = CC_Time[1];
float x = gl_FragCoord.x - (center.x - resolution.x / 2.0);
float y = gl_FragCoord.y - (center.y - resolution.y / 2.0);
float mov0 = x+y+cos(sin(time)*2.)*100.+sin(x/100.)*1000.;
float mov1 = y / resolution.y / 0.2 + time;
float mov2 = x / resolution.x / 0.2;
float c1 = abs(sin(mov1+time)/2.+mov2/2.-mov1-mov2+time);
float c2 = abs(sin(c1+sin(mov0/1000.+time)+sin(y/40.+time)+sin((x+y)/100.)*3.));
float c3 = abs(sin(c2+cos(mov1+mov2+c2)+cos(mov2)+sin(x/1000.)));
gl_FragColor = vec4( c1,c2,c3,1.0);
}

View File

@ -0,0 +1,8 @@
// http://www.cocos2d-iphone.org
attribute vec4 a_position;
void main()
{
gl_Position = CC_MVPMatrix * a_position;
}

View File

@ -0,0 +1,26 @@
// Shader from here: http://www.iquilezles.org/
#ifdef GL_ES
precision highp float;
#endif
uniform vec2 resolution;
uniform sampler2D tex0;
uniform sampler2D tex1;
void main(void)
{
float time = CC_Time[1];
vec2 p = -1.0 + 2.0 * gl_FragCoord.xy / resolution.xy;
vec2 uv;
float a = atan(p.y,p.x);
float r = sqrt(dot(p,p));
uv.x = r - CC_Time[2];
uv.y = sin(a*10.0 + 2.0*CC_CosTime[0];
vec3 col = (.5+.5*uv.y)*texture2D(tex0,uv).xyz;
gl_FragColor = vec4(col,1.0);
}

View File

@ -0,0 +1,8 @@
// http://www.cocos2d-iphone.org
attribute vec4 a_position;
void main()
{
gl_Position = CC_MVPMatrix * a_position;
}

View File

@ -638,7 +638,7 @@ var ShaderHeartTest = OpenGLTestLayer.extend({
this._super();
if( 'opengl' in cc.sys.capabilities ) {
var shaderNode = new ShaderNode("Shaders/example_Heart.vsh", "Shaders/example_Heart.fsh");
var shaderNode = new ShaderNode(ccbjs + "Shaders/example_Heart.vsh", ccbjs + "Shaders/example_Heart.fsh");
this.addChild(shaderNode,10);
shaderNode.x = winSize.width/2;
shaderNode.y = winSize.height/2;
@ -678,7 +678,7 @@ var ShaderMandelbrotTest = OpenGLTestLayer.extend({
this._super();
if( 'opengl' in cc.sys.capabilities ) {
var shaderNode = new ShaderNode("Shaders/example_Mandelbrot.vsh", "Shaders/example_Mandelbrot.fsh");
var shaderNode = new ShaderNode(ccbjs + "Shaders/example_Mandelbrot.vsh", ccbjs + "Shaders/example_Mandelbrot.fsh");
this.addChild(shaderNode,10);
shaderNode.x = winSize.width/2;
shaderNode.y = winSize.height/2;
@ -713,7 +713,7 @@ var ShaderMonjoriTest = OpenGLTestLayer.extend({
this._super();
if( 'opengl' in cc.sys.capabilities ) {
var shaderNode = new ShaderNode("Shaders/example_Monjori.vsh", "Shaders/example_Monjori.fsh");
var shaderNode = new ShaderNode(ccbjs + "Shaders/example_Monjori.vsh", ccbjs + "Shaders/example_Monjori.fsh");
this.addChild(shaderNode,10);
shaderNode.x = winSize.width/2;
shaderNode.y = winSize.height/2;
@ -748,7 +748,7 @@ var ShaderPlasmaTest = OpenGLTestLayer.extend({
this._super();
if( 'opengl' in cc.sys.capabilities ) {
var shaderNode = new ShaderNode("Shaders/example_Plasma.vsh", "Shaders/example_Plasma.fsh");
var shaderNode = new ShaderNode(ccbjs + "Shaders/example_Plasma.vsh", ccbjs + "Shaders/example_Plasma.fsh");
this.addChild(shaderNode,10);
shaderNode.x = winSize.width/2;
shaderNode.y = winSize.height/2;
@ -787,7 +787,7 @@ var ShaderFlowerTest = OpenGLTestLayer.extend({
if( 'opengl' in cc.sys.capabilities ) {
var shaderNode = new ShaderNode("Shaders/example_Flower.vsh", "Shaders/example_Flower.fsh");
var shaderNode = new ShaderNode(ccbjs + "Shaders/example_Flower.vsh", ccbjs + "Shaders/example_Flower.fsh");
this.addChild(shaderNode,10);
shaderNode.x = winSize.width/2;
shaderNode.y = winSize.height/2;
@ -826,7 +826,7 @@ var ShaderJuliaTest = OpenGLTestLayer.extend({
if( 'opengl' in cc.sys.capabilities ) {
var shaderNode = new ShaderNode("Shaders/example_Julia.vsh", "Shaders/example_Julia.fsh");
var shaderNode = new ShaderNode(ccbjs + "Shaders/example_Julia.vsh", ccbjs + "Shaders/example_Julia.fsh");
this.addChild(shaderNode,10);
shaderNode.x = winSize.width/2;
shaderNode.y = winSize.height/2;
@ -867,12 +867,12 @@ var ShaderOutlineEffect = OpenGLTestLayer.extend({
if( 'opengl' in cc.sys.capabilities ) {
if(cc.sys.isNative){
this.shader = new cc.GLProgram("Shaders/example_Outline_noMVP.vsh", "Shaders/example_Outline.fsh");
this.shader = new cc.GLProgram(ccbjs + "Shaders/example_Outline_noMVP.vsh", ccbjs + "Shaders/example_Outline.fsh");
this.shader.link();
this.shader.updateUniforms();
}
else{
this.shader = new cc.GLProgram("Shaders/example_Outline.vsh", "Shaders/example_Outline.fsh");
this.shader = new cc.GLProgram(ccbjs + "Shaders/example_Outline.vsh", ccbjs + "Shaders/example_Outline.fsh");
this.shader.addAttribute(cc.ATTRIBUTE_NAME_POSITION, cc.VERTEX_ATTRIB_POSITION);
this.shader.addAttribute(cc.ATTRIBUTE_NAME_TEX_COORD, cc.VERTEX_ATTRIB_TEX_COORDS);
this.shader.addAttribute(cc.ATTRIBUTE_NAME_COLOR, cc.VERTEX_ATTRIB_COLOR);
@ -943,7 +943,7 @@ var ShaderRetroEffect = OpenGLTestLayer.extend({
this._super();
if( 'opengl' in cc.sys.capabilities ) {
var program = new cc.GLProgram("Shaders/example_ColorBars.vsh", "Shaders/example_ColorBars.fsh");
var program = new cc.GLProgram(ccbjs + "Shaders/example_ColorBars.vsh", ccbjs + "Shaders/example_ColorBars.fsh");
program.addAttribute(cc.ATTRIBUTE_NAME_POSITION, cc.VERTEX_ATTRIB_POSITION);
program.addAttribute(cc.ATTRIBUTE_NAME_TEX_COORD, cc.VERTEX_ATTRIB_TEX_COORDS);
program.link();

View File

@ -1,6 +1,12 @@
// Resources prefix
var s_resprefix = "";
var ccbjs = "";
if (!cc.sys.isNative)
{
ccbjs = "../../js-tests/res/";
}
var s_pathGrossini = "Images/grossini.png";
var s_pathSister1 = "Images/grossinis_sister1.png";
var s_pathSister2 = "Images/grossinis_sister2.png";
@ -315,25 +321,25 @@ var g_s9s_blocks = [
var g_opengl_resources = [
//preload shader source
"Shaders/example_Outline.fsh",
"Shaders/example_Outline.vsh",
"Shaders/example_Blur.fsh",
"Shaders/example_ColorBars.fsh",
"Shaders/example_ColorBars.vsh",
"Shaders/example_Flower.fsh",
"Shaders/example_Flower.vsh",
"Shaders/example_Heart.fsh",
"Shaders/example_Heart.vsh",
"Shaders/example_Julia.fsh",
"Shaders/example_Julia.vsh",
"Shaders/example_Mandelbrot.fsh",
"Shaders/example_Mandelbrot.vsh",
"Shaders/example_Monjori.fsh",
"Shaders/example_Monjori.vsh",
"Shaders/example_Plasma.fsh",
"Shaders/example_Plasma.vsh",
"Shaders/example_Twist.fsh",
"Shaders/example_Twist.vsh",
ccbjs + "Shaders/example_Outline.fsh",
ccbjs + "Shaders/example_Outline.vsh",
ccbjs + "Shaders/example_Blur.fsh",
ccbjs + "Shaders/example_ColorBars.fsh",
ccbjs + "Shaders/example_ColorBars.vsh",
ccbjs + "Shaders/example_Flower.fsh",
ccbjs + "Shaders/example_Flower.vsh",
ccbjs + "Shaders/example_Heart.fsh",
ccbjs + "Shaders/example_Heart.vsh",
ccbjs + "Shaders/example_Julia.fsh",
ccbjs + "Shaders/example_Julia.vsh",
ccbjs + "Shaders/example_Mandelbrot.fsh",
ccbjs + "Shaders/example_Mandelbrot.vsh",
ccbjs + "Shaders/example_Monjori.fsh",
ccbjs + "Shaders/example_Monjori.vsh",
ccbjs + "Shaders/example_Plasma.fsh",
ccbjs + "Shaders/example_Plasma.vsh",
ccbjs + "Shaders/example_Twist.fsh",
ccbjs + "Shaders/example_Twist.vsh",
"fonts/west_england-64.fnt",
"fonts/west_england-64.png"
@ -469,11 +475,6 @@ var g_fonts = [
}
];
var ccbjs = "";
if (!cc.sys.isNative)
{
ccbjs = "../../js-tests/res/";
}
var g_extensions = [
s_image_icon,
s_extensions_background,