Jump to content

WebGL Context loss when using PIXI RenderTextures for split screen


arthuro555
 Share

Recommended Posts

Hello ?!

I am experimenting with making a split screen multiplayer game, using a game engine backed by PIXI, GDevelop. To do so, I'm moving the "camera" (the root Container's position) to center each player and render the root container into a sprite, each sprite being a player's screen.


To do the rendering, I've used code that looks like this (simplified for readability and to contain only the PIXI code, not the engine specific one) that runs every frame of the game:

const source = the root PIXI Container;
const width, height = the viewport width & height;
const renderTarget = a PIXI sprite;

global.rt = (global.rt || RenderTexture.create({ width, height }));

global.sprite = (global.sprite || Sprite.from(global.rt));

if(!renderTaget.texture instanceof RenderTexture) renderTarget.texture = RenderTexture.create({ width, height });

renderer.render(source, { renderTexture: global.rt });
renderer.render(global.sprite, { renderTexture: renderTarget.texture }); 


The texture of the render target seems to be replaced, but it seems to be transparent (or the background color), no messages in the console, but after a few dozens of seconds the webgl context is lost. The more renders the quicker, so i am guessing it has something to do with the amount of times i do the rendering.

Does anyone have some pointers about what i may have done wrong? Thanks :)

Link to comment
Share on other sites

Hello, I've solved my issue, posting here in case anyone gets the same kinds of issues!

I actually had two problems here, the first one was the context loss, which was due to this code: 

global.rt = (global.rt || RenderTexture.create({ width, height }));

I could have sworn that only the left side of the or is evaluated if it is true, but it seems i was mistaken and this created new render textures every frame, causing eventually the context loss.

 

My other issue of seeing nothing being rendered was due to the rendering process resizing the sprite, it would use the height and width of the rendered texture instead of the one the sprite previously had. I fixed it by getting the scale of the sprite before rendering and setting it back after rendering.

I hope this'll help someone!

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...