Fixing cachAsBitmap functionality
This commit is contained in:
parent
44330fa419
commit
8658124a4b
4 changed files with 43 additions and 37 deletions
|
@ -182,6 +182,7 @@ PIXI.DisplayObject = function()
|
|||
this._mask = null;
|
||||
|
||||
this._cacheAsBitmap = false;
|
||||
this._cacheIsDirty = false;
|
||||
/*
|
||||
* MOUSE Callbacks
|
||||
*/
|
||||
|
@ -377,6 +378,7 @@ Object.defineProperty(PIXI.DisplayObject.prototype, 'cacheAsBitmap', {
|
|||
|
||||
if(value)
|
||||
{
|
||||
//this._cacheIsDirty = true;
|
||||
this._generateCachedSprite();
|
||||
}
|
||||
else
|
||||
|
@ -470,11 +472,12 @@ PIXI.DisplayObject.prototype.generateTexture = function(renderer)
|
|||
|
||||
PIXI.DisplayObject.prototype._renderCachedSprite = function(renderSession)
|
||||
{
|
||||
if(this.dirty)
|
||||
// console.log(this._cacheIsDirty)
|
||||
/* if(this._cacheIsDirty)
|
||||
{
|
||||
this._generateCachedSprite();
|
||||
this.dirty = false;
|
||||
}
|
||||
//this._generateCachedSprite(renderSession)
|
||||
//this._cacheIsDirty = false;a
|
||||
}*/
|
||||
|
||||
if(renderSession.gl)
|
||||
{
|
||||
|
@ -486,15 +489,14 @@ PIXI.DisplayObject.prototype._renderCachedSprite = function(renderSession)
|
|||
}
|
||||
};
|
||||
|
||||
PIXI.DisplayObject.prototype._generateCachedSprite = function(renderer)
|
||||
PIXI.DisplayObject.prototype._generateCachedSprite = function()//renderSession)
|
||||
{
|
||||
this._cacheAsBitmap = false;
|
||||
var bounds = this.getLocalBounds();
|
||||
// console.log(bounds.width);
|
||||
// console.log(bounds )
|
||||
// console.log("generate sprite " + this._cachedSprite)
|
||||
|
||||
if(!this._cachedSprite)
|
||||
{
|
||||
var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0, renderer);
|
||||
var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0);//, renderSession.renderer);
|
||||
|
||||
this._cachedSprite = new PIXI.Sprite(renderTexture);
|
||||
this._cachedSprite.worldTransform = this.worldTransform;
|
||||
|
@ -504,13 +506,17 @@ PIXI.DisplayObject.prototype._generateCachedSprite = function(renderer)
|
|||
this._cachedSprite.texture.resize(bounds.width | 0, bounds.height | 0);
|
||||
}
|
||||
|
||||
|
||||
this._cachedSprite.texture.render(this);
|
||||
// document.body.appendChild(renderTexture.baseTexture.source)
|
||||
// this._cachedSprite.buffer.context.restore();
|
||||
|
||||
|
||||
this._cacheAsBitmap = true;
|
||||
};
|
||||
|
||||
PIXI.DisplayObject.prototype._destroyCachedSprite = function()
|
||||
{
|
||||
if(!this._cachedSprite)return;
|
||||
|
||||
this._cachedSprite.texture.destroy(true);
|
||||
// console.log("DESTROY")
|
||||
// let the gc collect the unused sprite
|
||||
|
|
|
@ -77,17 +77,7 @@ PIXI.Graphics = function()
|
|||
PIXI.Graphics.prototype = Object.create( PIXI.DisplayObjectContainer.prototype );
|
||||
PIXI.Graphics.prototype.constructor = PIXI.Graphics;
|
||||
|
||||
/**
|
||||
* If cacheAsBitmap is true the graphics object will then be rendered as if it was a sprite.
|
||||
* This is useful if your graphics element does not change often as it will speed up the rendering of the object
|
||||
* It is also usful as the graphics object will always be antialiased because it will be rendered using canvas
|
||||
* Not recommended if you are constanly redrawing the graphics element.
|
||||
*
|
||||
* @property cacheAsBitmap
|
||||
* @default false
|
||||
* @type Boolean
|
||||
* @private
|
||||
*/
|
||||
/*
|
||||
Object.defineProperty(PIXI.Graphics.prototype, "cacheAsBitmap", {
|
||||
get: function() {
|
||||
return this._cacheAsBitmap;
|
||||
|
@ -106,7 +96,7 @@ Object.defineProperty(PIXI.Graphics.prototype, "cacheAsBitmap", {
|
|||
}
|
||||
|
||||
}
|
||||
});
|
||||
});*/
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -117,7 +117,7 @@ PIXI.WebGLRenderer = function(width, height, view, transparent, antialias)
|
|||
this.renderSession.maskManager = this.maskManager;
|
||||
this.renderSession.filterManager = this.filterManager;
|
||||
this.renderSession.spriteBatch = this.spriteBatch;
|
||||
|
||||
this.renderSession.renderer = this;
|
||||
|
||||
gl.useProgram(this.shaderManager.defaultShader.program);
|
||||
|
||||
|
@ -156,6 +156,18 @@ PIXI.WebGLRenderer.prototype.render = function(stage)
|
|||
// update the scene graph
|
||||
stage.updateTransform();
|
||||
|
||||
|
||||
// interaction
|
||||
if(stage._interactive)
|
||||
{
|
||||
//need to add some events!
|
||||
if(!stage._interactiveEventsAdded)
|
||||
{
|
||||
stage._interactiveEventsAdded = true;
|
||||
stage.interactionManager.setTarget(this);
|
||||
}
|
||||
}
|
||||
|
||||
var gl = this.gl;
|
||||
|
||||
// -- Does this need to be set every frame? -- //
|
||||
|
@ -182,16 +194,7 @@ PIXI.WebGLRenderer.prototype.render = function(stage)
|
|||
|
||||
this.renderDisplayObject( stage, this.projection );
|
||||
|
||||
// interaction
|
||||
if(stage._interactive)
|
||||
{
|
||||
//need to add some events!
|
||||
if(!stage._interactiveEventsAdded)
|
||||
{
|
||||
stage._interactiveEventsAdded = true;
|
||||
stage.interactionManager.setTarget(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
//can simulate context loss in Chrome like so:
|
||||
|
@ -226,7 +229,7 @@ PIXI.WebGLRenderer.prototype.renderDisplayObject = function(displayObject, proje
|
|||
|
||||
// start the sprite batch
|
||||
this.spriteBatch.begin(this.renderSession);
|
||||
|
||||
|
||||
// start the filter manager
|
||||
this.filterManager.begin(this.renderSession, buffer);
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ PIXI.WebGLFilterManager.prototype.begin = function(renderSession, buffer)
|
|||
this.defaultShader = renderSession.shaderManager.defaultShader;
|
||||
|
||||
var projection = this.renderSession.projection;
|
||||
|
||||
// console.log(this.width)
|
||||
this.width = projection.x * 2;
|
||||
this.height = -projection.y * 2;
|
||||
this.buffer = buffer;
|
||||
|
@ -159,6 +159,7 @@ PIXI.WebGLFilterManager.prototype.popFilter = function()
|
|||
var inputTexture = texture;
|
||||
var outputTexture = this.texturePool.pop();
|
||||
if(!outputTexture)outputTexture = new PIXI.FilterTexture(this.gl, this.width, this.height);
|
||||
outputTexture.resize(this.width, this.height);
|
||||
|
||||
// need to clear this FBO as it may have some left over elements from a previous filter.
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, outputTexture.frameBuffer );
|
||||
|
@ -209,7 +210,7 @@ PIXI.WebGLFilterManager.prototype.popFilter = function()
|
|||
// time to render the filters texture to the previous scene
|
||||
if(this.filterStack.length === 0)
|
||||
{
|
||||
gl.colorMask(true, true, true, this.transparent);
|
||||
gl.colorMask(true, true, true, true);//this.transparent);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -266,7 +267,12 @@ PIXI.WebGLFilterManager.prototype.popFilter = function()
|
|||
|
||||
gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.uvArray);
|
||||
|
||||
//console.log(this.vertexArray)
|
||||
//console.log(this.uvArray)
|
||||
//console.log(sizeX + " : " + sizeY)
|
||||
|
||||
gl.viewport(0, 0, sizeX, sizeY);
|
||||
|
||||
// bind the buffer
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, buffer );
|
||||
|
||||
|
@ -324,6 +330,7 @@ PIXI.WebGLFilterManager.prototype.applyFilterPass = function(filter, filterArea,
|
|||
// console.log(this.vertexArray[5])
|
||||
}
|
||||
|
||||
// console.log(this.uvArray )
|
||||
shader.syncUniforms();
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue