com.jme3.renderer
Interface Renderer

All Known Subinterfaces:
GL1Renderer
All Known Implementing Classes:
LwjglGL1Renderer, LwjglRenderer, NullRenderer, OGLESShaderRenderer

public interface Renderer

The Renderer is responsible for taking rendering commands and executing them on the underlying video hardware.


Method Summary
 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)
          Copies contents from src to dst, scaling if necessary.
 void copyFrameBuffer(FrameBuffer src, FrameBuffer dst, boolean copyDepth)
          Copies contents from src to dst, scaling if necessary.
 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.
 java.util.EnumSet<Caps> getCaps()
          Get the capabilities of the renderer.
 Statistics getStatistics()
          The statistics allow tracking of how data per frame, such as number of objects rendered, number of triangles, etc.
 void invalidateState()
          Invalidates the current rendering state.
 void onFrame()
          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 renderMesh(Mesh mesh, int lod, int count)
          Renders count meshes, with the geometry 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 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 setLighting(LightList lights)
          Set lighting state.
 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 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 setViewProjectionMatrices(Matrix4f viewMatrix, Matrix4f projMatrix)
          Sets the view and projection matrices to use.
 void setWorldMatrix(Matrix4f worldMatrix)
          Set the world matrix to use.
 void updateBufferData(VertexBuffer vb)
          Uploads a vertex buffer to the GPU.
 

Method Detail

getCaps

java.util.EnumSet<Caps> getCaps()
Get the capabilities of the renderer.

Returns:
The capabilities of the renderer.

getStatistics

Statistics getStatistics()
The statistics allow tracking of how data per frame, such as number of objects rendered, number of triangles, etc. These are updated when the Renderer's methods are used, make sure to call Statistics.clearFrame() at the appropriate time to get accurate info per frame.


invalidateState

void invalidateState()
Invalidates the current rendering state. Should be called after the GL state was changed manually or through an external library.


clearBuffers

void clearBuffers(boolean color,
                  boolean depth,
                  boolean stencil)
Clears certain channels of the currently bound framebuffer.

Parameters:
color - True if to clear colors (RGBA)
depth - True if to clear depth/z
stencil - True if to clear stencil buffer (if available, otherwise ignored)

setBackgroundColor

void setBackgroundColor(ColorRGBA color)
Sets the background (aka clear) color.

Parameters:
color - The background color to set

applyRenderState

void applyRenderState(RenderState state)
Applies the given RenderState, making the necessary GL calls so that the state is applied.


setDepthRange

void setDepthRange(float start,
                   float end)
Set the range of the depth values for objects. All rendered objects will have their depth clamped to this range.

Parameters:
start - The range start
end - The range end

onFrame

void onFrame()
Called when a new frame has been rendered.


setWorldMatrix

void setWorldMatrix(Matrix4f worldMatrix)
Set the world matrix to use. Does nothing if the Renderer is shader based.

Parameters:
worldMatrix - World matrix to use.

setViewProjectionMatrices

void setViewProjectionMatrices(Matrix4f viewMatrix,
                               Matrix4f projMatrix)
Sets the view and projection matrices to use. Does nothing if the Renderer is shader based.

Parameters:
viewMatrix - The view matrix to use.
projMatrix - The projection matrix to use.

setViewPort

void setViewPort(int x,
                 int y,
                 int width,
                 int height)
Set the viewport location and resolution on the screen.

Parameters:
x - The x coordinate of the viewport
y - The y coordinate of the viewport
width - Width of the viewport
height - Height of the viewport

setClipRect

void setClipRect(int x,
                 int y,
                 int width,
                 int height)
Specifies a clipping rectangle. For all future rendering commands, no pixels will be allowed to be rendered outside of the clip rectangle.

Parameters:
x - The x coordinate of the clip rect
y - The y coordinate of the clip rect
width - Width of the clip rect
height - Height of the clip rect

clearClipRect

void clearClipRect()
Clears the clipping rectangle set with setClipRect(int, int, int, int).


setLighting

void setLighting(LightList lights)
Set lighting state. Does nothing if the renderer is shader based. The lights should be provided in world space. Specify null to disable lighting.

Parameters:
lights - The light list to set.

setShader

void setShader(Shader shader)
Sets the shader to use for rendering. If the shader has not been uploaded yet, it is compiled and linked. If it has been uploaded, then the uniform data is updated and the shader is set.

Parameters:
shader - The shader to use for rendering.

deleteShader

void deleteShader(Shader shader)
Deletes a shader. This method also deletes the attached shader sources.

Parameters:
shader - Shader to delete.

deleteShaderSource

void deleteShaderSource(Shader.ShaderSource source)
Deletes the provided shader source.

Parameters:
source - The ShaderSource to delete.

copyFrameBuffer

void copyFrameBuffer(FrameBuffer src,
                     FrameBuffer dst)
Copies contents from src to dst, scaling if necessary.


copyFrameBuffer

void copyFrameBuffer(FrameBuffer src,
                     FrameBuffer dst,
                     boolean copyDepth)
Copies contents from src to dst, scaling if necessary. set copyDepth to false to only copy the color buffers.


setFrameBuffer

void setFrameBuffer(FrameBuffer fb)
Sets the framebuffer that will be drawn to.


setMainFrameBufferOverride

void setMainFrameBufferOverride(FrameBuffer fb)
Set the framebuffer that will be set instead of the main framebuffer when a call to setFrameBuffer(null) is made.

Parameters:
fb -

readFrameBuffer

void readFrameBuffer(FrameBuffer fb,
                     java.nio.ByteBuffer byteBuf)
Reads the pixels currently stored in the specified framebuffer into the given ByteBuffer object. Only color pixels are transferred, the format is BGRA with 8 bits per component. The given byte buffer should have at least fb.getWidth() * fb.getHeight() * 4 bytes remaining.

Parameters:
fb - The framebuffer to read from
byteBuf - The bytebuffer to transfer color data to

deleteFrameBuffer

void deleteFrameBuffer(FrameBuffer fb)
Deletes a framebuffer and all attached renderbuffers


setTexture

void setTexture(int unit,
                Texture tex)
Sets the texture to use for the given texture unit.


deleteImage

void deleteImage(Image image)
Deletes a texture from the GPU.


updateBufferData

void updateBufferData(VertexBuffer vb)
Uploads a vertex buffer to the GPU.

Parameters:
vb - The vertex buffer to upload

deleteBuffer

void deleteBuffer(VertexBuffer vb)
Deletes a vertex buffer from the GPU.

Parameters:
vb - The vertex buffer to delete

renderMesh

void renderMesh(Mesh mesh,
                int lod,
                int count)
Renders count meshes, with the geometry data supplied. The shader which is currently set with setShader is responsible for transforming the input verticies into clip space and shading it based on the given vertex attributes. The int variable gl_InstanceID can be used to access the current instance of the mesh being rendered inside the vertex shader.

Parameters:
mesh - The mesh to render
lod - The LOD level to use, see Mesh.setLodLevels(com.jme3.scene.VertexBuffer[]).
count - Number of mesh instances to render

resetGLObjects

void resetGLObjects()
Resets all previously used 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.

See Also:
NativeObject.resetObject()

cleanup

void cleanup()
Deletes all previously used Native Objects on this Renderer, and then resets the native objects.

See Also:
resetGLObjects(), NativeObject#deleteObject(com.jme3.renderer.Renderer)

setAlphaToCoverage

void setAlphaToCoverage(boolean value)
Sets the alpha to coverage state.

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.