FlexBatch: Sprites with effects / batch anything

Any community contributions to libgdx go here! Some may get included in the core API when permission is granted.

FlexBatch: Sprites with effects / batch anything

Postby tenfour04 » Wed Jan 25, 2017 3:16 am

I put this library together because I wanted a way to easily draw bump-mapped sprites (or sprites with other types of effects), and SpriteBatch is too specialized for doing that easily. And then I realized there was a need for a tool that is flexible enough to easily tinker with different effects.

Image Image

FlexBatch works similarly to SpriteBatch, but it lets you easily draw sprites with custom vertex attributes and multi-texturing. The flexibility comes by subclassing a Batchable class to define the vertex attributes, textures, and OpenGL state. FlexBatch then sets itself up to batch that kind of object specifically.

There is a bit more method call overhead if you use the built-in batchable types as compared to SpriteBatch, but in most cases this is unlikely to be the bottleneck. And it's set up so you can come back later and write an optimized version of your Batchable implementation that doesn't have the extra method calls (if the need arises).

SpriteBatch has a lot of overloaded methods. FlexBatch instead uses method chaining to set Batchables' parameters, since it doesn't make sense to create a multitude of overloaded methods to cover all the possible combinations of parameters a Batchable might have.

Code: Select all
flexBatch.setProjectionMatrix(cam.combined);
flexBatch.begin();
flexBatch.draw().textureRegion(brickRegion).textureRegion(brickRegionNormals).position(5, 4).rotation(30);
flexBatch.end();


Since it's flexible, FlexBatch can also be used as a stand-in for DecalBatch (so you can draw 3D sprites with custom effects). There is also a special version of FlexBatch called CompliantBatch that can be used as a stand-in for SpriteBatch/PolygonSpriteBatch so it is compatible with the various LibGDX classes like Stage, BitmapFont, NinePatch, etc.

You can add it to your core gradle dependencies with:

Code: Select all
compile "com.cyphercove.gdx:flexbatch:1.0-SNAPSHOT"


The usage instructions are here. I'm sure this isn't quite adequately tested yet, so I'd love some feedback.
tenfour04
 
Posts: 1044
Joined: Sat Jun 18, 2011 3:24 pm

Re: FlexBatch: Sprites with effects / batch anything

Postby evilentity » Wed Jan 25, 2017 10:16 am

Looks cool!
Need a freelancer? PM me!
evilentity
 
Posts: 3582
Joined: Wed Aug 24, 2011 11:37 am

Re: FlexBatch: Sprites with effects / batch anything

Postby slebed » Thu Jan 26, 2017 6:49 pm

This looks great TenFour04! Can't wait to use this in my project
slebed
 
Posts: 175
Joined: Fri Dec 28, 2012 3:29 am

Re: FlexBatch: Sprites with effects / batch anything

Postby tenfour04 » Mon Mar 13, 2017 2:08 am

I released version 1.0 to Maven Central, so there's a firm base for usage.
tenfour04
 
Posts: 1044
Joined: Sat Jun 18, 2011 3:24 pm


Return to Libgdx Contributions

Who is online

Users browsing this forum: Majestic-12 [Bot] and 1 guest