aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp
diff options
context:
space:
mode:
authorSven Göthel <[email protected]>2024-01-09 03:13:20 +0100
committerSven Göthel <[email protected]>2024-01-09 03:13:20 +0100
commitbb11c498b7d4fe269e7273a1b164e46f3c7a3b50 (patch)
treeb613bdfa633df28841a68b45fe0e0f36e5385763 /src/jogl/classes/com/jogamp
parentf836fbd9201034010ecbf591348433f23920f527 (diff)
Graph Clipping: Initial Region impl of AABBox clipping using GLSL shader (Convenient using Graph/GraphUI produced AABBox)
Simple demo, setting clip-bbox manually: - src/demos/com/jogamp/opengl/demos/graph/ui/UIShapeClippingDemo00.java TODO: - GLSL: Add missing Mv-multiplication of vertex-position -> gcv_ClipBBoxCoord -- AABBox min/max should be set pre-multiplied w/ Mv covering an independent area, not per Shape/Region. -- This to properly work with moving/scaling of each Shape/Region etc
Diffstat (limited to 'src/jogl/classes/com/jogamp')
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java9
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java28
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java11
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/texture/TextureSequence.java4
4 files changed, 39 insertions, 13 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java
index 2cd40c6e4..af8a54177 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java
@@ -366,6 +366,7 @@ public abstract class GLRegion extends Region {
// gca_VerticesAttr.putf(coords, 0, 3);
// gca_CurveParamsAttr.putf(texParams, 0, 3);
// gca_VerticesAttr.put3f(coords.x(), coords.y(), coords.z());
+ // System.err.println("GLRegion V: "+coords);
put3f((FloatBuffer)vpc_ileave.getBuffer(), coords);
put3f((FloatBuffer)vpc_ileave.getBuffer(), texParams);
if( hasColorChannel() ) {
@@ -384,6 +385,7 @@ public abstract class GLRegion extends Region {
if( cc && null == rgba ) {
throw new IllegalArgumentException("Null color given for COLOR_CHANNEL rendering mode");
}
+ // System.err.println("GLRegion V: "+coords1+", "+coords2+", "+coords3);
put3f((FloatBuffer)vpc_ileave.getBuffer(), coords1);
put3f((FloatBuffer)vpc_ileave.getBuffer(), texParams1);
if( cc ) {
@@ -531,7 +533,7 @@ public abstract class GLRegion extends Region {
markStateDirty();
}
if( isShapeDirty() ) {
- updateImpl(gl, curRenderModes);
+ updateImpl(gl, renderer, curRenderModes);
}
drawImpl(gl, renderer, curRenderModes, sampleCount);
clearDirtyBits(DIRTY_SHAPE|DIRTY_STATE);
@@ -544,9 +546,8 @@ public abstract class GLRegion extends Region {
* objects for use in rendering if {@link #isShapeDirty()}.
* <p>Allocates the ogl related data and initializes it the 1st time.<p>
* <p>Called by {@link #draw(GL2ES2, RenderState, int, int, int)}.</p>
- * @param curRenderModes TODO
*/
- protected abstract void updateImpl(final GL2ES2 gl, int curRenderModes);
+ protected abstract void updateImpl(final GL2ES2 gl, final RegionRenderer renderer, final int curRenderModes);
- protected abstract void drawImpl(final GL2ES2 gl, final RegionRenderer renderer, int curRenderModes, final int[/*1*/] sampleCount);
+ protected abstract void drawImpl(final GL2ES2 gl, final RegionRenderer renderer, final int curRenderModes, final int[/*1*/] sampleCount);
}
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java
index 0927c41cb..06c10586c 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java
@@ -48,6 +48,7 @@ import com.jogamp.common.util.IntObjectHashMap;
import com.jogamp.graph.curve.Region;
import com.jogamp.math.Recti;
import com.jogamp.math.Vec4f;
+import com.jogamp.math.geom.AABBox;
import com.jogamp.math.util.PMVMatrix4f;
/**
@@ -302,6 +303,9 @@ public final class RegionRenderer {
public final void setColorStatic(final float r, final float g, final float b, final float a){ rs.setColorStatic(r, g, b, a); }
+ public final void setClipBBox(final AABBox clipBBox) { rs.setClipBBox(clipBBox); }
+ public final AABBox getClipBBox() { return rs.getClipBBox(); }
+
public final boolean isHintMaskSet(final int mask) { return rs.isHintMaskSet(mask); }
public final void setHintMask(final int mask) { rs.setHintMask(mask); }
@@ -398,9 +402,9 @@ public final class RegionRenderer {
private static final String SHADER_SRC_SUB = "";
private static final String SHADER_BIN_SUB = "bin";
-
private static final String GLSL_USE_COLOR_CHANNEL = "#define USE_COLOR_CHANNEL 1\n";
private static final String GLSL_USE_COLOR_TEXTURE = "#define USE_COLOR_TEXTURE 1\n";
+ private static final String GLSL_USE_AABBOX_CLIPPING = "#define USE_AABBOX_CLIPPING 1\n";
private static final String GLSL_DEF_SAMPLE_COUNT = "#define SAMPLE_COUNT ";
private static final String GLSL_CONST_SAMPLE_COUNT = "const float sample_count = ";
private static final String GLSL_MAIN_BEGIN = "void main (void)\n{\n";
@@ -530,6 +534,7 @@ public final class RegionRenderer {
final boolean pass1, final int quality, final int sampleCount, final TextureSequence colorTexSeq) {
final ShaderModeSelector1 sel1 = pass1 ? ShaderModeSelector1.selectPass1(renderModes) :
ShaderModeSelector1.selectPass2(renderModes, quality, sampleCount);
+ final boolean hasAABBoxClipping = null != getClipBBox();
final boolean isTwoPass = Region.isTwoPass( renderModes );
final boolean hasColorChannel = Region.hasColorChannel( renderModes );
final boolean hasColorTexture = Region.hasColorTexture( renderModes ) && null != colorTexSeq;
@@ -543,8 +548,16 @@ public final class RegionRenderer {
texLookupFuncName = null;
colorTexSeqHash = 0;
}
- final int shaderKey = ( (colorTexSeqHash << 5) - colorTexSeqHash ) +
- ( sel1.ordinal() | ( HIGH_MASK & renderModes ) | ( isTwoPass ? TWO_PASS_BIT : 0 ) );
+ final int shaderKey;
+ {
+ // 31 * x == (x << 5) - x
+ int hash = 31 + colorTexSeqHash;
+ hash = ((hash << 5) - hash) + sel1.ordinal();
+ hash = ((hash << 5) - hash) + ( HIGH_MASK & renderModes );
+ hash = ((hash << 5) - hash) + ( hasAABBoxClipping ? 1 : 0 );
+ hash = ((hash << 5) - hash) + ( isTwoPass ? TWO_PASS_BIT : 0 );
+ shaderKey = hash;
+ }
/**
if(DEBUG) {
@@ -617,6 +630,11 @@ public final class RegionRenderer {
posFp = rsFp.insertShaderSource(0, posFp, GLSL_USE_DISCARD);
}
+ if( hasAABBoxClipping ) {
+ posVp = rsVp.insertShaderSource(0, posVp, GLSL_USE_AABBOX_CLIPPING);
+ posFp = rsFp.insertShaderSource(0, posFp, GLSL_USE_AABBOX_CLIPPING);
+ }
+
if( hasColorChannel ) {
posVp = rsVp.insertShaderSource(0, posVp, GLSL_USE_COLOR_CHANNEL);
posFp = rsFp.insertShaderSource(0, posFp, GLSL_USE_COLOR_CHANNEL);
@@ -631,7 +649,9 @@ public final class RegionRenderer {
}
try {
- posFp = rsFp.insertShaderSource(0, posFp, AttributeNames.class, "functions.glsl");
+ if( isPass1ColorTexSeq || hasAABBoxClipping ) {
+ posFp = rsFp.insertShaderSource(0, posFp, AttributeNames.class, "functions.glsl");
+ }
posFp = rsFp.insertShaderSource(0, posFp, AttributeNames.class, "uniforms.glsl");
posFp = rsFp.insertShaderSource(0, posFp, AttributeNames.class, "varyings.glsl");
} catch (final IOException ioe) {
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java
index b1bbdde91..32483c1fc 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java
@@ -39,6 +39,7 @@ import jogamp.graph.curve.opengl.shader.UniformNames;
import com.jogamp.graph.curve.Region;
import com.jogamp.math.Vec4f;
+import com.jogamp.math.geom.AABBox;
import com.jogamp.math.util.PMVMatrix4f;
import com.jogamp.opengl.util.GLArrayDataWrapper;
import com.jogamp.opengl.util.glsl.ShaderProgram;
@@ -91,15 +92,16 @@ public class RenderState {
return (RenderState) gl.getContext().getAttachedObject(thisKey);
}
+ private final int id;
private final PMVMatrix4f pmvMatrix;
private final float[] weight;
private final FloatBuffer weightBuffer;
private final float[] colorStatic;
private final FloatBuffer colorStaticBuffer;
- private ShaderProgram sp;
+ private AABBox clipBBox;
private int hintBitfield;
+ private ShaderProgram sp;
- private final int id;
private static synchronized int getNextID() {
return nextID++;
}
@@ -189,13 +191,14 @@ public class RenderState {
*/
/* pp */ RenderState(final PMVMatrix4f sharedPMVMatrix) {
this.id = getNextID();
- this.sp = null;
this.pmvMatrix = null != sharedPMVMatrix ? sharedPMVMatrix : new PMVMatrix4f();
this.weight = new float[1];
this.weightBuffer = FloatBuffer.wrap(weight);
this.colorStatic = new float[] { 1, 1, 1, 1 };
this.colorStaticBuffer = FloatBuffer.wrap(colorStatic);
+ this.clipBBox = null;
this.hintBitfield = 0;
+ this.sp = null;
}
public final int id() { return id; }
@@ -259,6 +262,8 @@ public class RenderState {
colorStatic[3] = a;
}
+ public final void setClipBBox(final AABBox clipBBox) { this.clipBBox = clipBBox; }
+ public final AABBox getClipBBox() { return this.clipBBox; }
/**
*
diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureSequence.java b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureSequence.java
index 2951eec90..8376f0fa5 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureSequence.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureSequence.java
@@ -308,7 +308,7 @@ public interface TextureSequence {
/**
* Calculates the texture coordinates bounding box while correcting for aspect-ratio.
* @param tex the {@link Texture}
- * @param box the {@Link AABBpx} of the destination
+ * @param box the {@Link AABBox} of the destination
* @param letterBox true to produce letter-box space to match aspect-ratio, otherwise will zoom in
* @param colorTexBBox destination float[6] array for the following three texture-coordinate tuples: minX/minY, maxX/maxY, texW/texH
* @param verbose TODO
@@ -408,7 +408,7 @@ public interface TextureSequence {
System.err.println("XXX setTexCoordBBox:");
System.err.println("XXX ColorTex imgRatio "+imgRatio+", texRatio "+texRatio+", texPixelRatio[w "+texWidthRatio+", h "+texHeightRatio+"], "+tex);
System.err.println("XXX ColorTexBBox lbox "+letterBox+", cut "+boxWidthCut+"/"+boxHeightCut+", ext "+boxWidthExt+"/"+boxHeightExt);
- System.err.println("XXX ColorTexBBox min "+colorTexBBox[0]+"/"+colorTexBBox[1]+", max "+colorTexBBox[2]+" x "+colorTexBBox[3]+
+ System.err.println("XXX ColorTexBBox min "+colorTexBBox[0]+"/"+colorTexBBox[1]+", max "+colorTexBBox[2]+"/"+colorTexBBox[3]+
", dim "+colorTexBBoxW+" x "+colorTexBBoxH+
", tc-dim "+tcW+" x "+tcH+", tc "+tc+", box2ImgRatio "+box2ImgRatio+", box2TexRatio "+box2TexRatio);
System.err.println("XXX Box ratio "+boxRatio+", "+box);