summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes
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
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')
-rw-r--r--[-rwxr-xr-x]src/jogl/classes/com/jogamp/graph/curve/Region.java274
-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
-rwxr-xr-xsrc/jogl/classes/jogamp/graph/curve/opengl/RegionFactory.java (renamed from src/jogl/classes/com/jogamp/graph/curve/RegionFactory.java)39
-rwxr-xr-xsrc/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java60
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/RenderStateImpl.java57
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java12
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/UniformNames.java1
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-es2.fp6
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-es2.vp6
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-gl2.fp6
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-gl2.vp6
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-xxx.fp (renamed from src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.fp)16
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-xxx.vp (renamed from src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.vp)9
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02-es2.fp6
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02-gl2.fp6
-rw-r--r--[-rwxr-xr-x]src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02-xxx.fp (renamed from src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02.fp)16
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl4
20 files changed, 479 insertions, 487 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/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)} */
diff --git a/src/jogl/classes/com/jogamp/graph/curve/RegionFactory.java b/src/jogl/classes/jogamp/graph/curve/opengl/RegionFactory.java
index 23b318e8a..b5a89b40a 100755
--- a/src/jogl/classes/com/jogamp/graph/curve/RegionFactory.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/RegionFactory.java
@@ -25,45 +25,40 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of JogAmp Community.
*/
-package com.jogamp.graph.curve;
+package jogamp.graph.curve.opengl;
-import javax.media.opengl.GLProfile;
-
-import com.jogamp.graph.curve.opengl.RenderState;
-
-import jogamp.graph.curve.opengl.VBORegionSPES2;
-import jogamp.graph.curve.opengl.VBORegion2PES2;
+import com.jogamp.graph.curve.Region;
+import com.jogamp.graph.curve.opengl.GLRegion;
/** RegionFactory to create a Context specific Region implementation.
*
- * @see Region
+ * @see GLRegion
*/
public class RegionFactory {
/**
- * Create a Region using the passed curren GL object.
+ * Create a Region using the passed render mode
*
- * <p> In case {@link Region#TWO_PASS} is being requested the default texture unit
+ * <p> In case {@link Region#TWO_PASS_RENDERING_BIT} 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
+ * @param rs the RenderState to be used
+ * @param renderModes bit-field of modes, e.g. {@link Region#VARIABLE_CURVE_WEIGHT_BIT}, {@link Region#TWO_PASS_RENDERING_BIT}
*/
- public static Region create(RenderState rs, int type) {
- if( Region.TWO_PASS == type ){
- return new VBORegion2PES2(rs, Region.TWO_PASS_DEFAULT_TEXTURE_UNIT);
+ public static GLRegion create(int renderModes) {
+ if( 0 != ( Region.TWO_PASS_RENDERING_BIT & renderModes ) ){
+ return new VBORegion2PES2(renderModes, Region.TWO_PASS_DEFAULT_TEXTURE_UNIT);
}
else{
- return new VBORegionSPES2(rs);
+ return new VBORegionSPES2(renderModes);
}
}
-
- public static Region createSinglePass(RenderState rs) {
- return new VBORegionSPES2(rs);
+
+ public static GLRegion createSinglePass(int renderModes) {
+ return new VBORegionSPES2(renderModes);
}
- public static Region createTwoPass(RenderState rs, int textureUnit) {
- return new VBORegion2PES2(rs, textureUnit);
+ public static GLRegion createTwoPass(int renderModes, int textureUnit) {
+ return new VBORegion2PES2(renderModes, textureUnit);
}
}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java b/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java
index 09e94d618..dcfe3cae0 100755
--- a/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java
@@ -32,8 +32,8 @@ import javax.media.opengl.GLException;
import jogamp.graph.curve.opengl.shader.AttributeNames;
-import com.jogamp.graph.curve.OutlineShape;
import com.jogamp.graph.curve.Region;
+import com.jogamp.graph.curve.opengl.GLRegion;
import com.jogamp.graph.curve.opengl.RegionRenderer;
import com.jogamp.graph.curve.opengl.RenderState;
import com.jogamp.opengl.util.glsl.ShaderCode;
@@ -41,29 +41,26 @@ import com.jogamp.opengl.util.glsl.ShaderProgram;
import com.jogamp.opengl.util.glsl.ShaderState;
public class RegionRendererImpl01 extends RegionRenderer {
- public RegionRendererImpl01(RenderState rs, int type, boolean uniform) {
- super(rs, type, uniform);
+ public RegionRendererImpl01(RenderState rs, int renderModes) {
+ super(rs, renderModes);
}
- private String getVertexShaderName(){
- return "curverenderer01";
- }
-
- private String getFragmentShaderName(){
- if(!isUniformWeight()){
- return "curverenderer02";
+ @Override
+ protected String getFragmentShaderName(GL2ES2 gl) {
+ if(Region.usesVariableCurveWeight(renderModes)){
+ return "curverenderer02" + getShaderGLVersionSuffix(gl);
}
- return "curverenderer01";
+ return "curverenderer01" + getShaderGLVersionSuffix(gl);
}
protected boolean initShaderProgram(GL2ES2 gl) {
final ShaderState st = rs.getShaderState();
ShaderCode rsVp = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, 1, RegionRendererImpl01.class,
- "shader", "shader/bin", getVertexShaderName());
+ "shader", "shader/bin", getVertexShaderName(gl));
ShaderCode rsFp = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, 1, RegionRendererImpl01.class,
- "shader", "shader/bin", getFragmentShaderName());
+ "shader", "shader/bin", getFragmentShaderName(gl));
ShaderProgram sp = new ShaderProgram();
sp.add(rsVp);
@@ -86,39 +83,12 @@ public class RegionRendererImpl01 extends RegionRenderer {
}
@Override
- protected void disposeImpl(GL2ES2 gl) {
- super.disposeImpl(gl);
- }
-
-
- @Override
- public void renderOutlineShape(GL2ES2 gl, OutlineShape outlineShape, float[] position, int texSize) {
- if(!isInitialized()){
- throw new GLException("RegionRendererImpl01: not initialized!");
- }
- int hashCode = getHashCode(outlineShape);
- Region region = regions.get(hashCode);
-
- if(null == region) {
- region = createRegion(gl, outlineShape);
- regions.put(hashCode, region);
- }
- region.render(gl, rs, vp_width, vp_height, texSize);
+ protected void destroyImpl(GL2ES2 gl) {
+ super.destroyImpl(gl);
}
-
+
@Override
- public void renderOutlineShapes(GL2ES2 gl, OutlineShape[] outlineShapes, float[] position, int texSize) {
- if(!isInitialized()){
- throw new GLException("RegionRendererImpl01: not initialized!");
- }
-
- int hashCode = getHashCode(outlineShapes);
- Region region = regions.get(hashCode);
-
- if(null == region) {
- region = createRegion(gl, outlineShapes);
- regions.put(hashCode, region);
- }
- region.render(gl, rs, vp_width, vp_height, texSize);
+ protected void drawImpl(GL2ES2 gl, Region region, float[] position, int texSize) {
+ ((GLRegion)region).draw(gl, rs, vp_width, vp_height, texSize);
}
}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/RenderStateImpl.java b/src/jogl/classes/jogamp/graph/curve/opengl/RenderStateImpl.java
index 350c77d98..996ab4c02 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/RenderStateImpl.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/RenderStateImpl.java
@@ -31,23 +31,15 @@ import java.nio.FloatBuffer;
import javax.media.opengl.GL2ES2;
import javax.media.opengl.GLUniformData;
-import javax.media.opengl.fixedfunc.GLMatrixFunc;
import jogamp.graph.curve.opengl.shader.UniformNames;
-import com.jogamp.common.os.Platform;
import com.jogamp.graph.curve.opengl.RenderState;
import com.jogamp.graph.geom.Vertex;
import com.jogamp.opengl.util.PMVMatrix;
import com.jogamp.opengl.util.glsl.ShaderState;
-public class RenderStateImpl implements RenderState {
-
- private final ShaderState st;
- private final Vertex.Factory<? extends Vertex> pointFactory;
- private final PMVMatrix pmvMatrix;
- private final GLUniformData gcu_PMVMatrix;
-
+public class RenderStateImpl extends RenderState {
/**
* weight is equivalent to the
* global off-curve vertex weight.
@@ -62,11 +54,7 @@ public class RenderStateImpl implements RenderState {
}
public RenderStateImpl(ShaderState st, Vertex.Factory<? extends Vertex> pointFactory, PMVMatrix pmvMatrix) {
- this.st = st;
- this.pointFactory = pointFactory;
- this.pmvMatrix = pmvMatrix;
- this.gcu_PMVMatrix = new GLUniformData(UniformNames.gcu_PMVMatrix, 4, 4, pmvMatrix.glGetPMvMatrixf());
- st.ownUniform(gcu_PMVMatrix);
+ super(st, pointFactory, pmvMatrix);
gcu_Weight = new GLUniformData(UniformNames.gcu_Weight, 1.0f);
st.ownUniform(gcu_PMVMatrix);
@@ -80,53 +68,12 @@ public class RenderStateImpl implements RenderState {
public RenderStateImpl(ShaderState st, Vertex.Factory<? extends Vertex> pointFactory) {
this(st, pointFactory, new PMVMatrix());
-
- pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
- pmvMatrix.glLoadIdentity();
- pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
- pmvMatrix.glLoadIdentity();
- pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
- pmvMatrix.glLoadIdentity();
}
- public final ShaderState getShaderState() { return st; }
- public final Vertex.Factory<? extends Vertex> getPointFactory () { return pointFactory; }
- public final PMVMatrix pmvMatrix() { return pmvMatrix; }
- public final GLUniformData getPMVMatrix() { return gcu_PMVMatrix; }
public final GLUniformData getWeight() { return gcu_Weight; }
public final GLUniformData getAlpha() { return gcu_Alpha; }
public final GLUniformData getColorStatic() { return gcu_ColorStatic; }
//public final GLUniformData getStrength() { return gcu_Strength; }
- public void destroy(GL2ES2 gl) {
- st.destroy(gl);
- }
-
- public final RenderState attachTo(GL2ES2 gl) {
- return (RenderState) gl.getContext().attachObject(RenderState.class.getName(), this);
- }
- public final boolean detachFrom(GL2ES2 gl) {
- RenderState _rs = (RenderState) gl.getContext().getAttachedObject(RenderState.class.getName());
- if(_rs == this) {
- gl.getContext().detachObject(RenderState.class.getName());
- return true;
- }
- return false;
- }
-
- public StringBuilder toString(StringBuilder sb) {
- if(null==sb) {
- sb = new StringBuilder();
- }
-
- sb.append("RenderState[");
- st.toString(sb).append(Platform.getNewline());
- sb.append("]");
-
- return sb;
- }
- public String toString() {
- return toString(null).toString();
- }
}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java b/src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java
index 257d05fca..5ed3529bf 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java
@@ -48,11 +48,11 @@ public class TextRendererImpl01 extends TextRenderer {
@Override
protected boolean initShaderProgram(GL2ES2 gl){
final ShaderState st = rs.getShaderState();
-
+
ShaderCode rsVp = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, 1, TextRendererImpl01.class,
- "shader", "shader/bin", "curverenderer01");
+ "shader", "shader/bin", getVertexShaderName(gl));
ShaderCode rsFp = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, 1, TextRendererImpl01.class,
- "shader", "shader/bin", "curverenderer01");
+ "shader", "shader/bin", getFragmentShaderName(gl));
ShaderProgram sp = new ShaderProgram();
sp.add(rsVp);
@@ -75,12 +75,12 @@ public class TextRendererImpl01 extends TextRenderer {
}
@Override
- protected void disposeImpl(GL2ES2 gl) {
- super.disposeImpl(gl);
+ protected void destroyImpl(GL2ES2 gl) {
+ super.destroyImpl(gl);
}
@Override
- public void renderString3D(GL2ES2 gl, Font font, String str, float[] position, int fontSize, int texSize) {
+ public void drawString3D(GL2ES2 gl, Font font, String str, float[] position, int fontSize, int texSize) {
if(!isInitialized()){
throw new GLException("TextRendererImpl01: not initialized!");
}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/UniformNames.java b/src/jogl/classes/jogamp/graph/curve/opengl/shader/UniformNames.java
index bb6ff987d..ab6e0dc6e 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/UniformNames.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/UniformNames.java
@@ -6,4 +6,5 @@ public class UniformNames {
public static final String gcu_Alpha = "gcu_Alpha";
public static final String gcu_Weight = "gcu_Weight";
public static final String gcu_TextureUnit = "gcu_TextureUnit";
+ public static final String gcu_TextureSize = "gcu_TextureSize";
}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-es2.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-es2.fp
new file mode 100644
index 000000000..0131f38b0
--- /dev/null
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-es2.fp
@@ -0,0 +1,6 @@
+//Copyright 2010 JogAmp Community. All rights reserved.
+
+#version 100
+
+#include curverenderer01-xxx.fp
+
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-es2.vp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-es2.vp
new file mode 100644
index 000000000..8c0585b1d
--- /dev/null
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-es2.vp
@@ -0,0 +1,6 @@
+//Copyright 2010 JogAmp Community. All rights reserved.
+
+#version 100
+
+#include curverenderer01-xxx.vp
+
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-gl2.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-gl2.fp
new file mode 100644
index 000000000..ba4c7daa0
--- /dev/null
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-gl2.fp
@@ -0,0 +1,6 @@
+//Copyright 2010 JogAmp Community. All rights reserved.
+
+#version 110
+
+#include curverenderer01-xxx.fp
+
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-gl2.vp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-gl2.vp
new file mode 100644
index 000000000..1ac33e8b3
--- /dev/null
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-gl2.vp
@@ -0,0 +1,6 @@
+//Copyright 2010 JogAmp Community. All rights reserved.
+
+#version 110
+
+#include curverenderer01-xxx.vp
+
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-xxx.fp
index b3693ec88..e50aea04d 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.fp
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-xxx.fp
@@ -1,14 +1,5 @@
//Copyright 2010 JogAmp Community. All rights reserved.
-/**
- * AMD complains: #version must occur before any other statement in the program
-#ifdef GL_ES
- #version 100
-#else
- #version 110
-#endif
- */
-
#include uniforms.glsl
#include varyings.glsl
@@ -29,7 +20,12 @@ void main (void)
vec2 dfx = dFdx(gcv_TexCoord);
vec2 dfy = dFdy(gcv_TexCoord);
- vec2 size = 1.0/textureSize(gcu_TextureUnit,0); //version 130 - FIXME: replace with uniform value
+ vec2 size;
+ //#if __VERSION__ < 130
+ size = 1.0/gcu_TextureSize;
+ //#else
+ // size = 1.0/textureSize(gcu_TextureUnit,0);
+ //#endif
rtex -= 5.0;
vec4 t = texture2D(gcu_TextureUnit, rtex)* 0.18;
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.vp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-xxx.vp
index fe74caffb..64a6835ec 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.vp
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-xxx.vp
@@ -1,14 +1,5 @@
//Copyright 2010 JogAmp Community. All rights reserved.
-/**
- * AMD complains: #version must occur before any other statement in the program
-#ifdef GL_ES
- #version 100
-#else
- #version 110
-#endif
- */
-
#include uniforms.glsl
#include attributes.glsl
#include varyings.glsl
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02-es2.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02-es2.fp
new file mode 100644
index 000000000..358e68b81
--- /dev/null
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02-es2.fp
@@ -0,0 +1,6 @@
+//Copyright 2010 JogAmp Community. All rights reserved.
+
+#version 100
+
+#include curverenderer02-xxx.fp
+
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02-gl2.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02-gl2.fp
new file mode 100644
index 000000000..d7fe31a08
--- /dev/null
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02-gl2.fp
@@ -0,0 +1,6 @@
+//Copyright 2010 JogAmp Community. All rights reserved.
+
+#version 110
+
+#include curverenderer02-xxx.fp
+
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02-xxx.fp
index e3d5bc074..c6a3c56c8 100755..100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02.fp
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02-xxx.fp
@@ -1,11 +1,4 @@
//Copyright 2010 JogAmp Community. All rights reserved.
-/**
-#ifdef GL_ES
- #version 100
-#else
- #version 110
-#endif
- */
#include uniforms.glsl
#include varyings.glsl
@@ -27,7 +20,12 @@ void main (void)
vec2 dfx = dFdx(gcv_TexCoord);
vec2 dfy = dFdy(gcv_TexCoord);
- vec2 size = 1.0/textureSize(gcu_TextureUnit,0); //version 130 - FIXME: replace with uniform value
+ // vec2 size;
+ //#if __VERSION__ < 130
+ vec2 size = 1.0/gcu_TextureSize;
+ //#else
+ // size = 1.0/textureSize(gcu_TextureUnit,0);
+ //#endif
rtex -= 5.0;
vec4 t = texture2D(gcu_TextureUnit, rtex)* 0.18;
@@ -79,7 +77,7 @@ void main (void)
float aph = 2.0 - 2.0*w;
float gd = (aph*rtex.x*rtex.x + 2.0*rtex.x + 1.0)*(aph*rtex.x*rtex.x + 2.0*rtex.x + 1.0);
- vec2 f = vec2((dtx.y - (w*dtx.x*(1.0 - 2*rtex.x))/gd), (dty.y - (w*dty.x*(1.0 - 2*rtex.x))/gd));
+ vec2 f = vec2((dtx.y - (w*dtx.x*(1.0 - 2.0*rtex.x))/gd), (dty.y - (w*dty.x*(1.0 - 2.0*rtex.x))/gd));
float d = position/(length(f));
float a = (0.5 - d * sign(gcv_TexCoord.y));
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 332edd02b..6b3d846a3 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl
@@ -12,6 +12,10 @@ uniform HIGHP float gcu_Alpha;
uniform HIGHP float gcu_Weight;
uniform sampler2D gcu_TextureUnit;
+// #if __VERSION__ < 130
+ uniform HIGHP vec2 gcu_TextureSize;
+// #endif
+
// uniform HIGHP mat3 gcu_NormalMatrix; // transpose(inverse(ModelView)).3x3
// uniform LOWP int gcu_ColorEnabled;
// uniform LOWP int gcu_TexCoordEnabled[MAX_TEXTURE_UNITS];