Search the Community
Showing results for tags 'v2 to v3'.
-
Hi, I'm having a bit of trouble with my conversion of a piece of code. I have a layering object than "clips" a region of the screen before it draws it's children. On v2 it was quite easy to do: WindowLayer.prototype._webglMaskRect = function(renderSession, x, y, w, h) { if (w > 0 && h > 0) { var gl = renderSession.gl; var projection = renderSession.projection; console.log(renderSession); var offset = renderSession.offset; var shader = renderSession.shaderManager.primitiveShader; renderSession.shaderManager.setShader(shader); gl.uniformMatrix3fv(shader.translationMatrix, false, this._translationMatrix); gl.uniform1f(shader.flipY, 1); gl.uniform2f(shader.projectionVector, projection.x, -projection.y); gl.uniform2f(shader.offsetVector, -offset.x, -offset.y); gl.stencilFunc(gl.EQUAL, 0, 0xFF); gl.stencilOp(gl.KEEP, gl.KEEP, gl.INCR); var data = new Float32Array([x, y, x+w, y, x, y+h, x, y+h, x+w, y, x+w, y+h]); gl.bindBuffer(gl.ARRAY_BUFFER, this._vertexBuffer); gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW); gl.enableVertexAttribArray(shader.aVertexPosition); gl.vertexAttribPointer(shader.aVertexPosition, 2, gl.FLOAT, false, 0, 0); gl.drawArrays(gl.TRIANGLES, 0, 6); gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP); }};Right now I could move the projection matrix to this: WindowLayer.prototype._webglMaskRect = function(renderSession, x, y, w, h) { if (w > 0 && h > 0) { var gl = renderSession.gl; var projection = renderSession.currentRenderTarget.projectionMatrix; console.log(renderSession); // but here is the problem var offset = new Point(0, 0); var shader = renderSession.shaderManager.primitiveShader; renderSession.shaderManager.setShader(shader); gl.uniformMatrix3fv(shader.translationMatrix, false, this._translationMatrix); gl.uniform1f(shader.flipY, 1); gl.uniform2f(shader.projectionVector, projection.x, -projection.y); gl.uniform2f(shader.offsetVector, -offset.x, -offset.y); gl.stencilFunc(gl.EQUAL, 0, 0xFF); gl.stencilOp(gl.KEEP, gl.KEEP, gl.INCR); var data = new Float32Array([x, y, x+w, y, x, y+h, x, y+h, x+w, y, x+w, y+h]); gl.bindBuffer(gl.ARRAY_BUFFER, this._vertexBuffer); gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW); gl.enableVertexAttribArray(shader.aVertexPosition); gl.vertexAttribPointer(shader.aVertexPosition, 2, gl.FLOAT, false, 0, 0); gl.drawArrays(gl.TRIANGLES, 0, 6); gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP); }};But the offset (using 0,0 by now because I don't want to crash everything) is not correct if you move the origin of an sprite or tilling sprite... I don't find any translationPoint nor offsetPoint to do that. Does anyone knows how can I archieve the same effect? Thanks for reading my post