From e8a5a1cbb988670ca206ab1ac633e19a91bfa478 Mon Sep 17 00:00:00 2001
From: Sven Gothel
* MSAA based Anti-Aliasing, a two pass region rendering, slower and more
* resource hungry (FBO), but providing fast MSAA in case
@@ -61,7 +61,7 @@ public abstract class Region {
public static final int MSAA_RENDERING_BIT = 1 << 0;
/**
- * Rendering-Mode bit for {@link Region#getRenderModes() Region} and {@link com.jogamp.graph.curve.opengl.RegionRenderer#getRenderModes() RegionRenderer}.
+ * Rendering-Mode bit for {@link #getRenderModes() Region}
*
* View based Anti-Aliasing, a two pass region rendering, slower and more
* resource hungry (FBO), but AA is perfect. Otherwise the default fast one
@@ -71,7 +71,7 @@ public abstract class Region {
public static final int VBAA_RENDERING_BIT = 1 << 1;
/**
- * Rendering-Mode bit for {@link Region#getRenderModes() Region} and {@link com.jogamp.graph.curve.opengl.RegionRenderer#getRenderModes() RegionRenderer}.
+ * Rendering-Mode bit for {@link #getRenderModes() Region}
*
* Use non uniform weights [0.0 .. 1.9] for curve region rendering.
* Otherwise the default weight 1.0 for uniform curve region rendering is
@@ -81,7 +81,7 @@ public abstract class Region {
public static final int VARWEIGHT_RENDERING_BIT = 1 << 8;
/**
- * Rendering-Mode bit for {@link Region#getRenderModes() Region} and {@link com.jogamp.graph.curve.opengl.RegionRenderer#getRenderModes() RegionRenderer}.
+ * Rendering-Mode bit for {@link #getRenderModes() Region}
*
* If set, a color channel attribute per vertex is added to the stream,
* otherwise only the
@@ -92,13 +92,16 @@ public abstract class Region {
public static final int COLORCHANNEL_RENDERING_BIT = 1 << 9;
/**
- * Rendering-Mode bit for {@link Region#getRenderModes() Region} and {@link com.jogamp.graph.curve.opengl.RegionRenderer#getRenderModes() RegionRenderer}.
+ * Rendering-Mode bit for {@link #getRenderModes() Region}
*
* If set, a color texture is used to determine the color.
* Allocates the ogl related data and initializes it the 1st time.
* Called by {@link #draw(GL2ES2, RenderState, int, int, int)}.
* Implementation also sets {@link RegionRenderer#getRenderState() RenderState}'s {@link RenderState#BITHINT_BLENDING_ENABLED blending bit-hint}. *
- * @see #create(RenderState, int, GLCallback, GLCallback) + * @see #create(RenderState, GLCallback, GLCallback) * @see #enable(GL2ES2, boolean) */ public static final GLCallback defaultBlendEnable = new GLCallback() { @@ -89,7 +89,7 @@ public class RegionRenderer { ** Implementation also clears {@link RegionRenderer#getRenderState() RenderState}'s {@link RenderState#BITHINT_BLENDING_ENABLED blending bit-hint}. *
- * @see #create(RenderState, int, GLCallback, GLCallback) + * @see #create(RenderState, GLCallback, GLCallback) * @see #enable(GL2ES2, boolean) */ public static final GLCallback defaultBlendDisable = new GLCallback() { @@ -109,20 +109,18 @@ public class RegionRenderer { * can be utilized to enable and disable {@link GL#GL_BLEND}. * * @param rs the used {@link RenderState} - * @param renderModes bit-field of modes, e.g. {@link Region#VARWEIGHT_RENDERING_BIT}, {@link Region#VBAA_RENDERING_BIT} * @param enableCallback optional {@link GLCallback}, if notnull
will be issued at
- * {@link #init(GL2ES2) init(gl)} and {@link #enable(GL2ES2, boolean) enable(gl, true)}.
+ * {@link #init(GL2ES2, int) init(gl)} and {@link #enable(GL2ES2, boolean) enable(gl, true)}.
* @param disableCallback optional {@link GLCallback}, if not null
will be issued at
* {@link #enable(GL2ES2, boolean) enable(gl, false)}.
* @return an instance of Region Renderer
* @see #enable(GL2ES2, boolean)
*/
- public static RegionRenderer create(final RenderState rs, final int renderModes,
- final GLCallback enableCallback, final GLCallback disableCallback) {
- return new RegionRenderer(rs, renderModes, enableCallback, disableCallback);
+ public static RegionRenderer create(final RenderState rs, final GLCallback enableCallback,
+ final GLCallback disableCallback) {
+ return new RegionRenderer(rs, enableCallback, disableCallback);
}
- private final int renderModes;
private final RenderState rs;
private final GLCallback enableCallback;
@@ -149,30 +147,13 @@ public class RegionRenderer {
/**
* @param rs the used {@link RenderState}
- * @param renderModes bit-field of modes
*/
- protected RegionRenderer(final RenderState rs, final int renderModes, final GLCallback enableCallback, final GLCallback disableCallback) {
+ protected RegionRenderer(final RenderState rs, final GLCallback enableCallback, final GLCallback disableCallback) {
this.rs = rs;
- this.renderModes = renderModes;
this.enableCallback = enableCallback;
this.disableCallback = disableCallback;
}
- public final int getRenderModes() {
- return renderModes;
- }
-
- public final boolean usesVariableCurveWeight() { return Region.hasVariableWeight(renderModes); }
-
- /**
- * @return true if Region's renderModes contains all bits as this Renderer's renderModes
- * except {@link Region#VARWEIGHT_RENDERING_BIT}, otherwise false.
- */
- public final boolean areRenderModesCompatible(final Region region) {
- final int cleanRenderModes = getRenderModes() & ( Region.VARWEIGHT_RENDERING_BIT );
- return cleanRenderModes == ( region.getRenderModes() & cleanRenderModes );
- }
-
public final boolean isVBOSupported() { return vboSupported; }
/**
@@ -182,9 +163,10 @@ public class RegionRenderer {
* Shall be called by a {@code draw()} method, e.g. {@link RegionRenderer#draw(GL2ES2, Region, int)}
* * @param gl referencing the current GLContext to which the ShaderState is bound to + * @param renderModes TODO * @throws GLException if initialization failed */ - public final void init(GL2ES2 gl) throws GLException { + public final void init(final GL2ES2 gl, final int renderModes) throws GLException { if(initialized){ return; } @@ -227,6 +209,7 @@ public class RegionRenderer { final ShaderProgram sp = (ShaderProgram) i.next().getValue(); sp.destroy(gl); } + shaderPrograms.clear(); rs.destroy(gl); initialized = false; } @@ -237,10 +220,10 @@ public class RegionRenderer { * Enabling or disabling the {@link #getRenderState() RenderState}'s * {@link RenderState#getShaderProgram() shader program}. *- * In case enable and disable {@link GLCallback}s are setup via {@link #create(RenderState, int, GLCallback, GLCallback)}, + * In case enable and disable {@link GLCallback}s are setup via {@link #create(RenderState, GLCallback, GLCallback)}, * they will be called before toggling the shader program. *
- * @see #create(RenderState, int, GLCallback, GLCallback) + * @see #create(RenderState, GLCallback, GLCallback) */ public final void enable(GL2ES2 gl, boolean enable) { if( enable ) { 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 f915b7d49..c7083a41b 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java @@ -104,17 +104,20 @@ public class RenderState { * Set a {@link ShaderProgram} and enable it. If the given {@link ShaderProgram} is new, * method returns true, otherwise false. * @param gl - * @param sp + * @param spNext * @return true if a new shader program is being used and hence external uniform-data and -location, * as well as the attribute-location must be updated, otherwise false. */ - public final boolean setShaderProgram(final GL2ES2 gl, final ShaderProgram sp) { - if( sp.equals(this.sp) ) { - sp.useProgram(gl, true); + public final boolean setShaderProgram(final GL2ES2 gl, final ShaderProgram spNext) { + if( spNext.equals(this.sp) ) { + spNext.useProgram(gl, true); return false; } - this.sp = sp; - sp.useProgram(gl, true); + if( null != this.sp ) { + this.sp.notifyNotInUse(); + } + this.sp = spNext; + spNext.useProgram(gl, true); return true; } @@ -129,13 +132,6 @@ public class RenderState { public final void setMatrixDirty() { gcu_PMVMatrix01_dirty = true; } public final boolean isMatrixDirty() { return gcu_PMVMatrix01_dirty;} - public final void updateMatrix(GL2ES2 gl) { - if( gcu_PMVMatrix01_dirty && sp.inUse() ) { - gl.glUniform( gcu_PMVMatrix01 ); - gcu_PMVMatrix01_dirty = false; - } - } - public static boolean isWeightValid(float v) { return 0.0f <= v && v <= 1.9f ; } @@ -179,20 +175,17 @@ public class RenderState { if( null != sp && sp.inUse() ) { if( ( !Region.isTwoPass(renderModes) || !pass1 ) && ( gcu_PMVMatrix01_dirty || updateLocation ) ) { final boolean r0 = updateUniformDataLoc(gl, updateLocation, gcu_PMVMatrix01_dirty, gcu_PMVMatrix01); - System.err.println("XXX gcu_PMVMatrix01.update: "+r0); res = res && r0; gcu_PMVMatrix01_dirty = !r0; } if( pass1 ) { if( Region.hasVariableWeight( renderModes ) && ( gcu_Weight_dirty || updateLocation ) ) { final boolean r0 = updateUniformDataLoc(gl, updateLocation, gcu_Weight_dirty, gcu_Weight); - System.err.println("XXX gcu_Weight.update: "+r0); res = res && r0; gcu_Weight_dirty = !r0; } if( gcu_ColorStatic_dirty || updateLocation ) { final boolean r0 = updateUniformDataLoc(gl, updateLocation, gcu_ColorStatic_dirty, gcu_ColorStatic); - System.err.println("XXX gcu_ColorStatic.update: "+r0); res = res && r0; gcu_ColorStatic_dirty = false; } 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 6d9fdab0b..16b1224bd 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java @@ -48,10 +48,10 @@ import com.jogamp.graph.geom.Vertex.Factory; */ public class TextRegionUtil { - public final RegionRenderer renderer; + public final int renderModes; - public TextRegionUtil(final RegionRenderer renderer) { - this.renderer = renderer; + public TextRegionUtil(final int renderModes) { + this.renderModes = renderModes; } public static interface ShapeVisitor { @@ -144,6 +144,7 @@ public class TextRegionUtil { * Cached {@link GLRegion}s will be destroyed w/ {@link #clear(GL2ES2)} or to free memory. * * @param gl the current GL state + * @param renderer TODO * @param font {@link Font} to be used * @param pixelSize Use {@link Font#getPixelSize(float, float)} for resolution correct pixel-size. * @param str text to be rendered @@ -153,15 +154,15 @@ public class TextRegionUtil { * @throws Exception if TextRenderer not initialized */ public void drawString3D(final GL2ES2 gl, - final Font font, final float pixelSize, final CharSequence str, - final float[] rgbaColor, final int[/*1*/] sampleCount) { + final RegionRenderer renderer, final Font font, final float pixelSize, + final CharSequence str, final float[] rgbaColor, final int[/*1*/] sampleCount) { if( !renderer.isInitialized() ) { throw new GLException("TextRendererImpl01: not initialized!"); } final int special = 0; GLRegion region = getCachedRegion(font, str, pixelSize, special); if(null == region) { - region = GLRegion.create(renderer.getRenderModes()); + region = GLRegion.create(renderModes); addStringToRegion(region, renderer.getRenderState().getVertexFactory(), font, pixelSize, str, rgbaColor); addCachedRegion(gl, font, str, pixelSize, special, region); } @@ -174,10 +175,11 @@ public class TextRegionUtil { ** In case of a multisampling region renderer, i.e. {@link Region#VBAA_RENDERING_BIT}, recreating the {@link GLRegion} * is a huge performance impact. - * In such case better use {@link #drawString3D(GLRegion, RegionRenderer, GL2ES2, Font, float, CharSequence, float[], int[])} + * In such case better use {@link #drawString3D(GL2ES2, GLRegion, RegionRenderer, Font, float, CharSequence, float[], int[])} * instead. *
* @param gl the current GL state + * @param renderModes TODO * @param font {@link Font} to be used * @param pixelSize Use {@link Font#getPixelSize(float, float)} for resolution correct pixel-size. * @param str text to be rendered @@ -186,21 +188,21 @@ public class TextRegionUtil { * The actual used scample-count is written back when msaa-rendering is enabled, otherwise the store is untouched. * @throws Exception if TextRenderer not initialized */ - public static void drawString3D(final RegionRenderer renderer, final GL2ES2 gl, - final Font font, final float pixelSize, final CharSequence str, - final float[] rgbaColor, final int[/*1*/] sampleCount) { + public static void drawString3D(final GL2ES2 gl, final int renderModes, + final RegionRenderer renderer, final Font font, final float pixelSize, + final CharSequence str, final float[] rgbaColor, final int[/*1*/] sampleCount) { if(!renderer.isInitialized()){ throw new GLException("TextRendererImpl01: not initialized!"); } - final GLRegion region = GLRegion.create(renderer.getRenderModes()); + final GLRegion region = GLRegion.create(renderModes); addStringToRegion(region, renderer.getRenderState().getVertexFactory(), font, pixelSize, str, rgbaColor); region.draw(gl, renderer, sampleCount); - region.destroy(gl, renderer); + region.destroy(gl); } /** * Render the string in 3D space w.r.t. the font and pixelSize - * using the given {@link GLRegion}, which will {@link GLRegion#clear(GL2ES2, RegionRenderer) cleared} beforehand. + * using the given {@link GLRegion}, which will {@link GLRegion#clear(GL2ES2) cleared} beforehand. * @param gl the current GL state * @param font {@link Font} to be used * @param pixelSize Use {@link Font#getPixelSize(float, float)} for resolution correct pixel-size. @@ -210,13 +212,13 @@ public class TextRegionUtil { * The actual used scample-count is written back when msaa-rendering is enabled, otherwise the store is untouched. * @throws Exception if TextRenderer not initialized */ - public static void drawString3D(final GLRegion region, final RegionRenderer renderer, final GL2ES2 gl, + public static void drawString3D(final GL2ES2 gl, final GLRegion region, final RegionRenderer renderer, final Font font, final float pixelSize, final CharSequence str, final float[] rgbaColor, final int[/*1*/] sampleCount) { if(!renderer.isInitialized()){ throw new GLException("TextRendererImpl01: not initialized!"); } - region.clear(gl, renderer); + region.clear(gl); addStringToRegion(region, renderer.getRenderState().getVertexFactory(), font, pixelSize, str, rgbaColor); region.draw(gl, renderer, sampleCount); } @@ -229,7 +231,7 @@ public class TextRegionUtil { final Iterator