Skip to content

Commit

Permalink
fix: WebGLRenderer worldMatrix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
06wj committed Feb 15, 2016
1 parent 385bf7d commit 4efc6e6
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions src/renderer/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ var WebGLRenderer = Class.create(/** @lends WebGLRenderer.prototype */{
this._renderBatches();
}

var vertexs = this._createVertexs(image, rect[0], rect[1], sw, sh, -target.pivotX, -target.pivotY, w, h);
var vertexs = this._createVertexs(image, rect[0], rect[1], sw, sh, 0, 0, w, h);
var index = this.batchIndex * this.positionStride;
var positions = this.positions;
var alpha = target.__webglRenderAlpha;
Expand Down Expand Up @@ -297,7 +297,7 @@ var WebGLRenderer = Class.create(/** @lends WebGLRenderer.prototype */{
if(!this._projectionTransformElements||force){
this._projectionTransformElements = new Float32Array([
1/this.canvasHalfWidth, 0, 0,
0, 1/this.canvasHalfHeight, 0,
0, -1/this.canvasHalfHeight, 0,
-1, 1, 1,
]);
}
Expand Down Expand Up @@ -360,10 +360,6 @@ var WebGLRenderer = Class.create(/** @lends WebGLRenderer.prototype */{
th = 1 - ty;
}

ty = 1 - ty - th;

y = -h - y;

var index = 0;
tempVertexs[index++] = x; tempVertexs[index++] = y; tempVertexs[index++] = tx; tempVertexs[index++] = ty;
tempVertexs[index++] = x+w;tempVertexs[index++] = y; tempVertexs[index++] = tx+tw; tempVertexs[index++] = ty;
Expand All @@ -375,7 +371,7 @@ var WebGLRenderer = Class.create(/** @lends WebGLRenderer.prototype */{
_setConcatenatedMatrix:function(view, ancestor){
var mtx = view.__webglWorldMatrix;
var cos = 1, sin = 0,
rotation = 360-view.rotation % 360,
rotation = view.rotation % 360,
pivotX = view.pivotX, pivotY = view.pivotY,
scaleX = view.scaleX, scaleY = view.scaleY;

Expand All @@ -389,11 +385,10 @@ var WebGLRenderer = Class.create(/** @lends WebGLRenderer.prototype */{
mtx.b = sin*scaleX;
mtx.c = -sin*scaleY;
mtx.d = cos*scaleY;
mtx.tx = view.x;
mtx.ty = -view.y;
mtx.tx = view.x - mtx.a * pivotX - mtx.c * pivotY;
mtx.ty = view.y - mtx.b * pivotX - mtx.d * pivotY;

var aMtx = ancestor.__webglWorldMatrix;
mtx.concat(aMtx.a, aMtx.b, aMtx.c, aMtx.d, aMtx.tx, aMtx.ty);
mtx.concat(ancestor.__webglWorldMatrix);
}
});

Expand Down Expand Up @@ -458,7 +453,7 @@ Shader.prototype = {
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, texture);

gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 1);
// gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 1);
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 1);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);

Expand Down

0 comments on commit 4efc6e6

Please sign in to comment.