summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-03-14 08:13:42 +0100
committerSven Gothel <[email protected]>2014-03-14 08:13:42 +0100
commite16e974a3e2b38c65355838eeb010954354097d2 (patch)
treee1582436012d80ffddb5a81e6056a5aaa4e7368b /src/jogl/classes/com
parent70979247aad156418c32959bbf4962f175191ec2 (diff)
Bug 801: Add Frustum support to Region; Misc ..
Region: Add Frustum support, to drop 'out of sight' shapes RenderState: Add hints, e.g. BITHINT_BLENDING_ENABLED, allowing user code to toggle background color etc Demos: Incomplete - WIP - Reuse mapped object to window coords computed at reshape - TODO: Use minimal Scenegraph for Graph-UI ..
Diffstat (limited to 'src/jogl/classes/com')
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/Region.java95
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java16
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java18
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java33
4 files changed, 122 insertions, 40 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/curve/Region.java b/src/jogl/classes/com/jogamp/graph/curve/Region.java
index 8e68b7913..853c837f5 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/Region.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/Region.java
@@ -30,22 +30,20 @@ package com.jogamp.graph.curve;
import java.util.ArrayList;
import java.util.List;
-import jogamp.graph.curve.opengl.VBORegion2PVBAAES2;
-import jogamp.graph.curve.opengl.VBORegion2PMSAAES2;
-import jogamp.graph.curve.opengl.VBORegionSPES2;
import jogamp.graph.geom.plane.AffineTransform;
import jogamp.opengl.Debug;
-import com.jogamp.graph.curve.opengl.GLRegion;
import com.jogamp.graph.geom.Triangle;
import com.jogamp.graph.geom.Vertex;
import com.jogamp.opengl.math.geom.AABBox;
+import com.jogamp.opengl.math.geom.Frustum;
/**
* Abstract Outline shape representation define the method an OutlineShape(s)
* is bound and rendered.
*
- * @see GLRegion */
+ * @see com.jogamp.graph.curve.opengl.GLRegion
+ */
public abstract class Region {
/** Debug flag for region impl (graph.curve) */
@@ -53,25 +51,34 @@ public abstract class Region {
public static final boolean DEBUG_INSTANCE = Debug.debug("graph.curve.instance");
/**
+ * Rendering-Mode bit for {@link Region#getRenderModes() Region} and {@link com.jogamp.graph.curve.opengl.RegionRenderer#getRenderModes() RegionRenderer}.
+ * <p>
* MSAA based Anti-Aliasing, a two pass region rendering, slower and more
* resource hungry (FBO), but providing fast MSAA in case
* the whole scene is not rendered with MSAA.
+ * </p>
*/
- public static final int MSAA_RENDERING_BIT = 1 << 0;
+ 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}.
+ * <p>
* View based Anti-Aliasing, a two pass region rendering, slower and more
* resource hungry (FBO), but AA is perfect. Otherwise the default fast one
* pass MSAA region rendering is being used.
+ * </p>
*/
- public static final int VBAA_RENDERING_BIT = 1 << 1;
+ 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}.
+ * <p>
* Use non uniform weights [0.0 .. 1.9] for curve region rendering.
* Otherwise the default weight 1.0 for uniform curve region rendering is
* being applied.
+ * </p>
*/
- public static final int VARIABLE_CURVE_WEIGHT_BIT = 1 << 8;
+ public static final int VARIABLE_CURVE_WEIGHT_BIT = 1 << 8;
public static final int TWO_PASS_DEFAULT_TEXTURE_UNIT = 0;
@@ -79,6 +86,7 @@ public abstract class Region {
private boolean dirty = true;
private int numVertices = 0;
protected final AABBox box = new AABBox();
+ protected Frustum frustum = null;
public static boolean isVBAA(int renderModes) {
return 0 != (renderModes & Region.VBAA_RENDERING_BIT);
@@ -86,15 +94,6 @@ public abstract class Region {
public static boolean isMSAA(int renderModes) {
return 0 != (renderModes & Region.MSAA_RENDERING_BIT);
}
- public static String getRenderModeString(int renderModes) {
- if( Region.isVBAA(renderModes) ) {
- return "vbaa";
- } else if( Region.isMSAA(renderModes) ) {
- return "msaa";
- } else {
- return "norm" ;
- }
- }
/**
* Check if render mode capable of non uniform weights
@@ -108,22 +107,14 @@ public abstract class Region {
return 0 != (renderModes & Region.VARIABLE_CURVE_WEIGHT_BIT);
}
- /**
- * Create a Region using the passed render mode
- *
- * <p> In case {@link Region#VBAA_RENDERING_BIT} is being requested the default texture unit
- * {@link Region#TWO_PASS_DEFAULT_TEXTURE_UNIT} is being used.</p>
- *
- * @param rs the RenderState to be used
- * @param renderModes bit-field of modes, e.g. {@link Region#VARIABLE_CURVE_WEIGHT_BIT}, {@link Region#VBAA_RENDERING_BIT}
- */
- public static GLRegion create(int renderModes) {
- if( isVBAA(renderModes) ) {
- return new VBORegion2PVBAAES2(renderModes, Region.TWO_PASS_DEFAULT_TEXTURE_UNIT);
- } else if( isMSAA(renderModes) ) {
- return new VBORegion2PMSAAES2(renderModes, Region.TWO_PASS_DEFAULT_TEXTURE_UNIT);
+ public static String getRenderModeString(int renderModes) {
+ final String curveS = isNonUniformWeight(renderModes) ? "-curve" : "";
+ if( Region.isVBAA(renderModes) ) {
+ return "vbaa"+curveS;
+ } else if( Region.isMSAA(renderModes) ) {
+ return "msaa"+curveS;
} else {
- return new VBORegionSPES2(renderModes);
+ return "norm"+curveS;
}
}
@@ -170,6 +161,16 @@ public abstract class Region {
return Region.isNonUniformWeight(renderModes);
}
+ /** See {@link #setFrustum(Frustum)} */
+ public final Frustum getFrustum() { return frustum; }
+
+ /**
+ * Set {@link Frustum} culling for {@link #addOutlineShape(OutlineShape, AffineTransform)}.
+ */
+ public final void setFrustum(Frustum frustum) {
+ this.frustum = frustum;
+ }
+
final float[] coordsEx = new float[3];
private void pushNewVertexImpl(final Vertex vertIn, final AffineTransform transform) {
@@ -191,7 +192,33 @@ public abstract class Region {
pushNewVertexImpl(vertIn, transform);
}
+ private final AABBox tmpBox = new AABBox();
+
+ /**
+ * Add the given {@link OutlineShape} to this region with the given optional {@link AffineTransform}.
+ * <p>
+ * In case {@link #setFrustum(Frustum) frustum culling is set}, the {@link OutlineShape}
+ * is dropped if it's {@link OutlineShape#getBounds() bounding-box} is fully outside of the frustum.
+ * The optional {@link AffineTransform} is applied to the bounding-box beforehand.
+ * </p>
+ */
public final void addOutlineShape(final OutlineShape shape, final AffineTransform transform) {
+ if( null != frustum ) {
+ final AABBox shapeBox = shape.getBounds();
+ final AABBox shapeBoxT;
+ if( null != transform ) {
+ transform.transform(shapeBox, tmpBox);
+ shapeBoxT = tmpBox;
+ } else {
+ shapeBoxT = shapeBox;
+ }
+ if( frustum.isAABBoxOutside(shapeBoxT) ) {
+ if(DEBUG_INSTANCE) {
+ System.err.println("Region.addOutlineShape(): Dropping outside shapeBoxT: "+shapeBoxT);
+ }
+ return;
+ }
+ }
final List<Triangle> trisIn = shape.getTriangles(OutlineShape.VerticesState.QUADRATIC_NURBS);
final ArrayList<Vertex> vertsIn = shape.getVertices();
if(DEBUG_INSTANCE) {
@@ -277,4 +304,8 @@ public abstract class Region {
protected final void setDirty(boolean v) {
dirty = v;
}
+
+ public String toString() {
+ return "Region["+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 defb7722a..96d285898 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java
@@ -30,6 +30,10 @@ package com.jogamp.graph.curve.opengl;
import javax.media.opengl.GL;
import javax.media.opengl.GL2ES2;
+import jogamp.graph.curve.opengl.VBORegion2PMSAAES2;
+import jogamp.graph.curve.opengl.VBORegion2PVBAAES2;
+import jogamp.graph.curve.opengl.VBORegionSPES2;
+
import com.jogamp.opengl.util.PMVMatrix;
import com.jogamp.graph.curve.Region;
@@ -55,7 +59,13 @@ public abstract class GLRegion extends Region {
* @param renderModes bit-field of modes, e.g. {@link Region#VARIABLE_CURVE_WEIGHT_BIT}, {@link Region#VBAA_RENDERING_BIT}
*/
public static GLRegion create(int renderModes) {
- return Region.create(renderModes);
+ if( isVBAA(renderModes) ) {
+ return new VBORegion2PVBAAES2(renderModes, Region.TWO_PASS_DEFAULT_TEXTURE_UNIT);
+ } else if( isMSAA(renderModes) ) {
+ return new VBORegion2PMSAAES2(renderModes, Region.TWO_PASS_DEFAULT_TEXTURE_UNIT);
+ } else {
+ return new VBORegionSPES2(renderModes);
+ }
}
protected GLRegion(int renderModes) {
@@ -68,7 +78,7 @@ public abstract class GLRegion extends Region {
* <p>Allocates the ogl related data and initializes it the 1st time.<p>
* <p>Called by {@link #draw(GL2ES2, RenderState, int, int, int)}.</p>
*/
- protected abstract void update(GL2ES2 gl, RegionRenderer renderer);
+ protected abstract void updateImpl(GL2ES2 gl, RegionRenderer renderer);
protected abstract void destroyImpl(GL2ES2 gl, RegionRenderer renderer);
@@ -121,7 +131,7 @@ public abstract class GLRegion extends Region {
*/
public final void draw(GL2ES2 gl, RegionRenderer renderer, int[/*1*/] sampleCount) {
if(isDirty()) {
- update(gl, renderer);
+ updateImpl(gl, renderer);
setDirty(false);
}
drawImpl(gl, renderer, 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 1f6e532d3..bff7c905f 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java
@@ -62,27 +62,35 @@ public abstract class RegionRenderer {
* Default {@link GL#GL_BLEND} <i>enable</i> {@link GLCallback},
* turning on the {@link GL#GL_BLEND} state and setting up
* {@link GL#glBlendFunc(int, int) glBlendFunc}({@link GL#GL_SRC_ALPHA}, {@link GL#GL_ONE_MINUS_SRC_ALPHA}).
- * @see #setEnableCallback(GLCallback, GLCallback)
+ * <p>
+ * Implementation also sets {@link RegionRenderer#getRenderState() RenderState}'s {@link RenderState#BITHINT_BLENDING_ENABLED blending bit-hint}.
+ * </p>
+ * @see #create(RenderState, int, GLCallback, GLCallback)
* @see #enable(GL2ES2, boolean)
*/
public static final GLCallback defaultBlendEnable = new GLCallback() {
@Override
- public void run(final GL gl, final RegionRenderer args) {
+ public void run(final GL gl, final RegionRenderer renderer) {
gl.glEnable(GL.GL_BLEND);
gl.glBlendEquation(GL.GL_FUNC_ADD); // default
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
+ renderer.rs.setHintBits(RenderState.BITHINT_BLENDING_ENABLED);
}
};
/**
* Default {@link GL#GL_BLEND} <i>disable</i> {@link GLCallback},
* simply turning off the {@link GL#GL_BLEND} state.
- * @see #setEnableCallback(GLCallback, GLCallback)
+ * <p>
+ * Implementation also clears {@link RegionRenderer#getRenderState() RenderState}'s {@link RenderState#BITHINT_BLENDING_ENABLED blending bit-hint}.
+ * </p>
+ * @see #create(RenderState, int, GLCallback, GLCallback)
* @see #enable(GL2ES2, boolean)
*/
public static final GLCallback defaultBlendDisable = new GLCallback() {
@Override
- public void run(final GL gl, final RegionRenderer args) {
+ public void run(final GL gl, final RegionRenderer renderer) {
+ renderer.rs.clearHintBits(RenderState.BITHINT_BLENDING_ENABLED);
gl.glDisable(GL.GL_BLEND);
}
};
@@ -287,7 +295,7 @@ public abstract class RegionRenderer {
}
- public final void getColorStatic(GL2ES2 gl, float[] rgb) {
+ public final void getColorStatic(float[] rgb) {
FloatBuffer fb = (FloatBuffer) rs.getColorStatic().getBuffer();
rgb[0] = fb.get(0);
rgb[1] = fb.get(1);
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 9b0f32ef6..d6eac19de 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java
@@ -27,6 +27,7 @@
*/
package com.jogamp.graph.curve.opengl;
+import javax.media.opengl.GL;
import javax.media.opengl.GL2ES2;
import javax.media.opengl.GLUniformData;
@@ -34,6 +35,7 @@ import jogamp.graph.curve.opengl.RenderStateImpl;
import jogamp.graph.curve.opengl.shader.UniformNames;
import com.jogamp.common.os.Platform;
+import com.jogamp.graph.curve.Region;
import com.jogamp.graph.geom.Vertex;
import com.jogamp.opengl.util.PMVMatrix;
import com.jogamp.opengl.util.glsl.ShaderState;
@@ -41,6 +43,25 @@ import com.jogamp.opengl.util.glsl.ShaderState;
public abstract class RenderState {
private static final String thisKey = "jogamp.graph.curve.RenderState" ;
+ /**
+ * Bitfield hint, {@link #isHintBitSet(int) if set}
+ * stating <i>enabled</i> {@link GL#GL_BLEND}, otherwise <i>disabled</i>.
+ * <p>
+ * Shall be set via {@link #setHintBits(int)} and cleared via {@link #clearHintBits(int)}.
+ * </p>
+ * <p>
+ * Due to alpha blending and multipass rendering, e.g. {@link Region#VBAA_RENDERING_BIT},
+ * the clear-color shall be set to the {@link #getColorStatic() foreground color} and <i>zero alpha</i>,
+ * otherwise blending will amplify the scene's clear-color.
+ * </p>
+ * <p>
+ * Shall be called by custom code, e.g. via {@link RegionRenderer}'s
+ * enable and disable {@link RegionRenderer.GLCallback} as done in
+ * {@link RegionRenderer#defaultBlendEnable} and {@link RegionRenderer#defaultBlendDisable}.
+ * </p>
+ */
+ public static final int BITHINT_BLENDING_ENABLED = 1 << 0 ;
+
public static RenderState createRenderState(ShaderState st, Vertex.Factory<? extends Vertex> pointFactory) {
return new RenderStateImpl(st, pointFactory, null);
}
@@ -57,6 +78,7 @@ public abstract class RenderState {
protected final Vertex.Factory<? extends Vertex> vertexFactory;
protected final PMVMatrix pmvMatrix;
protected final GLUniformData gcu_PMVMatrix;
+ protected int hintBitfield;
protected RenderState(ShaderState st, Vertex.Factory<? extends Vertex> vertexFactory, PMVMatrix pmvMatrix) {
this.st = st;
@@ -64,6 +86,7 @@ public abstract class RenderState {
this.pmvMatrix = null != pmvMatrix ? pmvMatrix : new PMVMatrix();
this.gcu_PMVMatrix = new GLUniformData(UniformNames.gcu_PMVMatrix, 4, 4, this.pmvMatrix.glGetPMvMatrixf());
st.ownUniform(gcu_PMVMatrix);
+ this.hintBitfield = 0;
}
public final ShaderState getShaderState() { return st; }
@@ -71,6 +94,16 @@ public abstract class RenderState {
public final PMVMatrix pmvMatrix() { return pmvMatrix; }
public final GLUniformData getPMVMatrix() { return gcu_PMVMatrix; }
+ public final boolean isHintBitSet(int mask) {
+ return mask == ( hintBitfield & mask );
+ }
+ public final void setHintBits(int mask) {
+ hintBitfield |= mask;
+ }
+ public final void clearHintBits(int mask) {
+ hintBitfield &= ~mask;
+ }
+
public void destroy(GL2ES2 gl) {
st.destroy(gl);
}