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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidafterExecute(J job, Throwable thrown) Called byonDisplay(OGLGraphics)after the job is executed.protected voidbeforeExecute(J job) Called byonDisplay(OGLGraphics)when the job is dequeued, but before it is executed.final voidenqueueJob(J job) Enqueues an actionable job in the work queue.longReturns the length of time it took to render this node, in nanoseconds.final booleanChecks if the work queue is empty.protected booleanCalled byonDisplay(OGLGraphics)for determining if there's work available for processing.final voidDisplays this node.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface OGLNode
getPolygonsRendered, onFramebufferResize
-
Constructor Details
-
OGLWorkerNode
public OGLWorkerNode()Creates a new worker node, with no jobs in its queue.
-
-
Method Details
-
onDisplay
Description copied from interface:OGLNodeDisplays this node. The rendering thread for the target window enters this method, so it is safe to call allOGLGraphicsfunctions here.- Specified by:
onDisplayin interfaceOGLNode<GL extends OGLGraphics>- Parameters:
gl- the graphics object used for issuing commands to OpenGL.
-
getRenderTimeNanos
public long getRenderTimeNanos()Description copied from interface:OGLNodeReturns 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 hadOGLNode.onDisplay(OGLGraphics)called on it.- Specified by:
getRenderTimeNanosin interfaceOGLNode<GL extends OGLGraphics>- Returns:
- the length of time it took to render this node, in nanoseconds.
-
enqueueJob
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 byonDisplay(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
Called byonDisplay(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
Called byonDisplay(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.
-