Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving BitmapData.draw performance (in dispose Image mode) #2707

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

rainyt
Copy link
Contributor

@rainyt rainyt commented May 15, 2024

  1. Referencing the OpenGLRenderer renderer eliminates the need for reconstruction and reduces the cost of initializing the Shader.

  2. Set default shaders for existing OpenGLRenderer renderers.

It is very effective in the following code:

package;

import openfl.geom.Matrix;
import openfl.display.FPS;
import openfl.events.Event;
import openfl.display.BitmapData;
import openfl.display.Bitmap;
import openfl.display.Sprite;

class Main extends Sprite {
	public function new() {
		super();

		var spr = new Sprite();
		spr.graphics.beginFill(0xff0000);
		spr.graphics.drawCircle(0, 0, 10);
		spr.graphics.endFill();

		var drawBitmapData = new BitmapData(500, 500, false, 0);
		drawBitmapData.disposeImage();

		var drawBitmap = new Bitmap(drawBitmapData);
		this.addChild(drawBitmap);

		this.addEventListener(Event.ENTER_FRAME, (e) -> {
			var m = new Matrix();
			m.translate(Math.random() * 500, Math.random() * 500);
			for (i in 0...100) {
				drawBitmapData.draw(spr, m);
			}
		});

		var fps = new FPS();
		this.addChild(fps);
	}
}

1. Referencing the OpenGLRenderer renderer eliminates the need for reconstruction and reduces the cost of initializing the Shader.

2. Set default shaders for existing OpenGLRenderer renderers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant