diff --git a/src/pixi/extras/Strip.js b/src/pixi/extras/Strip.js index ebed079..c2b5d44 100644 --- a/src/pixi/extras/Strip.js +++ b/src/pixi/extras/Strip.js @@ -139,8 +139,17 @@ gl.vertexAttribPointer(shader.aTextureCoord, 2, gl.FLOAT, false, 0, 0); gl.activeTexture(gl.TEXTURE0); - // bind the current texture - gl.bindTexture(gl.TEXTURE_2D, this.texture.baseTexture._glTextures[gl.id] || renderSession.renderer.updateTexture(this.texture.baseTexture, gl)); + + // check if a texture is dirty.. + if(this.texture.baseTexture._dirty[gl.id]) + { + this.renderSession.renderer.updateTexture(this.texture.baseTexture); + } + else + { + // bind the current texture + gl.bindTexture(gl.TEXTURE_2D, this.texture.baseTexture._glTextures[gl.id]); + } // dont need to upload! gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer); @@ -161,7 +170,16 @@ gl.vertexAttribPointer(shader.aTextureCoord, 2, gl.FLOAT, false, 0, 0); gl.activeTexture(gl.TEXTURE0); - gl.bindTexture(gl.TEXTURE_2D, this.texture.baseTexture._glTextures[gl.id] || renderSession.renderer.updateTexture(this.texture.baseTexture, gl)); + + // check if a texture is dirty.. + if(this.texture.baseTexture._dirty[gl.id]) + { + this.renderSession.renderer.updateTexture(this.texture.baseTexture); + } + else + { + gl.bindTexture(gl.TEXTURE_2D, this.texture.baseTexture._glTextures[gl.id]); + } // dont need to upload! gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer); diff --git a/src/pixi/extras/Strip.js b/src/pixi/extras/Strip.js index ebed079..c2b5d44 100644 --- a/src/pixi/extras/Strip.js +++ b/src/pixi/extras/Strip.js @@ -139,8 +139,17 @@ gl.vertexAttribPointer(shader.aTextureCoord, 2, gl.FLOAT, false, 0, 0); gl.activeTexture(gl.TEXTURE0); - // bind the current texture - gl.bindTexture(gl.TEXTURE_2D, this.texture.baseTexture._glTextures[gl.id] || renderSession.renderer.updateTexture(this.texture.baseTexture, gl)); + + // check if a texture is dirty.. + if(this.texture.baseTexture._dirty[gl.id]) + { + this.renderSession.renderer.updateTexture(this.texture.baseTexture); + } + else + { + // bind the current texture + gl.bindTexture(gl.TEXTURE_2D, this.texture.baseTexture._glTextures[gl.id]); + } // dont need to upload! gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer); @@ -161,7 +170,16 @@ gl.vertexAttribPointer(shader.aTextureCoord, 2, gl.FLOAT, false, 0, 0); gl.activeTexture(gl.TEXTURE0); - gl.bindTexture(gl.TEXTURE_2D, this.texture.baseTexture._glTextures[gl.id] || renderSession.renderer.updateTexture(this.texture.baseTexture, gl)); + + // check if a texture is dirty.. + if(this.texture.baseTexture._dirty[gl.id]) + { + this.renderSession.renderer.updateTexture(this.texture.baseTexture); + } + else + { + gl.bindTexture(gl.TEXTURE_2D, this.texture.baseTexture._glTextures[gl.id]); + } // dont need to upload! gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer); diff --git a/src/pixi/renderers/webgl/WebGLRenderer.js b/src/pixi/renderers/webgl/WebGLRenderer.js index 0be1910..4fef08c 100644 --- a/src/pixi/renderers/webgl/WebGLRenderer.js +++ b/src/pixi/renderers/webgl/WebGLRenderer.js @@ -117,12 +117,12 @@ this.offset = new PIXI.Point(0, 0); // time to create the render managers! each one focuses on managine a state in webGL - this.shaderManager = new PIXI.WebGLShaderManager(); // deals with managing the shader programs and their attribs - this.spriteBatch = new PIXI.WebGLSpriteBatch(); // manages the rendering of sprites - this.maskManager = new PIXI.WebGLMaskManager(); // manages the masks using the stencil buffer - this.filterManager = new PIXI.WebGLFilterManager(); // manages the filters - this.stencilManager = new PIXI.WebGLStencilManager(); - this.blendModeManager = new PIXI.WebGLBlendModeManager(); + this.shaderManager = new PIXI.WebGLShaderManager(); // deals with managing the shader programs and their attribs + this.spriteBatch = new PIXI.WebGLSpriteBatch(); // manages the rendering of sprites + this.maskManager = new PIXI.WebGLMaskManager(); // manages the masks using the stencil buffer + this.filterManager = new PIXI.WebGLFilterManager(); // manages the filters + this.stencilManager = new PIXI.WebGLStencilManager(); // manages the stencil buffer + this.blendModeManager = new PIXI.WebGLBlendModeManager(); // manages the blendModes // TODO remove this.renderSession = {}; @@ -140,6 +140,7 @@ // time init the context.. this.initContext(); + // map some webGL blend modes.. this.mapBlendModes(); }; @@ -165,7 +166,7 @@ gl.disable(gl.CULL_FACE); gl.enable(gl.BLEND); - // need to set the context... + // need to set the context for all the managers... this.shaderManager.setContext(gl); this.spriteBatch.setContext(gl); this.maskManager.setContext(gl); @@ -188,9 +189,9 @@ */ PIXI.WebGLRenderer.prototype.render = function(stage) { + // no point rendering if our context has been blown up! if(this.contextLost)return; - // if rendering a new stage clear the batches.. if(this.__stage !== stage) { @@ -207,8 +208,7 @@ var gl = this.gl; - // -- Does this need to be set every frame? -- // - + // interaction if(stage._interactive) { @@ -228,6 +228,7 @@ } } + // -- Does this need to be set every frame? -- // gl.viewport(0, 0, this.width, this.height); // make sure we are bound to the main frame buffer @@ -296,8 +297,8 @@ this.view.width = this.width; this.view.height = this.height; - this.view.style.width = width + 'px'; - this.view.style.height = height + 'px'; + // this.view.style.width = width + 'px'; + // this.view.style.height = height + 'px'; // console.log(this.width / this.resolution) this.gl.viewport(0, 0, this.width, this.height); @@ -321,9 +322,10 @@ if(!texture._glTextures[gl.id])texture._glTextures[gl.id] = gl.createTexture(); gl.bindTexture(gl.TEXTURE_2D, texture._glTextures[gl.id]); - gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultipliedAlpha); + gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultipliedAlpha); gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture.source); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, texture.scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, texture.scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST); @@ -339,8 +341,6 @@ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT); } - gl.bindTexture(gl.TEXTURE_2D, null); - texture._dirty[gl.id] = false; return texture._glTextures[gl.id]; diff --git a/src/pixi/extras/Strip.js b/src/pixi/extras/Strip.js index ebed079..c2b5d44 100644 --- a/src/pixi/extras/Strip.js +++ b/src/pixi/extras/Strip.js @@ -139,8 +139,17 @@ gl.vertexAttribPointer(shader.aTextureCoord, 2, gl.FLOAT, false, 0, 0); gl.activeTexture(gl.TEXTURE0); - // bind the current texture - gl.bindTexture(gl.TEXTURE_2D, this.texture.baseTexture._glTextures[gl.id] || renderSession.renderer.updateTexture(this.texture.baseTexture, gl)); + + // check if a texture is dirty.. + if(this.texture.baseTexture._dirty[gl.id]) + { + this.renderSession.renderer.updateTexture(this.texture.baseTexture); + } + else + { + // bind the current texture + gl.bindTexture(gl.TEXTURE_2D, this.texture.baseTexture._glTextures[gl.id]); + } // dont need to upload! gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer); @@ -161,7 +170,16 @@ gl.vertexAttribPointer(shader.aTextureCoord, 2, gl.FLOAT, false, 0, 0); gl.activeTexture(gl.TEXTURE0); - gl.bindTexture(gl.TEXTURE_2D, this.texture.baseTexture._glTextures[gl.id] || renderSession.renderer.updateTexture(this.texture.baseTexture, gl)); + + // check if a texture is dirty.. + if(this.texture.baseTexture._dirty[gl.id]) + { + this.renderSession.renderer.updateTexture(this.texture.baseTexture); + } + else + { + gl.bindTexture(gl.TEXTURE_2D, this.texture.baseTexture._glTextures[gl.id]); + } // dont need to upload! gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer); diff --git a/src/pixi/renderers/webgl/WebGLRenderer.js b/src/pixi/renderers/webgl/WebGLRenderer.js index 0be1910..4fef08c 100644 --- a/src/pixi/renderers/webgl/WebGLRenderer.js +++ b/src/pixi/renderers/webgl/WebGLRenderer.js @@ -117,12 +117,12 @@ this.offset = new PIXI.Point(0, 0); // time to create the render managers! each one focuses on managine a state in webGL - this.shaderManager = new PIXI.WebGLShaderManager(); // deals with managing the shader programs and their attribs - this.spriteBatch = new PIXI.WebGLSpriteBatch(); // manages the rendering of sprites - this.maskManager = new PIXI.WebGLMaskManager(); // manages the masks using the stencil buffer - this.filterManager = new PIXI.WebGLFilterManager(); // manages the filters - this.stencilManager = new PIXI.WebGLStencilManager(); - this.blendModeManager = new PIXI.WebGLBlendModeManager(); + this.shaderManager = new PIXI.WebGLShaderManager(); // deals with managing the shader programs and their attribs + this.spriteBatch = new PIXI.WebGLSpriteBatch(); // manages the rendering of sprites + this.maskManager = new PIXI.WebGLMaskManager(); // manages the masks using the stencil buffer + this.filterManager = new PIXI.WebGLFilterManager(); // manages the filters + this.stencilManager = new PIXI.WebGLStencilManager(); // manages the stencil buffer + this.blendModeManager = new PIXI.WebGLBlendModeManager(); // manages the blendModes // TODO remove this.renderSession = {}; @@ -140,6 +140,7 @@ // time init the context.. this.initContext(); + // map some webGL blend modes.. this.mapBlendModes(); }; @@ -165,7 +166,7 @@ gl.disable(gl.CULL_FACE); gl.enable(gl.BLEND); - // need to set the context... + // need to set the context for all the managers... this.shaderManager.setContext(gl); this.spriteBatch.setContext(gl); this.maskManager.setContext(gl); @@ -188,9 +189,9 @@ */ PIXI.WebGLRenderer.prototype.render = function(stage) { + // no point rendering if our context has been blown up! if(this.contextLost)return; - // if rendering a new stage clear the batches.. if(this.__stage !== stage) { @@ -207,8 +208,7 @@ var gl = this.gl; - // -- Does this need to be set every frame? -- // - + // interaction if(stage._interactive) { @@ -228,6 +228,7 @@ } } + // -- Does this need to be set every frame? -- // gl.viewport(0, 0, this.width, this.height); // make sure we are bound to the main frame buffer @@ -296,8 +297,8 @@ this.view.width = this.width; this.view.height = this.height; - this.view.style.width = width + 'px'; - this.view.style.height = height + 'px'; + // this.view.style.width = width + 'px'; + // this.view.style.height = height + 'px'; // console.log(this.width / this.resolution) this.gl.viewport(0, 0, this.width, this.height); @@ -321,9 +322,10 @@ if(!texture._glTextures[gl.id])texture._glTextures[gl.id] = gl.createTexture(); gl.bindTexture(gl.TEXTURE_2D, texture._glTextures[gl.id]); - gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultipliedAlpha); + gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultipliedAlpha); gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture.source); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, texture.scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, texture.scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST); @@ -339,8 +341,6 @@ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT); } - gl.bindTexture(gl.TEXTURE_2D, null); - texture._dirty[gl.id] = false; return texture._glTextures[gl.id]; diff --git a/src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js b/src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js index c6aba1d..c9fcedd 100755 --- a/src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js +++ b/src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js @@ -412,7 +412,6 @@ gl.vertexAttribPointer(this.shader.aVertexPosition, 2, gl.FLOAT, false, stride, 0); gl.vertexAttribPointer(this.shader.aTextureCoord, 2, gl.FLOAT, false, stride, 2 * 4); gl.vertexAttribPointer(this.shader.colorAttribute, 2, gl.FLOAT, false, stride, 4 * 4); - } // upload the verts to the buffer @@ -439,7 +438,7 @@ nextTexture = this.textures[i]; nextBlendMode = this.blendModes[i]; blendSwap = currentBlendMode !== nextBlendMode; - + if(currentBaseTexture !== nextTexture || blendSwap) { this.renderBatch(currentBaseTexture, batchSize, start); @@ -466,14 +465,18 @@ if(size === 0)return; var gl = this.gl; - // bind the current texture - gl.bindTexture(gl.TEXTURE_2D, texture._glTextures[gl.id] || this.renderSession.renderer.updateTexture(texture)); // check if a texture is dirty.. if(texture._dirty[gl.id]) { this.renderSession.renderer.updateTexture(texture); } + else + { + // bind the current texture + gl.bindTexture(gl.TEXTURE_2D, texture._glTextures[gl.id]); + } + // now draw those suckas! gl.drawElements(gl.TRIANGLES, size * 6, gl.UNSIGNED_SHORT, startIndex * 6 * 2); @@ -490,6 +493,7 @@ PIXI.WebGLSpriteBatch.prototype.stop = function() { this.flush(); + this.dirty = true; }; /** diff --git a/src/pixi/extras/Strip.js b/src/pixi/extras/Strip.js index ebed079..c2b5d44 100644 --- a/src/pixi/extras/Strip.js +++ b/src/pixi/extras/Strip.js @@ -139,8 +139,17 @@ gl.vertexAttribPointer(shader.aTextureCoord, 2, gl.FLOAT, false, 0, 0); gl.activeTexture(gl.TEXTURE0); - // bind the current texture - gl.bindTexture(gl.TEXTURE_2D, this.texture.baseTexture._glTextures[gl.id] || renderSession.renderer.updateTexture(this.texture.baseTexture, gl)); + + // check if a texture is dirty.. + if(this.texture.baseTexture._dirty[gl.id]) + { + this.renderSession.renderer.updateTexture(this.texture.baseTexture); + } + else + { + // bind the current texture + gl.bindTexture(gl.TEXTURE_2D, this.texture.baseTexture._glTextures[gl.id]); + } // dont need to upload! gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer); @@ -161,7 +170,16 @@ gl.vertexAttribPointer(shader.aTextureCoord, 2, gl.FLOAT, false, 0, 0); gl.activeTexture(gl.TEXTURE0); - gl.bindTexture(gl.TEXTURE_2D, this.texture.baseTexture._glTextures[gl.id] || renderSession.renderer.updateTexture(this.texture.baseTexture, gl)); + + // check if a texture is dirty.. + if(this.texture.baseTexture._dirty[gl.id]) + { + this.renderSession.renderer.updateTexture(this.texture.baseTexture); + } + else + { + gl.bindTexture(gl.TEXTURE_2D, this.texture.baseTexture._glTextures[gl.id]); + } // dont need to upload! gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer); diff --git a/src/pixi/renderers/webgl/WebGLRenderer.js b/src/pixi/renderers/webgl/WebGLRenderer.js index 0be1910..4fef08c 100644 --- a/src/pixi/renderers/webgl/WebGLRenderer.js +++ b/src/pixi/renderers/webgl/WebGLRenderer.js @@ -117,12 +117,12 @@ this.offset = new PIXI.Point(0, 0); // time to create the render managers! each one focuses on managine a state in webGL - this.shaderManager = new PIXI.WebGLShaderManager(); // deals with managing the shader programs and their attribs - this.spriteBatch = new PIXI.WebGLSpriteBatch(); // manages the rendering of sprites - this.maskManager = new PIXI.WebGLMaskManager(); // manages the masks using the stencil buffer - this.filterManager = new PIXI.WebGLFilterManager(); // manages the filters - this.stencilManager = new PIXI.WebGLStencilManager(); - this.blendModeManager = new PIXI.WebGLBlendModeManager(); + this.shaderManager = new PIXI.WebGLShaderManager(); // deals with managing the shader programs and their attribs + this.spriteBatch = new PIXI.WebGLSpriteBatch(); // manages the rendering of sprites + this.maskManager = new PIXI.WebGLMaskManager(); // manages the masks using the stencil buffer + this.filterManager = new PIXI.WebGLFilterManager(); // manages the filters + this.stencilManager = new PIXI.WebGLStencilManager(); // manages the stencil buffer + this.blendModeManager = new PIXI.WebGLBlendModeManager(); // manages the blendModes // TODO remove this.renderSession = {}; @@ -140,6 +140,7 @@ // time init the context.. this.initContext(); + // map some webGL blend modes.. this.mapBlendModes(); }; @@ -165,7 +166,7 @@ gl.disable(gl.CULL_FACE); gl.enable(gl.BLEND); - // need to set the context... + // need to set the context for all the managers... this.shaderManager.setContext(gl); this.spriteBatch.setContext(gl); this.maskManager.setContext(gl); @@ -188,9 +189,9 @@ */ PIXI.WebGLRenderer.prototype.render = function(stage) { + // no point rendering if our context has been blown up! if(this.contextLost)return; - // if rendering a new stage clear the batches.. if(this.__stage !== stage) { @@ -207,8 +208,7 @@ var gl = this.gl; - // -- Does this need to be set every frame? -- // - + // interaction if(stage._interactive) { @@ -228,6 +228,7 @@ } } + // -- Does this need to be set every frame? -- // gl.viewport(0, 0, this.width, this.height); // make sure we are bound to the main frame buffer @@ -296,8 +297,8 @@ this.view.width = this.width; this.view.height = this.height; - this.view.style.width = width + 'px'; - this.view.style.height = height + 'px'; + // this.view.style.width = width + 'px'; + // this.view.style.height = height + 'px'; // console.log(this.width / this.resolution) this.gl.viewport(0, 0, this.width, this.height); @@ -321,9 +322,10 @@ if(!texture._glTextures[gl.id])texture._glTextures[gl.id] = gl.createTexture(); gl.bindTexture(gl.TEXTURE_2D, texture._glTextures[gl.id]); - gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultipliedAlpha); + gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultipliedAlpha); gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture.source); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, texture.scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, texture.scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST); @@ -339,8 +341,6 @@ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT); } - gl.bindTexture(gl.TEXTURE_2D, null); - texture._dirty[gl.id] = false; return texture._glTextures[gl.id]; diff --git a/src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js b/src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js index c6aba1d..c9fcedd 100755 --- a/src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js +++ b/src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js @@ -412,7 +412,6 @@ gl.vertexAttribPointer(this.shader.aVertexPosition, 2, gl.FLOAT, false, stride, 0); gl.vertexAttribPointer(this.shader.aTextureCoord, 2, gl.FLOAT, false, stride, 2 * 4); gl.vertexAttribPointer(this.shader.colorAttribute, 2, gl.FLOAT, false, stride, 4 * 4); - } // upload the verts to the buffer @@ -439,7 +438,7 @@ nextTexture = this.textures[i]; nextBlendMode = this.blendModes[i]; blendSwap = currentBlendMode !== nextBlendMode; - + if(currentBaseTexture !== nextTexture || blendSwap) { this.renderBatch(currentBaseTexture, batchSize, start); @@ -466,14 +465,18 @@ if(size === 0)return; var gl = this.gl; - // bind the current texture - gl.bindTexture(gl.TEXTURE_2D, texture._glTextures[gl.id] || this.renderSession.renderer.updateTexture(texture)); // check if a texture is dirty.. if(texture._dirty[gl.id]) { this.renderSession.renderer.updateTexture(texture); } + else + { + // bind the current texture + gl.bindTexture(gl.TEXTURE_2D, texture._glTextures[gl.id]); + } + // now draw those suckas! gl.drawElements(gl.TRIANGLES, size * 6, gl.UNSIGNED_SHORT, startIndex * 6 * 2); @@ -490,6 +493,7 @@ PIXI.WebGLSpriteBatch.prototype.stop = function() { this.flush(); + this.dirty = true; }; /** diff --git a/src/pixi/textures/BaseTexture.js b/src/pixi/textures/BaseTexture.js index 3e35ef7..ed2705f 100644 --- a/src/pixi/textures/BaseTexture.js +++ b/src/pixi/textures/BaseTexture.js @@ -85,9 +85,10 @@ // used for webGL this._glTextures = []; - // used for webGL texture updating... - this._dirty = []; + // TODO - this needs to be addressed + this._dirty = [true, true, true, true]; + if(!source)return; @@ -96,6 +97,7 @@ this.hasLoaded = true; this.width = this.source.naturalWidth || this.source.width; this.height = this.source.naturalHeight || this.source.height; + this.dirty(); } else {