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
BatchesRenderableinstances, fetchesShaders 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 multipleRenderables at once aRenderableProvidercan be used, e.g. aModelInstance.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classModelBatch.RenderablePool
-
Field Summary
Fields Modifier and Type Field Description protected Cameracameraprotected RenderContextcontexttheRenderContextprotected Array<Renderable>renderableslist of Renderables to be rendered in the current batchprotected ModelBatch.RenderablePoolrenderablesPoolprotected ShaderProvidershaderProvidertheShaderProvider, providesShaderinstances for Renderablesprotected RenderableSortersortertheRenderableSorter
-
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 voidbegin(Camera cam)Start rendering one or moreRenderables.voiddispose()Releases all resources of this object.voidend()End rendering one or moreRenderables.voidflush()Flushes the batch, causing allRenderables in the batch to be rendered.CameragetCamera()Provides access to the current camera in betweenbegin(Camera)andend().RenderableSortergetRenderableSorter()RenderContextgetRenderContext()ShaderProvidergetShaderProvider()booleanownsRenderContext()Checks whether theRenderContextreturned bygetRenderContext()is owned and managed by this ModelBatch.voidrender(Renderable renderable)Add a singleRenderableto the batch.voidrender(RenderableProvider renderableProvider)CallsRenderableProvider.getRenderables(Array, Pool)and adds all returnedRenderableinstances to the current batch to be rendered.voidrender(RenderableProvider renderableProvider, Environment environment)CallsRenderableProvider.getRenderables(Array, Pool)and adds all returnedRenderableinstances to the current batch to be rendered.voidrender(RenderableProvider renderableProvider, Environment environment, Shader shader)CallsRenderableProvider.getRenderables(Array, Pool)and adds all returnedRenderableinstances to the current batch to be rendered.voidrender(RenderableProvider renderableProvider, Shader shader)CallsRenderableProvider.getRenderables(Array, Pool)and adds all returnedRenderableinstances to the current batch to be rendered.<T extends RenderableProvider>
voidrender(java.lang.Iterable<T> renderableProviders)CallsRenderableProvider.getRenderables(Array, Pool)and adds all returnedRenderableinstances 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 returnedRenderableinstances 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 returnedRenderableinstances 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 returnedRenderableinstances to the current batch to be rendered.voidsetCamera(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, providesShaderinstances 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- TheRenderContextto use.shaderProvider- TheShaderProviderto use, will be disposed when this ModelBatch is disposed.sorter- TheRenderableSorterto 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- TheRenderContextto use.shaderProvider- TheShaderProviderto 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- TheRenderContextto use.sorter- TheRenderableSorterto 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- TheRenderContextto use.
-
ModelBatch
public ModelBatch(ShaderProvider shaderProvider, RenderableSorter sorter)
Construct a ModelBatch- Parameters:
shaderProvider- TheShaderProviderto use, will be disposed when this ModelBatch is disposed.sorter- TheRenderableSorterto use.
-
ModelBatch
public ModelBatch(RenderableSorter sorter)
Construct a ModelBatch- Parameters:
sorter- TheRenderableSorterto use.
-
ModelBatch
public ModelBatch(ShaderProvider shaderProvider)
Construct a ModelBatch- Parameters:
shaderProvider- TheShaderProviderto 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. SeeDefaultShaderfor more information about using a custom ubershader. Requires OpenGL ES 2.0.- Parameters:
vertexShader- TheFileHandleof the vertex shader to use.fragmentShader- TheFileHandleof 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. SeeDefaultShaderfor 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 moreRenderables. 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- TheCamerato 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 theRenderContextreturned 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
RenderContextused by this ModelBatch.
-
getShaderProvider
public ShaderProvider getShaderProvider()
- Returns:
- the
ShaderProviderused by this ModelBatch.
-
getRenderableSorter
public RenderableSorter getRenderableSorter()
- Returns:
- the
RenderableSorterused by this ModelBatch.
-
flush
public void flush()
Flushes the batch, causing allRenderables 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 moreRenderables. 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 singleRenderableto the batch. TheShaderProviderwill be used to fetch a suitableShader. Can only be called after a call tobegin(Camera)and before a call toend().- Parameters:
renderable- TheRenderableto be added.
-
render
public void render(RenderableProvider renderableProvider)
CallsRenderableProvider.getRenderables(Array, Pool)and adds all returnedRenderableinstances 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 returnedRenderableinstances 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 returnedRenderableinstances 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- theEnvironmentto 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 returnedRenderableinstances 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- theEnvironmentto use for the renderables
-
render
public void render(RenderableProvider renderableProvider, Shader shader)
CallsRenderableProvider.getRenderables(Array, Pool)and adds all returnedRenderableinstances 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 returnedRenderableinstances 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 returnedRenderableinstances 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- theEnvironmentto 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 returnedRenderableinstances 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- theEnvironmentto use for the renderablesshader- the shader to use for the renderables
-
dispose
public void dispose()
Description copied from interface:DisposableReleases all resources of this object.- Specified by:
disposein interfaceDisposable
-
-