aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-04-23 06:12:10 +0200
committerSven Gothel <[email protected]>2011-04-23 06:12:10 +0200
commit48201a6ea6471eb5951edb735b36156ab3410a15 (patch)
treeb22314430e78ee9269f4fcb358b9b5a7dc8d1de7 /src/jogl
parent54f58c0cb990eb2b4fc8c3be785cc47bde575f37 (diff)
Refactored graph: Reduce/remove data copy/recreation; Shader cleanup
- Pass the current GL context object where it's required - Introduce RenderState (which has ShaderState) to acquire/change shader related data (Region) - Shader Cleanup: User import for common stuff; use req. version - Reduce/remove data copy/recreation in *Region implementation - UI/RIButton: Use defaults I like :)
Diffstat (limited to 'src/jogl')
-rwxr-xr-xsrc/jogl/classes/com/jogamp/graph/curve/Region.java26
-rwxr-xr-xsrc/jogl/classes/com/jogamp/graph/curve/RegionFactory.java35
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java70
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java56
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java251
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java98
-rw-r--r--src/jogl/classes/com/jogamp/graph/geom/AABBox.java51
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java10
-rwxr-xr-xsrc/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java129
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/RenderStateImpl.java126
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java130
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java220
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java95
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/AttributeNames.java18
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/UniformNames.java10
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/attributes.glsl12
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/consts.glsl10
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.fp116
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.vp20
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/precision.glsl14
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl21
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/varyings.glsl13
-rw-r--r--src/jogl/classes/jogamp/graph/curve/text/GlyphString.java36
23 files changed, 937 insertions, 630 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/curve/Region.java b/src/jogl/classes/com/jogamp/graph/curve/Region.java
index 926ab5467..a759546ba 100755
--- a/src/jogl/classes/com/jogamp/graph/curve/Region.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/Region.java
@@ -29,6 +29,9 @@ 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;
@@ -48,33 +51,20 @@ import com.jogamp.opengl.util.PMVMatrix;
*/
public interface Region {
public static final boolean DEBUG = Debug.debug("graph.curve");
-
- /** The vertices index in an OGL object
- */
- public static int VERTEX_ATTR_IDX = 0;
- public static String VERTEX_ATTR_NAME = "v_position";
-
- /** The Texture Coord index in an OGL object
- */
- public static int TEXCOORD_ATTR_IDX = 1;
- public static String TEXCOORD_ATTR_NAME = "texCoord";
-
- /** The color index in an OGL object
- */
- public static int COLOR_ATTR_IDX = 2;
- public static String COLOR_ATTR_NAME = "v_color";
+ 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();
+ public void update(GL2ES2 gl);
/** Renders the associated OGL objects specifying
* current width/hight of window for multi pass rendering
@@ -86,7 +76,7 @@ public interface Region {
*
* @see update()
*/
- public void render(PMVMatrix matrix, int vp_width, int vp_height, int width);
+ 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
@@ -127,7 +117,7 @@ public interface Region {
/** Delete and clean the associated OGL
* objects
*/
- public void destroy();
+ public void destroy(GL2ES2 gl);
public AABBox getBounds();
diff --git a/src/jogl/classes/com/jogamp/graph/curve/RegionFactory.java b/src/jogl/classes/com/jogamp/graph/curve/RegionFactory.java
index 91bbbd787..23b318e8a 100755
--- a/src/jogl/classes/com/jogamp/graph/curve/RegionFactory.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/RegionFactory.java
@@ -27,36 +27,43 @@
*/
package com.jogamp.graph.curve;
-import javax.media.opengl.GLContext;
-import javax.media.opengl.GLException;
+import javax.media.opengl.GLProfile;
-import com.jogamp.opengl.util.glsl.ShaderState;
+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 based on the GLContext attached
- * @param context the current {@link GLContext}
- * @param st the {@link ShaderState} object
- * @param type can be one of Region.SINGLE_PASS or Region.TWO_PASS
+ /**
+ * 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(GLContext context, ShaderState st, int type){
- if( !context.isGL2ES2() ) {
- throw new GLException("At least a GL2ES2 GL context is required. Given: " + context);
- }
+ public static Region create(RenderState rs, int type) {
if( Region.TWO_PASS == type ){
- return new VBORegion2PES2(context, st);
+ return new VBORegion2PES2(rs, Region.TWO_PASS_DEFAULT_TEXTURE_UNIT);
}
else{
- return new VBORegionSPES2(context);
+ 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/RegionRenderer.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java
index c6e03cad6..2b4c8b7c5 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java
@@ -1,3 +1,30 @@
+/**
+ * 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;
@@ -13,15 +40,18 @@ import com.jogamp.graph.geom.Triangle;
import com.jogamp.graph.geom.Vertex;
public abstract class RegionRenderer extends Renderer {
-
- /** Create a Hardware accelerated Curve Region 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}
*/
- public static RegionRenderer create(Vertex.Factory<? extends Vertex> factory, int type) {
- return new jogamp.graph.curve.opengl.RegionRendererImpl01(factory, type);
+ public static RegionRenderer create(RenderState rs, int type) {
+ return new jogamp.graph.curve.opengl.RegionRendererImpl01(rs, type);
}
- public RegionRenderer(Vertex.Factory<? extends Vertex> factory, int type) {
- super(factory, type);
+ protected RegionRenderer(RenderState rs, int type) {
+ super(rs, type);
}
/** Render an array of {@link OutlineShape}s combined in one region
@@ -45,52 +75,50 @@ public abstract class RegionRenderer extends Renderer {
protected HashMap<Integer, Region> regions = new HashMap<Integer, Region>();
- public void flushCache() {
+ public void flushCache(GL2ES2 gl) {
Iterator<Region> iterator = regions.values().iterator();
while(iterator.hasNext()){
Region region = iterator.next();
- region.destroy();
+ region.destroy(gl);
}
regions.clear();
}
@Override
protected void disposeImpl(GL2ES2 gl) {
- flushCache();
+ // fluchCache(gl) already called
}
- /** Create an ogl {@link Region} defining this {@link OutlineShape}
- * @param sharpness parameter for Region generation
+ /**
+ * Create an ogl {@link Region} defining this {@link OutlineShape}
* @return the resulting Region.
*/
- protected Region createRegion(GL2ES2 gl, OutlineShape outlineShape, float sharpness) {
- Region region = RegionFactory.create(gl.getContext(), st, renderType);
+ protected Region createRegion(GL2ES2 gl, OutlineShape outlineShape) {
+ Region region = RegionFactory.create(rs, renderType);
outlineShape.transformOutlines(OutlineShape.QUADRATIC_NURBS);
-
- ArrayList<Triangle> triangles = (ArrayList<Triangle>) outlineShape.triangulate(sharpness);
+ ArrayList<Triangle> triangles = (ArrayList<Triangle>) outlineShape.triangulate(rs.getSharpness().floatValue());
ArrayList<Vertex> vertices = (ArrayList<Vertex>) outlineShape.getVertices();
region.addVertices(vertices);
region.addTriangles(triangles);
- region.update();
+ region.update(gl);
return region;
}
/** Create an ogl {@link Region} defining the list of {@link OutlineShape}.
* Combining the Shapes into single buffers.
- * @param sharpness parameter for Region generation
* @return the resulting Region inclusive the generated region
*/
- protected Region createRegion(GL2ES2 gl, OutlineShape[] outlineShapes, float sharpness) {
- Region region = RegionFactory.create(gl.getContext(), st, renderType);
+ protected Region createRegion(GL2ES2 gl, OutlineShape[] outlineShapes) {
+ Region region = RegionFactory.create(rs, renderType);
int numVertices = region.getNumVertices();
for(OutlineShape outlineShape:outlineShapes){
outlineShape.transformOutlines(OutlineShape.QUADRATIC_NURBS);
- ArrayList<Triangle> triangles = outlineShape.triangulate(sharpness);
+ ArrayList<Triangle> triangles = outlineShape.triangulate(rs.getSharpness().floatValue());
region.addTriangles(triangles);
ArrayList<Vertex> vertices = outlineShape.getVertices();
@@ -100,7 +128,7 @@ public abstract class RegionRenderer extends Renderer {
region.addVertices(vertices);
}
- region.update();
+ region.update(gl);
return region;
}
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java
new file mode 100644
index 000000000..6450f9f8b
--- /dev/null
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java
@@ -0,0 +1,56 @@
+/**
+ * Copyright 2011 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 javax.media.opengl.GL;
+import javax.media.opengl.GLProfile;
+import javax.media.opengl.GLUniformData;
+
+import com.jogamp.common.os.Platform;
+import com.jogamp.common.util.VersionUtil;
+import com.jogamp.graph.geom.Vertex;
+import com.jogamp.opengl.util.PMVMatrix;
+import com.jogamp.opengl.util.glsl.ShaderState;
+
+public interface RenderState {
+
+ ShaderState getShaderState();
+ Vertex.Factory<? extends Vertex> getPointFactory();
+ PMVMatrix getPMVMatrix();
+ GLUniformData getPMVMatrixUniform();
+ GLUniformData getSharpness();
+ GLUniformData getAlpha();
+ GLUniformData getColorStatic();
+ GLUniformData getStrength();
+
+ RenderState attachTo(GL gl);
+ boolean detachFrom(GL gl);
+
+ StringBuilder toString(StringBuilder sb);
+ String toString();
+}
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 ce3e83692..4db917fdd 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java
@@ -1,40 +1,75 @@
+/**
+ * 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.nio.FloatBuffer;
+
import javax.media.opengl.GL2ES2;
import javax.media.opengl.GLUniformData;
import javax.media.opengl.fixedfunc.GLMatrixFunc;
-import jogamp.opengl.Debug;
+import jogamp.graph.curve.opengl.RenderStateImpl;
import com.jogamp.graph.curve.Region;
import com.jogamp.graph.geom.Vertex;
-import com.jogamp.graph.geom.opengl.SVertex;
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;
+
+ public static RenderState createRenderState(ShaderState st, Vertex.Factory<? extends Vertex> pointFactory, PMVMatrix pmvMatrix) {
+ return new RenderStateImpl(st, pointFactory, pmvMatrix);
+ }
- protected abstract boolean initImpl(GL2ES2 gl);
+ public static RenderState createRenderState(ShaderState st, Vertex.Factory<? extends Vertex> pointFactory) {
+ return new RenderStateImpl(st, pointFactory);
+ }
+
+ /**
+ * Implementation shall load, compile and link the shader program and leave it active.
+ * @param gl
+ * @return
+ */
+ protected abstract boolean initShaderProgram(GL2ES2 gl);
protected abstract void disposeImpl(GL2ES2 gl);
/**
* Flushes all cached data
+ * @see #dispose(GL2ES2)
*/
- public abstract void flushCache();
+ public abstract void flushCache(GL2ES2 gl);
+
+ protected final RenderState rs;
+ public final int renderType;
- public abstract float getAlpha();
-
- public abstract void setAlpha(GL2ES2 gl, float alpha_t);
-
- public abstract void setColor(GL2ES2 gl, float r, float g, float b);
-
- protected final Vertex.Factory<? extends Vertex> pointFactory;
- protected ShaderState st = new ShaderState();
- protected PMVMatrix pmvMatrix = new PMVMatrix();
- protected GLUniformData mgl_PMVMatrix;
- protected int renderType;
protected int vp_width = 0;
protected int vp_height = 0;
@@ -42,16 +77,15 @@ public abstract class Renderer {
private boolean initialized = false;
/**
- *
- * @param factory
+ * @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}
*/
- protected Renderer(Vertex.Factory<? extends Vertex> factory, int renderType) {
+ protected Renderer(RenderState rs, int renderType) {
+ this.rs = rs;
this.renderType = renderType;
- this.pointFactory = (null != factory) ? factory : SVertex.factory();
}
- public Vertex.Factory<? extends Vertex> getFactory() { return pointFactory; }
+ public Vertex.Factory<? extends Vertex> getFactory() { return rs.getPointFactory(); }
public final boolean isInitialized() { return initialized; }
@@ -63,10 +97,12 @@ public abstract class Renderer {
public final int getHeight() { return vp_height; }
/**
- * Initialize shaders and bindings for GPU based rendering.
- * Leaves the renderer enabled, ie ShaderState on.
+ * Initialize shader and bindings for GPU based rendering bound to the given GL object's GLContext.
*
- * @param gl the current GL state
+ * Leaves the renderer enabled, ie ShaderState.
+ *
+ * @param gl referencing the current GLContext to which the ShaderState is bound to
+ *
* @return true if succeeded, false otherwise
*/
public boolean init(GL2ES2 gl) {
@@ -87,92 +123,175 @@ public abstract class Renderer {
System.err.println("TextRendererImpl01: VBO Supported = " + isVBOSupported());
}
- initialized = initImpl(gl);
+ if(!vboSupported){
+ return false;
+ }
+
+ rs.attachTo(gl);
+
+ gl.glEnable(GL2ES2.GL_BLEND);
+ gl.glBlendFunc(GL2ES2.GL_SRC_ALPHA, GL2ES2.GL_ONE_MINUS_SRC_ALPHA);
+
+ initialized = initShaderProgram(gl);
+ if(!initialized) {
+ return false;
+ }
+
+ if(!rs.getShaderState().glUniform(gl, rs.getPMVMatrixUniform())) {
+ if(DEBUG){
+ System.err.println("Error setting PMVMatrix in shader: "+rs.getShaderState());
+ }
+ return false;
+ }
+
+ if(!rs.getShaderState().glUniform(gl, rs.getSharpness())) {
+ if(DEBUG){
+ System.err.println("Error setting sharpness in shader: "+rs.getShaderState());
+ }
+ return false;
+ }
+
+ if(!rs.getShaderState().glUniform(gl, rs.getAlpha())) {
+ if(DEBUG){
+ System.err.println("Error setting global alpha in shader: "+rs.getShaderState());
+ }
+ return false;
+ }
+
+ if(!rs.getShaderState().glUniform(gl, rs.getColorStatic())) {
+ if(DEBUG){
+ System.err.println("Error setting global color in shader: "+rs.getShaderState());
+ }
+ return false;
+ }
+
+ if(!rs.getShaderState().glUniform(gl, rs.getStrength())) {
+ System.err.println("Error setting antialias strength in shader: "+rs.getShaderState());
+ }
+
return initialized;
}
public void dispose(GL2ES2 gl) {
if(!initialized){
- if(DEBUG) {
+ if(DEBUG_INSTANCE) {
System.err.println("TextRenderer: Not initialized!");
}
return;
}
+ flushCache(gl);
disposeImpl(gl);
- st.destroy(gl);
- flushCache();
+ rs.getShaderState().destroy(gl);
initialized = false;
}
- public final ShaderState getShaderState() { return st; }
+ public final RenderState getRenderState() { return rs; }
+ public final ShaderState getShaderState() { return rs.getShaderState(); }
public final void enable(GL2ES2 gl, boolean enable) {
- st.glUseProgram(gl, enable);
+ rs.getShaderState().glUseProgram(gl, enable);
}
- public final PMVMatrix getMatrix() { return pmvMatrix; }
+ public float getSharpness() {
+ return rs.getSharpness().floatValue();
+ }
+
+ public void setSharpness(GL2ES2 gl, float v) {
+ rs.getSharpness().setData(v);
+ if(null != gl && rs.getShaderState().inUse()) {
+ rs.getShaderState().glUniform(gl, rs.getSharpness());
+ }
+ }
- public void rotate(GL2ES2 gl, float angle, float x, float y, float z) {
- pmvMatrix.glRotatef(angle, x, y, z);
- if(initialized && null != gl && st.inUse()) {
- st.glUniform(gl, mgl_PMVMatrix);
+ public float getStrength() {
+ return rs.getStrength().floatValue();
+ }
+
+ public void setStrength(GL2ES2 gl, float v) {
+ rs.getStrength().setData(v);
+ if(null != gl && rs.getShaderState().inUse()) {
+ rs.getShaderState().glUniform(gl, rs.getStrength());
}
}
+
+ public float getAlpha() {
+ return rs.getAlpha().floatValue();
+ }
- public void translate(GL2ES2 gl, float x, float y, float z) {
- pmvMatrix.glTranslatef(x, y, z);
- if(initialized && null != gl && st.inUse()) {
- st.glUniform(gl, mgl_PMVMatrix);
+ public void setAlpha(GL2ES2 gl, float alpha_t) {
+ rs.getAlpha().setData(alpha_t);
+ if(null != gl && rs.getShaderState().inUse()) {
+ rs.getShaderState().glUniform(gl, rs.getAlpha());
}
+
+ }
+
+ public void getColorStatic(GL2ES2 gl, float[] rgb) {
+ FloatBuffer fb = (FloatBuffer) rs.getColorStatic().getBuffer();
+ rgb[0] = fb.get(0);
+ rgb[1] = fb.get(1);
+ rgb[2] = fb.get(2);
}
- public void scale(GL2ES2 gl, float x, float y, float z) {
- pmvMatrix.glScalef(x, y, z);
- if(initialized && null != gl && st.inUse()) {
- st.glUniform(gl, mgl_PMVMatrix);
+ public void setColorStatic(GL2ES2 gl, float r, float g, float b){
+ FloatBuffer fb = (FloatBuffer) rs.getColorStatic().getBuffer();
+ fb.put(0, r);
+ fb.put(1, g);
+ fb.put(2, b);
+ if(null != gl && rs.getShaderState().inUse()) {
+ rs.getShaderState().glUniform(gl, rs.getColorStatic());
}
}
+
+ public final PMVMatrix getMatrix() { return rs.getPMVMatrix(); }
+
+ public void rotate(GL2ES2 gl, float angle, float x, float y, float z) {
+ rs.getPMVMatrix().glRotatef(angle, x, y, z);
+ updateMatrix(gl);
+ }
+
+ public void translate(GL2ES2 gl, float x, float y, float z) {
+ rs.getPMVMatrix().glTranslatef(x, y, z);
+ updateMatrix(gl);
+ }
+
+ public void scale(GL2ES2 gl, float x, float y, float z) {
+ rs.getPMVMatrix().glScalef(x, y, z);
+ updateMatrix(gl);
+ }
public void resetModelview(GL2ES2 gl) {
- pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
- pmvMatrix.glLoadIdentity();
- if(initialized && null != gl && st.inUse()) {
- st.glUniform(gl, mgl_PMVMatrix);
- }
+ rs.getPMVMatrix().glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
+ rs.getPMVMatrix().glLoadIdentity();
+ updateMatrix(gl);
}
public void updateMatrix(GL2ES2 gl) {
- if(initialized && null != gl && st.inUse()) {
- st.glUniform(gl, mgl_PMVMatrix);
+ if(initialized && null != gl && rs.getShaderState().inUse()) {
+ rs.getShaderState().glUniform(gl, rs.getPMVMatrixUniform());
}
}
public boolean reshapePerspective(GL2ES2 gl, float angle, int width, int height, float near, float far) {
this.vp_width = width;
this.vp_height = height;
- float ratio = (float)width/(float)height;
- pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
- pmvMatrix.glLoadIdentity();
- pmvMatrix.gluPerspective(angle, ratio, near, far);
-
- if(initialized && null != gl) {
- st.glUniform(gl, mgl_PMVMatrix);
- }
-
+ final float ratio = (float)width/(float)height;
+ final PMVMatrix p = rs.getPMVMatrix();
+ p.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
+ p.glLoadIdentity();
+ p.gluPerspective(angle, ratio, near, far);
+ updateMatrix(gl);
return true;
}
public boolean reshapeOrtho(GL2ES2 gl, int width, int height, float near, float far) {
this.vp_width = width;
this.vp_height = height;
- pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
- pmvMatrix.glLoadIdentity();
- pmvMatrix.glOrthof(0, width, 0, height, near, far);
-
- if(initialized && null != gl) {
- st.glUniform(gl, mgl_PMVMatrix);
- }
-
+ final PMVMatrix p = rs.getPMVMatrix();
+ p.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
+ p.glLoadIdentity();
+ p.glOrthof(0, width, 0, height, near, far);
+ updateMatrix(gl);
return true;
}
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 ee8dfb372..a955d5a88 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java
@@ -1,9 +1,37 @@
+/**
+ * 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 java.util.HashMap;
import java.util.Iterator;
+import javax.media.opengl.GL;
import javax.media.opengl.GL2ES2;
import jogamp.graph.curve.text.GlyphString;
@@ -12,20 +40,21 @@ import jogamp.graph.geom.plane.AffineTransform;
import jogamp.graph.geom.plane.Path2D;
import com.jogamp.graph.font.Font;
-import com.jogamp.graph.geom.Vertex;
public abstract class TextRenderer extends Renderer {
/**
* Create a Hardware accelerated Text Renderer.
- * @param factory optional Point.Factory for Vertex construction. Default is Vertex.Factory.
+ * @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}
*/
- public static TextRenderer create(Vertex.Factory<? extends Vertex> factory, int type) {
- return new jogamp.graph.curve.opengl.TextRendererImpl01(factory, type);
+ public static TextRenderer create(RenderState rs, int type) {
+ return new jogamp.graph.curve.opengl.TextRendererImpl01(rs, type);
}
- protected TextRenderer(Vertex.Factory<? extends Vertex> factory, int type) {
- super(factory, type);
+ protected TextRenderer(RenderState rs, int type) {
+ super(rs, type);
}
+
/** Render the String in 3D space wrt to the font provided at the position provided
* the outlines will be generated, if not yet generated
@@ -45,30 +74,29 @@ public abstract class TextRenderer extends Renderer {
* @param font {@link Font} to be used
* @param size font size
* @param str {@link String} to be created
- * @param sharpness parameter for Region generation of the resulting GlyphString
* @return the resulting GlyphString inclusive the generated region
*/
- public GlyphString createString(GL2ES2 gl, Font font, int size, String str, float sharpness) {
- if(DEBUG) {
+ public GlyphString createString(GL2ES2 gl, Font font, int size, String str) {
+ if(DEBUG_INSTANCE) {
System.err.println("createString: "+getCacheSize()+"/"+getCacheLimit()+" - "+Font.NAME_UNIQUNAME + " - " + str + " - " + size);
}
- AffineTransform affineTransform = new AffineTransform(pointFactory);
+ AffineTransform affineTransform = new AffineTransform(rs.getPointFactory());
Path2D[] paths = new Path2D[str.length()];
((FontInt)font).getOutline(str, size, affineTransform, paths);
- GlyphString glyphString = new GlyphString(pointFactory, font.getName(Font.NAME_UNIQUNAME), str);
- glyphString.createfromFontPath(paths, affineTransform);
- glyphString.generateRegion(gl.getContext(), sharpness, st, renderType);
+ GlyphString glyphString = new GlyphString(font.getName(Font.NAME_UNIQUNAME), str);
+ glyphString.createfromFontPath(rs.getPointFactory(), paths, affineTransform);
+ glyphString.generateRegion(gl, rs, renderType);
return glyphString;
}
- public void flushCache() {
+ public void flushCache(GL2ES2 gl) {
Iterator<GlyphString> iterator = stringCacheMap.values().iterator();
while(iterator.hasNext()){
GlyphString glyphString = iterator.next();
- glyphString.destroy();
+ glyphString.destroy(gl);
}
stringCacheMap.clear();
stringCacheArray.clear();
@@ -76,18 +104,34 @@ public abstract class TextRenderer extends Renderer {
@Override
protected void disposeImpl(GL2ES2 gl) {
- flushCache();
+ // fluchCache(gl) already called
}
/**
- * Sets the cache limit for reusing GlyphString's and their Region.
- * Default is {@link #DEFAULT_CACHE_LIMIT}, -1 unlimited, 0 turns cache off, >0 limited
+ * <p>Sets the cache limit for reusing GlyphString's and their Region.
+ * Default is {@link #DEFAULT_CACHE_LIMIT}, -1 unlimited, 0 turns cache off, >0 limited </p>
+ *
+ * <p>The cache will be validate when the next string rendering happens.</p>
*
* @param newLimit new cache size
*
* @see #DEFAULT_CACHE_LIMIT
*/
- public final void setCacheLimit(int newLimit ) { stringCacheLimit = newLimit; validateCache(0); }
+ public final void setCacheLimit(int newLimit ) { stringCacheLimit = newLimit; }
+
+ /**
+ * Sets the cache limit, see {@link #setCacheLimit(int)} and validates the cache.
+ *
+ * @see #setCacheLimit(int)
+ *
+ * @param gl current GL used to remove cached objects if required
+ * @param newLimit new cache size
+ */
+ public final void setCacheLimit(GL2ES2 gl, int newLimit ) { stringCacheLimit = newLimit; validateCache(gl, 0); }
+
+ /**
+ * @return the current cache limit
+ */
public final int getCacheLimit() { return stringCacheLimit; }
/**
@@ -95,10 +139,10 @@ public abstract class TextRenderer extends Renderer {
*/
public final int getCacheSize() { return stringCacheArray.size(); }
- protected final void validateCache(int space) {
+ protected final void validateCache(GL2ES2 gl, int space) {
if ( getCacheLimit() > 0 ) {
while ( getCacheSize() + space > getCacheLimit() ) {
- removeCachedGlyphString(0);
+ removeCachedGlyphString(gl, 0);
}
}
}
@@ -107,32 +151,32 @@ public abstract class TextRenderer extends Renderer {
return stringCacheMap.get(getKey(font, str, fontSize));
}
- protected final void addCachedGlyphString(Font font, String str, int fontSize, GlyphString glyphString) {
+ protected final void addCachedGlyphString(GL2ES2 gl, Font font, String str, int fontSize, GlyphString glyphString) {
if ( 0 != getCacheLimit() ) {
final String key = getKey(font, str, fontSize);
GlyphString oldGlyphString = stringCacheMap.put(key, glyphString);
if ( null == oldGlyphString ) {
// new entry ..
- validateCache(1);
+ validateCache(gl, 1);
stringCacheArray.add(stringCacheArray.size(), key);
} /// else overwrite is nop ..
}
}
- protected final void removeCachedGlyphString(Font font, String str, int fontSize) {
+ protected final void removeCachedGlyphString(GL2ES2 gl, Font font, String str, int fontSize) {
final String key = getKey(font, str, fontSize);
GlyphString glyphString = stringCacheMap.remove(key);
if(null != glyphString) {
- glyphString.destroy();
+ glyphString.destroy(gl);
}
stringCacheArray.remove(key);
}
- protected final void removeCachedGlyphString(int idx) {
+ protected final void removeCachedGlyphString(GL2ES2 gl, int idx) {
final String key = stringCacheArray.remove(idx);
final GlyphString glyphString = stringCacheMap.remove(key);
if(null != glyphString) {
- glyphString.destroy();
+ glyphString.destroy(gl);
}
}
diff --git a/src/jogl/classes/com/jogamp/graph/geom/AABBox.java b/src/jogl/classes/com/jogamp/graph/geom/AABBox.java
index 8a604eccd..7051e9110 100644
--- a/src/jogl/classes/com/jogamp/graph/geom/AABBox.java
+++ b/src/jogl/classes/com/jogamp/graph/geom/AABBox.java
@@ -36,14 +36,16 @@ import com.jogamp.graph.math.VectorUtil;
*
*/
public class AABBox {
- private float[] low = {Float.MAX_VALUE,Float.MAX_VALUE,Float.MAX_VALUE};
- private float[] high = {-1*Float.MAX_VALUE,-1*Float.MAX_VALUE,-1*Float.MAX_VALUE};
+ private float[] low = new float[3];
+ private float[] high = new float[3];
private float[] center = new float[3];
/** Create a Axis Aligned bounding box (AABBox)
* where the low and and high MAX float Values.
*/
- public AABBox() {}
+ public AABBox() {
+ reset();
+ }
/** Create an AABBox specifying the coordinates
* of the low and high
@@ -57,6 +59,7 @@ public class AABBox {
public AABBox(float lx, float ly, float lz,
float hx, float hy, float hz)
{
+ reset();
resize(lx, ly, lz);
resize(hx, hy, hz);
@@ -67,24 +70,31 @@ public class AABBox {
* @param low min xyz-coordinates
* @param high max xyz-coordinates
*/
- public AABBox(float[] low, float[] high)
- {
+ public AABBox(float[] low, float[] high) {
+ reset();
resize(low[0],low[1],low[2]);
resize(high[0],high[1],high[2]);
computeCenter();
}
+
+ /** resets this box to the inverse low/high, allowing the next {@link #resize(float, float, float)} command to hit. */
+ public void reset() {
+ setLow(Float.MAX_VALUE,Float.MAX_VALUE,Float.MAX_VALUE);
+ setHigh(-1*Float.MAX_VALUE,-1*Float.MAX_VALUE,-1*Float.MAX_VALUE);
+ center[0] = 0f;
+ center[1] = 0f;
+ center[2] = 0f;
+ }
/** Get the max xyz-coordinates
* @return a float array containing the max xyz coordinates
*/
- public float[] getHigh()
- {
+ public float[] getHigh() {
return high;
}
- private void setHigh(float hx, float hy, float hz)
- {
+ private void setHigh(float hx, float hy, float hz) {
this.high[0] = hx;
this.high[1] = hy;
this.high[2] = hz;
@@ -93,13 +103,11 @@ public class AABBox {
/** Get the min xyz-coordinates
* @return a float array containing the min xyz coordinates
*/
- public float[] getLow()
- {
+ public float[] getLow() {
return low;
}
- private void setLow(float lx, float ly, float lz)
- {
+ private void setLow(float lx, float ly, float lz) {
this.low[0] = lx;
this.low[1] = ly;
this.low[2] = lz;
@@ -108,8 +116,7 @@ public class AABBox {
/** Resize the AABBox to encapsulate another AABox
* @param newBox AABBox to be encapsulated in
*/
- public void resize(AABBox newBox)
- {
+ public void resize(AABBox newBox) {
float[] newLow = newBox.getLow();
float[] newHigh = newBox.getHigh();
@@ -132,8 +139,7 @@ public class AABBox {
computeCenter();
}
- private void computeCenter()
- {
+ private void computeCenter() {
center[0] = (high[0] + low[0])/2;
center[1] = (high[1] + low[1])/2;
center[2] = (high[2] + low[2])/2;
@@ -145,8 +151,7 @@ public class AABBox {
* @param y y-axis coordinate value
* @param z z-axis coordinate value
*/
- public void resize(float x, float y, float z)
- {
+ public void resize(float x, float y, float z) {
/** test low */
if (x < low[0])
low[0] = x;
@@ -173,7 +178,7 @@ public class AABBox {
* @return true if x belong to (low.x, high.x) and
* y belong to (low.y, high.y)
*/
- public boolean contains(float x, float y){
+ public boolean contains(float x, float y) {
if(x<low[0] || x>high[0]){
return false;
}
@@ -191,7 +196,7 @@ public class AABBox {
* @return true if x belong to (low.x, high.x) and
* y belong to (low.y, high.y) and z belong to (low.z, high.z)
*/
- public boolean contains(float x, float y, float z){
+ public boolean contains(float x, float y, float z) {
if(x<low[0] || x>high[0]){
return false;
}
@@ -236,7 +241,7 @@ public class AABBox {
* length of the vector between low and high.
* @return a float representing the size of the AABBox
*/
- public float getSize(){
+ public float getSize() {
return VectorUtil.computeLength(low, high);
}
@@ -288,7 +293,7 @@ public class AABBox {
public float getDepth() {
return high[2] - low[2];
}
- public AABBox clone(){
+ public AABBox clone() {
return new AABBox(this.low, this.high);
}
diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java
index fe695ecb3..d3f224a2a 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java
@@ -594,8 +594,6 @@ public class ShaderState {
* If data location is unset it will be retrieved via {@link #glGetAttribLocation(GL2ES2, GLArrayData)}, set
* and cached in this state.
*
- * Enables the attribute via {@link #glEnableVertexAttribArray(GL2ES2, GLArrayData)} , if it is not enabled yet.
- *
* @return false, if the location could not be determined, otherwise true
*
* @throws GLException if the program is not in use
@@ -611,14 +609,6 @@ public class ShaderState {
if(0 > data.getLocation()) {
glGetAttribLocation(gl, data);
}
- if(!enabledVertexAttribArraySet.contains(data.getName())) {
- if(!glEnableVertexAttribArray(gl, data)) {
- if(verbose) {
- Throwable tX = new Throwable("Info: glVertexAttribPointer: couldn't enable: "+data);
- tX.printStackTrace();
- }
- }
- }
if(0 <= data.getLocation()) {
// only pass the data, if the attribute exists in the current shader
if(DEBUG) {
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java b/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java
index 683a72d96..4dcc4560e 100755
--- a/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java
@@ -27,53 +27,29 @@
*/
package jogamp.graph.curve.opengl;
-import java.nio.FloatBuffer;
import javax.media.opengl.GL2ES2;
import javax.media.opengl.GLException;
-import javax.media.opengl.GLUniformData;
-import javax.media.opengl.fixedfunc.GLMatrixFunc;
+
+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.RegionRenderer;
-import com.jogamp.graph.geom.Vertex;
+import com.jogamp.graph.curve.opengl.RenderState;
import com.jogamp.opengl.util.glsl.ShaderCode;
import com.jogamp.opengl.util.glsl.ShaderProgram;
import com.jogamp.opengl.util.glsl.ShaderState;
-
public class RegionRendererImpl01 extends RegionRenderer {
- /**Sharpness is equivalent to the value of t value of texture coord
- * on the off-curve vertex. The high value of sharpness will
- * result in high curvature.
- */
- private GLUniformData mgl_sharpness = new GLUniformData("p1y", 0.5f);
- GLUniformData mgl_alpha = new GLUniformData("g_alpha", 1.0f);
- private GLUniformData mgl_color = new GLUniformData("g_color", 3, FloatBuffer.allocate(3));
- private GLUniformData mgl_strength = new GLUniformData("a_strength", 3.0f);
-
- public RegionRendererImpl01(Vertex.Factory<? extends Vertex> factory, int type) {
- super(factory, type);
+ public RegionRendererImpl01(RenderState rs, int type) {
+ super(rs, type);
+ // rs.getSharpness().setData(0.5f);
+ // rs.getAlpha().setData(1.0f);
+ // rs.getStrength().setData(3.0f);
}
- protected boolean initImpl(GL2ES2 gl) {
- boolean VBOsupported = gl.isFunctionAvailable("glGenBuffers") &&
- gl.isFunctionAvailable("glBindBuffer") &&
- gl.isFunctionAvailable("glBufferData") &&
- gl.isFunctionAvailable("glDrawElements") &&
- gl.isFunctionAvailable("glVertexAttribPointer") &&
- gl.isFunctionAvailable("glDeleteBuffers");
-
- if(DEBUG) {
- System.err.println("RegionRenderer: VBO Supported = " + VBOsupported);
- }
-
- if(!VBOsupported){
- return false;
- }
-
- gl.glEnable(GL2ES2.GL_BLEND);
- gl.glBlendFunc(GL2ES2.GL_SRC_ALPHA, GL2ES2.GL_ONE_MINUS_SRC_ALPHA);
+ 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", "curverenderer01");
@@ -85,60 +61,15 @@ public class RegionRendererImpl01 extends RegionRenderer {
sp.add(rsFp);
sp.init(gl);
- gl.glBindAttribLocation(sp.program(), Region.VERTEX_ATTR_IDX, Region.VERTEX_ATTR_NAME);
- gl.glBindAttribLocation(sp.program(), Region.TEXCOORD_ATTR_IDX, Region.TEXCOORD_ATTR_NAME);
+ st.attachShaderProgram(gl, sp);
+ st.glBindAttribLocation(gl, AttributeNames.VERTEX_ATTR_IDX, AttributeNames.VERTEX_ATTR_NAME);
+ st.glBindAttribLocation(gl, AttributeNames.TEXCOORD_ATTR_IDX, AttributeNames.TEXCOORD_ATTR_NAME);
if(!sp.link(gl, System.err)) {
throw new GLException("RegionRenderer: Couldn't link program: "+sp);
- }
-
- st = new ShaderState();
- st.attachShaderProgram(gl, sp);
-
+ }
st.glUseProgram(gl, true);
- pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
- pmvMatrix.glLoadIdentity();
- pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
- pmvMatrix.glLoadIdentity();
-
- pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
- pmvMatrix.glLoadIdentity();
- resetModelview(null);
-
- mgl_PMVMatrix = new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf());
- if(!st.glUniform(gl, mgl_PMVMatrix)) {
- if(DEBUG){
- System.err.println("Error setting PMVMatrix in shader: "+st);
- }
- return false;
- }
-
- if(!st.glUniform(gl, mgl_sharpness)) {
- if(DEBUG){
- System.err.println("Error setting sharpness in shader: "+st);
- }
- return false;
- }
-
- if(!st.glUniform(gl, mgl_alpha)) {
- if(DEBUG){
- System.err.println("Error setting global alpha in shader: "+st);
- }
- return false;
- }
-
- if(!st.glUniform(gl, mgl_color)) {
- if(DEBUG){
- System.err.println("Error setting global color in shader: "+st);
- }
- return false;
- }
-
- if(!st.glUniform(gl, mgl_strength)) {
- System.err.println("Error setting antialias strength in shader: "+st);
- }
-
if(DEBUG) {
System.err.println("RegionRendererImpl01 initialized: " + Thread.currentThread()+" "+st);
}
@@ -150,30 +81,6 @@ public class RegionRendererImpl01 extends RegionRenderer {
super.disposeImpl(gl);
}
- @Override
- public float getAlpha() {
- return mgl_alpha.floatValue();
- }
-
- @Override
- public void setAlpha(GL2ES2 gl, float alpha_t) {
- mgl_alpha.setData(alpha_t);
- if(null != gl && st.inUse()) {
- st.glUniform(gl, mgl_alpha);
- }
- }
-
- @Override
- public void setColor(GL2ES2 gl, float r, float g, float b){
- FloatBuffer fb = (FloatBuffer) mgl_color.getBuffer();
- fb.put(0, r);
- fb.put(1, r);
- fb.put(2, r);
- if(null != gl && st.inUse()) {
- st.glUniform(gl, mgl_color);
- }
- }
-
@Override
public void renderOutlineShape(GL2ES2 gl, OutlineShape outlineShape, float[] position, int texSize) {
@@ -184,10 +91,10 @@ public class RegionRendererImpl01 extends RegionRenderer {
Region region = regions.get(hashCode);
if(null == region) {
- region = createRegion(gl, outlineShape, mgl_sharpness.floatValue());
+ region = createRegion(gl, outlineShape);
regions.put(hashCode, region);
}
- region.render(pmvMatrix, vp_width, vp_height, texSize);
+ region.render(gl, rs, vp_width, vp_height, texSize);
}
@Override
@@ -200,9 +107,9 @@ public class RegionRendererImpl01 extends RegionRenderer {
Region region = regions.get(hashCode);
if(null == region) {
- region = createRegion(gl, outlineShapes, mgl_sharpness.floatValue());
+ region = createRegion(gl, outlineShapes);
regions.put(hashCode, region);
}
- region.render(pmvMatrix, vp_width, vp_height, texSize);
+ region.render(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
new file mode 100644
index 000000000..4c4a325ae
--- /dev/null
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/RenderStateImpl.java
@@ -0,0 +1,126 @@
+/**
+ * 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 jogamp.graph.curve.opengl;
+
+import java.nio.FloatBuffer;
+
+import javax.media.opengl.GL;
+import javax.media.opengl.GLProfile;
+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.common.util.VersionUtil;
+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 {
+
+ public final ShaderState st;
+ public final Vertex.Factory<? extends Vertex> pointFactory;
+ public final PMVMatrix pmvMatrix;
+ public final GLUniformData mgl_PMVMatrix;
+
+ /**
+ * Sharpness is equivalent to the texture-coord component <i>t</i>
+ * on the off-curve vertex. Higher values of sharpness will
+ * result in higher curvature.
+ */
+ public final GLUniformData mgl_sharpness;
+ public final GLUniformData mgl_alpha;
+ public final GLUniformData mgl_colorStatic;
+ public final GLUniformData mgl_strength;
+
+ public static final RenderState getRenderState(GL gl) {
+ return (RenderState) gl.getContext().getAttachedObject(RenderState.class.getName());
+ }
+
+ public RenderStateImpl(ShaderState st, Vertex.Factory<? extends Vertex> pointFactory, PMVMatrix pmvMatrix) {
+ this.st = st;
+ this.pointFactory = pointFactory;
+ this.pmvMatrix = pmvMatrix;
+ this.mgl_PMVMatrix = new GLUniformData(UniformNames.gcu_PMVMatrix, 4, 4, pmvMatrix.glGetPMvMatrixf());
+
+ mgl_sharpness = new GLUniformData(UniformNames.gcu_P1Y, 0.5f);
+ mgl_alpha = new GLUniformData(UniformNames.gcu_Alpha, 1.0f);
+ mgl_colorStatic = new GLUniformData(UniformNames.gcu_ColorStatic, 3, FloatBuffer.allocate(3));
+ mgl_strength = new GLUniformData(UniformNames.gcu_Strength, 3.0f);
+ }
+
+ 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 getPMVMatrix() { return pmvMatrix; }
+ public final GLUniformData getPMVMatrixUniform() { return mgl_PMVMatrix; }
+ public final GLUniformData getSharpness() { return mgl_sharpness; }
+ public final GLUniformData getAlpha() { return mgl_alpha; }
+ public final GLUniformData getColorStatic() { return mgl_colorStatic; }
+ public final GLUniformData getStrength() { return mgl_strength; }
+
+ public final RenderState attachTo(GL gl) {
+ return (RenderState) gl.getContext().attachObject(RenderState.class.getName(), this);
+ }
+ public final boolean detachFrom(GL 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 bc94ab180..3bddaed3b 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java
@@ -27,119 +27,51 @@
*/
package jogamp.graph.curve.opengl;
-import java.nio.FloatBuffer;
-
import javax.media.opengl.GL2ES2;
import javax.media.opengl.GLException;
-import javax.media.opengl.GLUniformData;
-import javax.media.opengl.fixedfunc.GLMatrixFunc;
+import jogamp.graph.curve.opengl.shader.AttributeNames;
import jogamp.graph.curve.text.GlyphString;
-import com.jogamp.graph.curve.Region;
+import com.jogamp.graph.curve.opengl.RenderState;
import com.jogamp.graph.curve.opengl.TextRenderer;
import com.jogamp.graph.font.Font;
-import com.jogamp.graph.geom.Vertex;
import com.jogamp.opengl.util.glsl.ShaderCode;
import com.jogamp.opengl.util.glsl.ShaderProgram;
+import com.jogamp.opengl.util.glsl.ShaderState;
public class TextRendererImpl01 extends TextRenderer {
- /**Sharpness is equivalent to the value of t value of texture coord
- * on the off-curve vertex. The high value of sharpness will
- * result in high curvature.
- */
- private GLUniformData mgl_sharpness = new GLUniformData("p1y", 0.5f);
- GLUniformData mgl_alpha = new GLUniformData("g_alpha", 1.0f);
- private GLUniformData mgl_color = new GLUniformData("g_color", 3, FloatBuffer.allocate(3));
- private GLUniformData mgl_strength = new GLUniformData("a_strength", 1.8f);
-
- public TextRendererImpl01(Vertex.Factory<? extends Vertex> factory, int type) {
- super(factory, type);
+ public TextRendererImpl01(RenderState rs, int type) {
+ super(rs, type);
+ // rs.getSharpness().setData(0.5f);
+ // rs.getAlpha().setData(1.0f);
+ // rs.getStrength().setData(3.0f);
+ rs.getStrength().setData(1.9f);
}
-
+
@Override
- protected boolean initImpl(GL2ES2 gl){
- boolean VBOsupported = gl.isFunctionAvailable("glGenBuffers") &&
- gl.isFunctionAvailable("glBindBuffer") &&
- gl.isFunctionAvailable("glBufferData") &&
- gl.isFunctionAvailable("glDrawElements") &&
- gl.isFunctionAvailable("glVertexAttribPointer") &&
- gl.isFunctionAvailable("glDeleteBuffers");
-
- if(DEBUG) {
- System.err.println("TextRendererImpl01: VBO Supported = " + VBOsupported);
- }
-
- if(!VBOsupported){
- return false;
- }
-
- gl.glEnable(GL2ES2.GL_BLEND);
- gl.glBlendFunc(GL2ES2.GL_SRC_ALPHA, GL2ES2.GL_ONE_MINUS_SRC_ALPHA);
+ 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");
ShaderCode rsFp = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, 1, TextRendererImpl01.class,
"shader", "shader/bin", "curverenderer01");
-
+
ShaderProgram sp = new ShaderProgram();
sp.add(rsVp);
sp.add(rsFp);
sp.init(gl);
- gl.glBindAttribLocation(sp.program(), Region.VERTEX_ATTR_IDX, Region.VERTEX_ATTR_NAME);
- gl.glBindAttribLocation(sp.program(), Region.TEXCOORD_ATTR_IDX, Region.TEXCOORD_ATTR_NAME);
+ st.attachShaderProgram(gl, sp);
+ st.glBindAttribLocation(gl, AttributeNames.VERTEX_ATTR_IDX, AttributeNames.VERTEX_ATTR_NAME);
+ st.glBindAttribLocation(gl, AttributeNames.TEXCOORD_ATTR_IDX, AttributeNames.TEXCOORD_ATTR_NAME);
if(!sp.link(gl, System.err)) {
throw new GLException("TextRendererImpl01: Couldn't link program: "+sp);
}
-
- st.attachShaderProgram(gl, sp);
-
st.glUseProgram(gl, true);
- pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
- pmvMatrix.glLoadIdentity();
- pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
- pmvMatrix.glLoadIdentity();
-
- pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
- pmvMatrix.glLoadIdentity();
- resetModelview(null);
-
- mgl_PMVMatrix = new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf());
- if(!st.glUniform(gl, mgl_PMVMatrix)) {
- if(DEBUG){
- System.err.println("Error setting PMVMatrix in shader: "+st);
- }
- return false;
- }
-
- if(!st.glUniform(gl, mgl_sharpness)) {
- if(DEBUG){
- System.err.println("Error setting sharpness in shader: "+st);
- }
- return false;
- }
-
- if(!st.glUniform(gl, mgl_alpha)) {
- if(DEBUG){
- System.err.println("Error setting global alpha in shader: "+st);
- }
- return false;
- }
-
- if(!st.glUniform(gl, mgl_color)) {
- if(DEBUG){
- System.err.println("Error setting global color in shader: "+st);
- }
- return false;
- }
-
- if(!st.glUniform(gl, mgl_strength)) {
- System.err.println("Error setting antialias strength in shader: "+st);
- }
-
if(DEBUG) {
System.err.println("TextRendererImpl01 initialized: " + Thread.currentThread()+" "+st);
}
@@ -152,41 +84,17 @@ public class TextRendererImpl01 extends TextRenderer {
}
@Override
- public float getAlpha() {
- return mgl_alpha.floatValue();
- }
-
- @Override
- public void setAlpha(GL2ES2 gl, float alpha_t) {
- mgl_alpha.setData(alpha_t);
- if(null != gl && st.inUse()) {
- st.glUniform(gl, mgl_alpha);
- }
- }
-
- @Override
- public void setColor(GL2ES2 gl, float r, float g, float b){
- FloatBuffer fb = (FloatBuffer) mgl_color.getBuffer();
- fb.put(0, r);
- fb.put(1, r);
- fb.put(2, r);
- if(null != gl && st.inUse()) {
- st.glUniform(gl, mgl_color);
- }
- }
-
- @Override
public void renderString3D(GL2ES2 gl, Font font, String str, float[] position, int fontSize, int texSize) {
if(!isInitialized()){
throw new GLException("TextRendererImpl01: not initialized!");
}
GlyphString glyphString = getCachedGlyphString(font, str, fontSize);
if(null == glyphString) {
- glyphString = createString(gl, font, fontSize, str, mgl_sharpness.floatValue());
- addCachedGlyphString(font, str, fontSize, glyphString);
+ glyphString = createString(gl, font, fontSize, str);
+ addCachedGlyphString(gl, font, str, fontSize, glyphString);
}
- glyphString.renderString3D(pmvMatrix, vp_width, vp_height, texSize);
+ glyphString.renderString3D(gl, rs, vp_width, vp_height, texSize);
}
}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java
index 05814965e..181ce77b0 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java
@@ -32,15 +32,18 @@ import java.util.ArrayList;
import javax.media.opengl.GL2ES2;
// FIXME: Subsume GL2GL3.GL_DRAW_FRAMEBUFFER -> GL2ES2.GL_DRAW_FRAMEBUFFER !
import javax.media.opengl.GL;
-import javax.media.opengl.GLContext;
import javax.media.opengl.GLUniformData;
import javax.media.opengl.fixedfunc.GLMatrixFunc;
+import jogamp.graph.curve.opengl.shader.AttributeNames;
+import jogamp.graph.curve.opengl.shader.UniformNames;
+
import com.jogamp.graph.geom.AABBox;
import com.jogamp.graph.geom.Triangle;
import com.jogamp.graph.geom.Vertex;
import com.jogamp.graph.curve.Region;
+import com.jogamp.graph.curve.opengl.RenderState;
import com.jogamp.opengl.util.FBObject;
import com.jogamp.opengl.util.GLArrayDataServer;
import com.jogamp.opengl.util.PMVMatrix;
@@ -51,74 +54,82 @@ public class VBORegion2PES2 implements Region {
private ArrayList<Triangle> triangles = new ArrayList<Triangle>();
private ArrayList<Vertex> vertices = new ArrayList<Vertex>();
- private GLArrayDataServer verticeTxtAttr = null;
- private GLArrayDataServer texCoordTxtAttr = null;
- private GLArrayDataServer indicesTxt = null;
- private GLArrayDataServer verticeFboAttr = null;
- private GLArrayDataServer texCoordFboAttr = null;
- private GLArrayDataServer indicesFbo = null;
-
- private GLContext context;
+ private GLArrayDataServer verticeTxtAttr;
+ private GLArrayDataServer texCoordTxtAttr;
+ private GLArrayDataServer indicesTxt;
+ private GLArrayDataServer verticeFboAttr;
+ private GLArrayDataServer texCoordFboAttr;
+ private GLArrayDataServer indicesFbo;
private boolean flipped = false;
- private boolean dirty = false;
+ private boolean dirty = true;
- private AABBox box = null;
- private FBObject fbo = null;
+ private AABBox box;
+ private FBObject fbo;
+ private PMVMatrix fboPMVMatrix;
+ GLUniformData mgl_fboPMVMatrix;
+
private int tex_width_c = 0;
private int tex_height_c = 0;
+ GLUniformData mgl_ActiveTexture;
+ int activeTexture; // texture engine 0 == GL.GL_TEXTURE0
- private ShaderState st;
-
- public VBORegion2PES2(GLContext context, ShaderState st){
- this.context =context;
- this.st = st;
+ public VBORegion2PES2(RenderState rs, int textureEngine) {
+ fboPMVMatrix = new PMVMatrix();
+ mgl_fboPMVMatrix = new GLUniformData(UniformNames.gcu_PMVMatrix, 4, 4, fboPMVMatrix.glGetPMvMatrixf());
- GL2ES2 gl = context.getGL().getGL2ES2();
+ activeTexture = GL.GL_TEXTURE0 + textureEngine;
+ mgl_ActiveTexture = new GLUniformData(UniformNames.gcu_TextureUnit, textureEngine);
- indicesFbo = GLArrayDataServer.createGLSL(gl, null, 3, GL2ES2.GL_SHORT, false,
- 2, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
+ final int initialSize = 256;
+ final ShaderState st = rs.getShaderState();
+
+ indicesFbo = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialSize, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
indicesFbo.puts((short) 0); indicesFbo.puts((short) 1); indicesFbo.puts((short) 3);
indicesFbo.puts((short) 1); indicesFbo.puts((short) 2); indicesFbo.puts((short) 3);
- indicesFbo.seal(gl, true);
+ indicesFbo.seal(true);
- texCoordFboAttr = GLArrayDataServer.createGLSL(gl, Region.TEXCOORD_ATTR_NAME, 2, GL2ES2.GL_FLOAT, false,
- 4, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER);
- texCoordFboAttr.setLocation(Region.TEXCOORD_ATTR_IDX);
+ texCoordFboAttr = GLArrayDataServer.createGLSL(st, AttributeNames.TEXCOORD_ATTR_NAME, 2,
+ GL2ES2.GL_FLOAT, false, initialSize, GL.GL_STATIC_DRAW);
+ st.bindAttribute(texCoordFboAttr);
texCoordFboAttr.putf(5); texCoordFboAttr.putf(5);
texCoordFboAttr.putf(5); texCoordFboAttr.putf(6);
texCoordFboAttr.putf(6); texCoordFboAttr.putf(6);
texCoordFboAttr.putf(6); texCoordFboAttr.putf(5);
- texCoordFboAttr.seal(gl, true);
+ texCoordFboAttr.seal(true);
- verticeFboAttr = GLArrayDataServer.createGLSL(gl, Region.VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT, false,
- 4, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER);
- verticeFboAttr.setLocation(Region.VERTEX_ATTR_IDX);
- verticeFboAttr.putf(0f); indicesFbo.putf(0f); indicesFbo.putf(0f);
- verticeFboAttr.putf(0f); indicesFbo.putf(0f); indicesFbo.putf(0f);
- verticeFboAttr.putf(0f); indicesFbo.putf(0f); indicesFbo.putf(0f);
- verticeFboAttr.putf(0f); indicesFbo.putf(0f); indicesFbo.putf(0f);
- verticeFboAttr.seal(gl, true);
+ verticeFboAttr = GLArrayDataServer.createGLSL(st, AttributeNames.VERTEX_ATTR_NAME, 3,
+ GL2ES2.GL_FLOAT, false, initialSize, GL.GL_STATIC_DRAW);
+ st.bindAttribute(verticeFboAttr);
- verticeFboAttr.enableBuffer(gl, false);
- texCoordFboAttr.enableBuffer(gl, false);
- indicesFbo.enableBuffer(gl, false);
- if(DEBUG) {
+
+ box = new AABBox();
+
+ indicesTxt = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialSize, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
+
+ verticeTxtAttr = GLArrayDataServer.createGLSL(st, AttributeNames.VERTEX_ATTR_NAME, 3,
+ GL2ES2.GL_FLOAT, false, initialSize, GL.GL_STATIC_DRAW);
+ st.bindAttribute(verticeTxtAttr);
+
+ texCoordTxtAttr = GLArrayDataServer.createGLSL(st, AttributeNames.TEXCOORD_ATTR_NAME, 2,
+ GL2ES2.GL_FLOAT, false, initialSize, GL.GL_STATIC_DRAW);
+ st.bindAttribute(texCoordTxtAttr);
+
+ if(DEBUG_INSTANCE) {
System.err.println("VBORegion2PES2 Create: " + this);
}
}
- public void update(){
- GL2ES2 gl = context.getGL().getGL2ES2();
-
- destroyTxtAttr(gl);
+ public void update(GL2ES2 gl){
+ if(!dirty) {
+ return;
+ }
- box = new AABBox();
-
- indicesTxt = GLArrayDataServer.createGLSL(gl, null, 3, GL2ES2.GL_SHORT, false,
- triangles.size(), GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
+ // process triangles
+ indicesTxt.seal(gl, false);
+ indicesTxt.rewind();
for(Triangle t:triangles){
if(t.getVertices()[0].getId() == Integer.MAX_VALUE){
t.getVertices()[0].setId(numVertices++);
@@ -144,10 +155,14 @@ public class VBORegion2PES2 implements Region {
}
}
indicesTxt.seal(gl, true);
+ indicesTxt.enableBuffer(gl, false);
- verticeTxtAttr = GLArrayDataServer.createGLSL(gl, Region.VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT, false,
- vertices.size(), GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER);
- verticeTxtAttr.setLocation(Region.VERTEX_ATTR_IDX);
+ // process vertices and update bbox
+ box.reset();
+ verticeTxtAttr.seal(gl, false);
+ verticeTxtAttr.rewind();
+ texCoordTxtAttr.seal(gl, false);
+ texCoordTxtAttr.rewind();
for(Vertex v:vertices){
verticeTxtAttr.putf(v.getX());
if(flipped){
@@ -161,52 +176,65 @@ public class VBORegion2PES2 implements Region {
} else {
box.resize(v.getX(), v.getY(), v.getZ());
}
- }
- verticeTxtAttr.seal(gl, true);
-
- texCoordTxtAttr = GLArrayDataServer.createGLSL(gl, Region.TEXCOORD_ATTR_NAME, 2, GL2ES2.GL_FLOAT, false,
- vertices.size(), GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER);
- texCoordTxtAttr.setLocation(Region.TEXCOORD_ATTR_IDX);
- for(Vertex v:vertices){
- float[] tex = v.getTexCoord();
+
+ final float[] tex = v.getTexCoord();
texCoordTxtAttr.putf(tex[0]);
- texCoordTxtAttr.putf(tex[1]);
+ texCoordTxtAttr.putf(tex[1]);
}
texCoordTxtAttr.seal(gl, true);
-
- // leave the buffers enabled for subsequent render call
+ texCoordTxtAttr.enableBuffer(gl, false);
+ verticeTxtAttr.seal(gl, true);
+ verticeTxtAttr.enableBuffer(gl, false);
+
+ // update all bbox related data
+ verticeFboAttr.seal(gl, false);
+ verticeFboAttr.rewind();
+ verticeFboAttr.putf(box.getLow()[0]); verticeFboAttr.putf(box.getLow()[1]); verticeFboAttr.putf(box.getLow()[2]);
+ verticeFboAttr.putf(box.getLow()[0]); verticeFboAttr.putf(box.getHigh()[1]); verticeFboAttr.putf(box.getLow()[2]);
+ verticeFboAttr.putf(box.getHigh()[0]); verticeFboAttr.putf(box.getHigh()[1]); verticeFboAttr.putf(box.getLow()[2]);
+ verticeFboAttr.putf(box.getHigh()[0]); verticeFboAttr.putf(box.getLow()[1]); verticeFboAttr.putf(box.getLow()[2]);
+ verticeFboAttr.seal(gl, true);
+ verticeFboAttr.enableBuffer(gl, false);
+
+ fboPMVMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
+ fboPMVMatrix.glLoadIdentity();
+ fboPMVMatrix.glOrthof(box.getLow()[0], box.getHigh()[0], box.getLow()[1], box.getHigh()[1], -1, 1);
+
+ // push data 2 GPU ..
+ indicesFbo.seal(gl, true);
+ indicesFbo.enableBuffer(gl, false);
dirty = false;
+
+ // the buffers were disabled, since due to real/fbo switching and other vbo usage
}
- public void render(PMVMatrix matrix, int vp_width, int vp_height, int width){
- GL2ES2 gl = context.getGL().getGL2ES2();
- if(null == matrix || vp_width <=0 || vp_height <= 0 || width <= 0){
+ public void render(GL2ES2 gl, RenderState rs, int vp_width, int vp_height, int width) {
+ if(vp_width <=0 || vp_height <= 0 || width <= 0){
renderRegion(gl);
} else {
if(width != tex_width_c){
- renderRegion2FBO(gl, matrix, width);
- setupBBox2FboAttr(gl);
+ renderRegion2FBO(gl, rs, width);
}
-// System.out.println("Scale: " + matrix.glGetMatrixf().get(1+4*3) +" " + matrix.glGetMatrixf().get(2+4*3));
- renderFBO(gl, matrix, vp_width, vp_height);
+ // System.out.println("Scale: " + matrix.glGetMatrixf().get(1+4*3) +" " + matrix.glGetMatrixf().get(2+4*3));
+ renderFBO(gl, rs, vp_width, vp_height);
}
}
- private void renderFBO(GL2ES2 gl, PMVMatrix matrix, int width, int hight) {
- gl.glViewport(0, 0, width, hight);
- if(!st.glUniform(gl, new GLUniformData("mgl_PMVMatrix", 4, 4, matrix.glGetPMvMatrixf()))){
- System.out.println("Cnt set tex based mat");
- }
- gl.glEnable(GL2ES2.GL_TEXTURE_2D);
- gl.glActiveTexture(GL2ES2.GL_TEXTURE0);
- fbo.use(gl);
+ private void renderFBO(GL2ES2 gl, RenderState rs, int width, int hight) {
+ final ShaderState st = rs.getShaderState();
- st.glUniform(gl, new GLUniformData("texture", fbo.getTextureName()));
- int loc = gl.glGetUniformLocation(st.shaderProgram().program(), "texture");
- gl.glUniform1i(loc, 0);
+ gl.glViewport(0, 0, width, hight);
+ gl.glEnable(GL2ES2.GL_TEXTURE_2D);
+ /* setback:
+ int[] currentActiveTextureEngine = new int[1];
+ gl.glGetIntegerv(GL.GL_ACTIVE_TEXTURE, currentActiveTextureEngine, 0);
+ */
+ gl.glActiveTexture(activeTexture);
+ st.glUniform(gl, mgl_ActiveTexture);
+ fbo.use(gl);
verticeFboAttr.enableBuffer(gl, true);
texCoordFboAttr.enableBuffer(gl, true);
indicesFbo.enableBuffer(gl, true);
@@ -215,22 +243,15 @@ public class VBORegion2PES2 implements Region {
verticeFboAttr.enableBuffer(gl, false);
texCoordFboAttr.enableBuffer(gl, false);
- indicesFbo.enableBuffer(gl, false);
- }
-
- private void setupBBox2FboAttr(GL2ES2 gl){
- verticeFboAttr.seal(gl, false);
- verticeFboAttr.rewind();
-
- verticeFboAttr.putf(box.getLow()[0]); verticeFboAttr.putf(box.getLow()[1]); verticeFboAttr.putf(box.getLow()[2]);
- verticeFboAttr.putf(box.getLow()[0]); verticeFboAttr.putf(box.getHigh()[1]); verticeFboAttr.putf(box.getLow()[2]);
- verticeFboAttr.putf(box.getHigh()[0]); verticeFboAttr.putf(box.getHigh()[1]); verticeFboAttr.putf(box.getLow()[2]);
- verticeFboAttr.putf(box.getHigh()[0]); verticeFboAttr.putf(box.getLow()[1]); verticeFboAttr.putf(box.getLow()[2]);
+ indicesFbo.enableBuffer(gl, false);
+ fbo.unuse(gl);
- verticeFboAttr.seal(gl, true);
+ // setback: gl.glActiveTexture(currentActiveTextureEngine[0]);
}
- private void renderRegion2FBO(GL2ES2 gl, PMVMatrix m, int tex_width){
+ private void renderRegion2FBO(GL2ES2 gl, RenderState rs, int tex_width) {
+ final ShaderState st = rs.getShaderState();
+
tex_width_c = tex_width;
tex_height_c = (int)(tex_width_c*box.getHeight()/box.getWidth());
@@ -253,21 +274,15 @@ public class VBORegion2PES2 implements Region {
}
//render texture
- PMVMatrix tex_matrix = new PMVMatrix();
gl.glViewport(0, 0, tex_width_c, tex_height_c);
- tex_matrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
- tex_matrix.glLoadIdentity();
- tex_matrix.glOrthof(box.getLow()[0], box.getHigh()[0], box.getLow()[1], box.getHigh()[1], -1, 1);
-
- if(!st.glUniform(gl, new GLUniformData("mgl_PMVMatrix", 4, 4, tex_matrix.glGetPMvMatrixf()))){
- System.out.println("Cnt set tex based mat");
- }
+ st.glUniform(gl, mgl_fboPMVMatrix); // use orthogonal matrix
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glClear(GL2ES2.GL_COLOR_BUFFER_BIT | GL2ES2.GL_DEPTH_BUFFER_BIT);
renderRegion(gl);
-
fbo.unbind(gl);
+
+ st.glUniform(gl, rs.getPMVMatrixUniform()); // switch back to real PMV matrix
}
private void renderRegion(GL2ES2 gl) {
@@ -301,11 +316,10 @@ public class VBORegion2PES2 implements Region {
return dirty;
}
- public void destroy() {
- if(DEBUG) {
+ public void destroy(GL2ES2 gl) {
+ if(DEBUG_INSTANCE) {
System.err.println("VBORegion2PES2 Destroy: " + this);
- }
- GL2ES2 gl = context.getGL().getGL2ES2();
+ }
destroyFbo(gl);
destroyTxtAttr(gl);
destroyFboAttr(gl);
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
index 83cd6b80d..1b295de16 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
@@ -31,14 +31,16 @@ import java.util.ArrayList;
import javax.media.opengl.GL;
import javax.media.opengl.GL2ES2;
-import javax.media.opengl.GLContext;
+
+import jogamp.graph.curve.opengl.shader.AttributeNames;
import com.jogamp.graph.curve.Region;
+import com.jogamp.graph.curve.opengl.RenderState;
import com.jogamp.graph.geom.AABBox;
import com.jogamp.graph.geom.Vertex;
import com.jogamp.graph.geom.Triangle;
import com.jogamp.opengl.util.GLArrayDataServer;
-import com.jogamp.opengl.util.PMVMatrix;
+import com.jogamp.opengl.util.glsl.ShaderState;
public class VBORegionSPES2 implements Region {
private int numVertices = 0;
@@ -49,25 +51,40 @@ public class VBORegionSPES2 implements Region {
private GLArrayDataServer texCoordAttr = null;
private GLArrayDataServer indices = null;
- private GLContext context;
-
private boolean flipped = false;
- private boolean dirty = false;
+ private boolean dirty = true;
private AABBox box = null;
- public VBORegionSPES2(GLContext context){
- this.context =context;
+ public VBORegionSPES2(RenderState rs){
+ box = new AABBox();
+
+ final int initialSize = 256;
+ final ShaderState st = rs.getShaderState();
+
+ indices = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialSize, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
+
+ verticeAttr = GLArrayDataServer.createGLSL(st, AttributeNames.VERTEX_ATTR_NAME, 3,
+ GL2ES2.GL_FLOAT, false, initialSize, GL.GL_STATIC_DRAW);
+ st.bindAttribute(verticeAttr);
+
+ texCoordAttr = GLArrayDataServer.createGLSL(st, AttributeNames.TEXCOORD_ATTR_NAME, 2,
+ GL2ES2.GL_FLOAT, false, initialSize, GL.GL_STATIC_DRAW);
+ st.bindAttribute(texCoordAttr);
+
+ if(DEBUG_INSTANCE) {
+ System.err.println("VBORegionSPES2 Create: " + this);
+ }
}
- public void update(){
- box = new AABBox();
- GL2ES2 gl = context.getGL().getGL2ES2();
+ public void update(GL2ES2 gl){
+ if(!dirty) {
+ return;
+ }
- destroy(gl);
-
- indices = GLArrayDataServer.createGLSL(gl, null, 3, GL2ES2.GL_SHORT, false,
- triangles.size(), GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
+ // process triangles
+ indices.seal(gl, false);
+ indices.rewind();
for(Triangle t:triangles){
final Vertex[] t_vertices = t.getVertices();
@@ -95,12 +112,15 @@ public class VBORegionSPES2 implements Region {
}
}
indices.seal(gl, true);
+ indices.enableBuffer(gl, false);
- verticeAttr = GLArrayDataServer.createGLSL(gl, Region.VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT, false,
- vertices.size(), GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER);
- verticeAttr.setLocation(Region.VERTEX_ATTR_IDX);
- for(Vertex v:vertices){
-
+ // process vertices and update bbox
+ box.reset();
+ verticeAttr.seal(gl, false);
+ verticeAttr.rewind();
+ texCoordAttr.seal(gl, false);
+ texCoordAttr.rewind();
+ for(Vertex v:vertices){
if(flipped){
verticeAttr.putf(v.getX());
verticeAttr.putf(-1*v.getY());
@@ -115,29 +135,24 @@ public class VBORegionSPES2 implements Region {
box.resize(v.getX(),v.getY(),v.getZ());
}
- }
- verticeAttr.seal(gl, true);
-
- texCoordAttr = GLArrayDataServer.createGLSL(gl, Region.TEXCOORD_ATTR_NAME, 2, GL2ES2.GL_FLOAT, false,
- vertices.size(), GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER);
- texCoordAttr.setLocation(Region.TEXCOORD_ATTR_IDX);
- for(Vertex v:vertices){
- float[] tex = v.getTexCoord();
+
+ final float[] tex = v.getTexCoord();
texCoordAttr.putf(tex[0]);
texCoordAttr.putf(tex[1]);
}
+ verticeAttr.seal(gl, true);
+ verticeAttr.enableBuffer(gl, false);
texCoordAttr.seal(gl, true);
-
- verticeAttr.enableBuffer(gl, false);
texCoordAttr.enableBuffer(gl, false);
- indices.enableBuffer(gl, false);
+
+ // update all bbox related data: nope
dirty = false;
+
+ // the buffers were disabled, since due to real/fbo switching and other vbo usage
}
- private void render() {
- GL2ES2 gl = context.getGL().getGL2ES2();
-
+ private void render(GL2ES2 gl) {
verticeAttr.enableBuffer(gl, true);
texCoordAttr.enableBuffer(gl, true);
indices.enableBuffer(gl, true);
@@ -149,8 +164,8 @@ public class VBORegionSPES2 implements Region {
indices.enableBuffer(gl, false);
}
- public void render(PMVMatrix matrix, int vp_width, int vp_height, int width){
- render();
+ public void render(GL2ES2 gl, RenderState rs, int vp_width, int vp_height, int width) {
+ render(gl);
}
public void addTriangles(ArrayList<Triangle> tris) {
@@ -172,12 +187,10 @@ public class VBORegionSPES2 implements Region {
return dirty;
}
- public void destroy() {
- GL2ES2 gl = context.getGL().getGL2ES2();
- destroy(gl);
- }
-
- final void destroy(GL2ES2 gl) {
+ public final void destroy(GL2ES2 gl) {
+ if(DEBUG_INSTANCE) {
+ System.err.println("VBORegionSPES2 Destroy: " + this);
+ }
if(null != verticeAttr) {
verticeAttr.destroy(gl);
verticeAttr = null;
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/AttributeNames.java b/src/jogl/classes/jogamp/graph/curve/opengl/shader/AttributeNames.java
new file mode 100644
index 000000000..9fe084522
--- /dev/null
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/AttributeNames.java
@@ -0,0 +1,18 @@
+package jogamp.graph.curve.opengl.shader;
+
+public class AttributeNames {
+ /** The vertices index in an OGL object
+ */
+ public static final int VERTEX_ATTR_IDX = 1; // 0 is a generic special 0 ..
+ public static final String VERTEX_ATTR_NAME = "gca_Vertices";
+
+ /** The Texture Coord index in an OGL object
+ */
+ public static final int TEXCOORD_ATTR_IDX = 2;
+ public static final String TEXCOORD_ATTR_NAME = "gca_TexCoords";
+
+ /** The color index in an OGL object
+ */
+ public static final int COLOR_ATTR_IDX = 3;
+ public static final String COLOR_ATTR_NAME = "gca_Colors";
+}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/UniformNames.java b/src/jogl/classes/jogamp/graph/curve/opengl/shader/UniformNames.java
new file mode 100644
index 000000000..2e04278ca
--- /dev/null
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/UniformNames.java
@@ -0,0 +1,10 @@
+package jogamp.graph.curve.opengl.shader;
+
+public class UniformNames {
+ public static final String gcu_PMVMatrix = "gcu_PMVMatrix"; // gcu_PMVMatrix[3]; // P, Mv, and Mvi
+ public static final String gcu_ColorStatic = "gcu_ColorStatic";
+ public static final String gcu_Alpha = "gcu_Alpha";
+ public static final String gcu_P1Y = "gcu_P1Y";
+ public static final String gcu_Strength = "gcu_Strength";
+ public static final String gcu_TextureUnit = "gcu_TextureUnit";
+}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/attributes.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/attributes.glsl
new file mode 100644
index 000000000..e5ae2b42e
--- /dev/null
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/attributes.glsl
@@ -0,0 +1,12 @@
+
+#ifndef attributes_glsl
+#define attributes_glsl
+
+#include precision.glsl
+
+attribute HIGHP vec3 gca_Vertices;
+attribute HIGHP vec2 gca_TexCoords;
+//attribute HIGHP vec4 gca_Colors;
+//attribute HIGHP vec3 gca_Normals;
+
+#endif // attributes_glsl
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/consts.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/consts.glsl
new file mode 100644
index 000000000..4cb41c903
--- /dev/null
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/consts.glsl
@@ -0,0 +1,10 @@
+
+#ifndef consts_glsl
+#define consts_glsl
+
+#include precision.glsl
+
+const LOWP int MAX_TEXTURE_UNITS = 8; // <= gl_MaxTextureImageUnits
+// const LOWP int MAX_LIGHTS = 8;
+
+#endif // consts_glsl
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.fp
index 166937f7f..fca3bcc04 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.fp
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.fp
@@ -1,93 +1,93 @@
//Copyright 2010 JogAmp Community. All rights reserved.
-//#version 100
-uniform float p1y;
-uniform float g_alpha;
-uniform vec3 g_color;
-uniform float a_strength;
+#ifdef GL_ES
+ #version 100
+#else
+ #version 130
+#endif
-varying vec2 v_texCoord;
+#include uniforms.glsl
+#include attributes.glsl
+#include varyings.glsl
-vec3 b_color = vec3(0.0, 0.0, 0.0);
-
-uniform sampler2D texture;
-vec4 weights = vec4(0.075, 0.06, 0.045, 0.025);
+const vec3 b_color = vec3(0.0, 0.0, 0.0);
+const vec4 weights = vec4(0.075, 0.06, 0.045, 0.025);
void main (void)
{
- vec2 rtex = vec2(abs(v_texCoord.x),abs(v_texCoord.y));
- vec3 c = g_color;
+ vec2 rtex = vec2(abs(gcv_TexCoord.x),abs(gcv_TexCoord.y));
+ vec3 c = gcu_ColorStatic.rgb;
float alpha = 0.0;
- if((v_texCoord.x == 0.0) && (v_texCoord.y == 0.0)){
- alpha = g_alpha;
+ if((gcv_TexCoord.x == 0.0) && (gcv_TexCoord.y == 0.0)){
+ alpha = gcu_Alpha;
}
- else if((v_texCoord.x >= 5.0)){
- vec2 dfx = dFdx(v_texCoord);
- vec2 dfy = dFdy(v_texCoord);
+ else if((gcv_TexCoord.x >= 5.0)){
+ vec2 dfx = dFdx(gcv_TexCoord);
+ vec2 dfy = dFdy(gcv_TexCoord);
- vec2 size = 1.0/textureSize(texture,0); //version 130
+ vec2 size = 1.0/textureSize(gcu_TextureUnit,0); //version 130 - FIXME: replace with uniform value
rtex -= 5.0;
- vec4 t = texture2D(texture, rtex)* 0.18;
+ vec4 t = texture2D(gcu_TextureUnit, rtex)* 0.18;
- t += texture2D(texture, rtex + size*(vec2(1, 0)))*weights.x;
- t += texture2D(texture, rtex - size*(vec2(1, 0)))*weights.x;
- t += texture2D(texture, rtex + size*(vec2(0, 1)))*weights.x;
- t += texture2D(texture, rtex - size*(vec2(0, 1)))*weights.x;
+ t += texture2D(gcu_TextureUnit, rtex + size*(vec2(1, 0)))*weights.x;
+ t += texture2D(gcu_TextureUnit, rtex - size*(vec2(1, 0)))*weights.x;
+ t += texture2D(gcu_TextureUnit, rtex + size*(vec2(0, 1)))*weights.x;
+ t += texture2D(gcu_TextureUnit, rtex - size*(vec2(0, 1)))*weights.x;
- t += texture2D(texture, rtex + 2.0*size*(vec2(1, 0))) *weights.y;
- t += texture2D(texture, rtex - 2.0*size*(vec2(1, 0)))*weights.y;
- t += texture2D(texture, rtex + 2.0*size*(vec2(0, 1)))*weights.y;
- t += texture2D(texture, rtex - 2.0*size*(vec2(0, 1)))*weights.y;
+ t += texture2D(gcu_TextureUnit, rtex + 2.0*size*(vec2(1, 0)))*weights.y;
+ t += texture2D(gcu_TextureUnit, rtex - 2.0*size*(vec2(1, 0)))*weights.y;
+ t += texture2D(gcu_TextureUnit, rtex + 2.0*size*(vec2(0, 1)))*weights.y;
+ t += texture2D(gcu_TextureUnit, rtex - 2.0*size*(vec2(0, 1)))*weights.y;
- t += texture2D(texture, rtex + 3.0*size*(vec2(1, 0))) *weights.z;
- t += texture2D(texture, rtex - 3.0*size*(vec2(1, 0)))*weights.z;
- t += texture2D(texture, rtex + 3.0*size*(vec2(0, 1)))*weights.z;
- t += texture2D(texture, rtex - 3.0*size*(vec2(0, 1)))*weights.z;
+ t += texture2D(gcu_TextureUnit, rtex + 3.0*size*(vec2(1, 0)))*weights.z;
+ t += texture2D(gcu_TextureUnit, rtex - 3.0*size*(vec2(1, 0)))*weights.z;
+ t += texture2D(gcu_TextureUnit, rtex + 3.0*size*(vec2(0, 1)))*weights.z;
+ t += texture2D(gcu_TextureUnit, rtex - 3.0*size*(vec2(0, 1)))*weights.z;
- t += texture2D(texture, rtex + 4.0*size*(vec2(1, 0))) *weights.w;
- t += texture2D(texture, rtex - 4.0*size*(vec2(1, 0)))*weights.w;
- t += texture2D(texture, rtex + 4.0*size*(vec2(0, 1)))*weights.w;
- t += texture2D(texture, rtex - 4.0*size*(vec2(0, 1)))*weights.w;
+ t += texture2D(gcu_TextureUnit, rtex + 4.0*size*(vec2(1, 0)))*weights.w;
+ t += texture2D(gcu_TextureUnit, rtex - 4.0*size*(vec2(1, 0)))*weights.w;
+ t += texture2D(gcu_TextureUnit, rtex + 4.0*size*(vec2(0, 1)))*weights.w;
+ t += texture2D(gcu_TextureUnit, rtex - 4.0*size*(vec2(0, 1)))*weights.w;
if(t.w == 0.0){
discard;
}
c = t.xyz;
- alpha = g_alpha* t.w;
+ alpha = gcu_Alpha * t.w;
}
///////////////////////////////////////////////////////////
- else if ((v_texCoord.x > 0.0) && (rtex.y > 0.0 || rtex.x == 1.0)){
- vec2 dtx = dFdx(rtex);
- vec2 dty = dFdy(rtex);
+ else if ((gcv_TexCoord.x > 0.0) && (rtex.y > 0.0 || rtex.x == 1.0)){
+ vec2 dtx = dFdx(rtex);
+ vec2 dty = dFdy(rtex);
- rtex.y -= 0.1;
+ rtex.y -= 0.1;
- if(rtex.y < 0.0) {
- if(v_texCoord.y < 0.0)
- discard;
- else{
- rtex.y = 0.0;
- }
- }
+ if(rtex.y < 0.0) {
+ if(gcv_TexCoord.y < 0.0)
+ discard;
+ else{
+ rtex.y = 0.0;
+ }
+ }
- vec2 f = vec2((dtx.y - dtx.x + 2.0*rtex.x*dtx.x), (dty.y - dty.x + 2.0*rtex.x*dty.x));
- float position = rtex.y - (rtex.x * (1.0 - rtex.x));
- float d = position/(length(f));
+ vec2 f = vec2((dtx.y - dtx.x + 2.0*rtex.x*dtx.x), (dty.y - dty.x + 2.0*rtex.x*dty.x));
+ float position = rtex.y - (rtex.x * (1.0 - rtex.x));
+ float d = position/(length(f));
- float a = (0.5 - d * sign(v_texCoord.y));
+ float a = (0.5 - d * sign(gcv_TexCoord.y));
if (a >= 1.0) {
- alpha = g_alpha;
+ alpha = gcu_Alpha;
}
- else if (a <= 0.0) {
- alpha = 0.0;//discard;
- }
- else {
- alpha = g_alpha*a;
- mix(b_color,g_color, a);
+ else if (a <= 0.0) {
+ alpha = 0.0;//discard;
+ }
+ else {
+ alpha = gcu_Alpha * a;
+ mix(b_color,gcu_ColorStatic.rgb, a);
}
}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.vp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.vp
index bc9ecb41e..298dce7ef 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.vp
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.vp
@@ -1,13 +1,17 @@
-//#version 100
+//Copyright 2010 JogAmp Community. All rights reserved.
-uniform mat4 mgl_PMVMatrix[2];
-attribute vec4 v_position;
-attribute vec2 texCoord;
+#ifdef GL_ES
+ #version 100
+#else
+ #version 110
+#endif
-varying vec2 v_texCoord;
+#include uniforms.glsl
+#include attributes.glsl
+#include varyings.glsl
void main(void)
{
- gl_Position = mgl_PMVMatrix[0] * mgl_PMVMatrix[1] * v_position;
- v_texCoord = texCoord.st;
-} \ No newline at end of file
+ gl_Position = gcu_PMVMatrix[0] * gcu_PMVMatrix[1] * vec4(gca_Vertices, 1);
+ gcv_TexCoord = gca_TexCoords;
+}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/precision.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/precision.glsl
new file mode 100644
index 000000000..1ac4ed8e9
--- /dev/null
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/precision.glsl
@@ -0,0 +1,14 @@
+#ifndef precision_glsl
+#define precision_glsl
+
+#ifdef GL_ES
+ #define MEDIUMP mediump
+ #define HIGHP highp
+ #define LOWP lowp
+#else
+ #define MEDIUMP
+ #define HIGHP
+ #define LOWP
+#endif
+
+#endif // precision_glsl
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl
new file mode 100644
index 000000000..677c7324f
--- /dev/null
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl
@@ -0,0 +1,21 @@
+
+#ifndef uniforms_glsl
+#define uniforms_glsl
+
+#include precision.glsl
+
+// #include consts.glsl
+
+uniform HIGHP mat4 gcu_PMVMatrix[3]; // P, Mv, and Mvi
+uniform HIGHP vec3 gcu_ColorStatic;
+uniform HIGHP float gcu_Alpha;
+uniform HIGHP float gcu_P1Y;
+uniform HIGHP float gcu_Strength;
+uniform sampler2D gcu_TextureUnit;
+
+// uniform HIGHP mat3 gcu_NormalMatrix; // transpose(inverse(ModelView)).3x3
+// uniform LOWP int gcu_ColorEnabled;
+// uniform LOWP int gcu_TexCoordEnabled[MAX_TEXTURE_UNITS];
+// uniform LOWP int gcu_CullFace;
+
+#endif // uniforms_glsl
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/varyings.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/varyings.glsl
new file mode 100644
index 000000000..e70c25266
--- /dev/null
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/varyings.glsl
@@ -0,0 +1,13 @@
+
+#ifndef varyings_glsl
+#define varyings_glsl
+
+#include precision.glsl
+
+#include consts.glsl
+
+varying vec4 gcv_FrontColor;
+varying vec2 gcv_TexCoord;
+
+#endif // varyings_glsl
+
diff --git a/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java b/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java
index 705613447..8f7dcf30a 100644
--- a/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java
+++ b/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java
@@ -32,9 +32,10 @@ import java.util.ArrayList;
import com.jogamp.graph.geom.AABBox;
import com.jogamp.graph.geom.Vertex;
import com.jogamp.graph.geom.Triangle;
+import com.jogamp.graph.geom.Vertex.Factory;
import com.jogamp.graph.geom.opengl.SVertex;
-import javax.media.opengl.GLContext;
+import javax.media.opengl.GL2ES2;
import jogamp.graph.geom.plane.AffineTransform;
import jogamp.graph.geom.plane.Path2D;
@@ -43,11 +44,10 @@ import jogamp.graph.geom.plane.PathIterator;
import com.jogamp.graph.curve.Region;
import com.jogamp.graph.curve.RegionFactory;
-import com.jogamp.opengl.util.PMVMatrix;
+import com.jogamp.graph.curve.opengl.RenderState;
import com.jogamp.opengl.util.glsl.ShaderState;
public class GlyphString {
- private final Vertex.Factory<? extends Vertex> pointFactory;
private ArrayList<GlyphShape> glyphs = new ArrayList<GlyphShape>();
private String str = "";
private String fontname = "";
@@ -60,14 +60,11 @@ public class GlyphString {
* associated with
* @param str the string object
*/
- public GlyphString(Vertex.Factory<? extends Vertex> factory, String fontname, String str){
- pointFactory = factory;
+ public GlyphString(String fontname, String str){
this.fontname = fontname;
this.str = str;
}
- public final Vertex.Factory<? extends Vertex> pointFactory() { return pointFactory; }
-
public void addGlyphShape(GlyphShape glyph){
glyphs.add(glyph);
}
@@ -76,10 +73,11 @@ public class GlyphString {
}
/** Creates the Curve based Glyphs from a Font
+ * @param pointFactory TODO
* @param paths a list of FontPath2D objects that define the outline
* @param affineTransform a global affine transformation applied to the paths.
*/
- public void createfromFontPath(Path2D[] paths, AffineTransform affineTransform){
+ public void createfromFontPath(Factory<? extends Vertex> pointFactory, Path2D[] paths, AffineTransform affineTransform) {
final int numGlyps = paths.length;
for (int index=0;index<numGlyps;index++){
if(paths[index] == null){
@@ -109,11 +107,11 @@ public class GlyphString {
* @param shaprness the curvature sharpness of the object.
* @param st shader state
*/
- public void generateRegion(GLContext context, float shaprness, ShaderState st, int type){
- region = RegionFactory.create(context, st, type);
+ public void generateRegion(GL2ES2 gl, RenderState rs, int type){
+ region = RegionFactory.create(rs, type);
region.setFlipped(true);
- ArrayList<Triangle> tris = initializeTriangles(shaprness);
+ ArrayList<Triangle> tris = initializeTriangles(rs.getSharpness().floatValue());
region.addTriangles(tris);
int numVertices = region.getNumVertices();
@@ -126,7 +124,7 @@ public class GlyphString {
}
/** initialize the region */
- region.update();
+ region.update(gl);
}
/** Generate a Hashcode for this object
@@ -139,17 +137,17 @@ public class GlyphString {
/** Render the Object based using the associated Region
* previously generated.
*/
- public void renderString3D() {
- region.render(null, 0, 0, 0);
+ public void renderString3D(GL2ES2 gl) {
+ region.render(gl, null, 0, 0, 0);
}
/** Render the Object based using the associated Region
* previously generated.
*/
- public void renderString3D(PMVMatrix matrix, int vp_width, int vp_height, int size) {
- region.render(matrix, vp_width, vp_height, size);
+ public void renderString3D(GL2ES2 gl, RenderState rs, int vp_width, int vp_height, int size) {
+ region.render(gl, rs, vp_width, vp_height, size);
}
- /** Get the Origion of this GlyphString
+ /** Get the Origin of this GlyphString
* @return
*/
public Vertex getOrigin() {
@@ -158,8 +156,8 @@ public class GlyphString {
/** Destroy the associated OGL objects
*/
- public void destroy(){
- region.destroy();
+ public void destroy(GL2ES2 gl){
+ region.destroy(gl);
}
public AABBox getBounds(){