Package com.badlogic.gdx.graphics.g3d
Class ModelBatch
- java.lang.Object
-
- com.badlogic.gdx.graphics.g3d.ModelBatch
-
- All Implemented Interfaces:
Disposable
public class ModelBatch extends java.lang.Object implements Disposable
BatchesRenderable
instances, fetchesShader
s for them, sorts them and then renders them. Fetching the shaders is done using aShaderProvider
, which defaults toDefaultShaderProvider
. Sorting the renderables is done using aRenderableSorter
, which default toDefaultRenderableSorter
. The OpenGL context between thebegin(Camera)
andend()
call is maintained by theRenderContext
. To provide multipleRenderable
s at once aRenderableProvider
can be used, e.g. aModelInstance
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
ModelBatch.RenderablePool
-
Field Summary
Fields Modifier and Type Field Description protected Camera
camera
protected RenderContext
context
theRenderContext
protected Array<Renderable>
renderables
list of Renderables to be rendered in the current batchprotected ModelBatch.RenderablePool
renderablesPool
protected ShaderProvider
shaderProvider
theShaderProvider
, providesShader
instances for Renderablesprotected RenderableSorter
sorter
theRenderableSorter
-
Constructor Summary
Constructors Constructor Description ModelBatch()
Construct a ModelBatch with the default implementationModelBatch(FileHandle vertexShader, FileHandle fragmentShader)
Construct a ModelBatch with the default implementation and the specified ubershader.ModelBatch(RenderableSorter sorter)
Construct a ModelBatchModelBatch(RenderContext context)
Construct a ModelBatch, using this constructor makes you responsible for calling context.begin() and context.end() yourself.ModelBatch(RenderContext context, RenderableSorter sorter)
Construct a ModelBatch, using this constructor makes you responsible for calling context.begin() and context.end() yourself.ModelBatch(RenderContext context, ShaderProvider shaderProvider)
Construct a ModelBatch, using this constructor makes you responsible for calling context.begin() and context.end() yourself.ModelBatch(RenderContext context, ShaderProvider shaderProvider, RenderableSorter sorter)
Construct a ModelBatch, using this constructor makes you responsible for calling context.begin() and context.end() yourself.ModelBatch(ShaderProvider shaderProvider)
Construct a ModelBatchModelBatch(ShaderProvider shaderProvider, RenderableSorter sorter)
Construct a ModelBatchModelBatch(java.lang.String vertexShader, java.lang.String fragmentShader)
Construct a ModelBatch with the default implementation and the specified ubershader.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
begin(Camera cam)
Start rendering one or moreRenderable
s.void
dispose()
Releases all resources of this object.void
end()
End rendering one or moreRenderable
s.void
flush()
Flushes the batch, causing allRenderable
s in the batch to be rendered.Camera
getCamera()
Provides access to the current camera in betweenbegin(Camera)
andend()
.RenderableSorter
getRenderableSorter()
RenderContext
getRenderContext()
ShaderProvider
getShaderProvider()
boolean
ownsRenderContext()
Checks whether theRenderContext
returned bygetRenderContext()
is owned and managed by this ModelBatch.void
render(Renderable renderable)
Add a singleRenderable
to the batch.void
render(RenderableProvider renderableProvider)
CallsRenderableProvider.getRenderables(Array, Pool)
and adds all returnedRenderable
instances to the current batch to be rendered.void
render(RenderableProvider renderableProvider, Environment environment)
CallsRenderableProvider.getRenderables(Array, Pool)
and adds all returnedRenderable
instances to the current batch to be rendered.void
render(RenderableProvider renderableProvider, Environment environment, Shader shader)
CallsRenderableProvider.getRenderables(Array, Pool)
and adds all returnedRenderable
instances to the current batch to be rendered.void
render(RenderableProvider renderableProvider, Shader shader)
CallsRenderableProvider.getRenderables(Array, Pool)
and adds all returnedRenderable
instances to the current batch to be rendered.<T extends RenderableProvider>
voidrender(java.lang.Iterable<T> renderableProviders)
CallsRenderableProvider.getRenderables(Array, Pool)
and adds all returnedRenderable
instances to the current batch to be rendered.<T extends RenderableProvider>
voidrender(java.lang.Iterable<T> renderableProviders, Environment environment)
CallsRenderableProvider.getRenderables(Array, Pool)
and adds all returnedRenderable
instances to the current batch to be rendered.<T extends RenderableProvider>
voidrender(java.lang.Iterable<T> renderableProviders, Environment environment, Shader shader)
CallsRenderableProvider.getRenderables(Array, Pool)
and adds all returnedRenderable
instances to the current batch to be rendered.<T extends RenderableProvider>
voidrender(java.lang.Iterable<T> renderableProviders, Shader shader)
CallsRenderableProvider.getRenderables(Array, Pool)
and adds all returnedRenderable
instances to the current batch to be rendered.void
setCamera(Camera cam)
Change the camera in betweenbegin(Camera)
andend()
.
-
-
-
Field Detail
-
camera
protected Camera camera
-
renderablesPool
protected final ModelBatch.RenderablePool renderablesPool
-
renderables
protected final Array<Renderable> renderables
list of Renderables to be rendered in the current batch
-
context
protected final RenderContext context
theRenderContext
-
shaderProvider
protected final ShaderProvider shaderProvider
theShaderProvider
, providesShader
instances for Renderables
-
sorter
protected final RenderableSorter sorter
theRenderableSorter
-
-
Constructor Detail
-
ModelBatch
public ModelBatch(RenderContext context, ShaderProvider shaderProvider, RenderableSorter sorter)
Construct a ModelBatch, using this constructor makes you responsible for calling context.begin() and context.end() yourself.- Parameters:
context
- TheRenderContext
to use.shaderProvider
- TheShaderProvider
to use, will be disposed when this ModelBatch is disposed.sorter
- TheRenderableSorter
to use.
-
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
- TheRenderContext
to use.shaderProvider
- TheShaderProvider
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
- TheRenderContext
to use.sorter
- TheRenderableSorter
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
- TheRenderContext
to use.
-
ModelBatch
public ModelBatch(ShaderProvider shaderProvider, RenderableSorter sorter)
Construct a ModelBatch- Parameters:
shaderProvider
- TheShaderProvider
to use, will be disposed when this ModelBatch is disposed.sorter
- TheRenderableSorter
to use.
-
ModelBatch
public ModelBatch(RenderableSorter sorter)
Construct a ModelBatch- Parameters:
sorter
- TheRenderableSorter
to use.
-
ModelBatch
public ModelBatch(ShaderProvider shaderProvider)
Construct a ModelBatch- Parameters:
shaderProvider
- TheShaderProvider
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. SeeDefaultShader
for more information about using a custom ubershader. Requires OpenGL ES 2.0.- Parameters:
vertexShader
- TheFileHandle
of the vertex shader to use.fragmentShader
- TheFileHandle
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. SeeDefaultShader
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 moreRenderable
s. Use one of the render() methods to provide the renderables. Must be followed by a call toend()
. The OpenGL context must not be altered betweenbegin(Camera)
andend()
.- Parameters:
cam
- TheCamera
to be used when rendering and sorting.
-
setCamera
public void setCamera(Camera cam)
Change the camera in betweenbegin(Camera)
andend()
. This causes the batch to be flushed. Can only be called after the call tobegin(Camera)
and before the call toend()
.- Parameters:
cam
- The new camera to use.
-
getCamera
public Camera getCamera()
Provides access to the current camera in betweenbegin(Camera)
andend()
. Do not change the camera's values. UsesetCamera(Camera)
, if you need to change the camera.- Returns:
- The current camera being used or null if called outside
begin(Camera)
andend()
.
-
ownsRenderContext
public boolean ownsRenderContext()
Checks whether theRenderContext
returned bygetRenderContext()
is owned and managed by this ModelBatch. When the RenderContext isn't owned by the ModelBatch, you are responsible for calling theRenderContext.begin()
andRenderContext.end()
methods yourself, as well as disposing the RenderContext.- Returns:
- True if this ModelBatch owns the RenderContext, false otherwise.
-
getRenderContext
public RenderContext getRenderContext()
- Returns:
- the
RenderContext
used by this ModelBatch.
-
getShaderProvider
public ShaderProvider getShaderProvider()
- Returns:
- the
ShaderProvider
used by this ModelBatch.
-
getRenderableSorter
public RenderableSorter getRenderableSorter()
- Returns:
- the
RenderableSorter
used by this ModelBatch.
-
flush
public void flush()
Flushes the batch, causing allRenderable
s in the batch to be rendered. Can only be called after the call tobegin(Camera)
and before the call toend()
.
-
end
public void end()
End rendering one or moreRenderable
s. Must be called after a call tobegin(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 void render(Renderable renderable)
Add a singleRenderable
to the batch. TheShaderProvider
will be used to fetch a suitableShader
. Can only be called after a call tobegin(Camera)
and before a call toend()
.- Parameters:
renderable
- TheRenderable
to be added.
-
render
public void render(RenderableProvider renderableProvider)
CallsRenderableProvider.getRenderables(Array, Pool)
and adds all returnedRenderable
instances to the current batch to be rendered. Can only be called after a call tobegin(Camera)
and before a call toend()
.- Parameters:
renderableProvider
- the renderable provider
-
render
public <T extends RenderableProvider> void render(java.lang.Iterable<T> renderableProviders)
CallsRenderableProvider.getRenderables(Array, Pool)
and adds all returnedRenderable
instances to the current batch to be rendered. Can only be called after a call tobegin(Camera)
and before a call toend()
.- Parameters:
renderableProviders
- one or more renderable providers
-
render
public void render(RenderableProvider renderableProvider, Environment environment)
CallsRenderableProvider.getRenderables(Array, Pool)
and adds all returnedRenderable
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 tobegin(Camera)
and before a call toend()
.- Parameters:
renderableProvider
- the renderable providerenvironment
- theEnvironment
to use for the renderables
-
render
public <T extends RenderableProvider> void render(java.lang.Iterable<T> renderableProviders, Environment environment)
CallsRenderableProvider.getRenderables(Array, Pool)
and adds all returnedRenderable
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 tobegin(Camera)
and before a call toend()
.- Parameters:
renderableProviders
- one or more renderable providersenvironment
- theEnvironment
to use for the renderables
-
render
public void render(RenderableProvider renderableProvider, Shader shader)
CallsRenderableProvider.getRenderables(Array, Pool)
and adds all returnedRenderable
instances to the current batch to be rendered. Any shaders set on the returned renderables will be replaced with the givenShader
. Can only be called after a call tobegin(Camera)
and before a call toend()
.- Parameters:
renderableProvider
- the renderable providershader
- the shader to use for the renderables
-
render
public <T extends RenderableProvider> void render(java.lang.Iterable<T> renderableProviders, Shader shader)
CallsRenderableProvider.getRenderables(Array, Pool)
and adds all returnedRenderable
instances to the current batch to be rendered. Any shaders set on the returned renderables will be replaced with the givenShader
. Can only be called after a call tobegin(Camera)
and before a call toend()
.- Parameters:
renderableProviders
- one or more renderable providersshader
- the shader to use for the renderables
-
render
public void render(RenderableProvider renderableProvider, Environment environment, Shader shader)
CallsRenderableProvider.getRenderables(Array, Pool)
and adds all returnedRenderable
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 givenShader
. Can only be called after a call tobegin(Camera)
and before a call toend()
.- Parameters:
renderableProvider
- the renderable providerenvironment
- theEnvironment
to use for the renderablesshader
- the shader to use for the renderables
-
render
public <T extends RenderableProvider> void render(java.lang.Iterable<T> renderableProviders, Environment environment, Shader shader)
CallsRenderableProvider.getRenderables(Array, Pool)
and adds all returnedRenderable
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 givenShader
. Can only be called after a call tobegin(Camera)
and before a call toend()
.- Parameters:
renderableProviders
- one or more renderable providersenvironment
- theEnvironment
to use for the renderablesshader
- 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 interfaceDisposable
-
-