APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.badlogic.gdx.graphics.g3d

public Class ModelBatch

extends Object
implements Disposable
Class Inheritance
All Implemented Interfaces
com.badlogic.gdx.utils.Disposable
Imports
com.badlogic.gdx.files.FileHandle, com.badlogic.gdx.graphics.Camera, com.badlogic.gdx.graphics.g3d.shaders.DefaultShader, com.badlogic.gdx.graphics.g3d.utils.DefaultRenderableSorter, .DefaultShaderProvider, .DefaultTextureBinder, .RenderContext, .RenderableSorter, .ShaderProvider, com.badlogic.gdx.utils.Array, .Disposable, .FlushablePool, .GdxRuntimeException, .Pool

Batches Renderable instances, fetches Shaders for them, sorts them and then renders them. Fetching the shaders is done using a ShaderProvider, which defaults to DefaultShaderProvider. Sorting the renderables is done using a RenderableSorter, which default to DefaultRenderableSorter. The OpenGL context between the begin(Camera) and end() call is maintained by the RenderContext. To provide multiple Renderables at once a RenderableProvider can be used, e.g. a ModelInstance.
Author
xoppa, badlogic

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class

Field Summary

Modifier and TypeField and Description
protected Camera
protected final RenderContext
private final boolean
protected final Array<Renderable>
renderables

list of Renderables to be rendered in the current batch

protected final ModelBatch.RenderablePool
protected final ShaderProvider
shaderProvider

the ShaderProvider, provides Shader instances for Renderables

protected final RenderableSorter

Constructor Summary

AccessConstructor and Description
public
ModelBatch(final RenderContext
The RenderContext to use.
context
,
final ShaderProvider
The ShaderProvider to use, will be disposed when this ModelBatch is disposed.
shaderProvider
,
final RenderableSorter
The RenderableSorter to use.
sorter
)

Construct a ModelBatch, using this constructor makes you responsible for calling context.begin() and context.end() yourself.

public
ModelBatch(final RenderContext
The RenderContext to use.
context
,
final ShaderProvider
The ShaderProvider to use, will be disposed when this ModelBatch is disposed.
shaderProvider
)

Construct a ModelBatch, using this constructor makes you responsible for calling context.begin() and context.end() yourself.

public
ModelBatch(final RenderContext
The RenderContext to use.
context
,
final RenderableSorter
The RenderableSorter to use.
sorter
)

Construct a ModelBatch, using this constructor makes you responsible for calling context.begin() and context.end() yourself.

public
ModelBatch(final RenderContext
The RenderContext to use.
context
)

Construct a ModelBatch, using this constructor makes you responsible for calling context.begin() and context.end() yourself.

public
ModelBatch(final ShaderProvider
The ShaderProvider to use, will be disposed when this ModelBatch is disposed.
shaderProvider
,
final RenderableSorter
The RenderableSorter to use.
sorter
)

Construct a ModelBatch

public
ModelBatch(final RenderableSorter
The RenderableSorter to use.
sorter
)

Construct a ModelBatch

public
ModelBatch(final ShaderProvider
The ShaderProvider to use, will be disposed when this ModelBatch is disposed.
shaderProvider
)

Construct a ModelBatch

public
ModelBatch(final FileHandle
The FileHandle of the vertex shader to use.
vertexShader
,
final FileHandle
The FileHandle of the fragment shader to use.
fragmentShader
)

Construct a ModelBatch with the default implementation and the specified ubershader.

public
ModelBatch(final String
The vertex shader to use.
vertexShader
,
final String
The fragment shader to use.
fragmentShader
)

Construct a ModelBatch with the default implementation and the specified ubershader.

public
ModelBatch()

Construct a ModelBatch with the default implementation

Method Summary

Modifier and TypeMethod and Description
public void
begin(final Camera
The Camera to be used when rendering and sorting.
cam
)

Start rendering one or more Renderables.

public void
dispose()

Implements com.badlogic.gdx.utils.Disposable.dispose.

Releases all resources of this object.

public void
end()

End rendering one or more Renderables.

public void
flush()

Flushes the batch, causing all Renderables in the batch to be rendered.

public Camera

Returns:

The current camera being used or null if called outside begin(Camera) and end().
getCamera
()

Provides access to the current camera in between begin(Camera) and end().

public RenderableSorter
getRenderableSorter()

Returns: the RenderableSorter used by this ModelBatch.

public RenderContext
getRenderContext()

Returns: the RenderContext used by this ModelBatch.

public ShaderProvider
getShaderProvider()

Returns: the ShaderProvider used by this ModelBatch.

public boolean

Returns:

True if this ModelBatch owns the RenderContext, false otherwise.
ownsRenderContext
()

Checks whether the RenderContext returned by getRenderContext() is owned and managed by this ModelBatch.

public void
render(final Renderable
The Renderable to be added.
renderable
)

Add a single Renderable to the batch.

public void
render(final RenderableProvider
the renderable provider
renderableProvider
)

