Class ModelCache

java.lang.Object
com.badlogic.gdx.graphics.g3d.ModelCache
All Implemented Interfaces:
RenderableProvider, Disposable

public class ModelCache extends Object implements Disposable, RenderableProvider
ModelCache tries to combine multiple render calls into a single render call by merging them where possible. Can be used for multiple type of models (e.g. varying vertex attributes or materials), the ModelCache will combine where possible. Can be used dynamically (e.g. every frame) or statically (e.g. to combine part of scenery). Be aware that any combined vertices are directly transformed, therefore the resulting Renderable.worldTransform might not be suitable for sorting anymore (such as the default sorter of ModelBatch does).
  • Constructor Details

  • Method Details

    • begin

      public 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. 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.
    • begin

      public 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. 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.
      Parameters:
      camera - The Camera that will passed to the RenderableSorter
    • end

      public void end()
      Finishes creating the cache, must be called after a call to begin(), only after this call the cache will be valid (until the next call to begin()). Calling this method will process all renderables added using one of the add(...) methods and will combine them if possible.
    • add

      public void add(Renderable renderable)
      Adds the specified 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.
      Parameters:
      renderable - The Renderable to add, should not change while the cache is needed.
    • add

      public void add(RenderableProvider renderableProvider)
      Adds the specified RenderableProvider to the cache, see add(Renderable).
    • add

      public <T extends RenderableProvider> void add(Iterable<T> renderableProviders)
      Adds the specified RenderableProviders to the cache, see add(Renderable).
    • getRenderables

      public void getRenderables(Array<Renderable> renderables, Pool<Renderable> pool)
      Description copied from interface: RenderableProvider
      Returns Renderable 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.
      Specified by:
      getRenderables in interface RenderableProvider
      Parameters:
      renderables - the output array
      pool - the pool to obtain Renderables from
    • dispose

      public void dispose()
      Description copied from interface: Disposable
      Releases all resources of this object.
      Specified by:
      dispose in interface Disposable