de.grogra.imp3d.glsl
Class GLSLDisplay

java.lang.Object
  extended by de.grogra.imp.awt.ViewComponentAdapter
      extended by de.grogra.imp3d.glsl.GLDisplay
          extended by de.grogra.imp3d.glsl.GLSLDisplay
All Implemented Interfaces:
ViewComponent, RenderState, ComponentWrapper, Selectable, Disposable, java.awt.image.ImageObserver, java.lang.Runnable, java.util.EventListener, javax.media.opengl.GLEventListener

public class GLSLDisplay
extends GLDisplay

Extension to the GLDisplay class to work with shaders generated by ShaderOGL

Author:
Konni Hartmann, nmi

Nested Class Summary
 
Nested classes/interfaces inherited from class de.grogra.imp3d.glsl.GLDisplay
GLDisplay.GLVisitor
 
Field Summary
static boolean DEBUG
          Debug switch.
protected  boolean optionShowBGImage
           
static EnumerationType TONEMAPPING_TYPE
          Enumeration of the available Tonemapping-Algorithms.
 
Fields inherited from class de.grogra.imp3d.glsl.GLDisplay
curHighlight, dlSphere, dlSupershape, endPoint, gridColor, lineWidth, LOD_LEVELS, optionGridColorB, optionGridColorG, optionGridColorR, optionGridDimension, optionGridSpacing, optionShowAxes, optionShowDisplaySize, optionShowGrid, optionShowPoints, polyCache, pool, RENDER_MODE, startPoint, supportsVBO, visitor
 
Fields inherited from class de.grogra.imp.awt.ViewComponentAdapter
DISPOSED, DISPOSING, RENDERED_IMAGE, RENDERING, REPAINT_MASK
 
Fields inherited from interface de.grogra.imp3d.RenderState
CURRENT_HIGHLIGHT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Fields inherited from interface de.grogra.imp.ViewComponent
ALL, CHANGED, MIN_USER_FLAG, SCENE, SELECTION, TOOLS
 
Constructor Summary
GLSLDisplay()
           
 
Method Summary
 void drawBoxImpl(javax.media.opengl.GL gl, float x0, float y0, float z0, float x1, float y1, float z1)
          Draw a box on gl.
 void drawGrid(javax.media.opengl.GL gl)
           
 void drawParallelogram(float length, Vector3f axis, float scaleU, float scaleV, Shader s, int highlight, Matrix4d t)
           
 void drawPlane(Shader s, int highlight, Matrix4d t)
          Draw an x/y plane.
 void drawPoint(Tuple3f origin, int pixelSize, Tuple3f color, int highlight, Matrix4d t)
          Draw a single point with the specified pixel size and color.
 void drawPolygons(Polygonizable pz, java.lang.Object obj, boolean asNode, Shader s, int highlight, Matrix4d t)
           
 void drawPolygons(Polygonizable pz, java.lang.Object obj, boolean asNode, Shader s, int highlight, Matrix4d t, int defaultCulledSide, boolean cullingEnabled, boolean normalMode)
          Draw a polygonizable Object.
 void drawRectangle(int x, int y, int w, int h, Tuple3f color)
          Draw a rectangle from (x/y) to (x+w/y+h) with the specified color.
 void fillRectangle(int x, int y, int w, int h, Tuple3f color)
          Draw a filled rectangle from (x/y) to (x+w/y+h) with the specified color.
 void findAndActivateShader(Shader s)
          Searches Shader-Cache for a GLSL-Shader corresponding to the given Shader s.
 GLSLManagedShader findShader(Shader s)
          Searches Shader-Cache for a GLSL-Shader corresponding to the given Shader s.
 float getBackgroundAlpha()
           
 float getBackgroundColorB()
           
 float getBackgroundColorG()
           
 float getBackgroundColorR()
           
 float getBrightness()
           
 OpenGLState getCurrentGLState()
          Returns the OpenGLState associated with the current GLContext.
 int getDebugRenderPass()
           
