Skip to content

Make Flixel GPU accelerated #219

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

Merged
merged 35 commits into from
Nov 15, 2014
Merged

Conversation

Dovyski
Copy link
Member

@Dovyski Dovyski commented Sep 12, 2014

I am really happy to issue this pull request. It makes Flixel Community GPU accelerated by using Genome2D as a render.

This is the first step to bring Flixel to the GPU world, there is still room for improvement. Despite of that I've ran some tests and the new GPU render is way faster than the CPU blitting one.

I have tried to keep changes to a minimum, avoiding modifications that would break too many things. I think the only significant modification I've made that deeply changes the current API was the addition of a Camera param in FlxBasic#draw(), which is now FlxBasic#draw(Camera:FlxCamera). There was no way I could think of to implement multiple cameras without that change.

Special thanks to @pshtif and @Beeblerox for helping making it happen!

Fix #90

Dovyski added 30 commits August 17, 2014 18:51
Only FlxBlittingRender is drawing something, the FlxGenome2DRender is displaying a bunny and ignoring all state members.
I've used placeholder code everywhere, but FlxGenome2DRender is rendering single-frame FlxSprites in simpleRender.
This is not the best approach to achieve that, but I've tried to keep changes to a minimum. This commit also differs from my original idea of implementing a render that is completely decoupled from renderable entities (e.g. FlxSprite).

I've left some hardwired rendering code in FlxSprite (see calcFrame(), for instance), but they will be removed as I progress.
I've tried my best to implement the GPU render without affecting the current drawing API, but that was not possible. The way Flixel draws entities is completely unfriendly for a GPU render using cameras. My best bet was to use render to texture to overcome the problems, but that didn't work either.

I was forced to change the draw() method to draw(c:Camera), which means the Flixel render will now invoke draw() for each entity, telling it to render to the specified camera.
It's not perfect and a little bit unpleasant since fxColorAcumulator must be reset by the GPU render, not the camera itself, but it's a start already.
The debug buffer is based on blitting and it enables Flixel to draw dynamic graphics to the screen, such as debug lines (VIS).

The debug lines used in tilemaps are not working yet.
The code is extremely ugly and it needs some serious love. It's just a prof of concept for now, but it's not good. When showing debug tiles, the framerate dropped from 30 to 20 because the tilemap is being rendered twice.

I've left several TODOs and clues to refactor the code later.
Several method in the FlxRender class were renamed to better mimic BitmapData method names. I did that to make the new rendering pipeline look more similar to the old one Flixel was using.
The FlxCamera code is simpler and easier to understand regarding the GPU rendering. I've added the FlxTexture class that abstracts the concept of graphics (Bitmap or GPU texture).

FlxCamera should be tweaked in the future to use screen.texture instead of bgTexture. It should save some memory and performance.
@IQAndreas
Copy link
Member

Awesome work!

High five

I have never played with GPU rendering, so this is over my head. You are going to have to find someone else to do the double checking. Or if you have tested the code enough and feel comfortable that it is stable, I trust your judgement and coding. We can always open new issues and fix any unexpected bugs that arise further down the line.

Is there a flag or variable you can set to switch between Bitmap and GPU rendering, or is it always on?

@Beeblerox
Copy link

i want to play with your code this week (while i'm on vacation and have plenty of time), but can't promise anything

@Dovyski
Copy link
Member Author

Dovyski commented Sep 22, 2014

@IQAndreas Thanks! :D I will try to get as much feedback as I can (code review, play testing, etc) before merging this. If it is not stable/smooth enough, we can ship it as an experimental feature disabled by default.

s there a flag or variable you can set to switch between Bitmap and GPU rendering, or is it always on?

Yep, during the game creation, the last parameter of FlxGame is UseGPU:Boolean = false (GPU disabled by default).

@Beeblerox Awesome! Just let me know if you need anything.

@jboadas
Copy link

jboadas commented Sep 26, 2014

Nice news. While gpu render is better for mobile games, software render is better for web games, you are going to keep both renders ?

@Dovyski
Copy link
Member Author

Dovyski commented Sep 26, 2014

Yes, both renders are available. It's up to developers to choose the best one during the game creation.

@WingEraser
Copy link

How to get this running? I've download several Genome2D repositories, imported in FDT and FlixelCommuntiy got reference to them. Still getting error.

@Dovyski
Copy link
Member Author

Dovyski commented Sep 27, 2014

@WingEraser You have to download Genome2D SWC at build.genome2D.com and include it in your project. It should compile just fine after that. If you have any problems, let me know.

@WingEraser
Copy link

Downloaded. I'm not sure why there are a lot of errors which doesn't make sense. I'm better off getting rid of FDT4 and use other IDE.
A lot of changes has been made. It will cost me too much time to check all the changes. I cannot run Mode. Can you also do a PR for mode.

@Dovyski
Copy link
Member Author

Dovyski commented Sep 29, 2014

I've updated our fork of Mode to make it run against version 2.57 (with GPU support).

Using FlashDevelop, all you have to do is clone the dev branch and add Flixel code (Genome2D SWC is already included in the project).

@IQAndreas
Copy link
Member

Do you feel the the GPU support stable enough to be merged into dev? If so, would you like to merge it?

I have some free time this week (a rare commodity these days) and would like to spend it rearranging the functions, and merging some of Flixel Power Tools. I figured if these massive changes are merged, there will be less merge conflicts to deal with.

... all you have to do is clone the dev branch and add Flixel code (Genome2D SWC is already included in the project).

Actually, he would have to clone Dovyski:fix-issue-90 (add Dovyski/flixel as a remote, and checkout the fix-issue-90 branch); since this pull request hasn't been merged yet.

@Dovyski
Copy link
Member Author

Dovyski commented Oct 13, 2014

I think it is stable enough to be merged, but there are a few rough edges we need to smooth. I think it's a good idea to merge it now to avoid any merge conflicts. The GPU acceleration is disabled by default, so I think it will not bite anyone.

I will try to finish all my pending pull requests, so we can merge them as well.

@Dovyski Dovyski merged commit 49cbc56 into FlixelCommunity:dev Nov 15, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants