Merge pull request #84 from Jephery/master
Consolidated shader compilers
This commit is contained in:
commit
cd29c475dc
1 changed files with 42 additions and 57 deletions
|
@ -2,68 +2,53 @@
|
||||||
/**
|
/**
|
||||||
* @author Mat Groves http://matgroves.com/ @Doormat23
|
* @author Mat Groves http://matgroves.com/ @Doormat23
|
||||||
*/
|
*/
|
||||||
|
|
||||||
PIXI.shaderFragmentSrc = [ "precision mediump float;",
|
|
||||||
"varying vec2 vTextureCoord;",
|
|
||||||
"varying float vColor;",
|
|
||||||
"uniform sampler2D uSampler;",
|
|
||||||
"void main(void) {",
|
|
||||||
"gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y));",
|
|
||||||
"gl_FragColor = gl_FragColor * vColor;",
|
|
||||||
"}"];
|
|
||||||
|
|
||||||
PIXI.shaderVertexSrc = [ "attribute vec2 aVertexPosition;",
|
PIXI.shaderFragmentSrc = [
|
||||||
"attribute vec2 aTextureCoord;",
|
"precision mediump float;",
|
||||||
"attribute float aColor;",
|
"varying vec2 vTextureCoord;",
|
||||||
"uniform mat4 uMVMatrix;",
|
"varying float vColor;",
|
||||||
"varying vec2 vTextureCoord;",
|
"uniform sampler2D uSampler;",
|
||||||
"varying float vColor;",
|
"void main(void) {",
|
||||||
"void main(void) {",
|
"gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y));",
|
||||||
"gl_Position = uMVMatrix * vec4(aVertexPosition, 1.0, 1.0);",
|
"gl_FragColor = gl_FragColor * vColor;",
|
||||||
"vTextureCoord = aTextureCoord;",
|
"}"
|
||||||
"vColor = aColor;",
|
];
|
||||||
"}"]
|
|
||||||
|
PIXI.shaderVertexSrc = [
|
||||||
|
"attribute vec2 aVertexPosition;",
|
||||||
|
"attribute vec2 aTextureCoord;",
|
||||||
|
"attribute float aColor;",
|
||||||
|
"uniform mat4 uMVMatrix;",
|
||||||
|
"varying vec2 vTextureCoord;",
|
||||||
|
"varying float vColor;",
|
||||||
|
"void main(void) {",
|
||||||
|
"gl_Position = uMVMatrix * vec4(aVertexPosition, 1.0, 1.0);",
|
||||||
|
"vTextureCoord = aTextureCoord;",
|
||||||
|
"vColor = aColor;",
|
||||||
|
"}"
|
||||||
|
];
|
||||||
|
|
||||||
PIXI.CompileVertexShader = function(gl, shaderSrc)
|
PIXI.CompileVertexShader = function(gl, shaderSrc)
|
||||||
{
|
{
|
||||||
var src = "";
|
return PIXI._CompileShader(gl, shaderSrc, gl.VERTEX_SHADER);
|
||||||
|
|
||||||
for (var i=0; i < shaderSrc.length; i++) {
|
|
||||||
src += shaderSrc[i];
|
|
||||||
};
|
|
||||||
|
|
||||||
var shader;
|
|
||||||
shader = gl.createShader(gl.VERTEX_SHADER);
|
|
||||||
|
|
||||||
gl.shaderSource(shader, src);
|
|
||||||
gl.compileShader(shader);
|
|
||||||
|
|
||||||
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
|
||||||
alert(gl.getShaderInfoLog(shader));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return shader;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PIXI.CompileFragmentShader = function(gl, shaderSrc)
|
PIXI.CompileFragmentShader = function(gl, shaderSrc)
|
||||||
{
|
{
|
||||||
var src = "";
|
return PIXI._CompileShader(gl, shaderSrc, gl.FRAGMENT_SHADER);
|
||||||
|
}
|
||||||
for (var i=0; i < shaderSrc.length; i++) {
|
|
||||||
src += shaderSrc[i];
|
PIXI._CompileShader = function(gl, shaderSrc, shaderType)
|
||||||
};
|
{
|
||||||
|
var src = shaderSrc.join("\n");
|
||||||
var shader;
|
var shader = gl.createShader(shaderType);
|
||||||
shader = gl.createShader(gl.FRAGMENT_SHADER);
|
gl.shaderSource(shader, src);
|
||||||
|
gl.compileShader(shader);
|
||||||
gl.shaderSource(shader, src);
|
|
||||||
gl.compileShader(shader);
|
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
||||||
|
alert(gl.getShaderInfoLog(shader));
|
||||||
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
return null;
|
||||||
alert(gl.getShaderInfoLog(shader));
|
}
|
||||||
return null;
|
|
||||||
}
|
return shader;
|
||||||
|
}
|
||||||
return shader;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue