Class ModelCache

  • All Implemented Interfaces:
    RenderableProvider, Disposable

    public class ModelCache
    extends java.lang.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).
    • Method Detail

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