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

Flambe doesn't batch the textures created using the "subTexture" function. #314

Open
aglitchman opened this issue Jan 7, 2015 · 6 comments · May be fixed by #318
Open

Flambe doesn't batch the textures created using the "subTexture" function. #314

aglitchman opened this issue Jan 7, 2015 · 6 comments · May be fixed by #318

Comments

@aglitchman
Copy link

When I enabled the flambe_debug_renderer, I noticed Flambe draws all animated
sprites individually.
Looks like Flambe doesn't batch the textures created using the "subTexture" function (flambe.swf.BitmapSymbol uses it). It should batch them because subtextures have same parent texture.

@markknol
Copy link
Contributor

markknol commented Jan 8, 2015

Could this gain performance?

@aglitchman
Copy link
Author

Yes!
OUYA showed 20 FPS when I added 50 different animated sprites from the same atlas (texture) to the stage. I temporarily fixed the bug by using this code (ImageSprite class):

    override public function draw (g :Graphics)
    {
        if (texture != null) {
            if (Std.is(texture, SubTexture)) {
                var sub = cast(texture, SubTexture);
                if (sub.parent != null) {
                    g.drawSubTexture(sub.parent, 0, 0, sub.x, sub.y, sub.width, sub.height);
                } else {
                    g.drawTexture(texture, 0, 0);
                }
            } else {
                g.drawTexture(texture, 0, 0);
            }
        }
    }

And now OUYA shows 60 FPS.

@markknol
Copy link
Contributor

markknol commented Jan 8, 2015

Wow that looks quite significant. @aduros should this be put on this spot?

@aduros
Copy link
Owner

aduros commented Jan 8, 2015

Looks like a possible bug. I think it should be fixed in Stage3DGraphics/Batcher rather than up in ImageSprite.

@volkipp
Copy link
Contributor

volkipp commented Jan 22, 2015

Does this code give you the same speedup? If you add this to Stage3DGraphics.hx (after the line that says root.assertNotDisposed() in drawSubTexture()):

        if (texture.parent != null) {
            sourceX += texture.x;
            sourceY += texture.y;
            texture = Lib.as(texture.parent, Stage3DTexture);
        }

@volkipp
Copy link
Contributor

volkipp commented Jan 22, 2015

Sorry to spam the topic, but maybe this would work better / instead? In Stage3DBatcher.hx replace prepareDrawTexture with this:

    public function prepareDrawTexture (renderTarget :Stage3DTextureRoot,
        blendMode :BlendMode, scissor :Rectangle, texture :Stage3DTexture) :Int
    {
        if (_lastTexture == null || texture.root != _lastTexture.root) {
            flush();
            _lastTexture = texture;
        }
        return prepareQuad(5, renderTarget, blendMode, scissor, _drawTextureShader);
    }

I'm assuming that we don't need call flush() if we are using the same texture root, which would skip the flush() calls for those subtextures. Or am I wrong?

@volkipp volkipp linked a pull request Jan 26, 2015 that will close this issue
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.

4 participants