public class ModelCache extends java.lang.Object implements Disposable, RenderableProvider
Renderable.worldTransform might not be suitable for sorting anymore (such
as the default sorter of ModelBatch does).| Modifier and Type | Class and Description |
|---|---|
static interface |
ModelCache.MeshPool
Allows to reuse one or more meshes while avoiding creating new objects.
|
static class |
ModelCache.SimpleMeshPool
A basic
ModelCache.MeshPool implementation that avoids creating new meshes at the cost of memory usage. |
static class |
ModelCache.Sorter
A
RenderableSorter that sorts by vertex attributes, material attributes and primitive types (in that order), so that
meshes can be easily merged. |
static class |
ModelCache.TightMeshPool
A tight
ModelCache.MeshPool implementation, which is typically used for static meshes (create once, use many). |
| Constructor and Description |
|---|
ModelCache()
Create a ModelCache using the default
ModelCache.Sorter and the ModelCache.SimpleMeshPool implementation. |
ModelCache(RenderableSorter sorter,
ModelCache.MeshPool meshPool)
Create a ModelCache using the specified
RenderableSorter and ModelCache.MeshPool implementation. |
| Modifier and Type | Method and Description |
|---|---|
<T extends RenderableProvider> |
add(java.lang.Iterable<T> renderableProviders)
Adds the specified
RenderableProviders to the cache, see add(Renderable). |
void |
add(Renderable renderable)
Adds the specified
Renderable to the cache. |
void |
add(RenderableProvider renderableProvider)
Adds the specified
RenderableProvider to the cache, see add(Renderable). |
void |
begin()
Begin creating the cache, must be followed by a call to
end(), in between these calls one or more calls to one of
the add(...) methods can be made. |
void |
begin(Camera camera)
Begin creating the cache, must be followed by a call to
end(), in between these calls one or more calls to one of
the add(...) methods can be made. |
void |
dispose()
Releases all resources of this object.
|
void |
end()
|
void |
getRenderables(Array<Renderable> renderables,
Pool<Renderable> pool)
Returns
Renderable instances. |
public ModelCache()
ModelCache.Sorter and the ModelCache.SimpleMeshPool implementation. This might not be the
most optimal implementation for you use-case, but should be good to start with.public ModelCache(RenderableSorter sorter, ModelCache.MeshPool meshPool)
RenderableSorter and ModelCache.MeshPool implementation. The
RenderableSorter implementation will be called with the camera specified in begin(Camera). By default this
will be null. The sorter is important for optimizing the cache. For the best result, make sure that renderables that can be
merged are next to each other.public void begin()
end(), in between these calls one or more calls to one of
the add(...) methods can be made. Calling this method will clear the cache and prepare it for creating a new cache. The
cache is not valid until the call to end() is made. Use one of the add methods (e.g. add(Renderable) or
add(RenderableProvider)) to add renderables to the cache.public void begin(Camera camera)
end(), in between these calls one or more calls to one of
the add(...) methods can be made. Calling this method will clear the cache and prepare it for creating a new cache. The
cache is not valid until the call to end() is made. Use one of the add methods (e.g. add(Renderable) or
add(RenderableProvider)) to add renderables to the cache.camera - The Camera that will passed to the RenderableSorterpublic void end()
public void add(Renderable renderable)
Renderable to the cache. Must be called in between a call to begin() and end().
All member objects might (depending on possibilities) be used by reference and should not change while the cache is used. If
the Renderable.bones member is not null then skinning is assumed and the renderable will be added as-is, by
reference. Otherwise the renderable will be merged with other renderables as much as possible, depending on the
Mesh.getVertexAttributes(), Renderable.material and primitiveType (in that order). The
Renderable.environment, Renderable.shader and Renderable.userData values (if any) are removed.renderable - The Renderable to add, should not change while the cache is needed.public void add(RenderableProvider renderableProvider)
RenderableProvider to the cache, see add(Renderable).public <T extends RenderableProvider> void add(java.lang.Iterable<T> renderableProviders)
RenderableProviders to the cache, see add(Renderable).public void getRenderables(Array<Renderable> renderables, Pool<Renderable> pool)
RenderableProviderRenderable instances. Renderables are obtained from the provided Pool and added to the provided
array. The Renderables obtained using Pool.obtain() will later be put back into the pool, do not store them
internally. The resulting array can be rendered via a ModelBatch.getRenderables in interface RenderableProviderrenderables - the output arraypool - the pool to obtain Renderables frompublic void dispose()
Disposabledispose in interface Disposable