Class OGLSystem<G extends OGLGraphics>

java.lang.Object
com.blackrook.gloop.opengl.OGLSystem<G>
Type Parameters:
G - the graphics object to call.

public class OGLSystem<G extends OGLGraphics> extends Object
The starting point: the OpenGL subsystem.

An implementation of OpenGL is initialized here, attached to a GLFWWindow and spawns a thread that makes it responsible for the rendering the context (see GLFWContext.makeContextCurrent(GLFWWindow)). The rendering thread can either fire refreshes at a steady rate or listen for a trigger via display() to kick off a frame draw.

Author:
Matthew Tropiano
  • Method Details

    • attachToWindow

      public OGLSystem<G>.RenderingThreadControl attachToWindow(com.blackrook.gloop.glfw.GLFWWindow window)
      Locks this OGLSystem to a window and returns a control for setting the screen redraw interval for the rendering thread.

      DO NOT call this method if you have generated an OGLCanvas for this system.

      Parameters:
      window - the window to lock the render context to.
      Returns:
      a controller for setting rendering speed.
      Throws:
      IllegalStateException - if already attached to a window.
    • display

      public boolean display()
      Triggers a display refresh, telling the rendering thread to draw a frame. If a frame is currently being drawn, this will return false, indicating a dropped frame. Otherwise, this returns true.
      Returns:
      true if redrawing, false if not.
      Throws:
      IllegalStateException - if not attached to a window.
    • addNode

      public OGLSystem<G> addNode(OGLNode<? super G> node)
      Adds a node to this system.

      Compatible nodes must use an implementation of GL with a version equivalent to this one or earlier.

      Parameters:
      node - the node to add.
      Returns:
      this, for chaining calls.
    • removeNode

      public boolean removeNode(OGLNode<? super G> node)
      Removes a node from this system.

      Compatible nodes must use an implementation of GL with a version equivalent to this one or earlier.

      Parameters:
      node - the node to remove.
      Returns:
      true if removed, false if not (wasn't added).
    • getFrameRenderTimeNanos

      public long getFrameRenderTimeNanos()
      Returns the length of time it took to render this frame. This is NOT the same as getRenderTimeNanos(), as it takes time between frames (real time) into consideration. The method getFPS() uses this information.

      Results of this call should not be considered accurate until the node has had display() called on it twice.

      Returns:
      the length of time in nanoseconds.
    • getRenderTimeNanos

      public long getRenderTimeNanos()
      Gets the length of time it took to render each individual node in nanoseconds, accumulated from the executed nodes. The results of this call should not be considered accurate until the node has had display() called on it.
      Returns:
      the length of time it took to render each individual node in nanoseconds.
    • getPolygonsRendered

      public int getPolygonsRendered()
      Gets the number of polygonal objects rendered in this canvas, gathered from the executed nodes. The results of this call should not be considered accurate until the node has had display() called on it.
      Returns:
      the number of polygonal objects rendered in this canvas.
    • getFPS

      public float getFPS()
      Returns:
      the estimated frames per second in this context based on the time to render the nodes.