j3d.org Aviatrix3D

org.j3d.aviatrix3d.surface
Class StereoAWTSurface

java.lang.Object
  extended byorg.j3d.aviatrix3d.surface.StereoAWTSurface
All Implemented Interfaces:
DrawableSurface, java.util.EventListener, net.java.games.jogl.GLEventListener

public class StereoAWTSurface
extends java.lang.Object
implements DrawableSurface, net.java.games.jogl.GLEventListener

Implementation of the most drawable surface, supporting stereo rendering capabilities.

This implementation of DrawableSurface renders to a normal GLCanvas instance and provides pBuffer support as needed. Stereo support is provided based on the underlying hardware capabilities in combination with the user requested features.

In implementing the alternate frame mode rendering, there's some odd artifacts/bugs in the rendering process. What seems to be happening is if we draw left and then right on the same canvas one after the other, the left one always gets drawn, and the right one is drawn, with the left cleared very quickly. The effect is that the right image is very prominent, but the left is almost not seen at all.

So, for now the implementation uses an internal flag to draw to alternate eyes on each alternate call to display() from the external rendering thread. This really slows the renderer down from a frame rate perspective, so make sure your rendering cycle time is halved if you are using that to control frame rate.

Version:
$Revision: 1.9 $
Author:
Justin Couch

Field Summary
 
Fields inherited from interface org.j3d.aviatrix3d.DrawableSurface
ALTERNATE_FRAME_STEREO, NO_STEREO, QUAD_BUFFER_STEREO, TWO_CANVAS_STEREO
 
Constructor Summary
StereoAWTSurface(net.java.games.jogl.GLCapabilities caps)
          Construct a surface that requires the given set of capabilities.
 
Method Summary
 void checkForExtension(java.lang.String glExtensionString)
          Add an extension string to check for at startup.
 void display(net.java.games.jogl.GLDrawable drawable)
          Not used in this implementation
 void displayChanged(net.java.games.jogl.GLDrawable drawable, boolean modeChanged, boolean deviceChanged)
          Not used in this implementation
 void dispose()
          Instruct this surface that you have finished with the resources needed and to dispose all rendering resources.
 void draw()
          Instruct the surface to draw the collected set of nodes now.
 void getCenterEyeInSurface(javax.vecmath.Point3f position)
          Get the Center Eye position in surface coordinates.
 void getPixelLocationInSurface(float x, float y, javax.vecmath.Point3f position)
          Convert a pixel location to surface coordinates.
 float getStereoEyeSeparation()
          Get the current eye separation value - always returns 0.
 int getStereoRenderingPolicy()
          Get the current stereo rendering policy in use.
 java.lang.Object getSurfaceObject()
          Get the underlying object that this surface is rendered to.
 void getSurfaceToVWorld(javax.vecmath.Matrix4f matrix)
          Get the surface to VWorld transformation matrix.
 void init(net.java.games.jogl.GLDrawable drawable)
          Called by the drawable immediately after the OpenGL context is initialized; the GLContext has already been made current when this method is called.
 boolean isQuadStereoAvailable()
          Check to see whether this surface supports Quad buffer stereo rendering.
 boolean isStereoAvailable()
          Check to see whether this surface supports stereo rendering.
 void queueDeletedObject(DeletableSceneGraphObject obj)
          An object has been detected as being deleted (no internal or external references to it left) and it needs to be cleaned up.
 void queueShaderRequests(ShaderSceneGraphObject[] initList, int numInit, ShaderSceneGraphObject[] logList, int numLog)
          Queue up a collection of shader objects for processing on the next frame.
 void reshape(net.java.games.jogl.GLDrawable drawable, int x, int y, int width, int height)
          Not used in this implementation
 void resychronizeRenderTarget()
          Resynchronise the stereo rendering to be the next frame as the left eye view.
 void setClearColor(float r, float g, float b, float a)
          Set the background colour that this surface should be cleared to before the drawing step.
 void setDrawableObjects(RenderInstructions[] commands, int numValid)
          Update the list of items to be rendered to the current list.
 void setRenderControlThread(java.lang.Thread th)
          Tell the surface to use the given thread as the rendering control thread.
 void setStereoEyeSeparation(float sep)
          Set the eye separation value when rendering stereo.
 void setStereoRenderingPolicy(int policy)
          Set the rendering policy used when handling stereo.
 void swap()
          Swap the buffers now if the surface supports multiple buffer drawing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StereoAWTSurface

