com.jme.renderer.jogl
Class JOGLRenderer

java.lang.Object
  extended by com.jme.renderer.Renderer
      extended by com.jme.renderer.jogl.JOGLRenderer

public class JOGLRenderer
extends Renderer

JOGLRenderer provides an implementation of the Renderer interface using the JOGL API.

Version:
$Id: JOGLRenderer.java 4137 2009-03-20 18:38:24Z christoph.luder $
Author:
Mark Powell - initial implementation, and more., Joshua Slack - Further work, Optimizations, Headless rendering, Tijl Houtbeckers - Small optimizations and improved VBO, Steve Vaughan - JOGL port
See Also:
Renderer

Field Summary
protected  WeakIdentityCache<java.nio.Buffer,java.lang.Integer> vboMap
           
 
Fields inherited from class com.jme.renderer.Renderer
backgroundColor, camera, defaultStateList, height, processingQueue, queue, QUEUE_INHERIT, QUEUE_OPAQUE, QUEUE_ORTHO, QUEUE_SKIP, QUEUE_TRANSPARENT, width
 
Constructor Summary
JOGLRenderer(JOGLDisplaySystem display, JOGLContextCapabilities caps, int width, int height)
          Constructor instantiates a new JOGLRenderer object.
 
Method Summary
 void applyStates(RenderState[] states, Geometry geom)
          setStates applies the given states if and only if they are different from the currently set states.
 boolean checkAndAdd(Spatial s)
          checkAndAdd is used to process the Spatial for the render queue.
 void checkCardError()
          Check the underlying rendering system (opengl, etc.) for exceptions.
 void cleanup()
          Perform any necessary cleanup operations such as deleting VBOs, etc.
 void clearBuffers()
          clearBuffers clears both the color and the depth buffer.
 void clearColorBuffer()
          clearBackBuffer clears the OpenGL color buffer.
 void clearPolygonOffset()
          Removes any previously set offset from the renderer.
 void clearStencilBuffer()
          clearStencilBuffer
 void clearStrictBuffers()
          clearBuffers clears both the color and the depth buffer for only the part of the buffer defined by the renderer width/height.
 void clearVBOCache()
          Clears all entries from the VBO cache.
 void clearZBuffer()
          clearZBuffer clears the OpenGL depth buffer.
 BlendState createBlendState()
          createBlendState returns a new JOGLBlendState object as a regular BlendState.
 Camera createCamera(int width, int height)
          createCamera returns a default camera for use with the JOGL renderer.
 ClipState createClipState()
          createClipState returns a new JOGLClipState object as a regular ClipState.
 ColorMaskState createColorMaskState()
          createColorMaskState returns a new JOGLColorMaskState object as a regular ColorMaskState.
 CullState createCullState()
          createCullState returns a new JOGLCullState object as a regular CullState.
 int createDisplayList(Geometry g)
          Generate a DisplayList for drawing the given Geometry.
 FogState createFogState()
          createFogState returns a new JOGLFogState object as a regular FogState.
 FragmentProgramState createFragmentProgramState()
          createFragmentProgramState returns a new JOGLFragmentProgramState object as a regular FragmentProgramState.
 GLSLShaderObjectsState createGLSLShaderObjectsState()
          createShaderObjectsState returns a new JOGLShaderObjectsState object as a regular ShaderObjectsState.
 LightState createLightState()
          createLightState returns a new JOGLLightState object as a regular LightState.
 StateRecord createLineRecord()
           
 MaterialState createMaterialState()
          createMaterialState returns a new JOGLMaterialState object as a regular MaterialState.
 StateRecord createRendererRecord()
           
 ShadeState createShadeState()
          createShadeState returns a new JOGLShadeState object as a regular ShadeState.
 StencilState createStencilState()
          createStencilState returns a new JOGLStencilState object as a regular StencilState.
 StippleState createStippleState()
          createStippleState returns a new JOGLStippleState object as a regular StippleState.
 TextureState createTextureState()
          createTextureState returns a new JOGLTextureState object as a regular TextureState.
 VertexProgramState createVertexProgramState()
          createVertexProgramState returns a new JOGLVertexProgramState object as a regular VertexProgramState.
 WireframeState createWireframeState()
          createWireframeState returns a new JOGLWireframeState object as a regular WireframeState.
 ZBufferState createZBufferState()
          createZBufferState returns a new JOGLZBufferState object as a regular ZBufferState.
 void deleteVBO(java.nio.Buffer buffer)
          Checks the VBO cache to see if this Buffer is mapped to a VBO-id.
 void deleteVBO(int vboid)
          Attempts to delete the VBO with this VBO id.
 void displayBackBuffer()
          displayBackBuffer renders any queued items then flips the rendered buffer (back) with the currently displayed buffer.
