Aviatrix3D
2.0 Beta 2

org.j3d.aviatrix3d.output.graphics
Class BaseRenderingProcessor

java.lang.Object
  extended byorg.j3d.aviatrix3d.output.graphics.BaseRenderingProcessor
All Implemented Interfaces:
RenderingProcessor
Direct Known Subclasses:
DebugRenderingProcessor, ElumensRenderingProcessor, QuadBufferStereoProcessor, SingleEyeStereoProcessor, StandardRenderingProcessor

public abstract class BaseRenderingProcessor
extends java.lang.Object
implements RenderingProcessor

Common implementation for rendering handling to render for a single output device - be it on-screen or off.

This class implements everything except for the display() method of GLEventListener.

Version:
$Revision: 3.25 $
Author:
Alan Hudson

Field Summary
protected  boolean alwaysLocalClear
          Flag to say if we the default clear colour should be used, or if there is at least one background that we can make use of
protected  java.lang.Integer[] availableClips
          Stack of the available OGL clip IDs that could be assigned to clips
protected  java.lang.Integer[] availableLights
          Stack of the available OGL light IDs that could be assigned to lights
protected  float[] clearColor
          The current clear colour
protected  org.j3d.util.IntHashMap clipIdMap
          Mapping of the object ID to it's used clip ID
protected  java.lang.Integer currentShaderProgramId
          The current program ID for GLSLang shaders.
protected  float[] currentViewport
          Data describing the current viewport if explicit values used
protected  DeletableRenderable[] deleteQueue
          Queue for holding deleted textures
protected  GraphicsEnvironmentData[] environmentList
          Local storage of the environment data collections
protected  org.j3d.util.ErrorReporter errorReporter
          Error reporter used to send out messages
protected  float[] eyePoint
          The eye offset from the normal position
protected  javax.media.opengl.GLContext glContext
          The context from the drawable
protected  boolean initComplete
          Flag indicating if any initialisation has been performed yet.
protected static int INITIAL_DELETE_SIZE
          Initial size of the deletion queue array
protected static int INITIAL_PATH_DEPTH
          Initial depth for the number of transforms above a view,fog or bg
protected static java.lang.Integer INVALID_SHADER
          The invalid shader ID
protected  int lastClipIdx
          index in the availableClips list of the last available
protected  int lastLightIdx
          index in the availableLights list of the last available
protected  int lastShaderInitIdx
          The current place to add shader init requestors
protected  int lastShaderLogIdx
          The current place to add shader log requestors
protected  org.j3d.util.IntHashMap lightIdMap
          Mapping of the object ID to it's used light ID
protected static int LIST_START_SIZE
          The initial size of the children list
protected  int numDeletions
          The number of deletable objects to handle next frame
protected  int numRenderables
          Number of items in the renderable list
protected  int[] operationList
          Local storage of the nodes that need to be rendered
protected  GraphicsDetails[] renderableList
          Local storage of the nodes that need to be rendered
protected  boolean resetColor
          Flag to say that colour needs to be reset this frame
protected  ShaderSourceRenderable[] shaderInitList
          The change requestors for data changed sets
protected static int SHADERLIST_START_SIZE
          The initial size of the shader init/log lists
protected  ShaderSourceRenderable[] shaderLogList
          The change requestors for bounds changed sets
protected  boolean singleThreaded
          Single threaded rendering mode operation state.
protected  javax.vecmath.Matrix4f surfaceMatrix
          Combined view and projection matrix.
protected  boolean terminate
          Request that the current drawing terminate immediately.
 
Constructor Summary
protected BaseRenderingProcessor(javax.media.opengl.GLContext context)
          Construct handler for rendering objects to the main screen.
 