public StereoAWTSurface(net.java.games.jogl.GLCapabilities caps)
Construct a surface that requires the given set of capabilities. Note that if you want to attempt quad buffered stereo, the capabilties need to be explicitly set up before calling this constructor.

Parameters:
caps - A set of required capabilities for this canvas.
Method Detail

isStereoAvailable

public boolean isStereoAvailable()
Check to see whether this surface supports stereo rendering. As this is not known until after initialisation, this method will return false until it can determine whether or not stereo is available.

Specified by:
isStereoAvailable in interface DrawableSurface
Returns:
true Stereo support is currently available

isQuadStereoAvailable

public boolean isQuadStereoAvailable()
Check to see whether this surface supports Quad buffer stereo rendering. Quadbuffers uses the GL_BACK_LEFT and GL_BACK_RIGHT for rendering pairs rather than drawing alternate frames to the same window.

As this is not known until after initialisation, this method will return false until it can determine whether or not stereo is available.

Specified by:
isQuadStereoAvailable in interface DrawableSurface
Returns:
true Stereo support is currently available

setStereoEyeSeparation

public void setStereoEyeSeparation(float sep)
Set the eye separation value when rendering stereo. The default value is 0.33 for most applications. The absolute value of the separation is always used. Ignored for this implementation.

Specified by:
setStereoEyeSeparation in interface DrawableSurface
Parameters:
sep - The amount of eye separation

getStereoEyeSeparation

public float getStereoEyeSeparation()
Get the current eye separation value - always returns 0.

Specified by:
getStereoEyeSeparation in interface DrawableSurface
Returns:
sep The amount of eye separation

setStereoRenderingPolicy

public void setStereoRenderingPolicy(int policy)
Set the rendering policy used when handling stereo. The policy must be one of the _STEREO constants defined in this interface.

Specified by:
setStereoRenderingPolicy in interface DrawableSurface
Parameters:
policy - The policy to currently use
Throws:
java.lang.IllegalArgumentException - The policy type is not one of the legal selections.

getStereoRenderingPolicy

public int getStereoRenderingPolicy()
Get the current stereo rendering policy in use. If not explicitly set by the user, then it will default to NO_STEREO.

Specified by:
getStereoRenderingPolicy in interface DrawableSurface
Returns:
One of the *_STEREO values

queueDeletedObject

public void queueDeletedObject(DeletableSceneGraphObject obj)
An object has been detected as being deleted (no internal or external references to it left) and it needs to be cleaned up. The next oppourtunity this drawable and any sub-drawables get, this object should have it's cleanup() method called and then the reference to it should be discarded.

Specified by:
queueDeletedObject in interface DrawableSurface
Parameters:
obj - The instance to be queued for deletion

queueShaderRequests

public void queueShaderRequests(ShaderSceneGraphObject[] initList,
                                int numInit,
                                ShaderSceneGraphObject[] logList,
                                int numLog)
Queue up a collection of shader objects for processing on the next frame. These processing requests are for either initialisation or log handling, not for rendering.

Specified by:
queueShaderRequests in interface DrawableSurface
Parameters:
initList - The shaders needing initialisation
numInit - The number of shaders needing initialisation
logList - The shaders needing log fetching
numLog - The number of shaders needing log fetching

setClearColor

public void setClearColor(float r,
                          float g,
                          float b,
                          float a)
Set the background colour that this surface should be cleared to before the drawing step. Colours range from 0 to 1 in the normal manner.

Specified by:
setClearColor in interface DrawableSurface
Parameters:
r - The red component of the background clear colour
g - The green component of the background clear colour
b - The blue component of the background clear colour
a - The alpha component of the background clear colour

setDrawableObjects

public void setDrawableObjects(RenderInstructions[] commands,
                               int numValid)
