public class GLDeferredDeleteQueue
extends java.lang.Object
GLResources that a background sweep has found to
be unreferenced and that are awaiting deletion.
The point of this class is to move the actual GL delete calls
(glDeleteBuffers, glDeleteTextures, ...) off the background garbage
collector thread and onto a render thread that owns a live GL context. A
sweep running on the collector thread only needs to do cheap, context-free
reference-count bookkeeping and enqueue(maspack.render.GL.GLResource) the dead resources here;
each viewer then calls drain(com.jogamp.opengl.GL) during its own frame to perform the GL
deletes on its own context. This avoids issuing GL operations against a
context shared with the renderer, which on Windows forces driver-level
synchronization and produces rendering stalls.
A LinkedHashSet backs the queue so that repeated enqueues of the
same resource (which happen when several sweeps run before a drain) collapse
to a single entry while preserving insertion order.
| Modifier and Type | Field and Description |
|---|---|
static boolean |
enabled
Global switch for deferred deletion of GL resources.
|
| Constructor and Description |
|---|
GLDeferredDeleteQueue() |
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Discards all pending entries without disposing them.
|
int |
drain(com.jogamp.opengl.GL gl)
Disposes all pending resources that are still unreferenced, using the
supplied context.
|
void |
enqueue(GLResource resource)
Marks a resource for deferred deletion.
|
int |
size()
Number of resources currently awaiting deletion.
|
public static boolean enabled
true
(the default), background garbage sweeps only enqueue unreferenced
resources and the actual GL deletes happen on a render thread (see class
comment). When false, the original behaviour is restored and
sweeps delete resources inline on whatever thread runs them.
Consulted dynamically at each sweep/drain, so it may be toggled at
runtime. May also be set at startup via the system property
maspack.render.deferredDelete=false.
public void enqueue(GLResource resource)
public int size()
public int drain(com.jogamp.opengl.GL gl)
gl current
(i.e. from within a viewer's render callback).
Each resource's reference count is re-checked immediately before disposal: a resource that has been re-acquired since it was enqueued is simply dropped from the queue (its owning list is still tracking it), so a resurrected resource is never deleted out from under a live user. The GL deletes themselves are performed outside the lock so that the collector thread can keep enqueueing while a drain is in progress.
public void clear()