protected  boolean doTransforms(Spatial t)
           
 void draw(Curve curve)
          draw renders a curve object.
 void draw(Line lines)
          draw renders a Line object including it's normals, colors, textures and vertices.
 void draw(Point points)
          draw renders a Point object including it's normals, colors, textures and vertices.
 void draw(QuadMesh quads)
          draw renders a QuadMesh object including it's normals, colors, textures and vertices.
 void draw(Spatial s)
          draw renders a scene by calling the nodes onDraw method.
 void draw(Text t)
          draw renders a text object using a predefined font.
 void draw(TriMesh tris)
          draw renders a TriMesh object including it's normals, colors, textures and vertices.
 void finish()
          finish is similar to flush, however it blocks until all waiting OpenGL commands have been finished.
 void flush()
          flush tells opengl to send through all currently waiting commands in the buffer.
 void grabScreenContents(java.nio.ByteBuffer buff, Image.Format format, int x, int y, int w, int h)
          grabScreenContents reads a block of pixels from the current framebuffer.
 boolean isInOrthoMode()
           
protected  void postdrawGeometry(Geometry g)
          re-initializes the GL context for rendering of another piece of geometry.
protected  boolean predrawGeometry(Geometry g)
          Prepares the GL Context for rendering this geometry.
protected  void prepVBO(Geometry g)
          prepVBO binds the geometry data to a vbo buffer and sends it to the GPU if necessary.
 void reinit(int width, int height)
          Reinitialize the renderer with the given width/height.
 void releaseDisplayList(int listId)
          Releases a DisplayList from the card.
 java.lang.Integer removeFromVBOCache(java.nio.Buffer buffer)
          Removes the mapping between this Buffer and it's VBO-id.
 void reset()
           
 void setBackgroundColor(ColorRGBA c)
          setBackgroundColor sets the OpenGL clear color to the color specified.
 void setCamera(Camera camera)
          setCamera sets the camera this renderer is using.
 void setOrtho()
          setOrtho sets the display system to be in orthographic mode.
 void setOrthoCenter()
          setOrthoCenter sets the display system to be in orthographic mode.
 void setPolygonOffset(float factor, float offset)
          Sets an offset to the zbuffer to be used when comparing an incoming polygon for depth buffer pass/fail.
 boolean supportsVBO()
          Return true if the system running this supports VBO
 boolean takeScreenShot(java.lang.String filename)
          takeScreenShot saves the current buffer to a file.
protected  void undoTransforms(Spatial t)
           
 void unsetOrtho()
          setOrthoCenter sets the display system to be in orthographic mode.
 void updateTextureSubImage(Texture dstTexture, int dstX, int dstY, Image srcImage, int srcX, int srcY, int width, int height)
          Updates a region of the content area of the provided texture using the specified region of the given data.
 
Methods inherited from class com.jme.renderer.Renderer
clearQueue, createState, createState, getBackgroundColor, getCamera, getHeight, getQueue, getWidth, isHeadless, isProcessingQueue, renderQueue, setHeadless
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

vboMap

protected WeakIdentityCache<java.nio.Buffer,java.lang.Integer> vboMap
Constructor Detail

JOGLRenderer

public JOGLRenderer(JOGLDisplaySystem display,
                    JOGLContextCapabilities caps,
                    int width,
                    int height)
Constructor instantiates a new JOGLRenderer object. The size of the rendering window is passed during construction.