static int getDepthStencilSetup()
           
 int getMaxDepth()
           
 TextureManager getTextureManager()
           
 int getTonemapping()
           
 Matrix4d getTransformation(Matrix4d t)
           
 GLDisplay.GLVisitor getVisitor()
           
 void init()
          Initialize OpenGL (Proteus).
 void init(javax.media.opengl.GLAutoDrawable d)
          Initialise opengl state and set default values.
 void initView(View view, EventListener listener)
          Initializes this component.
 boolean isOptionAltDrawing()
           
 boolean isOptionAutoAdjustBrightness()
           
 boolean isOptionEdgeFiltering()
           
 boolean isOptionLighting()
           
 boolean isOptionPhysicalLighting()
           
 boolean isOptionShaderAntialiasing()
           
 boolean isOptionShowBGImage()
           
 boolean isOptionShowDiffuseSkyLight()
           
 boolean isOptionShowGrid()
           
 boolean isOptionShowShadows()
           
 boolean isOptionShowSky()
           
 boolean isVisible(int layer)
          Tests if the given layer is currently visible.
protected  void optionValueChanged(java.lang.String name, java.lang.Object value)
           
static void printDebugInfo(java.lang.String string)
          Output a string to OUT if the DEBUG switch is set.
static void printDebugInfoN(java.lang.String string)
          Output a string to OUT if the DEBUG switch is set.
protected  void render(int flags)
          Render the scene graph.
 void renderScene()
          This method renders the Scene.
 void resize()
          If called, all associated FBOs are resized to the current viewports size.
 void setGL(javax.media.opengl.GL gl)
          Sets the gl object as current active GL object.
 boolean setupBGShader(Sky node)
          Setup a sky.
 void setUpContext(javax.media.opengl.GLContext context)
          Setter for GL.
 void setVisitor(GLDisplay.GLVisitor visitor)
          Sets the active visitor.
static void ViewOrtho(javax.media.opengl.GL gl, int width, int height)
          construct an orthogonal view matrix for easing full screen Quad drawing
static void ViewPerspective(javax.media.opengl.GL gl)
          change view matrix back to default
 
Methods inherited from class de.grogra.imp3d.glsl.GLDisplay
display, displayChanged, dispose, drawAxes, drawBox, drawDisplaySize, drawFrustum, drawLine, drawPointCloud, drawSphere, drawString, drawSupershape, drawWithDisplayList, estimateScaleAt, estimateScaleAt, getComponent, getCurrentHighlight, getCurrentShader, getLOD, getObserverForRenderer, getPool, getShader, getView3D, getWindowPos, imageUpdate, initRender, invokeRender, isExtensionSupported, makeSnapshot, reshape
 
Methods inherited from class de.grogra.imp.awt.ViewComponentAdapter
checkRepaint, checkRepaintWrapException, disposeRenderer, getColor, getColor, getFactory, getFontMetrics, getGlobalLOD, getIntColor, getInterruptedException, getOption, getRenderGraphState, getView, initFactory, installListeners, invokeRenderSync, render, render, renderUninterruptibly, repaint, run, toSelection, uninstallListeners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.grogra.imp3d.RenderState
getFontMetrics, getRenderGraphState
 
Methods inherited from interface de.grogra.pf.ui.edit.Selectable
toSelection
 

Field Detail

DEBUG

public static final boolean DEBUG
Debug switch. May be used to test if debug output should be printed. This variable is set to true by specifying the argument "-Dgroimp.debug.GLSLDisplay=1" for the Java VM.


optionShowBGImage

protected boolean optionShowBGImage

TONEMAPPING_TYPE

public static final EnumerationType TONEMAPPING_TYPE
Enumeration of the available Tonemapping-Algorithms. This is used by the configuration Dialog of OpenGL (Proteus).