Update the list of items to be rendered to the current list. Draw them at the next oppourtunity.

Specified by:
setDrawableObjects in interface DrawableSurface
Parameters:
commands - The list of drawable surfaces to render
numValid - The number of valid items in the array

draw

public void draw()
Instruct the surface to draw the collected set of nodes now. The registered view environment is used to draw to this surface. If no view is registered, the surface is cleared and then this call is exited. The drawing surface does not swap the buffers at this point.

Specified by:
draw in interface DrawableSurface

swap

public void swap()
Swap the buffers now if the surface supports multiple buffer drawing. For surfaces that don't support multiple buffers, this does nothing.

Specified by:
swap in interface DrawableSurface

getSurfaceObject

public java.lang.Object getSurfaceObject()
Get the underlying object that this surface is rendered to. If it is a screen display device, the surface can be one of AWT Component or Swing JComponent. An off-screen buffer would be a form of AWT Image etc.

Specified by:
getSurfaceObject in interface DrawableSurface
Returns:
The drawable surface representation

getSurfaceToVWorld

public void getSurfaceToVWorld(javax.vecmath.Matrix4f matrix)
Get the surface to VWorld transformation matrix.

Specified by:
getSurfaceToVWorld in interface DrawableSurface
Parameters:
matrix - The matrix instance to copy into

getPixelLocationInSurface

public void getPixelLocationInSurface(float x,
                                      float y,
                                      javax.vecmath.Point3f position)
Convert a pixel location to surface coordinates.

Specified by:
getPixelLocationInSurface in interface DrawableSurface
Parameters:
x - The X coordinate
y - The Y coordinate
position - The converted position. It must be preallocated.

getCenterEyeInSurface

public void getCenterEyeInSurface(javax.vecmath.Point3f position)
Get the Center Eye position in surface coordinates.

Specified by:
getCenterEyeInSurface in interface DrawableSurface
Parameters:
position - The current eye position. It must be preallocated.

dispose

public void dispose()
Instruct this surface that you have finished with the resources needed and to dispose all rendering resources.

Specified by:
dispose in interface DrawableSurface

setRenderControlThread

public void setRenderControlThread(java.lang.Thread th)
Tell the surface to use the given thread as the rendering control thread. Used when you want to clock the renderer to the rest of the pipeline, rather than letting it sit in it's own loop. Due to bugs in JOGL, we have to start the internal rendering threads after the containing window has become visible. See JOGL issue #54 for more details on this bug.

Specified by:
setRenderControlThread in interface DrawableSurface
Parameters:
th - The render control thread instance to use or null

init

public void init(net.java.games.jogl.GLDrawable drawable)
Called by the drawable immediately after the OpenGL context is initialized; the GLContext has already been made current when this method is called.

Specified by:
init in interface net.java.games.jogl.GLEventListener
Parameters:
drawable - The display context to render to

reshape

public void reshape(net.java.games.jogl.GLDrawable drawable,
                    int x,
                    int y,
                    int width,
                    int height)
Not used in this implementation

Specified by:
reshape in interface net.java.games.jogl.GLEventListener
Parameters:
drawable - The display context to render to

displayChanged

public void displayChanged(net.java.games.jogl.GLDrawable drawable,
                           boolean modeChanged,
                           boolean deviceChanged)
Not used in this implementation

Specified by:
displayChanged in interface net.java.games.jogl.GLEventListener
Parameters:
drawable - The display context to render to

display

public void display(net.java.games.jogl.GLDrawable drawable)
Not used in this implementation

Specified by:
display in interface net.java.games.jogl.GLEventListener
Parameters:
drawable - The display context to render to

resychronizeRenderTarget

public void resychronizeRenderTarget()
Resynchronise the stereo rendering to be the next frame as the left eye view. Useful when the shutter glasses or other device needs to reset with the output.


checkForExtension

public void checkForExtension(java.lang.String glExtensionString)
Add an extension string to check for at startup.

Parameters:
glExtensionString - String to check for being valid

j3d.org Aviatrix3D

Latest Info from http://aviatrix3d.j3d.org/
Copyright © 2003 - j3d.org