Class ModelBatch

    • Constructor Detail

      • ModelBatch

        public ModelBatch​(RenderContext context,
                          ShaderProvider shaderProvider)
        Construct a ModelBatch, using this constructor makes you responsible for calling context.begin() and context.end() yourself.
        Parameters:
        context - The RenderContext to use.
        shaderProvider - The ShaderProvider to use, will be disposed when this ModelBatch is disposed.
      • ModelBatch

        public ModelBatch​(RenderContext context,
                          RenderableSorter sorter)
        Construct a ModelBatch, using this constructor makes you responsible for calling context.begin() and context.end() yourself.
        Parameters:
        context - The RenderContext to use.
        sorter - The RenderableSorter to use.
      • ModelBatch

        public ModelBatch​(RenderContext context)
        Construct a ModelBatch, using this constructor makes you responsible for calling context.begin() and context.end() yourself.
        Parameters:
        context - The RenderContext to use.
      • ModelBatch

        public ModelBatch​(ShaderProvider shaderProvider)
        Construct a ModelBatch
        Parameters:
        shaderProvider - The ShaderProvider to use, will be disposed when this ModelBatch is disposed.
      • ModelBatch

        public ModelBatch​(FileHandle vertexShader,
                          FileHandle fragmentShader)
        Construct a ModelBatch with the default implementation and the specified ubershader. See DefaultShader for more information about using a custom ubershader. Requires OpenGL ES 2.0.
        Parameters:
        vertexShader - The FileHandle of the vertex shader to use.
        fragmentShader - The FileHandle of the fragment shader to use.
      • ModelBatch

        public ModelBatch​(java.lang.String vertexShader,
                          java.lang.String fragmentShader)
        Construct a ModelBatch with the default implementation and the specified ubershader. See DefaultShader for more information about using a custom ubershader. Requires OpenGL ES 2.0.
        Parameters:
        vertexShader - The vertex shader to use.
        fragmentShader - The fragment shader to use.
      • ModelBatch

        public ModelBatch()
        Construct a ModelBatch with the default implementation
    • Method Detail

      • begin

        public void begin​(Camera cam)
        Start rendering one or more Renderables. Use one of the render() methods to provide the renderables. Must be followed by a call to end(). The OpenGL context must not be altered between begin(Camera) and end().
        Parameters:
        cam - The Camera to be used when rendering and sorting.
      • setCamera

        public void setCamera​(Camera cam)
        Change the camera in between begin(Camera) and end(). This causes the batch to be flushed. Can only be called after the call to begin(Camera) and before the call to end().
        Parameters:
        cam - The new camera to use.
      • getCamera

        public Camera getCamera()
        Provides access to the current camera in between begin(Camera) and end(). Do not change the camera's values. Use setCamera(Camera), if you need to change the camera.
        Returns:
        The current camera being used or null if called outside begin(Camera) and end().
      • ownsRenderContext

        public boolean ownsRenderContext()
        Checks whether the RenderContext returned by getRenderContext() is owned and managed by this ModelBatch. When the RenderContext isn't owned by the ModelBatch, you are responsible for calling the RenderContext.begin() and RenderContext.end() methods yourself, as well as disposing the RenderContext.
        Returns:
        True if this ModelBatch owns the RenderContext, false otherwise.
      • flush

        public void flush()
        Flushes the batch, causing all Renderables in the batch to be rendered. Can only be called after the call to begin(Camera) and before the call to end().
      • end

        public void end()
        End rendering one or more Renderables. Must be called after a call to begin(Camera). This will flush the batch, causing any renderables provided using one of the render() methods to be rendered. After a call to this method the OpenGL context can be altered again.
      • render

        public <T extends RenderableProvider> void render​(java.lang.Iterable<T> renderableProviders,
                                                          Shader shader)
        Calls RenderableProvider.getRenderables(Array, Pool) and adds all returned Renderable instances to the current batch to be rendered. Any shaders set on the returned renderables will be replaced with the given Shader. Can only be called after a call to begin(Camera) and before a call to end().
        Parameters:
        renderableProviders - one or more renderable providers
        shader - the shader to use for the renderables
      • render

        public void render​(RenderableProvider renderableProvider,
                           Environment environment,
                           Shader shader)
        Calls RenderableProvider.getRenderables(Array, Pool) and adds all returned Renderable instances to the current batch to be rendered. Any environment set on the returned renderables will be replaced with the given environment. Any shaders set on the returned renderables will be replaced with the given Shader. Can only be called after a call to begin(Camera) and before a call to end().
        Parameters:
        renderableProvider - the renderable provider
        environment - the Environment to use for the renderables
        shader - the shader to use for the renderables
      • render

        public <T extends RenderableProvider> void render​(java.lang.Iterable<T> renderableProviders,
                                                          Environment environment,
                                                          Shader shader)
        Calls RenderableProvider.getRenderables(Array, Pool) and adds all returned Renderable instances to the current batch to be rendered. Any environment set on the returned renderables will be replaced with the given environment. Any shaders set on the returned renderables will be replaced with the given Shader. Can only be called after a call to begin(Camera) and before a call to end().
        Parameters:
        renderableProviders - one or more renderable providers
        environment - the Environment to use for the renderables
        shader - the shader to use for the renderables
      • dispose

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