Method Summary
protected abstract  void display()
          Called for each rendering loop.
 void disposeSingleThreadResources()
          If the output device is marked as single threaded, this instructs the device that the current rendering thread has exited.
 void enableSingleThreaded(boolean state)
          Notification that this surface is being drawn to with a single thread.
 boolean getCenterEyeInSurface(int x, int y, int layer, int subLayer, javax.vecmath.Point3f position)
          Get the Center Eye position in surface coordinates.
 boolean getPixelLocationInSurface(int x, int y, int layer, int subLayer, javax.vecmath.Point3f position)
          Convert a pixel location to surface coordinates.
 boolean getSurfaceToVWorld(int x, int y, int layer, int subLayer, javax.vecmath.Matrix4f matrix)
          Get the surface to VWorld transformation matrix.
 void halt()
          Force a halt of the current processing.
protected  void init()
          Called by the drawable immediately after the OpenGL context is initialized or has changed; the GLContext has already been made current when this method is called.
protected  void postLayerEnvironmentDraw(javax.media.opengl.GL gl, GraphicsEnvironmentData data)
          Complete the view environment setup at the end of the layer.
protected  void postMPPassEnvironmentDraw(javax.media.opengl.GL gl, GraphicsEnvironmentData data)
          Complete the view environment setup at the end of the layer.
protected  void preLayerEnvironmentDraw(javax.media.opengl.GL gl, GraphicsEnvironmentData data)
          Setup the view environment for a specific layer for drawing now.