Calls RenderableProvider#getRenderables(Array, Pool) and adds all returned Renderable instances to the current batch to be rendered.

public <T extends RenderableProvider> void
render(final Iterable<T>
one or more renderable providers
renderableProviders
)

Calls RenderableProvider#getRenderables(Array, Pool) and adds all returned Renderable instances to the current batch to be rendered.

public void
render(final RenderableProvider
the renderable provider
renderableProvider
,
final Environment
the Environment to use for the renderables
environment
)

Calls RenderableProvider#getRenderables(Array, Pool) and adds all returned Renderable instances to the current batch to be rendered.

public <T extends RenderableProvider> void
render(final Iterable<T>
one or more renderable providers
renderableProviders
,
final Environment
the Environment to use for the renderables
environment
)

Calls RenderableProvider#getRenderables(Array, Pool) and adds all returned Renderable instances to the current batch to be rendered.

public void
render(final RenderableProvider
the renderable provider
renderableProvider
,
final Shader
the shader to use for the renderables
shader
)

Calls RenderableProvider#getRenderables(Array, Pool) and adds all returned Renderable instances to the current batch to be rendered.

public <T extends RenderableProvider> void
render(final Iterable<T>
one or more renderable providers
renderableProviders
,
final Shader
the shader to use for the renderables
shader
)

Calls RenderableProvider#getRenderables(Array, Pool) and adds all returned Renderable instances to the current batch to be rendered.

public void
render(final RenderableProvider
the renderable provider
renderableProvider
,
final Environment
the Environment to use for the renderables
environment
,
final Shader
the shader to use for the renderables
shader
)

Calls RenderableProvider#getRenderables(Array, Pool) and adds all returned Renderable instances to the current batch to be rendered.

public <T extends RenderableProvider> void
render(final Iterable<T>
one or more renderable providers
renderableProviders
,
final Environment
the Environment to use for the renderables
environment
,
final Shader
the shader to use for the renderables
shader
)

Calls RenderableProvider#getRenderables(Array, Pool) and adds all returned Renderable instances to the current batch to be rendered.

public void
setCamera(final Camera
The new camera to use.
cam
)

Change the camera in between begin(Camera) and end().

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cameraback to summary
protected Camera camera
contextback to summary
protected final RenderContext context

the RenderContext

ownContextback to summary
private final boolean ownContext
renderablesback to summary
protected final Array<Renderable> renderables

list of Renderables to be rendered in the current batch

renderablesPoolback to summary
protected final ModelBatch.RenderablePool renderablesPool
shaderProviderback to summary
protected final ShaderProvider shaderProvider

the ShaderProvider, provides Shader instances for Renderables

sorterback to summary
protected final RenderableSorter sorter

the RenderableSorter

Constructor Detail

ModelBatchback to summary
public ModelBatch(final RenderContext context, final ShaderProvider shaderProvider, final RenderableSorter sorter)

Construct a ModelBatch, using this constructor makes you responsible for calling context.begin() and context.end() yourself.

Parameters
context:RenderContext

The RenderContext to use.

shaderProvider:ShaderProvider

The ShaderProvider to use, will be disposed when this ModelBatch is disposed.

sorter:RenderableSorter

The RenderableSorter to use.

ModelBatchback to summary
public ModelBatch(final RenderContext context, final ShaderProvider shaderProvider)

Construct a ModelBatch, using this constructor makes you responsible for calling context.begin() and context.end() yourself.

Parameters
context:RenderContext

The RenderContext to use.

shaderProvider:ShaderProvider

The ShaderProvider to use, will be disposed when this ModelBatch is disposed.

ModelBatchback to summary
public ModelBatch(final RenderContext context, final RenderableSorter sorter)

Construct a ModelBatch, using this constructor makes you responsible for calling context.begin() and context.end() yourself.

Parameters
context:RenderContext

The RenderContext to use.

sorter:RenderableSorter

The RenderableSorter to use.

ModelBatchback to summary
public ModelBatch(final RenderContext context)

Construct a ModelBatch, using this constructor makes you responsible for calling context.begin() and context.end() yourself.

Parameters
context:RenderContext

The RenderContext to use.

ModelBatchback to summary
public ModelBatch(final ShaderProvider shaderProvider, final RenderableSorter sorter)

Construct a ModelBatch

Parameters
shaderProvider:ShaderProvider

The ShaderProvider to use, will be disposed when this ModelBatch is disposed.

sorter:RenderableSorter

The RenderableSorter to use.

ModelBatchback to summary
public ModelBatch(final RenderableSorter sorter)

Construct a ModelBatch

Parameters
sorter:RenderableSorter

The RenderableSorter to use.

ModelBatchback to summary
public ModelBatch(final ShaderProvider shaderProvider)

Construct a ModelBatch

Parameters
shaderProvider:ShaderProvider

The ShaderProvider to use, will be disposed when this ModelBatch is disposed.

