Jump to content

A migration problem from pixi v2 to pixi v3


Ramiro
 Share

Recommended Posts

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 :)

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...