Class ShapeCache

  • All Implemented Interfaces:
    RenderableProvider, Disposable

    public class ShapeCache
    extends java.lang.Object
    implements Disposable, RenderableProvider
    A relatively lightweight class which can be used to render basic shapes which don't need a node structure and alike. Can be used for batching both static and dynamic shapes which share the same Material and transformation Matrix4 within the world. Use ModelBatch to render the `ShapeCache`. Must be disposed when no longer needed to release native resources.

    How to use it :

     // Create cache
     ShapeCache cache = new ShapeCache();
     // Build the cache, for dynamic shapes, this would be in the render method.
     MeshPartBuilder builder = cache.begin();
     FrustumShapeBuilder.build(builder, camera);
     BoxShapeBuilder.build(builder, box);
     cache.end()
     // Render
     modelBatch.render(cache);
     // After using it
     cache.dispose();
     
    • Constructor Detail

      • ShapeCache

        public ShapeCache()
        Create a ShapeCache with default values
      • ShapeCache

        public ShapeCache​(int maxVertices,
                          int maxIndices,
                          VertexAttributes attributes,
                          int primitiveType)
        Create a ShapeCache with parameters
        Parameters:
        maxVertices - max vertices in mesh
        maxIndices - max indices in mesh
        attributes - vertex attributes
        primitiveType -
    • Method Detail

      • begin

        public MeshPartBuilder begin()
        Initialize ShapeCache for mesh generation with GL_LINES primitive type
      • begin

        public MeshPartBuilder begin​(int primitiveType)
        Initialize ShapeCache for mesh generation
        Parameters:
        primitiveType - OpenGL primitive type
      • end

        public void end()
        Generate mesh and 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
      • getMaterial

        public Material getMaterial()
        Allows to customize the material.
        Returns:
        material
      • getWorldTransform

        public Matrix4 getWorldTransform()
        Allows to customize the world transform matrix.
        Returns:
        world transform
      • dispose

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