Added fromCanvas to base texture
added destroy function to webGLRenderer (WIP)
This commit is contained in:
parent
6e27b116e7
commit
8fa1f20eb2
5 changed files with 190 additions and 30 deletions
110
bin/pixi.dev.js
110
bin/pixi.dev.js
|
@ -5247,8 +5247,12 @@ PIXI.WebGLRenderer = function(width, height, view, transparent, antialias)
|
||||||
|
|
||||||
// deal with losing context..
|
// deal with losing context..
|
||||||
var scope = this;
|
var scope = this;
|
||||||
this.view.addEventListener('webglcontextlost', function(event) { scope.handleContextLost(event); }, false);
|
|
||||||
this.view.addEventListener('webglcontextrestored', function(event) { scope.handleContextRestored(event); }, false);
|
this.contextLost = this.handleContextLost.bind(this);
|
||||||
|
this.contextRestoredLost = this.handleContextRestored.bind(this);
|
||||||
|
// console.log(this.handleContextRestored)
|
||||||
|
this.view.addEventListener('webglcontextlost', this.contextLost, false);
|
||||||
|
this.view.addEventListener('webglcontextrestored', this.contextRestoredLost, false);
|
||||||
|
|
||||||
this.options = {
|
this.options = {
|
||||||
alpha: this.transparent,
|
alpha: this.transparent,
|
||||||
|
@ -5657,6 +5661,33 @@ PIXI.WebGLRenderer.prototype.handleContextRestored = function()
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PIXI.WebGLRenderer.prototype.destroy = function()
|
||||||
|
{
|
||||||
|
|
||||||
|
// deal with losing context..
|
||||||
|
var scope = this;
|
||||||
|
|
||||||
|
// remove listeners
|
||||||
|
this.view.removeEventListener('webglcontextlost', this.contextLost);
|
||||||
|
this.view.removeEventListener('webglcontextrestored', this.contextRestoredLost);
|
||||||
|
|
||||||
|
PIXI.glContexts[this.glContextId] = null;
|
||||||
|
|
||||||
|
this.projection = null;
|
||||||
|
this.offset = null;
|
||||||
|
|
||||||
|
// time to create the render managers! each one focuses on managine a state in webGL
|
||||||
|
// this.shaderManager.destroy();
|
||||||
|
// this.spriteBatch.destroy();
|
||||||
|
// this.maskManager.destroy();
|
||||||
|
this.filterManager.destroy();
|
||||||
|
|
||||||
|
this.gl = null;
|
||||||
|
//
|
||||||
|
this.renderSession = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
PIXI.WebGLRenderer.glContextId = 0;
|
PIXI.WebGLRenderer.glContextId = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -7006,6 +7037,28 @@ PIXI.WebGLFilterManager.prototype.initShaderBuffers = function()
|
||||||
gl.STATIC_DRAW);
|
gl.STATIC_DRAW);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PIXI.WebGLFilterManager.prototype.destroy = function()
|
||||||
|
{
|
||||||
|
var gl = this.gl;
|
||||||
|
|
||||||
|
this.filterStack = null
|
||||||
|
|
||||||
|
this.offsetX = 0;
|
||||||
|
this.offsetY = 0;
|
||||||
|
|
||||||
|
// destroy textures
|
||||||
|
for (var i = 0; i < this.texturePool.length; i++) {
|
||||||
|
this.texturePool.destroy();
|
||||||
|
};
|
||||||
|
this.texturePool = null;
|
||||||
|
|
||||||
|
//destroy buffers..
|
||||||
|
gl.deleteBuffer(this.vertexBuffer);
|
||||||
|
gl.deleteBuffer(this.uvBuffer);
|
||||||
|
gl.deleteBuffer(this.colorBuffer);
|
||||||
|
gl.deleteBuffer(this.indexBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
PIXI.FilterTexture = function(gl, width, height)
|
PIXI.FilterTexture = function(gl, width, height)
|
||||||
{
|
{
|
||||||
this.gl = gl;
|
this.gl = gl;
|
||||||
|
@ -7049,6 +7102,17 @@ PIXI.FilterTexture.prototype.resize = function(width, height)
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PIXI.FilterTexture.prototype.destroy = function()
|
||||||
|
{
|
||||||
|
var gl = this.gl;
|
||||||
|
gl.deleteFramebuffer( this.frameBuffer );
|
||||||
|
gl.deleteTexture( this.texture );
|
||||||
|
|
||||||
|
this.frameBuffer = null;
|
||||||
|
this.texture = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mat Groves
|
* @author Mat Groves
|
||||||
*
|
*
|
||||||
|
@ -10474,6 +10538,8 @@ PIXI.BaseTextureCache = {};
|
||||||
PIXI.texturesToUpdate = [];
|
PIXI.texturesToUpdate = [];
|
||||||
PIXI.texturesToDestroy = [];
|
PIXI.texturesToDestroy = [];
|
||||||
|
|
||||||
|
PIXI.BaseTextureCacheIdGenerator = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A texture stores the information that represents an image. All textures have a base texture
|
* A texture stores the information that represents an image. All textures have a base texture
|
||||||
*
|
*
|
||||||
|
@ -10570,6 +10636,8 @@ PIXI.BaseTexture = function(source, scaleMode)
|
||||||
this.imageUrl = null;
|
this.imageUrl = null;
|
||||||
this._powerOf2 = false;
|
this._powerOf2 = false;
|
||||||
|
|
||||||
|
//TODO will be used for futer pixi 1.5...
|
||||||
|
this.id = PIXI.BaseTextureCacheIdGenerator++;
|
||||||
|
|
||||||
// used for webGL
|
// used for webGL
|
||||||
this._glTextures = [];
|
this._glTextures = [];
|
||||||
|
@ -10639,6 +10707,27 @@ PIXI.BaseTexture.fromImage = function(imageUrl, crossorigin, scaleMode)
|
||||||
return baseTexture;
|
return baseTexture;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PIXI.BaseTexture.fromCanvas = function(canvas, scaleMode)
|
||||||
|
{
|
||||||
|
if(!canvas._pixiId)
|
||||||
|
{
|
||||||
|
canvas._pixiId = "canvas_" + PIXI.TextureCacheIdGenerator++;
|
||||||
|
}
|
||||||
|
|
||||||
|
var baseTexture = PIXI.BaseTextureCache[canvas._pixiId];
|
||||||
|
|
||||||
|
if(!baseTexture)
|
||||||
|
{
|
||||||
|
var baseTexture = new PIXI.BaseTexture(canvas, scaleMode);
|
||||||
|
baseTexture = new PIXI.Texture(baseTexture);
|
||||||
|
PIXI.BaseTextureCache[canvas._pixiId] = baseTexture;
|
||||||
|
}
|
||||||
|
|
||||||
|
return baseTexture;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mat Groves http://matgroves.com/ @Doormat23
|
* @author Mat Groves http://matgroves.com/ @Doormat23
|
||||||
*/
|
*/
|
||||||
|
@ -10762,6 +10851,8 @@ PIXI.Texture.prototype.setFrame = function(frame)
|
||||||
this.updateFrame = true;
|
this.updateFrame = true;
|
||||||
|
|
||||||
PIXI.Texture.frameUpdates.push(this);
|
PIXI.Texture.frameUpdates.push(this);
|
||||||
|
|
||||||
|
|
||||||
//this.dispatchEvent( { type: 'update', content: this } );
|
//this.dispatchEvent( { type: 'update', content: this } );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -10836,21 +10927,10 @@ PIXI.Texture.fromFrame = function(frameId)
|
||||||
*/
|
*/
|
||||||
PIXI.Texture.fromCanvas = function(canvas, scaleMode)
|
PIXI.Texture.fromCanvas = function(canvas, scaleMode)
|
||||||
{
|
{
|
||||||
if(!canvas._pixiId)
|
var baseTexture = PIXI.BaseTexture.fromCanvas(canvas, scaleMode);
|
||||||
{
|
|
||||||
canvas._pixiId = "canvas_" + PIXI.TextureCacheIdGenerator++;
|
|
||||||
}
|
|
||||||
|
|
||||||
var texture = PIXI.TextureCache[canvas._pixiId];
|
return new PIXI.Texture( baseTexture );
|
||||||
|
|
||||||
if(!texture)
|
|
||||||
{
|
|
||||||
var baseTexture = new PIXI.BaseTexture(canvas, scaleMode);
|
|
||||||
texture = new PIXI.Texture(baseTexture);
|
|
||||||
PIXI.TextureCache[canvas._pixiId] = texture;
|
|
||||||
}
|
|
||||||
|
|
||||||
return texture;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -37,8 +37,12 @@ PIXI.WebGLRenderer = function(width, height, view, transparent, antialias)
|
||||||
|
|
||||||
// deal with losing context..
|
// deal with losing context..
|
||||||
var scope = this;
|
var scope = this;
|
||||||
this.view.addEventListener('webglcontextlost', function(event) { scope.handleContextLost(event); }, false);
|
|
||||||
this.view.addEventListener('webglcontextrestored', function(event) { scope.handleContextRestored(event); }, false);
|
this.contextLost = this.handleContextLost.bind(this);
|
||||||
|
this.contextRestoredLost = this.handleContextRestored.bind(this);
|
||||||
|
// console.log(this.handleContextRestored)
|
||||||
|
this.view.addEventListener('webglcontextlost', this.contextLost, false);
|
||||||
|
this.view.addEventListener('webglcontextrestored', this.contextRestoredLost, false);
|
||||||
|
|
||||||
this.options = {
|
this.options = {
|
||||||
alpha: this.transparent,
|
alpha: this.transparent,
|
||||||
|
@ -447,4 +451,31 @@ PIXI.WebGLRenderer.prototype.handleContextRestored = function()
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PIXI.WebGLRenderer.prototype.destroy = function()
|
||||||
|
{
|
||||||
|
|
||||||
|
// deal with losing context..
|
||||||
|
var scope = this;
|
||||||
|
|
||||||
|
// remove listeners
|
||||||
|
this.view.removeEventListener('webglcontextlost', this.contextLost);
|
||||||
|
this.view.removeEventListener('webglcontextrestored', this.contextRestoredLost);
|
||||||
|
|
||||||
|
PIXI.glContexts[this.glContextId] = null;
|
||||||
|
|
||||||
|
this.projection = null;
|
||||||
|
this.offset = null;
|
||||||
|
|
||||||
|
// time to create the render managers! each one focuses on managine a state in webGL
|
||||||
|
// this.shaderManager.destroy();
|
||||||
|
// this.spriteBatch.destroy();
|
||||||
|
// this.maskManager.destroy();
|
||||||
|
this.filterManager.destroy();
|
||||||
|
|
||||||
|
this.gl = null;
|
||||||
|
//
|
||||||
|
this.renderSession = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
PIXI.WebGLRenderer.glContextId = 0;
|
PIXI.WebGLRenderer.glContextId = 0;
|
||||||
|
|
|
@ -399,6 +399,28 @@ PIXI.WebGLFilterManager.prototype.initShaderBuffers = function()
|
||||||
gl.STATIC_DRAW);
|
gl.STATIC_DRAW);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PIXI.WebGLFilterManager.prototype.destroy = function()
|
||||||
|
{
|
||||||
|
var gl = this.gl;
|
||||||
|
|
||||||
|
this.filterStack = null
|
||||||
|
|
||||||
|
this.offsetX = 0;
|
||||||
|
this.offsetY = 0;
|
||||||
|
|
||||||
|
// destroy textures
|
||||||
|
for (var i = 0; i < this.texturePool.length; i++) {
|
||||||
|
this.texturePool.destroy();
|
||||||
|
};
|
||||||
|
this.texturePool = null;
|
||||||
|
|
||||||
|
//destroy buffers..
|
||||||
|
gl.deleteBuffer(this.vertexBuffer);
|
||||||
|
gl.deleteBuffer(this.uvBuffer);
|
||||||
|
gl.deleteBuffer(this.colorBuffer);
|
||||||
|
gl.deleteBuffer(this.indexBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
PIXI.FilterTexture = function(gl, width, height)
|
PIXI.FilterTexture = function(gl, width, height)
|
||||||
{
|
{
|
||||||
this.gl = gl;
|
this.gl = gl;
|
||||||
|
@ -441,3 +463,14 @@ PIXI.FilterTexture.prototype.resize = function(width, height)
|
||||||
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
|
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PIXI.FilterTexture.prototype.destroy = function()
|
||||||
|
{
|
||||||
|
var gl = this.gl;
|
||||||
|
gl.deleteFramebuffer( this.frameBuffer );
|
||||||
|
gl.deleteTexture( this.texture );
|
||||||
|
|
||||||
|
this.frameBuffer = null;
|
||||||
|
this.texture = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@ PIXI.BaseTextureCache = {};
|
||||||
PIXI.texturesToUpdate = [];
|
PIXI.texturesToUpdate = [];
|
||||||
PIXI.texturesToDestroy = [];
|
PIXI.texturesToDestroy = [];
|
||||||
|
|
||||||
|
PIXI.BaseTextureCacheIdGenerator = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A texture stores the information that represents an image. All textures have a base texture
|
* A texture stores the information that represents an image. All textures have a base texture
|
||||||
*
|
*
|
||||||
|
@ -102,6 +104,8 @@ PIXI.BaseTexture = function(source, scaleMode)
|
||||||
this.imageUrl = null;
|
this.imageUrl = null;
|
||||||
this._powerOf2 = false;
|
this._powerOf2 = false;
|
||||||
|
|
||||||
|
//TODO will be used for futer pixi 1.5...
|
||||||
|
this.id = PIXI.BaseTextureCacheIdGenerator++;
|
||||||
|
|
||||||
// used for webGL
|
// used for webGL
|
||||||
this._glTextures = [];
|
this._glTextures = [];
|
||||||
|
@ -170,3 +174,24 @@ PIXI.BaseTexture.fromImage = function(imageUrl, crossorigin, scaleMode)
|
||||||
|
|
||||||
return baseTexture;
|
return baseTexture;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PIXI.BaseTexture.fromCanvas = function(canvas, scaleMode)
|
||||||
|
{
|
||||||
|
if(!canvas._pixiId)
|
||||||
|
{
|
||||||
|
canvas._pixiId = "canvas_" + PIXI.TextureCacheIdGenerator++;
|
||||||
|
}
|
||||||
|
|
||||||
|
var baseTexture = PIXI.BaseTextureCache[canvas._pixiId];
|
||||||
|
|
||||||
|
if(!baseTexture)
|
||||||
|
{
|
||||||
|
var baseTexture = new PIXI.BaseTexture(canvas, scaleMode);
|
||||||
|
baseTexture = new PIXI.Texture(baseTexture);
|
||||||
|
PIXI.BaseTextureCache[canvas._pixiId] = baseTexture;
|
||||||
|
}
|
||||||
|
|
||||||
|
return baseTexture;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -121,6 +121,8 @@ PIXI.Texture.prototype.setFrame = function(frame)
|
||||||
this.updateFrame = true;
|
this.updateFrame = true;
|
||||||
|
|
||||||
PIXI.Texture.frameUpdates.push(this);
|
PIXI.Texture.frameUpdates.push(this);
|
||||||
|
|
||||||
|
|
||||||
//this.dispatchEvent( { type: 'update', content: this } );
|
//this.dispatchEvent( { type: 'update', content: this } );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -195,21 +197,10 @@ PIXI.Texture.fromFrame = function(frameId)
|
||||||
*/
|
*/
|
||||||
PIXI.Texture.fromCanvas = function(canvas, scaleMode)
|
PIXI.Texture.fromCanvas = function(canvas, scaleMode)
|
||||||
{
|
{
|
||||||
if(!canvas._pixiId)
|
var baseTexture = PIXI.BaseTexture.fromCanvas(canvas, scaleMode);
|
||||||
{
|
|
||||||
canvas._pixiId = "canvas_" + PIXI.TextureCacheIdGenerator++;
|
|
||||||
}
|
|
||||||
|
|
||||||
var texture = PIXI.TextureCache[canvas._pixiId];
|
return new PIXI.Texture( baseTexture );
|
||||||
|
|
||||||
if(!texture)
|
|
||||||
{
|
|
||||||
var baseTexture = new PIXI.BaseTexture(canvas, scaleMode);
|
|
||||||
texture = new PIXI.Texture(baseTexture);
|
|
||||||
PIXI.TextureCache[canvas._pixiId] = texture;
|
|
||||||
}
|
|
||||||
|
|
||||||
return texture;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue