Fixed setTexture bug with TilingSprite and Fixed SpriteBatch canvas transform bug
This commit is contained in:
parent
818f709764
commit
91b23a130a
6 changed files with 246 additions and 481 deletions
176
bin/pixi.dev.js
176
bin/pixi.dev.js
|
@ -4,7 +4,7 @@
|
|||
* Copyright (c) 2012-2014, Mat Groves
|
||||
* http://goodboydigital.com/
|
||||
*
|
||||
* Compiled: 2014-02-13
|
||||
* Compiled: 2014-02-14
|
||||
*
|
||||
* pixi.js is licensed under the MIT License.
|
||||
* http://www.opensource.org/licenses/mit-license.php
|
||||
|
@ -35,7 +35,7 @@ PIXI.WEBGL_RENDERER = 0;
|
|||
PIXI.CANVAS_RENDERER = 1;
|
||||
|
||||
// useful for testing against if your lib is using pixi.
|
||||
PIXI.VERSION = "v1.4.4";
|
||||
PIXI.VERSION = "v1.5.0";
|
||||
|
||||
// the various blend modes supported by pixi
|
||||
PIXI.blendModes = {
|
||||
|
@ -2053,20 +2053,12 @@ PIXI.SpriteBatch.prototype._renderCanvas = function(renderSession)
|
|||
var context = renderSession.context;
|
||||
context.globalAlpha = this.worldAlpha;
|
||||
|
||||
var transform = this.worldTransform;
|
||||
PIXI.DisplayObject.prototype.updateTransform.call(this);
|
||||
|
||||
var transform = this.worldTransform;
|
||||
// alow for trimming
|
||||
|
||||
if (renderSession.roundPixels)
|
||||
{
|
||||
context.setTransform(transform.a, transform.c, transform.b, transform.d, Math.floor(transform.tx), Math.floor(transform.ty));
|
||||
}
|
||||
else
|
||||
{
|
||||
context.setTransform(transform.a, transform.c, transform.b, transform.d, transform.tx, transform.ty);
|
||||
}
|
||||
|
||||
context.save();
|
||||
var isRotated = true;
|
||||
|
||||
for (var i = 0; i < this.children.length; i++) {
|
||||
|
||||
|
@ -2078,8 +2070,13 @@ PIXI.SpriteBatch.prototype._renderCanvas = function(renderSession)
|
|||
|
||||
if(child.rotation % (Math.PI * 2) === 0)
|
||||
{
|
||||
|
||||
// this is the fastest way to optimise! - if rotation is 0 then we can avoid any kind of setTransform call
|
||||
if(isRotated)
|
||||
{
|
||||
context.setTransform(transform.a, transform.c, transform.b, transform.d, transform.tx, transform.ty);
|
||||
isRotated = false;
|
||||
}
|
||||
|
||||
// this is the fastest way to optimise! - if rotation is 0 then we can avoid any kind of setTransform call
|
||||
context.drawImage(texture.baseTexture.source,
|
||||
frame.x,
|
||||
frame.y,
|
||||
|
@ -2092,24 +2089,23 @@ PIXI.SpriteBatch.prototype._renderCanvas = function(renderSession)
|
|||
}
|
||||
else
|
||||
{
|
||||
if(!isRotated)isRotated = true;
|
||||
|
||||
PIXI.DisplayObject.prototype.updateTransform.call(child);
|
||||
|
||||
transform = child.localTransform;
|
||||
var childTransform = child.worldTransform;
|
||||
|
||||
if(this.rotation !== this.rotationCache)
|
||||
// allow for trimming
|
||||
|
||||
if (renderSession.roundPixels)
|
||||
{
|
||||
this.rotationCache = this.rotation;
|
||||
this._sr = Math.sin(this.rotation);
|
||||
this._cr = Math.cos(this.rotation);
|
||||
context.setTransform(childTransform.a, childTransform.c, childTransform.b, childTransform.d, childTransform.tx || 0, childTransform.ty || 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
context.setTransform(childTransform.a, childTransform.c, childTransform.b, childTransform.d, childTransform.tx, childTransform.ty);
|
||||
}
|
||||
|
||||
var a = child._cr * child.scale.x,
|
||||
b = -child._sr * child.scale.y,
|
||||
c = child._sr * child.scale.x,
|
||||
d = child._cr * child.scale.y;
|
||||
|
||||
context.setTransform(a, c, b, d, child.position.x, child.position.y);
|
||||
|
||||
context.drawImage(texture.baseTexture.source,
|
||||
frame.x,
|
||||
frame.y,
|
||||
|
@ -2119,11 +2115,14 @@ PIXI.SpriteBatch.prototype._renderCanvas = function(renderSession)
|
|||
((child.anchor.y) * (-frame.height) + 0.5) | 0,
|
||||
frame.width,
|
||||
frame.height);
|
||||
|
||||
|
||||
}
|
||||
|
||||
// context.restore();
|
||||
}
|
||||
|
||||
context.restore();
|
||||
// context.restore();
|
||||
};
|
||||
|
||||
|
||||
|
@ -4053,11 +4052,11 @@ PIXI.EventTarget = function () {
|
|||
* @param width=800 {Number} the width of the renderers view
|
||||
* @param height=600 {Number} the height of the renderers view
|
||||
* @param [view] {Canvas} the canvas to use as a view, optional
|
||||
* @param [antialias=false] {Boolean} sets antialias (only applicable in webGL chrome at the moment)
|
||||
* @param [transparent=false] {Boolean} the transparency of the render view, default false
|
||||
* @param [antialias=false] {Boolean} sets antialias (only applicable in webGL chrome at the moment)
|
||||
*
|
||||
*/
|
||||
PIXI.autoDetectRenderer = function(width, height, view,antialias,transparent)
|
||||
PIXI.autoDetectRenderer = function(width, height, view, transparent, antialias)
|
||||
{
|
||||
if(!width)width = 800;
|
||||
if(!height)height = 600;
|
||||
|
@ -9727,6 +9726,36 @@ PIXI.TilingSprite.prototype.onTextureUpdate = function()
|
|||
this.updateFrame = true;
|
||||
};
|
||||
|
||||
PIXI.TilingSprite.prototype.setTexture = function(texture)
|
||||
{
|
||||
if(this.texture === texture)return;
|
||||
|
||||
this.texture = texture;
|
||||
|
||||
this.refreshTexture = true;
|
||||
/*
|
||||
if(this.tilingTexture)
|
||||
{
|
||||
this.generateTilingTexture(true);
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
// stop current texture;
|
||||
if(this.texture.baseTexture !== texture.baseTexture)
|
||||
{
|
||||
this.textureChange = true;
|
||||
this.texture = texture;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.texture = texture;
|
||||
}
|
||||
|
||||
this.updateFrame = true;*/
|
||||
this.cachedTint = 0xFFFFFF;
|
||||
};
|
||||
|
||||
/**
|
||||
* Renders the object using the WebGL renderer
|
||||
*
|
||||
|
@ -9756,7 +9785,7 @@ PIXI.TilingSprite.prototype._renderWebGL = function(renderSession)
|
|||
renderSession.filterManager.pushFilter(this._filterBlock);
|
||||
}
|
||||
|
||||
if(!this.tilingTexture)this.generateTilingTexture(true);
|
||||
if(!this.tilingTexture || this.refreshTexture)this.generateTilingTexture(true);
|
||||
else renderSession.spriteBatch.renderTilingSprite(this);
|
||||
|
||||
// simple render children!
|
||||
|
@ -9774,7 +9803,17 @@ PIXI.TilingSprite.prototype._renderWebGL = function(renderSession)
|
|||
}
|
||||
else
|
||||
{
|
||||
if(!this.tilingTexture)this.generateTilingTexture(true);
|
||||
if(!this.tilingTexture || this.refreshTexture)
|
||||
{
|
||||
this.generateTilingTexture(true);
|
||||
if(this.tilingTexture.needsUpdate)
|
||||
{
|
||||
//TODO - tweaking
|
||||
PIXI.updateWebGLTexture(this.tilingTexture.baseTexture, renderSession.gl);
|
||||
this.tilingTexture.needsUpdate = false;
|
||||
// this.tilingTexture._uvs = null;
|
||||
}
|
||||
}
|
||||
else renderSession.spriteBatch.renderTilingSprite(this);
|
||||
|
||||
// simple render children!
|
||||
|
@ -9813,10 +9852,10 @@ PIXI.TilingSprite.prototype._renderCanvas = function(renderSession)
|
|||
context.setTransform(transform.a, transform.c, transform.b, transform.d, transform.tx, transform.ty);
|
||||
|
||||
|
||||
if(!this.__tilePattern)
|
||||
if(!this.__tilePattern || this.refreshTexture)
|
||||
{
|
||||
this.generateTilingTexture(false);
|
||||
|
||||
|
||||
if(this.tilingTexture)
|
||||
{
|
||||
this.__tilePattern = context.createPattern(this.tilingTexture.baseTexture.source, 'repeat');
|
||||
|
@ -9955,11 +9994,8 @@ PIXI.TilingSprite.prototype.generateTilingTexture = function(forcePowerOfTwo)
|
|||
var targetWidth, targetHeight;
|
||||
|
||||
// check that the frame is the same size as the base texture.
|
||||
|
||||
var isFrame = frame.width !== baseTexture.width || frame.height !== baseTexture.height;
|
||||
|
||||
this.tilingTexture = texture;
|
||||
|
||||
var newTextureRequired = false;
|
||||
|
||||
if(!forcePowerOfTwo)
|
||||
|
@ -9968,39 +10004,69 @@ PIXI.TilingSprite.prototype.generateTilingTexture = function(forcePowerOfTwo)
|
|||
{
|
||||
targetWidth = frame.width;
|
||||
targetHeight = frame.height;
|
||||
|
||||
|
||||
newTextureRequired = true;
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
targetWidth = PIXI.getNextPowerOfTwo(texture.frame.width);
|
||||
targetHeight = PIXI.getNextPowerOfTwo(texture.frame.height);
|
||||
|
||||
targetWidth = PIXI.getNextPowerOfTwo(frame.width);
|
||||
targetHeight = PIXI.getNextPowerOfTwo(frame.height);
|
||||
if(frame.width !== targetWidth && frame.height !== targetHeight)newTextureRequired = true;
|
||||
}
|
||||
|
||||
if(newTextureRequired)
|
||||
{
|
||||
var canvasBuffer = new PIXI.CanvasBuffer(targetWidth, targetHeight);
|
||||
var canvasBuffer;
|
||||
|
||||
if(this.tilingTexture && this.tilingTexture.isTiling)
|
||||
{
|
||||
canvasBuffer = this.tilingTexture.canvasBuffer;
|
||||
canvasBuffer.resize(targetWidth, targetHeight);
|
||||
this.tilingTexture.baseTexture.width = targetWidth;
|
||||
this.tilingTexture.baseTexture.height = targetHeight;
|
||||
this.tilingTexture.needsUpdate = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
canvasBuffer = new PIXI.CanvasBuffer(targetWidth, targetHeight);
|
||||
|
||||
this.tilingTexture = PIXI.Texture.fromCanvas(canvasBuffer.canvas);
|
||||
this.tilingTexture.canvasBuffer = canvasBuffer;
|
||||
this.tilingTexture.isTiling = true;
|
||||
|
||||
}
|
||||
|
||||
canvasBuffer.context.drawImage(texture.baseTexture.source,
|
||||
frame.x,
|
||||
frame.y,
|
||||
frame.width,
|
||||
frame.height,
|
||||
0,
|
||||
0,
|
||||
targetWidth,
|
||||
targetHeight);
|
||||
|
||||
this.tilingTexture = PIXI.Texture.fromCanvas(canvasBuffer.canvas);
|
||||
frame.x,
|
||||
frame.y,
|
||||
frame.width,
|
||||
frame.height,
|
||||
0,
|
||||
0,
|
||||
targetWidth,
|
||||
targetHeight);
|
||||
|
||||
this.tileScaleOffset.x = frame.width / targetWidth;
|
||||
this.tileScaleOffset.y = frame.height / targetHeight;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//TODO - switching?
|
||||
if(this.tilingTexture && this.tilingTexture.isTiling)
|
||||
{
|
||||
// destroy the tiling texture!
|
||||
// TODO could store this somewhere?
|
||||
this.tilingTexture.destroy(true);
|
||||
}
|
||||
|
||||
this.tileScaleOffset.x = 1;
|
||||
this.tileScaleOffset.y = 1;
|
||||
this.tilingTexture = texture;
|
||||
}
|
||||
this.refreshTexture = false;
|
||||
this.tilingTexture.baseTexture._powerOf2 = true;
|
||||
};
|
||||
/**
|
||||
|
@ -11721,6 +11787,8 @@ PIXI.Texture = function(baseTexture, frame)
|
|||
|
||||
this.scope = this;
|
||||
|
||||
this._uvs = null;
|
||||
|
||||
if(baseTexture.hasLoaded)
|
||||
{
|
||||
if(this.noFrame)frame = new PIXI.Rectangle(0,0, baseTexture.width, baseTexture.height);
|
||||
|
|
12
bin/pixi.js
12
bin/pixi.js
File diff suppressed because one or more lines are too long
|
@ -1,371 +0,0 @@
|
|||
|
||||
|
||||
PIXI.ParticleBatch = function(texture)
|
||||
{
|
||||
PIXI.DisplayObjectContainer.call( this);
|
||||
|
||||
this.textureThing = texture;
|
||||
|
||||
this.ready = false;
|
||||
}
|
||||
|
||||
PIXI.ParticleBatch.prototype = Object.create( PIXI.DisplayObjectContainer.prototype );
|
||||
PIXI.ParticleBatch.constructor = PIXI.ParticleBatch;
|
||||
|
||||
PIXI.ParticleBatch.prototype.initWebGL = function(gl)
|
||||
{
|
||||
|
||||
var vecShaderSrc = [
|
||||
|
||||
"attribute vec2 aVertexPosition;",
|
||||
"attribute vec2 aMovement;",
|
||||
"attribute vec2 aTexture;",
|
||||
|
||||
"uniform mat3 translationMatrix;",
|
||||
|
||||
"uniform float time;",
|
||||
// "uniform float pos;",
|
||||
|
||||
"uniform vec2 projectionVector;",
|
||||
"varying vec2 vTextureCoord;",
|
||||
"const float PI = 3.14159265358;",
|
||||
|
||||
"void main(void) {",
|
||||
|
||||
"vec2 v = aVertexPosition;",
|
||||
"float x = aMovement.x * 0.01;",
|
||||
"vec2 scaledVertex = aVertexPosition;",
|
||||
"v.x = (scaledVertex.x) * cos(x) - (scaledVertex.y) * sin(x);",
|
||||
"v.y = (scaledVertex.x) * sin(x) + (scaledVertex.y) * cos(x);",
|
||||
|
||||
//"float pos = p * p * ((this._p1 + 1) * p - this._p1);"
|
||||
|
||||
//"v.y = sin(-time*PI * 2.0) * -aMovement.y;",
|
||||
"v += aMovement;",
|
||||
|
||||
// "v += aVertexPosition;",
|
||||
// "v.y *= 1.0 + smoothstep(time, 0.5, 1.0) * 3.0;",
|
||||
// "v.y += aMovement.y * time + aVertexPosition.y;",
|
||||
// "v.y = time * aMovement.y;;",
|
||||
// "v.y += aVertexPosition.y;",
|
||||
//"v.x += aMovement.x ;",
|
||||
|
||||
// "v.y *= -1.0;",
|
||||
|
||||
"v.x += 1280.0/2.0;",
|
||||
"v.y += 800.0/2.0;",
|
||||
|
||||
|
||||
"gl_Position = vec4( v.x / projectionVector.x -1.0, v.y / projectionVector.y + 1.0 , 0.0, 1.0);",
|
||||
|
||||
// "gl_Position = vec4(aVertexPosition, 0.0, 1.0);",
|
||||
"vTextureCoord = aTexture;",
|
||||
|
||||
"}"
|
||||
|
||||
];
|
||||
|
||||
var fragShaderSrc = [
|
||||
"precision lowp float;",
|
||||
"varying vec2 vTextureCoord;",
|
||||
|
||||
"uniform sampler2D uSampler;",
|
||||
"void main(void) {",
|
||||
"gl_FragColor = texture2D(uSampler, vTextureCoord);",
|
||||
"}"
|
||||
];
|
||||
|
||||
|
||||
|
||||
|
||||
this.program = PIXI.compileProgram(gl, vecShaderSrc, fragShaderSrc)
|
||||
|
||||
gl.useProgram(this.program);
|
||||
|
||||
|
||||
this.translationMatrix = gl.getUniformLocation(this.program, "translationMatrix");
|
||||
this.projectionVector = gl.getUniformLocation(this.program, "projectionVector");
|
||||
this.time = gl.getUniformLocation(this.program, "time");
|
||||
|
||||
|
||||
this.aVertexPosition = gl.getAttribLocation(this.program, "aVertexPosition");
|
||||
this.aMovement = gl.getAttribLocation(this.program, "aMovement");
|
||||
this.aTexture = gl.getAttribLocation(this.program, "aTexture");
|
||||
|
||||
// console.log(":::" + this.aMovement)
|
||||
this.totalItems = 10000;
|
||||
|
||||
|
||||
this.verticies = new Float32Array( this.totalItems * 8 );
|
||||
this.movement = new Float32Array( this.totalItems * 8 );
|
||||
|
||||
this.posData = new Float32Array( this.totalItems * 3 );
|
||||
|
||||
this.texture = new Float32Array( this.totalItems * 8 );
|
||||
|
||||
this.indices = new Uint16Array( this.totalItems * 6);
|
||||
|
||||
for (var i = 0; i < this.totalItems * 8; i+=8) {
|
||||
|
||||
var scale = 1// + Math.random()
|
||||
// position..
|
||||
this.verticies[i] = -20 * scale;
|
||||
this.verticies[i+1] = -20 * scale;
|
||||
|
||||
this.verticies[i+2] = 20 * scale;
|
||||
this.verticies[i+3] = -20 * scale;
|
||||
|
||||
this.verticies[i+4] = 20 * scale;
|
||||
this.verticies[i+5] = 20 * scale;
|
||||
|
||||
this.verticies[i+6] = -20 * scale;
|
||||
this.verticies[i+7] = 20 * scale;
|
||||
};
|
||||
|
||||
var fullWidth = 142;
|
||||
var fullHeight= 157;
|
||||
|
||||
var simpleFrame = new PIXI.Rectangle(0, 0, 142, 157);
|
||||
|
||||
var gemCount = 0;
|
||||
|
||||
for (var i = 0; i < this.totalItems * 8; i+=8) {
|
||||
|
||||
gemCount++
|
||||
var gemFrame = this.texture.frame || simpleFrame;//this.gems[gemCount % this.gems.length].frame;
|
||||
// console.log(gemFrame);
|
||||
// position..
|
||||
|
||||
var xoff = gemFrame.x / fullWidth;
|
||||
var yoff = gemFrame.y / fullHeight;
|
||||
|
||||
this.texture[i] = xoff;
|
||||
this.texture[i+1] = yoff;
|
||||
|
||||
this.texture[i+2] = xoff + gemFrame.width / fullWidth;
|
||||
this.texture[i+3] = yoff;
|
||||
|
||||
this.texture[i+4] = xoff + gemFrame.width / fullWidth;
|
||||
this.texture[i+5] = yoff + gemFrame.height / fullHeight;
|
||||
|
||||
this.texture[i+6] = xoff;
|
||||
this.texture[i+7] = yoff + gemFrame.height / fullHeight;
|
||||
|
||||
|
||||
|
||||
//
|
||||
|
||||
};
|
||||
|
||||
for (var i = 0; i < this.totalItems* 8; i+=8) {
|
||||
|
||||
var pos = 0//Math.random() * 200;
|
||||
|
||||
var angle = Math.random() * Math.PI * 2;
|
||||
|
||||
var speed = (0.3 + Math.random() * 0.9) * 0.01;
|
||||
|
||||
var pos = Math.sin(angle) * speed;//Math.random() * 10 - 5;
|
||||
var posY = Math.cos(angle) * speed;
|
||||
|
||||
var scale = 1;
|
||||
// var posY = 0.5 + Math.random()// * 200
|
||||
|
||||
// console.log(pos);
|
||||
this.movement[i] = pos;
|
||||
this.movement[i+1] = posY;
|
||||
|
||||
this.movement[i+2] = scale;
|
||||
this.movement[i+3] = scale;
|
||||
|
||||
this.movement[i+4] = rotation;
|
||||
|
||||
this.movement[i+5] = scale;
|
||||
|
||||
this.movement[i+2] = pos;
|
||||
this.movement[i+3] = posY;
|
||||
|
||||
this.movement[i+4] = pos;
|
||||
this.movement[i+5] = posY;
|
||||
|
||||
this.movement[i+6] = pos;
|
||||
this.movement[i+7] = posY;
|
||||
}
|
||||
|
||||
this.reset();
|
||||
|
||||
for (var i = 0; i < this.totalItems * 6; i+=6) {
|
||||
|
||||
var i3 = (i / 6) * 4;
|
||||
|
||||
this.indices[i] = i3;
|
||||
this.indices[i+1] = i3+1;
|
||||
this.indices[i+2] = i3+2;
|
||||
this.indices[i+3] = i3;
|
||||
this.indices[i+4] = i3+2;
|
||||
this.indices[i+5] = i3+3;
|
||||
|
||||
}
|
||||
|
||||
// console.log(this);
|
||||
this.vertexBuffer = gl.createBuffer();
|
||||
this.textureBuffer = gl.createBuffer();
|
||||
this.movementBuffer = gl.createBuffer();
|
||||
|
||||
this.indexBuffer = gl.createBuffer();
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
|
||||
gl.bufferData(gl.ARRAY_BUFFER, this.verticies, gl.STATIC_DRAW);
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.textureBuffer);
|
||||
gl.bufferData(gl.ARRAY_BUFFER, this.texture, gl.STATIC_DRAW);
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.movementBuffer);
|
||||
gl.bufferData(gl.ARRAY_BUFFER, this.movement, gl.DYNAMIC_DRAW);
|
||||
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
|
||||
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, this.indices, gl.STATIC_DRAW);
|
||||
|
||||
this.count = 0;
|
||||
this.speed = 18;
|
||||
this.posy = 0;
|
||||
|
||||
this.ready = true;
|
||||
// alert("!")
|
||||
}
|
||||
|
||||
PIXI.ParticleBatch.prototype.addChild = function(child)
|
||||
{
|
||||
PIXI.DisplayObjectContainer.prototype.addChild.call(child);
|
||||
|
||||
|
||||
}
|
||||
|
||||
PIXI.ParticleBatch.prototype.reset = function()
|
||||
{
|
||||
for (var i = 0; i < this.totalItems* 4; i+=4) {
|
||||
|
||||
this.posData[i] = 0; // pos x
|
||||
this.posData[i + 1] = 0; // pos y
|
||||
|
||||
var angle = Math.random() * Math.PI * 2;
|
||||
|
||||
var speed = 10 + Math.random() * 15;
|
||||
|
||||
var pos = Math.sin(angle) * speed;//Math.random() * 10 - 5;
|
||||
var posY = Math.cos(angle) *speed;
|
||||
|
||||
|
||||
this.posData[i + 2] = pos; // speed x
|
||||
this.posData[i + 3] = posY - 10; // speed y
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
PIXI.ParticleBatch.prototype._renderWebGL = function(renderSession)
|
||||
{
|
||||
if(!this.visible)return;
|
||||
|
||||
renderSession.shaderManager.deactivateDefaultShader()
|
||||
if(!this.ready)this.initWebGL( renderSession.gl );
|
||||
|
||||
renderSession.spriteBatch.stop();
|
||||
|
||||
this.speed -= 0.4;
|
||||
|
||||
this.count += this.speed;
|
||||
|
||||
|
||||
var gl = renderSession.gl;
|
||||
var glTexture = this.textureThing.baseTexture._glTextures[gl.id] || PIXI.createWebGLTexture(this.textureThing.baseTexture, gl)
|
||||
|
||||
gl.useProgram(this.program);
|
||||
|
||||
|
||||
gl.enableVertexAttribArray(this.aVertexPosition);
|
||||
gl.enableVertexAttribArray(this.aMovement);
|
||||
gl.enableVertexAttribArray(this.aTexture);
|
||||
|
||||
|
||||
gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
gl.activeTexture(gl.TEXTURE0);
|
||||
gl.bindTexture(gl.TEXTURE_2D, glTexture);
|
||||
|
||||
gl.uniform1f(this.time, this.count);
|
||||
gl.uniform2f(this.projectionVector, renderSession.projection.x, renderSession.projection.y);
|
||||
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
|
||||
gl.vertexAttribPointer(this.aVertexPosition, 2, gl.FLOAT, false, 0, 0);
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.textureBuffer);
|
||||
gl.vertexAttribPointer(this.aTexture, 2, gl.FLOAT, false, 0, 0);
|
||||
|
||||
|
||||
|
||||
for (var i = 0; i < this.totalItems* 8; i+=8) {
|
||||
|
||||
var val = ( i / 8 ) * 4;
|
||||
|
||||
this.posData[val + 3] += 0.02;
|
||||
|
||||
this.posData[val] += this.posData[val + 2];
|
||||
this.posData[val + 1] += this.posData[val + 3];
|
||||
|
||||
var pos = this.posData[val];
|
||||
var posY = this.posData[val + 1];
|
||||
|
||||
//pos += this.posData[val + 2];
|
||||
//posY += this.posData[val + 3];
|
||||
|
||||
this.movement[i] = pos;
|
||||
this.movement[i+1] = posY;
|
||||
|
||||
this.movement[i+2] = pos;
|
||||
this.movement[i+3] = posY;
|
||||
|
||||
this.movement[i+4] = pos;
|
||||
this.movement[i+5] = posY;
|
||||
|
||||
this.movement[i+6] = pos;
|
||||
this.movement[i+7] = posY;
|
||||
}
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.movementBuffer);
|
||||
gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.movement);
|
||||
|
||||
gl.vertexAttribPointer(this.aMovement, 2, gl.FLOAT, false, 0, 0);
|
||||
|
||||
//gl.bindBuffer(gl.ARRAY_BUFFER, this.movementBuffer);
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
|
||||
|
||||
gl.drawElements(gl.TRIANGLES, 6 * this.totalItems , gl.UNSIGNED_SHORT, 0);
|
||||
|
||||
// not sure if both needed? but ya have for now!
|
||||
// override!
|
||||
// disable the current stuff..
|
||||
|
||||
|
||||
// gl.disableVertexAttribArray(PIXI.stripShader.aVertexPosition);
|
||||
//gl.disableVertexAttribArray(PIXI.stripShader.colorAttribute);
|
||||
//gl.disableVertexAttribArray(PIXI.stripShader.aTextureCoord);
|
||||
gl.disableVertexAttribArray(this.aVertexPosition);
|
||||
gl.disableVertexAttribArray(this.aMovement);
|
||||
gl.disableVertexAttribArray(this.aTexture);
|
||||
|
||||
|
||||
renderSession.shaderManager.activateDefaultShader()
|
||||
|
||||
renderSession.spriteBatch.start();
|
||||
/*
|
||||
gl.useProgram(PIXI.defaultShader.program);
|
||||
|
||||
gl.enableVertexAttribArray(PIXI.defaultShader.aVertexPosition);
|
||||
gl.enableVertexAttribArray(PIXI.defaultShader.colorAttribute);
|
||||
gl.enableVertexAttribArray(PIXI.defaultShader.aTextureCoord);
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -99,20 +99,12 @@ PIXI.SpriteBatch.prototype._renderCanvas = function(renderSession)
|
|||
var context = renderSession.context;
|
||||
context.globalAlpha = this.worldAlpha;
|
||||
|
||||
var transform = this.worldTransform;
|
||||
PIXI.DisplayObject.prototype.updateTransform.call(this);
|
||||
|
||||
var transform = this.worldTransform;
|
||||
// alow for trimming
|
||||
|
||||
if (renderSession.roundPixels)
|
||||
{
|
||||
context.setTransform(transform.a, transform.c, transform.b, transform.d, Math.floor(transform.tx), Math.floor(transform.ty));
|
||||
}
|
||||
else
|
||||
{
|
||||
context.setTransform(transform.a, transform.c, transform.b, transform.d, transform.tx, transform.ty);
|
||||
}
|
||||
|
||||
context.save();
|
||||
var isRotated = true;
|
||||
|
||||
for (var i = 0; i < this.children.length; i++) {
|
||||
|
||||
|
@ -124,8 +116,13 @@ PIXI.SpriteBatch.prototype._renderCanvas = function(renderSession)
|
|||
|
||||
if(child.rotation % (Math.PI * 2) === 0)
|
||||
{
|
||||
|
||||
// this is the fastest way to optimise! - if rotation is 0 then we can avoid any kind of setTransform call
|
||||
if(isRotated)
|
||||
{
|
||||
context.setTransform(transform.a, transform.c, transform.b, transform.d, transform.tx, transform.ty);
|
||||
isRotated = false;
|
||||
}
|
||||
|
||||
// this is the fastest way to optimise! - if rotation is 0 then we can avoid any kind of setTransform call
|
||||
context.drawImage(texture.baseTexture.source,
|
||||
frame.x,
|
||||
frame.y,
|
||||
|
@ -138,24 +135,23 @@ PIXI.SpriteBatch.prototype._renderCanvas = function(renderSession)
|
|||
}
|
||||
else
|
||||
{
|
||||
if(!isRotated)isRotated = true;
|
||||
|
||||
PIXI.DisplayObject.prototype.updateTransform.call(child);
|
||||
|
||||
transform = child.localTransform;
|
||||
var childTransform = child.worldTransform;
|
||||
|
||||
if(this.rotation !== this.rotationCache)
|
||||
// allow for trimming
|
||||
|
||||
if (renderSession.roundPixels)
|
||||
{
|
||||
this.rotationCache = this.rotation;
|
||||
this._sr = Math.sin(this.rotation);
|
||||
this._cr = Math.cos(this.rotation);
|
||||
context.setTransform(childTransform.a, childTransform.c, childTransform.b, childTransform.d, childTransform.tx || 0, childTransform.ty || 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
context.setTransform(childTransform.a, childTransform.c, childTransform.b, childTransform.d, childTransform.tx, childTransform.ty);
|
||||
}
|
||||
|
||||
var a = child._cr * child.scale.x,
|
||||
b = -child._sr * child.scale.y,
|
||||
c = child._sr * child.scale.x,
|
||||
d = child._cr * child.scale.y;
|
||||
|
||||
context.setTransform(a, c, b, d, child.position.x, child.position.y);
|
||||
|
||||
context.drawImage(texture.baseTexture.source,
|
||||
frame.x,
|
||||
frame.y,
|
||||
|
@ -165,10 +161,13 @@ PIXI.SpriteBatch.prototype._renderCanvas = function(renderSession)
|
|||
((child.anchor.y) * (-frame.height) + 0.5) | 0,
|
||||
frame.width,
|
||||
frame.height);
|
||||
|
||||
|
||||
}
|
||||
|
||||
// context.restore();
|
||||
}
|
||||
|
||||
context.restore();
|
||||
// context.restore();
|
||||
};
|
||||
|
||||
|
|
|
@ -132,6 +132,36 @@ PIXI.TilingSprite.prototype.onTextureUpdate = function()
|
|||
this.updateFrame = true;
|
||||
};
|
||||
|
||||
PIXI.TilingSprite.prototype.setTexture = function(texture)
|
||||
{
|
||||
if(this.texture === texture)return;
|
||||
|
||||
this.texture = texture;
|
||||
|
||||
this.refreshTexture = true;
|
||||
/*
|
||||
if(this.tilingTexture)
|
||||
{
|
||||
this.generateTilingTexture(true);
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
// stop current texture;
|
||||
if(this.texture.baseTexture !== texture.baseTexture)
|
||||
{
|
||||
this.textureChange = true;
|
||||
this.texture = texture;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.texture = texture;
|
||||
}
|
||||
|
||||
this.updateFrame = true;*/
|
||||
this.cachedTint = 0xFFFFFF;
|
||||
};
|
||||
|
||||
/**
|
||||
* Renders the object using the WebGL renderer
|
||||
*
|
||||
|
@ -161,7 +191,7 @@ PIXI.TilingSprite.prototype._renderWebGL = function(renderSession)
|
|||
renderSession.filterManager.pushFilter(this._filterBlock);
|
||||
}
|
||||
|
||||
if(!this.tilingTexture)this.generateTilingTexture(true);
|
||||
if(!this.tilingTexture || this.refreshTexture)this.generateTilingTexture(true);
|
||||
else renderSession.spriteBatch.renderTilingSprite(this);
|
||||
|
||||
// simple render children!
|
||||
|
@ -179,7 +209,17 @@ PIXI.TilingSprite.prototype._renderWebGL = function(renderSession)
|
|||
}
|
||||
else
|
||||
{
|
||||
if(!this.tilingTexture)this.generateTilingTexture(true);
|
||||
if(!this.tilingTexture || this.refreshTexture)
|
||||
{
|
||||
this.generateTilingTexture(true);
|
||||
if(this.tilingTexture.needsUpdate)
|
||||
{
|
||||
//TODO - tweaking
|
||||
PIXI.updateWebGLTexture(this.tilingTexture.baseTexture, renderSession.gl);
|
||||
this.tilingTexture.needsUpdate = false;
|
||||
// this.tilingTexture._uvs = null;
|
||||
}
|
||||
}
|
||||
else renderSession.spriteBatch.renderTilingSprite(this);
|
||||
|
||||
// simple render children!
|
||||
|
@ -218,10 +258,10 @@ PIXI.TilingSprite.prototype._renderCanvas = function(renderSession)
|
|||
context.setTransform(transform.a, transform.c, transform.b, transform.d, transform.tx, transform.ty);
|
||||
|
||||
|
||||
if(!this.__tilePattern)
|
||||
if(!this.__tilePattern || this.refreshTexture)
|
||||
{
|
||||
this.generateTilingTexture(false);
|
||||
|
||||
|
||||
if(this.tilingTexture)
|
||||
{
|
||||
this.__tilePattern = context.createPattern(this.tilingTexture.baseTexture.source, 'repeat');
|
||||
|
@ -360,11 +400,8 @@ PIXI.TilingSprite.prototype.generateTilingTexture = function(forcePowerOfTwo)
|
|||
var targetWidth, targetHeight;
|
||||
|
||||
// check that the frame is the same size as the base texture.
|
||||
|
||||
var isFrame = frame.width !== baseTexture.width || frame.height !== baseTexture.height;
|
||||
|
||||
this.tilingTexture = texture;
|
||||
|
||||
var newTextureRequired = false;
|
||||
|
||||
if(!forcePowerOfTwo)
|
||||
|
@ -373,38 +410,68 @@ PIXI.TilingSprite.prototype.generateTilingTexture = function(forcePowerOfTwo)
|
|||
{
|
||||
targetWidth = frame.width;
|
||||
targetHeight = frame.height;
|
||||
|
||||
|
||||
newTextureRequired = true;
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
targetWidth = PIXI.getNextPowerOfTwo(texture.frame.width);
|
||||
targetHeight = PIXI.getNextPowerOfTwo(texture.frame.height);
|
||||
|
||||
targetWidth = PIXI.getNextPowerOfTwo(frame.width);
|
||||
targetHeight = PIXI.getNextPowerOfTwo(frame.height);
|
||||
if(frame.width !== targetWidth && frame.height !== targetHeight)newTextureRequired = true;
|
||||
}
|
||||
|
||||
if(newTextureRequired)
|
||||
{
|
||||
var canvasBuffer = new PIXI.CanvasBuffer(targetWidth, targetHeight);
|
||||
var canvasBuffer;
|
||||
|
||||
if(this.tilingTexture && this.tilingTexture.isTiling)
|
||||
{
|
||||
canvasBuffer = this.tilingTexture.canvasBuffer;
|
||||
canvasBuffer.resize(targetWidth, targetHeight);
|
||||
this.tilingTexture.baseTexture.width = targetWidth;
|
||||
this.tilingTexture.baseTexture.height = targetHeight;
|
||||
this.tilingTexture.needsUpdate = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
canvasBuffer = new PIXI.CanvasBuffer(targetWidth, targetHeight);
|
||||
|
||||
this.tilingTexture = PIXI.Texture.fromCanvas(canvasBuffer.canvas);
|
||||
this.tilingTexture.canvasBuffer = canvasBuffer;
|
||||
this.tilingTexture.isTiling = true;
|
||||
|
||||
}
|
||||
|
||||
canvasBuffer.context.drawImage(texture.baseTexture.source,
|
||||
frame.x,
|
||||
frame.y,
|
||||
frame.width,
|
||||
frame.height,
|
||||
0,
|
||||
0,
|
||||
targetWidth,
|
||||
targetHeight);
|
||||
|
||||
this.tilingTexture = PIXI.Texture.fromCanvas(canvasBuffer.canvas);
|
||||
frame.x,
|
||||
frame.y,
|
||||
frame.width,
|
||||
frame.height,
|
||||
0,
|
||||
0,
|
||||
targetWidth,
|
||||
targetHeight);
|
||||
|
||||
this.tileScaleOffset.x = frame.width / targetWidth;
|
||||
this.tileScaleOffset.y = frame.height / targetHeight;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//TODO - switching?
|
||||
if(this.tilingTexture && this.tilingTexture.isTiling)
|
||||
{
|
||||
// destroy the tiling texture!
|
||||
// TODO could store this somewhere?
|
||||
this.tilingTexture.destroy(true);
|
||||
}
|
||||
|
||||
this.tileScaleOffset.x = 1;
|
||||
this.tileScaleOffset.y = 1;
|
||||
this.tilingTexture = texture;
|
||||
}
|
||||
this.refreshTexture = false;
|
||||
this.tilingTexture.baseTexture._powerOf2 = true;
|
||||
};
|
|
@ -56,6 +56,8 @@ PIXI.Texture = function(baseTexture, frame)
|
|||
|
||||
this.scope = this;
|
||||
|
||||
this._uvs = null;
|
||||
|
||||
if(baseTexture.hasLoaded)
|
||||
{
|
||||
if(this.noFrame)frame = new PIXI.Rectangle(0,0, baseTexture.width, baseTexture.height);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue