public class ModelBatch extends java.lang.Object implements Disposable
Renderable
instances, fetches Shader
s 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 Renderable
s at once a RenderableProvider
can be used, e.g. a ModelInstance
.Modifier and Type | Field and Description |
---|---|
protected Camera |
camera |
protected RenderContext |
context
the
RenderContext |
protected Array<Renderable> |
renderables
list of Renderables to be rendered in the current batch
|
protected Pool<Renderable> |
renderablesPool |
protected Array<Renderable> |
reuseableRenderables
list of Renderables that can be put back into the pool
|
protected ShaderProvider |
shaderProvider
the
ShaderProvider , provides Shader instances for Renderables |
protected RenderableSorter |
sorter
the
RenderableSorter |
Constructor and Description |
---|
ModelBatch()
Construct a ModelBatch with the default implementation
|
ModelBatch(FileHandle vertexShader,
FileHandle fragmentShader)
Construct a ModelBatch with the default implementation and the specified ubershader.
|
ModelBatch(RenderContext context,
ShaderProvider shaderProvider,
RenderableSorter sorter)
Construct a ModelBatch, using this constructor makes you responsible for calling context.begin() and contact.end() yourself.
|
ModelBatch(ShaderProvider shaderProvider)
Construct a ModelBatch, using this constructor makes you responsible for calling context.begin() and contact.end() yourself.
|
ModelBatch(java.lang.String vertexShader,
java.lang.String fragmentShader)
Construct a ModelBatch with the default implementation and the specified ubershader.
|
Modifier and Type | Method and Description |
---|---|
void |
begin(Camera cam)
Start rendering one or more
Renderable s. |
void |
dispose()
Releases all resources of this object.
|
void |
end()
End rendering one or more
Renderable s. |
void |
flush()
Flushes the batch, causing all
Renderable s in the batch to be rendered. |
Camera |
getCamera()
Provides access to the current camera in between
begin(Camera) and end() . |
<T extends RenderableProvider> |
render(java.lang.Iterable<T> renderableProviders)
Calls
RenderableProvider.getRenderables(Array, Pool) and adds all returned Renderable
instances to the current batch to be rendered. |
<T extends RenderableProvider> |
render(java.lang.Iterable<T> renderableProviders,
Environment lights)
Calls
RenderableProvider.getRenderables(Array, Pool) and adds all returned Renderable
instances to the current batch to be rendered. |
<T extends RenderableProvider> |
render(java.lang.Iterable<T> renderableProviders,
Environment lights,
Shader shader)
Calls
RenderableProvider.getRenderables(Array, Pool) and adds all returned Renderable
instances to the current batch to be rendered. |
<T extends RenderableProvider> |
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. |
void |
render(Renderable renderable)
Add a single
Renderable to the batch. |
void |
render(RenderableProvider renderableProvider)
Calls
RenderableProvider.getRenderables(Array, Pool) and adds all returned Renderable
instances to the current batch to be rendered. |
void |
render(RenderableProvider renderableProvider,
Environment lights)
Calls
RenderableProvider.getRenderables(Array, Pool) and adds all returned Renderable
instances to the current batch to be rendered. |
void |
render(RenderableProvider renderableProvider,
Environment lights,
Shader shader)
Calls
RenderableProvider.getRenderables(Array, Pool) and adds all returned Renderable
instances to the current batch to be rendered. |
void |
render(RenderableProvider renderableProvider,
Shader shader)
Calls
RenderableProvider.getRenderables(Array, Pool) and adds all returned Renderable
instances to the current batch to be rendered. |
void |
setCamera(Camera cam)
Change the camera in between
begin(Camera) and end() . |
protected Camera camera
protected final Pool<Renderable> renderablesPool
protected final Array<Renderable> renderables
protected final Array<Renderable> reuseableRenderables
protected final RenderContext context
RenderContext
protected final ShaderProvider shaderProvider
ShaderProvider
, provides Shader
instances for Renderablesprotected final RenderableSorter sorter
RenderableSorter
public ModelBatch(RenderContext context, ShaderProvider shaderProvider, RenderableSorter sorter)
context
- The RenderContext
to use.shaderProvider
- The ShaderProvider
to use.sorter
- The RenderableSorter
to use.public ModelBatch(ShaderProvider shaderProvider)
shaderProvider
- The ShaderProvider
to use.public ModelBatch(FileHandle vertexShader, FileHandle fragmentShader)
DefaultShader
for
more information about using a custom ubershader. Requires OpenGL ES 2.0.vertexShader
- The FileHandle
of the vertex shader to use.fragmentShader
- The FileHandle
of the fragment shader to use.public ModelBatch(java.lang.String vertexShader, java.lang.String fragmentShader)
DefaultShader
for
more information about using a custom ubershader. Requires OpenGL ES 2.0.vertexShader
- The vertex shader to use.fragmentShader
- The fragment shader to use.public ModelBatch()
public void begin(Camera cam)
Renderable
s. 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()
.cam
- The Camera
to be used when rendering and sorting.public void setCamera(Camera cam)
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()
.cam
- The new camera to use.public Camera getCamera()
begin(Camera)
and end()
. Do not change
the camera's values. Use setCamera(Camera)
, if you need to change the camera.begin(Camera)
and end()
.public void flush()
Renderable
s in the batch to be rendered. Can only be called after the
call to begin(Camera)
and before the call to end()
.public void end()
Renderable
s. 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.public void render(Renderable renderable)
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()
.renderable
- The Renderable
to be added.public void render(RenderableProvider renderableProvider)
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()
.renderableProvider
- the renderable providerpublic <T extends RenderableProvider> void render(java.lang.Iterable<T> renderableProviders)
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()
.renderableProviders
- one or more renderable providerspublic void render(RenderableProvider renderableProvider, Environment lights)
RenderableProvider.getRenderables(Array, Pool)
and adds all returned Renderable
instances to the current batch to be rendered. Any lights set on the returned renderables will be replaced
with the given lights. Can only be called after a call to begin(Camera)
and before a call to end()
.renderableProvider
- the renderable providerlights
- the lights to use for the renderablespublic <T extends RenderableProvider> void render(java.lang.Iterable<T> renderableProviders, Environment lights)
RenderableProvider.getRenderables(Array, Pool)
and adds all returned Renderable
instances to the current batch to be rendered. Any lights set on the returned renderables will be replaced
with the given lights. Can only be called after a call to begin(Camera)
and before a call to end()
.renderableProviders
- one or more renderable providerslights
- the lights to use for the renderablespublic void render(RenderableProvider renderableProvider, Shader shader)
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()
.renderableProvider
- the renderable providershader
- the shader to use for the renderablespublic <T extends RenderableProvider> void render(java.lang.Iterable<T> renderableProviders, Shader shader)
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()
.renderableProviders
- one or more renderable providersshader
- the shader to use for the renderablespublic void render(RenderableProvider renderableProvider, Environment lights, Shader shader)
RenderableProvider.getRenderables(Array, Pool)
and adds all returned Renderable
instances to the current batch to be rendered. Any lights set on the returned renderables will be replaced
with the given lights. 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()
.renderableProvider
- the renderable providerlights
- the lights to use for the renderablesshader
- the shader to use for the renderablespublic <T extends RenderableProvider> void render(java.lang.Iterable<T> renderableProviders, Environment lights, Shader shader)
RenderableProvider.getRenderables(Array, Pool)
and adds all returned Renderable
instances to the current batch to be rendered. Any lights set on the returned renderables will be replaced
with the given lights. 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()
.renderableProviders
- one or more renderable providerslights
- the lights to use for the renderablesshader
- the shader to use for the renderablespublic void dispose()
Disposable
dispose
in interface Disposable