Parameters:
width - the width of the rendering context.
height - the height of the rendering context. TODO Replace all of these fields with one surface reference? TODO If the capabilities are really context specific the field should be dropped.
Method Detail

reinit

public void reinit(int width,
                   int height)
Reinitialize the renderer with the given width/height. Also calls resize on the attached camera if present.

Specified by:
reinit in class Renderer
Parameters:
width - int
height - int

setCamera

public void setCamera(Camera camera)
setCamera sets the camera this renderer is using. It asserts that the camera is of type JOGLCamera.

Specified by:
setCamera in class Renderer
Parameters:
camera - the camera object to use with this Renderer.
See Also:
Renderer.setCamera(com.jme.renderer.Camera)

createCamera

public Camera createCamera(int width,
                           int height)
createCamera returns a default camera for use with the JOGL renderer.

Specified by:
createCamera in class Renderer
Parameters:
width - the width of the frame.
height - the height of the frame.
Returns:
a default JOGL camera.

createBlendState

public BlendState createBlendState()
createBlendState returns a new JOGLBlendState object as a regular BlendState.

Specified by:
createBlendState in class Renderer
Returns:
an BlendState object.

createCullState

public CullState createCullState()
createCullState returns a new JOGLCullState object as a regular CullState.

Specified by:
createCullState in class Renderer
Returns:
a CullState object.
See Also:
Renderer.createCullState()

createFogState

public FogState createFogState()
createFogState returns a new JOGLFogState object as a regular FogState.

Specified by:
createFogState in class Renderer
Returns:
an FogState object.

createLightState

public LightState createLightState()
createLightState returns a new JOGLLightState object as a regular LightState.

Specified by:
createLightState in class Renderer
Returns:
an LightState object.

createMaterialState

public MaterialState createMaterialState()
createMaterialState returns a new JOGLMaterialState object as a regular MaterialState.

Specified by:
createMaterialState in class Renderer
Returns:
an MaterialState object.

createShadeState

public ShadeState createShadeState()
createShadeState returns a new JOGLShadeState object as a regular ShadeState.

Specified by:
createShadeState in class Renderer
Returns:
an ShadeState object.

createTextureState

public TextureState createTextureState()
createTextureState returns a new JOGLTextureState object as a regular TextureState.

Specified by:
createTextureState in class Renderer
Returns:
an TextureState object.

createWireframeState

public WireframeState createWireframeState()
createWireframeState returns a new JOGLWireframeState object as a regular WireframeState.

Specified by:
createWireframeState in class Renderer
Returns:
an WireframeState object.

createZBufferState

public ZBufferState createZBufferState()
createZBufferState returns a new JOGLZBufferState object as a regular ZBufferState.

Specified by:
createZBufferState in class Renderer
Returns:
a ZBufferState object.

createVertexProgramState

public VertexProgramState createVertexProgramState()
createVertexProgramState returns a new JOGLVertexProgramState object as a regular VertexProgramState.

Specified by:
createVertexProgramState in class Renderer
Returns:
a JOGLVertexProgramState object.

createFragmentProgramState

public FragmentProgramState createFragmentProgramState()
createFragmentProgramState returns a new JOGLFragmentProgramState object as a regular FragmentProgramState.

Specified by:
createFragmentProgramState in class Renderer
Returns:
a JOGLFragmentProgramState object.

createGLSLShaderObjectsState

public GLSLShaderObjectsState createGLSLShaderObjectsState()
createShaderObjectsState returns a new JOGLShaderObjectsState object as a regular ShaderObjectsState.

Specified by:
createGLSLShaderObjectsState in class Renderer
Returns:
an ShaderObjectsState object.

createStencilState

public StencilState createStencilState()
createStencilState returns a new JOGLStencilState object as a regular StencilState.

Specified by:
createStencilState in class Renderer
Returns:
a StencilState object.

createClipState

public ClipState createClipState()
createClipState returns a new JOGLClipState object as a regular ClipState.

Specified by:
createClipState in class Renderer
Returns:
a ClipState object.
See Also:
Renderer.createClipState()

