BillboardSpriteBatch now manages it's own DecalBatch instance
DecalBatch doesn't really contain too many useful properties/methods by itself which really warrant having both of these objects being managed separately
This commit is contained in:
parent
a685be02fb
commit
f623a1f883
|
@ -8,8 +8,10 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
import com.badlogic.gdx.graphics.g3d.decals.Decal;
|
import com.badlogic.gdx.graphics.g3d.decals.Decal;
|
||||||
import com.badlogic.gdx.graphics.g3d.decals.DecalBatch;
|
import com.badlogic.gdx.graphics.g3d.decals.DecalBatch;
|
||||||
import com.badlogic.gdx.graphics.g3d.decals.DecalMaterial;
|
import com.badlogic.gdx.graphics.g3d.decals.DecalMaterial;
|
||||||
|
import com.badlogic.gdx.graphics.g3d.decals.GroupStrategy;
|
||||||
import com.badlogic.gdx.math.Vector3;
|
import com.badlogic.gdx.math.Vector3;
|
||||||
import com.badlogic.gdx.utils.Array;
|
import com.badlogic.gdx.utils.Array;
|
||||||
|
import com.badlogic.gdx.utils.Disposable;
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -18,7 +20,7 @@ import com.badlogic.gdx.utils.Array;
|
||||||
* as easy as rendering 2D sprites is with SpriteBatch / DelayedSpriteBatch.
|
* as easy as rendering 2D sprites is with SpriteBatch / DelayedSpriteBatch.
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public class BillboardSpriteBatch {
|
public class BillboardSpriteBatch implements Disposable {
|
||||||
public enum Type {
|
public enum Type {
|
||||||
Spherical,
|
Spherical,
|
||||||
Cylindrical,
|
Cylindrical,
|
||||||
|
@ -31,8 +33,8 @@ public class BillboardSpriteBatch {
|
||||||
Array<Decal> sprites;
|
Array<Decal> sprites;
|
||||||
int pointer;
|
int pointer;
|
||||||
boolean hasBegun;
|
boolean hasBegun;
|
||||||
DecalBatch decalBatch;
|
final AlphaTestCameraGroupStrategy groupStrategy;
|
||||||
Camera camera;
|
final DecalBatch decalBatch;
|
||||||
|
|
||||||
public BillboardSpriteBatch() {
|
public BillboardSpriteBatch() {
|
||||||
sprites = new Array<Decal>(true, CAPACITY_INCREMENT, Decal.class);
|
sprites = new Array<Decal>(true, CAPACITY_INCREMENT, Decal.class);
|
||||||
|
@ -40,19 +42,17 @@ public class BillboardSpriteBatch {
|
||||||
addNewSprites(CAPACITY_INCREMENT);
|
addNewSprites(CAPACITY_INCREMENT);
|
||||||
|
|
||||||
hasBegun = false;
|
hasBegun = false;
|
||||||
decalBatch = null;
|
groupStrategy = new AlphaTestCameraGroupStrategy(null);
|
||||||
|
decalBatch = new DecalBatch(groupStrategy);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void begin(DecalBatch decalBatch, Camera camera) {
|
public void begin(Camera camera) {
|
||||||
if (hasBegun)
|
if (hasBegun)
|
||||||
throw new IllegalStateException("Cannot be called within an existing begin/end block.");
|
throw new IllegalStateException("Cannot be called within an existing begin/end block.");
|
||||||
if (decalBatch == null)
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
if (camera == null)
|
if (camera == null)
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
|
|
||||||
this.decalBatch = decalBatch;
|
groupStrategy.setCamera(camera);
|
||||||
this.camera = camera;
|
|
||||||
hasBegun = true;
|
hasBegun = true;
|
||||||
pointer = 0;
|
pointer = 0;
|
||||||
}
|
}
|
||||||
|
@ -138,9 +138,6 @@ public class BillboardSpriteBatch {
|
||||||
flush();
|
flush();
|
||||||
|
|
||||||
hasBegun = false;
|
hasBegun = false;
|
||||||
// don't need to hold on to these references anymore
|
|
||||||
decalBatch = null;
|
|
||||||
camera = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setTexture(Decal decal, Texture texture) {
|
private void setTexture(Decal decal, Texture texture) {
|
||||||
|
@ -174,6 +171,8 @@ public class BillboardSpriteBatch {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setRotation(Decal decal, Type type) {
|
private void setRotation(Decal decal, Type type) {
|
||||||
|
Camera camera = groupStrategy.getCamera();
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Spherical:
|
case Spherical:
|
||||||
decal.lookAt(camera.position, Vector3.Y);
|
decal.lookAt(camera.position, Vector3.Y);
|
||||||
|
@ -231,4 +230,10 @@ public class BillboardSpriteBatch {
|
||||||
pointer++;
|
pointer++;
|
||||||
return usable;
|
return usable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dispose() {
|
||||||
|
decalBatch.dispose();
|
||||||
|
groupStrategy.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue