Module gl1

Class GLSLDisplay

All Implemented Interfaces:
ViewComponent, RenderState, ComponentWrapper, Selectable, Disposable, ImageObserver, Runnable, 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
  • Field Details

    • 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.
    • TONEMAPPING_TYPE

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

      protected boolean optionShowBGImage
  • Constructor Details

    • GLSLDisplay

      public GLSLDisplay()
  • Method Details

    • printDebugInfoN

      public static void printDebugInfoN(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.
    • printDebugInfo

      public static void printDebugInfo(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.
    • 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
    • render

      protected void render(int flags) throws 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:
      InterruptedException - if the rendering has been interrupted
    • 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
    • drawBoxImpl

      public void drawBoxImpl(javax.media.opengl.GL gl, float x0, float y0, float z0, float x1, float y1, float z1)
    • drawPlane

      public void drawPlane(Shader s, int highlight, boolean asWireframe, Matrix4d t)
      Description copied from class: GLDisplay
      Draw an x/y plane.
      Specified by:
      drawPlane in interface RenderState
      Overrides:
      drawPlane in class GLDisplay
    • drawPolygons

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

      public void drawPolygons(Polygonizable pz, Object obj, boolean asNode, Shader s, int highlight, boolean asWireframe, 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)
    • drawParallelogram

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

      public void drawGrid(javax.media.opengl.GL gl)
    • 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.
    • 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
    • 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
    • getTransformation

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

      protected void optionValueChanged(String name, Object value)
      Overrides:
      optionValueChanged in class GLDisplay
    • isOptionShowGrid

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

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

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

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

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

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

      public float getBackgroundAlpha()
      Returns:
      alpha value of background
    • isOptionLighting

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

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

      public boolean isOptionShowShadows()
      Returns:
      true, if shadows should be rendered and displayed.
    • 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.
    • isOptionAltDrawing

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

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

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

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

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

      public float getBrightness()
      Returns:
      the brightness factor used to brighten the rendered image.
    • 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.
    • 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.
    • getMaxDepth

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

      public GLDisplay.GLVisitor getVisitor()
      Returns:
      The current active Visitor to traverse the Scene-Tree.
    • 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.
    • getTextureManager

      public TextureManager getTextureManager()
      Returns:
      The Manager used to the Textures for each translated material.
    • 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.
    • getCurrentGLState

      public OpenGLState getCurrentGLState()
      Returns the OpenGLState associated with the current GLContext.
      Returns:
      The current OpenGLState.
      See Also:
    • getDepthStencilSetup

      public static int getDepthStencilSetup()
    • init

      public void init()
      Initialize OpenGL (Proteus). This will initialize all Collections
    • 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
    • resize

      public void resize()
      If called, all associated FBOs are resized to the current viewports size.
    • 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.
    • 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).
    • 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.
    • 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.