diff options
Diffstat (limited to 'src')
37 files changed, 871 insertions, 430 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/curve/Region.java b/src/jogl/classes/com/jogamp/graph/curve/Region.java index 7edd2f572..230fa324d 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/Region.java +++ b/src/jogl/classes/com/jogamp/graph/curve/Region.java @@ -37,6 +37,7 @@ import com.jogamp.graph.geom.Triangle; import com.jogamp.graph.geom.Vertex; import com.jogamp.opengl.math.geom.AABBox; import com.jogamp.opengl.math.geom.Frustum; +import com.jogamp.opengl.util.texture.TextureSequence; /** * Abstract Outline shape representation define the method an OutlineShape(s) @@ -102,7 +103,7 @@ public abstract class Region { /** Default maximum {@link #getQuality() quality}, {@value}. */ public static final int MAX_QUALITY = 1; - public static final int TWO_PASS_DEFAULT_TEXTURE_UNIT = 0; + public static final int DEFAULT_TWO_PASS_TEXTURE_UNIT = 0; private final int renderModes; private int quality; @@ -175,7 +176,7 @@ public abstract class Region { protected abstract void pushIndex(int idx); /** - * Return bit-field of render modes, see {@link #create(int)}. + * Return bit-field of render modes, see {@link #create(int, TextureSequence)}. */ public final int getRenderModes() { return renderModes; } @@ -369,19 +370,33 @@ public abstract class Region { return box; } - /** Check if this region is dirty. A region is marked dirty when new - * Vertices, Triangles, and or Lines are added after a call to update() + /** + * Check if this region is dirty. A region is marked dirty when new + * Vertices, Triangles, and or Lines are added after a call to update(). + * <p> + * A region is also dirty if other render attributes or parameters are changed! + * </p> * * @return true if region is Dirty, false otherwise * - * @see update(GL2ES2) */ + * @see update(GL2ES2) + */ public final boolean isDirty() { return dirty; } + /** + * See {@link #isDirty()}. + */ protected final void setDirty(boolean v) { dirty = v; } + /** + * See {@link #isDirty()}. + */ + public final void markDirty() { + dirty = true; + } public String toString() { return "Region["+getRenderModeString(this.renderModes)+", q "+quality+", dirty "+dirty+", vertices "+numVertices+", box "+box+"]"; diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java index 9505f2a9d..3c6045a1f 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java @@ -35,6 +35,7 @@ import jogamp.graph.curve.opengl.VBORegion2PVBAAES2; import jogamp.graph.curve.opengl.VBORegionSPES2;
import com.jogamp.opengl.util.PMVMatrix;
+import com.jogamp.opengl.util.texture.TextureSequence;
import com.jogamp.graph.curve.Region;
/** A GLRegion is the OGL binding of one or more OutlineShapes
@@ -53,23 +54,31 @@ public abstract class GLRegion extends Region { * Create a GLRegion using the passed render mode
*
* <p> In case {@link Region#VBAA_RENDERING_BIT} is being requested the default texture unit
- * {@link Region#TWO_PASS_DEFAULT_TEXTURE_UNIT} is being used.</p>
- *
- * @param rs the RenderState to be used
+ * {@link Region#DEFAULT_TWO_PASS_TEXTURE_UNIT} is being used.</p>
* @param renderModes bit-field of modes, e.g. {@link Region#VARWEIGHT_RENDERING_BIT}, {@link Region#VBAA_RENDERING_BIT}
+ * @param colorTexSeq TODO
+ * @param rs the RenderState to be used
*/
- public static GLRegion create(int renderModes) {
+ public static GLRegion create(int renderModes, final TextureSequence colorTexSeq) {
+ if( null != colorTexSeq ) {
+ renderModes |= Region.COLORTEXTURE_RENDERING_BIT;
+ } else if( Region.hasColorTexture(renderModes) ) {
+ throw new IllegalArgumentException("COLORTEXTURE_RENDERING_BIT set but null TextureSequence");
+ }
if( isVBAA(renderModes) ) {
- return new VBORegion2PVBAAES2(renderModes, Region.TWO_PASS_DEFAULT_TEXTURE_UNIT);
+ return new VBORegion2PVBAAES2(renderModes, colorTexSeq, Region.DEFAULT_TWO_PASS_TEXTURE_UNIT);
} else if( isMSAA(renderModes) ) {
- return new VBORegion2PMSAAES2(renderModes, Region.TWO_PASS_DEFAULT_TEXTURE_UNIT);
+ return new VBORegion2PMSAAES2(renderModes, colorTexSeq, Region.DEFAULT_TWO_PASS_TEXTURE_UNIT);
} else {
- return new VBORegionSPES2(renderModes);
+ return new VBORegionSPES2(renderModes, colorTexSeq);
}
}
- protected GLRegion(int renderModes) {
+ protected final TextureSequence colorTexSeq;
+
+ protected GLRegion(int renderModes, TextureSequence colorTexSeq) {
super(renderModes);
+ this.colorTexSeq = colorTexSeq;
}
/**
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 ade6098e1..8724baff8 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java @@ -139,9 +139,6 @@ public class RegionRenderer { public final int getHeight() { return vp_height; } public final PMVMatrix getMatrix() { return rs.getMatrix(); } - public final PMVMatrix getMatrixMutable() { return rs.getMatrixMutable(); } - public final void setMatrixDirty() { rs.setMatrixDirty(); } - public final boolean isMatrixDirty() { return rs.isMatrixDirty(); } ////////////////////////////////////// @@ -190,12 +187,6 @@ public class RegionRenderer { if( null != enableCallback ) { enableCallback.run(gl, this); } - - useShaderProgram(gl, renderModes, true, 0, 0); - initialized = rs.update(gl, true, renderModes, true); - if(!initialized) { - throw new GLException("Shader initialization failed"); - } } public final void destroy(GL2ES2 gl) { @@ -247,14 +238,13 @@ public class RegionRenderer { public final void reshapeNotify(int width, int height) { this.vp_width = width; this.vp_height = height; - rs.setMatrixDirty(); } public final void reshapePerspective(float angle, int width, int height, float near, float far) { this.vp_width = width; this.vp_height = height; final float ratio = (float)width/(float)height; - final PMVMatrix p = rs.getMatrixMutable(); + final PMVMatrix p = rs.getMatrix(); p.glMatrixMode(GLMatrixFunc.GL_PROJECTION); p.glLoadIdentity(); p.gluPerspective(angle, ratio, near, far); @@ -263,7 +253,7 @@ public class RegionRenderer { public final void reshapeOrtho(int width, int height, float near, float far) { this.vp_width = width; this.vp_height = height; - final PMVMatrix p = rs.getMatrixMutable(); + final PMVMatrix p = rs.getMatrix(); p.glMatrixMode(GLMatrixFunc.GL_PROJECTION); p.glLoadIdentity(); p.glOrthof(0, width, 0, height, near, far); @@ -368,6 +358,7 @@ public class RegionRenderer { private final IntObjectHashMap shaderPrograms = new IntObjectHashMap(); private static final int HIGH_MASK = Region.COLORCHANNEL_RENDERING_BIT | Region.COLORTEXTURE_RENDERING_BIT; + private static final int TWO_PASS_BIT = 1 << 31; /** * @param gl @@ -382,7 +373,8 @@ public class RegionRenderer { final boolean pass1, final int quality, final int sampleCount) { final ShaderModeSelector1 sel1 = pass1 ? ShaderModeSelector1.selectPass1(renderModes) : ShaderModeSelector1.selectPass2(renderModes, quality, sampleCount); - final int shaderKey = sel1.ordinal() | ( HIGH_MASK & renderModes ); + final boolean isTwoPass = Region.isTwoPass( renderModes ); + final int shaderKey = sel1.ordinal() | ( HIGH_MASK & renderModes ) | ( isTwoPass ? TWO_PASS_BIT : 0 ); /** if(DEBUG) { @@ -395,14 +387,16 @@ public class RegionRenderer { final boolean spChanged = getRenderState().setShaderProgram(gl, sp); if(DEBUG) { if( spChanged ) { - System.err.printf("RegionRendererImpl01.useShaderProgram.X1: GOT renderModes %s, sel1 %s, key 0x%X (changed)%n", Region.getRenderModeString(renderModes), sel1, shaderKey); + System.err.printf("RegionRendererImpl01.useShaderProgram.X1: GOT renderModes %s, sel1 %s, key 0x%X -> sp %d / %d (changed)%n", Region.getRenderModeString(renderModes), sel1, shaderKey, sp.program(), sp.id()); + } else { + System.err.printf("RegionRendererImpl01.useShaderProgram.X1: GOT renderModes %s, sel1 %s, key 0x%X -> sp %d / %d (keep)%n", Region.getRenderModeString(renderModes), sel1, shaderKey, sp.program(), sp.id()); } } return spChanged; } final String versionedBaseName = getVersionedShaderName(); final String vertexShaderName; - if( Region.isTwoPass( renderModes ) ) { + if( isTwoPass ) { vertexShaderName = versionedBaseName+"-pass"+(pass1?1:2); } else { vertexShaderName = versionedBaseName+"-single"; @@ -453,6 +447,7 @@ public class RegionRenderer { if( !sp.init(gl) ) { throw new GLException("RegionRenderer: Couldn't init program: "+sp); } + if( !sp.link(gl, System.err) ) { throw new GLException("could not link program: "+sp); } @@ -460,8 +455,8 @@ public class RegionRenderer { shaderPrograms.put(shaderKey, sp); if(DEBUG) { - System.err.printf("RegionRendererImpl01.useShaderProgram.X1: PUT renderModes %s, sel1 %s, key 0x%X -> SP %s (changed)%n", - Region.getRenderModeString(renderModes), sel1, shaderKey, sp); + System.err.printf("RegionRendererImpl01.useShaderProgram.X1: PUT renderModes %s, sel1 %s, key 0x%X -> sp %d / %d (changed)%n", + Region.getRenderModeString(renderModes), sel1, shaderKey, sp.program(), sp.id()); } return true; } diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java index c7083a41b..818526cd7 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java @@ -31,6 +31,7 @@ import java.nio.FloatBuffer; import javax.media.opengl.GL; import javax.media.opengl.GL2ES2; +import javax.media.opengl.GLException; import javax.media.opengl.GLUniformData; import jogamp.graph.curve.opengl.shader.UniformNames; @@ -78,25 +79,109 @@ public class RenderState { private final Vertex.Factory<? extends Vertex> vertexFactory; private final PMVMatrix pmvMatrix; - private final GLUniformData gcu_PMVMatrix01; - private final GLUniformData gcu_Weight; - private final GLUniformData gcu_ColorStatic; - private boolean gcu_PMVMatrix01_dirty = true; - private boolean gcu_Weight_dirty = true; - private boolean gcu_ColorStatic_dirty = true; + private final float[] weight; + private final FloatBuffer weightBuffer; + private final float[] colorStatic; + private final FloatBuffer colorStaticBuffer; private ShaderProgram sp; private int hintBitfield; + private final int id; + private static synchronized int getNextID() { + return nextID++; + } + private static int nextID = 1; + + /** + * Representation of {@link RenderState} data for one {@link ShaderProgram} + * as {@link GLUniformData}. + * <p> + * FIXME: Utilize 'ARB_Uniform_Buffer_Object' where available! + * </p> + */ + public static class ProgramLocal { + public final GLUniformData gcu_PMVMatrix01; + public final GLUniformData gcu_Weight; + public final GLUniformData gcu_ColorStatic; + private int rsId = -1; + + public ProgramLocal() { + gcu_PMVMatrix01 = GLUniformData.creatEmptyMatrix(UniformNames.gcu_PMVMatrix01, 4, 4); + gcu_Weight = GLUniformData.creatEmptyVector(UniformNames.gcu_Weight, 1); + gcu_ColorStatic = GLUniformData.creatEmptyVector(UniformNames.gcu_ColorStatic, 4); + } + + public final int getRenderStateId() { return rsId; } + + /** + * <p> + * Since {@link RenderState} data is being used in multiple + * {@link ShaderProgram}s the data must always be written. + * </p> + * @param gl + * @param updateLocation + * @param renderModes + * @param throwOnError TODO + * @return true if no error occurred, i.e. all locations found, otherwise false. + */ + public final boolean update(final GL2ES2 gl, final RenderState rs, final boolean updateLocation, final int renderModes, final boolean pass1, final boolean throwOnError) { + if( rs.id() != rsId ) { + gcu_PMVMatrix01.setData(rs.pmvMatrix.glGetPMvMatrixf()); + gcu_Weight.setData(rs.weightBuffer); + gcu_ColorStatic.setData(rs.colorStaticBuffer); + rsId = rs.id(); + } + boolean res = true; + if( null != rs.sp && rs.sp.inUse() ) { + if( !Region.isTwoPass(renderModes) || !pass1 ) { + final boolean r0 = rs.updateUniformDataLoc(gl, updateLocation, true, gcu_PMVMatrix01, throwOnError); + res = res && r0; + } + if( pass1 ) { + if( Region.hasVariableWeight( renderModes ) ) { + final boolean r0 = rs.updateUniformDataLoc(gl, updateLocation, true, gcu_Weight, throwOnError); + res = res && r0; + } + { + final boolean r0 = rs.updateUniformDataLoc(gl, updateLocation, true, gcu_ColorStatic, throwOnError); + res = res && r0; + } + } + } + return res; + } + + public StringBuilder toString(StringBuilder sb, boolean alsoUnlocated) { + if(null==sb) { + sb = new StringBuilder(); + } + sb.append("ProgramLocal[rsID ").append(rsId).append(Platform.NEWLINE); + // pmvMatrix.toString(sb, "%.2f"); + sb.append(gcu_PMVMatrix01).append(", ").append(Platform.NEWLINE); + sb.append(gcu_ColorStatic).append(", "); + sb.append(gcu_Weight).append("]"); + return sb; + } + + @Override + public String toString() { + return toString(null, false).toString(); + } + } + protected RenderState(Vertex.Factory<? extends Vertex> vertexFactory, PMVMatrix pmvMatrix) { + this.id = getNextID(); this.sp = null; this.vertexFactory = vertexFactory; this.pmvMatrix = null != pmvMatrix ? pmvMatrix : new PMVMatrix(); - this.gcu_PMVMatrix01 = new GLUniformData(UniformNames.gcu_PMVMatrix01, 4, 4, this.pmvMatrix.glGetPMvMatrixf()); - this.gcu_Weight = new GLUniformData(UniformNames.gcu_Weight, 1.0f); - this.gcu_ColorStatic = new GLUniformData(UniformNames.gcu_ColorStatic, 4, FloatBuffer.allocate(4)); + this.weight = new float[1]; + this.weightBuffer = FloatBuffer.wrap(weight); + this.colorStatic = new float[4]; + this.colorStaticBuffer = FloatBuffer.wrap(colorStatic); this.hintBitfield = 0; } + public final int id() { return id; } public final ShaderProgram getShaderProgram() { return sp; } public final boolean isShaderProgramInUse() { return null != sp ? sp.inUse() : false; } @@ -124,42 +209,28 @@ public class RenderState { public final Vertex.Factory<? extends Vertex> getVertexFactory() { return vertexFactory; } public final PMVMatrix getMatrix() { return pmvMatrix; } - public final PMVMatrix getMatrixMutable() { - gcu_PMVMatrix01_dirty = true; - return pmvMatrix; - } - public final GLUniformData getMatrixUniform() { return gcu_PMVMatrix01; } - public final void setMatrixDirty() { gcu_PMVMatrix01_dirty = true; } - public final boolean isMatrixDirty() { return gcu_PMVMatrix01_dirty;} public static boolean isWeightValid(float v) { return 0.0f <= v && v <= 1.9f ; } - public final float getWeight() { return gcu_Weight.floatValue(); } + public final float getWeight() { return weight[0]; } public final void setWeight(float v) { if( !isWeightValid(v) ) { throw new IllegalArgumentException("Weight out of range"); } - gcu_Weight_dirty = true; - gcu_Weight.setData(v); + weight[0] = v; } public final float[] getColorStatic(float[] rgbaColor) { - FloatBuffer fb = (FloatBuffer) gcu_ColorStatic.getBuffer(); - rgbaColor[0] = fb.get(0); - rgbaColor[1] = fb.get(1); - rgbaColor[2] = fb.get(2); - rgbaColor[3] = fb.get(3); + System.arraycopy(colorStatic, 0, rgbaColor, 0, 4); return rgbaColor; } public final void setColorStatic(float r, float g, float b, float a){ - final FloatBuffer fb = (FloatBuffer) gcu_ColorStatic.getBuffer(); - fb.put(0, r); - fb.put(1, g); - fb.put(2, b); - fb.put(3, a); - gcu_ColorStatic_dirty = true; + colorStatic[0] = r; + colorStatic[1] = g; + colorStatic[2] = b; + colorStatic[3] = a; } @@ -167,43 +238,17 @@ public class RenderState { * * @param gl * @param updateLocation - * @param renderModes - * @return true if no error occurred, i.e. all locations found, otherwise false. - */ - public final boolean update(GL2ES2 gl, final boolean updateLocation, final int renderModes, final boolean pass1) { - boolean res = true; - if( null != sp && sp.inUse() ) { - if( ( !Region.isTwoPass(renderModes) || !pass1 ) && ( gcu_PMVMatrix01_dirty || updateLocation ) ) { - final boolean r0 = updateUniformDataLoc(gl, updateLocation, gcu_PMVMatrix01_dirty, gcu_PMVMatrix01); - res = res && r0; - gcu_PMVMatrix01_dirty = !r0; - } - if( pass1 ) { - if( Region.hasVariableWeight( renderModes ) && ( gcu_Weight_dirty || updateLocation ) ) { - final boolean r0 = updateUniformDataLoc(gl, updateLocation, gcu_Weight_dirty, gcu_Weight); - res = res && r0; - gcu_Weight_dirty = !r0; - } - if( gcu_ColorStatic_dirty || updateLocation ) { - final boolean r0 = updateUniformDataLoc(gl, updateLocation, gcu_ColorStatic_dirty, gcu_ColorStatic); - res = res && r0; - gcu_ColorStatic_dirty = false; - } - } - } - return res; - } - - /** - * - * @param gl - * @param updateLocation * @param data + * @param throwOnError TODO * @return true if no error occured, i.e. all locations found, otherwise false. */ - public final boolean updateUniformLoc(final GL2ES2 gl, final boolean updateLocation, final GLUniformData data) { + public final boolean updateUniformLoc(final GL2ES2 gl, final boolean updateLocation, final GLUniformData data, final boolean throwOnError) { if( updateLocation || 0 > data.getLocation() ) { - return 0 <= data.setLocation(gl, sp.program()); + final boolean ok = 0 <= data.setLocation(gl, sp.program()); + if( throwOnError && !ok ) { + throw new GLException("Could not locate "+data); + } + return ok; } else { return true; } @@ -215,12 +260,16 @@ public class RenderState { * @param updateLocation * @param updateData TODO * @param data + * @param throwOnError TODO * @return true if no error occured, i.e. all locations found, otherwise false. */ - public final boolean updateUniformDataLoc(final GL2ES2 gl, boolean updateLocation, boolean updateData, final GLUniformData data) { + public final boolean updateUniformDataLoc(final GL2ES2 gl, boolean updateLocation, boolean updateData, final GLUniformData data, final boolean throwOnError) { updateLocation = updateLocation || 0 > data.getLocation(); if( updateLocation ) { updateData = 0 <= data.setLocation(gl, sp.program()); + if( throwOnError && !updateData ) { + throw new GLException("Could not locate "+data); + } } if( updateData ){ gl.glUniform(data); @@ -233,11 +282,16 @@ public class RenderState { /** * @param gl * @param data + * @param throwOnError TODO * @return true if no error occured, i.e. all locations found, otherwise false. */ - public final boolean updateAttributeLoc(final GL2ES2 gl, final boolean updateLocation, final GLArrayDataServer data) { + public final boolean updateAttributeLoc(final GL2ES2 gl, final boolean updateLocation, final GLArrayDataServer data, boolean throwOnError) { if( updateLocation || 0 > data.getLocation() ) { - return 0 <= data.setLocation(gl, sp.program()); + final boolean ok = 0 <= data.setLocation(gl, sp.program()); + if( throwOnError && !ok ) { + throw new GLException("Could not locate "+data); + } + return ok; } else { return true; } @@ -274,21 +328,8 @@ public class RenderState { return false; } - public StringBuilder toString(StringBuilder sb, boolean alsoUnlocated) { - if(null==sb) { - sb = new StringBuilder(); - } - sb.append("RenderState[").append(sp).append(Platform.NEWLINE); - // pmvMatrix.toString(sb, "%.2f"); - sb.append(", dirty[pmv "+gcu_PMVMatrix01_dirty+", color "+gcu_ColorStatic_dirty+", weight "+gcu_Weight_dirty+"], ").append(Platform.NEWLINE); - sb.append(gcu_PMVMatrix01).append(", ").append(Platform.NEWLINE); - sb.append(gcu_ColorStatic).append(", "); - sb.append(gcu_Weight).append("]"); - return sb; - } - @Override public String toString() { - return toString(null, false).toString(); + return "RenderState["+sp+"]"; } } diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java index f944843e9..aadbecc91 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java @@ -178,7 +178,7 @@ public class TextRegionUtil { final int special = 0; GLRegion region = getCachedRegion(font, str, pixelSize, special); if(null == region) { - region = GLRegion.create(renderModes); + region = GLRegion.create(renderModes, null); addStringToRegion(region, renderer.getRenderState().getVertexFactory(), font, pixelSize, str, rgbaColor, tempT1, tempT2); addCachedRegion(gl, font, str, pixelSize, special, region); } @@ -213,7 +213,7 @@ public class TextRegionUtil { if(!renderer.isInitialized()){ throw new GLException("TextRendererImpl01: not initialized!"); } - final GLRegion region = GLRegion.create(renderModes); + final GLRegion region = GLRegion.create(renderModes, null); addStringToRegion(region, renderer.getRenderState().getVertexFactory(), font, pixelSize, str, rgbaColor, temp1, temp2); region.draw(gl, renderer, sampleCount); region.destroy(gl); diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java index 6a4b13dfb..3ac17b0c5 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java +++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java @@ -56,7 +56,7 @@ public class ShaderProgram { /** * returns the uniq shader id as an integer */ - public int id() { return id; } + public int id() { return id; } /** * Detaches all shader codes and deletes the program. @@ -321,7 +321,7 @@ public class ShaderProgram { private int shaderProgram = 0; // non zero is valid! private final HashSet<ShaderCode> allShaderCode = new HashSet<ShaderCode>(); private final HashSet<ShaderCode> attachedShaderCode = new HashSet<ShaderCode>(); - private int id = -1; + private final int id; private static synchronized int getNextID() { return nextID++; diff --git a/src/jogl/classes/javax/media/opengl/GLUniformData.java b/src/jogl/classes/javax/media/opengl/GLUniformData.java index 412bfb0a9..fac8b7a1f 100644 --- a/src/jogl/classes/javax/media/opengl/GLUniformData.java +++ b/src/jogl/classes/javax/media/opengl/GLUniformData.java @@ -15,7 +15,7 @@ public class GLUniformData { * */ public GLUniformData(String name, int val) { - init(name, 1, new Integer(val)); + initScalar(name, 1, new Integer(val)); } /** @@ -25,7 +25,7 @@ public class GLUniformData { * */ public GLUniformData(String name, float val) { - init(name, 1, new Float(val)); + initScalar(name, 1, new Float(val)); } /** @@ -36,7 +36,7 @@ public class GLUniformData { * @param components number of elements of one object, ie 4 for GL_FLOAT_VEC4, */ public GLUniformData(String name, int components, IntBuffer data) { - init(name, components, data); + initBuffer(name, components, data); } /** @@ -47,7 +47,19 @@ public class GLUniformData { * @param components number of elements of one object, ie 4 for GL_FLOAT_VEC4, */ public GLUniformData(String name, int components, FloatBuffer data) { - init(name, components, data); + initBuffer(name, components, data); + } + + private GLUniformData(int components, String name) { + initBuffer(name, components, null); + } + + public static GLUniformData creatEmptyVector(String name, int components) { + return new GLUniformData(components, name); + } + + public static GLUniformData creatEmptyMatrix(String name, int rows, int columns) { + return new GLUniformData(name, rows, columns, null); } /** @@ -59,13 +71,13 @@ public class GLUniformData { * @param column the matrix column */ public GLUniformData(String name, int rows, int columns, FloatBuffer data) { - init(name, rows, columns, data); + initBuffer(name, rows, columns, data); } - public GLUniformData setData(int data) { init(new Integer(data)); return this; } - public GLUniformData setData(float data) { init(new Float(data)); return this; } - public GLUniformData setData(IntBuffer data) { init(data); return this; } - public GLUniformData setData(FloatBuffer data) { init(data); return this; } + public GLUniformData setData(final int data) { initScalar(new Integer(data)); return this; } + public GLUniformData setData(final float data) { initScalar(new Float(data)); return this; } + public GLUniformData setData(final IntBuffer data) { initBuffer(data); return this; } + public GLUniformData setData(final FloatBuffer data) { initBuffer(data); return this; } public int intValue() { return ((Integer)data).intValue(); }; public float floatValue() { return ((Float)data).floatValue(); }; @@ -102,7 +114,7 @@ public class GLUniformData { return toString(null).toString(); } - private void init(String name, int rows, int columns, Object data) { + private void initBuffer(String name, int rows, int columns, Buffer buffer) { if( 2>rows || rows>4 || 2>columns || columns>4 ) { throw new GLException("rowsXcolumns must be within [2..4]X[2..4], is: "+rows+"X"+columns); } @@ -111,10 +123,20 @@ public class GLUniformData { this.columns=columns; this.isMatrix=true; this.location=-1; - init(data); + initBuffer(buffer); } - - private void init(String name, int components, Object data) { + private void initScalar(String name, int components, Object data) { + if( 1>components || components>4 ) { + throw new GLException("components must be within [1..4], is: "+components); + } + this.name=name; + this.columns=components; + this.rows=1; + this.isMatrix=false; + this.location=-1; + initScalar(data); + } + private void initBuffer(String name, int components, Buffer buffer) { if( 1>components || components>4 ) { throw new GLException("components must be within [1..4], is: "+components); } @@ -123,24 +145,36 @@ public class GLUniformData { this.rows=1; this.isMatrix=false; this.location=-1; - init(data); + initBuffer(buffer); } - private void init(Object data) { + private void initScalar(Object data) { if(data instanceof Buffer) { + initBuffer((Buffer)data); + } else if( null != data ) { + if(isMatrix) { + throw new GLException("Atom type not allowed for matrix : "+this); + } + this.count=1; + this.data=data; + } else { + this.count=0; + this.data=data; + } + } + + private void initBuffer(final Buffer buffer) { + if( null != buffer ) { final int sz = rows*columns; - final Buffer buffer = (Buffer)data; if(buffer.remaining()<sz || 0!=buffer.remaining()%sz) { throw new GLException("remaining data buffer size invalid: buffer: "+buffer.toString()+"\n\t"+this); } - this.count=buffer.remaining()/(rows*columns); + this.count=buffer.remaining()/sz; + this.data=buffer; } else { - if(isMatrix) { - throw new GLException("Atom type not allowed for matrix : "+this); - } - this.count=1; + this.count=0; + this.data=null; } - this.data=data; } public String getName() { return name; } diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java index 172bd52c8..33527381d 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java @@ -36,7 +36,6 @@ import javax.media.opengl.GLUniformData; import jogamp.graph.curve.opengl.shader.AttributeNames; import jogamp.graph.curve.opengl.shader.UniformNames; -import com.jogamp.common.nio.Buffers; import com.jogamp.graph.curve.opengl.GLRegion; import com.jogamp.graph.curve.opengl.RegionRenderer; import com.jogamp.graph.curve.opengl.RenderState; @@ -46,16 +45,23 @@ import com.jogamp.opengl.math.FloatUtil; import com.jogamp.opengl.math.geom.AABBox; import com.jogamp.opengl.util.GLArrayDataServer; import com.jogamp.opengl.util.glsl.ShaderProgram; +import com.jogamp.opengl.util.texture.Texture; +import com.jogamp.opengl.util.texture.TextureSequence; public class VBORegion2PMSAAES2 extends GLRegion { private static final boolean DEBUG_FBO_1 = false; private static final boolean DEBUG_FBO_2 = false; + private final RenderState.ProgramLocal rsLocal; + // Pass-1: private GLArrayDataServer gca_VerticesAttr; private GLArrayDataServer gca_CurveParamsAttr; private GLArrayDataServer gca_ColorsAttr; private GLArrayDataServer indicesBuffer; + private final GLUniformData gcu_ColorTexUnit; + private final float[] colorTexBBox; // x0, y0, x1, y1 + private final GLUniformData gcu_ColorTexBBox; private ShaderProgram spPass1 = null; // Pass-2: @@ -63,7 +69,6 @@ public class VBORegion2PMSAAES2 extends GLRegion { private GLArrayDataServer gca_FboTexCoordsAttr; private GLArrayDataServer indicesFbo; private final GLUniformData gcu_FboTexUnit; - private final GLUniformData gcu_FboTexSize; private final float[] pmvMatrix02 = new float[2*16]; // P + Mv private final GLUniformData gcu_PMVMatrix02; private ShaderProgram spPass2 = null; @@ -76,34 +81,63 @@ public class VBORegion2PMSAAES2 extends GLRegion { final int[] maxTexSize = new int[] { -1 } ; + /** + * <p> + * Since multiple {@link Region}s may share one + * {@link ShaderProgram}, the uniform data must always be updated. + * </p> + * + * @param gl + * @param renderer + * @param renderModes + * @param pass1 + * @param quality + * @param sampleCount + */ public void useShaderProgram(final GL2ES2 gl, final RegionRenderer renderer, final int renderModes, final boolean pass1, final int quality, final int sampleCount) { final RenderState rs = renderer.getRenderState(); - renderer.useShaderProgram(gl, renderModes, pass1, quality, sampleCount); + final boolean updateLocGlobal = renderer.useShaderProgram(gl, renderModes, pass1, quality, sampleCount); final ShaderProgram sp = renderer.getRenderState().getShaderProgram(); - final boolean updateLocation; + final boolean updateLocLocal; if( pass1 ) { - updateLocation = !sp.equals(spPass1); + updateLocLocal = !sp.equals(spPass1); spPass1 = sp; - rs.update(gl, updateLocation, renderModes, true); - rs.updateUniformLoc(gl, updateLocation, gcu_PMVMatrix02); - rs.updateAttributeLoc(gl, updateLocation, gca_VerticesAttr); - rs.updateAttributeLoc(gl, updateLocation, gca_CurveParamsAttr); - if( null != gca_ColorsAttr ) { - rs.updateAttributeLoc(gl, updateLocation, gca_ColorsAttr); + if( DEBUG ) { + System.err.println("XXX changedSP.p1 updateLocation loc "+updateLocLocal+" / glob "+updateLocGlobal); + } + if( updateLocLocal ) { + rs.updateAttributeLoc(gl, true, gca_VerticesAttr, true); + rs.updateAttributeLoc(gl, true, gca_CurveParamsAttr, true); + if( null != gca_ColorsAttr ) { + rs.updateAttributeLoc(gl, true, gca_ColorsAttr, true); + } + } + rsLocal.update(gl, rs, updateLocLocal, renderModes, true, true); + rs.updateUniformLoc(gl, updateLocLocal, gcu_PMVMatrix02, true); + if( null != gcu_ColorTexUnit ) { + rs.updateUniformLoc(gl, updateLocLocal, gcu_ColorTexUnit, true); + rs.updateUniformLoc(gl, updateLocLocal, gcu_ColorTexBBox, true); } } else { - updateLocation = !sp.equals(spPass2); + updateLocLocal = !sp.equals(spPass2); spPass2 = sp; - rs.update(gl, updateLocation, renderModes, false); - rs.updateAttributeLoc(gl, updateLocation, gca_FboVerticesAttr); - rs.updateAttributeLoc(gl, updateLocation, gca_FboTexCoordsAttr); - rs.updateUniformDataLoc(gl, updateLocation, true, gcu_FboTexUnit); - rs.updateUniformLoc(gl, updateLocation, gcu_FboTexSize); + if( DEBUG ) { + System.err.println("XXX changedSP.p2 updateLocation loc "+updateLocLocal+" / glob "+updateLocGlobal); + } + if( updateLocLocal ) { + rs.updateAttributeLoc(gl, true, gca_FboVerticesAttr, true); + rs.updateAttributeLoc(gl, true, gca_FboTexCoordsAttr, true); + } + rsLocal.update(gl, rs, updateLocLocal, renderModes, false, true); + rs.updateUniformDataLoc(gl, updateLocLocal, false /* updateData */, gcu_FboTexUnit, true); // FIXME always update if changing tex-unit } } - public VBORegion2PMSAAES2(final int renderModes, final int textureUnit) { - super(renderModes); + public VBORegion2PMSAAES2(final int renderModes, final TextureSequence colorTexSeq, final int pass2TexUnit) { + super(renderModes, colorTexSeq); + + rsLocal = new RenderState.ProgramLocal(); + final int initialElementCount = 256; // Pass 1: @@ -121,14 +155,22 @@ public class VBORegion2PMSAAES2 extends GLRegion { } else { gca_ColorsAttr = null; } + if( hasColorTexture() ) { + gcu_ColorTexUnit = new GLUniformData(UniformNames.gcu_ColorTexUnit, colorTexSeq.getTextureUnit()); + colorTexBBox = new float[4]; + gcu_ColorTexBBox = new GLUniformData(UniformNames.gcu_ColorTexBBox, 4, FloatBuffer.wrap(colorTexBBox)); + } else { + gcu_ColorTexUnit = null; + colorTexBBox = null; + gcu_ColorTexBBox = null; + } FloatUtil.makeIdentityf(pmvMatrix02, 0); FloatUtil.makeIdentityf(pmvMatrix02, 16); gcu_PMVMatrix02 = new GLUniformData(UniformNames.gcu_PMVMatrix02, 4, 4, FloatBuffer.wrap(pmvMatrix02)); // Pass 2: - gcu_FboTexUnit = new GLUniformData(UniformNames.gcu_FboTexUnit, textureUnit); - gcu_FboTexSize = new GLUniformData(UniformNames.gcu_FboTexSize, 2, Buffers.newDirectFloatBuffer(2)); + gcu_FboTexUnit = new GLUniformData(UniformNames.gcu_FboTexUnit, pass2TexUnit); indicesFbo = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, 2, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER); indicesFbo.puts((short) 0); indicesFbo.puts((short) 1); indicesFbo.puts((short) 3); @@ -208,8 +250,12 @@ public class VBORegion2PMSAAES2 extends GLRegion { gca_ColorsAttr.seal(gl, true); gca_ColorsAttr.enableBuffer(gl, false); } - - // update all bbox related data + if( null != gcu_ColorTexUnit ) { + colorTexBBox[0] = box.getMinX(); + colorTexBBox[1] = box.getMinY(); + colorTexBBox[2] = box.getMaxX(); + colorTexBBox[3] = box.getMaxY(); + } gca_FboVerticesAttr.seal(gl, false); { final FloatBuffer fb = (FloatBuffer)gca_FboVerticesAttr.getBuffer(); @@ -350,8 +396,6 @@ public class VBORegion2PMSAAES2 extends GLRegion { private void renderFBO(final GL2ES2 gl, final RenderState rs, final int width, final int height, final int sampleCount) { gl.glViewport(0, 0, width, height); - gl.glUniform(gcu_FboTexSize); - gl.glActiveTexture(GL.GL_TEXTURE0 + gcu_FboTexUnit.intValue()); fbo.use(gl, fbo.getSamplingSink()); @@ -378,11 +422,6 @@ public class VBORegion2PMSAAES2 extends GLRegion { if(null == fbo) { fboWidth = targetFboWidth; fboHeight = targetFboHeight; - final FloatBuffer fboTexSize = (FloatBuffer) gcu_FboTexSize.getBuffer(); - { - fboTexSize.put(0, fboWidth); - fboTexSize.put(1, fboHeight); - } fbo = new FBObject(); fbo.reset(gl, fboWidth, fboHeight, sampleCount[0], false); sampleCount[0] = fbo.getNumSamples(); @@ -409,11 +448,6 @@ public class VBORegion2PMSAAES2 extends GLRegion { } fboWidth = targetFboWidth; fboHeight = targetFboHeight; - final FloatBuffer fboTexSize = (FloatBuffer) gcu_FboTexSize.getBuffer(); - { - fboTexSize.put(0, fboWidth); - fboTexSize.put(1, fboHeight); - } } fbo.bind(gl); @@ -434,8 +468,23 @@ public class VBORegion2PMSAAES2 extends GLRegion { gca_ColorsAttr.enableBuffer(gl, true); } indicesBuffer.bindBuffer(gl, true); // keeps VBO binding - - gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesBuffer.getElementCount() * indicesBuffer.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0); + if( null != gcu_ColorTexUnit ) { + final TextureSequence.TextureFrame frame = colorTexSeq.getNextTexture(gl); + gl.glActiveTexture(GL.GL_TEXTURE0 + colorTexSeq.getTextureUnit()); + final Texture tex = frame.getTexture(); + tex.bind(gl); + tex.enable(gl); // nop on core + final int colorTexUnit = colorTexSeq.getTextureUnit(); + if( colorTexUnit != gcu_ColorTexUnit.intValue() ) { + gcu_ColorTexUnit.setData(colorTexUnit); + gl.glUniform(gcu_ColorTexUnit); + } + gl.glUniform(gcu_ColorTexBBox); // FIXME: Only if changed! + gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesBuffer.getElementCount() * indicesBuffer.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0); + tex.disable(gl); // nop on core + } else { + gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesBuffer.getElementCount() * indicesBuffer.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0); + } indicesBuffer.bindBuffer(gl, false); if( null != gca_ColorsAttr ) { diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java index a701a4b19..c623eddb7 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java @@ -37,7 +37,6 @@ import jogamp.graph.curve.opengl.shader.AttributeNames; import jogamp.graph.curve.opengl.shader.UniformNames; import jogamp.opengl.Debug; -import com.jogamp.common.nio.Buffers; import com.jogamp.graph.curve.Region; import com.jogamp.graph.curve.opengl.GLRegion; import com.jogamp.graph.curve.opengl.RegionRenderer; @@ -49,6 +48,8 @@ import com.jogamp.opengl.math.FloatUtil; import com.jogamp.opengl.math.geom.AABBox; import com.jogamp.opengl.util.GLArrayDataServer; import com.jogamp.opengl.util.glsl.ShaderProgram; +import com.jogamp.opengl.util.texture.Texture; +import com.jogamp.opengl.util.texture.TextureSequence; public class VBORegion2PVBAAES2 extends GLRegion { private static final boolean DEBUG_FBO_1 = false; @@ -84,11 +85,16 @@ public class VBORegion2PVBAAES2 extends GLRegion { } + private final RenderState.ProgramLocal rsLocal; + // Pass-1: private GLArrayDataServer gca_VerticesAttr; private GLArrayDataServer gca_CurveParamsAttr; private GLArrayDataServer gca_ColorsAttr; private GLArrayDataServer indicesBuffer; + private final GLUniformData gcu_ColorTexUnit; + private final float[] colorTexBBox; // x0, y0, x1, y1 + private final GLUniformData gcu_ColorTexBBox; private ShaderProgram spPass1 = null; // Pass-2: @@ -110,34 +116,64 @@ public class VBORegion2PVBAAES2 extends GLRegion { final int[] maxTexSize = new int[] { -1 } ; + /** + * <p> + * Since multiple {@link Region}s may share one + * {@link ShaderProgram}, the uniform data must always be updated. + * </p> + * + * @param gl + * @param renderer + * @param renderModes + * @param pass1 + * @param quality + * @param sampleCount + */ public void useShaderProgram(final GL2ES2 gl, final RegionRenderer renderer, final int renderModes, final boolean pass1, final int quality, final int sampleCount) { final RenderState rs = renderer.getRenderState(); - renderer.useShaderProgram(gl, renderModes, pass1, quality, sampleCount); + final boolean updateLocGlobal = renderer.useShaderProgram(gl, renderModes, pass1, quality, sampleCount); final ShaderProgram sp = renderer.getRenderState().getShaderProgram(); - final boolean updateLocation; + final boolean updateLocLocal; if( pass1 ) { - updateLocation = !sp.equals(spPass1); + updateLocLocal = !sp.equals(spPass1); spPass1 = sp; - rs.update(gl, updateLocation, renderModes, true); - rs.updateUniformLoc(gl, updateLocation, gcu_PMVMatrix02); - rs.updateAttributeLoc(gl, updateLocation, gca_VerticesAttr); - rs.updateAttributeLoc(gl, updateLocation, gca_CurveParamsAttr); - if( null != gca_ColorsAttr ) { - rs.updateAttributeLoc(gl, updateLocation, gca_ColorsAttr); + if( DEBUG ) { + System.err.println("XXX changedSP.p1 updateLocation loc "+updateLocLocal+" / glob "+updateLocGlobal); + } + if( updateLocLocal ) { + rs.updateAttributeLoc(gl, true, gca_VerticesAttr, true); + rs.updateAttributeLoc(gl, true, gca_CurveParamsAttr, true); + if( null != gca_ColorsAttr ) { + rs.updateAttributeLoc(gl, true, gca_ColorsAttr, true); + } + } + rsLocal.update(gl, rs, updateLocLocal, renderModes, true, true); + rs.updateUniformLoc(gl, updateLocLocal, gcu_PMVMatrix02, true); + if( null != gcu_ColorTexUnit ) { + rs.updateUniformLoc(gl, updateLocLocal, gcu_ColorTexUnit, true); + rs.updateUniformLoc(gl, updateLocLocal, gcu_ColorTexBBox, true); } } else { - updateLocation = !sp.equals(spPass2); + updateLocLocal = !sp.equals(spPass2); spPass2 = sp; - rs.update(gl, updateLocation, renderModes, false); - rs.updateAttributeLoc(gl, updateLocation, gca_FboVerticesAttr); - rs.updateAttributeLoc(gl, updateLocation, gca_FboTexCoordsAttr); - rs.updateUniformDataLoc(gl, updateLocation, true, gcu_FboTexUnit); - rs.updateUniformLoc(gl, updateLocation, gcu_FboTexSize); + if( DEBUG ) { + System.err.println("XXX changedSP.p2 updateLocation loc "+updateLocLocal+" / glob "+updateLocGlobal); + } + if( updateLocLocal ) { + rs.updateAttributeLoc(gl, true, gca_FboVerticesAttr, true); + rs.updateAttributeLoc(gl, true, gca_FboTexCoordsAttr, true); + } + rsLocal.update(gl, rs, updateLocLocal, renderModes, false, true); + rs.updateUniformDataLoc(gl, updateLocLocal, false /* updateData */, gcu_FboTexUnit, true); // FIXME always update if changing tex-unit + rs.updateUniformLoc(gl, updateLocLocal, gcu_FboTexSize, true); } } - public VBORegion2PVBAAES2(final int renderModes, final int textureUnit) { - super(renderModes); + public VBORegion2PVBAAES2(final int renderModes, final TextureSequence colorTexSeq, final int pass2TexUnit) { + super(renderModes, colorTexSeq); + + rsLocal = new RenderState.ProgramLocal(); + final int initialElementCount = 256; // Pass 1: @@ -154,14 +190,23 @@ public class VBORegion2PVBAAES2 extends GLRegion { } else { gca_ColorsAttr = null; } + if( hasColorTexture() ) { + gcu_ColorTexUnit = new GLUniformData(UniformNames.gcu_ColorTexUnit, colorTexSeq.getTextureUnit()); + colorTexBBox = new float[4]; + gcu_ColorTexBBox = new GLUniformData(UniformNames.gcu_ColorTexBBox, 4, FloatBuffer.wrap(colorTexBBox)); + } else { + gcu_ColorTexUnit = null; + colorTexBBox = null; + gcu_ColorTexBBox = null; + } FloatUtil.makeIdentityf(pmvMatrix02, 0); FloatUtil.makeIdentityf(pmvMatrix02, 16); gcu_PMVMatrix02 = new GLUniformData(UniformNames.gcu_PMVMatrix02, 4, 4, FloatBuffer.wrap(pmvMatrix02)); // Pass 2: - gcu_FboTexUnit = new GLUniformData(UniformNames.gcu_FboTexUnit, textureUnit); - gcu_FboTexSize = new GLUniformData(UniformNames.gcu_FboTexSize, 2, Buffers.newDirectFloatBuffer(2)); + gcu_FboTexUnit = new GLUniformData(UniformNames.gcu_FboTexUnit, pass2TexUnit); + gcu_FboTexSize = new GLUniformData(UniformNames.gcu_FboTexSize, 2, FloatBuffer.wrap(new float[2])); indicesFbo = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, 2, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER); indicesFbo.puts((short) 0); indicesFbo.puts((short) 1); indicesFbo.puts((short) 3); @@ -250,8 +295,12 @@ public class VBORegion2PVBAAES2 extends GLRegion { gca_ColorsAttr.seal(gl, true); gca_ColorsAttr.enableBuffer(gl, false); } - - // update all bbox related data + if( null != gcu_ColorTexUnit ) { + colorTexBBox[0] = box.getMinX(); + colorTexBBox[1] = box.getMinY(); + colorTexBBox[2] = box.getMaxX(); + colorTexBBox[3] = box.getMaxY(); + } gca_FboVerticesAttr.seal(gl, false); { final FloatBuffer fb = (FloatBuffer)gca_FboVerticesAttr.getBuffer(); @@ -537,14 +586,30 @@ public class VBORegion2PVBAAES2 extends GLRegion { private void renderRegion(final GL2ES2 gl) { gl.glUniform(gcu_PMVMatrix02); + gca_VerticesAttr.enableBuffer(gl, true); gca_CurveParamsAttr.enableBuffer(gl, true); if( null != gca_ColorsAttr ) { gca_ColorsAttr.enableBuffer(gl, true); } indicesBuffer.bindBuffer(gl, true); // keeps VBO binding - - gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesBuffer.getElementCount() * indicesBuffer.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0); + if( null != gcu_ColorTexUnit ) { + final TextureSequence.TextureFrame frame = colorTexSeq.getNextTexture(gl); + gl.glActiveTexture(GL.GL_TEXTURE0 + colorTexSeq.getTextureUnit()); + final Texture tex = frame.getTexture(); + tex.bind(gl); + tex.enable(gl); // nop on core + final int colorTexUnit = colorTexSeq.getTextureUnit(); + if( colorTexUnit != gcu_ColorTexUnit.intValue() ) { + gcu_ColorTexUnit.setData(colorTexUnit); + gl.glUniform(gcu_ColorTexUnit); + } + gl.glUniform(gcu_ColorTexBBox); // FIXME: Only if changed! + gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesBuffer.getElementCount() * indicesBuffer.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0); + tex.disable(gl); // nop on core + } else { + gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesBuffer.getElementCount() * indicesBuffer.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0); + } indicesBuffer.bindBuffer(gl, false); if( null != gca_ColorsAttr ) { diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java index 8268394dd..0ec139a0f 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java @@ -27,26 +27,41 @@ */ package jogamp.graph.curve.opengl; +import java.nio.FloatBuffer; + import javax.media.opengl.GL; import javax.media.opengl.GL2ES2; +import javax.media.opengl.GLUniformData; import jogamp.graph.curve.opengl.shader.AttributeNames; +import jogamp.graph.curve.opengl.shader.UniformNames; +import com.jogamp.graph.curve.Region; import com.jogamp.graph.curve.opengl.GLRegion; import com.jogamp.graph.curve.opengl.RegionRenderer; import com.jogamp.graph.curve.opengl.RenderState; import com.jogamp.opengl.util.GLArrayDataServer; import com.jogamp.opengl.util.glsl.ShaderProgram; +import com.jogamp.opengl.util.texture.Texture; +import com.jogamp.opengl.util.texture.TextureSequence; public class VBORegionSPES2 extends GLRegion { + private final RenderState.ProgramLocal rsLocal; + private GLArrayDataServer gca_VerticesAttr = null; private GLArrayDataServer gca_CurveParamsAttr = null; private GLArrayDataServer gca_ColorsAttr; private GLArrayDataServer indicesBuffer = null; + private final GLUniformData gcu_ColorTexUnit; + private final float[] colorTexBBox; // x0, y0, x1, y1 + private final GLUniformData gcu_ColorTexBBox; private ShaderProgram spPass1 = null; - public VBORegionSPES2(final int renderModes) { - super(renderModes); + public VBORegionSPES2(final int renderModes, final TextureSequence colorTexSeq) { + super(renderModes, colorTexSeq); + + rsLocal = new RenderState.ProgramLocal(); + final int initialElementCount = 256; indicesBuffer = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialElementCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER); @@ -62,6 +77,15 @@ public class VBORegionSPES2 extends GLRegion { } else { gca_ColorsAttr = null; } + if( hasColorTexture() ) { + gcu_ColorTexUnit = new GLUniformData(UniformNames.gcu_ColorTexUnit, colorTexSeq.getTextureUnit()); + colorTexBBox = new float[4]; + gcu_ColorTexBBox = new GLUniformData(UniformNames.gcu_ColorTexBBox, 4, FloatBuffer.wrap(colorTexBBox)); + } else { + gcu_ColorTexUnit = null; + colorTexBBox = null; + gcu_ColorTexBBox = null; + } } @Override @@ -117,8 +141,6 @@ public class VBORegionSPES2 extends GLRegion { @Override protected void updateImpl(final GL2ES2 gl) { // seal buffers - indicesBuffer.seal(gl, true); - indicesBuffer.enableBuffer(gl, false); gca_VerticesAttr.seal(gl, true); gca_VerticesAttr.enableBuffer(gl, false); gca_CurveParamsAttr.seal(gl, true); @@ -127,6 +149,14 @@ public class VBORegionSPES2 extends GLRegion { gca_ColorsAttr.seal(gl, true); gca_ColorsAttr.enableBuffer(gl, false); } + if( null != gcu_ColorTexUnit ) { + colorTexBBox[0] = box.getMinX(); + colorTexBBox[1] = box.getMinY(); + colorTexBBox[2] = box.getMaxX(); + colorTexBBox[3] = box.getMaxY(); + } + indicesBuffer.seal(gl, true); + indicesBuffer.enableBuffer(gl, false); if(DEBUG_INSTANCE) { System.err.println("VBORegionSPES2 idx "+indicesBuffer); System.err.println("VBORegionSPES2 ver "+gca_VerticesAttr); @@ -134,22 +164,37 @@ public class VBORegionSPES2 extends GLRegion { } } + /** + * <p> + * Since multiple {@link Region}s may share one + * {@link ShaderProgram}, the uniform data must always be updated. + * </p> + * + * @param gl + * @param renderer + * @param renderModes + * @param quality + */ public void useShaderProgram(final GL2ES2 gl, final RegionRenderer renderer, final int renderModes, final int quality) { final RenderState rs = renderer.getRenderState(); - final boolean updateLocation0 = renderer.useShaderProgram(gl, renderModes, true, quality, 0); + final boolean updateLocGlobal = renderer.useShaderProgram(gl, renderModes, true, quality, 0); final ShaderProgram sp = renderer.getRenderState().getShaderProgram(); - final boolean updateLocation = !sp.equals(spPass1); + final boolean updateLocLocal = !sp.equals(spPass1); spPass1 = sp; - - // update attribute-location and uniform data and location - rs.update(gl, updateLocation, renderModes, true); - rs.updateAttributeLoc(gl, updateLocation, gca_VerticesAttr); - rs.updateAttributeLoc(gl, updateLocation, gca_CurveParamsAttr); - if( null != gca_ColorsAttr ) { - rs.updateAttributeLoc(gl, updateLocation, gca_ColorsAttr); - } if( DEBUG ) { - System.err.println("XXX changedSP.p1 "+updateLocation+" / "+updateLocation0); + System.err.println("XXX changedSP.p1 updateLocation loc "+updateLocLocal+" / glob "+updateLocGlobal); + } + if( updateLocLocal ) { + rs.updateAttributeLoc(gl, true, gca_VerticesAttr, true); + rs.updateAttributeLoc(gl, true, gca_CurveParamsAttr, true); + if( null != gca_ColorsAttr ) { + rs.updateAttributeLoc(gl, true, gca_ColorsAttr, true); + } + } + rsLocal.update(gl, rs, updateLocLocal, renderModes, true, true); + if( null != gcu_ColorTexUnit ) { + rs.updateUniformLoc(gl, updateLocLocal, gcu_ColorTexUnit, true); + rs.updateUniformLoc(gl, updateLocLocal, gcu_ColorTexBBox, true); } } @@ -171,8 +216,23 @@ public class VBORegionSPES2 extends GLRegion { gca_ColorsAttr.enableBuffer(gl, true); } indicesBuffer.bindBuffer(gl, true); // keeps VBO binding - - gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesBuffer.getElementCount() * indicesBuffer.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0); + if( null != gcu_ColorTexUnit ) { + final TextureSequence.TextureFrame frame = colorTexSeq.getNextTexture(gl); + gl.glActiveTexture(GL.GL_TEXTURE0 + colorTexSeq.getTextureUnit()); + final Texture tex = frame.getTexture(); + tex.bind(gl); + tex.enable(gl); // nop on core + final int colorTexUnit = colorTexSeq.getTextureUnit(); + if( colorTexUnit != gcu_ColorTexUnit.intValue() ) { + gcu_ColorTexUnit.setData(colorTexUnit); + gl.glUniform(gcu_ColorTexUnit); + } + gl.glUniform(gcu_ColorTexBBox); // FIXME: Only if changed! + gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesBuffer.getElementCount() * indicesBuffer.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0); + tex.disable(gl); // nop on core + } else { + gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesBuffer.getElementCount() * indicesBuffer.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0); + } indicesBuffer.bindBuffer(gl, false); if( null != gca_ColorsAttr ) { diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/AttributeNames.java b/src/jogl/classes/jogamp/graph/curve/opengl/shader/AttributeNames.java index b2c73a2e4..dff536645 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/AttributeNames.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/AttributeNames.java @@ -44,6 +44,7 @@ public class AttributeNames { public static final String COLOR_ATTR_NAME = "gca_Colors"; public static final String FBO_VERTEX_ATTR_NAME = "gca_FboVertices"; + public static final String FBO_TEXCOORDS_ATTR_NAME = "gca_FboTexCoords"; } diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/UniformNames.java b/src/jogl/classes/jogamp/graph/curve/opengl/shader/UniformNames.java index f37025516..7244851ff 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/UniformNames.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/UniformNames.java @@ -4,6 +4,8 @@ public class UniformNames { public static final String gcu_PMVMatrix01 = "gcu_PMVMatrix01"; // gcu_PMVMatrix[3]; // P, Mv, and Mvi public static final String gcu_ColorStatic = "gcu_ColorStatic"; public static final String gcu_Weight = "gcu_Weight"; + public static final String gcu_ColorTexUnit = "gcu_ColorTexUnit"; + public static final String gcu_ColorTexBBox = "gcu_ColorTexBBox"; public static final String gcu_PMVMatrix02 = "gcu_PMVMatrix02"; // gcu_PMVMatrix[3]; // P, Mv, and Mvi public static final String gcu_FboTexUnit = "gcu_FboTexUnit"; diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_simple.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_simple.glsl index 373e8d575..83b312a0b 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_simple.glsl +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_simple.glsl @@ -1,7 +1,11 @@ if( gcv_CurveParam.x == 0.0 && gcv_CurveParam.y == 0.0 ) { // pass-1: Lines -#ifdef USE_COLOR_CHANNEL +#if defined(USE_COLOR_TEXTURE) && defined(USE_COLOR_CHANNEL) + mgl_FragColor = texture2D(gcu_ColorTexUnit, gcv_ColorTexCoord.st) * gcv_Color * gcu_ColorStatic; +#elif defined(USE_COLOR_TEXTURE) + mgl_FragColor = texture2D(gcu_ColorTexUnit, gcv_ColorTexCoord.st) * gcu_ColorStatic; +#elif defined(USE_COLOR_CHANNEL) mgl_FragColor = gcv_Color * gcu_ColorStatic; #else mgl_FragColor = gcu_ColorStatic; @@ -17,7 +21,13 @@ float position = rtex.y - (rtex.x * (1.0 - rtex.x)); float a = clamp(0.5 - ( position/length(f) ) * sign(gcv_CurveParam.y), 0.0, 1.0); -#ifdef USE_COLOR_CHANNEL +#if defined(USE_COLOR_TEXTURE) && defined(USE_COLOR_CHANNEL) + vec4 t = texture2D(gcu_ColorTexUnit, gcv_ColorTexCoord.st); + mgl_FragColor = vec4(t.rgb * gcv_Color.rgb * gcu_ColorStatic.rgb, t.a * gcv_Color.a * gcu_ColorStatic.a * a); +#elif defined(USE_COLOR_TEXTURE) + vec4 t = texture2D(gcu_ColorTexUnit, gcv_ColorTexCoord.st); + mgl_FragColor = vec4(t.rgb * gcu_ColorStatic.rgb, t.a * gcu_ColorStatic.a * a); +#elif defined(USE_COLOR_CHANNEL) mgl_FragColor = vec4(gcv_Color.rgb * gcu_ColorStatic.rgb, gcv_Color.a * gcu_ColorStatic.a * a); #else mgl_FragColor = vec4(gcu_ColorStatic.rgb, gcu_ColorStatic.a * a); diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1.vp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1.vp index 46729cfd0..c6ed4ca58 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1.vp +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1.vp @@ -11,7 +11,6 @@ void main(void) { - // gl_Position = gcu_PMVMatrix02[0] * gcu_PMVMatrix02[1] * vec4(gca_Vertices, 1); gl_Position = gcu_PMVMatrix02[0] * gcu_PMVMatrix02[1] * gca_Vertices; #if 1 gcv_CurveParam = gca_CurveParams; @@ -24,6 +23,10 @@ void main(void) gcv_CurveParam = gca_CurveParams; } #endif +#ifdef USE_COLOR_TEXTURE + vec2 dim = vec2(gcu_ColorTexBBox.z - gcu_ColorTexBBox.x, gcu_ColorTexBBox.w - gcu_ColorTexBBox.y); + gcv_ColorTexCoord = vec2(gca_Vertices.x - gcu_ColorTexBBox.x, gca_Vertices.y - gcu_ColorTexBBox.y) / dim; +#endif #ifdef USE_COLOR_CHANNEL gcv_Color = gca_Colors; #endif diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-single.vp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-single.vp index 7598c23f8..14210be39 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-single.vp +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-single.vp @@ -11,7 +11,6 @@ void main(void) { - // gl_Position = gcu_PMVMatrix01[0] * gcu_PMVMatrix01[1] * vec4(gca_Vertices, 1); gl_Position = gcu_PMVMatrix01[0] * gcu_PMVMatrix01[1] * gca_Vertices; #if 1 gcv_CurveParam = gca_CurveParams; @@ -24,6 +23,10 @@ void main(void) gcv_CurveParam = gca_CurveParams; } #endif +#ifdef USE_COLOR_TEXTURE + vec2 dim = vec2(gcu_ColorTexBBox.z - gcu_ColorTexBBox.x, gcu_ColorTexBBox.w - gcu_ColorTexBBox.y); + gcv_ColorTexCoord = vec2(gca_Vertices.x - gcu_ColorTexBBox.x, gca_Vertices.y - gcu_ColorTexBBox.y) / dim; +#endif #ifdef USE_COLOR_CHANNEL gcv_Color = gca_Colors; #endif diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl index 848c26819..ae7fa8490 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl @@ -6,6 +6,11 @@ uniform mat4 gcu_PMVMatrix01[3]; // P, Mv, and Mvi uniform vec4 gcu_ColorStatic; uniform float gcu_Weight; +#ifdef USE_COLOR_TEXTURE + uniform sampler2D gcu_ColorTexUnit; + uniform vec4 gcu_ColorTexBBox; +#endif + uniform mat4 gcu_PMVMatrix02[3]; // P, Mv, and Mvi uniform sampler2D gcu_FboTexUnit; @@ -14,11 +19,4 @@ uniform sampler2D gcu_FboTexUnit; */ uniform vec2 gcu_FboTexSize; -// const int MAX_TEXTURE_UNITS = 8; // <= gl_MaxTextureImageUnits -// const int MAX_LIGHTS = 8; -// uniform mat3 gcu_NormalMatrix; // transpose(inverse(ModelView)).3x3 -// uniform int gcu_ColorEnabled; -// uniform int gcu_TexCoordEnabled[MAX_TEXTURE_UNITS]; -// uniform 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 index 2054c9c21..265ab6915 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/varyings.glsl +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/varyings.glsl @@ -6,6 +6,10 @@ varying vec3 gcv_CurveParam; varying vec2 gcv_FboTexCoord; +#ifdef USE_COLOR_TEXTURE + varying vec2 gcv_ColorTexCoord; +#endif + #ifdef USE_COLOR_CHANNEL varying vec4 gcv_Color; #endif diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java index f9107ef3e..ae435961e 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java @@ -278,8 +278,8 @@ public class TestTextRendererNEWT00 extends UITestCase { setRendererCallbacks(RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable); setRenderState(rs); - regionFPS = GLRegion.create(renderModes); - regionFPSAnim = GLRegion.create(renderModes); + regionFPS = GLRegion.create(renderModes, null); + regionFPSAnim = GLRegion.create(renderModes, null); if( null != fontFileName ) { Font _font = null; try { @@ -377,7 +377,7 @@ public class TestTextRendererNEWT00 extends UITestCase { final String modeS = Region.getRenderModeString(renderModes); - if( true ) { + if( false ) { // renderString(drawable, font, pixelSize, "I - / H P 7 0", 0, 0, 0, 0, -1000f, true); // renderString(drawable, font, pixelSize, "A M > } ] ", 0, 0, 0, 0, -1000f, true); // renderString(drawable, font, pixelSize, "M", 0, 0, 0, 0, -1000f, true); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java index b04808300..ad794b646 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java @@ -191,7 +191,7 @@ public class TestTextRendererNEWT10 extends UITestCase { dx += font.getAdvanceWidth('X', fontSize) * column; dy -= (int)textBox.getHeight() * ( row + 1 ); - final PMVMatrix pmv = renderer.getMatrixMutable(); + final PMVMatrix pmv = renderer.getMatrix(); pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); pmv.glLoadIdentity(); pmv.glTranslatef(dx, dy, z0); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TextRendererGLELBase.java b/src/test/com/jogamp/opengl/test/junit/graph/TextRendererGLELBase.java index 207904f89..127cf3fc3 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/TextRendererGLELBase.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/TextRendererGLELBase.java @@ -253,7 +253,7 @@ public abstract class TextRendererGLELBase implements GLEventListener { dx += pixelScale * font.getAdvanceWidth('X', pixelSize) * column; dy -= pixelScale * lineHeight * ( row + 1 ); - final PMVMatrix pmvMatrix = rs.getMatrixMutable(); + final PMVMatrix pmvMatrix = rs.getMatrix(); pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); if( !exclusivePMVMatrix ) { pmvMatrix.glPushMatrix(); @@ -279,7 +279,6 @@ public abstract class TextRendererGLELBase implements GLEventListener { renderer.enable(gl, false); if( !exclusivePMVMatrix ) { - rs.setMatrixDirty(); pmvMatrix.glPopMatrix(); } lastRow = row + newLineCount; diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener01.java index 2b3b2e7d9..48ba148a9 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener01.java @@ -90,7 +90,7 @@ public class GPURegionGLListener01 extends GPURendererListenerBase01 { outlineShape.addVertex(offset+10.0f,0.0f, true); outlineShape.closeLastOutline(true); - region = GLRegion.create(getRenderModes()); + region = GLRegion.create(getRenderModes(), null); region.addOutlineShape(outlineShape, null, region.hasColorChannel() ? getRenderer().getRenderState().getColorStatic(new float[4]) : null); } @@ -116,7 +116,7 @@ public class GPURegionGLListener01 extends GPURendererListenerBase01 { gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); final RegionRenderer regionRenderer = getRenderer(); - final PMVMatrix pmv = regionRenderer.getMatrixMutable(); + final PMVMatrix pmv = regionRenderer.getMatrix(); pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); pmv.glLoadIdentity(); pmv.glTranslatef(getXTran(), getYTran(), getZTran()); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener02.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener02.java index fbf110809..374f2928c 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener02.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener02.java @@ -92,7 +92,7 @@ public class GPURegionGLListener02 extends GPURendererListenerBase01 { shape.addVertex(offset+10.0f,0.0f, true); shape.closeLastOutline(true); - region = GLRegion.create(getRenderModes()); + region = GLRegion.create(getRenderModes(), null); region.addOutlineShapes(outlineShapes, null, null); } @@ -119,7 +119,7 @@ public class GPURegionGLListener02 extends GPURendererListenerBase01 { final RegionRenderer regionRenderer = getRenderer(); - final PMVMatrix pmv = regionRenderer.getMatrixMutable(); + final PMVMatrix pmv = regionRenderer.getMatrix(); pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); pmv.glLoadIdentity(); pmv.glTranslatef(getXTran(), getYTran(), getZTran()); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java index 420e23f4d..72c2509cc 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java @@ -146,7 +146,7 @@ public abstract class GPURendererListenerBase01 implements GLEventListener { @Override public void reshape(GLAutoDrawable drawable, int xstart, int ystart, int width, int height) { - final PMVMatrix pmv = renderer.getMatrixMutable(); + final PMVMatrix pmv = renderer.getMatrix(); renderer.reshapePerspective(45.0f, width, height, zNear, zFar); pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); pmv.glLoadIdentity(); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java index 8b653bdfa..5704f3e7a 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java @@ -117,8 +117,8 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB blending ? RegionRenderer.defaultBlendDisable : null), renderModes, debug, trace); this.textRegionUtil = new TextRegionUtil(renderModes); - this.regionFPS = GLRegion.create(renderModes); - this.regionBottom = GLRegion.create(renderModes); + this.regionFPS = GLRegion.create(renderModes, null); + this.regionBottom = GLRegion.create(renderModes, null); try { this.font = FontFactory.get(fontSet).getDefault(); dumpFontNames(); @@ -213,7 +213,7 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB final RegionRenderer renderer = getRenderer(); final RenderState rs = renderer.getRenderState(); - final PMVMatrix pmv = renderer.getMatrixMutable(); + final PMVMatrix pmv = renderer.getMatrix(); pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); pmv.glLoadIdentity(); rs.setColorStatic(0.1f, 0.1f, 0.1f, 1.0f); @@ -254,7 +254,6 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB float dx = width-fontNameBox.getWidth()-2f; float dy = height - 10f; - renderer.setMatrixDirty(); pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); pmv.glLoadIdentity(); pmv.glTranslatef(nearPlaneX0+(dx*nearPlaneSx), nearPlaneY0+(dy*nearPlaneSy), nearPlaneZ0); @@ -265,7 +264,6 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB dy += -fontNameBox.getHeight() - 10f; if(null != headtext) { - renderer.setMatrixDirty(); pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); pmv.glLoadIdentity(); // System.err.printf("Head: [%f %f] -> [%f %f]%n", dx, dy, nearPlaneX0+(dx*nearPlaneSx), nearPlaneY0+(dy*nearPlaneSy)); @@ -276,7 +274,6 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB dy += -headbox.getHeight() - font.getLineHeight(pixelSizeBottom); - renderer.setMatrixDirty(); pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); pmv.glLoadIdentity(); pmv.glTranslatef(nearPlaneX0+(dx*nearPlaneSx), nearPlaneY0+(dy*nearPlaneSy), nearPlaneZ0); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java index e93d6607e..f9f9d58a0 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java @@ -29,9 +29,12 @@ import com.jogamp.opengl.math.FloatUtil; import com.jogamp.opengl.math.VectorUtil; import com.jogamp.opengl.test.junit.graph.demos.ui.CrossHair; import com.jogamp.opengl.test.junit.graph.demos.ui.Label; -import com.jogamp.opengl.test.junit.graph.demos.ui.RIButton; +import com.jogamp.opengl.test.junit.graph.demos.ui.LabelButton; +import com.jogamp.opengl.test.junit.graph.demos.ui.RoundButton; import com.jogamp.opengl.test.junit.graph.demos.ui.SceneUIController; +import com.jogamp.opengl.test.junit.graph.demos.ui.TextureButton; import com.jogamp.opengl.test.junit.graph.demos.ui.UIShape; +import com.jogamp.opengl.test.junit.jogl.demos.TextureSequenceDemo01; import com.jogamp.opengl.util.GLReadBufferUtil; public class GPUUISceneGLListener0A implements GLEventListener { @@ -52,7 +55,7 @@ public class GPUUISceneGLListener0A implements GLEventListener { private final float zNear = 0.1f, zFar = 7000f; private final float relTop = 5f/6f; - private final float relRight = 2f/6f; + private final float relMiddle = 2f/6f; private final float relLeft = 1f/6f; /** Proportional Button Size to Window Height, per-vertical-pixels [PVP] */ @@ -70,7 +73,7 @@ public class GPUUISceneGLListener0A implements GLEventListener { private String actionText = null; private Label[] labels = null; private String[] strings = null; - private final List<RIButton> buttons = new ArrayList<RIButton>(); + private final List<RoundButton> buttons = new ArrayList<RoundButton>(); private Label truePtSizeLabel = null; private Label jogampLabel = null; private Label fpsLabel = null; @@ -122,9 +125,13 @@ public class GPUUISceneGLListener0A implements GLEventListener { private void setButtonsSpacing(float dx, float dy) { for(int i=0; i<buttons.size(); i++) { - final float sx = buttons.get(i).getSpacingX()+dx, sy = buttons.get(i).getSpacingY()+dy; - System.err.println("Spacing: X "+sx+", Y "+sy); - buttons.get(i).setSpacing(sx, sy); + final RoundButton b = buttons.get(i); + if( b instanceof LabelButton ) { + final LabelButton lb = (LabelButton) b; + final float sx = lb.getSpacingX()+dx, sy = lb.getSpacingY()+dy; + System.err.println("Spacing: X "+sx+", Y "+sy); + lb.setSpacing(sx, sy); + } } } @@ -138,13 +145,16 @@ public class GPUUISceneGLListener0A implements GLEventListener { private void resetButtons() { for(int i=0; i<buttons.size(); i++) { - buttons.get(i).getRotation().setIdentity(); - buttons.get(i).setCorner(RIButton.DEFAULT_CORNER); - buttons.get(i).setSpacing(RIButton.DEFAULT_SPACING_X, RIButton.DEFAULT_SPACING_Y); + final RoundButton b = buttons.get(i); + b.getRotation().setIdentity(); + b.setCorner(RoundButton.DEFAULT_CORNER); + if( b instanceof LabelButton ) { + ((LabelButton)b).setSpacing(LabelButton.DEFAULT_SPACING_X, LabelButton.DEFAULT_SPACING_Y); + } } } - private void initButtons(final GL gl, final int width, final int height, final float labelZOffset, final RegionRenderer renderer) { + private void initButtons(final GL2ES2 gl, final int width, final int height, final float labelZOffset, final RegionRenderer renderer) { final boolean pass2Mode = Region.isTwoPass( renderModes ) ; buttons.clear(); @@ -156,9 +166,8 @@ public class GPUUISceneGLListener0A implements GLEventListener { final float diffX = 1.2f * buttonXSize; final float diffY = 1.5f * buttonYSize; - RIButton button = new RIButton(SVertex.factory(), renderModes, font, "Next Text", buttonXSize, buttonYSize, labelZOffset); + LabelButton button = new LabelButton(SVertex.factory(), renderModes, font, "Next Text", buttonXSize, buttonYSize, labelZOffset); button.translate(xstart,ystart-diffY*buttons.size(), 0f); - button.setLabelColor(1.0f, 1.0f, 1.0f); button.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { @@ -173,11 +182,11 @@ public class GPUUISceneGLListener0A implements GLEventListener { button.addMouseListener(dragZoomRotateListener); buttons.add(button); - button = new RIButton(SVertex.factory(), renderModes, font, "Show FPS", buttonXSize, buttonYSize, labelZOffset); + button = new LabelButton(SVertex.factory(), renderModes, font, "Show FPS", buttonXSize, buttonYSize, labelZOffset); + button.setName(100); // FIXME: DEBUG tag button.translate(xstart,ystart - diffY*buttons.size(), 0f); button.setToggleable(true); - button.setPressed(fpsLabel.isEnabled()); - button.setLabelColor(1.0f, 1.0f, 1.0f); + button.setToggleState(fpsLabel.isEnabled()); button.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { @@ -190,11 +199,10 @@ public class GPUUISceneGLListener0A implements GLEventListener { button.addMouseListener(dragZoomRotateListener); buttons.add(button); - button = new RIButton(SVertex.factory(), renderModes, font, "v-sync", buttonXSize, buttonYSize, labelZOffset); + button = new LabelButton(SVertex.factory(), renderModes, font, "v-sync", buttonXSize, buttonYSize, labelZOffset); button.translate(xstart,ystart - diffY*buttons.size(), 0f); button.setToggleable(true); - button.setPressed(gl.getSwapInterval()>0); - button.setLabelColor(1.0f, 1.0f, 1.0f); + button.setToggleState(gl.getSwapInterval()>0); button.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { @@ -214,9 +222,8 @@ public class GPUUISceneGLListener0A implements GLEventListener { button.addMouseListener(dragZoomRotateListener); buttons.add(button); - button = new RIButton(SVertex.factory(), renderModes, font, "< tilt >", buttonXSize, buttonYSize, labelZOffset); + button = new LabelButton(SVertex.factory(), renderModes, font, "< tilt >", buttonXSize, buttonYSize, labelZOffset); button.translate(xstart,ystart - diffY*buttons.size(), 0f); - button.setLabelColor(1.0f, 1.0f, 1.0f); button.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { @@ -237,9 +244,8 @@ public class GPUUISceneGLListener0A implements GLEventListener { buttons.add(button); if( pass2Mode ) { // second column to the left - button = new RIButton(SVertex.factory(), renderModes, font, "< samples >", buttonXSize, buttonYSize, labelZOffset); + button = new LabelButton(SVertex.factory(), renderModes, font, "< samples >", buttonXSize, buttonYSize, labelZOffset); button.translate(xstart,ystart - diffY*buttons.size(), 0f); - button.setLabelColor(1.0f, 1.0f, 1.0f); button.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { @@ -264,9 +270,8 @@ public class GPUUISceneGLListener0A implements GLEventListener { button.addMouseListener(dragZoomRotateListener); buttons.add(button); - button = new RIButton(SVertex.factory(), renderModes, font, "< quality >", buttonXSize, buttonYSize, labelZOffset); + button = new LabelButton(SVertex.factory(), renderModes, font, "< quality >", buttonXSize, buttonYSize, labelZOffset); button.translate(xstart,ystart - diffY*buttons.size(), 0f); - button.setLabelColor(1.0f, 1.0f, 1.0f); button.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { @@ -293,10 +298,9 @@ public class GPUUISceneGLListener0A implements GLEventListener { buttons.add(button); } - button = new RIButton(SVertex.factory(), renderModes, font, "Quit", buttonXSize, buttonYSize, labelZOffset); + button = new LabelButton(SVertex.factory(), renderModes, font, "Quit", buttonXSize, buttonYSize, labelZOffset); button.translate(xstart,ystart - diffY*buttons.size(), 0f); button.setColor(0.8f, 0.0f, 0.0f, 1.0f); - button.setLabelColor(1.0f, 1.0f, 1.0f); button.setSelectedColorMod(0.8f, 0.8f, 0.8f, 1.0f); button.addMouseListener(new MouseAdapter() { @Override @@ -319,9 +323,8 @@ public class GPUUISceneGLListener0A implements GLEventListener { { int j = 1; // column int k = 0; // row - button = new RIButton(SVertex.factory(), renderModes, font, "y flip", buttonXSize, buttonYSize, labelZOffset); + button = new LabelButton(SVertex.factory(), renderModes, font, "y flip", buttonXSize, buttonYSize, labelZOffset); button.translate(xstart - diffX*j,ystart - diffY*k, 0f); - button.setLabelColor(1.0f, 1.0f, 1.0f); button.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { @@ -331,9 +334,8 @@ public class GPUUISceneGLListener0A implements GLEventListener { buttons.add(button); k++; - button = new RIButton(SVertex.factory(), renderModes, font, "x flip", buttonXSize, buttonYSize, labelZOffset); + button = new LabelButton(SVertex.factory(), renderModes, font, "x flip", buttonXSize, buttonYSize, labelZOffset); button.translate(xstart - diffX*j,ystart - diffY*k, 0f); - button.setLabelColor(1.0f, 1.0f, 1.0f); button.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { @@ -343,9 +345,8 @@ public class GPUUISceneGLListener0A implements GLEventListener { buttons.add(button); k++; - button = new RIButton(SVertex.factory(), renderModes, font, "+", buttonXSize, buttonYSize, labelZOffset); + button = new LabelButton(SVertex.factory(), renderModes, font, "+", buttonXSize, buttonYSize, labelZOffset); button.translate(xstart - diffX*j,ystart - diffY*k, 0f); - button.setLabelColor(1.0f, 1.0f, 1.0f); button.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { @@ -371,9 +372,8 @@ public class GPUUISceneGLListener0A implements GLEventListener { buttons.add(button); k++; - button = new RIButton(SVertex.factory(), renderModes, font, "< space >", buttonXSize, buttonYSize, labelZOffset); + button = new LabelButton(SVertex.factory(), renderModes, font, "< space >", buttonXSize, buttonYSize, labelZOffset); button.translate(xstart - diffX*j,ystart - diffY*k, 0f); - button.setLabelColor(1.0f, 1.0f, 1.0f); button.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { @@ -396,9 +396,8 @@ public class GPUUISceneGLListener0A implements GLEventListener { buttons.add(button); k++; - button = new RIButton(SVertex.factory(), renderModes, font, "< corner >", buttonXSize, buttonYSize, labelZOffset); + button = new LabelButton(SVertex.factory(), renderModes, font, "< corner >", buttonXSize, buttonYSize, labelZOffset); button.translate(xstart - diffX*j,ystart - diffY*k, 0f); - button.setLabelColor(1.0f, 1.0f, 1.0f); button.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { @@ -422,9 +421,8 @@ public class GPUUISceneGLListener0A implements GLEventListener { buttons.add(button); k++; - button = new RIButton(SVertex.factory(), renderModes, font, "reset", buttonXSize, buttonYSize, labelZOffset); + button = new LabelButton(SVertex.factory(), renderModes, font, "reset", buttonXSize, buttonYSize, labelZOffset); button.translate(xstart - diffX*j,ystart - diffY*k, 0f); - button.setLabelColor(1.0f, 1.0f, 1.0f); button.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { @@ -434,9 +432,8 @@ public class GPUUISceneGLListener0A implements GLEventListener { buttons.add(button); k++; - button = new RIButton(SVertex.factory(), renderModes, font, "screenshot", buttonXSize, buttonYSize, labelZOffset); + button = new LabelButton(SVertex.factory(), renderModes, font, "screenshot", buttonXSize, buttonYSize, labelZOffset); button.translate(xstart - diffX*j,ystart - diffY*k, 0f); - button.setLabelColor(1.0f, 1.0f, 1.0f); button.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { @@ -453,6 +450,17 @@ public class GPUUISceneGLListener0A implements GLEventListener { k++; } + if(true) { + final TextureSequenceDemo01 texSeq = new TextureSequenceDemo01(true); + gl.glActiveTexture(GL.GL_TEXTURE0 + texSeq.getTextureUnit()); + texSeq.initGLResources(gl); + final TextureButton texButton = new TextureButton(renderer.getRenderState().getVertexFactory(), renderModes, + 2f*buttonXSize, 2f*buttonYSize, texSeq); + texButton.translate(xstart + diffX*5, ystart - diffY*1, 0f); + texButton.setToggleable(true); + texButton.addMouseListener(dragZoomRotateListener); + buttons.add(texButton); + } } private void initTexts() { @@ -541,7 +549,7 @@ public class GPUUISceneGLListener0A implements GLEventListener { final int zBits = drawable.getChosenGLCapabilities().getDepthBits(); final float zEpsilon = FloatUtil.getZBufferEpsilon(zBits, sceneDist, zNear); - final float labelZOffset = Region.isTwoPass(renderModes) ? RIButton.DEFAULT_2PASS_LABEL_ZOFFSET : -2f*zEpsilon; + final float labelZOffset = Region.isTwoPass(renderModes) ? LabelButton.DEFAULT_2PASS_LABEL_ZOFFSET : -2f*zEpsilon; System.err.println("zEpsilon "+zEpsilon+" ( zBits "+zBits+") -> labelZOffset "+labelZOffset); renderer.init(gl, renderModes); @@ -634,7 +642,7 @@ public class GPUUISceneGLListener0A implements GLEventListener { if(null == labels[currentText]) { final float pixelSizeFixed = fontSizeFixedPVP * drawable.getHeight(); final float dyTop = drawable.getHeight() * relTop; - final float dxRight = drawable.getWidth() * relRight; + final float dxRight = drawable.getWidth() * relMiddle; labels[currentText] = new Label(renderer.getRenderState().getVertexFactory(), renderModes, font, pixelSizeFixed, strings[currentText]); labels[currentText].setColor(0.1f, 0.1f, 0.1f, 1.0f); labels[currentText].setEnabled(enableOthers); @@ -689,17 +697,17 @@ public class GPUUISceneGLListener0A implements GLEventListener { final float dz = 0f; final float dyTop = dh * relTop; - final float dxRight = dw * relRight; + final float dxMiddle = dw * relMiddle; final float dxLeft = dw * relLeft; for(int i=0; i<buttons.size(); i++) { buttons.get(i).translate(dxLeft, dyTop, dz); } - jogampLabel.translate(dxRight, dyTop, dz); - truePtSizeLabel.translate(dxRight, dyTop, dz); + jogampLabel.translate(dxMiddle, dyTop, dz); + truePtSizeLabel.translate(dxMiddle, dyTop, dz); fpsLabel.translate(0f, 0f, 0f); if( null != labels[currentText] ) { - labels[currentText].translate(dxRight, dyTop, 0f); + labels[currentText].translate(dxMiddle, dyTop, 0f); } crossHairCtr.translate(dw/2f, dh/2f, 0f); @@ -784,7 +792,7 @@ public class GPUUISceneGLListener0A implements GLEventListener { if( attachment instanceof UIShape.EventDetails ) { final UIShape.EventDetails shapeEvent = (UIShape.EventDetails)attachment; if( 0 == ( ~InputEvent.BUTTONALL_MASK & e.getModifiers() ) ) { - float tz = 2f*e.getRotation()[1]; // vertical: wheel + float tz = 8f*e.getRotation()[1]; // vertical: wheel System.err.println("tz.4 "+tz); shapeEvent.shape.translate(0f, 0f, tz); } else if( e.isControlDown() ) { diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/CrossHair.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/CrossHair.java index a0842b142..a15e2acdd 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/CrossHair.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/CrossHair.java @@ -55,7 +55,7 @@ public class CrossHair extends UIShape { this.width = width; this.height = height; this.lineWidth = lineWidth; - dirty |= DIRTY_SHAPE; + markShapeDirty(); } @Override diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label.java index 4a14bb442..37a82fe0f 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label.java @@ -56,7 +56,7 @@ public class Label extends UIShape { public void setText(String text) { this.text = text; - dirty |= DIRTY_SHAPE; + markShapeDirty(); } public Font getFont() { @@ -65,7 +65,7 @@ public class Label extends UIShape { public void setFont(Font font) { this.font = font; - dirty |= DIRTY_SHAPE; + markShapeDirty(); } public float getPixelSize() { @@ -78,7 +78,7 @@ public class Label extends UIShape { public void setPixelSize(float pixelSize) { this.pixelSize = pixelSize; - dirty |= DIRTY_SHAPE; + markShapeDirty(); } @Override diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/RIButton.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/LabelButton.java index 5315a8927..64cf794c6 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/RIButton.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/LabelButton.java @@ -29,8 +29,6 @@ package com.jogamp.opengl.test.junit.graph.demos.ui; import javax.media.opengl.GL2ES2; -import jogamp.graph.geom.plane.AffineTransform; - import com.jogamp.graph.curve.OutlineShape; import com.jogamp.graph.curve.Region; import com.jogamp.graph.curve.opengl.RegionRenderer; @@ -42,49 +40,25 @@ import com.jogamp.opengl.math.geom.AABBox; /** * GPU based resolution independent Button impl */ -public class RIButton extends UIShape { +public class LabelButton extends RoundButton { /** {@value} */ public static final float DEFAULT_SPACING_X = 0.08f; /** {@value} */ public static final float DEFAULT_SPACING_Y = 0.40f; - /** {@value} */ - public static final float DEFAULT_CORNER = 1f; - public static final float DEFAULT_2PASS_LABEL_ZOFFSET = -0.05f; - private float width, height, labelZOffset; + private float labelZOffset; private final Label0 label; private float spacingX = DEFAULT_SPACING_X; private float spacingY = DEFAULT_SPACING_Y; - private float corner = DEFAULT_CORNER; - private final AffineTransform tempT1 = new AffineTransform(); - private final AffineTransform tempT2 = new AffineTransform(); - - public RIButton(Factory<? extends Vertex> factory, int renderModes, Font labelFont, String labelText, float width, float height, float labelZOffset) { - super(factory, renderModes | Region.COLORCHANNEL_RENDERING_BIT); + public LabelButton(final Factory<? extends Vertex> factory, final int renderModes, + final Font labelFont, final String labelText, + final float width, final float height, final float labelZOffset) { + super(factory, renderModes | Region.COLORCHANNEL_RENDERING_BIT, width, height); this.label = new Label0(labelFont, labelText, new float[] { 0.9f, 0.9f, 0.9f, 1.0f }); - this.width = width; - this.height = height; this.labelZOffset = labelZOffset; - } - - public final float getWidth() { return width; } - public final float getHeight() { return height; } - public final float getCorner() { return corner; } - - public void setDimension(float width, float height) { - this.width = width; - this.height = height; - dirty |= DIRTY_SHAPE; - } - - @Override - protected void clearImpl(GL2ES2 gl, RegionRenderer renderer) { - } - - @Override - protected void destroyImpl(GL2ES2 gl, RegionRenderer renderer) { + setLabelColor(1.0f, 1.0f, 1.0f); } @Override @@ -104,9 +78,9 @@ public class RIButton extends UIShape { protected void addShapeToRegion(GL2ES2 gl, RegionRenderer renderer) { final OutlineShape shape = new OutlineShape(renderer.getRenderState().getVertexFactory()); if(corner == 0.0f) { - createSharpOutline(shape); + createSharpOutline(shape, labelZOffset); } else { - createCurvedOutline(shape); + createCurvedOutline(shape, labelZOffset); } shape.setIsQuadraticNurbs(); shape.setSharpness(shapesSharpness); @@ -148,68 +122,14 @@ public class RIButton extends UIShape { System.err.println("XXX.UIShape.RIButton: Added Shape: "+shape+", "+box); } } - private void createSharpOutline(OutlineShape shape) { - final float tw = getWidth(); - final float th = getHeight(); - - final float minX = 0; - final float minY = 0; - final float minZ = labelZOffset; - - shape.addVertex(minX, minY, minZ, true); - shape.addVertex(minX+tw, minY, minZ, true); - shape.addVertex(minX+tw, minY + th, minZ, true); - shape.addVertex(minX, minY + th, minZ, true); - shape.closeLastOutline(true); - } - private void createCurvedOutline(OutlineShape shape) { - final float tw = getWidth(); - final float th = getHeight(); - final float dC = 0.5f*corner*Math.min(tw, th); - - final float minX = 0; - final float minY = 0; - final float minZ = labelZOffset; - - shape.addVertex(minX, minY + dC, minZ, true); - shape.addVertex(minX, minY, minZ, false); - - shape.addVertex(minX + dC, minY, minZ, true); - - shape.addVertex(minX + tw - dC, minY, minZ, true); - shape.addVertex(minX + tw, minY, minZ, false); - shape.addVertex(minX + tw, minY + dC, minZ, true); - shape.addVertex(minX + tw, minY + th- dC, minZ, true); - shape.addVertex(minX + tw, minY + th, minZ, false); - shape.addVertex(minX + tw - dC, minY + th, minZ, true); - shape.addVertex(minX + dC, minY + th, minZ, true); - shape.addVertex(minX, minY + th, minZ, false); - shape.addVertex(minX, minY + th - dC, minZ, true); - - shape.closeLastOutline(true); - } - /** Set corner size, default is {@link #DEFAULT_CORNER} */ - public void setCorner(float corner) { - if(corner > 1.0f){ - this.corner = 1.0f; - } - else if(corner < 0.01f){ - this.corner = 0.0f; - } - else{ - this.corner = corner; - } - dirty |= DIRTY_SHAPE; - } - - public float getLabelZOffset() { + public final float getLabelZOffset() { return labelZOffset; } - public void setLabelZOffset(final float labelZOffset) { + public final void setLabelZOffset(final float labelZOffset) { this.labelZOffset = labelZOffset; - dirty |= DIRTY_SHAPE; + markShapeDirty(); } public final float getSpacingX() { return spacingX; } public final float getSpacingY() { return spacingY; } @@ -219,7 +139,7 @@ public class RIButton extends UIShape { * @param spacingX spacing in percent on X, default is {@link #DEFAULT_SPACING_X} * @param spacingY spacing in percent on Y, default is {@link #DEFAULT_SPACING_Y} */ - public void setSpacing(float spacingX, float spacingY) { + public final void setSpacing(float spacingX, float spacingY) { if ( spacingX < 0.0f ) { this.spacingX = 0.0f; } else if ( spacingX > 1.0f ) { @@ -234,21 +154,27 @@ public class RIButton extends UIShape { } else { this.spacingY = spacingY; } - dirty |= DIRTY_SHAPE; + markShapeDirty(); } - public float[] getLabelColor() { + public final float[] getLabelColor() { return label.getColor(); } - public void setLabelColor(float r, float g, float b) { + public final void setLabelColor(float r, float g, float b) { label.setColor(r, g, b, 1.0f); + markShapeDirty(); + } + + public final void setLabelText(final Font labelFont, final String labelText) { + label.setFont(labelFont); + label.setText(labelText); + markShapeDirty(); } @Override - public String toString() { - return "RIButton [" + translate[0]+getWidth()/2f+" / "+translate[1]+getHeight()/2f+" "+getWidth() + "x" + getHeight() + ", " - + label + ", " + "spacing: " + spacingX+"/"+spacingY - + ", " + "corner: " + corner + ", " + "shapeOffset: " + labelZOffset + ", "+box+" ]"; + public String getSubString() { + return super.getSubString()+", "+ label + ", " + "spacing: " + spacingX+"/"+spacingY+ + ", labelZOffset " + labelZOffset; } } diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/RoundButton.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/RoundButton.java new file mode 100644 index 000000000..eddcb756e --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/RoundButton.java @@ -0,0 +1,108 @@ +package com.jogamp.opengl.test.junit.graph.demos.ui; + +import javax.media.opengl.GL2ES2; + +import jogamp.graph.geom.plane.AffineTransform; + +import com.jogamp.graph.curve.OutlineShape; +import com.jogamp.graph.curve.opengl.RegionRenderer; +import com.jogamp.graph.geom.Vertex; +import com.jogamp.graph.geom.Vertex.Factory; + +public abstract class RoundButton extends UIShape { + + /** {@value} */ + public static final float DEFAULT_CORNER = 1f; + protected float width; + protected float height; + protected float corner = DEFAULT_CORNER; + protected final AffineTransform tempT1 = new AffineTransform(); + protected final AffineTransform tempT2 = new AffineTransform(); + + protected RoundButton(final Factory<? extends Vertex> factory, final int renderModes, final float width, final float height) { + super(factory, renderModes); + this.width = width; + this.height = height; + } + + @Override + protected void clearImpl(GL2ES2 gl, RegionRenderer renderer) { + } + + @Override + protected void destroyImpl(GL2ES2 gl, RegionRenderer renderer) { + } + + public final float getWidth() { return width; } + + public final float getHeight() { return height; } + + public final float getCorner() { return corner; } + + public void setDimension(float width, float height) { + this.width = width; + this.height = height; + markShapeDirty(); + } + + protected void createSharpOutline(final OutlineShape shape, final float zOffset) { + final float tw = getWidth(); + final float th = getHeight(); + + final float minX = 0; + final float minY = 0; + final float minZ = zOffset; + + shape.addVertex(minX, minY, minZ, true); + shape.addVertex(minX+tw, minY, minZ, true); + shape.addVertex(minX+tw, minY + th, minZ, true); + shape.addVertex(minX, minY + th, minZ, true); + shape.closeLastOutline(true); + } + + protected void createCurvedOutline(final OutlineShape shape, final float zOffset) { + final float tw = getWidth(); + final float th = getHeight(); + final float dC = 0.5f*corner*Math.min(tw, th); + + final float minX = 0; + final float minY = 0; + final float minZ = zOffset; + + shape.addVertex(minX, minY + dC, minZ, true); + shape.addVertex(minX, minY, minZ, false); + + shape.addVertex(minX + dC, minY, minZ, true); + + shape.addVertex(minX + tw - dC, minY, minZ, true); + shape.addVertex(minX + tw, minY, minZ, false); + shape.addVertex(minX + tw, minY + dC, minZ, true); + shape.addVertex(minX + tw, minY + th- dC, minZ, true); + shape.addVertex(minX + tw, minY + th, minZ, false); + shape.addVertex(minX + tw - dC, minY + th, minZ, true); + shape.addVertex(minX + dC, minY + th, minZ, true); + shape.addVertex(minX, minY + th, minZ, false); + shape.addVertex(minX, minY + th - dC, minZ, true); + + shape.closeLastOutline(true); + } + + /** Set corner size, default is {@link #DEFAULT_CORNER} */ + public void setCorner(float corner) { + if(corner > 1.0f){ + this.corner = 1.0f; + } + else if(corner < 0.01f){ + this.corner = 0.0f; + } + else{ + this.corner = corner; + } + markShapeDirty(); + } + + @Override + public String getSubString() { + return super.getSubString()+", dim "+getWidth() + "x" + getHeight() + ", corner " + corner; + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/SceneUIController.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/SceneUIController.java index 62e82a038..45907ad6a 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/SceneUIController.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/SceneUIController.java @@ -96,7 +96,7 @@ public class SceneUIController implements GLEventListener{ } public void markAllShapesDirty() { for(int i=0; i<shapes.size(); i++) { - shapes.get(i).markDirty(); + shapes.get(i).markShapeDirty(); } } @@ -180,7 +180,7 @@ public class SceneUIController implements GLEventListener{ gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); - final PMVMatrix pmv = renderer.getMatrixMutable(); + final PMVMatrix pmv = renderer.getMatrix(); pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); final int shapeCount = shapes.size(); @@ -191,7 +191,6 @@ public class SceneUIController implements GLEventListener{ pmv.glPushMatrix(); transformShape(pmv, uiShape); uiShape.drawShape(gl, renderer, sampleCount); - renderer.setMatrixDirty(); pmv.glPopMatrix(); } } @@ -218,7 +217,7 @@ public class SceneUIController implements GLEventListener{ viewport[2] = width; viewport[3] = height; - final PMVMatrix pmv = renderer.getMatrixMutable(); + final PMVMatrix pmv = renderer.getMatrix(); renderer.reshapePerspective(45.0f, width, height, zNear, zFar); pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); pmv.glLoadIdentity(); @@ -308,7 +307,6 @@ public class SceneUIController implements GLEventListener{ activeId = pickShape(glWinX, glWinY); final UIShape uiShape = getActiveUI(); if(uiShape != null) { - uiShape.setPressed(true); uiShape.dispatchMouseEvent(e, glWinX, glWinY); } return true; @@ -319,7 +317,6 @@ public class SceneUIController implements GLEventListener{ public void mouseReleased(MouseEvent e) { final UIShape uiShape = getActiveUI(); if(uiShape != null){ - uiShape.setPressed(false); uiShape.dispatchMouseEvent(e, e.getX(), viewport[3]-e.getY()); } } diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/TextureButton.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/TextureButton.java new file mode 100644 index 000000000..eeb5e19f3 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/TextureButton.java @@ -0,0 +1,82 @@ +/** + * Copyright 2014 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.opengl.test.junit.graph.demos.ui; + +import javax.media.opengl.GL2ES2; + +import com.jogamp.graph.curve.OutlineShape; +import com.jogamp.graph.curve.Region; +import com.jogamp.graph.curve.opengl.GLRegion; +import com.jogamp.graph.curve.opengl.RegionRenderer; +import com.jogamp.graph.geom.Vertex; +import com.jogamp.graph.geom.Vertex.Factory; +import com.jogamp.opengl.util.texture.TextureSequence; + +/** + * GPU based resolution independent Button impl + */ +public class TextureButton extends RoundButton { + private TextureSequence texSeq; + + public TextureButton(final Factory<? extends Vertex> factory, final int renderModes, + final float width, final float height, final TextureSequence texSeq) { + super(factory, renderModes | Region.COLORTEXTURE_RENDERING_BIT, width, height); + this.texSeq = texSeq; + setColor(1.0f, 1.0f, 1.0f, 1.0f); + setSelectedColorMod(0.9f, 0.9f, 0.9f, 0.9f); + } + + @Override + protected GLRegion createGLRegion() { + return GLRegion.create(getRenderModes(), texSeq); + } + + public void setTextureSequence(final TextureSequence texSeq) { this.texSeq = texSeq; } + public TextureSequence getTextureSequence() { return this.texSeq; } + + @Override + protected void addShapeToRegion(GL2ES2 gl, RegionRenderer renderer) { + final OutlineShape shape = new OutlineShape(renderer.getRenderState().getVertexFactory()); + if(corner == 0.0f) { + createSharpOutline(shape, 0f); + } else { + createCurvedOutline(shape, 0f); + } + shape.setIsQuadraticNurbs(); + shape.setSharpness(shapesSharpness); + region.addOutlineShape(shape, null, rgbaColor); + box.resize(shape.getBounds()); + + final float[] ctr = box.getCenter(); + setRotationOrigin( ctr[0], ctr[1], ctr[2]); + + if( DRAW_DEBUG_BOX ) { + System.err.println("XXX.UIShape.TextureButton: Added Shape: "+shape+", "+box); + } + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIGLListener01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIGLListener01.java index 4bab03088..90eb7d4f0 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIGLListener01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIGLListener01.java @@ -50,7 +50,7 @@ public class UIGLListener01 extends UIListenerBase01 { setMatrix(-20, 00, 0f, -50); try { final Font font = FontFactory.get(FontFactory.UBUNTU).getDefault(); - button = new RIButton(SVertex.factory(), 0, font, "Click me!", 4f, 3f, -0.05f); + button = new LabelButton(SVertex.factory(), 0, font, "Click me!", 4f, 3f, -0.05f); button.translate(2,1,0); /** Button defaults ! button.setLabelColor(1.0f,1.0f,1.0f); @@ -89,7 +89,7 @@ public class UIGLListener01 extends UIListenerBase01 { final float[] translate = button.getTranslate(); final RegionRenderer regionRenderer = getRegionRenderer(); - final PMVMatrix pmv = regionRenderer.getMatrixMutable(); + final PMVMatrix pmv = regionRenderer.getMatrix(); pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); pmv.glLoadIdentity(); pmv.glTranslatef(getXTran(), getYTran(), getZoom()); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIListenerBase01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIListenerBase01.java index 5445c6145..638ddac3c 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIListenerBase01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIListenerBase01.java @@ -67,7 +67,7 @@ public abstract class UIListenerBase01 implements GLEventListener { private final boolean debug; private final boolean trace; - protected RIButton button; + protected LabelButton button; private KeyAction keyAction; private MouseAction mouseAction; diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIShape.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIShape.java index 554398435..abe0fcc76 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIShape.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIShape.java @@ -50,6 +50,7 @@ public abstract class UIShape { public static final boolean DRAW_DEBUG_BOX = false; protected static final int DIRTY_SHAPE = 1 << 0 ; + protected static final int DIRTY_STATE = 1 << 1 ; private final Factory<? extends Vertex> vertexFactory; private final int renderModes; @@ -63,12 +64,14 @@ public abstract class UIShape { protected GLRegion region = null; protected int regionQuality = Region.MAX_QUALITY; - protected int dirty = DIRTY_SHAPE; + protected int dirty = DIRTY_SHAPE | DIRTY_STATE; protected float shapesSharpness = OutlineShape.DEFAULT_SHARPNESS; protected final float[] rgbaColor = {0.6f, 0.6f, 0.6f, 1.0f}; protected final float[] selectedRGBAModulate = {1.4f, 1.4f, 1.4f, 1.0f}; + private int name = -1; + private boolean down = false; private boolean toggle =false; private boolean toggleable = false; @@ -81,6 +84,9 @@ public abstract class UIShape { this.box = new AABBox(); } + public void setName(final int name) { this.name = name; } + public int getName() { return this.name; } + public final Vertex.Factory<? extends Vertex> getVertexFactory() { return vertexFactory; } public boolean isEnabled() { return enabled; } @@ -104,7 +110,7 @@ public abstract class UIShape { scale[1] = 1f; scale[2] = 1f; box.reset(); - dirty = DIRTY_SHAPE; + markShapeDirty(); } /** @@ -125,7 +131,7 @@ public abstract class UIShape { scale[1] = 1f; scale[2] = 1f; box.reset(); - dirty = DIRTY_SHAPE; + markShapeDirty(); } public void setTranslate(float tx, float ty, float tz) { @@ -160,12 +166,18 @@ public abstract class UIShape { } public final float[] getScale() { return scale; } - public final void markDirty() { - dirty = DIRTY_SHAPE; + public final void markShapeDirty() { + dirty |= DIRTY_SHAPE; } public final boolean isShapeDirty() { return 0 != ( dirty & DIRTY_SHAPE ) ; } + public final void markStateDirty() { + dirty |= DIRTY_STATE; + } + public final boolean isStateDirty() { + return 0 != ( dirty & DIRTY_STATE ) ; + } public final AABBox getBounds() { return box; } @@ -188,7 +200,7 @@ public abstract class UIShape { public void drawShape(GL2ES2 gl, RegionRenderer renderer, int[] sampleCount) { final float r, g, b, a; final boolean isSelect; - if( isPressed() || toggle ) { + if( isPressed() || getToggleState() ) { isSelect = true; r = rgbaColor[0]*selectedRGBAModulate[0]; g = rgbaColor[1]*selectedRGBAModulate[1]; @@ -203,11 +215,12 @@ public abstract class UIShape { } if( renderer.getRenderState().isHintMaskSet(RenderState.BITHINT_BLENDING_ENABLED) ) { - gl.glClearColor(r, g, b, 0.0f); + // gl.glClearColor(r, g, b, 0.0f); + gl.glClearColor(1.0f, 1.0f, 1.0f, 0.0f); } final RenderState rs = renderer.getRenderState(); - if( Region.hasColorChannel( renderModes ) ) { + if( Region.hasColorChannel( renderModes ) || Region.hasColorTexture( renderModes ) ) { if( isSelect ) { rs.setColorStatic(selectedRGBAModulate[0], selectedRGBAModulate[1], selectedRGBAModulate[2], selectedRGBAModulate[3]); } else { @@ -219,11 +232,15 @@ public abstract class UIShape { getRegion(gl, renderer).draw(gl, renderer, sampleCount); } - public final boolean validate(GL2ES2 gl, RegionRenderer renderer) { - if( isShapeDirty() ) { + protected GLRegion createGLRegion() { + return GLRegion.create(renderModes, null); + } + + public final void validate(GL2ES2 gl, RegionRenderer renderer) { + if( isShapeDirty() || null == region ) { box.reset(); if( null == region ) { - region = GLRegion.create(renderModes); + region = createGLRegion(); } else { region.clear(gl); } @@ -236,10 +253,12 @@ public abstract class UIShape { region.addOutlineShape(shape, null, rgbaColor); } region.setQuality(regionQuality); - dirty &= ~DIRTY_SHAPE; - return true; - } else { - return false; + // dirty &= ~(DIRTY_SHAPE | DIRTY_STATE); + dirty = 0; + } else if( isStateDirty() ) { + region.markDirty(); + // dirty &= ~DIRTY_STATE; + dirty = 0; } } @@ -256,7 +275,7 @@ public abstract class UIShape { } public final void setSharpness(float sharpness) { this.shapesSharpness = sharpness; - dirty = DIRTY_SHAPE; + markShapeDirty(); } public final float getSharpness() { return shapesSharpness; @@ -276,33 +295,44 @@ public abstract class UIShape { } public String toString() { - return getClass().getSimpleName()+"[enabled "+enabled+", "+translate[0]+" / "+translate[1]+", box "+box+"]"; + return getClass().getSimpleName()+"["+getSubString()+"]"; + } + + public String getSubString() { + return "enabled "+enabled+", toggle[able "+toggleable+", state "+toggle+"], "+translate[0]+" / "+translate[1]+", box "+box; } // // Input // - public void setPressed(boolean b) { + public void setPressed(final boolean b) { this.down = b; - if(isToggleable() && b) { + if( isToggleable() && b ) { toggle = !toggle; } + markStateDirty(); } public boolean isPressed() { return this.down; } + public void setToggleable(final boolean toggleable) { + this.toggleable = toggleable; + } + public boolean isToggleable() { return toggleable; } - public void setToggleable(boolean toggleable) { - this.toggleable = toggleable; + public void setToggleState(final boolean v) { + toggle = v; + markStateDirty(); } + public boolean getToggleState() { return toggle; } - public final void addMouseListener(MouseListener l) { + public final void addMouseListener(final MouseListener l) { if(l == null) { return; } @@ -373,9 +403,16 @@ public abstract class UIShape { // set as attachment e.setAttachment(new EventDetails(this, rbox, relPos)); + final short eventType = e.getEventType(); + if( MouseEvent.EVENT_MOUSE_PRESSED == eventType ) { + setPressed(true); + } else if ( MouseEvent.EVENT_MOUSE_RELEASED == eventType ) { + setPressed(false); + } + for(int i = 0; !e.isConsumed() && i < mouseListeners.size(); i++ ) { final MouseListener l = mouseListeners.get(i); - switch(e.getEventType()) { + switch( eventType ) { case MouseEvent.EVENT_MOUSE_CLICKED: l.mouseClicked(e); break; @@ -386,11 +423,9 @@ public abstract class UIShape { l.mouseExited(e); break; case MouseEvent.EVENT_MOUSE_PRESSED: - markDirty(); l.mousePressed(e); break; case MouseEvent.EVENT_MOUSE_RELEASED: - markDirty(); l.mouseReleased(e); break; case MouseEvent.EVENT_MOUSE_MOVED: diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/GLReadBuffer00Base.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/GLReadBuffer00Base.java index b96ef21a9..35b2242ae 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/GLReadBuffer00Base.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/GLReadBuffer00Base.java @@ -63,7 +63,7 @@ public abstract class GLReadBuffer00Base extends UITestCase { // FIXME: Graph TextRenderer does not AA well w/o MSAA and FBO super(Region.VBAA_RENDERING_BIT, new int[] { 4 }); this.setRendererCallbacks(RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable); - regionFPS = GLRegion.create(renderModes); + regionFPS = GLRegion.create(renderModes, null); staticRGBAColor[0] = 0.9f; staticRGBAColor[1] = 0.9f; diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java index 2abf083b1..bbf6d81ae 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java @@ -180,7 +180,7 @@ public class MovieCube implements GLEventListener { if( lowPerfDevice ) { regionFPS = null; } else { - regionFPS = GLRegion.create(renderModes); + regionFPS = GLRegion.create(renderModes, null); System.err.println("RegionFPS "+Region.getRenderModeString(renderModes)+", sampleCount "+textSampleCount[0]+", class "+regionFPS.getClass().getName()); } staticRGBAColor[0] = 0.1f; diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java index f76859a9e..96ed57a8f 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java @@ -149,7 +149,7 @@ public class MovieSimple implements GLEventListener { if( lowPerfDevice ) { regionFPS = null; } else { - regionFPS = GLRegion.create(renderModes); + regionFPS = GLRegion.create(renderModes, null); System.err.println("RegionFPS "+Region.getRenderModeString(renderModes)+", sampleCount "+textSampleCount[0]+", class "+regionFPS.getClass().getName()); } staticRGBAColor[0] = 0.9f; |