From c1531c3d99b19032040018b9414263b0d3000147 Mon Sep 17 00:00:00 2001 From: Sven Göthel Date: Sat, 20 Jan 2024 05:01:38 +0100 Subject: Graph Clipping: Use Frustum Clipping using AABBox -> Mv transformed Cube -> Frustum mapping + GraphUI Support AABBox clipping naturally couldn't be transformed into 3D Model-View (Mv) Space, as it is axis aligned and only provided 2 points (min/max). Therefor we map the Group's AABBox to a 8-point Cube, perform the Mv-transformation and then produce the 6-plane Frustum. As before, we cull fully outside shapes within the Group's draw method and perform fragment clipping with same Frustum planes in the shader. With clipping enabled, the 3D z-axis getBounds() depth will be slightly increased for functional Frustum operation. This is also done for setFixedSize(Vec2f). The Frustum planes are copied to the Graph shader via float[4*6] -> uniform vec4 gcu_ClipFrustum[6]; // L, R, B, T, N, F each {n.x, n.y, n.z, d} +++ Concludes related work of below commits - 1040bed4ecc6f4598ea459f1073a9240583fc3c3 - 5cca51e32999a882e2a5f00cb45ecafc824ffd86 --- .../com/jogamp/graph/curve/opengl/RenderState.java | 26 +++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java') 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 ed5bcb110..d6be9e07b 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java @@ -39,7 +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.geom.Frustum; import com.jogamp.math.util.PMVMatrix4f; import com.jogamp.opengl.util.GLArrayDataWrapper; import com.jogamp.opengl.util.glsl.ShaderProgram; @@ -102,8 +102,9 @@ public class RenderState { private int aaQuality; /** Default pass2 AA sample count {@value} for Graph Region AA {@link Region#getRenderModes() render-modes}: {@link Region#VBAA_RENDERING_BIT} or {@link Region#MSAA_RENDERING_BIT}. */ private int sampleCount; - /** Optional clipping {@link AABBox}, which shall be pre-multiplied with the Mv-matrix. Null if unused. */ - private AABBox clipBBox; + /** Optional clipping {@link Frustum}, which shall be pre-multiplied with the Mv-matrix. Null if unused. */ + private final Frustum clipFrustum; + private boolean useClipFrustum; private int hintBitfield; private ShaderProgram sp; @@ -205,7 +206,9 @@ public class RenderState { this.colorStaticBuffer = FloatBuffer.wrap(colorStatic); this.aaQuality = Region.DEFAULT_AA_QUALITY; this.sampleCount = Region.DEFAULT_AA_SAMPLE_COUNT; - this.clipBBox = null; + this.clipFrustum = new Frustum(); + this.useClipFrustum = false; + this.hintBitfield = 0; this.sp = null; } @@ -281,10 +284,17 @@ public class RenderState { /** Returns pass2 AA sample count for Graph Region AA {@link Region#getRenderModes() render-modes}: {@link #VBAA_RENDERING_BIT} or {@link Region#MSAA_RENDERING_BIT}. */ public final int getSampleCount() { return this.sampleCount; } - /** Set the optional clipping {@link AABBox}, which shall be pre-multiplied with the Mv-matrix or null to disable. */ - public final void setClipBBox(final AABBox clipBBox) { this.clipBBox = clipBBox; } - /** Returns the optional Mv-premultiplied clipping {@link AABBox} or null if unused. */ - public final AABBox getClipBBox() { return this.clipBBox; } + /** Set the optional clipping {@link Frustum}, which shall be pre-multiplied with the Mv-matrix or null to disable. */ + public final void setClipFrustum(final Frustum clipFrustum) { + if( null != clipFrustum ) { + this.clipFrustum.set(clipFrustum); + this.useClipFrustum=true; + } else { + this.useClipFrustum=false; + } + } + /** Returns the optional Mv-premultiplied clipping {@link Frustum} or null if unused. */ + public final Frustum getClipFrustum() { return useClipFrustum ? this.clipFrustum : null; } /** * -- cgit v1.2.3