ModelBatchback to summary
public ModelBatch(final FileHandle vertexShader, final 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:FileHandle

The FileHandle of the vertex shader to use.

fragmentShader:FileHandle

The FileHandle of the fragment shader to use.

ModelBatchback to summary
public ModelBatch(final String vertexShader, final 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:String

The vertex shader to use.

fragmentShader:String

The fragment shader to use.

ModelBatchback to summary
public ModelBatch()

Construct a ModelBatch with the default implementation

Method Detail

beginback to summary
public void begin(final 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:Camera

The Camera to be used when rendering and sorting.

disposeback to summary
public void dispose()

Implements com.badlogic.gdx.utils.Disposable.dispose.

Doc from com.badlogic.gdx.utils.Disposable.dispose.

Releases all resources of this object.

Annotations
@Override
endback to summary
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.

flushback to summary
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().

getCameraback to summary
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:Camera

The current camera being used or null if called outside begin(Camera) and end().

getRenderableSorterback to summary
public RenderableSorter getRenderableSorter()
Returns:RenderableSorter

the RenderableSorter used by this ModelBatch.

getRenderContextback to summary
public RenderContext getRenderContext()
Returns:RenderContext

the RenderContext used by this ModelBatch.

getShaderProviderback to summary
public ShaderProvider getShaderProvider()
Returns:ShaderProvider

the ShaderProvider used by this ModelBatch.

ownsRenderContextback to summary
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:boolean

True if this ModelBatch owns the RenderContext, false otherwise.

renderback to summary
public void render(final Renderable renderable)

Add a single Renderable to the batch. The ShaderProvider will be used to fetch a suitable Shader. Can only be called after a call to begin(Camera) and before a call to end().

Parameters
renderable:Renderable

The Renderable to be added.

renderback to summary
public void render(final RenderableProvider renderableProvider)

Calls RenderableProvider#getRenderables(Array, Pool) and adds all returned Renderable instances to the current batch to be rendered. Can only be called after a call to begin(Camera) and before a call to end().

Parameters
renderableProvider:RenderableProvider

the renderable provider

renderback to summary
public <T extends RenderableProvider> void render(final Iterable<T> renderableProviders)

Calls RenderableProvider#getRenderables(Array, Pool) and adds all returned Renderable instances to the current batch to be rendered. Can only be called after a call to begin(Camera) and before a call to end().

Parameters
renderableProviders:Iterable<T>

one or more renderable providers

renderback to summary
public void render(final RenderableProvider renderableProvider, final Environment environment)

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. Can only be called after a call to begin(Camera) and before a call to end().

Parameters
renderableProvider:RenderableProvider

the renderable provider

environment:Environment

the Environment to use for the renderables

renderback to summary
public <T extends RenderableProvider> void render(final Iterable<T> renderableProviders, final Environment environment)

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. Can only be called after a call to begin(Camera) and before a call to end().

Parameters
renderableProviders:Iterable<T>

one or more renderable providers

environment:Environment

the Environment to use for the renderables

renderback to summary
public void render(final RenderableProvider renderableProvider, final 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
renderableProvider:RenderableProvider

the renderable provider

shader:Shader

the shader to use for the renderables

renderback to summary
public <T extends RenderableProvider> void render(final Iterable<T> renderableProviders, final 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:Iterable<T>

one or more renderable providers

shader:Shader

the shader to use for the renderables

renderback to summary
public void render(final RenderableProvider renderableProvider, final Environment environment, final 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:RenderableProvider

the renderable provider

environment:Environment

the Environment to use for the renderables

shader:Shader

the shader to use for the renderables

renderback to summary
public <T extends RenderableProvider> void render(final Iterable<T> renderableProviders, final Environment environment, final 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:Iterable<T>

one or more renderable providers

environment:Environment

the Environment to use for the renderables

shader:Shader

the shader to use for the renderables

setCameraback to summary
public void setCamera(final 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:Camera

The new camera to use.

com.badlogic.gdx.graphics.g3d back to summary

protected Class ModelBatch.RenderablePool

extends FlushablePool<Renderable>
Class Inheritance

Field Summary

Inherited from com.badlogic.gdx.utils.FlushablePool:
obtained

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
protected Renderable
public Renderable
obtain()

Overrides com.badlogic.gdx.utils.FlushablePool.obtain.

Returns an object from this pool.

Inherited from com.badlogic.gdx.utils.FlushablePool:
flushfreefreeAll

Constructor Detail

RenderablePoolback to summary
protected RenderablePool()

Method Detail

newObjectback to summary
protected Renderable newObject()

Implements abstract com.badlogic.gdx.utils.Pool.newObject.

Annotations
@Override
obtainback to summary
public Renderable obtain()

Overrides com.badlogic.gdx.utils.FlushablePool.obtain.

Doc from com.badlogic.gdx.utils.Pool.obtain.

Returns an object from this pool. The object may be new (from newObject()) or reused (previously freed).

Annotations
@Override