Constructor Detail

GLSLDisplay

public GLSLDisplay()
Method Detail

drawBoxImpl

public void drawBoxImpl(javax.media.opengl.GL gl,
                        float x0,
                        float y0,
                        float z0,
                        float x1,
                        float y1,
                        float z1)
Description copied from class: GLDisplay
Draw a box on gl. The box will be axis-aligned and surrounded by the planes x = x0, x = x1, y = y0, y = y1, z = z0, z = z1. The function will generate the vertices, normals and texture coordinates for the box.


drawGrid

public void drawGrid(javax.media.opengl.GL gl)

drawParallelogram

public void drawParallelogram(float length,
                              Vector3f axis,
                              float scaleU,
                              float scaleV,
                              Shader s,
                              int highlight,
                              Matrix4d t)
Specified by:
drawParallelogram in interface RenderState
Overrides:
drawParallelogram in class GLDisplay

drawPlane

public void drawPlane(Shader s,
                      int highlight,
                      Matrix4d t)
Description copied from class: GLDisplay
Draw an x/y plane.

Specified by:
drawPlane in interface RenderState
Overrides:
drawPlane in class GLDisplay

drawPoint

public void drawPoint(Tuple3f origin,
                      int pixelSize,
                      Tuple3f color,
                      int highlight,
                      Matrix4d t)
Description copied from class: GLDisplay
Draw a single point with the specified pixel size and color. Although OpenGL provides a function to draw points, the point is represented by a sphere, because some graphics cards/drivers seem to have problems setting the size for the point.

Specified by:
drawPoint in interface RenderState
Overrides:
drawPoint in class GLDisplay
pixelSize - size of point on screen in pixels

drawPolygons

public void drawPolygons(Polygonizable pz,
                         java.lang.Object obj,
                         boolean asNode,
                         Shader s,
                         int highlight,
                         Matrix4d t)
Specified by:
drawPolygons in interface RenderState
Overrides:
drawPolygons in class GLDisplay

drawPolygons

public void drawPolygons(Polygonizable pz,
                         java.lang.Object obj,
                         boolean asNode,
                         Shader s,
                         int highlight,
                         Matrix4d t,
                         int defaultCulledSide,
                         boolean cullingEnabled,
                         boolean normalMode)
Draw a polygonizable Object. This Method adds additional parameters for dealing with different culling modes set by OpenGL.

Parameters:
pz -
obj -
asNode -
s -
highlight -
t - Transformation matrix. Input for getTransformation(Matrix4d)
defaultCulledSide - Default state for culling. This is one of GL.FRONT, GL.GL_BACK
cullingEnabled - True if culling is currently enabled in OpenGL. False else.
normalMode - True if this is used for drawing visible geometry. False if used for drawing into Shadow Map.
See Also:
GLDisplay.drawPolygons(Polygonizable, Object, boolean, Shader, int, Matrix4d)

drawRectangle

public void drawRectangle(int x,
                          int y,
                          int w,
                          int h,
                          Tuple3f color)
Description copied from class: GLDisplay
Draw a rectangle from (x/y) to (x+w/y+h) with the specified color.

Specified by:
drawRectangle in interface RenderState
Overrides:
drawRectangle in class GLDisplay

fillRectangle

public void fillRectangle(int x,
                          int y,
                          int w,
                          int h,
                          Tuple3f color)
Description copied from class: GLDisplay
Draw a filled rectangle from (x/y) to (x+w/y+h) with the specified color.

Specified by:
fillRectangle in interface RenderState
Overrides:
fillRectangle in class GLDisplay

findAndActivateShader

public void findAndActivateShader(Shader s)
Searches Shader-Cache for a GLSL-Shader corresponding to the given Shader s. If no GLSL-Shader is found one is created. The Shader is then activated.

Parameters:
s - The GroIMP-Shader.

findShader

