Toggling from OpenGLRenderer to Cairo or Canvas Renderer

I always wondered,
In OpenFL there are two types of renderers: GPU based (OpenGL) and CPU based (Cairo/Canvas)
I wanted to know, is there a way to toggle everything to be only with the CPU, or are they meant to compliment each other in certain ways?

I experimented with drawing on lime quite awhile ago. My approach was to extend the Lime Application class ( details may well have changed ).

as you can see OpenFL/Lime provides ‘context’ so to use WebGL and Canvas context you would likely need to setup two contexts.
You can see I use the GL context here

You can compare with NME which probably only use GL context so can extend the Application without context switches.

With flash you would often share stage3D context with away3D/starling/feathers and have a cpu context, or even more but essentially I seem to remember you could have a front and back GPU layer and middle layer was normally CPU dynamic and timeline, but it got quite complex. Old article on flash MX talking about depths.
https://www.senocular.com/flash/tutorials/depths/?page=2

Cairo was for c# from my understanding and that is a lower tier haxe target, it can’t do Barycentric triangle distortions so it’s limited to mostly non 3D as you need 3D image distortions . I believe that you don’t really need Cairo it’s not important - was it because of Blackberry mobile support more than anything?

So ignoring flash ( AIR ) that leaves mostly GPU rendering for JS and C++, but via bitmaps stuff can be done with graphics and CPU and then drawn on a GPU context as an image.

The CPU modes seem to be
CAIRO, CANVAS, DOM, FLASH

DOM is really a fallback mode, so that just leaves CANVAS, I am not sure how OpenFL uses Canvas but Canvas internally uses WebGL in the browser?

So each context is a layer or depth. If you use Kha it has Graphics2 and Graphics4 you can draw one as an image on another to mix but it is normally GL.

Not sure if that really answers your question, but NME seems to just use GL context ( c++ ) on JS and C++. So perhaps only GL context is really relevant in the future? But think of graphics layers or dom layers for the GL or CPU you can use a renderTexture to draw one on the other but otherwise they are different.

You can force pure DOM, CANVAS or WebGL context for html target, but it is probably just use Stage3D and normal openfl.display.Sprites for CPU and GPU differences, and ignore Cairo as it is limiting and haxe c# is not priority haxe target.

I applogise for all errors in my limited understanding but maybe some gives insight.

Add the cairo define to force the software renderer on native targets.

<define name="cairo" unless="html5"/>

Add the canvas define to force the software renderer on the html5 target.

<define name="canvas" if="html5"/>

html5 also has an optional DOM renderer, using the dom define (don’t combine canvas and dom in the same project, though!).

<define name="dom" if="html5"/>
1 Like

The DOM renderer seems so “magical” to me… (just commenting)