diff options
author | Sven Gothel <[email protected]> | 2023-09-30 01:28:59 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-09-30 01:28:59 +0200 |
commit | 297c48f4fefd1ab59800524ea5f0dd56684d6786 (patch) | |
tree | 02c1b8f65de349c9af3bc2a5b94e04e90d75c684 /src/jogl | |
parent | 2e46eb1bf06ef07801062122716aa99a6c871646 (diff) |
Bug 1465 - Graph / GraphUI: Render a Region's ColorTexture in proper aspect-ratio, letter-boxed or zoomed (config) + Bug 1466 Fix color mixing
Bug 1465: Region currently simply bloats a given texture to its region AABBox,
which renders textures with the wrong aspect ratio.
Add facility to program the texture-coordinates to either letter-box
or scaled-up (and cut) true aspect-ratio.
Default shall be zoom (scale-up and cut),
but user shall be able to set a flag in the Region for letter-box.
Have the shader clip texture coordinates properly,
best w/o branching to soothe performance.
See functions.glsl
+++
Bug 1466: Current color mix: texture * color_channel * color_static
is useless in GraphUI.
color_static shall modulate the texture, which works.
But in case of color_channel (attribute/varying)
we want it to be mixed so it can become the more dominant color
for e.g. a border.
Desired is:
color = vec4( mix( tex.rgb * gcu_ColorStatic.rgb, gcv_Color.rgb, gcv_Color.a ),
mix( tex.a * gcu_ColorStatic.a, 1, gcv_Color.a) );
Diffstat (limited to 'src/jogl')
13 files changed, 233 insertions, 81 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/curve/Region.java b/src/jogl/classes/com/jogamp/graph/curve/Region.java index 93b05aefa..5f78283ed 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/Region.java +++ b/src/jogl/classes/com/jogamp/graph/curve/Region.java @@ -127,9 +127,21 @@ public abstract class Region { * <p> * If set, a color texture is used to determine the color. * </p> + * @see #COLORTEXTURE_LETTERBOX_RENDERING_BIT */ 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> + * 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; + /** Default maximum {@link #getQuality() quality}, {@value}. */ public static final int MAX_QUALITY = 1; @@ -147,6 +159,9 @@ public abstract class Region { protected final AABBox box = new AABBox(); protected Frustum frustum = null; + public static final boolean isRenderModeSet(final int renderModes, final int mask) { return mask == ( renderModes & mask ); } + public static final int setRenderMode(int renderModes, final int mask, final boolean v) { if( v ) { renderModes |= mask; } else { renderModes &= ~mask; }; return renderModes; } + /** Returns true if given {@code renderModes} has {@link Region#VBAA_RENDERING_BIT} set. */ public static boolean isVBAA(final int renderModes) { return 0 != (renderModes & Region.VBAA_RENDERING_BIT); @@ -194,6 +209,11 @@ 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> @@ -204,7 +224,16 @@ public abstract class Region { public static String getRenderModeString(final int renderModes) { final String curveS = hasVariableWeight(renderModes) ? "-curve" : ""; final String cChanS = hasColorChannel(renderModes) ? "-cols" : ""; - final String cTexS = hasColorTexture(renderModes) ? "-ctex" : ""; + final String cTexS; + if( hasColorTexture(renderModes) ) { + if( Region.isColorTextureLetterbox(renderModes) ) { + cTexS = "-ctex_lbox"; + } else { + cTexS = "-ctex_zoom"; + } + } else { + cTexS = ""; + } if( Region.isVBAA(renderModes) ) { return "vbaa"+curveS+cChanS+cTexS; } else if( Region.isMSAA(renderModes) ) { @@ -299,6 +328,8 @@ public abstract class Region { box.reset(); } + public final boolean isRenderModeSet(final int mask) { return mask == ( renderModes & mask ); } + /** * Returns true if capable of two pass rendering - VBAA, otherwise false. * @see #getRenderModes() @@ -340,11 +371,16 @@ public abstract class Region { * i.e. the bit {@link #COLORTEXTURE_RENDERING_BIT} is set, * otherwise false. * @see #getRenderModes() + * @see #isColorTextureLetterbox() */ public final boolean hasColorTexture() { 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/graph/curve/opengl/RegionRenderer.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java index 7e3a7ff30..0927c41cb 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java @@ -631,6 +631,7 @@ public final class RegionRenderer { } try { + 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/opengl/util/texture/TextureCoords.java b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureCoords.java index 17fcc7016..b4fd0cc1e 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureCoords.java +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureCoords.java @@ -78,20 +78,16 @@ public class TextureCoords { return d; } - /** Returns the leftmost (x) texture coordinate of this - rectangle. */ + /** Returns the leftmost (x) texture coordinate of this rectangle. */ public float left() { return left; } - /** Returns the rightmost (x) texture coordinate of this - rectangle. */ + /** Returns the rightmost (x) texture coordinate of this rectangle. */ public float right() { return right; } - /** Returns the bottommost (y) texture coordinate of this - rectangle. */ + /** Returns the bottommost (y) texture coordinate of this rectangle. */ public float bottom() { return bottom; } - /** Returns the topmost (y) texture coordinate of this - rectangle. */ + /** Returns the topmost (y) texture coordinate of this rectangle. */ public float top() { return top; } @Override 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 1e308b215..7c924864a 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,7 @@ import com.jogamp.opengl.GLRunnable; import com.jogamp.opengl.GLEventListener; import com.jogamp.common.av.TimeFrameI; +import com.jogamp.math.geom.AABBox; /** * Protocol for texture sequences, like animations, movies, etc. @@ -303,4 +304,114 @@ public interface TextureSequence { * @see #getTextureLookupFragmentShaderImpl() */ public int getTextureFragmentShaderHashCode(); + + /** + * 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 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 + */ + @SuppressWarnings("unused") + public static void setTexCoordBBox(final Texture tex, final AABBox box, final boolean letterBox, final float[] colorTexBBox) { + final TextureCoords tc = tex.getImageTexCoords(); + final float boxRatio = box.getWidth() / box.getHeight(); + final float imgRatio = tex.getAspectRatio(); + final float box2ImgRatio = boxRatio / imgRatio; + 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 ); + final float tcWH = tcW * 0.5f; + final float boxWidthCutL = boxWidthCut * tcWH; + final float boxWidthCutR = boxWidthCut * ( 1f - tcWH ); + colorTexBBox[0] = ( box.getMinX() + boxWidthCutL ) / tcW; + colorTexBBox[2] = ( box.getMaxX() - boxWidthCutR ) / 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; + } + } else { + colorTexBBox[0] = box.getMinX() / tcW; + colorTexBBox[2] = box.getMaxX() / tcW; + boxHeightExt = box.getHeight() * ( box2ImgRatio - 1f ); + if( tex.getMustFlipVertically() ) { + tcH = tc.bottom() - tc.top(); + final float tcHH = tcH * 0.5f; + final float boxHeightExtB = boxHeightExt * tcHH; + final float boxHeightExtT = boxHeightExt * ( 1f - tcHH ); + colorTexBBox[1] = ( box.getMaxY() + boxHeightExtT ) / tcH; + colorTexBBox[3] = ( box.getMinY() - boxHeightExtB ) / tcH; + } else { + tcH = tc.top() - tc.bottom(); + final float tcHH = tcH * 0.5f; + final float boxHeightExtB = boxHeightExt * tcHH; + final float boxHeightExtT = boxHeightExt * ( 1f - tcHH ); + colorTexBBox[1] = ( box.getMinY() - boxHeightExtB ) / tcH; + colorTexBBox[3] = ( box.getMaxY() + boxHeightExtT ) / tcH; + } + } + } else { + if( letterBox ) { + colorTexBBox[0] = box.getMinX() / tcW; + colorTexBBox[2] = box.getMaxX() / tcW; + boxHeightCut = box.getHeight() * ( 1f - box2ImgRatio ); + if( tex.getMustFlipVertically() ) { + tcH = tc.bottom() - tc.top(); + final float tcHH = tcH * 0.5f; + final float boxHeightCutB = boxHeightCut * tcHH; + final float boxHeightCutT = boxHeightCut * ( 1f - tcHH ); + colorTexBBox[1] = ( box.getMaxY() - boxHeightCutT ) / tcH; + colorTexBBox[3] = ( box.getMinY() + boxHeightCutB ) / tcH; + } else { + tcH = tc.top() - tc.bottom(); + final float tcHH = tcH * 0.5f; + final float boxHeightCutB = boxHeightCut * tcHH; + final float boxHeightCutT = boxHeightCut * ( 1f - tcHH ); + colorTexBBox[1] = ( box.getMinY() + boxHeightCutB ) / tcH; + colorTexBBox[3] = ( box.getMaxY() - boxHeightCutT ) / tcH; + } + } else { + boxWidthExt = box.getWidth() * ( 1f / box2ImgRatio - 1f ); + final float tcWH = tcW * 0.5f; + final float boxWidthExtL = boxWidthExt * tcWH; + final float boxWidthExtR = boxWidthExt * ( 1f - tcWH ); + colorTexBBox[0] = ( box.getMinX() - boxWidthExtL ) / tcW; + colorTexBBox[2] = ( box.getMaxX() + boxWidthExtR ) / 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( false ) { + final float texWidthRatio = (float)tex.getImageWidth() / (float)tex.getWidth(); + final float texHeightRatio = (float)tex.getImageHeight() / (float)tex.getHeight(); + final float texRatio = ( tc.right() - tc.left() ) / ( tc.bottom() - tc.top() ); + final float box2TexRatio = boxRatio / texRatio; + final float colorTexBBoxW = colorTexBBox[2] - colorTexBBox[0]; + final float colorTexBBoxH = colorTexBBox[3] - colorTexBBox[1]; + System.err.println("XXX"); + 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]+ + ", 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 73af4603d..c5b1e8309 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java @@ -50,7 +50,6 @@ import com.jogamp.opengl.FBObject.Attachment; import com.jogamp.opengl.util.GLArrayDataServer; import com.jogamp.opengl.util.glsl.ShaderProgram; import com.jogamp.opengl.util.texture.Texture; -import com.jogamp.opengl.util.texture.TextureCoords; import com.jogamp.opengl.util.texture.TextureSequence; public final class VBORegion2PMSAAES2 extends GLRegion { @@ -61,8 +60,8 @@ public final class VBORegion2PMSAAES2 extends GLRegion { // Pass-1: private final GLUniformData gcu_ColorTexUnit; - private final float[] colorTexBBox; // x0, y0, x1, y1 - private final GLUniformData gcu_ColorTexBBox; + 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 ShaderProgram spPass1 = null; // Pass-2: @@ -97,8 +96,8 @@ public final class VBORegion2PMSAAES2 extends GLRegion { if( hasColorTexture() ) { gcu_ColorTexUnit = new GLUniformData(UniformNames.gcu_ColorTexUnit, colorTexSeq.getTextureUnit()); - colorTexBBox = new float[4]; - gcu_ColorTexBBox = new GLUniformData(UniformNames.gcu_ColorTexBBox, 4, FloatBuffer.wrap(colorTexBBox)); + colorTexBBox = new float[6]; + gcu_ColorTexBBox = new GLUniformData(UniformNames.gcu_ColorTexBBox, 2, FloatBuffer.wrap(colorTexBBox)); } else { gcu_ColorTexUnit = null; colorTexBBox = null; @@ -148,21 +147,7 @@ public final class VBORegion2PMSAAES2 extends GLRegion { vpc_ileave.enableBuffer(gl, false); if( hasColorTexture && null != gcu_ColorTexUnit && colorTexSeq.isTextureAvailable() ) { - final TextureSequence.TextureFrame frame = colorTexSeq.getLastTexture(); - final Texture tex = frame.getTexture(); - final TextureCoords tc = tex.getImageTexCoords(); - final float tcSx = 1f / ( tc.right() - tc.left() ); - colorTexBBox[0] = box.getMinX() * tcSx; - colorTexBBox[2] = box.getMaxX() * tcSx; - if( tex.getMustFlipVertically() ) { - final float tcSy = 1f / ( tc.bottom() - tc.top() ); - colorTexBBox[1] = box.getMaxY() * tcSy; - colorTexBBox[3] = box.getMinY() * tcSy; - } else { - final float tcSy = 1f / ( tc.top() - tc.bottom() ); - colorTexBBox[1] = box.getMinY() * tcSy; - colorTexBBox[3] = box.getMaxY() * tcSy; - } + TextureSequence.setTexCoordBBox(colorTexSeq.getLastTexture().getTexture(), box, isColorTextureLetterbox(), colorTexBBox); } gca_FboVerticesAttr.seal(gl, false); { diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java index 9fad72881..b05a04802 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java @@ -53,7 +53,6 @@ import com.jogamp.opengl.FBObject.TextureAttachment; import com.jogamp.opengl.util.GLArrayDataServer; import com.jogamp.opengl.util.glsl.ShaderProgram; import com.jogamp.opengl.util.texture.Texture; -import com.jogamp.opengl.util.texture.TextureCoords; import com.jogamp.opengl.util.texture.TextureSequence; public final class VBORegion2PVBAAES2 extends GLRegion { @@ -94,8 +93,9 @@ public final class VBORegion2PVBAAES2 extends GLRegion { // Pass-1: private final GLUniformData gcu_ColorTexUnit; - private final float[] colorTexBBox; // x0, y0, x1, y1 - private final GLUniformData gcu_ColorTexBBox; + 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 ShaderProgram spPass1 = null; // Pass-2: @@ -193,8 +193,8 @@ public final class VBORegion2PVBAAES2 extends GLRegion { if( hasColorTexture() ) { gcu_ColorTexUnit = new GLUniformData(UniformNames.gcu_ColorTexUnit, colorTexSeq.getTextureUnit()); - colorTexBBox = new float[4]; - gcu_ColorTexBBox = new GLUniformData(UniformNames.gcu_ColorTexBBox, 4, FloatBuffer.wrap(colorTexBBox)); + colorTexBBox = new float[6]; + gcu_ColorTexBBox = new GLUniformData(UniformNames.gcu_ColorTexBBox, 2, FloatBuffer.wrap(colorTexBBox)); } else { gcu_ColorTexUnit = null; colorTexBBox = null; @@ -235,6 +235,7 @@ public final class VBORegion2PVBAAES2 extends GLRegion { @Override protected void updateImpl(final GL2ES2 gl, final int curRenderModes) { + @SuppressWarnings("unused") final boolean hasColorChannel = Region.hasColorChannel( curRenderModes ); final boolean hasColorTexture = Region.hasColorTexture( curRenderModes ); @@ -244,21 +245,7 @@ public final class VBORegion2PVBAAES2 extends GLRegion { vpc_ileave.seal(gl, true); vpc_ileave.enableBuffer(gl, false); if( hasColorTexture && null != gcu_ColorTexUnit && colorTexSeq.isTextureAvailable() ) { - final TextureSequence.TextureFrame frame = colorTexSeq.getLastTexture(); - final Texture tex = frame.getTexture(); - final TextureCoords tc = tex.getImageTexCoords(); - final float tcSx = 1f / ( tc.right() - tc.left() ); - colorTexBBox[0] = box.getMinX() * tcSx; - colorTexBBox[2] = box.getMaxX() * tcSx; - if( tex.getMustFlipVertically() ) { - final float tcSy = 1f / ( tc.bottom() - tc.top() ); - colorTexBBox[1] = box.getMaxY() * tcSy; - colorTexBBox[3] = box.getMinY() * tcSy; - } else { - final float tcSy = 1f / ( tc.top() - tc.bottom() ); - colorTexBBox[1] = box.getMinY() * tcSy; - colorTexBBox[3] = box.getMaxY() * tcSy; - } + TextureSequence.setTexCoordBBox(colorTexSeq.getLastTexture().getTexture(), box, isColorTextureLetterbox(), colorTexBBox); } gca_FboVerticesAttr.seal(gl, false); { diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java index a819f9267..634b53fe2 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java @@ -42,7 +42,6 @@ import com.jogamp.graph.curve.opengl.RegionRenderer; import com.jogamp.graph.curve.opengl.RenderState; import com.jogamp.opengl.util.glsl.ShaderProgram; import com.jogamp.opengl.util.texture.Texture; -import com.jogamp.opengl.util.texture.TextureCoords; import com.jogamp.opengl.util.texture.TextureSequence; public final class VBORegionSPES2 extends GLRegion { @@ -50,8 +49,8 @@ public final class VBORegionSPES2 extends GLRegion { // Pass-1: private final GLUniformData gcu_ColorTexUnit; - private final float[] colorTexBBox; // x0, y0, x1, y1 - private final GLUniformData gcu_ColorTexBBox; + 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 ShaderProgram spPass1 = null; public VBORegionSPES2(final GLProfile glp, final int renderModes, final TextureSequence colorTexSeq, @@ -65,8 +64,8 @@ public final class VBORegionSPES2 extends GLRegion { if( hasColorTexture() ) { gcu_ColorTexUnit = new GLUniformData(UniformNames.gcu_ColorTexUnit, colorTexSeq.getTextureUnit()); - colorTexBBox = new float[4]; - gcu_ColorTexBBox = new GLUniformData(UniformNames.gcu_ColorTexBBox, 4, FloatBuffer.wrap(colorTexBBox)); + colorTexBBox = new float[6]; + gcu_ColorTexBBox = new GLUniformData(UniformNames.gcu_ColorTexBBox, 2, FloatBuffer.wrap(colorTexBBox)); } else { gcu_ColorTexUnit = null; colorTexBBox = null; @@ -91,22 +90,7 @@ public final class VBORegionSPES2 extends GLRegion { vpc_ileave.seal(gl, true); vpc_ileave.enableBuffer(gl, false); if( hasColorTexture && null != gcu_ColorTexUnit && colorTexSeq.isTextureAvailable() ) { - final TextureSequence.TextureFrame frame = colorTexSeq.getLastTexture(); - final Texture tex = frame.getTexture(); - final TextureCoords tc = tex.getImageTexCoords(); - final float tcSx = 1f / ( tc.right() - tc.left() ); - colorTexBBox[0] = box.getMinX() * tcSx; - colorTexBBox[2] = box.getMaxX() * tcSx; - final float tcSy; - if( tex.getMustFlipVertically() ) { - tcSy = 1f / ( tc.bottom() - tc.top() ); - colorTexBBox[1] = box.getMaxY() * tcSy; - colorTexBBox[3] = box.getMinY() * tcSy; - } else { - tcSy = 1f / ( tc.top() - tc.bottom() ); - colorTexBBox[1] = box.getMinY() * tcSy; - colorTexBBox[3] = box.getMaxY() * tcSy; - } + TextureSequence.setTexCoordBBox(colorTexSeq.getLastTexture().getTexture(), box, isColorTextureLetterbox(), colorTexBBox); } indicesBuffer.seal(gl, true); indicesBuffer.enableBuffer(gl, false); diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_simple.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_simple.glsl index 447242438..6ff35df85 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_simple.glsl +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_simple.glsl @@ -1,10 +1,15 @@ + // Copyright 2010-2023 JogAmp Community. All rights reserved. if( gcv_CurveParam.x == 0.0 && gcv_CurveParam.y == 0.0 ) { // pass-1: Lines #if defined(USE_COLOR_TEXTURE) && defined(USE_COLOR_CHANNEL) - mgl_FragColor = gcuTexture2D(gcu_ColorTexUnit, gcv_ColorTexCoord.st) * gcv_Color * gcu_ColorStatic; + vec4 t = clip_coord(gcuTexture2D(gcu_ColorTexUnit, gcv_ColorTexCoord.st), vec4(1), gcv_ColorTexCoord, vec2(0), gcv_ColorTexExt); + + mgl_FragColor = vec4( mix( t.rgb * gcu_ColorStatic.rgb, gcv_Color.rgb, gcv_Color.a ), + mix( t.a * gcu_ColorStatic.a, 1, gcv_Color.a) ); #elif defined(USE_COLOR_TEXTURE) - mgl_FragColor = gcuTexture2D(gcu_ColorTexUnit, gcv_ColorTexCoord.st) * gcu_ColorStatic; + mgl_FragColor = clip_coord(gcuTexture2D(gcu_ColorTexUnit, gcv_ColorTexCoord.st), vec4(1), gcv_ColorTexCoord, vec2(0), gcv_ColorTexExt) + * gcu_ColorStatic; #elif defined(USE_COLOR_CHANNEL) mgl_FragColor = gcv_Color * gcu_ColorStatic; #else @@ -22,10 +27,13 @@ float a = clamp(0.5 - ( position/length(f) ) * sign(gcv_CurveParam.y), 0.0, 1.0); #if defined(USE_COLOR_TEXTURE) && defined(USE_COLOR_CHANNEL) - vec4 t = gcuTexture2D(gcu_ColorTexUnit, gcv_ColorTexCoord.st); - mgl_FragColor = vec4(t.rgb * gcv_Color.rgb * gcu_ColorStatic.rgb, t.a * gcv_Color.a * gcu_ColorStatic.a * a); + vec4 t = clip_coord(gcuTexture2D(gcu_ColorTexUnit, gcv_ColorTexCoord.st), vec4(1), gcv_ColorTexCoord, vec2(0), gcv_ColorTexExt); + + mgl_FragColor = vec4( mix( t.rgb * gcu_ColorStatic.rgb, gcv_Color.rgb, gcv_Color.a ), + a * mix( t.a * gcu_ColorStatic.a, 1, gcv_Color.a) ); #elif defined(USE_COLOR_TEXTURE) - vec4 t = gcuTexture2D(gcu_ColorTexUnit, gcv_ColorTexCoord.st); + vec4 t = clip_coord(gcuTexture2D(gcu_ColorTexUnit, gcv_ColorTexCoord.st), vec4(1), gcv_ColorTexCoord, vec2(0), gcv_ColorTexExt); + mgl_FragColor = vec4(t.rgb * gcu_ColorStatic.rgb, t.a * gcu_ColorStatic.a * a); #elif defined(USE_COLOR_CHANNEL) mgl_FragColor = vec4(gcv_Color.rgb * gcu_ColorStatic.rgb, gcv_Color.a * gcu_ColorStatic.a * a); diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1.vp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1.vp index c6ed4ca58..de41d9198 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1.vp +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1.vp @@ -1,4 +1,4 @@ -//Copyright 2010 JogAmp Community. All rights reserved. +// Copyright 2010-2023 JogAmp Community. All rights reserved. #if __VERSION__ >= 130 #define attribute in @@ -24,8 +24,9 @@ void main(void) } #endif #ifdef USE_COLOR_TEXTURE - vec2 dim = vec2(gcu_ColorTexBBox.z - gcu_ColorTexBBox.x, gcu_ColorTexBBox.w - gcu_ColorTexBBox.y); - gcv_ColorTexCoord = vec2(gca_Vertices.x - gcu_ColorTexBBox.x, gca_Vertices.y - gcu_ColorTexBBox.y) / dim; + vec2 dim = vec2(gcu_ColorTexBBox[1].x - gcu_ColorTexBBox[0].x, gcu_ColorTexBBox[1].y - gcu_ColorTexBBox[0].y); + gcv_ColorTexCoord = vec2(gca_Vertices.x - gcu_ColorTexBBox[0].x, gca_Vertices.y - gcu_ColorTexBBox[0].y) / dim; + gcv_ColorTexExt = gcu_ColorTexBBox[2]; // texture-size #endif #ifdef USE_COLOR_CHANNEL gcv_Color = gca_Colors; diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-segment-head.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-segment-head.fp index 05407a4e6..c88619154 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-segment-head.fp +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-segment-head.fp @@ -1,4 +1,4 @@ -//Copyright 2010 JogAmp Community. All rights reserved. +// Copyright 2010-2023 JogAmp Community. All rights reserved. // // 2-pass shader w/o weight @@ -13,4 +13,3 @@ #endif #define GetSample(texUnit, texCoord, psize, cx, cy, offX, offY) texture2D(texUnit, texCoord + psize * vec2(cx+offX, cy+offY)) - diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/functions.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/functions.glsl new file mode 100644 index 000000000..eeab54ebf --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/functions.glsl @@ -0,0 +1,42 @@ +// Copyright 2023 JogAmp Community. All rights reserved. + +#ifndef functions_glsl +#define functions_glsl + +/** Returns product of components. */ +float v_mul( vec2 v ) { + return v.x * v.y; +} +/** Returns component wise logical 'or' as float '0' or '1' using the components product and clamp. */ +float v_or( vec2 v ) { + return clamp(v.x * v.y, 0, 1); +} + +/** Returns sum of components. */ +float v_sum( vec2 v ) { + return v.x + v.y; +} +/** Returns component wise logical 'and' as float '0' or '1' using the components sum and clamp. */ +float v_and( vec2 v ) { + return clamp(v.x + v.y, 0, 1); +} + +/** + * Branch-less clipping function. + * <p> + * Returns either 'col_in' if the 'coord' is within ['low'..'high'] range, + * otherwise 'col_ex'. + * </p> + * <p> + * This is achieved via the build-in 'step' and 'mix' function + * as well as our own 'v_mul' and v_and' function, + * which flattens a 'vec2' to one float suitable to be used as the 'mix' criteria. + * </p> + */ +vec4 clip_coord(vec4 col_in, vec4 col_ex, vec2 coord, vec2 low, vec2 high) { + vec4 c = mix( col_ex, col_in, v_mul( step(low, coord) )); + return mix( c, col_ex, v_and( step(high, coord) )); +} + +#endif // functions_glsl + diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl index cd014b732..956c31d4b 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl @@ -7,7 +7,7 @@ uniform vec4 gcu_ColorStatic; uniform float gcu_Weight; #ifdef USE_COLOR_TEXTURE - uniform vec4 gcu_ColorTexBBox; + uniform vec2 gcu_ColorTexBBox[3]; // box-min[2], box-max[2] and tex-size[2] #endif uniform mat4 gcu_PMVMatrix02[3]; // P, Mv, and Mvi diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/varyings.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/varyings.glsl index 265ab6915..a64b8ad4d 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/varyings.glsl +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/varyings.glsl @@ -8,11 +8,13 @@ varying vec2 gcv_FboTexCoord; #ifdef USE_COLOR_TEXTURE varying vec2 gcv_ColorTexCoord; + varying vec2 gcv_ColorTexExt; #endif #ifdef USE_COLOR_CHANNEL varying vec4 gcv_Color; #endif + #endif // varyings_glsl |