public GLSLManagedShader findShader(Shader s)
Searches Shader-Cache for a GLSL-Shader corresponding to the given Shader s. If no GLSL-Shader is found one is created.

Parameters:
s - The GroIMP-Shader.
Returns:
The GLSL-Shader.

getBackgroundAlpha

public float getBackgroundAlpha()
Returns:
alpha value of background

getBackgroundColorB

public float getBackgroundColorB()
Returns:
blue value of background color

getBackgroundColorG

public float getBackgroundColorG()
Returns:
green value of background color

getBackgroundColorR

public float getBackgroundColorR()
Returns:
red value of background color

getBrightness

public float getBrightness()
Returns:
the brightness factor used to brighten the rendered image.

getCurrentGLState

public OpenGLState getCurrentGLState()
Returns the OpenGLState associated with the current GLContext.

Returns:
The current OpenGLState.
See Also:
OpenGLState

getDebugRenderPass

public int getDebugRenderPass()
Returns:
the index of a renderpass, which should be displayed. This will render the content of each HDR- and DeferredShading-FBO as seen at the specified RenderPass to the screen.

getDepthStencilSetup

public static int getDepthStencilSetup()

getMaxDepth

public int getMaxDepth()
Returns:
Number of Depth-Peeling passes used to display transparent materials.

getTextureManager

public TextureManager getTextureManager()
Returns:
The Manager used to the Textures for each translated material.

getTonemapping

public int getTonemapping()
Returns:
the index of the choosen tonemapping algorithm. For now this is: 0: Linear tonemapping 1: DDR (Dynamic Range Reduction). See paper at link.

getTransformation

public Matrix4d getTransformation(Matrix4d t)
Overrides:
getTransformation in class GLDisplay

getVisitor

public GLDisplay.GLVisitor getVisitor()
Returns:
The current active Visitor to traverse the Scene-Tree.

init

public void init()
Initialize OpenGL (Proteus). This will initialize all Collections


init

public void init(javax.media.opengl.GLAutoDrawable d)
Initialise opengl state and set default values. All functions can assume those values being set upon call (i.e. MatrixMode as GL_MODELVIEW). If a function changes any of those values, it has to restore its state before calling another function or exiting. This also wraps DebugGL arround the current GL-Object if DEBUG is set to true resulting in detailed Debug-Output if an GLError occurs.

Specified by:
init in interface javax.media.opengl.GLEventListener
Overrides:
init in class GLDisplay

initView

public void initView(View view,
                     EventListener listener)
Description copied from interface: ViewComponent
Initializes this component. This method sets the view within which this view component is used to display the graph. It also sets an event listener. this has to be informed of mouse and keys events within the view component by implementations of this method.

Specified by:
initView in interface ViewComponent
Overrides:
initView in class GLDisplay
Parameters:
view - the containing view
listener - mouse and key events will be reported to this listener

isOptionAltDrawing

public boolean isOptionAltDrawing()
Returns:
true, if alternative drawing methods should be called. Up to now this will only result in infinite planes.

isOptionAutoAdjustBrightness

public boolean isOptionAutoAdjustBrightness()
Returns:
true, if brightness should be automatically adjusted for the rendered image.

isOptionEdgeFiltering

public boolean isOptionEdgeFiltering()
Returns:
true, if edge-filtering should be used. This Option is currently unused since a working filtering approach was not implemented.

isOptionLighting

public boolean isOptionLighting()
Returns:
true, if scene should be rendered with all lights. false, only use default directional light.

isOptionPhysicalLighting

public boolean isOptionPhysicalLighting()
Returns:
true, if lights intensity should decrease by the squared distance from the lights source.

isOptionShaderAntialiasing

public boolean isOptionShaderAntialiasing()
Returns:
true, if anti-aliasing material-shaders should be used.

isOptionShowBGImage

public boolean isOptionShowBGImage()
Returns:
true, if the background (checkboard) image should be rendered. false, else

