Page 1 of 1

Is it possible to save WebGL canvas as image like Chromium?

PostPosted: Sat Aug 25, 2018 2:53 am
by RadarNyan
Hi everyone,

I'm building a special browser for a web game, which uses WebGL to render everything onto on canvas element. I want to save the canvas as image (as a screenshot) but Canvas.toDataURL() doesn't work as the canvas is rendered with WebGL.

I have two ways to workaround this, one is by disable GPU which makes the game fall back to 2D rendering, then I can use Canvas.toDataURL() but the game would run slower and have some visual artifacts. Another is to modify the game / game engine code to force "preserveDrawingBuffer = true" - it's not only unsafe and dirty, but also give me a great performance hit on my old laptop. So I gave up getting image from canvas, just captured what's on screen.

Then I noticed in Chromium, if you right click on a canvas, you can save it as image or copy image to clipboard, I've confirmed it works even with WebGL canvas. How did Chromium do this, can we have this feature in Cef?