Jump to content

rendering to offscreen canvas


Baker Xiao
 Share

Recommended Posts

Hi folks,

How do we render a scene to an offscreen canvas? We want to use that to construct screenshots for people to download but we won't show these screenshots in the main game. 

 

Currently if we create a BABYLON.Engine with document.createElement("canvas") but don't attach this canvas element to document.body, we get errors like below:

[.Offscreen-For-WebGL-0x7fe2e1614a00]GL ERROR :GL_INVALID_FRAMEBUFFER_OPERATION : glClear: framebuffer incomplete

 

Any trick to get it done?

Link to comment
Share on other sites

1 minute ago, brianzinn said:

Likely there is a better trick, but what about adding to canvas style= visibility:hidden?

Lol that's exactly what I'm doing. But not sure if that creates any overhead to the browser or not... (e.g. would the browser still use the GPU for this canvas even though it's visibility:hidden?) Ideally I want to avoid burdening the DOM in any way. 

Link to comment
Share on other sites

I do believe your GPU will anyhow continue rendering (otherise, how would you be able to create a real-time screenshot?)

A quick experiment (setting the playground's canvas' visibility to hidden) showed that the before- and afterRender loops are being executed. Check the performance tab in chrome also shows the GPU continues working. 

I wouldn't call it an "offscreen" canvas. But it should work nonetheless :) 

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