protected  void preMPPassEnvironmentDraw(javax.media.opengl.GL gl, GraphicsEnvironmentData data)
          Setup the view environment for a specific pass of a multipass rendering for drawing now.
 void queueDeletedObject(DeletableRenderable 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(ShaderSourceRenderable[] initList, int numInit, ShaderSourceRenderable[] logList, int numLog)
          Queue up a collection of shader objects for processing on the next frame.
 boolean render()
          Draw to the drawable now.
protected  void renderViewpoint(javax.media.opengl.GL gl, GraphicsEnvironmentData data)
          Render the viewpoint setup.
 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 setColorClearNeeded(boolean state)
          Set whether we should always force a local colour clear before beginning any drawing.
 void setDrawableObjects(GraphicsDetails[] nodes, int[] renderOps, int numValid, GraphicsEnvironmentData[] envData)
          Update the list of items to be rendered to the current list.
 void setErrorReporter(org.j3d.util.ErrorReporter reporter)
          Register an error reporter with the engine so that any errors generated by the node's internals can be reported in a nice, pretty fashion.
protected  void setupMultipassViewport(javax.media.opengl.GL gl, GraphicsEnvironmentData data)
          Setup the viewport environment to be drawn for a multipass rendering.
protected  void setupViewport(javax.media.opengl.GL gl, GraphicsEnvironmentData data)
          Setup the viewport environment to be drawn, but do not yet set up the viewpoint and other per-layer-specific effects.
 void swapBuffers()
          Cause the buffers of the underlying drawable to swap now.
protected  void terminateCleanup()
          If termination has been requested during the last call to the display loop, this method is called to destroy and cleanup the context instance.
protected  void updateProjectionMatrix(javax.media.opengl.GL gl, GraphicsEnvironmentData data)
          Update the projection matrix.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LIST_START_SIZE

protected static final int LIST_START_SIZE
The initial size of the children list

See Also:
Constant Field Values

INITIAL_PATH_DEPTH

protected static final int INITIAL_PATH_DEPTH
Initial depth for the number of transforms above a view,fog or bg

See Also:
Constant Field Values

INITIAL_DELETE_SIZE

protected static final int INITIAL_DELETE_SIZE
Initial size of the deletion queue array

See Also:
Constant Field Values

SHADERLIST_START_SIZE

protected static final int SHADERLIST_START_SIZE
The initial size of the shader init/log lists

See Also:
Constant Field Values

INVALID_SHADER

protected static final java.lang.Integer INVALID_SHADER
The invalid shader ID


clearColor

protected float[] clearColor
The current clear colour


resetColor

protected boolean resetColor
Flag to say that colour needs to be reset this frame


renderableList

protected GraphicsDetails[] renderableList
Local storage of the nodes that need to be rendered


operationList

protected int[] operationList
Local storage of the nodes that need to be rendered


numRenderables

protected int numRenderables
Number of items in the renderable list


environmentList

protected GraphicsEnvironmentData[] environmentList
Local storage of the environment data collections


deleteQueue

protected DeletableRenderable[] deleteQueue
Queue for holding deleted textures


numDeletions

protected int numDeletions
The number of deletable objects to handle next frame


shaderInitList

protected ShaderSourceRenderable[] shaderInitList
The change requestors for data changed sets


shaderLogList

protected ShaderSourceRenderable[] shaderLogList
The change requestors for bounds changed sets


lastShaderInitIdx

protected int lastShaderInitIdx
The current place to add shader init requestors


lastShaderLogIdx

protected int lastShaderLogIdx
The current place to add shader log requestors


currentShaderProgramId

protected java.lang.Integer currentShaderProgramId
The current program ID for GLSLang shaders.


availableLights

protected java.lang.Integer[] availableLights
Stack of the available OGL light IDs that could be assigned to lights


lastLightIdx

protected int lastLightIdx
index in the availableLights list of the last available


lightIdMap

protected org.j3d.util.IntHashMap lightIdMap
Mapping of the object ID to it's used light ID


availableClips

protected java.lang.Integer[] availableClips
Stack of the available OGL clip IDs that could be assigned to clips


lastClipIdx

protected int lastClipIdx
index in the availableClips list of the last available


clipIdMap

protected org.j3d.util.IntHashMap clipIdMap
Mapping of the object ID to it's used clip ID


alwaysLocalClear

protected boolean alwaysLocalClear
Flag to say if we the default clear colour should be used, or if there is at least one background that we can make use of


surfaceMatrix

protected javax.vecmath.Matrix4f surfaceMatrix
Combined view and projection matrix. This used to be set in setEnvironmentData when we had a single one. Now there is one per layer and we need to do something about it.


eyePoint

protected float[] eyePoint
The eye offset from the normal position


currentViewport

protected float[] currentViewport
Data describing the current viewport if explicit values used


initComplete

protected boolean initComplete
Flag indicating if any initialisation has been performed yet. Sometimes we can get into situations where the GL context is already valid, but we don't get the NEW context status being reported. If we haven't initialised ourselves at this point, then we really need to, to stop crashing.


terminate

protected boolean terminate
Request that the current drawing terminate immediately. App closing


errorReporter

protected org.j3d.util.ErrorReporter errorReporter
Error reporter used to send out messages


glContext

protected javax.media.opengl.GLContext glContext
The context from the drawable


singleThreaded

protected boolean singleThreaded
Single threaded rendering mode operation state. Defaults to false.

Constructor Detail

BaseRenderingProcessor

protected BaseRenderingProcessor(javax.media.opengl.GLContext context)
Construct handler for rendering objects to the main screen.

Parameters:
context - The context that this processor is working on
Method Detail

setErrorReporter

public void setErrorReporter(org.j3d.util.ErrorReporter reporter)
Register an error reporter with the engine so that any errors generated by the node's internals can be reported in a nice, pretty fashion. Setting a value of null will clear the currently set reporter. If one is already set, the new value replaces the old.

Specified by:
setErrorReporter in interface RenderingProcessor
Parameters:
reporter - The instance to use or null

halt

public void halt()
Force a halt of the current processing. Any processing in progress should exit immediately. Used to abort the current scene processing due to application shutdown.

Specified by:
halt in interface RenderingProcessor

queueDeletedObject

public void queueDeletedObject(DeletableRenderable 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 RenderingProcessor
Parameters:
obj - The instance to be queued up as no longer being used

queueShaderRequests

public void queueShaderRequests(ShaderSourceRenderable[] initList,
                                int numInit,
                                ShaderSourceRenderable[] 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 RenderingProcessor
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 RenderingProcessor
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

setColorClearNeeded

public void setColorClearNeeded(boolean state)
Set whether we should always force a local colour clear before beginning any drawing. If this is set to false, then we can assume that there is at least one background floating around that we can use to clear whatever was drawn in the previous frame, and so we can ignore the glClear(GL.GL_COLOR_BUFFER_BIT) call. The default is set to true.

Specified by:
setColorClearNeeded in interface RenderingProcessor
Parameters:
state - true if we should always locally clear first

setDrawableObjects

public void setDrawableObjects(GraphicsDetails[] nodes,
                               int[] renderOps,
                               int numValid,
                               GraphicsEnvironmentData[] envData)
Update the list of items to be rendered to the current list. Draw them at the next oppourtunity.

Specified by:
setDrawableObjects in interface RenderingProcessor
Parameters:
nodes - The list of nodes in sorted order
renderOps - Operation to perform on each node
numValid - The number of valid items in the array
envData - environment data to be rendered with this scene

render

public final boolean render()
Draw to the drawable now. This causes the drawable's context to be made current and the GL commands are issued. Derived classes should not override this method, instead they should use the display() or init() methods as needed.

Specified by:
render in interface RenderingProcessor
Returns:
false if the rendering should not continue

swapBuffers

public void swapBuffers()
Cause the buffers of the underlying drawable to swap now.

Specified by:
swapBuffers in interface RenderingProcessor

enableSingleThreaded

public void enableSingleThreaded(boolean state)
Notification that this surface is being drawn to with a single thread. This can be used to optmise internal state handling when needed in a single versus multithreaded environment.

This method should never be called by end user code. It is purely for the purposes of the RenderManager to inform the device about what state it can expect.

Specified by:
enableSingleThreaded in interface RenderingProcessor
Parameters:
state - true if the device can expect single threaded behaviour

disposeSingleThreadResources

public void disposeSingleThreadResources()
If the output device is marked as single threaded, this instructs the device that the current rendering thread has exited. Next time the draw method is called, a new rendering context will need to be created for a new incoming thread instance. Also, if any other per-thread resources are around, clean those up now. This is called just before that thread exits.

Specified by:
disposeSingleThreadResources in interface RenderingProcessor

getSurfaceToVWorld

public boolean getSurfaceToVWorld(int x,
                                  int y,
                                  int layer,
                                  int subLayer,
                                  javax.vecmath.Matrix4f matrix)
Get the surface to VWorld transformation matrix. The coordinate system is in the window-system interface: The x,y position is the lower left corner, with height going up the screen and width heading to the right.

Specified by:
getSurfaceToVWorld in interface RenderingProcessor
Parameters:
x - The X coordinate on the surface
y - The Y coordinate on the surface
matrix - The matrix to copy into It must be preallocated.
layer - The layer ID to fetch from. Layer 0 is the front-most
subLayer - The ID of the viewport-layer that is needed. If there are no sub-layers, use 0.
Returns:
Whether the coordinates where on the layer

getPixelLocationInSurface

public boolean getPixelLocationInSurface(int x,
                                         int y,
                                         int layer,
                                         int subLayer,
                                         javax.vecmath.Point3f position)
Convert a pixel location to surface coordinates. The coordinate system is in the window-system interface: The x,y position is the lower left corner, with height going up the screen and width heading to the right.

Specified by:
getPixelLocationInSurface in interface RenderingProcessor
Parameters:
x - The X coordinate
y - The Y coordinate
layer - The layer ID to fetch from. Layer 0 is the front-most
subLayer - The ID of the viewport-layer that is needed. If there are no sub-layers, use 0.
position - The converted position. It must be preallocated.
Returns:
Whether the coordinates where on the layer

getCenterEyeInSurface

public boolean getCenterEyeInSurface(int x,
                                     int y,
                                     int layer,
                                     int subLayer,
                                     javax.vecmath.Point3f position)
Get the Center Eye position in surface coordinates.

Specified by:
getCenterEyeInSurface in interface RenderingProcessor
Parameters:
x - The X coordinate on the surface
y - The Y coordinate on the surface
position - The current eye position. It must be preallocated.
layer - The layer ID to fetch from. Layer 0 is the front-most
subLayer - The ID of the viewport-layer that is needed. If there are no sub-layers, use 0.
Returns:
Whether the coordinates where on the layer

display

protected abstract void display()
Called for each rendering loop. The derived class should now perform the rendering that they need to do for the given type of renderer. The context is made current before this call and is made non current after this call. Derived code does not need to worry about context state handling.


init

protected void init()
Called by the drawable immediately after the OpenGL context is initialized or has changed; the GLContext has already been made current when this method is called.


terminateCleanup

protected void terminateCleanup()
If termination has been requested during the last call to the display loop, this method is called to destroy and cleanup the context instance. Once called, this instance can no longer be used.


setupViewport

protected void setupViewport(javax.media.opengl.GL gl,
                             GraphicsEnvironmentData data)
Setup the viewport environment to be drawn, but do not yet set up the viewpoint and other per-layer-specific effects. If a viewport has multiple layers, then each layer could potentially have a different viewpoint etc.

Parameters:
gl - The gl context to draw with
data - The view environment information to setup

setupMultipassViewport

protected void setupMultipassViewport(javax.media.opengl.GL gl,
                                      GraphicsEnvironmentData data)
Setup the viewport environment to be drawn for a multipass rendering. The difference between this and the normal viewport setup is that this always assumes starting at 0,0 and just uses the width and height to setup the bounds. It is assuming rendering to one of the auxillary buffers rather than the main back buffer.

Parameters:
gl - The gl context to draw with
data - The view environment information to setup

preLayerEnvironmentDraw

protected void preLayerEnvironmentDraw(javax.media.opengl.GL gl,
                                       GraphicsEnvironmentData data)
Setup the view environment for a specific layer for drawing now. This calls the render effects processor, draws the background, initiates the viewpoint, frustum etc.

Parameters:
gl - The gl context to draw with
data - The view environment information to setup

postLayerEnvironmentDraw

protected void postLayerEnvironmentDraw(javax.media.opengl.GL gl,
                                        GraphicsEnvironmentData data)
Complete the view environment setup at the end of the layer. This disables any fog, the current viewpoint and the post draw action on the render effects processor.

Parameters:
gl - The gl context to draw with
data - The view environment information to setup

preMPPassEnvironmentDraw

protected void preMPPassEnvironmentDraw(javax.media.opengl.GL gl,
                                        GraphicsEnvironmentData data)
Setup the view environment for a specific pass of a multipass rendering for drawing now. This calls the multipass observer, and initiates the viewpoint, frustum etc. Backgrounds are not drawn.

Parameters:
gl - The gl context to draw with
data - The view environment information to setup

postMPPassEnvironmentDraw

protected void postMPPassEnvironmentDraw(javax.media.opengl.GL gl,
                                         GraphicsEnvironmentData data)
Complete the view environment setup at the end of the layer. This disables any fog, the current viewpoint and the post draw action on the render effects processor.

Parameters:
gl - The gl context to draw with
data - The view environment information to setup

renderViewpoint

protected void renderViewpoint(javax.media.opengl.GL gl,
                               GraphicsEnvironmentData data)
Render the viewpoint setup.

Parameters:
gl - The gl context to draw with
data - The view environment information to setup

updateProjectionMatrix

protected void updateProjectionMatrix(javax.media.opengl.GL gl,
                                      GraphicsEnvironmentData data)
Update the projection matrix.

Parameters:
gl - The gl context to draw with
data - The view environment information to setup

Aviatrix3D
2.0 Beta 2

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