WebGL Render Bug Fix

This commit is contained in:
Mat Groves 2013-06-24 15:32:52 +01:00
parent 953a19ff5c
commit c6e6f7458e
36 changed files with 729 additions and 340 deletions

View file

@ -337,6 +337,7 @@ PIXI.InteractionManager.prototype.update = function()
PIXI.InteractionManager.prototype.onMouseMove = function(event)
{
this.mouse.originalEvent = event || window.event; //IE uses window.event
// TODO optimize by not check EVERY TIME! maybe half as often? //
var rect = this.target.view.getBoundingClientRect();
@ -362,6 +363,7 @@ PIXI.InteractionManager.prototype.onMouseMove = function(event)
PIXI.InteractionManager.prototype.onMouseDown = function(event)
{
event.preventDefault();
this.mouse.originalEvent = event || window.event; //IE uses window.event
// loop through inteaction tree...
// hit test each item! ->
@ -399,7 +401,7 @@ PIXI.InteractionManager.prototype.onMouseDown = function(event)
PIXI.InteractionManager.prototype.onMouseUp = function(event)
{
this.mouse.originalEvent = event || window.event; //IE uses window.event
var global = this.mouse.global;
@ -532,6 +534,7 @@ PIXI.InteractionManager.prototype.hitTest = function(item, interactionData)
PIXI.InteractionManager.prototype.onTouchMove = function(event)
{
this.mouse.originalEvent = event || window.event; //IE uses window.event
var rect = this.target.view.getBoundingClientRect();
var changedTouches = event.changedTouches;
@ -556,6 +559,7 @@ PIXI.InteractionManager.prototype.onTouchMove = function(event)
PIXI.InteractionManager.prototype.onTouchStart = function(event)
{
event.preventDefault();
this.mouse.originalEvent = event || window.event; //IE uses window.event
var rect = this.target.view.getBoundingClientRect();
@ -598,6 +602,7 @@ PIXI.InteractionManager.prototype.onTouchStart = function(event)
PIXI.InteractionManager.prototype.onTouchEnd = function(event)
{
this.mouse.originalEvent = event || window.event; //IE uses window.event
var rect = this.target.view.getBoundingClientRect();
var changedTouches = event.changedTouches;
@ -682,6 +687,13 @@ PIXI.InteractionData = function()
* @type Sprite
*/
this.target;
/**
* When passed to an event handler, this will be the original DOM Event that was captured
* @property originalEvent
* @type Event
*/
this.originalEvent;
}
/**

View file

@ -236,6 +236,7 @@ PIXI.SpriteSheetLoader.prototype.onLoaded = function () {
content: this
});
};
</pre>
</div>

View file

@ -149,6 +149,8 @@
&#x2F;**
* The Graphics class contains a set of methods that you can use to create primitive shapes and lines.
* It is important to know that with the webGL renderer only simple polys can be filled at this stage
* Complex polys will not be filled. Heres an example of a complex poly: http:&#x2F;&#x2F;www.goodboydigital.com&#x2F;wp-content&#x2F;uploads&#x2F;2013&#x2F;06&#x2F;complexPolygon.png
* @class Graphics
* @extends DisplayObjectContainer
* @constructor

View file

@ -166,6 +166,7 @@ PIXI.CanvasGraphics = function()
*&#x2F;
PIXI.CanvasGraphics.renderGraphics = function(graphics, context)
{
var worldAlpha = graphics.worldAlpha;
for (var i=0; i &lt; graphics.graphicsData.length; i++)
{
@ -198,13 +199,13 @@ PIXI.CanvasGraphics.renderGraphics = function(graphics, context)
if(data.fill)
{
context.globalAlpha = data.fillAlpha;
context.globalAlpha = data.fillAlpha * worldAlpha;
context.fillStyle = color = &#x27;#&#x27; + (&#x27;00000&#x27; + ( data.fillColor | 0).toString(16)).substr(-6);
context.fill();
}
if(data.lineWidth)
{
context.globalAlpha = data.lineAlpha;
context.globalAlpha = data.lineAlpha * worldAlpha;
context.stroke();
}
}
@ -213,14 +214,14 @@ PIXI.CanvasGraphics.renderGraphics = function(graphics, context)
&#x2F;&#x2F; TODO - need to be Undefined!
if(data.fillColor)
{
context.globalAlpha = data.fillAlpha;
context.globalAlpha = data.fillAlpha * worldAlpha;
context.fillStyle = color = &#x27;#&#x27; + (&#x27;00000&#x27; + ( data.fillColor | 0).toString(16)).substr(-6);
context.fillRect(points[0], points[1], points[2], points[3]);
}
if(data.lineWidth)
{
context.globalAlpha = data.lineAlpha;
context.globalAlpha = data.lineAlpha * worldAlpha;
context.strokeRect(points[0], points[1], points[2], points[3]);
}
}
@ -233,13 +234,13 @@ PIXI.CanvasGraphics.renderGraphics = function(graphics, context)
if(data.fill)
{
context.globalAlpha = data.fillAlpha;
context.globalAlpha = data.fillAlpha * worldAlpha;
context.fillStyle = color = &#x27;#&#x27; + (&#x27;00000&#x27; + ( data.fillColor | 0).toString(16)).substr(-6);
context.fill();
}
if(data.lineWidth)
{
context.globalAlpha = data.lineAlpha;
context.globalAlpha = data.lineAlpha * worldAlpha;
context.stroke();
}
}
@ -276,13 +277,13 @@ PIXI.CanvasGraphics.renderGraphics = function(graphics, context)
if(data.fill)
{
context.globalAlpha = data.fillAlpha;
context.globalAlpha = data.fillAlpha * worldAlpha;
context.fillStyle = color = &#x27;#&#x27; + (&#x27;00000&#x27; + ( data.fillColor | 0).toString(16)).substr(-6);
context.fill();
}
if(data.lineWidth)
{
context.globalAlpha = data.lineAlpha;
context.globalAlpha = data.lineAlpha * worldAlpha;
context.stroke();
}
}

View file

@ -401,6 +401,8 @@ PIXI.CanvasRenderer.prototype.renderTilingSprite = function(sprite)
{
var context = this.context;
context.globalAlpha = sprite.worldAlpha;
if(!sprite.__tilePattern) sprite.__tilePattern = context.createPattern(sprite.texture.baseTexture.source, &quot;repeat&quot;);
context.beginPath();

View file

@ -660,6 +660,7 @@ PIXI.WebGLBatch.prototype.update = function()
*&#x2F;
PIXI.WebGLBatch.prototype.render = function(start, end)
{
&#x2F;&#x2F; console.log(start + &quot; :: &quot; + end + &quot; : &quot; + this.size);
start = start || 0;
&#x2F;&#x2F;end = end || this.size;
@ -672,6 +673,7 @@ PIXI.WebGLBatch.prototype.render = function(start, end)
}
if (this.size == 0)return;
this.update();
@ -688,7 +690,6 @@ PIXI.WebGLBatch.prototype.render = function(start, end)
&#x2F;&#x2F; ok..
gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.verticies)
gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 0, 0);
&#x2F;&#x2F; update the uvs
gl.bindBuffer(gl.ARRAY_BUFFER, this.uvBuffer);
@ -722,7 +723,7 @@ PIXI.WebGLBatch.prototype.render = function(start, end)
var len = end - start;
&#x2F;&#x2F; console.log(this.size)
&#x2F;&#x2F; DRAW THAT this!
gl.drawElements(gl.TRIANGLES, len * 6, gl.UNSIGNED_SHORT, start * 2 * 6 );
&#x2F;&#x2F; gl.drawElements(gl.TRIANGLES, len * 6, gl.UNSIGNED_SHORT, start * 2 * 6 );
}

View file

@ -159,7 +159,7 @@ PIXI.WebGLGraphics = function()
PIXI.WebGLGraphics.renderGraphics = function(graphics, projection)
{
PIXI.activatePrimitiveShader();
var gl = PIXI.gl;
if(!graphics._webGL)graphics._webGL = {points:[], indices:[], lastIndex:0,
@ -176,27 +176,47 @@ PIXI.WebGLGraphics.renderGraphics = function(graphics, projection)
graphics._webGL.lastIndex = 0;
graphics._webGL.points = [];
graphics._webGL.indices = [];
}
PIXI.WebGLGraphics.updateGraphics(graphics);
}
PIXI.activatePrimitiveShader();
&#x2F;&#x2F; This could be speeded up fo sure!
var m = PIXI.mat3.clone(graphics.worldTransform);
PIXI.mat3.transpose(m);
&#x2F;&#x2F; set the matrix transform for the
gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
gl.uniformMatrix3fv(PIXI.primitiveProgram.translationMatrix, false, m);
gl.uniform2f(PIXI.primitiveProgram.projectionVector, projection.x, projection.y);
gl.uniform1f(PIXI.primitiveProgram.alpha, graphics.worldAlpha);
gl.bindBuffer(gl.ARRAY_BUFFER, graphics._webGL.buffer);
&#x2F;&#x2F; WHY DOES THIS LINE NEED TO BE THERE???
gl.vertexAttribPointer(PIXI.shaderProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 0, 0);
&#x2F;&#x2F; its not even used.. but need to be set or it breaks?
&#x2F;&#x2F; only on pc though..
gl.vertexAttribPointer(PIXI.primitiveProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 4 * 6, 0);
gl.vertexAttribPointer(PIXI.primitiveProgram.colorAttribute, 4, gl.FLOAT, false,4 * 6, 2 * 4);
&#x2F;&#x2F; console.log(PIXI.primitiveProgram.vertexPositionAttribute);
&#x2F;&#x2F;console.log(&quot;Color &quot; + PIXI.primitiveProgram.colorAttribute);
&#x2F;&#x2F; set the index buffer!
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, graphics._webGL.indexBuffer);
gl.drawElements(gl.TRIANGLE_STRIP, graphics._webGL.indices.length, gl.UNSIGNED_SHORT, 0 );
&#x2F;&#x2F; return to default shader...
@ -237,6 +257,7 @@ PIXI.WebGLGraphics.updateGraphics = function(graphics)
var gl = PIXI.gl;
graphics._webGL.glPoints = new Float32Array(graphics._webGL.points);
gl.bindBuffer(gl.ARRAY_BUFFER, graphics._webGL.buffer);
gl.bufferData(gl.ARRAY_BUFFER, graphics._webGL.glPoints, gl.STATIC_DRAW);

View file

@ -928,6 +928,8 @@ PIXI.WebGLRenderGroup.prototype.renderStrip = function(strip, projection)
&#x2F;&#x2F; set the matrix transform for the
gl.uniformMatrix3fv(PIXI.stripShaderProgram.translationMatrix, false, m);
gl.uniform2f(PIXI.stripShaderProgram.projectionVector, projection.x, projection.y);
gl.uniform1f(PIXI.stripShaderProgram.alpha, strip.worldAlpha);
if(strip.blendMode == PIXI.blendModes.NORMAL)
{
@ -938,6 +940,8 @@ PIXI.WebGLRenderGroup.prototype.renderStrip = function(strip, projection)
gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_COLOR);
}
if(!strip.dirty)
{
@ -1030,7 +1034,7 @@ PIXI.WebGLRenderGroup.prototype.renderTilingSprite = function(sprite, projection
&#x2F;**
* @private
*&#x2F;
PIXI.WebGLRenderer.prototype.initStrip = function(strip)
PIXI.WebGLRenderGroup.prototype.initStrip = function(strip)
{
&#x2F;&#x2F; build the strip!
var gl = this.gl;

View file

@ -191,7 +191,7 @@ PIXI.WebGLRenderer = function(width, height, view, transparent)
{
PIXI.gl = this.gl = this.view.getContext(&quot;experimental-webgl&quot;, {
alpha: this.transparent,
antialias:false, &#x2F;&#x2F; SPEED UP??
antialias:true, &#x2F;&#x2F; SPEED UP??
premultipliedAlpha:false
});
}
@ -446,9 +446,11 @@ PIXI.WebGLRenderer.prototype.handleContextRestored = function(event)
this.initShaders();
for (var i=0; i &lt; PIXI.TextureCache.length; i++)
for(var key in PIXI.TextureCache)
{
this.updateTexture(PIXI.TextureCache[i]);
var texture = PIXI.TextureCache[key].baseTexture;
texture._glTexture = null;
PIXI.WebGLRenderer.updateTexture(texture);
};
for (var i=0; i &lt; this.batchs.length; i++)

View file

@ -168,6 +168,7 @@ PIXI.shaderVertexSrc = [
&quot;attribute vec2 aTextureCoord;&quot;,
&quot;attribute float aColor;&quot;,
&#x2F;&#x2F;&quot;uniform mat4 uMVMatrix;&quot;,
&quot;uniform vec2 projectionVector;&quot;,
&quot;varying vec2 vTextureCoord;&quot;,
&quot;varying float vColor;&quot;,
@ -182,6 +183,20 @@ PIXI.shaderVertexSrc = [
&#x2F;*
* the triangle strip shader..
*&#x2F;
PIXI.stripShaderFragmentSrc = [
&quot;precision mediump float;&quot;,
&quot;varying vec2 vTextureCoord;&quot;,
&quot;varying float vColor;&quot;,
&quot;uniform float alpha;&quot;,
&quot;uniform sampler2D uSampler;&quot;,
&quot;void main(void) {&quot;,
&quot;gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y));&quot;,
&quot;gl_FragColor = gl_FragColor * alpha;&quot;,
&quot;}&quot;
];
PIXI.stripShaderVertexSrc = [
&quot;attribute vec2 aVertexPosition;&quot;,
&quot;attribute vec2 aTextureCoord;&quot;,
@ -216,16 +231,18 @@ PIXI.primitiveShaderVertexSrc = [
&quot;attribute vec4 aColor;&quot;,
&quot;uniform mat3 translationMatrix;&quot;,
&quot;uniform vec2 projectionVector;&quot;,
&quot;uniform float alpha;&quot;,
&quot;varying vec4 vColor;&quot;,
&quot;void main(void) {&quot;,
&quot;vec3 v = translationMatrix * vec3(aVertexPosition, 1.0);&quot;,
&quot;gl_Position = vec4( v.x &#x2F; projectionVector.x -1.0, v.y &#x2F; -projectionVector.y + 1.0 , 0.0, 1.0);&quot;,
&quot;vColor = aColor;&quot;,
&quot;vColor = aColor * alpha;&quot;,
&quot;}&quot;
];
PIXI.initPrimitiveShader = function()
{
return;
var gl = PIXI.gl;
var shaderProgram = PIXI.compileProgram(PIXI.primitiveShaderVertexSrc, PIXI.primitiveShaderFragmentSrc)
@ -234,8 +251,11 @@ PIXI.initPrimitiveShader = function()
shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, &quot;aVertexPosition&quot;);
shaderProgram.colorAttribute = gl.getAttribLocation(shaderProgram, &quot;aColor&quot;);
shaderProgram.projectionVector = gl.getUniformLocation(shaderProgram, &quot;projectionVector&quot;);
shaderProgram.translationMatrix = gl.getUniformLocation(shaderProgram, &quot;translationMatrix&quot;);
shaderProgram.alpha = gl.getUniformLocation(shaderProgram, &quot;alpha&quot;);
PIXI.primitiveProgram = shaderProgram;
}
@ -252,7 +272,7 @@ PIXI.initDefaultShader = function()
shaderProgram.textureCoordAttribute = gl.getAttribLocation(shaderProgram, &quot;aTextureCoord&quot;);
shaderProgram.colorAttribute = gl.getAttribLocation(shaderProgram, &quot;aColor&quot;);
shaderProgram.mvMatrixUniform = gl.getUniformLocation(shaderProgram, &quot;uMVMatrix&quot;);
&#x2F;&#x2F; shaderProgram.mvMatrixUniform = gl.getUniformLocation(shaderProgram, &quot;uMVMatrix&quot;);
shaderProgram.samplerUniform = gl.getUniformLocation(shaderProgram, &quot;uSampler&quot;);
PIXI.shaderProgram = shaderProgram;
@ -261,7 +281,7 @@ PIXI.initDefaultShader = function()
PIXI.initDefaultStripShader = function()
{
var gl = this.gl;
var shaderProgram = PIXI.compileProgram(PIXI.stripShaderVertexSrc, PIXI.shaderFragmentSrc)
var shaderProgram = PIXI.compileProgram(PIXI.stripShaderVertexSrc, PIXI.stripShaderFragmentSrc)
gl.useProgram(shaderProgram);
@ -269,6 +289,7 @@ PIXI.initDefaultStripShader = function()
shaderProgram.projectionVector = gl.getUniformLocation(shaderProgram, &quot;projectionVector&quot;);
shaderProgram.textureCoordAttribute = gl.getAttribLocation(shaderProgram, &quot;aTextureCoord&quot;);
shaderProgram.translationMatrix = gl.getUniformLocation(shaderProgram, &quot;translationMatrix&quot;);
shaderProgram.alpha = gl.getUniformLocation(shaderProgram, &quot;alpha&quot;);
shaderProgram.colorAttribute = gl.getAttribLocation(shaderProgram, &quot;aColor&quot;);
@ -311,9 +332,13 @@ PIXI.activateDefaultShader = function()
gl.useProgram(shaderProgram);
gl.enableVertexAttribArray(shaderProgram.vertexPositionAttribute);
gl.enableVertexAttribArray(shaderProgram.textureCoordAttribute);
gl.enableVertexAttribArray(shaderProgram.colorAttribute);
}
PIXI.compileProgram = function(vertexSrc, fragmentSrc)

View file

@ -256,7 +256,9 @@ PIXI.BaseTexture.fromImage = function(imageUrl, crossorigin)
var baseTexture = PIXI.BaseTextureCache[imageUrl];
if(!baseTexture)
{
var image = new Image();
&#x2F;&#x2F; new Image() breaks tex loading in some versions of Chrome.
&#x2F;&#x2F; See https:&#x2F;&#x2F;code.google.com&#x2F;p&#x2F;chromium&#x2F;issues&#x2F;detail?id=238071
var image = new Image();&#x2F;&#x2F;document.createElement(&#x27;img&#x27;);
if (crossorigin)
{
image.crossOrigin = &#x27;&#x27;;

View file

@ -147,13 +147,33 @@
*&#x2F;
&#x2F;**
* A RenderTexture is a special texture that allows any pixi displayObject to be rendered to it.
* @class RenderTexture
* @extends Texture
* @constructor
* @param width {Number}
* @param height {Number}
*&#x2F;
A RenderTexture is a special texture that allows any pixi displayObject to be rendered to it.
__Hint__: All DisplayObjects (exmpl. Sprites) that renders on RenderTexture should be preloaded.
Otherwise black rectangles will be drawn instead.
RenderTexture takes snapshot of DisplayObject passed to render method. If DisplayObject is passed to render method, position and rotation of it will be ignored. For example:
var renderTexture = new PIXI.RenderTexture(800, 600);
var sprite = PIXI.Sprite.fromImage(&quot;spinObj_01.png&quot;);
sprite.position.x = 800&#x2F;2;
sprite.position.y = 600&#x2F;2;
sprite.anchor.x = 0.5;
sprite.anchor.y = 0.5;
renderTexture.render(sprite);
Sprite in this case will be rendered to 0,0 position. To render this sprite at center DisplayObjectContainer should be used:
var doc = new PIXI.DisplayObjectContainer();
doc.addChild(sprite);
renderTexture.render(doc); &#x2F;&#x2F; Renders to center of renderTexture
@class RenderTexture
@extends Texture
@constructor
@param width {Number}
@param height {Number}
**&#x2F;
PIXI.RenderTexture = function(width, height)
{
PIXI.EventTarget.call( this );