createColorMaskState

public ColorMaskState createColorMaskState()
createColorMaskState returns a new JOGLColorMaskState object as a regular ColorMaskState.

Specified by:
createColorMaskState in class Renderer
Returns:
a ColorMaskState object.

createStippleState

public StippleState createStippleState()
createStippleState returns a new JOGLStippleState object as a regular StippleState.

Specified by:
createStippleState in class Renderer
Returns:
a StippleState object.

setBackgroundColor

public void setBackgroundColor(ColorRGBA c)
setBackgroundColor sets the OpenGL clear color to the color specified.

Specified by:
setBackgroundColor in class Renderer
Parameters:
c - the color to set the background color to.
See Also:
Renderer.setBackgroundColor(com.jme.renderer.ColorRGBA)

clearZBuffer

public void clearZBuffer()
clearZBuffer clears the OpenGL depth buffer.

Specified by:
clearZBuffer in class Renderer
See Also:
Renderer.clearZBuffer()

clearColorBuffer

public void clearColorBuffer()
clearBackBuffer clears the OpenGL color buffer.

Specified by:
clearColorBuffer in class Renderer
See Also:
Renderer.clearColorBuffer()

clearStencilBuffer

public void clearStencilBuffer()
clearStencilBuffer

Specified by:
clearStencilBuffer in class Renderer
See Also:
Renderer.clearStencilBuffer()

clearBuffers

public void clearBuffers()
clearBuffers clears both the color and the depth buffer.

Specified by:
clearBuffers in class Renderer
See Also:
Renderer.clearBuffers()

clearStrictBuffers

public void clearStrictBuffers()
clearBuffers clears both the color and the depth buffer for only the part of the buffer defined by the renderer width/height.

Specified by:
clearStrictBuffers in class Renderer
See Also:
Renderer.clearBuffers()

displayBackBuffer

public void displayBackBuffer()
displayBackBuffer renders any queued items then flips the rendered buffer (back) with the currently displayed buffer.

Specified by:
displayBackBuffer in class Renderer
See Also:
Renderer.displayBackBuffer()

reset

public void reset()

isInOrthoMode

public boolean isInOrthoMode()
Specified by:
isInOrthoMode in class Renderer
Returns:
true if the renderer is currently in ortho mode.

setOrtho

public void setOrtho()
setOrtho sets the display system to be in orthographic mode. If the system has already been set to orthographic mode a JmeException is thrown. The origin (0,0) is the bottom left of the screen.

Specified by:
setOrtho in class Renderer

setOrthoCenter

public void setOrthoCenter()
Description copied from class: Renderer
setOrthoCenter sets the display system to be in orthographic mode. If the system has already been set to orthographic mode a JmeException is thrown. The origin (0,0) is the center of the screen.

Specified by:
setOrthoCenter in class Renderer

unsetOrtho

public void unsetOrtho()
setOrthoCenter sets the display system to be in orthographic mode. If the system has already been set to orthographic mode a JmeException is thrown. The origin (0,0) is the center of the screen.

Specified by:
unsetOrtho in class Renderer

takeScreenShot

public boolean takeScreenShot(java.lang.String filename)
takeScreenShot saves the current buffer to a file. The file name is provided, and .png will be appended. True is returned if the capture was successful, false otherwise.

Specified by:
takeScreenShot in class Renderer
Parameters:
filename - the name of the file to save.
Returns:
true if successful, false otherwise.

grabScreenContents

public void grabScreenContents(java.nio.ByteBuffer buff,
                               Image.Format format,
                               int x,
                               int y,
                               int w,
                               int h)
grabScreenContents reads a block of pixels from the current framebuffer.

Specified by:
grabScreenContents in class Renderer
Parameters:
buff - a buffer to store contents in.
format - the format to read
x - - x starting point of block
y - - y starting point of block
w - - width of block
h - - height of block

draw

public void draw(Curve curve)
draw renders a curve object.

Specified by:
draw in class Renderer
Parameters:
curve - the curve object to render.

draw

