From 6363ae5fb6975a6f2e7c1093ce81f25b699e3e61 Mon Sep 17 00:00:00 2001
From: Sven Göthel
* One pass `norm` rendering either using no AA or underlying full-screen AA (fsaa).
*
+ * This mode-bit is a shader-key.
+ *
* MSAA based Anti-Aliasing, a two pass region rendering, slower and more
- * resource hungry (FBO), but providing fast MSAA in case
+ * resource hungry (FBO with sample buffer), but providing fast MSAA in case
* the whole scene is not rendered with MSAA.
*
+ * In case sample count is 1, no FBO sample buffer is used but a simple bilinear texture filter.
+ *
+ * This mode-bit is a shader-key.
+ *
+ * In case sample count is 1, no FBO supersampling is performed but a simple bilinear texture filter used. + *
+ *+ * Depending on AA-quality, {@link #MAX_AA_QUALITY} denotes full 4x billinear filtering per sample + * and {@code 0} denotes 1x flipquad filtering per sample. + *
+ *+ * This mode-bit is a shader-key. + *
*/ public static final int VBAA_RENDERING_BIT = 1 << 1; @@ -105,6 +124,9 @@ public abstract class Region { * Otherwise the default weight 1.0 for uniform curve region rendering is * being applied. * + *+ * This mode-bit is a shader-key. + *
*/ public static final int VARWEIGHT_RENDERING_BIT = 1 << 8; @@ -115,6 +137,9 @@ public abstract class Region { * otherwise {@link com.jogamp.graph.curve.opengl.RegionRenderer#setColorStatic(com.jogamp.opengl.GL2ES2, float, float, float, float) static color} * can being used for a monotonic color. * + *+ * This mode-bit is a shader-key. + *
* @see #getRenderModes() * @see #hasColorChannel() * @see #addOutlineShape(OutlineShape, AffineTransform, float[]) @@ -127,6 +152,9 @@ public abstract class Region { ** If set, a color texture is used to determine the color. *
+ *+ * This mode-bit is a shader-key. + *
* @see #COLORTEXTURE_LETTERBOX_RENDERING_BIT */ public static final int COLORTEXTURE_RENDERING_BIT = 1 << 10; @@ -137,13 +165,23 @@ public abstract class Region { * 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. * *+ * This mode-bit is not a shader-key. + *
+ ** Note that {@link #COLORTEXTURE_RENDERING_BIT} must also be set to even enable color texture. *
*/ public static final int COLORTEXTURE_LETTERBOX_RENDERING_BIT = 1 << 11; - /** Default maximum {@link #getQuality() quality}, {@value}. */ - public static final int MAX_QUALITY = 1; + /** Minimum pass2 AA-quality rendering {@value} (default) 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} (default) for Graph Region AA {@link Region#getRenderModes() render-modes}: {@link #VBAA_RENDERING_BIT}. */ + public static final int MAX_AA_QUALITY = 1; + + /** Minimum 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}. */ + public static final int MIN_AA_SAMPLE_COUNT = 1; + /** Maximum 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}. */ + public static final int MAX_AA_SAMPLE_COUNT = 8; public static final int DEFAULT_TWO_PASS_TEXTURE_UNIT = 0; @@ -153,7 +191,6 @@ public abstract class Region { private final int renderModes; private final boolean use_int32_idx; private final int max_indices; - private int quality; private int dirty = DIRTY_SHAPE | DIRTY_STATE; private int numVertices = 0; protected final AABBox box = new AABBox(); @@ -265,7 +302,6 @@ public abstract class Region { } else { this.max_indices = GL_UINT16_MAX; } - this.quality = MAX_QUALITY; } /** Print implementation buffer stats like detailed and total size and capacity in bytes etc */ @@ -316,12 +352,6 @@ public abstract class Region { */ public final int getRenderModes() { return renderModes; } - /** See {@link #MAX_QUALITY} */ - public final int getQuality() { return quality; } - - /** See {@link #MAX_QUALITY} */ - public final void setQuality(final int q) { quality=q; } - protected final void clearImpl() { dirty = DIRTY_SHAPE | DIRTY_STATE; numVertices = 0; @@ -760,7 +790,7 @@ public abstract class Region { * Mark this region's shape dirty, * i.e. its vertices, triangles, lines and/or color-texture coordinates changed. *- * The data will be re-uploaded to the GPU at next {@link GLRegion#draw(com.jogamp.opengl.GL2ES2, com.jogamp.graph.curve.opengl.RegionRenderer, int[]) draw(..)}. + * The data will be re-uploaded to the GPU at next {@link GLRegion#draw(com.jogamp.opengl.GL2ES2, com.jogamp.graph.curve.opengl.RegionRenderer, int, int[]) draw(..)}. *
** In 2-pass mode, this implies updating the FBO itself as well. @@ -798,6 +828,6 @@ public abstract class Region { @Override public String toString() { - return "Region[0x"+Integer.toHexString(hashCode())+", "+getRenderModeString(this.renderModes)+", q "+quality+", dirty "+dirty+", vertices "+numVertices+", box "+box+"]"; + return "Region[0x"+Integer.toHexString(hashCode())+", "+getRenderModeString(this.renderModes)+", dirty "+dirty+", vertices "+numVertices+", box "+box+"]"; } } \ No newline at end of file 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 af8a54177..5849a8581 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java @@ -511,14 +511,15 @@ public abstract class GLRegion extends Region { *
* @param gl current {@link GL2ES2}. * @param renderer the {@link RegionRenderer} to be used - * @param sampleCount desired multisampling sample count for vbaa- or msaa-rendering. + * @param pass2Quality pass2 AA-quality selector in the range [{@link Region#MIN_AA_QUALITY}..{@link Region#MAX_AA_QUALITY}] for Graph Region AA {@link Region#getRenderModes() render-modes}: {@link Region#VBAA_RENDERING_BIT} + * @param sampleCount desired pass2 AA-multisampling sample count in the typical range [{@link Region#MIN_AA_SAMPLE_COUNT}..{@link Region#MAX_AA_SAMPLE_COUNT}] for Graph Region AA {@link Region#getRenderModes() render-modes}: {@link Region#VBAA_RENDERING_BIT}, {@link Region#MSAA_RENDERING_BIT} * Use -1 for glSelect mode, pass1 w/o any color texture nor channel, use static select color only. * The actual used scample-count is written back when msaa-rendering is enabled, otherwise the store is untouched. * @see RegionRenderer#enable(GL2ES2, boolean) */ - public final void draw(final GL2ES2 gl, final RegionRenderer renderer, final int[/*1*/] sampleCount) { + public final void draw(final GL2ES2 gl, final RegionRenderer renderer, final int pass2Quality, final int[/*1*/] sampleCount) { final int curRenderModes; - if( null == sampleCount || 0 == sampleCount[0] ) { + if( 0 == sampleCount[0] ) { // no sampling, reduce to pass1 curRenderModes = getRenderModes() & ~( VBAA_RENDERING_BIT | MSAA_RENDERING_BIT ); } else if( 0 > sampleCount[0] ) { @@ -528,6 +529,9 @@ public abstract class GLRegion extends Region { // normal 2-pass sampling curRenderModes = getRenderModes(); } + // System.err.println("XXX.0 "+Region.getRenderModeString(getRenderModes(), sampleCount[0], 0)+": "+ + // Region.getRenderModeString(lastRenderModes, sampleCount[0], 0)+" -> "+Region.getRenderModeString(curRenderModes, sampleCount[0], 0)); + if( lastRenderModes != curRenderModes ) { markShapeDirty(); markStateDirty(); @@ -535,7 +539,7 @@ public abstract class GLRegion extends Region { if( isShapeDirty() ) { updateImpl(gl, renderer, curRenderModes); } - drawImpl(gl, renderer, curRenderModes, sampleCount); + drawImpl(gl, renderer, curRenderModes, pass2Quality, sampleCount); clearDirtyBits(DIRTY_SHAPE|DIRTY_STATE); lastRenderModes = curRenderModes; } @@ -549,5 +553,5 @@ public abstract class GLRegion extends Region { */ protected abstract void updateImpl(final GL2ES2 gl, final RegionRenderer renderer, final int curRenderModes); - protected abstract void drawImpl(final GL2ES2 gl, final RegionRenderer renderer, final int curRenderModes, final int[/*1*/] sampleCount); + protected abstract void drawImpl(final GL2ES2 gl, final RegionRenderer renderer, final int curRenderModes, int pass2Quality, 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 c43dc7913..cf9ac637b 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java @@ -28,6 +28,7 @@ package com.jogamp.graph.curve.opengl; import java.io.IOException; +import java.util.HashMap; import java.util.Iterator; import com.jogamp.opengl.GL; @@ -44,7 +45,6 @@ import com.jogamp.opengl.util.glsl.ShaderCode; import com.jogamp.opengl.util.glsl.ShaderProgram; import com.jogamp.opengl.util.texture.TextureSequence; import com.jogamp.common.os.Platform; -import com.jogamp.common.util.IntObjectHashMap; import com.jogamp.graph.curve.Region; import com.jogamp.math.Recti; import com.jogamp.math.Vec4f; @@ -67,6 +67,7 @@ public final class RegionRenderer { protected static final boolean DEBUG = Region.DEBUG; protected static final boolean DEBUG_ALL_EVENT = Region.DEBUG_ALL_EVENT; protected static final boolean DEBUG_INSTANCE = Region.DEBUG_INSTANCE; + private static final boolean DEBUG_SHADER_MAP = DEBUG; /** * May be passed to @@ -91,7 +92,7 @@ public final class RegionRenderer { * and turning-on the {@link GL#GL_BLEND} state. ** Implementation also sets {@link RegionRenderer#getRenderState() RenderState}'s {@link RenderState#BITHINT_BLENDING_ENABLED blending bit-hint}, - * which will cause {@link GLRegion#draw(GL2ES2, RegionRenderer, int[]) GLRegion's draw-method} + * which will cause {@link GLRegion#draw(GL2ES2, RegionRenderer, int, int[]) GLRegion's draw-method} * to set the proper {@link GL#glBlendFuncSeparate(int, int, int, int) blend-function} * and the clear-color to transparent-black in case of {@link Region#isTwoPass(int) multipass} FBO rendering. *
@@ -235,7 +236,7 @@ public final class RegionRenderer { * Initialize shader and bindings for GPU based rendering bound to the given GL object's GLContext * if not initialized yet. *Disables the renderer via {@link #enable(GL2ES2, boolean)} to remove any side-effects, ie ShaderState incl. shader program.
- *Shall be called once before at initialization before a {@code draw()} method, e.g. {@link RegionRenderer#draw(GL2ES2, Region, int)}
+ *Shall be called once before at initialization before a {@code draw()} method, e.g. {@link RegionRenderer#draw(GL2ES2, Region, int, int)}
* * @param gl referencing the current GLContext to which the ShaderState is bound to * @throws GLException if initialization failed @@ -273,8 +274,8 @@ public final class RegionRenderer { } return; } - for(final Iterator- * If set, {@link GLRegion#draw(GL2ES2, RegionRenderer, int[]) GLRegion's draw-method} + * If set, {@link GLRegion#draw(GL2ES2, RegionRenderer, int, int[]) GLRegion's draw-method} * will set the proper {@link GL#glBlendFuncSeparate(int, int, int, int) blend-function} * and the clear-color to transparent-black in case of {@link Region#isTwoPass(int) multipass} FBO rendering. *
@@ -79,7 +79,7 @@ public class RenderState { * Shall be set via {@link #setHintMask(int)} and cleared via {@link #clearHintMask(int)}. * *- * {@link GLRegion#draw(GL2ES2, RegionRenderer, int[]) GLRegion's draw-method} + * {@link GLRegion#draw(GL2ES2, RegionRenderer, int, int[]) GLRegion's draw-method} * may toggle depth test, and reset it's state according to this hint. *
*@@ -137,10 +137,12 @@ public class RenderState { * @param gl * @param updateLocation * @param renderModes + * @param setPMVMat01 TODO * @param throwOnError TODO * @return true if no error occurred, i.e. all locations found, otherwise false. */ - public final boolean update(final GL2ES2 gl, final RenderState rs, final boolean updateLocation, final int renderModes, final boolean pass1, final boolean throwOnError) { + public final boolean update(final GL2ES2 gl, final RenderState rs, final boolean updateLocation, final int renderModes, + final boolean setPMVMat01, final boolean pass1, final boolean throwOnError) { if( rs.id() != rsId ) { // Assignment of Renderstate buffers to uniforms (no copy, direct reference) gcu_PMVMatrix01.setData(rs.pmvMatrix.getSyncPMv()); @@ -150,7 +152,7 @@ public class RenderState { } boolean res = true; if( null != rs.sp && rs.sp.inUse() ) { - if( !Region.isTwoPass(renderModes) || !pass1 ) { + if( setPMVMat01 ) { final boolean r0 = rs.updateUniformDataLoc(gl, updateLocation, true, gcu_PMVMatrix01, throwOnError); res = res && r0; } diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java index e6e4f3e0c..a0e342acd 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java @@ -231,7 +231,7 @@ public class TextRegionUtil { } else { renderer.setColorStatic(1, 1, 1, 1); } - region.draw(gl, renderer, sampleCount); + region.draw(gl, renderer, Region.MAX_AA_QUALITY, sampleCount); return res; } @@ -293,7 +293,7 @@ public class TextRegionUtil { } else { renderer.setColorStatic(1, 1, 1, 1); } - region.draw(gl, renderer, sampleCount); + region.draw(gl, renderer, Region.MAX_AA_QUALITY, sampleCount); region.destroy(gl); return res; } @@ -352,7 +352,7 @@ public class TextRegionUtil { } else { renderer.setColorStatic(1, 1, 1, 1); } - region.draw(gl, renderer, sampleCount); + region.draw(gl, renderer, Region.MAX_AA_QUALITY, sampleCount); return res; } 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 2da2dcbfc..99704ced0 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/ImageSequence.java +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/ImageSequence.java @@ -159,6 +159,7 @@ public class ImageSequence implements TextureSequence { } else if(null != texLookupFuncName && texLookupFuncName.length()>0) { textureLookupFunctionName = texLookupFuncName; } + textureFragmentShaderHashCode = 0; return textureLookupFunctionName; } @@ -179,14 +180,23 @@ public class ImageSequence implements TextureSequence { "}\n\n"; } + @Override + public String getTextureFragmentShaderHashID() { + // return getTextureSampler2DType()+";"+getTextureLookupFunctionName()+";"+getTextureLookupFragmentShaderImpl(); + if( useBuildInTexLookup ) { + return getTextureSampler2DType()+";"+getTextureLookupFunctionName(); + } else { + return getTextureLookupFragmentShaderImpl(); + } + } + @Override public int getTextureFragmentShaderHashCode() { if( !isTextureAvailable() ) { textureFragmentShaderHashCode = 0; return 0; } else if( 0 == textureFragmentShaderHashCode ) { - int hash = 31 + getTextureLookupFragmentShaderImpl().hashCode(); - hash = ((hash << 5) - hash) + getTextureSampler2DType().hashCode(); + final int hash = getTextureFragmentShaderHashID().hashCode(); textureFragmentShaderHashCode = hash; } return textureFragmentShaderHashCode; 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 8376f0fa5..6aa70f014 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureSequence.java +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureSequence.java @@ -274,19 +274,31 @@ public interface TextureSequence { * @throws IllegalStateException if instance is not initialized * @see #getTextureLookupFunctionName() * @see #setTextureLookupFunctionName(String) + * @see #getTextureFragmentShaderHashID() * @see #getTextureFragmentShaderHashCode() * @see #getTextureSampler2DType() */ public String getTextureLookupFragmentShaderImpl() throws IllegalStateException; /** - * Returns the hash code of the strings: + * Returns the concatenated string representing the following values + * utilized for {@link #getTextureFragmentShaderHashCode()}. *
+ * To reduce string concatenating, implementation may simply return {@link #getTextureLookupFragmentShaderImpl()}, + * if it covers {@link #getTextureSampler2DType()} and {@link #getTextureLookupFunctionName()}. + *
+ * @see #getTextureFragmentShaderHashCode() + */ + public String getTextureFragmentShaderHashID(); + + /** + * Returns the hash code of the string {@link #getTextureFragmentShaderHashID()}. + ** User shall call {@link #setTextureLookupFunctionName(String)} first if intended. *
*@@ -296,12 +308,13 @@ public interface TextureSequence { *
*
*- * Implementation caches the resulting hash code, - * which must be reset to zero if {@link #isTextureAvailable() texture is not available}. + * Implementation caches the resulting hash code, which is reset by {@link #setTextureLookupFunctionName(String)} + * and this method if {@link #isTextureAvailable() texture is not available}. *
* @see #setTextureLookupFunctionName(String) * @see #getTextureLookupFunctionName() * @see #getTextureLookupFragmentShaderImpl() + * @see #getTextureFragmentShaderHashID() */ public int getTextureFragmentShaderHashCode(); -- cgit v1.2.3