summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/jogamp/opengl
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-08-01 14:07:27 +0200
committerSven Gothel <[email protected]>2023-08-01 14:07:27 +0200
commit76078006e7befe830a235fbceda0d46e7db0c149 (patch)
treeca71dfd861b0be6f206ae034cba7ff76bebc8ad7 /src/jogl/classes/jogamp/opengl
parent16b9a3ac358b3ad34dd9eb9df090b59f25e26b75 (diff)
GLStateTracker: Add tracking of blending states (part-1)
Diffstat (limited to 'src/jogl/classes/jogamp/opengl')
-rw-r--r--src/jogl/classes/jogamp/opengl/GLStateTracker.java131
1 files changed, 129 insertions, 2 deletions
diff --git a/src/jogl/classes/jogamp/opengl/GLStateTracker.java b/src/jogl/classes/jogamp/opengl/GLStateTracker.java
index 4084887da..83b85a7e6 100644
--- a/src/jogl/classes/jogamp/opengl/GLStateTracker.java
+++ b/src/jogl/classes/jogamp/opengl/GLStateTracker.java
@@ -53,7 +53,6 @@ import java.util.ArrayList;
* Currently supported states: PixelStorei
*/
public class GLStateTracker {
-
/** Minimum value of MAX_CLIENT_ATTRIB_STACK_DEPTH */
public static final int MIN_CLIENT_ATTRIB_STACK_DEPTH = 16;
@@ -104,19 +103,124 @@ public class GLStateTracker {
}
}
+ /**
+ * Blending function and equation states per output draw buffer without color and enable.
+ * <p>
+ * GL_MAX_DRAW_BUFFERS >= 8
+ * </p>
+ */
+ public static class BlendFuncEq {
+ /**
+ * Set via {@link GL#glBlendFunc(int, int)}, {@link GL#glBlendFuncSeparate(int, int, int, int)}
+ * or {@link GL2ES3#glBlendFunci(int, int, int)}, {@link GL2ES3#glBlendFuncSeparatei(int, int, int, int, int)}.
+ * <p>
+ * Values are one of
+ * <code>
+ * GL_ZERO (dest default), GL_ONE (source default),
+ * GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR,
+ * GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA,
+ * GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR, GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA,
+ * GL_SRC_ALPHA_SATURATE, GL_SRC1_COLOR, GL_ONE_MINUS_SRC1_COLOR, GL_SRC1_ALPHA, and GL_ONE_MINUS_SRC1_ALPHA
+ * </code>
+ * </p>
+ */
+ int dst_alpha;
+ /** See {@link #dst_alpha}. */
+ int dst_rgb;
+ /** See {@link #dst_alpha}. */
+ int src_alpha;
+ /** See {@link #dst_alpha}. */
+ int src_rgb;
+ /**
+ * Set via {@link GL#glBlendEquation(int)}, {@link GL#glBlendEquationSeparate(int, int)}
+ * or {@link GL2ES3#glBlendEquationi(int, int)}, {@link GL2ES3#glBlendEquationSeparatei(int, int, int)}.
+ * <p>
+ * Values are on of
+ * <code>
+ * GL_FUNC_ADD (default), GL_FUNC_SUBTRACT, GL_FUNC_REVERSE_SUBTRACT, GL_MIN, GL_MAX.
+ * </code>
+ * </p>
+ */
+ int eq_alpha;
+ /** See {@link #eq_alpha}. */
+ int eq_rgb;
+ public BlendFuncEq() {
+ clearStates();
+ }
+ /** Copy constructor */
+ public BlendFuncEq(final BlendFuncEq src) {
+ set(src);
+ }
+ /** Set this instance's state using OpenGL default values. */
+ public final void clearStates() {
+ dst_alpha = GL.GL_ZERO;
+ dst_rgb = GL.GL_ZERO;
+ src_alpha = GL.GL_ONE;
+ src_rgb = GL.GL_ONE;
+ eq_alpha = GL.GL_FUNC_ADD;
+ eq_rgb = GL.GL_FUNC_ADD;
+ }
+ /** Set this instance's state using given src values */
+ public final void set(final BlendFuncEq src) {
+ dst_alpha = src.dst_alpha;
+ dst_rgb = src.dst_rgb;
+ src_alpha = src.src_alpha;
+ src_rgb = src.src_rgb;
+ eq_alpha = src.eq_alpha;
+ eq_rgb = src.eq_rgb;
+ }
+ }
+
+ /** Global blending states color and enabled. */
+ public static class BlendGlobal {
+ /** glBlendColor(..) */
+ public float r, g, b, a;
+ public boolean enabled;
+ public BlendFuncEq state;
+
+ public BlendGlobal() {
+ state = new BlendFuncEq();
+ clearStates();
+ }
+
+ /** Copy constructor */
+ public BlendGlobal(final BlendGlobal src) {
+ set(src);
+ }
+ /** Set this instance's state using OpenGL default values. */
+ public final void clearStates() {
+ r=0f; g=0f; b=0f; a=0f;
+ enabled = false;
+ state.clearStates();
+ }
+ /** Set this instance's state using given src values */
+ public final void set(final BlendGlobal src) {
+ r = src.r;
+ g = src.g;
+ b = src.b;
+ a = src.a;
+ enabled = src.enabled;
+ state.set(src.state);
+ }
+ }
private volatile boolean enabled = true;
private PixelStateMap pixelStateMap;
+ private final BlendGlobal blendGlobalState;
+ private final ArrayList<BlendFuncEq> blendStatePerOutput;
+
private final ArrayList<SavedState> stack;
static class SavedState {
-
/**
* Empty pixel-store state
*/
private PixelStateMap pixelStateMap;
+ // private BlendGlobal blendState;
+ // private ArrayList<BlendFuncEq> blendStatePerOutput;
+
/**
* set (client) pixel-store state, deep copy
*/
@@ -125,14 +229,30 @@ public class GLStateTracker {
}
/**
+ * set (client) pixel-store state, deep copy
+ final void setPixelStateMap(final PixelStateMap pixelStateMap, final BlendGlobal blendState, final ArrayList<BlendFuncEq> blendStatePerOutput) {
+ this.pixelStateMap = new PixelStateMap(pixelStateMap);
+ this.blendState = new BlendGlobal(blendState);
+ this.blendStatePerOutput = new ArrayList<BlendFuncEq>(blendStatePerOutput.size());
+ for(final BlendFuncEq bfeq : blendStatePerOutput) {
+ this.blendStatePerOutput.add(new BlendFuncEq(bfeq));
+ }
+ }
+ */
+
+ /**
* get (client) pixel-store state, return reference
*/
final PixelStateMap getPixelStateMap() { return pixelStateMap; }
+ // final BlendGlobal getBlendGlobal() { return blendState; }
+ // final ArrayList<BlendFuncEq> getBlendStatePerOutput() { return blendStatePerOutput; }
}
public GLStateTracker() {
pixelStateMap = new PixelStateMap();
+ blendGlobalState = new BlendGlobal();
+ blendStatePerOutput = new ArrayList<BlendFuncEq>(0); // FIXME
stack = new ArrayList<SavedState>(MIN_CLIENT_ATTRIB_STACK_DEPTH);
clearStates();
@@ -148,6 +268,11 @@ public class GLStateTracker {
/** Return the local {@link PixelStateMap} */
public final PixelStateMap getPixelStateMap() { return this.pixelStateMap; }
+ /** Return the local {@link BlendGlobal} */
+ public final BlendGlobal getBlendGlobal() { return blendGlobalState; }
+ /** Return the local array of {@link BlendFuncEq} */
+ public final ArrayList<BlendFuncEq> getBlendStatePerOutput() { return this.blendStatePerOutput; }
+
/** @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) {
@@ -217,6 +342,8 @@ public class GLStateTracker {
public final void clearStates() {
stack.clear();
pixelStateMap.clearStates();
+ blendGlobalState.clearStates();
+ blendStatePerOutput.clear();
}
}