-
-
Save flashingpumpkin/153d4bc319da0b0f9efd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Mesh implements Disposable { | |
public enum VertexDataType { | |
VertexArray, VertexBufferObject, VertexBufferObjectSubData, | |
} | |
/** list of all meshes **/ | |
static final Map<Application, List<Mesh>> meshes = new HashMap<Application, List<Mesh>>(); | |
/** used for benchmarking **/ | |
public static boolean forceVBO = false; | |
final VertexData vertices; | |
final IndexData indices; | |
boolean autoBind = true; | |
final boolean isVertexArray; | |
int refCount = 0; | |
/** Creates a new Mesh with the given attributes. | |
* | |
* @param isStatic whether this mesh is static or not. Allows for internal optimizations. | |
* @param maxVertices the maximum number of vertices this mesh can hold | |
* @param maxIndices the maximum number of indices this mesh can hold | |
* @param attributes the {@link VertexAttribute}s. Each vertex attribute defines one property of a vertex such as position, | |
* normal or texture coordinate */ | |
public Mesh (boolean isStatic, int maxVertices, int maxIndices, VertexAttribute... attributes) { | |
if (Gdx.gl20 != null || Gdx.gl11 != null || Mesh.forceVBO) { | |
vertices = new VertexBufferObject(isStatic, maxVertices, attributes); | |
indices = new IndexBufferObject(isStatic, maxIndices); | |
isVertexArray = false; | |
} else { | |
vertices = new VertexArray(maxVertices, attributes); | |
indices = new IndexBufferObject(maxIndices); | |
isVertexArray = true; | |
} | |
addManagedMesh(Gdx.app, this); | |
} | |
/** Creates a new Mesh with the given attributes. | |
* | |
* @param isStatic whether this mesh is static or not. Allows for internal optimizations. | |
* @param maxVertices the maximum number of vertices this mesh can hold | |
* @param maxIndices the maximum number of indices this mesh can hold | |
* @param attributes the {@link VertexAttributes}. Each vertex attribute defines one property of a vertex such as position, | |
* normal or texture coordinate */ | |
public Mesh (boolean isStatic, int maxVertices, int maxIndices, VertexAttributes attributes) { | |
if (Gdx.gl20 != null || Gdx.gl11 != null || Mesh.forceVBO) { | |
vertices = new VertexBufferObject(isStatic, maxVertices, attributes); | |
indices = new IndexBufferObject(isStatic, maxIndices); | |
isVertexArray = false; | |
} else { | |
vertices = new VertexArray(maxVertices, attributes); | |
indices = new IndexBufferObject(maxIndices); | |
isVertexArray = true; | |
} | |
addManagedMesh(Gdx.app, this); | |
} | |
/** Creates a new Mesh with the given attributes. This is an expert method with no error checking. Use at your own risk. | |
* | |
* @param type the {@link VertexDataType} to be used, VBO or VA. | |
* @param isStatic whether this mesh is static or not. Allows for internal optimizations. | |
* @param maxVertices the maximum number of vertices this mesh can hold | |
* @param maxIndices the maximum number of indices this mesh can hold | |
* @param attributes the {@link VertexAttribute}s. Each vertex attribute defines one property of a vertex such as position, | |
* normal or texture coordinate */ | |
public Mesh (VertexDataType type, boolean isStatic, int maxVertices, int maxIndices, VertexAttribute... attributes) { | |
if (type == VertexDataType.VertexArray && Gdx.graphics.isGL20Available()) type = VertexDataType.VertexBufferObject; | |
if (type == VertexDataType.VertexBufferObject) { | |
vertices = new VertexBufferObject(isStatic, maxVertices, attributes); | |
indices = new IndexBufferObject(isStatic, maxIndices); | |
isVertexArray = false; | |
} else if (type == VertexDataType.VertexBufferObjectSubData) { | |
vertices = new VertexBufferObjectSubData(isStatic, maxVertices, attributes); | |
indices = new IndexBufferObjectSubData(isStatic, maxIndices); | |
isVertexArray = false; | |
} else { | |
vertices = new VertexArray(maxVertices, attributes); | |
indices = new IndexBufferObject(maxIndices); | |
isVertexArray = true; | |
} | |
addManagedMesh(Gdx.app, this); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment