public interface Renderer
Renderer
is responsible for taking rendering commands and
executing them on the underlying video hardware.Modifier and Type | Method and Description |
---|---|
void |
applyRenderState(RenderState state)
Applies the given
RenderState , making the necessary
GL calls so that the state is applied. |
void |
cleanup()
Deletes all previously used
Native Objects on this Renderer, and
then resets the native objects. |
void |
clearBuffers(boolean color,
boolean depth,
boolean stencil)
Clears certain channels of the currently bound framebuffer.
|
void |
clearClipRect()
Clears the clipping rectangle set with
setClipRect(int, int, int, int) . |
void |
copyFrameBuffer(FrameBuffer src,
FrameBuffer dst,
boolean copyDepth)
|
void |
copyFrameBuffer(FrameBuffer src,
FrameBuffer dst,
boolean copyColor,
boolean copyDepth)
Copies contents from src to dst, scaling if necessary.
|
void |
deleteBuffer(BufferObject bo)
Deletes the buffer object from the GPU.
|
void |
deleteBuffer(VertexBuffer vb)
Deletes a vertex buffer from the GPU.
|
void |
deleteFrameBuffer(FrameBuffer fb)
Deletes a framebuffer and all attached renderbuffers
|
void |
deleteImage(Image image)
Deletes a texture from the GPU.
|
void |
deleteShader(Shader shader)
Deletes a shader.
|
void |
deleteShaderSource(Shader.ShaderSource source)
Deletes the provided shader source.
|
int[] |
generateProfilingTasks(int numTasks)
Generates a pool of gpu queries meant to use as profiling tasks
|
boolean |
getAlphaToCoverage()
Gets the alpha to coverage state.
|
java.util.EnumSet<Caps> |
getCaps()
Get the capabilities of the renderer.
|
int |
getDefaultAnisotropicFilter()
Get the default anisotropic filter level for textures.
|
java.util.EnumMap<Limits,java.lang.Integer> |
getLimits()
Get the limits of the renderer.
|
long |
getProfilingTime(int taskId)
Returns the time in nano seconds elapsed for the task with the given id.
|
Statistics |
getStatistics()
The statistics allow tracking of how data
per frame, such as number of objects rendered, number of triangles, etc.
|
void |
initialize()
Detects available capabilities of the GPU.
|
void |
invalidateState()
Invalidates the current rendering state.
|
boolean |
isLinearizeSrgbImages()
Test whether images with the sRGB flag will be linearized when read by a
shader.
|
boolean |
isMainFrameBufferSrgb()
Test whether colors rendered to the main framebuffer undergo
linear-to-sRGB conversion.
|
boolean |
isTaskResultAvailable(int taskId)
Check if the profiling results are available
|
void |
modifyTexture(Texture tex,
Image pixels,
int x,
int y)
Modify the given Texture with the given Image.
|
void |
postFrame()
Called when a new frame has been rendered.
|
void |
readFrameBuffer(FrameBuffer fb,
java.nio.ByteBuffer byteBuf)
Reads the pixels currently stored in the specified framebuffer
into the given ByteBuffer object.
|
void |
readFrameBufferWithFormat(FrameBuffer fb,
java.nio.ByteBuffer byteBuf,
Image.Format format)
Reads the pixels currently stored in the specified framebuffer
into the given ByteBuffer object.
|
void |
renderMesh(Mesh mesh,
int lod,
int count,
VertexBuffer[] instanceData)
Renders
count meshes, with the geometry data supplied and
per-instance data supplied. |
void |
resetGLObjects()
Resets all previously used
Native Objects on this Renderer. |
void |
setAlphaToCoverage(boolean value)
Sets the alpha to coverage state.
|
void |
setBackgroundColor(ColorRGBA color)
Sets the background (aka clear) color.
|
void |
setClipRect(int x,
int y,
int width,
int height)
Specifies a clipping rectangle.
|
void |
setDefaultAnisotropicFilter(int level)
Set the default anisotropic filter level for textures.
|
void |
setDepthRange(float start,
float end)
Set the range of the depth values for objects.
|
void |
setFrameBuffer(FrameBuffer fb)
Sets the framebuffer that will be drawn to.
|
void |
setLinearizeSrgbImages(boolean linearize)
|
void |
setMainFrameBufferOverride(FrameBuffer fb)
Set the framebuffer that will be set instead of the main framebuffer
when a call to setFrameBuffer(null) is made.
|
void |
setMainFrameBufferSrgb(boolean srgb)
If enabled, color values rendered to the main framebuffer undergo
linear -> sRGB conversion.
|
void |
setShader(Shader shader)
Sets the shader to use for rendering.
|
void |
setTexture(int unit,
Texture tex)
Sets the texture to use for the given texture unit.
|
void |
setViewPort(int x,
int y,
int width,
int height)
Set the viewport location and resolution on the screen.
|
void |
startProfiling(int taskId)
Starts a time profiling task on the GPU.
|
void |
stopProfiling()
Will stop the last profiling task started with startProfiling
|
void |
updateBufferData(BufferObject bo)
Uploads data of the buffer object on the GPU.
|
void |
updateBufferData(VertexBuffer vb)
Uploads a vertex buffer to the GPU.
|
void initialize()
java.util.EnumSet<Caps> getCaps()
java.util.EnumMap<Limits,java.lang.Integer> getLimits()
Statistics getStatistics()
Statistics.clearFrame()
at the appropriate time
to get accurate info per frame.void invalidateState()
void clearBuffers(boolean color, boolean depth, boolean stencil)
color
- True if to clear colors (RGBA)depth
- True if to clear depth/zstencil
- True if to clear stencil buffer (if available, otherwise
ignored)void setBackgroundColor(ColorRGBA color)
color
- The background color to setvoid applyRenderState(RenderState state)
RenderState
, making the necessary
GL calls so that the state is applied.state
- the RenderState to applyvoid setDepthRange(float start, float end)
start
- The range startend
- The range endvoid postFrame()
void setViewPort(int x, int y, int width, int height)
x
- The x coordinate of the viewporty
- The y coordinate of the viewportwidth
- Width of the viewportheight
- Height of the viewportvoid setClipRect(int x, int y, int width, int height)
x
- The x coordinate of the clip recty
- The y coordinate of the clip rectwidth
- Width of the clip rectheight
- Height of the clip rectvoid clearClipRect()
setClipRect(int, int, int, int)
.void setShader(Shader shader)
shader
- The shader to use for rendering.void deleteShader(Shader shader)
shader
- Shader to delete.deleteShaderSource(com.jme3.shader.Shader.ShaderSource)
void deleteShaderSource(Shader.ShaderSource source)
source
- The ShaderSource to delete.@Deprecated void copyFrameBuffer(FrameBuffer src, FrameBuffer dst, boolean copyDepth)
copyFrameBuffer(com.jme3.texture.FrameBuffer, com.jme3.texture.FrameBuffer, boolean, boolean)
.src
- the source FrameBuffer (unaffected)dst
- the destination FrameBuffer (modified)copyDepth
- true→copy depth info, false→don't copy itvoid copyFrameBuffer(FrameBuffer src, FrameBuffer dst, boolean copyColor, boolean copyDepth)
src
- the source FrameBuffer (unaffected)dst
- the destination FrameBuffer (modified)copyColor
- true→copy color info, false→don't copy itcopyDepth
- true→copy depth info, false→don't copy itvoid setFrameBuffer(FrameBuffer fb)
fb
- The framebuffer to setvoid setMainFrameBufferOverride(FrameBuffer fb)
fb
- The framebuffer to override the main framebuffer.void readFrameBuffer(FrameBuffer fb, java.nio.ByteBuffer byteBuf)
fb
- The framebuffer to read frombyteBuf
- The bytebuffer to transfer color data tovoid readFrameBufferWithFormat(FrameBuffer fb, java.nio.ByteBuffer byteBuf, Image.Format format)
fb
- The framebuffer to read frombyteBuf
- The bytebuffer to transfer color data toformat
- the image format to use when reading the frameBuffer.void deleteFrameBuffer(FrameBuffer fb)
fb
- the FrameBuffer to be deletedvoid setTexture(int unit, Texture tex)
unit
- which unittex
- the Texture to usevoid modifyTexture(Texture tex, Image pixels, int x, int y)
tex
- the Texture that will be modifiedpixels
- the source Image data to copy data fromx
- the x position to put the image into the texturey
- the y position to put the image into the texturevoid deleteImage(Image image)
image
- the texture to deletevoid updateBufferData(VertexBuffer vb)
vb
- The vertex buffer to uploadvoid updateBufferData(BufferObject bo)
bo
- the buffer object to upload.void deleteBuffer(VertexBuffer vb)
vb
- The vertex buffer to deletevoid deleteBuffer(BufferObject bo)
bo
- the buffer object to delete.void renderMesh(Mesh mesh, int lod, int count, VertexBuffer[] instanceData)
count
meshes, with the geometry data supplied and
per-instance data supplied.
The shader which is currently set with setShader
is
responsible for transforming the input vertices into clip space
and shading it based on the given vertex attributes.
The integer variable gl_InstanceID can be used to access the current
instance of the mesh being rendered inside the vertex shader.
If the instance data is non-null, then it is submitted as a
per-instance vertex attribute to the shader.mesh
- The mesh to renderlod
- The LOD level to use, see Mesh.setLodLevels(com.jme3.scene.VertexBuffer[])
.count
- Number of mesh instances to renderinstanceData
- When count is greater than 1, these buffers provide
the per-instance attributes.void resetGLObjects()
Native Objects
on this Renderer.
The state of the native objects is reset in such way, that using
them again will cause the renderer to reupload them.
Call this method when you know the GL context is going to shutdown.NativeObject.resetObject()
void cleanup()
Native Objects
on this Renderer, and
then resets the native objects.void setDefaultAnisotropicFilter(int level)
texture anisotropic filter
is
set to 0, then the default level is used. Otherwise if the texture level
is 1 or greater, then the texture's value overrides the default value.level
- The default anisotropic filter level to use. Default: 1.java.lang.IllegalArgumentException
- If level is less than 1.void setAlphaToCoverage(boolean value)
When alpha coverage and multi-sampling is enabled, each pixel will contain alpha coverage in all of its subsamples, which is then combined when other future alpha-blended objects are rendered.
Alpha-to-coverage is useful for rendering transparent objects without having to worry about sorting them.
value
- true to enable alpha coverage, otherwise falsevoid setMainFrameBufferSrgb(boolean srgb)
FrameBuffer.setSrgb(boolean)
except it is toggled
for the main framebuffer instead of an offscreen buffer.
This should be set together with setLinearizeSrgbImages(boolean)
As a shorthand, the user can set AppSettings.setGammaCorrection(boolean)
to true
to toggle both setLinearizeSrgbImages(boolean)
and
setMainFrameBufferSrgb(boolean)
if the
Caps.Srgb
is supported by the GPU.srgb
- true for sRGB colorspace, false for linear colorspaceRendererException
- If the GPU hardware does not support sRGB.FrameBuffer.setSrgb(boolean)
,
Caps.Srgb
void setLinearizeSrgbImages(boolean linearize)
images
with the sRGB flag
set shall undergo an sRGB to linear RGB color conversion when read by a shader.
The conversion is performed for the following formats:
- Image.Format.RGB8
- Image.Format.RGBA8
- Image.Format.Luminance8
- Image.Format.Luminance8Alpha8
- Image.Format.DXT1
- Image.Format.DXT1A
- Image.Format.DXT3
- Image.Format.DXT5
For all other formats, no conversion is performed.
If this option is toggled at runtime, textures must be reloaded for the change to take effect.linearize
- If sRGB images undergo sRGB -> linear conversion prior to rendering.RendererException
- If the GPU hardware does not support sRGB.Caps.Srgb
int[] generateProfilingTasks(int numTasks)
numTasks
- the number of task ids to generatevoid startProfiling(int taskId)
taskId
- the id of the task to start profiling.void stopProfiling()
long getProfilingTime(int taskId)
taskId
- the id of the task given by startProfiling.boolean isTaskResultAvailable(int taskId)
taskId
- the id of the task provided by startProfilingboolean getAlphaToCoverage()
int getDefaultAnisotropicFilter()
boolean isLinearizeSrgbImages()
boolean isMainFrameBufferSrgb()