Render Texture added

Render texture finished
custom render item added
pivot added to display object

grunt file updated
docs updated
This commit is contained in:
Mat Groves 2013-05-23 22:57:27 +01:00
parent 6a049c788e
commit 2a6169a952
94 changed files with 13380 additions and 4464 deletions

View file

@ -51,6 +51,8 @@
<li><a href="..&#x2F;classes/CanvasRenderer.html">CanvasRenderer</a></li>
<li><a href="..&#x2F;classes/CustomRenderable.html">CustomRenderable</a></li>
<li><a href="..&#x2F;classes/DisplayObject.html">DisplayObject</a></li>
<li><a href="..&#x2F;classes/DisplayObjectContainer.html">DisplayObjectContainer</a></li>
@ -201,11 +203,10 @@ PIXI.WebGLRenderer = function(width, height, view, transparent)
gl.colorMask(true, true, true, this.transparent);
this.projectionMatrix = PIXI.mat4.create();
this.resize(this.width, this.height)
this.resize(this.width, this.height);
this.contextLost = false;
this.stageRenderGroup = new PIXI.WebGLRenderGroup(this.gl);
}
&#x2F;&#x2F; constructor
@ -245,9 +246,9 @@ PIXI.WebGLRenderer.prototype.initShaders = function()
var fragmentShader = PIXI.CompileFragmentShader(gl, PIXI.shaderFragmentSrc);
var vertexShader = PIXI.CompileVertexShader(gl, PIXI.shaderVertexSrc);
this.shaderProgram = gl.createProgram();
PIXI.shaderProgram = gl.createProgram();
var shaderProgram = this.shaderProgram;
var shaderProgram = PIXI.shaderProgram;
gl.attachShader(shaderProgram, vertexShader);
gl.attachShader(shaderProgram, fragmentShader);
@ -271,8 +272,6 @@ PIXI.WebGLRenderer.prototype.initShaders = function()
shaderProgram.mvMatrixUniform = gl.getUniformLocation(shaderProgram, &quot;uMVMatrix&quot;);
shaderProgram.samplerUniform = gl.getUniformLocation(shaderProgram, &quot;uSampler&quot;);
PIXI.shaderProgram = this.shaderProgram;
}
@ -290,27 +289,29 @@ PIXI.WebGLRenderer.prototype.render = function(stage)
if(this.__stage !== stage)
{
&#x2F;&#x2F; TODO make this work
if(this.__stage)this.checkVisibility(this.__stage, false)
&#x2F;&#x2F; dont think this is needed any more?
&#x2F;&#x2F;if(this.__stage)this.checkVisibility(this.__stage, false)
this.__stage = stage;
this.stageRenderGroup.setRenderable(stage);
}
&#x2F;&#x2F; TODO not needed now...
&#x2F;&#x2F; update children if need be
&#x2F;&#x2F; best to remove first!
for (var i=0; i &lt; stage.__childrenRemoved.length; i++)
&#x2F;*for (var i=0; i &lt; stage.__childrenRemoved.length; i++)
{
var group = stage.__childrenRemoved[i].__renderGroup
if(group)group.removeDisplayObject(stage.__childrenRemoved[i]);
}
}*&#x2F;
&#x2F;&#x2F; update any textures
for (var i=0; i &lt; PIXI.texturesToUpdate.length; i++) this.updateTexture(PIXI.texturesToUpdate[i]);
for (var i=0; i &lt; PIXI.texturesToDestroy.length; i++) this.destroyTexture(PIXI.texturesToDestroy[i]);
&#x2F;&#x2F; empty out the arrays
stage.__childrenRemoved = [];
stage.__childrenAdded = [];
&#x2F;&#x2F;stage.__childrenRemoved = [];
&#x2F;&#x2F;stage.__childrenAdded = [];
PIXI.texturesToUpdate = [];
PIXI.texturesToDestroy = [];
@ -327,7 +328,7 @@ PIXI.WebGLRenderer.prototype.render = function(stage)
gl.viewport(0, 0, this.width, this.height);
&#x2F;&#x2F; set the correct matrix..
gl.uniformMatrix4fv(this.shaderProgram.mvMatrixUniform, false, this.projectionMatrix);
&#x2F;&#x2F; gl.uniformMatrix4fv(this.shaderProgram.mvMatrixUniform, false, this.projectionMatrix);
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
@ -335,9 +336,8 @@ PIXI.WebGLRenderer.prototype.render = function(stage)
gl.clear(gl.COLOR_BUFFER_BIT);
&#x2F;&#x2F; render all the batchs!
this.stageRenderGroup.backgroundColor = stage.backgroundColorSplit;
this.stageRenderGroup.render();
this.stageRenderGroup.render(this.projectionMatrix);
&#x2F;&#x2F; interaction
&#x2F;&#x2F; run interaction!
@ -386,8 +386,6 @@ PIXI.WebGLRenderer.prototype.updateTexture = function(texture)
&#x2F;&#x2F; reguler...
&#x2F;&#x2F;gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
&#x2F;&#x2F;gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
if(!texture._powerOf2)
{
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
@ -399,7 +397,6 @@ PIXI.WebGLRenderer.prototype.updateTexture = function(texture)
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
}
&#x2F;&#x2F; gl.generateMipmap(gl.TEXTURE_2D);
gl.bindTexture(gl.TEXTURE_2D, null);
}
@ -417,8 +414,6 @@ PIXI.WebGLRenderer.prototype.destroyTexture = function(texture)
}
}
&#x2F;**
* resizes the webGL view to the specified width and height
* @method resize
@ -443,226 +438,6 @@ PIXI.WebGLRenderer.prototype.resize = function(width, height)
projectionMatrix[13] = 1;
}
&#x2F;**
* @private
*&#x2F;
PIXI.WebGLRenderer.prototype.initTilingSprite = function(sprite)
{
var gl = this.gl;
&#x2F;&#x2F; make the texture tilable..
sprite.verticies = new Float32Array([0, 0,
sprite.width, 0,
sprite.width, sprite.height,
0, sprite.height]);
sprite.uvs = new Float32Array([0, 0,
1, 0,
1, 1,
0, 1]);
sprite.colors = new Float32Array([1,1,1,1]);
sprite.indices = new Uint16Array([0, 1, 3,2])&#x2F;&#x2F;, 2]);
sprite._vertexBuffer = gl.createBuffer();
sprite._indexBuffer = gl.createBuffer();
sprite._uvBuffer = gl.createBuffer();
sprite._colorBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, sprite._vertexBuffer);
gl.bufferData(gl.ARRAY_BUFFER, sprite.verticies, gl.STATIC_DRAW);
gl.bindBuffer(gl.ARRAY_BUFFER, sprite._uvBuffer);
gl.bufferData(gl.ARRAY_BUFFER, sprite.uvs, gl.DYNAMIC_DRAW);
gl.bindBuffer(gl.ARRAY_BUFFER, sprite._colorBuffer);
gl.bufferData(gl.ARRAY_BUFFER, sprite.colors, gl.STATIC_DRAW);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, sprite._indexBuffer);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, sprite.indices, gl.STATIC_DRAW);
&#x2F;&#x2F; return ( (x &gt; 0) &amp;&amp; ((x &amp; (x - 1)) == 0) );
if(sprite.texture.baseTexture._glTexture)
{
gl.bindTexture(gl.TEXTURE_2D, sprite.texture.baseTexture._glTexture);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
sprite.texture.baseTexture._powerOf2 = true;
}
else
{
sprite.texture.baseTexture._powerOf2 = true;
}
&#x2F;*
var context = this.context;
if(!sprite.__tilePattern) sprite.__tilePattern = context.createPattern(sprite.texture.baseTexture.source, &quot;repeat&quot;);
context.beginPath();
var tilePosition = sprite.tilePosition;
var tileScale = sprite.tileScale;
&#x2F;&#x2F; offset
context.scale(tileScale.x,tileScale.y);
context.translate(tilePosition.x, tilePosition.y);
context.fillStyle = sprite.__tilePattern;
context.fillRect(-tilePosition.x,-tilePosition.y,sprite.width &#x2F; tileScale.x, sprite.height &#x2F; tileScale.y);
context.translate(-tilePosition.x, -tilePosition.y);
context.scale(1&#x2F;tileScale.x, 1&#x2F;tileScale.y);
*&#x2F;
}
&#x2F;**
* @private
*&#x2F;
PIXI.WebGLRenderer.prototype.renderTilingSprite = function(sprite)
{
var gl = this.gl;
var shaderProgram = this.shaderProgram;
var tilePosition = sprite.tilePosition;
var tileScale = sprite.tileScale;
var offsetX = tilePosition.x&#x2F;sprite.texture.baseTexture.width;
var offsetY = tilePosition.y&#x2F;sprite.texture.baseTexture.height;
var scaleX = (sprite.width &#x2F; sprite.texture.baseTexture.width) &#x2F; tileScale.x;
var scaleY = (sprite.height &#x2F; sprite.texture.baseTexture.height) &#x2F; tileScale.y;
sprite.uvs[0] = 0 - offsetX;
sprite.uvs[1] = 0 - offsetY;
sprite.uvs[2] = (1 * scaleX) -offsetX;
sprite.uvs[3] = 0 - offsetY;
sprite.uvs[4] = (1 *scaleX) - offsetX;
sprite.uvs[5] = (1 *scaleY) - offsetY;
sprite.uvs[6] = 0 - offsetX;
sprite.uvs[7] = (1 *scaleY) - offsetY;
gl.bindBuffer(gl.ARRAY_BUFFER, sprite._uvBuffer);
gl.bufferSubData(gl.ARRAY_BUFFER, 0, sprite.uvs)
this.renderStrip(sprite);
}
&#x2F;**
* @private
*&#x2F;
PIXI.WebGLRenderer.prototype.initStrip = function(strip)
{
&#x2F;&#x2F; build the strip!
var gl = this.gl;
var shaderProgram = this.shaderProgram;
strip._vertexBuffer = gl.createBuffer();
strip._indexBuffer = gl.createBuffer();
strip._uvBuffer = gl.createBuffer();
strip._colorBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, strip._vertexBuffer);
gl.bufferData(gl.ARRAY_BUFFER, strip.verticies, gl.DYNAMIC_DRAW);
gl.bindBuffer(gl.ARRAY_BUFFER, strip._uvBuffer);
gl.bufferData(gl.ARRAY_BUFFER, strip.uvs, gl.STATIC_DRAW);
gl.bindBuffer(gl.ARRAY_BUFFER, strip._colorBuffer);
gl.bufferData(gl.ARRAY_BUFFER, strip.colors, gl.STATIC_DRAW);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, strip._indexBuffer);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, strip.indices, gl.STATIC_DRAW);
}
&#x2F;**
* @private
*&#x2F;
PIXI.WebGLRenderer.prototype.renderStrip = function(strip)
{
var gl = this.gl;
var shaderProgram = this.shaderProgram;
&#x2F;&#x2F; mat
var mat4Real = PIXI.mat3.toMat4(strip.worldTransform);
PIXI.mat4.transpose(mat4Real);
PIXI.mat4.multiply(this.projectionMatrix, mat4Real, mat4Real )
gl.uniformMatrix4fv(this.shaderProgram.mvMatrixUniform, false, mat4Real);
if(strip.blendMode == PIXI.blendModes.NORMAL)
{
gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
}
else
{
gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_COLOR);
}
if(!strip.dirty)
{
gl.bindBuffer(gl.ARRAY_BUFFER, strip._vertexBuffer);
gl.bufferSubData(gl.ARRAY_BUFFER, 0, strip.verticies)
gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 0, 0);
&#x2F;&#x2F; update the uvs
gl.bindBuffer(gl.ARRAY_BUFFER, strip._uvBuffer);
gl.vertexAttribPointer(shaderProgram.textureCoordAttribute, 2, gl.FLOAT, false, 0, 0);
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, strip.texture.baseTexture._glTexture);
gl.bindBuffer(gl.ARRAY_BUFFER, strip._colorBuffer);
gl.vertexAttribPointer(shaderProgram.colorAttribute, 1, gl.FLOAT, false, 0, 0);
&#x2F;&#x2F; dont need to upload!
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, strip._indexBuffer);
}
else
{
strip.dirty = false;
gl.bindBuffer(gl.ARRAY_BUFFER, strip._vertexBuffer);
gl.bufferData(gl.ARRAY_BUFFER, strip.verticies, gl.STATIC_DRAW)
gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 0, 0);
&#x2F;&#x2F; update the uvs
gl.bindBuffer(gl.ARRAY_BUFFER, strip._uvBuffer);
gl.bufferData(gl.ARRAY_BUFFER, strip.uvs, gl.STATIC_DRAW)
gl.vertexAttribPointer(shaderProgram.textureCoordAttribute, 2, gl.FLOAT, false, 0, 0);
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, strip.texture.baseTexture._glTexture);
gl.bindBuffer(gl.ARRAY_BUFFER, strip._colorBuffer);
gl.bufferData(gl.ARRAY_BUFFER, strip.colors, gl.STATIC_DRAW)
gl.vertexAttribPointer(shaderProgram.colorAttribute, 1, gl.FLOAT, false, 0, 0);
&#x2F;&#x2F; dont need to upload!
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, strip._indexBuffer);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, strip.indices, gl.STATIC_DRAW);
}
&#x2F;&#x2F;console.log(gl.TRIANGLE_STRIP)
gl.drawElements(gl.TRIANGLE_STRIP, strip.indices.length, gl.UNSIGNED_SHORT, 0);
gl.uniformMatrix4fv(this.shaderProgram.mvMatrixUniform, false, this.projectionMatrix);
&#x2F;&#x2F; console.log(&quot;!!!&quot;)
}
&#x2F;**
* @private
*&#x2F;