diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 807b85b..6b95180 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -162,7 +162,9 @@ */ this._renderTargetStack = []; - + this._activShader = null; + this._activeTextureLocation = null; + this._activeTexture = null; } // constructor @@ -374,6 +376,21 @@ } }; +WebGLRenderer.prototype.bindShader = function (shader)//projection, buffer) +{ + //TODO cache + if(this._activShader !== shader) + { + this._activShader = shader; + + shader.bind(); + + // automatically set the projection matrix + shader.uniforms.projectionMatrix = this.currentRenderTarget.projectionMatrix.toArray(true); + } +} + + WebGLRenderer.prototype.bindTexture = function (texture, location) { var gl = this.gl; diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 807b85b..6b95180 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -162,7 +162,9 @@ */ this._renderTargetStack = []; - + this._activShader = null; + this._activeTextureLocation = null; + this._activeTexture = null; } // constructor @@ -374,6 +376,21 @@ } }; +WebGLRenderer.prototype.bindShader = function (shader)//projection, buffer) +{ + //TODO cache + if(this._activShader !== shader) + { + this._activShader = shader; + + shader.bind(); + + // automatically set the projection matrix + shader.uniforms.projectionMatrix = this.currentRenderTarget.projectionMatrix.toArray(true); + } +} + + WebGLRenderer.prototype.bindTexture = function (texture, location) { var gl = this.gl; diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index e483a7f..8795d01 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -305,12 +305,12 @@ if (this.currentBatchSize > ( this.size * 0.5 ) ) { // gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.vertices); - this.vertexBuffer.upload(this.vertices); + this.vertexBuffer.upload(this.vertices, 0, true); } else { var view = this.positions.subarray(0, this.currentBatchSize * this.vertByteSize); - this.vertexBuffer.upload(view); + this.vertexBuffer.upload(view, 0, true); } var nextTexture, nextBlendMode, nextShader; @@ -368,10 +368,10 @@ // set shader function??? // this.renderer.shaderManager.setShader(shader); - this._shader.bind(); + this.renderer.bindShader(this._shader); //gl.enableVertexAttribArray(1); - this._shader.uniforms.projectionMatrix = this.renderer.currentRenderTarget.projectionMatrix.toArray(true); + //this._shader.uniforms.projectionMatrix = this.renderer.currentRenderTarget.projectionMatrix.toArray(true); //TODO - i KNOW this can be optimised! Once v3 is stable il look at this next... // shader.uniforms.projectionMatrix.value = this.renderer.currentRenderTarget.projectionMatrix.toArray(true); @@ -380,7 +380,7 @@ //TODO investigate some kind of texture state managment?? // need to make sure this texture is the active one for all the batch swaps.. - gl.activeTexture(gl.TEXTURE0); + // gl.activeTexture(gl.TEXTURE0); } }