OpenFL rendering system

Hello, I want to know details of OpenFL rendering system.

What is drawTiles or drawTriangles?

Does system support automated batching when texture atlases in use?

How we should implement things which will draw a lot of images with only one draw call to GPU? How system can be CPU and GPU effective?

Thanks.

1 Like

Firstly, the most efficient way to blit images to the screen is by using the copyPixels function of the BitmapData class. For example, you could have a bitmap which takes a bitmapData, such as in the following code:

var myBitmap = new Bitmap(null);
var bi = new BitmapData(32, 32);
bi.copyPixels(Assets.getBitmapData("img/myImg.png"), new Rectangle(0, 0, 32, 32), new Point(0, 0));
myBitmap.bitmapData = bi;

Basically, what the copyPixels function does is it takes a source image (of type BitmapData), the source from the image using a Rectangle, and where to place the source in the instance of the BitmapData you are operating on, in this case is bi.

That’s for images.

The graphics class in general is not so efficient, but is okay for a small number of graphical operations. I wouldn’t recommend it for any more than 2000 operations at once.

In general, the most efficient system for GPU batching is drawTiles, which lets you combine multiple quads into one draw call.

That requires a Sprite, right? Which as far as I am concerned is going to take more memory versus a Bitmap? I don’t know, it’s your library I suppose ;p

Both Sprite and Bitmap are logical objects, they don’t really cost anything

Calling BitmapData operations is going to move pixels in memory, with native, this is done on the CPU, on HTML5, this sometimes uses drawImage (which is the fastest canvas operation) but may require getting all pixels from the canvas and modifying them instead.

When using OpenGL, BitmapData changes need to uploaded to your graphics card again to render

If you are in software, the “closest to the metal” operation is copying pixels – that’s what a software renderer does. However, in hardware, it’s happiest when you texture uploads, and instead upload geometry. That’s what something like drawTiles or drawTriangles does

Thank you for the answers, they were very enlightening.