diff options
author | Sven Gothel <[email protected]> | 2023-09-03 08:37:28 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-09-03 08:37:28 +0200 |
commit | bc4a97a3751b32a7825a41481959f04ff3efb3d2 (patch) | |
tree | a9d8734dee55149a6218b18cb82e2601843a1ae4 | |
parent | 604b7cd0a4062a5aa44d669a51882f7f80efd08f (diff) |
GraphUI Scene: Expose Z-Epsilon API for default and current PMVMatrixSetup values; Button add Z-Epsilon API for ctor and setLabelZOffset(..)
-rw-r--r-- | src/graphui/classes/com/jogamp/graph/ui/Scene.java | 25 | ||||
-rw-r--r-- | src/graphui/classes/com/jogamp/graph/ui/shapes/Button.java | 34 |
2 files changed, 53 insertions, 6 deletions
diff --git a/src/graphui/classes/com/jogamp/graph/ui/Scene.java b/src/graphui/classes/com/jogamp/graph/ui/Scene.java index 1de608d12..1a55b39c7 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/Scene.java +++ b/src/graphui/classes/com/jogamp/graph/ui/Scene.java @@ -102,10 +102,22 @@ public final class Scene implements Container, GLEventListener { public static final float DEFAULT_SCENE_DIST = -1/5f; /** Default projection angle in radians is PI/4, i.e. 45.0 degrees. */ public static final float DEFAULT_ANGLE = FloatUtil.QUARTER_PI; - /** Default projection z-near value is 0.1. */ + /** Default projection z-near value is {@value}. */ public static final float DEFAULT_ZNEAR = 0.1f; - /** Default projection z-far value is 7000. */ + /** Default projection z-far value is {@value}. */ public static final float DEFAULT_ZFAR = 7000.0f; + /** Default Z precision on 16-bit depth buffer using {@link #DEFAULT_SCENE_DIST} z-position and {@link #DEFAULT_ZNEAR}. Value is {@code 0.0000061033...}*/ + public static final float DEFAULT_Z16_EPSILON = FloatUtil.getZBufferEpsilon(16 /* zBits */, DEFAULT_SCENE_DIST, DEFAULT_ZNEAR); + + /** + * Return Z precision on using {@link PMVMatrixSetup#getSceneDist()} z-position and {@link PMVMatrixSetup#getZNear()}. + * @param zBits depth buffer bit-depth, minimum 16-bit + * @param setup {@link PMVMatrixSetup} for scene-distance as z-position and zNear + * @return the Z precision + */ + public static float getZEpsilon(final int zBits, final PMVMatrixSetup setup) { + return FloatUtil.getZBufferEpsilon(zBits, setup.getSceneDist(), setup.getZNear()); + } /** Minimum sample count {@value} for Graph Region AA {@link Region#getRenderModes() render-modes}: {@link Region#VBAA_RENDERING_BIT} or {@link Region#MSAA_RENDERING_BIT}. */ public static final int MIN_SAMPLE_COUNT = 1; @@ -813,6 +825,15 @@ public final class Scene implements Container, GLEventListener { public AABBox getBounds() { return planeBox; } /** + * Return Z precision on using current {@link #getPMVMatrixSetup()}'s {@link PMVMatrixSetup#getSceneDist()} z-position and {@link PMVMatrixSetup#getZNear()}. + * @param zBits depth buffer bit-depth, minimum 16-bit + * @return the Z precision + */ + public float getZEpsilon(final int zBits) { + return FloatUtil.getZBufferEpsilon(zBits, pmvMatrixSetup.getSceneDist(), pmvMatrixSetup.getZNear()); + } + + /** * * @param pmv * @param viewport diff --git a/src/graphui/classes/com/jogamp/graph/ui/shapes/Button.java b/src/graphui/classes/com/jogamp/graph/ui/shapes/Button.java index 9ce04cb47..ec07d7c4a 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/shapes/Button.java +++ b/src/graphui/classes/com/jogamp/graph/ui/shapes/Button.java @@ -36,6 +36,7 @@ import com.jogamp.graph.curve.opengl.TextRegionUtil; import com.jogamp.graph.font.Font; import com.jogamp.graph.geom.plane.AffineTransform; import com.jogamp.graph.ui.GraphShape; +import com.jogamp.graph.ui.Scene; import com.jogamp.opengl.math.FloatUtil; import com.jogamp.opengl.math.Vec2f; import com.jogamp.opengl.math.Vec3f; @@ -60,7 +61,7 @@ public class Button extends BaseButton { /** {@value} */ public static final float DEFAULT_SPACING_Y = 0.42f; - private static final float DEFAULT_LABEL_ZOFFSET = 0.0001f; // 0.05f; + private static final float DEFAULT_LABEL_ZOFFSET = 0.00016f; // 16 zBits, -1 zDist, 0.1 zNear, i.e. FloatUtil.getZBufferEpsilon(16, -1f, 0.1f) private float labelZOffset; private final Label0 label; @@ -72,10 +73,26 @@ public class Button extends BaseButton { private final AffineTransform tempT3 = new AffineTransform(); public Button(final int renderModes, final Font labelFont, - final String labelText, final float width, - final float height) { + final String labelText, final float width, final float height) { + this(renderModes, labelFont, labelText, width, height, DEFAULT_LABEL_ZOFFSET); + } + + public Button(final int renderModes, final Font labelFont, + final String labelText, final float width, final float height, + final int zBits, final Scene.PMVMatrixSetup setup) { + this(renderModes, labelFont, labelText, width, height, Scene.getZEpsilon(zBits, setup)); + } + + public Button(final int renderModes, final Font labelFont, + final String labelText, final float width, final float height, + final int zBits, final Scene scene) { + this(renderModes, labelFont, labelText, width, height, scene.getZEpsilon(zBits)); + } + + public Button(final int renderModes, final Font labelFont, final String labelText, + final float width, final float height, final float zOffset) { super(renderModes | Region.COLORCHANNEL_RENDERING_BIT, width, height); - this.labelZOffset = DEFAULT_LABEL_ZOFFSET; + this.labelZOffset = zOffset; this.label = new Label0(labelFont, labelText, new Vec4f( 1.66f, 1.66f, 1.66f, 1.0f )); // 0.60 * 1.66 ~= 1.0 } @@ -144,6 +161,15 @@ public class Button extends BaseButton { markShapeDirty(); return this; } + public Button setLabelZOffset(final int zBits, final float zDist, final float zNear) { + return setLabelZOffset( FloatUtil.getZBufferEpsilon(zBits, zDist, zNear) ); + } + public Button setLabelZOffset(final int zBits, final Scene.PMVMatrixSetup setup) { + return setLabelZOffset( Scene.getZEpsilon(zBits, setup) ); + } + public Button setLabelZOffset(final int zBits, final Scene scene) { + return setLabelZOffset( scene.getZEpsilon(zBits) ); + } public final float getSpacingX() { return spacingX; } public final float getSpacingY() { return spacingY; } |