diff options
author | Sven Gothel <[email protected]> | 2023-08-01 14:06:48 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-08-01 14:06:48 +0200 |
commit | 16b9a3ac358b3ad34dd9eb9df090b59f25e26b75 (patch) | |
tree | 8442bce4834f78ec207f3dec359839032514c42b | |
parent | 7d9bfe58e6ef48e5c7d3da322dbc558285791af9 (diff) |
GLStateTracker: Encapsulate PixelStateMap for PixelStorei states (prepare for tracking of blending states)
-rw-r--r-- | src/jogl/classes/jogamp/opengl/GLStateTracker.java | 113 |
1 files changed, 69 insertions, 44 deletions
diff --git a/src/jogl/classes/jogamp/opengl/GLStateTracker.java b/src/jogl/classes/jogamp/opengl/GLStateTracker.java index d85fb1347..4084887da 100644 --- a/src/jogl/classes/jogamp/opengl/GLStateTracker.java +++ b/src/jogl/classes/jogamp/opengl/GLStateTracker.java @@ -57,15 +57,57 @@ public class GLStateTracker { /** Minimum value of MAX_CLIENT_ATTRIB_STACK_DEPTH */ public static final int MIN_CLIENT_ATTRIB_STACK_DEPTH = 16; - /** static size of pixel state map - private static final int PIXEL_STATE_MAP_SIZE = 16; - */ - /** avoid rehash of static size pixel state map */ - private static final int PIXEL_STATE_MAP_CAPACITY = 32; + /** + * PixelStorei states + */ + public static class PixelStateMap { + /** static size of pixel state map + private static final int PIXEL_STATE_MAP_SIZE = 16; + */ + /** avoid rehash of static size pixel state map */ + private static final int PIXEL_STATE_MAP_CAPACITY = 32; + + private final IntIntHashMap states; + + public PixelStateMap() { + states = new IntIntHashMap(PIXEL_STATE_MAP_CAPACITY, 0.75f); + states.setKeyNotFoundValue(0xFFFFFFFF); + } + + /** Copy constructor */ + public PixelStateMap(final PixelStateMap src) { + this.states = (IntIntHashMap) src.states.clone(); + } + + /** Set this instance's state using OpenGL default values. */ + public final void clearStates() { + states.clear(); + + // 16 values -> PIXEL_STATE_MAP_SIZE + states.put(GL.GL_PACK_ALIGNMENT, 4); + states.put(GL2GL3.GL_PACK_SWAP_BYTES, GL.GL_FALSE); + states.put(GL2GL3.GL_PACK_LSB_FIRST, GL.GL_FALSE); + states.put(GL2ES3.GL_PACK_ROW_LENGTH, 0); + states.put(GL2ES3.GL_PACK_SKIP_ROWS, 0); + states.put(GL2ES3.GL_PACK_SKIP_PIXELS, 0); + states.put(GL2GL3.GL_PACK_IMAGE_HEIGHT, 0); + states.put(GL2GL3.GL_PACK_SKIP_IMAGES, 0); + + states.put(GL.GL_UNPACK_ALIGNMENT, 4); + states.put(GL2GL3.GL_UNPACK_SWAP_BYTES, GL.GL_FALSE); + states.put(GL2GL3.GL_UNPACK_LSB_FIRST, GL.GL_FALSE); + states.put(GL2ES2.GL_UNPACK_ROW_LENGTH, 0); + states.put(GL2ES2.GL_UNPACK_SKIP_ROWS, 0); + states.put(GL2ES2.GL_UNPACK_SKIP_PIXELS, 0); + states.put(GL2ES3.GL_UNPACK_IMAGE_HEIGHT, 0); + states.put(GL2ES3.GL_UNPACK_SKIP_IMAGES, 0); + } + } + private volatile boolean enabled = true; - private IntIntHashMap pixelStateMap; + private PixelStateMap pixelStateMap; private final ArrayList<SavedState> stack; static class SavedState { @@ -73,32 +115,27 @@ public class GLStateTracker { /** * Empty pixel-store state */ - private IntIntHashMap pixelStateMap; + private PixelStateMap pixelStateMap; /** * set (client) pixel-store state, deep copy */ - final void setPixelStateMap(final IntIntHashMap pixelStateMap) { - this.pixelStateMap = (IntIntHashMap) pixelStateMap.clone(); + final void setPixelStateMap(final PixelStateMap pixelStateMap) { + this.pixelStateMap = new PixelStateMap(pixelStateMap); } /** * get (client) pixel-store state, return reference */ - final IntIntHashMap getPixelStateMap() { return pixelStateMap; } + final PixelStateMap getPixelStateMap() { return pixelStateMap; } } public GLStateTracker() { - pixelStateMap = new IntIntHashMap(PIXEL_STATE_MAP_CAPACITY, 0.75f); - pixelStateMap.setKeyNotFoundValue(0xFFFFFFFF); - resetStates(); + pixelStateMap = new PixelStateMap(); stack = new ArrayList<SavedState>(MIN_CLIENT_ATTRIB_STACK_DEPTH); - } - - public final void clearStates() { - pixelStateMap.clear(); + clearStates(); } public final void setEnabled(final boolean on) { @@ -109,11 +146,13 @@ public class GLStateTracker { return enabled; } + /** Return the local {@link PixelStateMap} */ + public final PixelStateMap getPixelStateMap() { return this.pixelStateMap; } /** @return true if found in our map, otherwise false, * which forces the caller to query GL. */ public final boolean getInt(final int pname, final int[] params, final int params_offset) { if(enabled) { - final int value = pixelStateMap.get(pname); + final int value = pixelStateMap.states.get(pname); if(0xFFFFFFFF != value) { params[params_offset] = value; return true; @@ -126,7 +165,7 @@ public class GLStateTracker { * which forces the caller to query GL. */ public final boolean getInt(final int pname, final IntBuffer params, final int dummy) { if(enabled) { - final int value = pixelStateMap.get(pname); + final int value = pixelStateMap.states.get(pname); if(0xFFFFFFFF != value) { params.put(params.position(), value); return true; @@ -137,10 +176,14 @@ public class GLStateTracker { public final void setInt(final int pname, final int param) { if(enabled) { - pixelStateMap.put(pname, param); + pixelStateMap.states.put(pname, param); } } + /** + * GL_CLIENT_PIXEL_STORE_BIT + * @param flags + */ public final void pushAttrib(final int flags) { if(enabled) { final SavedState state = new SavedState(); // empty-slot @@ -162,36 +205,18 @@ public class GLStateTracker { if(null==state) { throw new GLException("null stack element (remaining stack size "+stack.size()+")"); } - final IntIntHashMap statePixelStateMap = state.getPixelStateMap(); + final PixelStateMap savedPixelStateMap = state.getPixelStateMap(); - if ( null != statePixelStateMap ) { + if ( null != savedPixelStateMap ) { // use pulled client pixel-store state from stack - pixelStateMap = statePixelStateMap; + pixelStateMap = savedPixelStateMap; } // else: empty-slot, not pushed by GL_CLIENT_PIXEL_STORE_BIT } } - private final void resetStates() { - pixelStateMap.clear(); - - // 16 values -> PIXEL_STATE_MAP_SIZE - pixelStateMap.put(GL.GL_PACK_ALIGNMENT, 4); - pixelStateMap.put(GL2GL3.GL_PACK_SWAP_BYTES, GL.GL_FALSE); - pixelStateMap.put(GL2GL3.GL_PACK_LSB_FIRST, GL.GL_FALSE); - pixelStateMap.put(GL2ES3.GL_PACK_ROW_LENGTH, 0); - pixelStateMap.put(GL2ES3.GL_PACK_SKIP_ROWS, 0); - pixelStateMap.put(GL2ES3.GL_PACK_SKIP_PIXELS, 0); - pixelStateMap.put(GL2GL3.GL_PACK_IMAGE_HEIGHT, 0); - pixelStateMap.put(GL2GL3.GL_PACK_SKIP_IMAGES, 0); - - pixelStateMap.put(GL.GL_UNPACK_ALIGNMENT, 4); - pixelStateMap.put(GL2GL3.GL_UNPACK_SWAP_BYTES, GL.GL_FALSE); - pixelStateMap.put(GL2GL3.GL_UNPACK_LSB_FIRST, GL.GL_FALSE); - pixelStateMap.put(GL2ES2.GL_UNPACK_ROW_LENGTH, 0); - pixelStateMap.put(GL2ES2.GL_UNPACK_SKIP_ROWS, 0); - pixelStateMap.put(GL2ES2.GL_UNPACK_SKIP_PIXELS, 0); - pixelStateMap.put(GL2ES3.GL_UNPACK_IMAGE_HEIGHT, 0); - pixelStateMap.put(GL2ES3.GL_UNPACK_SKIP_IMAGES, 0); + public final void clearStates() { + stack.clear(); + pixelStateMap.clearStates(); } } |