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

FlxSprite.isSimpleRender() is nasty, causing implicit batch flushes! #78

Open
kamstrup opened this issue Nov 10, 2014 · 4 comments · May be fixed by #79
Open

FlxSprite.isSimpleRender() is nasty, causing implicit batch flushes! #78

kamstrup opened this issue Nov 10, 2014 · 4 comments · May be fixed by #79

Comments

@kamstrup
Copy link

I noticed that EVERY FlxSprite caused an implicit flush of the SpriteBatch on every draw() entirely defeating batching at all. After much chasing I discovered that the seemingly innocent FlxSprite.isSimpleRender() is a wolf in sheep's clothes.

Not only is it a boolean check that has major unexpected side effects (changing the rendering configuration!), it also assumes that calling batch.setShader(null) is a no-op if the shader already is null. This is not true. It causes a flush() no matter if you "change" it from null to null. This could be considered an issue in libgdx, but we have to deal with it.

I looked a bit at a solution, but since there is no way to pry the active shader config from the SpriteBatch, we have no sane way to tell if we need to clear the shader... Pondering this a bit, but good ideas welcome!

@kamstrup
Copy link
Author

For the record, I would expect an isXYZ() function to be simple ad side-effect-free, and more human readable, ala:

    @Override
    public boolean isSimpleRender()
    {
        boolean simpleGeometry = ((angle == 0) || (_bakedRotation > 0)) &&
                                 (scale.x == 1) && (scale.y == 1);
        boolean noBlend = (blend == null);
        boolean noShading = ((shader == null) && (blendGL20 == null) ||
                             (FlxG.batchShader != null && !ignoreBatchShader));

        return simpleGeometry &&
               noBlend &&
               noShading;
    }

The compiler/JIT will almost certainly optimize the temporary booleans away.

kamstrup pushed a commit to kamstrup/flixel-gdx that referenced this issue Nov 10, 2014
flush on EVERY call.

Make the function simple and readable, and defer render state
handling to where we already have it, in FlxSprite.draw().

Tested on my own games that uses rotating sprites and 1 shader.
Blending and other fancyness not tested, but I think it will work.

Fixes flixel-gdx#78
@kamstrup
Copy link
Author

Attached a pull request with my suggested fix. It has been tested on 2 of my games. Using rotating sprites and one using 1 shader (Spider Water Up! to render the water).

@ghost
Copy link

ghost commented Dec 13, 2014

Does this bug still exist?To know if I need to look up into it or not.

@WingEraser
Copy link
Member

kamstrup fixed for his game, but the OpenGL ES 2.0 doesn't work as before with this PR. You're welcome to look into it.

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 a pull request may close this issue.

2 participants