diff options
author | Sven Göthel <[email protected]> | 2024-02-01 15:37:03 +0100 |
---|---|---|
committer | Sven Göthel <[email protected]> | 2024-02-01 15:37:03 +0100 |
commit | 9ff736464e0d2762c424bab66bc6d03ccc6e6d11 (patch) | |
tree | 14e1a383a86bca406608841c7e3acf5d44cbee11 /src/jogl/classes/com/jogamp | |
parent | ca846bc67e6a074a182e97f29b3c34b90a12cac3 (diff) |
Bug 805: Graph/GraphUI TextureSequence Scale: Move Region.COLORTEXTURE_LETTERBOX_RENDERING_BIT to TextureSequence and add enabling/disabling of aratio adjustment + letter-box back-color
TextureSequence color-texture params fetched from Graph VBORegion* and fed into shader.
This allows more flexibility in aspect-ratio adjustment as well as setting a clipping background color for
the added letter-box space.
Diffstat (limited to 'src/jogl/classes/com/jogamp')
4 files changed, 195 insertions, 31 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/curve/Region.java b/src/jogl/classes/com/jogamp/graph/curve/Region.java index fac65c6ee..0238ba154 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/Region.java +++ b/src/jogl/classes/com/jogamp/graph/curve/Region.java @@ -150,29 +150,16 @@ public abstract class Region { /** * Rendering-Mode bit for {@link #getRenderModes() Region} * <p> - * If set, a color texture is used to determine the color. + * If set, a color texture is used to determine the color via {#link TextureSequence} passed to implementation, e.g. GLRegion. * </p> * <p> * This mode-bit is a shader-key. * </p> - * @see #COLORTEXTURE_LETTERBOX_RENDERING_BIT + * @see TextureSequence#useARatioAdjustment() + * @see TextureSequence#useARatioLetterbox() */ public static final int COLORTEXTURE_RENDERING_BIT = 1 << 10; - /** - * Rendering-Mode bit for {@link #getRenderModes() Region} - * <p> - * If set, a used {@link #COLORTEXTURE_RENDERING_BIT} color texture is added letter-box space to match aspect-ratio, otherwise it will be zoomed in. - * </p> - * <p> - * This mode-bit is not a shader-key. - * </p> - * <p> - * Note that {@link #COLORTEXTURE_RENDERING_BIT} must also be set to even enable color texture. - * </p> - */ - public static final int COLORTEXTURE_LETTERBOX_RENDERING_BIT = 1 << 11; - /** Minimum pass2 AA-quality rendering {@value} for Graph Region AA {@link Region#getRenderModes() render-modes}: {@link #VBAA_RENDERING_BIT}. */ public static final int MIN_AA_QUALITY = 0; /** Maximum pass2 AA-quality rendering {@value} for Graph Region AA {@link Region#getRenderModes() render-modes}: {@link #VBAA_RENDERING_BIT}. */ @@ -254,11 +241,6 @@ public abstract class Region { return 0 != (renderModes & Region.COLORTEXTURE_RENDERING_BIT); } - /** Returns true if given {@code renderModes} has {@link Region#COLORTEXTURE_LETTERBOX_RENDERING_BIT} set. */ - public static boolean isColorTextureLetterbox(final int renderModes) { - return 0 != ( renderModes & Region.COLORTEXTURE_LETTERBOX_RENDERING_BIT ); - } - /** * Returns a unique technical description string for renderModes as follows: * <pre> @@ -271,11 +253,7 @@ public abstract class Region { final String cChanS = hasColorChannel(renderModes) ? "-cols" : ""; final String cTexS; if( hasColorTexture(renderModes) ) { - if( Region.isColorTextureLetterbox(renderModes) ) { - cTexS = "-ctex_lbox"; - } else { - cTexS = "-ctex_zoom"; - } + cTexS = "-ctex"; } else { cTexS = ""; } @@ -420,11 +398,6 @@ public abstract class Region { return Region.hasColorTexture(renderModes); } - /** Returns true if given {@code renderModes} has {@link Region#COLORTEXTURE_LETTERBOX_RENDERING_BIT} set. */ - public final boolean isColorTextureLetterbox() { - return Region.isColorTextureLetterbox(renderModes); - } - /** See {@link #setFrustum(Frustum)} */ public final Frustum getFrustum() { return frustum; } diff --git a/src/jogl/classes/com/jogamp/opengl/util/av/GLMediaPlayer.java b/src/jogl/classes/com/jogamp/opengl/util/av/GLMediaPlayer.java index 987031b6b..2767ea7ef 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/av/GLMediaPlayer.java +++ b/src/jogl/classes/com/jogamp/opengl/util/av/GLMediaPlayer.java @@ -456,6 +456,48 @@ public interface GLMediaPlayer extends TextureSequence { public void setTextureWrapST(int[] wrapST); /** + * {@inheritDoc} + * <p> + * Defaults to {@code true} and toggling not supported. + * </p> + */ + @Override + public boolean useARatioAdjustment(); + + /** + * {@inheritDoc} + * <p> + * Defaults to {@code true} and toggling is not supported. + * </p> + */ + @Override + public void setARatioAdjustment(final boolean v); + + /** + * {@inheritDoc} + * <p> + * Defaults to {@code false} and toggling is supported via {@link #setARatioLetterbox(boolean, Vec4f)} + * </p> + */ + @Override + public boolean useARatioLetterbox(); + + /** + * {@inheritDoc} + */ + @Override + public Vec4f getARatioLetterboxBackColor(); + + /** + * {@inheritDoc} + * <p> + * Defaults to {@code false}. + * </p> + */ + @Override + public void setARatioLetterbox(final boolean v, Vec4f backColor); + + /** * Limit maximum supported audio channels by user. * <p> * Must be set before {@link #playStream(Uri, int, int, int, int)} diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/ImageSequence.java b/src/jogl/classes/com/jogamp/opengl/util/texture/ImageSequence.java index 69a990fde..4cd78b177 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/ImageSequence.java +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/ImageSequence.java @@ -37,6 +37,7 @@ import com.jogamp.opengl.GLException; import com.jogamp.opengl.GLProfile; import com.jogamp.common.util.IOUtil; +import com.jogamp.math.Vec4f; /** * Simple {@link TextureSequence} implementation @@ -53,6 +54,9 @@ public class ImageSequence implements TextureSequence { private volatile int frameIdx = 0; private volatile boolean manualStepping = false; private int textureFragmentShaderHashCode = 0; + private boolean aRatioAdjustment = true; + private boolean aRatioLbox = false; + private final Vec4f aRatioLboxBackColor = new Vec4f(); public ImageSequence(final int textureUnit, final boolean useBuildInTexLookup) { this.textureUnit = textureUnit; @@ -136,6 +140,50 @@ public class ImageSequence implements TextureSequence { return texWrapST; } + /** + * {@inheritDoc} + * <p> + * Defaults to {@code true} and toggling is supported via {@link #setARatioAdjustment(boolean)} + * </p> + */ + @Override + public boolean useARatioAdjustment() { return aRatioAdjustment; } + + /** + * {@inheritDoc} + * <p> + * Defaults to {@code true}. + * </p> + */ + @Override + public void setARatioAdjustment(final boolean v) { aRatioAdjustment = v; } + + /** + * {@inheritDoc} + * <p> + * Defaults to {@code false} and toggling is supported via {@link #setARatioLetterbox(boolean, Vec4f)} + * </p> + */ + @Override + public boolean useARatioLetterbox() { return aRatioLbox; } + + @Override + public Vec4f getARatioLetterboxBackColor() { return aRatioLboxBackColor; } + + /** + * {@inheritDoc} + * <p> + * Defaults to {@code false}. + * </p> + */ + @Override + public void setARatioLetterbox(final boolean v, final Vec4f backColor) { + aRatioLbox = v; + if( null != backColor ) { + aRatioLboxBackColor.set(backColor); + } + }; + @Override public boolean isTextureAvailable() { return frames.size() > 0; } 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 d2f30723e..a41c8f22e 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureSequence.java +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureSequence.java @@ -33,6 +33,8 @@ import com.jogamp.opengl.GLRunnable; import com.jogamp.opengl.GLEventListener; import com.jogamp.common.av.TimeFrameI; +import com.jogamp.graph.curve.Region; +import com.jogamp.math.Vec4f; import com.jogamp.math.geom.AABBox; /** @@ -175,6 +177,66 @@ public interface TextureSequence { public int[] getTextureWrapST(); /** + * Returning {@code true} indicates texture correction for aspect-ratio in the shader. + * Graph's {@link Region} shader will utilize {@link #setTexCoordBBox(Texture, AABBox, boolean, float[], boolean)} + * for texture-coordinate bounding-box calculation. + * <p> + * Returning {@code false} indicates no correction for aspect-ratio in the shader. + * Graph's {@link Region} shader will utilize {@link #setTexCoordBBoxSimple(Texture, AABBox, float[], boolean)} + * for texture-coordinate bounding-box calculation. + * </p> + * <p> + * Default value is implementation specific + * and toggling is optional. + * </p> + * @see #setTexCoordBBox(Texture, AABBox, boolean, float[], boolean) + * @see #setTexCoordBBoxSimple(Texture, AABBox, float[], boolean) + * @see #useARatioLetterbox() + */ + public boolean useARatioAdjustment(); + + /** + * Toggles {@link #useARatioLetterbox()}. + * <p> + * Default value is implementation specific + * and toggling is optional. + * </p> + * @see #useARatioLetterbox() + * @see #useARatioAdjustment() + */ + public void setARatioAdjustment(final boolean v); + + /** + * Returns whether {@link #useARatioAdjustment()} shall add letter-box space to match aspect-ratio, otherwise it will be zoomed in. + * <p> + * Default value is implementation specific + * and toggling is optional. + * </p> + * @see #useARatioAdjustment() + * @see #setARatioLetterbox(boolean, Vec4f) + */ + public boolean useARatioLetterbox(); + + /** Returns {@link #useARatioLetterbox()} background color for added letter-box space, defaults to transparent zero. */ + public Vec4f getARatioLetterboxBackColor(); + + /** + * Toggles {@link #useARatioLetterbox()}. + * <p> + * Default value is implementation specific + * and toggling is optional. + * </p> + * <p> + * Impacts only if {@link #useARatioAdjustment()} returns {@code true}. + * </p> + * @param v new value for {@link #useARatioLetterbox()} + * @param backColor optional background color for added letter-box space, defaults to transparent zero + * @see #useARatioLetterbox() + * @see #useARatioAdjustment() + */ + public void setARatioLetterbox(final boolean v, Vec4f backColor); + + /** * Returns true if texture source is ready <i>and</i> a texture is available * via {@link #getNextTexture(GL)} and {@link #getLastTexture()}. */ @@ -319,12 +381,50 @@ public interface TextureSequence { public int getTextureFragmentShaderHashCode(); /** + * Calculates the texture coordinates bounding box w/o correcting aspect-ratio. + * @param tex the {@link Texture} + * @param box the {@Link AABBox} of the destination + * @param colorTexBBox destination float[6] array for the following three texture-coordinate tuples: minX/minY, maxX/maxY, texW/texH + * @param verbose TODO + * @see #useARatioAdjustment() + */ + public static void setTexCoordBBoxSimple(final Texture tex, final AABBox box, final float[] colorTexBBox, final boolean verbose) { + final TextureCoords tc = tex.getImageTexCoords(); + final float tcW = tc.right() - tc.left(); + final float tcH; + colorTexBBox[0] = box.getMinX() / tcW; + colorTexBBox[2] = box.getMaxX() / tcW; + if( tex.getMustFlipVertically() ) { + tcH = tc.bottom() - tc.top(); + colorTexBBox[1] = box.getMaxY() / tcH; + colorTexBBox[3] = box.getMinY() / tcH; + } else { + tcH = tc.top() - tc.bottom(); + colorTexBBox[1] = box.getMinY() / tcH; + colorTexBBox[3] = box.getMaxY() / tcH; + } + colorTexBBox[4] = tcW; + colorTexBBox[5] = tcH; + if( verbose ) { + final float colorTexBBoxW = colorTexBBox[2] - colorTexBBox[0]; + final float colorTexBBoxH = colorTexBBox[3] - colorTexBBox[1]; + System.err.println("XXX setTexCoordBBoxSimple:"); + System.err.println("XXX ColorTex "+tex); + 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); + } + + } + + /** * Calculates the texture coordinates bounding box while correcting for aspect-ratio. * @param tex the {@link Texture} * @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 + * @see #useARatioAdjustment() */ public static void setTexCoordBBox(final Texture tex, final AABBox box, final boolean letterBox, final float[] colorTexBBox, final boolean verbose) { final TextureCoords tc = tex.getImageTexCoords(); @@ -334,6 +434,7 @@ public interface TextureSequence { final float tcW = tc.right() - tc.left(); final float tcH; float boxWidthCut=0, boxHeightCut=0, boxWidthExt=0, boxHeightExt=0; + if( box2ImgRatio >= 1.0f ) { if( letterBox ) { boxWidthCut = box.getWidth() * ( 1f - 1f / box2ImgRatio ); |