isOptionShowDiffuseSkyLight

public boolean isOptionShowDiffuseSkyLight()
Returns:
true, if diffuse light of sky-Nodes should be approximated.

isOptionShowGrid

public boolean isOptionShowGrid()
Returns:
true, if grid should be rendered. false, else

isOptionShowShadows

public boolean isOptionShowShadows()
Returns:
true, if shadows should be rendered and displayed.

isOptionShowSky

public boolean isOptionShowSky()
Returns:
true, if scene sky should be rendered.

isVisible

public boolean isVisible(int layer)
Tests if the given layer is currently visible.

Parameters:
layer - The layer that should be tested.
Returns:
true, if the layer is visible.

optionValueChanged

protected void optionValueChanged(java.lang.String name,
                                  java.lang.Object value)
Overrides:
optionValueChanged in class GLDisplay

printDebugInfo

public static void printDebugInfo(java.lang.String string)
Output a string to OUT if the DEBUG switch is set. This version does not terminate the line.

Parameters:
string - The String to be printed.

printDebugInfoN

public static void printDebugInfoN(java.lang.String string)
Output a string to OUT if the DEBUG switch is set. This version terminates the line.

Parameters:
string - The String to be printed.

render

protected void render(int flags)
               throws java.lang.InterruptedException
Description copied from class: GLDisplay
Render the scene graph. This function will traverse the scene graph and render all objects of it. These steps are performed:
  1. get GL
  2. if GL changed, delete textures
  3. clear the frame buffer
  4. draw background image (i.e. from povray)
  5. cleaar depth buffer
  6. set projection matrix
  7. check if the scene graph changed since last render, than remember that and perform an update of the light sources
  8. walk graph first time, visit every object, update lights if necessary
  9. if lights have changed, draw the scene again
  10. walk graph second time, visit highlighted objects
  11. disable lighting and depth buffer
  12. walk graph third time, visit tools (i.e. arrows to move objects)
  13. enable lighting and depth buffer

Overrides:
render in class GLDisplay
Parameters:
flags - combination of bit masks
Throws:
java.lang.InterruptedException - if the rendering has been interrupted

renderScene

public void renderScene()
This method renders the Scene. This includes all objects of the Scene-Graph. Additional rendering like highlighting of objects and the size of the current viewport will be handled by GLDisplay.render(int).


resize

public void resize()
If called, all associated FBOs are resized to the current viewports size.


setGL

public void setGL(javax.media.opengl.GL gl)
Sets the gl object as current active GL object. Effectively this will call OpenGLState.setGL(GL).

Parameters:
gl - The GL object

setupBGShader

public boolean setupBGShader(Sky node)
Setup a sky. This method is used by a visitor to store a sky-node. Since it is considered a hack this method will be removed in upcoming commits of the source-code.

Parameters:
node -
Returns:
false, if a sky has already been set.

setUpContext

public void setUpContext(javax.media.opengl.GLContext context)
Setter for GL. This will also reset glState and cleanup the Java-Side of the used OpenGL-Objects.

Parameters:
context - The new GL-context that should be used for all actions.

setVisitor

public void setVisitor(GLDisplay.GLVisitor visitor)
Sets the active visitor. The previous visitor will not be saved. Use getVisitor() to store a reference.

Parameters:
visitor - The visitor Object that replaces the active visitor.

ViewOrtho

public static void ViewOrtho(javax.media.opengl.GL gl,
                             int width,
                             int height)
construct an orthogonal view matrix for easing full screen Quad drawing

Parameters:
gl - Current GL Object. Used to issue OpenGL commands.
width - Width of the orthogonal projection in OpenGL units.
height - Height of the orthogonal projection in OpenGL units.

ViewPerspective

public static void ViewPerspective(javax.media.opengl.GL gl)
change view matrix back to default

Parameters:
gl - Current GL Object. Used to issue OpenGL commands.