aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/graph
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-05-08 05:21:50 +0200
committerSven Gothel <[email protected]>2011-05-08 05:21:50 +0200
commite122b2f92b2302362569cdc9a67efd5750f46eb1 (patch)
tree8941dcce577ff5e1378a7322932c4bbfc586373c /src/jogl/classes/com/jogamp/graph
parentf88a51cb1c811bba5b5803aee03829b41da308c3 (diff)
Graph: GLSL fix, Adding renderModes bits instead of dedicated booleans, Region/GLRegion, ..
GLSL fix: - allowing #version tag - add uniform textureSize (ES2) - fix int/float conversion Region/GLRegion: - non OpenGL Region and GL related GLRegion split Region/Renderer renderModes bits (def. in Region) - user creates a Renderer* impl .. and derive Region*'s from outline, possibly from a different code path. - to avoid mode explosion, a bit field is being used for now - Renderer: remove flushCache(), since non caching impl. is intended, or caching by an external user transparent object.
Diffstat (limited to 'src/jogl/classes/com/jogamp/graph')
-rw-r--r--[-rwxr-xr-x]src/jogl/classes/com/jogamp/graph/curve/Region.java274
-rwxr-xr-xsrc/jogl/classes/com/jogamp/graph/curve/RegionFactory.java69
-rwxr-xr-xsrc/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java125
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java126
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java155
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java36
6 files changed, 385 insertions, 400 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/curve/Region.java b/src/jogl/classes/com/jogamp/graph/curve/Region.java
index eb88b787c..320483d8d 100755..100644
--- a/src/jogl/classes/com/jogamp/graph/curve/Region.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/Region.java
@@ -1,132 +1,142 @@
-/**
- * Copyright 2010 JogAmp Community. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are
- * permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list
- * of conditions and the following disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * The views and conclusions contained in the software and documentation are those of the
- * authors and should not be interpreted as representing official policies, either expressed
- * or implied, of JogAmp Community.
- */
-package com.jogamp.graph.curve;
-
-import java.util.ArrayList;
-
-import javax.media.opengl.GL2ES2;
-
-import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.graph.geom.AABBox;
-import jogamp.opengl.Debug;
-
-import com.jogamp.graph.geom.Triangle;
-import com.jogamp.graph.geom.Vertex;
-import com.jogamp.opengl.util.PMVMatrix;
-
-/** A Region is the OGL binding of one or more OutlineShapes
- * Defined by its vertices and generated triangles. The Region
- * defines the final shape of the OutlineShape(s), which shall produced a shaded
- * region on the screen.
- *
- * Implementations of the Region shall take care of the OGL
- * binding of the depending on its context, profile.
- *
- * @see RegionFactory, OutlineShape
- */
-public interface Region {
- public static final boolean DEBUG = Debug.debug("graph.curve");
- public static final boolean DEBUG_INSTANCE = false;
-
- /** single pass rendering, fast, but AA might not be perfect */
- public static int SINGLE_PASS = 1;
-
- /** two pass rendering, slower and more resource hungry (FBO), but AA is perfect */
- public static int TWO_PASS = 2;
- public static int TWO_PASS_DEFAULT_TEXTURE_UNIT = 0;
-
- /** Updates a graph region by updating the ogl related
- * objects for use in rendering. if called for the first time
- * it initialize the objects.
- */
- public void update(GL2ES2 gl);
-
- /** Renders the associated OGL objects specifying
- * current width/hight of window for multi pass rendering
- * of the region.
- * @param matrix current {@link PMVMatrix}.
- * @param vp_width current screen width
- * @param vp_height current screen height
- * @param width texture width for mp rendering
- *
- * @see update()
- */
- public void render(GL2ES2 gl, RenderState rs, int vp_width, int vp_height, int width);
-
- /** Adds a list of {@link Triangle} objects to the Region
- * These triangles are to be binded to OGL objects
- * on the next call to {@code update}
- * @param tris an arraylist of triangle objects
- *
- * @see update()
- */
- public void addTriangles(ArrayList<Triangle> tris);
-
- /** Get the current number of vertices associated
- * with this region. This number is not necessary equal to
- * the OGL binded number of vertices.
- * @return vertices count
- *
- * @see isDirty()
- */
- public int getNumVertices();
-
- /** Adds a list of {@link Vertex} objects to the Region
- * These vertices are to be binded to OGL objects
- * on the next call to {@code update}
- * @param verts an arraylist of vertex objects
- *
- * @see update()
- */
- public void addVertices(ArrayList<Vertex> verts);
-
- /** Check if this region is dirty. A region is marked dirty
- * when new Vertices, Triangles, and or Lines are added after a
- * call to update()
- * @return true if region is Dirty, false otherwise
- *
- * @see update();
- */
- public boolean isDirty();
-
- /** Delete and clean the associated OGL
- * objects
- */
- public void destroy(GL2ES2 gl, RenderState rs);
-
- public AABBox getBounds();
-
- public boolean isFlipped();
-
- /** Set if the y coordinate of the region should be flipped
- * {@code y=-y} used mainly for fonts since they use opposite vertex
- * as origion
- * @param flipped flag if the coordinate is flipped defaults to false.
- */
- public void setFlipped(boolean flipped);
-}
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package com.jogamp.graph.curve;
+
+import java.util.ArrayList;
+
+import jogamp.opengl.Debug;
+
+import com.jogamp.graph.geom.AABBox;
+import com.jogamp.graph.geom.Triangle;
+import com.jogamp.graph.geom.Vertex;
+
+public abstract class Region {
+ public static final boolean DEBUG = Debug.debug("graph.curve");
+ public static final boolean DEBUG_INSTANCE = false;
+
+ /** 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. */
+ public static final int TWO_PASS_RENDERING_BIT = 1 << 0;
+
+ /** Use non uniform weights [0.0 .. 1.9] for curve region rendering.
+ * Otherwise the default weight 1.0 for Bezier curve region rendering is being applied. */
+ public static final int VARIABLE_CURVE_WEIGHT_BIT = 1 << 1;
+
+ public static final int TWO_PASS_DEFAULT_TEXTURE_UNIT = 0;
+
+ private final int renderModes;
+ private boolean dirty = true;
+ protected int numVertices = 0;
+ protected boolean flipped = false;
+ protected final AABBox box = new AABBox();
+ protected ArrayList<Triangle> triangles = new ArrayList<Triangle>();
+ protected ArrayList<Vertex> vertices = new ArrayList<Vertex>();
+
+ public static boolean usesTwoPassRendering(int renderModes) {
+ return 0 != ( renderModes & Region.TWO_PASS_RENDERING_BIT );
+ }
+
+ public static boolean usesVariableCurveWeight(int renderModes) {
+ return 0 != ( renderModes & Region.VARIABLE_CURVE_WEIGHT_BIT );
+ }
+
+ protected Region(int regionRenderModes) {
+ this.renderModes = regionRenderModes;
+ }
+
+ public final int getRenderModes() { return renderModes; }
+
+ public boolean usesTwoPassRendering() { return Region.usesTwoPassRendering(renderModes); }
+ public boolean usesVariableCurveWeight() { return Region.usesVariableCurveWeight(renderModes); }
+
+ /** Get the current number of vertices associated
+ * with this region. This number is not necessary equal to
+ * the OGL bound number of vertices.
+ * @return vertices count
+ */
+ public final int getNumVertices(){
+ return numVertices;
+ }
+
+ /** Adds a list of {@link Triangle} objects to the Region
+ * These triangles are to be binded to OGL objects
+ * on the next call to {@code update}
+ * @param tris an arraylist of triangle objects
+ *
+ * @see update(GL2ES2)
+ */
+ public void addTriangles(ArrayList<Triangle> tris) {
+ triangles.addAll(tris);
+ setDirty(true);
+ }
+
+ /** Adds a list of {@link Vertex} objects to the Region
+ * These vertices are to be binded to OGL objects
+ * on the next call to {@code update}
+ * @param verts an arraylist of vertex objects
+ *
+ * @see update(GL2ES2)
+ */
+ public void addVertices(ArrayList<Vertex> verts) {
+ vertices.addAll(verts);
+ numVertices = vertices.size();
+ setDirty(true);
+ }
+
+ public final AABBox getBounds(){
+ return box;
+ }
+
+ /** Set if the y coordinate of the region should be flipped
+ * {@code y=-y} used mainly for fonts since they use opposite vertex
+ * as origion
+ * @param flipped flag if the coordinate is flipped defaults to false.
+ */
+ public void setFlipped(boolean flipped) {
+ this.flipped = flipped;
+ }
+
+ public final boolean isFlipped() {
+ return flipped;
+ }
+
+ /** Check if this region is dirty. A region is marked dirty
+ * when new Vertices, Triangles, and or Lines are added after a
+ * call to update()
+ * @return true if region is Dirty, false otherwise
+ *
+ * @see update(GL2ES2)
+ */
+ public final boolean isDirty() {
+ return dirty;
+ }
+
+ protected final void setDirty(boolean v) {
+ dirty = v;
+ }
+} \ No newline at end of file
diff --git a/src/jogl/classes/com/jogamp/graph/curve/RegionFactory.java b/src/jogl/classes/com/jogamp/graph/curve/RegionFactory.java
deleted file mode 100755
index 23b318e8a..000000000
--- a/src/jogl/classes/com/jogamp/graph/curve/RegionFactory.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/**
- * Copyright 2010 JogAmp Community. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are
- * permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list
- * of conditions and the following disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * The views and conclusions contained in the software and documentation are those of the
- * authors and should not be interpreted as representing official policies, either expressed
- * or implied, of JogAmp Community.
- */
-package com.jogamp.graph.curve;
-
-import javax.media.opengl.GLProfile;
-
-import com.jogamp.graph.curve.opengl.RenderState;
-
-import jogamp.graph.curve.opengl.VBORegionSPES2;
-import jogamp.graph.curve.opengl.VBORegion2PES2;
-
-/** RegionFactory to create a Context specific Region implementation.
- *
- * @see Region
- */
-public class RegionFactory {
-
- /**
- * Create a Region using the passed curren GL object.
- *
- * <p> In case {@link Region#TWO_PASS} is being requested the default texture unit
- * {@link Region#TWO_PASS_DEFAULT_TEXTURE_UNIT} is being used.</p>
- * @param rs TODO
- * @param type can be one of {@link Region#SINGLE_PASS} or {@link Region#TWO_PASS}
- *
- * @return region
- */
- public static Region create(RenderState rs, int type) {
- if( Region.TWO_PASS == type ){
- return new VBORegion2PES2(rs, Region.TWO_PASS_DEFAULT_TEXTURE_UNIT);
- }
- else{
- return new VBORegionSPES2(rs);
- }
- }
-
- public static Region createSinglePass(RenderState rs) {
- return new VBORegionSPES2(rs);
- }
-
- public static Region createTwoPass(RenderState rs, int textureUnit) {
- return new VBORegion2PES2(rs, textureUnit);
- }
-}
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java
new file mode 100755
index 000000000..20b4d61a1
--- /dev/null
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java
@@ -0,0 +1,125 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package com.jogamp.graph.curve.opengl;
+
+
+import java.util.ArrayList;
+
+import javax.media.opengl.GL2ES2;
+import com.jogamp.opengl.util.PMVMatrix;
+
+import com.jogamp.graph.curve.OutlineShape;
+import com.jogamp.graph.curve.Region;
+import com.jogamp.graph.geom.Triangle;
+import com.jogamp.graph.geom.Vertex;
+import jogamp.graph.curve.opengl.RegionFactory;
+
+/** A Region is the OGL binding of one or more OutlineShapes
+ * Defined by its vertices and generated triangles. The Region
+ * defines the final shape of the OutlineShape(s), which shall produced a shaded
+ * region on the screen.
+ *
+ * Implementations of the Region shall take care of the OGL
+ * binding of the depending on its context, profile.
+ *
+ * @see RegionFactory, OutlineShape
+ */
+public abstract class GLRegion extends Region {
+
+ /** Create an ogl {@link GLRegion} defining the list of {@link OutlineShape}.
+ * Combining the Shapes into single buffers.
+ * @return the resulting Region inclusive the generated region
+ */
+ public static GLRegion create(OutlineShape[] outlineShapes, int renderModes) {
+ final GLRegion region = RegionFactory.create(renderModes);
+
+ int numVertices = region.getNumVertices();
+
+ for(OutlineShape outlineShape:outlineShapes){
+ outlineShape.transformOutlines(OutlineShape.VerticesState.QUADRATIC_NURBS);
+
+ ArrayList<Triangle> triangles = outlineShape.triangulate();
+ region.addTriangles(triangles);
+
+ ArrayList<Vertex> vertices = outlineShape.getVertices();
+ for(Vertex vert:vertices){
+ vert.setId(numVertices++);
+ }
+ region.addVertices(vertices);
+ }
+
+ return region;
+ }
+
+ /**
+ * Create an ogl {@link GLRegion} defining this {@link OutlineShape}
+ * @return the resulting Region.
+ */
+ public static GLRegion create(OutlineShape outlineShape, int renderModes) {
+ final GLRegion region = RegionFactory.create(renderModes);
+
+ outlineShape.transformOutlines(OutlineShape.VerticesState.QUADRATIC_NURBS);
+ ArrayList<Triangle> triangles = (ArrayList<Triangle>) outlineShape.triangulate();
+ ArrayList<Vertex> vertices = (ArrayList<Vertex>) outlineShape.getVertices();
+ region.addVertices(vertices);
+ region.addTriangles(triangles);
+ return region;
+ }
+
+ protected GLRegion(int renderModes) {
+ super(renderModes);
+ }
+
+ /** Updates a graph region by updating the ogl related
+ * objects for use in rendering if {@link #isDirty()}.
+ * <p>Allocates the ogl related data and initializes it the 1st time.<p>
+ * <p>Called by {@link #draw(GL2ES2, RenderState, int, int, int)}.</p>
+ * @param rs TODO
+ */
+ protected abstract void update(GL2ES2 gl, RenderState rs);
+
+ /** Delete and clean the associated OGL
+ * objects
+ */
+ public abstract void destroy(GL2ES2 gl, RenderState rs);
+
+ /** Renders the associated OGL objects specifying
+ * current width/hight of window for multi pass rendering
+ * of the region.
+ * @param matrix current {@link PMVMatrix}.
+ * @param vp_width current screen width
+ * @param vp_height current screen height
+ * @param width texture width for mp rendering
+ */
+ public final void draw(GL2ES2 gl, RenderState rs, int vp_width, int vp_height, int width) {
+ update(gl, rs);
+ drawImpl(gl, rs, vp_width, vp_height, width);
+ }
+
+ protected abstract void drawImpl(GL2ES2 gl, RenderState rs, int vp_width, int vp_height, int width);
+}
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 c7a01b8b8..8624c582c 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java
@@ -27,137 +27,57 @@
*/
package com.jogamp.graph.curve.opengl;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-
import javax.media.opengl.GL2ES2;
+import javax.media.opengl.GLException;
import com.jogamp.graph.curve.OutlineShape;
import com.jogamp.graph.curve.Region;
-import com.jogamp.graph.curve.RegionFactory;
-import com.jogamp.graph.geom.Triangle;
-import com.jogamp.graph.geom.Vertex;
public abstract class RegionRenderer extends Renderer {
- private boolean uniform = true;
/**
* Create a Hardware accelerated Region Renderer.
* @param rs the used {@link RenderState}
- * @param type either {@link com.jogamp.graph.curve.Region#SINGLE_PASS} or {@link com.jogamp.graph.curve.Region#TWO_PASS}
- * @return an instance of Region Renderer
- */
- public static RegionRenderer create(RenderState rs, int type) {
- return new jogamp.graph.curve.opengl.RegionRendererImpl01(rs, type, true);
- }
-
- /** Create a Hardware accelerated Region Renderer.
- * @param rs the used {@link RenderState}
- * @param type either {@link com.jogamp.graph.curve.Region#SINGLE_PASS} or {@link com.jogamp.graph.curve.Region#TWO_PASS}
- * @param uniformWeight flag true uniform weights (equal 1.0f)for off-curve vertex, else otherwise.
+ * @param renderModes bit-field of modes, e.g. {@link Region#VARIABLE_CURVE_WEIGHT_BIT}, {@link Region#TWO_PASS_RENDERING_BIT}
* @return an instance of Region Renderer
*/
- public static RegionRenderer create(RenderState rs, int type, boolean uniformWeight) {
- return new jogamp.graph.curve.opengl.RegionRendererImpl01(rs, type, uniformWeight);
+ public static RegionRenderer create(RenderState rs, int renderModes) {
+ return new jogamp.graph.curve.opengl.RegionRendererImpl01(rs, renderModes);
}
- protected RegionRenderer(RenderState rs, int type, boolean uniformWeight) {
- super(rs, type);
- this.uniform = uniformWeight;
+ protected RegionRenderer(RenderState rs, int renderModes) {
+ super(rs, renderModes);
}
- public boolean isUniformWeight(){
- return uniform;
- }
- /** Render an array of {@link OutlineShape}s combined in one region
- * at the position provided the triangles of the
- * shapes will be generated, if not yet generated
- * @param outlineShapes array of OutlineShapes to Render.
- * @param position the initial translation of the outlineShapes.
- * @param texSize texture size for multipass render *
- * @throws Exception if HwRegionRenderer not initialized
- */
- public abstract void renderOutlineShapes(GL2ES2 gl, OutlineShape[] outlineShapes, float[] position, int texSize);
-
/** Render an {@link OutlineShape} in 3D space at the position provided
* the triangles of the shapes will be generated, if not yet generated
- * @param outlineShape the OutlineShape to Render.
+ * @param region the OutlineShape to Render.
* @param position the initial translation of the outlineShape.
* @param texSize texture size for multipass render
* @throws Exception if HwRegionRenderer not initialized
*/
- public abstract void renderOutlineShape(GL2ES2 gl, OutlineShape outlineShape, float[] position, int texSize);
-
- protected HashMap<Integer, Region> regions = new HashMap<Integer, Region>();
-
- public void flushCache(GL2ES2 gl) {
- Iterator<Region> iterator = regions.values().iterator();
- while(iterator.hasNext()){
- Region region = iterator.next();
- region.destroy(gl, rs);
+ public final void draw(GL2ES2 gl, Region region, float[] position, int texSize) {
+ if(!isInitialized()) {
+ throw new GLException("RegionRenderer: not initialized!");
}
- regions.clear();
- }
-
- @Override
- protected void disposeImpl(GL2ES2 gl) {
- // fluchCache(gl) already called
- }
-
- /**
- * Create an ogl {@link Region} defining this {@link OutlineShape}
- * @return the resulting Region.
- */
- protected Region createRegion(GL2ES2 gl, OutlineShape outlineShape) {
- Region region = RegionFactory.create(rs, renderType);
-
- outlineShape.transformOutlines(OutlineShape.VerticesState.QUADRATIC_NURBS);
- ArrayList<Triangle> triangles = (ArrayList<Triangle>) outlineShape.triangulate();
- ArrayList<Vertex> vertices = (ArrayList<Vertex>) outlineShape.getVertices();
- region.addVertices(vertices);
- region.addTriangles(triangles);
-
- region.update(gl);
- return region;
+ if( !areRenderModesCompatible(region) ) {
+ throw new GLException("Incompatible render modes, : region modes "+region.getRenderModes()+
+ " doesn't contain renderer modes "+this.getRenderModes());
+ }
+ drawImpl(gl, region, position, texSize);
}
- /** Create an ogl {@link Region} defining the list of {@link OutlineShape}.
- * Combining the Shapes into single buffers.
- * @return the resulting Region inclusive the generated region
+ /**
+ * Usually just dispatched the draw call to the Region's draw implementation,
+ * e.g. {@link com.jogamp.graph.curve.opengl.GLRegion#draw(GL2ES2, RenderState, int, int, int) GLRegion#draw(GL2ES2, RenderState, int, int, int)}.
*/
- protected Region createRegion(GL2ES2 gl, OutlineShape[] outlineShapes) {
- Region region = RegionFactory.create(rs, renderType);
-
- int numVertices = region.getNumVertices();
-
- for(OutlineShape outlineShape:outlineShapes){
- outlineShape.transformOutlines(OutlineShape.VerticesState.QUADRATIC_NURBS);
+ protected abstract void drawImpl(GL2ES2 gl, Region region, float[] position, int texSize);
- ArrayList<Triangle> triangles = outlineShape.triangulate();
- region.addTriangles(triangles);
-
- ArrayList<Vertex> vertices = outlineShape.getVertices();
- for(Vertex vert:vertices){
- vert.setId(numVertices++);
- }
- region.addVertices(vertices);
- }
-
- region.update(gl);
- return region;
+ @Override
+ protected void destroyImpl(GL2ES2 gl) {
+ // nop
}
- protected static int getHashCode(OutlineShape outlineShape){
- return outlineShape.hashCode();
- }
- protected static int getHashCode(OutlineShape[] outlineShapes){
- int hashcode = 0;
- for(OutlineShape outlineShape:outlineShapes){
- hashcode += getHashCode(outlineShape);
- }
- return hashcode;
- }
-} \ No newline at end of file
+}
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java
index aea2197d8..e45cacbf6 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java
@@ -30,87 +30,86 @@ package com.jogamp.graph.curve.opengl;
import java.nio.FloatBuffer;
import javax.media.opengl.GL2ES2;
-import javax.media.opengl.GLUniformData;
+import javax.media.opengl.GLException;
import javax.media.opengl.fixedfunc.GLMatrixFunc;
-import jogamp.graph.curve.opengl.RenderStateImpl;
+import com.jogamp.opengl.util.glsl.ShaderState;
+import com.jogamp.opengl.util.PMVMatrix;
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;
public abstract class Renderer {
protected static final boolean DEBUG = Region.DEBUG;
- protected static final boolean DEBUG_INSTANCE = Region.DEBUG_INSTANCE;
+ protected static final boolean DEBUG_INSTANCE = Region.DEBUG_INSTANCE;
- public static RenderState createRenderState(ShaderState st, Vertex.Factory<? extends Vertex> pointFactory, PMVMatrix pmvMatrix) {
- return new RenderStateImpl(st, pointFactory, pmvMatrix);
+ public static boolean isWeightValid(float v) {
+ return 0.0f <= v && v <= 1.9f ;
}
- public static RenderState createRenderState(ShaderState st, Vertex.Factory<? extends Vertex> pointFactory) {
- return new RenderStateImpl(st, pointFactory);
- }
+ protected final int renderModes;
+ protected int vp_width;
+ protected int vp_height;
+ protected boolean initialized;
+ protected final RenderState rs;
+ private boolean vboSupported = false;
+
+ public final boolean isInitialized() { return initialized; }
+
+ public final int getWidth() { return vp_width; }
+ public final int getHeight() { return vp_height; }
+
+ public float getWeight() { return rs.getWeight().floatValue(); }
+ public float getAlpha() { return rs.getAlpha().floatValue(); }
+ public final PMVMatrix getMatrix() { return rs.pmvMatrix(); }
/**
* Implementation shall load, compile and link the shader program and leave it active.
- * @param gl
+ * @param gl referencing the current GLContext to which the ShaderState is bound to
* @return
*/
protected abstract boolean initShaderProgram(GL2ES2 gl);
- protected abstract void disposeImpl(GL2ES2 gl);
+ protected abstract void destroyImpl(GL2ES2 gl);
- /**
- * Flushes all cached data
- * @see #destroy(GL2ES2)
- */
- public abstract void flushCache(GL2ES2 gl);
-
- protected final RenderState rs;
- public final int renderType;
-
- protected int vp_width = 0;
- protected int vp_height = 0;
-
- private boolean vboSupported = false;
- private boolean initialized = false;
-
/**
* @param rs the used {@link RenderState}
- * @param renderType either {@link com.jogamp.graph.curve.Region#SINGLE_PASS} or {@link com.jogamp.graph.curve.Region#TWO_PASS}
+ * @param renderModes bit-field of modes
*/
- protected Renderer(RenderState rs, int renderType) {
+ protected Renderer(RenderState rs, int renderModes) {
this.rs = rs;
- this.renderType = renderType;
+ this.renderModes = renderModes;
}
- public Vertex.Factory<? extends Vertex> getFactory() { return rs.getPointFactory(); }
+ public final int getRenderModes() {
+ return renderModes;
+ }
- public final boolean isInitialized() { return initialized; }
+ public boolean usesVariableCurveWeight() { return Region.usesVariableCurveWeight(renderModes); }
+
+ /**
+ * @return true if Region's renderModes contains all bits as this Renderer's renderModes
+ * except {@link Region#VARIABLE_CURVE_WEIGHT_BIT}, otherwise false.
+ */
+ public final boolean areRenderModesCompatible(Region region) {
+ final int cleanRenderModes = getRenderModes() & ( Region.VARIABLE_CURVE_WEIGHT_BIT );
+ return cleanRenderModes == ( region.getRenderModes() & cleanRenderModes );
+ }
public final boolean isVBOSupported() { return vboSupported; }
- public final int getRenderType() { return renderType; }
-
- public final int getWidth() { return vp_width; }
- public final int getHeight() { return vp_height; }
-
/**
- * Initialize shader and bindings for GPU based rendering bound to the given GL object's GLContext.
- *
- * Leaves the renderer enabled, ie ShaderState.
+ * Initialize shader and bindings for GPU based rendering bound to the given GL object's GLContext
+ * if not initialized yet.
+ * <p>Leaves the renderer enabled, ie ShaderState.</p>
+ * <p>Shall be called by a {@code draw()} method, e.g. {@link RegionRenderer#draw(GL2ES2, Region, float[], int)}</p>
*
* @param gl referencing the current GLContext to which the ShaderState is bound to
- *
- * @return true if succeeded, false otherwise
+ * @throws GLException if initialization failed
*/
- public boolean init(GL2ES2 gl) {
+ public final void init(GL2ES2 gl) throws GLException {
if(initialized){
- if(DEBUG) {
- System.err.println("TextRenderer: Already initialized!");
- }
- return true;
+ return;
}
vboSupported = gl.isFunctionAvailable("glGenBuffers") &&
gl.isFunctionAvailable("glBindBuffer") &&
@@ -124,7 +123,7 @@ public abstract class Renderer {
}
if(!vboSupported){
- return false;
+ throw new GLException("VBO not supported");
}
rs.attachTo(gl);
@@ -134,40 +133,30 @@ public abstract class Renderer {
initialized = initShaderProgram(gl);
if(!initialized) {
- return false;
+ throw new GLException("Shader initialization failed");
}
if(!rs.getShaderState().uniform(gl, rs.getPMVMatrix())) {
- if(DEBUG){
- System.err.println("Error setting PMVMatrix in shader: "+rs.getShaderState());
- }
- return false;
+ throw new GLException("Error setting PMVMatrix in shader: "+rs.getShaderState());
}
if(!rs.getShaderState().uniform(gl, rs.getWeight())) {
- if(DEBUG){
- System.err.println("Error setting weight in shader: "+rs.getShaderState());
- }
- return false;
+ throw new GLException("Error setting weight in shader: "+rs.getShaderState());
}
if(!rs.getShaderState().uniform(gl, rs.getAlpha())) {
- if(DEBUG){
- System.err.println("Error setting global alpha in shader: "+rs.getShaderState());
- }
- return false;
+ throw new GLException("Error setting global alpha in shader: "+rs.getShaderState());
}
if(!rs.getShaderState().uniform(gl, rs.getColorStatic())) {
- if(DEBUG){
- System.err.println("Error setting global color in shader: "+rs.getShaderState());
- }
- return false;
+ throw new GLException("Error setting global color in shader: "+rs.getShaderState());
}
-
- return initialized;
}
+ public final void flushCache(GL2ES2 gl) {
+ // FIXME: REMOVE !
+ }
+
public void destroy(GL2ES2 gl) {
if(!initialized){
if(DEBUG_INSTANCE) {
@@ -176,8 +165,7 @@ public abstract class Renderer {
return;
}
rs.getShaderState().useProgram(gl, false);
- flushCache(gl);
- disposeImpl(gl);
+ destroyImpl(gl);
rs.destroy(gl);
initialized = false;
}
@@ -189,24 +177,16 @@ public abstract class Renderer {
rs.getShaderState().useProgram(gl, enable);
}
- public float getWeight() {
- return rs.getWeight().floatValue();
- }
-
public void setWeight(GL2ES2 gl, float v) {
- if(v > 1.9f || v < 0.0f)
+ if( !isWeightValid(v) ) {
throw new IllegalArgumentException("Weight out of range");
-
+ }
rs.getWeight().setData(v);
if(null != gl && rs.getShaderState().inUse()) {
rs.getShaderState().uniform(gl, rs.getWeight());
}
}
- public float getAlpha() {
- return rs.getAlpha().floatValue();
- }
-
public void setAlpha(GL2ES2 gl, float alpha_t) {
rs.getAlpha().setData(alpha_t);
if(null != gl && rs.getShaderState().inUse()) {
@@ -232,8 +212,6 @@ public abstract class Renderer {
}
}
- public final PMVMatrix getMatrix() { return rs.pmvMatrix(); }
-
public void rotate(GL2ES2 gl, float angle, float x, float y, float z) {
rs.pmvMatrix().glRotatef(angle, x, y, z);
updateMatrix(gl);
@@ -284,4 +262,19 @@ public abstract class Renderer {
return true;
}
+ protected String getVertexShaderName(GL2ES2 gl) {
+ return "curverenderer01" + getShaderGLVersionSuffix(gl);
+ }
+
+ protected String getFragmentShaderName(GL2ES2 gl) {
+ return "curverenderer01" + getShaderGLVersionSuffix(gl);
+ }
+
+ protected String getShaderGLVersionSuffix(GL2ES2 gl) {
+ if(gl.isGLES2()) {
+ return "-es2";
+ }
+ return "-gl2";
+ }
+
} \ No newline at end of file
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java
index 75f3e017a..073afe9bd 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java
@@ -39,13 +39,16 @@ import jogamp.graph.font.FontInt;
import jogamp.graph.geom.plane.AffineTransform;
import jogamp.graph.geom.plane.Path2D;
+import com.jogamp.graph.curve.OutlineShape;
import com.jogamp.graph.font.Font;
+import com.jogamp.graph.geom.Vertex;
+import com.jogamp.graph.geom.Vertex.Factory;
public abstract class TextRenderer extends Renderer {
/**
* Create a Hardware accelerated Text Renderer.
* @param rs the used {@link RenderState}
- * @param renderType either {@link com.jogamp.graph.curve.Region#SINGLE_PASS} or {@link com.jogamp.graph.curve.Region#TWO_PASS}
+ * @param renderModes either {@link com.jogamp.graph.curve.opengl.GLRegion#SINGLE_PASS} or {@link com.jogamp.graph.curve.Region#TWO_PASS_RENDERING_BIT}
*/
public static TextRenderer create(RenderState rs, int type) {
return new jogamp.graph.curve.opengl.TextRendererImpl01(rs, type);
@@ -66,8 +69,8 @@ public abstract class TextRenderer extends Renderer {
* @param texSize texture size for multipass render
* @throws Exception if TextRenderer not initialized
*/
- public abstract void renderString3D(GL2ES2 gl, Font font,
- String str, float[] position, int fontSize, int texSize);
+ public abstract void drawString3D(GL2ES2 gl, Font font,
+ String str, float[] position, int fontSize, int texSize);
/**Create the resulting {@link GlyphString} that represents
* the String wrt to the font.
@@ -80,18 +83,12 @@ public abstract class TextRenderer extends Renderer {
if(DEBUG_INSTANCE) {
System.err.println("createString: "+getCacheSize()+"/"+getCacheLimit()+" - "+Font.NAME_UNIQUNAME + " - " + str + " - " + size);
}
- AffineTransform affineTransform = new AffineTransform(rs.getPointFactory());
-
- Path2D[] paths = new Path2D[str.length()];
- ((FontInt)font).getPaths(str, size, affineTransform, paths);
-
- GlyphString glyphString = new GlyphString(font.getName(Font.NAME_UNIQUNAME), str);
- glyphString.createfromFontPath(rs.getPointFactory(), paths, affineTransform);
- glyphString.generateRegion(gl, rs, renderType);
-
+ final GlyphString glyphString = GlyphString.createString(null, rs.getVertexFactory(), font, size, str);
+ glyphString.createRegion(gl, renderModes);
return glyphString;
}
+ /** FIXME
public void flushCache(GL2ES2 gl) {
Iterator<GlyphString> iterator = stringCacheMap.values().iterator();
while(iterator.hasNext()){
@@ -100,11 +97,18 @@ public abstract class TextRenderer extends Renderer {
}
stringCacheMap.clear();
stringCacheArray.clear();
- }
+ } */
@Override
- protected void disposeImpl(GL2ES2 gl) {
+ protected void destroyImpl(GL2ES2 gl) {
// fluchCache(gl) already called
+ Iterator<GlyphString> iterator = stringCacheMap.values().iterator();
+ while(iterator.hasNext()){
+ GlyphString glyphString = iterator.next();
+ glyphString.destroy(gl, rs);
+ }
+ stringCacheMap.clear();
+ stringCacheArray.clear();
}
/**
@@ -181,7 +185,9 @@ public abstract class TextRenderer extends Renderer {
}
protected final String getKey(Font font, String str, int fontSize) {
- return font.getName(Font.NAME_UNIQUNAME) + "." + str.hashCode() + "." + fontSize;
+ final StringBuilder sb = new StringBuilder();
+ return font.getName(sb, Font.NAME_UNIQUNAME)
+ .append(".").append(str.hashCode()).append(".").append(fontSize).toString();
}
/** Default cache limit, see {@link #setCacheLimit(int)} */