diff --git a/src/core/renderers/webgl/shaders/Shader.js b/src/core/renderers/webgl/shaders/Shader.js index 6bfc288..84f321f 100644 --- a/src/core/renderers/webgl/shaders/Shader.js +++ b/src/core/renderers/webgl/shaders/Shader.js @@ -47,7 +47,9 @@ } this.attributes = { - aVertexPosition: 0 + aVertexPosition: 0, + aTextureCoord: 0, + aColor: 0 }; for (var a in customAttributes) diff --git a/src/core/renderers/webgl/shaders/Shader.js b/src/core/renderers/webgl/shaders/Shader.js index 6bfc288..84f321f 100644 --- a/src/core/renderers/webgl/shaders/Shader.js +++ b/src/core/renderers/webgl/shaders/Shader.js @@ -47,7 +47,9 @@ } this.attributes = { - aVertexPosition: 0 + aVertexPosition: 0, + aTextureCoord: 0, + aColor: 0 }; for (var a in customAttributes) diff --git a/src/core/sprites/SpriteBatch.js b/src/core/sprites/SpriteBatch.js index ee0d34b..c1e674c 100644 --- a/src/core/sprites/SpriteBatch.js +++ b/src/core/sprites/SpriteBatch.js @@ -68,8 +68,14 @@ // renderer.spriteBatch.start(); - renderer.setObjectRenderer(renderer.plugins.spriteBatch); + renderer.currentRenderer.stop(); + + renderer.shaderManager.setShader(renderer.plugins.spriteBatch.shader); + + renderer.plugins.spriteBatch.start(this); renderer.plugins.spriteBatch.render(this); + + renderer.currentRenderer.start(); }; /** diff --git a/src/core/renderers/webgl/shaders/Shader.js b/src/core/renderers/webgl/shaders/Shader.js index 6bfc288..84f321f 100644 --- a/src/core/renderers/webgl/shaders/Shader.js +++ b/src/core/renderers/webgl/shaders/Shader.js @@ -47,7 +47,9 @@ } this.attributes = { - aVertexPosition: 0 + aVertexPosition: 0, + aTextureCoord: 0, + aColor: 0 }; for (var a in customAttributes) diff --git a/src/core/sprites/SpriteBatch.js b/src/core/sprites/SpriteBatch.js index ee0d34b..c1e674c 100644 --- a/src/core/sprites/SpriteBatch.js +++ b/src/core/sprites/SpriteBatch.js @@ -68,8 +68,14 @@ // renderer.spriteBatch.start(); - renderer.setObjectRenderer(renderer.plugins.spriteBatch); + renderer.currentRenderer.stop(); + + renderer.shaderManager.setShader(renderer.plugins.spriteBatch.shader); + + renderer.plugins.spriteBatch.start(this); renderer.plugins.spriteBatch.render(this); + + renderer.currentRenderer.start(); }; /** diff --git a/src/core/sprites/webgl/SpriteBatchRenderer.js b/src/core/sprites/webgl/SpriteBatchRenderer.js index 1ff4ec6..82a2318 100644 --- a/src/core/sprites/webgl/SpriteBatchRenderer.js +++ b/src/core/sprites/webgl/SpriteBatchRenderer.js @@ -186,9 +186,6 @@ */ SpriteBatchRenderer.prototype.render = function (spriteBatch) { - // set the matrix from the spriteBatch - this.renderer.gl.uniformMatrix3fv(this.shader.uniforms.uMatrix._location, false, spriteBatch.worldTransform.toArray(true)); - var children = spriteBatch.children; var sprite = children[0]; @@ -413,7 +410,7 @@ /** * */ -SpriteBatchRenderer.prototype.start = function () +SpriteBatchRenderer.prototype.start = function (spriteBatch) { var gl = this.renderer.gl; @@ -429,15 +426,19 @@ // gl.uniform2f(this.shader.uniforms.projectionVector._location, projection.x, projection.y); gl.uniformMatrix3fv(this.shader.uniforms.projectionMatrix._location, false, this.renderer.currentRenderTarget.projectionMatrix.toArray(true)); + // set the matrix from the spriteBatch + gl.uniformMatrix3fv(this.shader.uniforms.uMatrix._location, false, spriteBatch.worldTransform.toArray(true)); + // set the pointers - var stride = this.vertByteSize; + var stride = this.vertByteSize; gl.vertexAttribPointer(this.shader.attributes.aVertexPosition, 2, gl.FLOAT, false, stride, 0); - gl.vertexAttribPointer(this.shader.attributes.aPositionCoord, 2, gl.FLOAT, false, stride, 2 * 4); - gl.vertexAttribPointer(this.shader.attributes.aScale, 2, gl.FLOAT, false, stride, 4 * 4); - gl.vertexAttribPointer(this.shader.attributes.aRotation, 1, gl.FLOAT, false, stride, 6 * 4); - gl.vertexAttribPointer(this.shader.attributes.aTextureCoord, 2, gl.FLOAT, false, stride, 7 * 4); - gl.vertexAttribPointer(this.shader.attributes.aColor, 1, gl.FLOAT, false, stride, 9 * 4); + gl.vertexAttribPointer(this.shader.attributes.aTextureCoord, 2, gl.FLOAT, false, stride, 2 * 4); + gl.vertexAttribPointer(this.shader.attributes.aColor, 1, gl.FLOAT, false, stride, 4 * 4); + + gl.vertexAttribPointer(this.shader.attributes.aPositionCoord, 2, gl.FLOAT, false, stride, 5 * 4); + gl.vertexAttribPointer(this.shader.attributes.aScale, 2, gl.FLOAT, false, stride, 7 * 4); + gl.vertexAttribPointer(this.shader.attributes.aRotation, 1, gl.FLOAT, false, stride, 9 * 4); }; /** diff --git a/src/core/renderers/webgl/shaders/Shader.js b/src/core/renderers/webgl/shaders/Shader.js index 6bfc288..84f321f 100644 --- a/src/core/renderers/webgl/shaders/Shader.js +++ b/src/core/renderers/webgl/shaders/Shader.js @@ -47,7 +47,9 @@ } this.attributes = { - aVertexPosition: 0 + aVertexPosition: 0, + aTextureCoord: 0, + aColor: 0 }; for (var a in customAttributes) diff --git a/src/core/sprites/SpriteBatch.js b/src/core/sprites/SpriteBatch.js index ee0d34b..c1e674c 100644 --- a/src/core/sprites/SpriteBatch.js +++ b/src/core/sprites/SpriteBatch.js @@ -68,8 +68,14 @@ // renderer.spriteBatch.start(); - renderer.setObjectRenderer(renderer.plugins.spriteBatch); + renderer.currentRenderer.stop(); + + renderer.shaderManager.setShader(renderer.plugins.spriteBatch.shader); + + renderer.plugins.spriteBatch.start(this); renderer.plugins.spriteBatch.render(this); + + renderer.currentRenderer.start(); }; /** diff --git a/src/core/sprites/webgl/SpriteBatchRenderer.js b/src/core/sprites/webgl/SpriteBatchRenderer.js index 1ff4ec6..82a2318 100644 --- a/src/core/sprites/webgl/SpriteBatchRenderer.js +++ b/src/core/sprites/webgl/SpriteBatchRenderer.js @@ -186,9 +186,6 @@ */ SpriteBatchRenderer.prototype.render = function (spriteBatch) { - // set the matrix from the spriteBatch - this.renderer.gl.uniformMatrix3fv(this.shader.uniforms.uMatrix._location, false, spriteBatch.worldTransform.toArray(true)); - var children = spriteBatch.children; var sprite = children[0]; @@ -413,7 +410,7 @@ /** * */ -SpriteBatchRenderer.prototype.start = function () +SpriteBatchRenderer.prototype.start = function (spriteBatch) { var gl = this.renderer.gl; @@ -429,15 +426,19 @@ // gl.uniform2f(this.shader.uniforms.projectionVector._location, projection.x, projection.y); gl.uniformMatrix3fv(this.shader.uniforms.projectionMatrix._location, false, this.renderer.currentRenderTarget.projectionMatrix.toArray(true)); + // set the matrix from the spriteBatch + gl.uniformMatrix3fv(this.shader.uniforms.uMatrix._location, false, spriteBatch.worldTransform.toArray(true)); + // set the pointers - var stride = this.vertByteSize; + var stride = this.vertByteSize; gl.vertexAttribPointer(this.shader.attributes.aVertexPosition, 2, gl.FLOAT, false, stride, 0); - gl.vertexAttribPointer(this.shader.attributes.aPositionCoord, 2, gl.FLOAT, false, stride, 2 * 4); - gl.vertexAttribPointer(this.shader.attributes.aScale, 2, gl.FLOAT, false, stride, 4 * 4); - gl.vertexAttribPointer(this.shader.attributes.aRotation, 1, gl.FLOAT, false, stride, 6 * 4); - gl.vertexAttribPointer(this.shader.attributes.aTextureCoord, 2, gl.FLOAT, false, stride, 7 * 4); - gl.vertexAttribPointer(this.shader.attributes.aColor, 1, gl.FLOAT, false, stride, 9 * 4); + gl.vertexAttribPointer(this.shader.attributes.aTextureCoord, 2, gl.FLOAT, false, stride, 2 * 4); + gl.vertexAttribPointer(this.shader.attributes.aColor, 1, gl.FLOAT, false, stride, 4 * 4); + + gl.vertexAttribPointer(this.shader.attributes.aPositionCoord, 2, gl.FLOAT, false, stride, 5 * 4); + gl.vertexAttribPointer(this.shader.attributes.aScale, 2, gl.FLOAT, false, stride, 7 * 4); + gl.vertexAttribPointer(this.shader.attributes.aRotation, 1, gl.FLOAT, false, stride, 9 * 4); }; /** diff --git a/src/core/sprites/webgl/SpriteBatchShader.js b/src/core/sprites/webgl/SpriteBatchShader.js index 6adce5b..1f53252 100644 --- a/src/core/sprites/webgl/SpriteBatchShader.js +++ b/src/core/sprites/webgl/SpriteBatchShader.js @@ -6,7 +6,7 @@ * @namespace PIXI * @param shaderManager {WebGLShaderManager} The webgl shader manager this shader works for. */ -function FastShader(shaderManager) +function SpriteBatchShader(shaderManager) { Shader.call(this, shaderManager, @@ -22,13 +22,13 @@ 'uniform mat3 projectionMatrix;', // 'uniform vec2 projectionVector;', - 'uniform vec2 offsetVector;', + // 'uniform vec2 offsetVector;', 'uniform mat3 uMatrix;', 'varying vec2 vTextureCoord;', 'varying float vColor;', - 'const vec2 center = vec2(-1.0, 1.0);', + // 'const vec2 center = vec2(-1.0, 1.0);', 'void main(void){', ' vec2 v;', @@ -39,8 +39,7 @@ // ' gl_Position = vec4( ( v / projectionVector) + center , 0.0, 1.0);', - // ' gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);', - ' gl_Position = vec4((v / projectionMatrix[0].xy) + center, 0.0, 1.0);', + ' gl_Position = vec4((projectionMatrix * vec3(v, 1.0)).xy, 0.0, 1.0);', ' vTextureCoord = aTextureCoord;', @@ -68,12 +67,12 @@ // custom attributes { aPositionCoord: 0, - aRotation: 0, - aScale: 0 + aScale: 0, + aRotation: 0 } ); } -FastShader.prototype = Object.create(Shader.prototype); -FastShader.prototype.constructor = FastShader; -module.exports = FastShader; +SpriteBatchShader.prototype = Object.create(Shader.prototype); +SpriteBatchShader.prototype.constructor = SpriteBatchShader; +module.exports = SpriteBatchShader;