public void draw(Line lines)
draw renders a Line object including it's normals, colors, textures and vertices.

Specified by:
draw in class Renderer
Parameters:
lines - the lines to render.
See Also:
Renderer.draw(Line)

draw

public void draw(Point points)
draw renders a Point object including it's normals, colors, textures and vertices.

Specified by:
draw in class Renderer
Parameters:
points - the points to render.
See Also:
Renderer.draw(Point)

draw

public void draw(QuadMesh quads)
draw renders a QuadMesh object including it's normals, colors, textures and vertices.

Specified by:
draw in class Renderer
Parameters:
quads - the mesh to render.
See Also:
Renderer.draw(QuadMesh)

draw

public void draw(TriMesh tris)
draw renders a TriMesh object including it's normals, colors, textures and vertices.

Specified by:
draw in class Renderer
Parameters:
tris - the mesh to render.
See Also:
Renderer.draw(TriMesh)

prepVBO

protected void prepVBO(Geometry g)
prepVBO binds the geometry data to a vbo buffer and sends it to the GPU if necessary. The vbo id is stored in the geometry's VBOInfo class. If a new vbo id is created, the VBO is also stored in a cache. Before creating a new VBO this cache will be checked to see if a VBO is already created for that Buffer.

Parameters:
g - the geometry to initialize VBO for.

draw

public void draw(Spatial s)
draw renders a scene by calling the nodes onDraw method.

Specified by:
draw in class Renderer
Parameters:
s - the scene to render.
See Also:
Renderer.draw(com.jme.scene.Spatial)

draw

public void draw(Text t)
draw renders a text object using a predefined font.

Specified by:
draw in class Renderer
Parameters:
t - the text object to be rendered.
See Also:
Renderer.draw(com.jme.scene.Text)

checkAndAdd

public boolean checkAndAdd(Spatial s)
checkAndAdd is used to process the Spatial for the render queue. It's queue mode is checked, and it is added to the proper queue. If the queue mode is QUEUE_SKIP, false is returned.

Specified by:
checkAndAdd in class Renderer
Parameters:
s - Spatial to check
Returns:
true if the Spatial was added to a queue, false otherwise.

supportsVBO

public boolean supportsVBO()
Return true if the system running this supports VBO

Specified by:
supportsVBO in class Renderer
Returns:
boolean true if VBO supported

postdrawGeometry

protected void postdrawGeometry(Geometry g)
re-initializes the GL context for rendering of another piece of geometry.


flush

public void flush()
flush tells opengl to send through all currently waiting commands in the buffer.

Specified by:
flush in class Renderer

finish

public void finish()
finish is similar to flush, however it blocks until all waiting OpenGL commands have been finished.

Specified by:
finish in class Renderer

predrawGeometry

protected boolean predrawGeometry(Geometry g)
Prepares the GL Context for rendering this geometry. This involves initializing the VBO and obtaining the buffer data.

Parameters:
g - the geometry to process.
Returns:
true if VBO is used for indicis, false if not

doTransforms

protected boolean doTransforms(Spatial t)

undoTransforms

protected void undoTransforms(Spatial t)

createDisplayList

public int createDisplayList(Geometry g)
Description copied from class: Renderer
Generate a DisplayList for drawing the given Geometry.

Specified by:
createDisplayList in class Renderer
Parameters:
g - the geometry to make a display list for
Returns:
the id of the list

releaseDisplayList

public void releaseDisplayList(int listId)
Description copied from class: Renderer
Releases a DisplayList from the card.

Specified by:
releaseDisplayList in class Renderer
Parameters:
listId - the id of the display list to release

setPolygonOffset

public void setPolygonOffset(float factor,
                             float offset)
Description copied from class: Renderer
Sets an offset to the zbuffer to be used when comparing an incoming polygon for depth buffer pass/fail.

Specified by:
setPolygonOffset in class Renderer
Parameters:
factor - Specifies a scale factor that is used to create a variable depth offset for each polygon. The initial value is 0.
offset - Is multiplied by an implementation-specific value to create a constant depth offset. The initial value is 0.

