aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com
diff options
context:
space:
mode:
Diffstat (limited to 'src/jogl/classes/com')
-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
8 files changed, 418 insertions, 179 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) {