Class OGLWorkerNode<GL extends OGLGraphics, J extends Consumer<? super GL>>

java.lang.Object
com.blackrook.gloop.opengl.node.OGLWorkerNode<GL,J>
Type Parameters:
GL - the graphics object to call.
J - the "job" type. Must be of type Consumer<? super GL>.
All Implemented Interfaces:
OGLNode<GL>

public class OGLWorkerNode<GL extends OGLGraphics, J extends Consumer<? super GL>> extends Object implements OGLNode<GL>
An OpenGL node that contains a set of jobs (Consumers) for executing on this node's parent system's thread, the idea being that other non-context threads may want to execute OpenGL commands somewhere in the pipeline, such as prepping shader programs or loading/assigning texture objects.

The enables setting up things to run at the place that this node is added to the system.

All public non-OGLNode methods are thread-safe unless otherwise specified.

If the queue is empty, this node does nothing.

You can guarantee that the following methods will be executed in order by the same thread:

Author:
Matthew Tropiano
  • Constructor Details

    • OGLWorkerNode

      public OGLWorkerNode()
      Creates a new worker node, with no jobs in its queue.
  • Method Details

    • onDisplay

      public final void onDisplay(GL gl)
      Description copied from interface: OGLNode
      Displays this node. The rendering thread for the target window enters this method, so it is safe to call all OGLGraphics functions here.
      Specified by:
      onDisplay in interface OGLNode<GL extends OGLGraphics>
      Parameters:
      gl - the graphics object used for issuing commands to OpenGL.
    • getRenderTimeNanos

      public long getRenderTimeNanos()
      Description copied from interface: OGLNode
      Returns the length of time it took to render this node, in nanoseconds. Results of this call should not be considered accurate until the node has had OGLNode.onDisplay(OGLGraphics) called on it.
      Specified by:
      getRenderTimeNanos in interface OGLNode<GL extends OGLGraphics>
      Returns:
      the length of time it took to render this node, in nanoseconds.
    • enqueueJob

      public final void enqueueJob(J job)
      Enqueues an actionable job in the work queue.
      Parameters:
      job - the job to execute.
    • isQueueEmpty

      public final boolean isQueueEmpty()
      Checks if the work queue is empty.
      Returns:
      true if so, false if not.
    • isWorkAvailable

      protected boolean isWorkAvailable()
      Called by onDisplay(OGLGraphics) for determining if there's work available for processing.

      By default, this just checks if the work queue is not empty via isQueueEmpty().

      If this returns false, this node completes, else a job is dequeued and executed.

      Do NOT call this method outside of the main context thread.

      Returns:
      true if work is available, false if not.
      See Also:
    • beforeExecute

      protected void beforeExecute(J job)
      Called by onDisplay(OGLGraphics) when the job is dequeued, but before it is executed.

      Do NOT call this method outside of the main context thread.

      Parameters:
      job - the dequeued job.
    • afterExecute

      protected void afterExecute(J job, Throwable thrown)
      Called by onDisplay(OGLGraphics) after the job is executed.

      Do NOT call this method outside of the main context thread.

      Parameters:
      job - the executed job.
      thrown - an uncaught Throwable that may have occurred in the job, if any. If not, this is null.