clearPolygonOffset

public void clearPolygonOffset()
Description copied from class: Renderer
Removes any previously set offset from the renderer.

Specified by:
clearPolygonOffset in class Renderer

deleteVBO

public void deleteVBO(java.nio.Buffer buffer)
Description copied from class: Renderer
Checks the VBO cache to see if this Buffer is mapped to a VBO-id. If it does the mapping will be removed from the cache and the VBO with the VBO-id found will be deleted. If no mapped VBO-id is found, this method does not do anything else.

Specified by:
deleteVBO in class Renderer
Parameters:
buffer - The Buffer who's associated VBO should be deleted.
See Also:
Renderer.deleteVBO(Buffer)

deleteVBO

public void deleteVBO(int vboid)
Description copied from class: Renderer
Attempts to delete the VBO with this VBO id. Ignores ids < 1.

Specified by:
deleteVBO in class Renderer
See Also:
Renderer.deleteVBO(int)

clearVBOCache

public void clearVBOCache()
Description copied from class: Renderer
Clears all entries from the VBO cache. Does not actually delete any VBO buffer, only all mappings between Buffers and VBO-ids.

Specified by:
clearVBOCache in class Renderer
See Also:
Renderer.clearVBOCache()

removeFromVBOCache

public java.lang.Integer removeFromVBOCache(java.nio.Buffer buffer)
Description copied from class: Renderer
Removes the mapping between this Buffer and it's VBO-id. Does not actually delete the VBO.
This method is usefull if you want to use the same Buffer to create several VBOs. After a VBO is created for this Buffer, update the Buffer and remove it from the VBO cache. You can now reuse the same buffer with another Geometry object.
If no association is found, this method does nothing.

Specified by:
removeFromVBOCache in class Renderer
Parameters:
buffer - The nio Buffer whose associated VBO should be deleted.
Returns:
An int wrapped in an Integer object that's the VBO-id of the VBO previously mapped to this Buffer, or null is no mapping existed.
See Also:
Renderer.removeFromVBOCache(Buffer)

applyStates

public void applyStates(RenderState[] states,
                        Geometry geom)
setStates applies the given states if and only if they are different from the currently set states.


createLineRecord

public StateRecord createLineRecord()
Specified by:
createLineRecord in class Renderer
Returns:
a generated StateRecord representing gl line values for a gl context.

createRendererRecord

public StateRecord createRendererRecord()
Specified by:
createRendererRecord in class Renderer
Returns:
a generated StateRecord representing basic values for this renderer context.

updateTextureSubImage

public void updateTextureSubImage(Texture dstTexture,
                                  int dstX,
                                  int dstY,
                                  Image srcImage,
                                  int srcX,
                                  int srcY,
                                  int width,
                                  int height)
                           throws JmeException
Description copied from class: Renderer
Updates a region of the content area of the provided texture using the specified region of the given data.

Specified by:
updateTextureSubImage in class Renderer
Parameters:
dstTexture - the texture to be updated
dstX - the x offset relative to the lower-left corner of this texture where the update will be applied
dstY - the y offset relative to the lower-left corner of this texture where the update will be applied
srcImage - the image data to be uploaded to the texture
srcX - the x offset relative to the lower-left corner of the supplied buffer from which to fetch the update rectangle
srcY - the y offset relative to the lower-left corner of the supplied buffer from which to fetch the update rectangle
width - the width of the region to be updated
height - the height of the region to be updated
Throws:
JmeException - if unable to update the texture
See Also:
com.sun.opengl.util.texture.Texture#updateSubImage(com.sun.opengl.util.texture.TextureData, int, int, int, int, int, int, int)

checkCardError

public void checkCardError()
                    throws JmeException
Description copied from class: Renderer
Check the underlying rendering system (opengl, etc.) for exceptions.

Specified by:
checkCardError in class Renderer
Throws:
JmeException - if an error is found.

cleanup

public void cleanup()
Description copied from class: Renderer
Perform any necessary cleanup operations such as deleting VBOs, etc.

Specified by:
cleanup in class Renderer