aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--make/scripts/tests.sh1
-rw-r--r--src/demos/com/jogamp/opengl/demos/graph/ui/UIShapeClippingDemo00.java350
-rw-r--r--src/graphui/classes/com/jogamp/graph/ui/shapes/Rectangle.java3
-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
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java32
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java35
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java26
10 files changed, 465 insertions, 34 deletions
diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh
index 0bc112255..8c0effbd2 100644
--- a/make/scripts/tests.sh
+++ b/make/scripts/tests.sh
@@ -1007,6 +1007,7 @@ function testawtswt() {
#
#testnoawt com.jogamp.opengl.demos.graph.GPUTextNewtDemo $*
#testnoawt com.jogamp.opengl.demos.graph.GPURegionNewtDemo $*
+#testnoawt com.jogamp.opengl.demos.graph.ui.UIShapeClippingDemo00 $*
#testnoawt com.jogamp.opengl.demos.graph.ui.UIShapeDemo01 $*
#testnoawt com.jogamp.opengl.demos.graph.ui.UITypeDemo01 $*
diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UIShapeClippingDemo00.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UIShapeClippingDemo00.java
new file mode 100644
index 000000000..08d771d8a
--- /dev/null
+++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UIShapeClippingDemo00.java
@@ -0,0 +1,350 @@
+/**
+ * Copyright 2010-2024 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package com.jogamp.opengl.demos.graph.ui;
+
+import java.io.File;
+import java.io.IOException;
+
+import com.jogamp.common.util.InterruptSource;
+import com.jogamp.graph.curve.Region;
+import com.jogamp.graph.curve.opengl.RegionRenderer;
+import com.jogamp.graph.ui.Shape;
+import com.jogamp.graph.ui.shapes.Rectangle;
+import com.jogamp.math.FloatUtil;
+import com.jogamp.math.geom.plane.AffineTransform;
+import com.jogamp.math.util.PMVMatrix4f;
+import com.jogamp.newt.Window;
+import com.jogamp.newt.event.KeyAdapter;
+import com.jogamp.newt.event.KeyEvent;
+import com.jogamp.newt.event.KeyListener;
+import com.jogamp.newt.event.WindowAdapter;
+import com.jogamp.newt.event.WindowEvent;
+import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.opengl.GL;
+import com.jogamp.opengl.GL2ES2;
+import com.jogamp.opengl.GLAutoDrawable;
+import com.jogamp.opengl.GLCapabilities;
+import com.jogamp.opengl.GLEventListener;
+import com.jogamp.opengl.GLException;
+import com.jogamp.opengl.GLPipelineFactory;
+import com.jogamp.opengl.GLRunnable;
+import com.jogamp.opengl.demos.graph.MSAATool;
+import com.jogamp.opengl.demos.util.CommandlineOptions;
+import com.jogamp.opengl.util.Animator;
+import com.jogamp.opengl.util.GLReadBufferUtil;
+
+/**
+ * Basic UIShape Clipping demo.
+ *
+ * Action Cursor-Keys:
+ * - With Control: Move Left and Bottom Clipping Edge of AABBox
+ * - No Modifiers: Move Right and Top Clipping Edge of AABBox
+ */
+public class UIShapeClippingDemo00 implements GLEventListener {
+ static final boolean DEBUG = false;
+ static final boolean TRACE = false;
+
+ static CommandlineOptions options = new CommandlineOptions(1280, 720, Region.VBAA_RENDERING_BIT);
+
+ static final float szw = 1/3f * 0.8f;
+ static final float szh = szw * 1f/2f;
+ static Rectangle clipRect;
+
+ public static void main(final String[] args) throws IOException {
+ final int[] idx = { 0 };
+ for (idx[0] = 0; idx[0] < args.length; ++idx[0]) {
+ if( options.parse(args, idx) ) {
+ continue;
+ }
+ }
+ System.err.println(options);
+ final GLCapabilities reqCaps = options.getGLCaps();
+ System.out.println("Requested: " + reqCaps);
+
+ final GLWindow window = GLWindow.create(reqCaps);
+ // window.setPosition(10, 10);
+ window.setSize(options.surface_width, options.surface_height);
+ window.setTitle(UIShapeClippingDemo00.class.getSimpleName()+": "+window.getSurfaceWidth()+" x "+window.getSurfaceHeight());
+
+ clipRect = new Rectangle(options.renderModes, szw, szh, 1/2000f);
+ clipRect.move(-szw/2f, -szh/2f, 0).setColor(0, 0, 0, 1);
+
+ final UIShapeClippingDemo00 uiGLListener = new UIShapeClippingDemo00(options.renderModes, DEBUG, TRACE);
+ uiGLListener.attachInputListenerTo(window);
+ window.addGLEventListener(uiGLListener);
+ window.setVisible(true);
+
+ final Animator animator = new Animator(0 /* w/o AWT */);
+ animator.setUpdateFPSFrames(5*60, null);
+ animator.add(window);
+
+ window.addKeyListener(new KeyAdapter() {
+ @Override
+ public void keyPressed(final KeyEvent arg0) {
+ final short keySym = arg0.getKeySymbol();
+ final float less = 0.99f;
+ final float more = 1.01f;
+ final float x = clipRect.getX();
+ final float y = clipRect.getY();
+ final float z = clipRect.getZ();
+ final float w = clipRect.getWidth();
+ final float h = clipRect.getHeight();
+ if( keySym == KeyEvent.VK_LEFT ) {
+ if( arg0.isControlDown() ) {
+ final float d = w*more - w;
+ clipRect.setPosition(x-d, y, z);
+ clipRect.setDimension(w*more, h, clipRect.getLineWidth());
+ } else {
+ clipRect.setDimension(w*less, h, clipRect.getLineWidth());
+ }
+ } else if( keySym == KeyEvent.VK_RIGHT ) {
+ if( arg0.isControlDown() ) {
+ final float d = w - w*less;
+ clipRect.setPosition(x+d, y, z);
+ clipRect.setDimension(w*less, h, clipRect.getLineWidth());
+ } else {
+ clipRect.setDimension(w*more, h, clipRect.getLineWidth());
+ }
+ } else if( keySym == KeyEvent.VK_UP ) {
+ if( arg0.isControlDown() ) {
+ final float d = h - h*less;
+ clipRect.setPosition(x, y+d, z);
+ clipRect.setDimension(w, h*less, clipRect.getLineWidth());
+ } else {
+ clipRect.setDimension(w, h*more, clipRect.getLineWidth());
+ }
+ } else if( keySym == KeyEvent.VK_DOWN ) {
+ if( arg0.isControlDown() ) {
+ final float d = h*more - h;
+ clipRect.setPosition(x, y-d, z);
+ clipRect.setDimension(w, h*more, clipRect.getLineWidth());
+ } else {
+ clipRect.setDimension(w, h*less, clipRect.getLineWidth());
+ }
+ } else if( keySym == KeyEvent.VK_F4 || keySym == KeyEvent.VK_ESCAPE || keySym == KeyEvent.VK_Q ) {
+ new InterruptSource.Thread( () -> { window.destroy(); } ).start();
+ }
+ }
+ });
+ window.addWindowListener(new WindowAdapter() {
+ @Override
+ public void windowDestroyed(final WindowEvent e) {
+ animator.stop();
+ }
+ });
+
+ animator.start();
+ }
+
+ private final GLReadBufferUtil screenshot;
+ private final int renderModes;
+ private final RegionRenderer rRenderer;
+ private final boolean debug;
+ private final boolean trace;
+
+ private Shape shape;
+
+ private KeyAction keyAction;
+
+ private volatile GLAutoDrawable autoDrawable = null;
+
+ private final float[] position = new float[] {0,0,0};
+
+ private static final float xTran = 0f;
+ private static final float yTran = 0f;
+ private static final float zTran = -1/5f;
+ private static final float zNear = 0.1f;
+ private static final float zFar = 7000.0f;
+
+ boolean ignoreInput = false;
+
+ protected final AffineTransform tempT1 = new AffineTransform();
+ protected final AffineTransform tempT2 = new AffineTransform();
+
+ public UIShapeClippingDemo00(final int renderModes, final boolean debug, final boolean trace) {
+ this.renderModes = renderModes;
+ this.rRenderer = RegionRenderer.create(RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable);
+ this.debug = debug;
+ this.trace = trace;
+ this.screenshot = new GLReadBufferUtil(false, false);
+
+ this.shape = new Rectangle(renderModes, szw, szh, 0);
+ this.shape.move(-szw/2f, -szh/2f, 0);
+ }
+
+ public final RegionRenderer getRegionRenderer() { return rRenderer; }
+ public final float[] getPosition() { return position; }
+
+ @Override
+ public void init(final GLAutoDrawable drawable) {
+ autoDrawable = drawable;
+ GL2ES2 gl = drawable.getGL().getGL2ES2();
+ if(debug) {
+ gl = gl.getContext().setGL( GLPipelineFactory.create("com.jogamp.opengl.Debug", null, gl, null) ).getGL2ES2();
+ }
+ if(trace) {
+ gl = gl.getContext().setGL( GLPipelineFactory.create("com.jogamp.opengl.Trace", null, gl, new Object[] { System.err } ) ).getGL2ES2();
+ }
+ gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
+ getRegionRenderer().init(gl);
+
+ gl.setSwapInterval(1);
+ gl.glEnable(GL.GL_DEPTH_TEST);
+ // gl.glEnable(GL.GL_POLYGON_OFFSET_FILL);
+ MSAATool.dump(drawable);
+ }
+
+ @Override
+ public void reshape(final GLAutoDrawable drawable, final int xstart, final int ystart, final int width, final int height) {
+ // final GL2ES2 gl = drawable.getGL().getGL2ES2();
+ // gl.glViewport(xstart, ystart, width, height);
+
+ rRenderer.reshapePerspective(FloatUtil.QUARTER_PI, width, height, zNear, zFar);
+ // rRenderer.reshapeOrtho(width, height, zNear, zFar);
+
+ final PMVMatrix4f pmv = rRenderer.getMatrix();
+ pmv.loadMvIdentity();
+ pmv.translateMv(xTran, yTran, zTran);
+
+ if( drawable instanceof Window ) {
+ ((Window)drawable).setTitle(UIShapeClippingDemo00.class.getSimpleName()+": "+drawable.getSurfaceWidth()+" x "+drawable.getSurfaceHeight());
+ }
+ }
+
+ final int[] sampleCount = { 4 };
+
+ private void drawShape(final GL2ES2 gl, final RegionRenderer renderer, final Shape shape) {
+ final PMVMatrix4f pmv = renderer.getMatrix();
+ pmv.pushMv();
+ if( null != shape && shape.isVisible() ) {
+ shape.setTransformMv(pmv);
+ shape.draw(gl, renderer, sampleCount);
+ }
+ pmv.popMv();
+ }
+
+ @Override
+ public void display(final GLAutoDrawable drawable) {
+ final GL2ES2 gl = drawable.getGL().getGL2ES2();
+
+ gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
+ gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
+
+ final RegionRenderer renderer = getRegionRenderer();
+ renderer.enable(gl, true);
+ {
+ drawShape(gl, renderer, clipRect);
+ renderer.setClipBBox(clipRect.getBounds());
+ // System.err.println("Clipping "+renderer.getClipBBox());
+ drawShape(gl, renderer, shape);
+ // System.err.println("draw.0: "+shape);
+ renderer.setClipBBox(null);
+ }
+ renderer.enable(gl, false);
+ }
+
+ @Override
+ public void dispose(final GLAutoDrawable drawable) {
+ final GL2ES2 gl = drawable.getGL().getGL2ES2();
+ if( null != shape ) {
+ shape.destroy(gl, getRegionRenderer());
+ shape = null;
+ }
+ if( null != clipRect ) {
+ clipRect.destroy(gl, getRegionRenderer());
+ }
+ autoDrawable = null;
+ screenshot.dispose(gl);
+ rRenderer.destroy(gl);
+ }
+
+ /** Attach the input listener to the window */
+ public void attachInputListenerTo(final GLWindow window) {
+ if ( null == keyAction ) {
+ keyAction = new KeyAction();
+ window.addKeyListener(keyAction);
+ }
+ }
+
+ public void detachFrom(final GLWindow window) {
+ if ( null == keyAction ) {
+ return;
+ }
+ window.removeGLEventListener(this);
+ window.removeKeyListener(keyAction);
+ }
+
+ public void printScreen(final GLAutoDrawable drawable, final String dir, final String tech, final String objName, final boolean exportAlpha) throws GLException, IOException {
+ final String sw = String.format("-%03dx%03d-Z%04d-T%04d-%s", drawable.getSurfaceWidth(), drawable.getSurfaceHeight(), (int)Math.abs(zTran), 0, objName);
+
+ final String filename = dir + tech + sw +".png";
+ if(screenshot.readPixels(drawable.getGL(), false)) {
+ screenshot.write(new File(filename));
+ }
+ }
+
+ int screenshot_num = 0;
+
+ public void setIgnoreInput(final boolean v) {
+ ignoreInput = v;
+ }
+ public boolean getIgnoreInput() {
+ return ignoreInput;
+ }
+
+ public class KeyAction implements KeyListener {
+ @Override
+ public void keyPressed(final KeyEvent arg0) {
+ if(ignoreInput) {
+ return;
+ }
+
+ if(arg0.getKeyCode() == KeyEvent.VK_S){
+ if(null != autoDrawable) {
+ autoDrawable.invoke(false, new GLRunnable() {
+ @Override
+ public boolean run(final GLAutoDrawable drawable) {
+ try {
+ final String type = Region.getRenderModeString(renderModes);
+ printScreen(drawable, "./", "demo-"+type, "snap"+screenshot_num, false);
+ screenshot_num++;
+ } catch (final GLException e) {
+ e.printStackTrace();
+ } catch (final IOException e) {
+ e.printStackTrace();
+ }
+ return true;
+ }
+ });
+ }
+ }
+ }
+ @Override
+ public void keyReleased(final KeyEvent arg0) {}
+ }
+}
diff --git a/src/graphui/classes/com/jogamp/graph/ui/shapes/Rectangle.java b/src/graphui/classes/com/jogamp/graph/ui/shapes/Rectangle.java
index fd564c800..ae2af3960 100644
--- a/src/graphui/classes/com/jogamp/graph/ui/shapes/Rectangle.java
+++ b/src/graphui/classes/com/jogamp/graph/ui/shapes/Rectangle.java
@@ -108,6 +108,9 @@ public class Rectangle extends GraphShape {
this( renderModes, 0, 0, width, height, lineWidth, 0);
}
+ public final float getX() { return minX; }
+ public final float getY() { return minY; }
+ public final float getZ() { return zPos; }
public final float getWidth() { return width; }
public final float getHeight() { return height; }
public final float getLineWidth() { return lineWidth; }
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);
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java
index 040e0328c..7abcf8818 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java
@@ -62,6 +62,8 @@ public final class VBORegion2PMSAAES2 extends GLRegion {
private final GLUniformData gcu_ColorTexUnit;
private final float[] colorTexBBox; // minX/minY, maxX/maxY, texW/texH
private final GLUniformData gcu_ColorTexBBox; // vec2 gcu_ColorTexBBox[3] -> boxMin[2], boxMax[2] and texSize[2]
+ private final float[] clipBBox; // minX/minY/minZ, maxX/maxY/maxZ
+ private final GLUniformData gcu_ClipBBox; // uniform vec3 gcu_ClipBBox[2]; // box-min[3], box-max[3]
private ShaderProgram spPass1 = null;
// Pass-2:
@@ -103,6 +105,8 @@ public final class VBORegion2PMSAAES2 extends GLRegion {
colorTexBBox = null;
gcu_ColorTexBBox = null;
}
+ clipBBox = new float[6];
+ gcu_ClipBBox = new GLUniformData(UniformNames.gcu_ClipBBox, 3, FloatBuffer.wrap(clipBBox));
gcu_PMVMatrix02 = new GLUniformData(UniformNames.gcu_PMVMatrix02, 4, 4, new SyncMatrices4f16( new Matrix4f[] { matP, matMv } ));
// Pass 2:
@@ -136,8 +140,8 @@ public final class VBORegion2PMSAAES2 extends GLRegion {
}
@Override
- protected void updateImpl(final GL2ES2 gl, final int curRenderModes) {
- final boolean hasColorChannel = Region.hasColorChannel( curRenderModes );
+ protected void updateImpl(final GL2ES2 gl, final RegionRenderer renderer, final int curRenderModes) {
+ // final boolean hasColorChannel = Region.hasColorChannel( curRenderModes );
final boolean hasColorTexture = Region.hasColorTexture( curRenderModes );
// seal buffers
@@ -186,6 +190,8 @@ public final class VBORegion2PMSAAES2 extends GLRegion {
final boolean hasColorTexture = Region.hasColorTexture( curRenderModes ) && null != colorTexSeq;
final RenderState rs = renderer.getRenderState();
+ final boolean hasAABBoxClipping = null != rs.getClipBBox();
+
final boolean updateLocGlobal = renderer.useShaderProgram(gl, curRenderModes, pass1, quality, sampleCount, colorTexSeq);
final ShaderProgram sp = renderer.getRenderState().getShaderProgram();
final boolean updateLocLocal;
@@ -203,6 +209,9 @@ public final class VBORegion2PMSAAES2 extends GLRegion {
if( hasColorChannel && null != gca_ColorsAttr ) {
rs.updateAttributeLoc(gl, true, gca_ColorsAttr, true);
}
+ if( hasAABBoxClipping ) {
+ rs.updateUniformLoc(gl, true, gcu_ClipBBox, true);
+ }
}
rsLocal.update(gl, rs, updateLocLocal, curRenderModes, true, true);
if( isTwoPass ) {
@@ -248,16 +257,16 @@ public final class VBORegion2PMSAAES2 extends GLRegion {
}
return; // inf
}
+ final RenderState rs = renderer.getRenderState();
final int vpWidth = renderer.getWidth();
final int vpHeight = renderer.getHeight();
if(vpWidth <=0 || vpHeight <= 0 || null==sampleCount || sampleCount[0] <= 0) {
useShaderProgram(gl, renderer, curRenderModes, true, getQuality(), sampleCount[0]);
- renderRegion(gl, curRenderModes);
+ renderRegion(gl, rs, curRenderModes);
} else {
if(0 > maxTexSize[0]) {
gl.glGetIntegerv(GL.GL_MAX_TEXTURE_SIZE, maxTexSize, 0);
}
- final RenderState rs = renderer.getRenderState();
final float winWidth, winHeight;
final float ratioObjWinWidth, ratioObjWinHeight;
@@ -449,17 +458,26 @@ public final class VBORegion2PMSAAES2 extends GLRegion {
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
}
- renderRegion(gl, curRenderModes);
+ renderRegion(gl, rs, curRenderModes);
fbo.unbind(gl);
fboDirty = false;
}
- private void renderRegion(final GL2ES2 gl, final int curRenderModes) {
- final boolean hasColorChannel = Region.hasColorChannel( curRenderModes );
+ private void renderRegion(final GL2ES2 gl, final RenderState rs, final int curRenderModes) {
+ // final boolean hasColorChannel = Region.hasColorChannel( curRenderModes );
final boolean hasColorTexture = Region.hasColorTexture( curRenderModes );
gl.glUniform(gcu_PMVMatrix02);
+ {
+ final AABBox cb = rs.getClipBBox();
+ if( null != cb ) {
+ clipBBox[0] = cb.getMinX(); clipBBox[1] = cb.getMinY(); clipBBox[2] = cb.getMinZ();
+ clipBBox[3] = cb.getMaxX(); clipBBox[4] = cb.getMaxY(); clipBBox[5] = cb.getMaxZ();
+ gl.glUniform(gcu_ClipBBox); // Always update, since program maybe used by multiple regions
+ }
+ }
+
vpc_ileave.enableBuffer(gl, true);
indicesBuffer.bindBuffer(gl, true); // keeps VBO binding
if( hasColorTexture && null != gcu_ColorTexUnit && colorTexSeq.isTextureAvailable() ) {
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java
index a26e5d70a..82426a73c 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java
@@ -95,7 +95,8 @@ public final class VBORegion2PVBAAES2 extends GLRegion {
private final GLUniformData gcu_ColorTexUnit;
private final float[] colorTexBBox; // minX/minY, maxX/maxY, texW/texH
private final GLUniformData gcu_ColorTexBBox; // vec2 gcu_ColorTexBBox[3] -> boxMin[2], boxMax[2] and texSize[2]
-
+ private final float[] clipBBox; // minX/minY/minZ, maxX/maxY/maxZ
+ private final GLUniformData gcu_ClipBBox; // uniform vec3 gcu_ClipBBox[2]; // box-min[3], box-max[3]
private ShaderProgram spPass1 = null;
// Pass-2:
@@ -137,6 +138,8 @@ public final class VBORegion2PVBAAES2 extends GLRegion {
final boolean hasColorTexture = Region.hasColorTexture( curRenderModes ) && null != colorTexSeq;
final RenderState rs = renderer.getRenderState();
+ final boolean hasAABBoxClipping = null != rs.getClipBBox();
+
final boolean updateLocGlobal = renderer.useShaderProgram(gl, curRenderModes, pass1, quality, sampleCount, colorTexSeq);
final ShaderProgram sp = renderer.getRenderState().getShaderProgram();
final boolean updateLocLocal;
@@ -154,6 +157,9 @@ public final class VBORegion2PVBAAES2 extends GLRegion {
if( hasColorChannel && null != gca_ColorsAttr ) {
rs.updateAttributeLoc(gl, true, gca_ColorsAttr, true);
}
+ if( hasAABBoxClipping ) {
+ rs.updateUniformLoc(gl, true, gcu_ClipBBox, true);
+ }
}
rsLocal.update(gl, rs, updateLocLocal, curRenderModes, true, true);
if( isTwoPass ) {
@@ -200,6 +206,8 @@ public final class VBORegion2PVBAAES2 extends GLRegion {
colorTexBBox = null;
gcu_ColorTexBBox = null;
}
+ clipBBox = new float[6];
+ gcu_ClipBBox = new GLUniformData(UniformNames.gcu_ClipBBox, 3, FloatBuffer.wrap(clipBBox));
gcu_PMVMatrix02 = new GLUniformData(UniformNames.gcu_PMVMatrix02, 4, 4, new SyncMatrices4f16( new Matrix4f[] { matP, matMv } ));
// Pass 2:
@@ -234,9 +242,8 @@ public final class VBORegion2PVBAAES2 extends GLRegion {
}
@Override
- protected void updateImpl(final GL2ES2 gl, final int curRenderModes) {
- @SuppressWarnings("unused")
- final boolean hasColorChannel = Region.hasColorChannel( curRenderModes );
+ protected void updateImpl(final GL2ES2 gl, final RegionRenderer renderer, final int curRenderModes) {
+ // final boolean hasColorChannel = Region.hasColorChannel( curRenderModes );
final boolean hasColorTexture = Region.hasColorTexture( curRenderModes );
// seal buffers
@@ -284,16 +291,16 @@ public final class VBORegion2PVBAAES2 extends GLRegion {
}
return; // inf
}
+ final RenderState rs = renderer.getRenderState();
final int vpWidth = renderer.getWidth();
final int vpHeight = renderer.getHeight();
if(vpWidth <=0 || vpHeight <= 0 || null==sampleCount || sampleCount[0] <= 0) {
useShaderProgram(gl, renderer, curRenderModes, true, getQuality(), sampleCount[0]);
- renderRegion(gl, curRenderModes);
+ renderRegion(gl, rs, curRenderModes);
} else {
if(0 > maxTexSize[0]) {
gl.glGetIntegerv(GL.GL_MAX_TEXTURE_SIZE, maxTexSize, 0);
}
- final RenderState rs = renderer.getRenderState();
final float winWidth, winHeight;
final float ratioObjWinWidth, ratioObjWinHeight;
@@ -388,7 +395,7 @@ public final class VBORegion2PVBAAES2 extends GLRegion {
}
if( sampleCount[0] <= 0 ) {
// Last way out!
- renderRegion(gl, curRenderModes);
+ renderRegion(gl, rs, curRenderModes);
return;
}
}
@@ -555,17 +562,25 @@ public final class VBORegion2PVBAAES2 extends GLRegion {
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
}
- renderRegion(gl, curRenderModes);
+ renderRegion(gl, rs, curRenderModes);
fbo.unbind(gl);
fboDirty = false;
}
- private void renderRegion(final GL2ES2 gl, final int curRenderModes) {
- final boolean hasColorChannel = Region.hasColorChannel( curRenderModes );
+ private void renderRegion(final GL2ES2 gl, final RenderState rs, final int curRenderModes) {
+ // final boolean hasColorChannel = Region.hasColorChannel( curRenderModes );
final boolean hasColorTexture = Region.hasColorTexture( curRenderModes );
gl.glUniform(gcu_PMVMatrix02);
+ {
+ final AABBox cb = rs.getClipBBox();
+ if( null != cb ) {
+ clipBBox[0] = cb.getMinX(); clipBBox[1] = cb.getMinY(); clipBBox[2] = cb.getMinZ();
+ clipBBox[3] = cb.getMaxX(); clipBBox[4] = cb.getMaxY(); clipBBox[5] = cb.getMaxZ();
+ gl.glUniform(gcu_ClipBBox); // Always update, since program maybe used by multiple regions
+ }
+ }
vpc_ileave.enableBuffer(gl, true);
indicesBuffer.bindBuffer(gl, true); // keeps VBO binding
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
index 2514f4a1e..281757da4 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
@@ -40,6 +40,7 @@ import com.jogamp.graph.curve.Region;
import com.jogamp.graph.curve.opengl.GLRegion;
import com.jogamp.graph.curve.opengl.RegionRenderer;
import com.jogamp.graph.curve.opengl.RenderState;
+import com.jogamp.math.geom.AABBox;
import com.jogamp.opengl.util.glsl.ShaderProgram;
import com.jogamp.opengl.util.texture.Texture;
import com.jogamp.opengl.util.texture.TextureSequence;
@@ -51,6 +52,8 @@ public final class VBORegionSPES2 extends GLRegion {
private final GLUniformData gcu_ColorTexUnit;
private final float[] colorTexBBox; // minX/minY, maxX/maxY, texW/texH
private final GLUniformData gcu_ColorTexBBox; // vec2 gcu_ColorTexBBox[3] -> boxMin[2], boxMax[2] and texSize[2]
+ private final float[] clipBBox; // minX/minY/minZ, maxX/maxY/maxZ
+ private final GLUniformData gcu_ClipBBox; // uniform vec3 gcu_ClipBBox[2]; // box-min[3], box-max[3]
private ShaderProgram spPass1 = null;
public VBORegionSPES2(final GLProfile glp, final int renderModes, final TextureSequence colorTexSeq,
@@ -71,6 +74,8 @@ public final class VBORegionSPES2 extends GLRegion {
colorTexBBox = null;
gcu_ColorTexBBox = null;
}
+ clipBBox = new float[6];
+ gcu_ClipBBox = new GLUniformData(UniformNames.gcu_ClipBBox, 3, FloatBuffer.wrap(clipBBox));
}
@Override
@@ -82,15 +87,15 @@ public final class VBORegionSPES2 extends GLRegion {
protected final void clearImpl(final GL2ES2 gl) { }
@Override
- protected void updateImpl(final GL2ES2 gl, final int curRenderModes) {
- final boolean hasColorChannel = Region.hasColorChannel( curRenderModes );
+ protected void updateImpl(final GL2ES2 gl, final RegionRenderer renderer, final int curRenderModes) {
+ // final boolean hasColorChannel = Region.hasColorChannel( curRenderModes );
final boolean hasColorTexture = Region.hasColorTexture( curRenderModes );
// seal buffers
vpc_ileave.seal(gl, true);
vpc_ileave.enableBuffer(gl, false);
if( hasColorTexture && null != gcu_ColorTexUnit && colorTexSeq.isTextureAvailable() ) {
- TextureSequence.setTexCoordBBox(colorTexSeq.getLastTexture().getTexture(), box, isColorTextureLetterbox(), colorTexBBox, false);
+ TextureSequence.setTexCoordBBox(colorTexSeq.getLastTexture().getTexture(), box, isColorTextureLetterbox(), colorTexBBox, true);
}
indicesBuffer.seal(gl, true);
indicesBuffer.enableBuffer(gl, false);
@@ -117,6 +122,8 @@ public final class VBORegionSPES2 extends GLRegion {
final boolean hasColorTexture = Region.hasColorTexture( curRenderModes ) && null != colorTexSeq;
final RenderState rs = renderer.getRenderState();
+ final boolean hasAABBoxClipping = null != rs.getClipBBox();
+
final boolean updateLocGlobal = renderer.useShaderProgram(gl, curRenderModes, true, quality, 0, colorTexSeq);
final ShaderProgram sp = renderer.getRenderState().getShaderProgram();
final boolean updateLocLocal = !sp.equals(spPass1);
@@ -132,6 +139,9 @@ public final class VBORegionSPES2 extends GLRegion {
if( hasColorChannel && null != gca_ColorsAttr ) {
rs.updateAttributeLoc(gl, true, gca_ColorsAttr, throwOnError);
}
+ if( hasAABBoxClipping ) {
+ rs.updateUniformLoc(gl, true, gcu_ClipBBox, throwOnError);
+ }
}
rsLocal.update(gl, rs, updateLocLocal, curRenderModes, true, throwOnError);
if( hasColorTexture && null != gcu_ColorTexUnit ) {
@@ -143,10 +153,18 @@ public final class VBORegionSPES2 extends GLRegion {
@Override
protected void drawImpl(final GL2ES2 gl, final RegionRenderer renderer, final int curRenderModes, final int[/*1*/] sampleCount) {
- final boolean hasColorChannel = Region.hasColorChannel( curRenderModes );
+ // final boolean hasColorChannel = Region.hasColorChannel( curRenderModes );
final boolean hasColorTexture = Region.hasColorTexture( curRenderModes );
useShaderProgram(gl, renderer, curRenderModes, getQuality());
+ {
+ final AABBox cb = renderer.getClipBBox();
+ if( null != cb ) {
+ clipBBox[0] = cb.getMinX(); clipBBox[1] = cb.getMinY(); clipBBox[2] = cb.getMinZ();
+ clipBBox[3] = cb.getMaxX(); clipBBox[4] = cb.getMaxY(); clipBBox[5] = cb.getMaxZ();
+ gl.glUniform(gcu_ClipBBox); // Always update, since program maybe used by multiple regions
+ }
+ }
if( 0 >= indicesBuffer.getElemCount() ) {
if(DEBUG_INSTANCE) {