diff options
Diffstat (limited to 'src/jogl')
61 files changed, 2161 insertions, 1496 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java b/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java index 44744584d..d4977669e 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java +++ b/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java @@ -111,6 +111,9 @@ public class OutlineShape implements Comparable<OutlineShape> { } } + /** Initial {@link #getSharpness()} value, which can be modified via {@link #setSharpness(float)}. */ + public static final float DEFAULT_SHARPNESS = 0.5f; + public static final int DIRTY_BOUNDS = 1 << 0; /** * Modified shape, requires to update the vertices and triangles, here: vertices. @@ -131,6 +134,7 @@ public class OutlineShape implements Comparable<OutlineShape> { private final AABBox bbox; private final ArrayList<Triangle> triangles; private final ArrayList<Vertex> vertices; + private int addedVerticeCount; private VerticesState outlineState; @@ -153,12 +157,24 @@ public class OutlineShape implements Comparable<OutlineShape> { this.bbox = new AABBox(); this.triangles = new ArrayList<Triangle>(); this.vertices = new ArrayList<Vertex>(); + this.addedVerticeCount = 0; this.dirtyBits = 0; - this.sharpness = 0.5f; + this.sharpness = DEFAULT_SHARPNESS; + } + + /** + * Return the number of newly added vertices during {@link #getTriangles(VerticesState)} + * while transforming the outlines to {@link VerticesState#QUADRATIC_NURBS} and triangulation. + * @see #setIsQuadraticNurbs() + */ + public int getAddedVerticeCount() { + return addedVerticeCount; } + /** Sharpness value, defaults to {@link #DEFAULT_SHARPNESS}. */ public float getSharpness() { return sharpness; } + /** Sets sharpness, defaults to {@link #DEFAULT_SHARPNESS}. */ public void setSharpness(final float s) { if( this.sharpness != s ) { clearCache(); @@ -174,6 +190,7 @@ public class OutlineShape implements Comparable<OutlineShape> { bbox.reset(); vertices.clear(); triangles.clear(); + addedVerticeCount = 0; dirtyBits = 0; } @@ -418,21 +435,12 @@ public class OutlineShape implements Comparable<OutlineShape> { } /** - * Ensure the outlines represent - * the specified destinationType. - * and removes all overlaps in boundary triangles - * @param destinationType the target outline's vertices state. Currently only - * {@link OutlineShape.VerticesState#QUADRATIC_NURBS} are supported. + * Claim this outline's vertices are all {@link OutlineShape.VerticesState#QUADRATIC_NURBS}, + * hence no cubic transformations will be performed. */ - protected final void transformOutlines(VerticesState destinationType) { - if(outlineState != destinationType){ - if(destinationType == VerticesState.QUADRATIC_NURBS){ - transformOutlines2Quadratic(); - checkOverlaps(); - } else { - throw new IllegalStateException("destinationType "+destinationType.name()+" not supported (currently "+outlineState.name()+")"); - } - } + public final void setIsQuadraticNurbs() { + outlineState = VerticesState.QUADRATIC_NURBS; + // checkPossibleOverlaps = false; } private void subdivideTriangle(final Outline outline, Vertex a, Vertex b, Vertex c, int index){ @@ -446,6 +454,8 @@ public class OutlineShape implements Comparable<OutlineShape> { outline.addVertex(index, vertexFactory.create(tmpV1, 0, 3, false)); outline.addVertex(index+2, vertexFactory.create(tmpV3, 0, 3, false)); + + addedVerticeCount += 2; } /** @@ -470,21 +480,24 @@ public class OutlineShape implements Comparable<OutlineShape> { if ( !currentVertex.isOnCurve()) { final Vertex nextV = outline.getVertex((i+1)%vertexCount); final Vertex prevV = outline.getVertex((i+vertexCount-1)%vertexCount); - Vertex overlap =null; - - //check for overlap even if already set for subdivision - //ensuring both trianglur overlaps get divided - //for pref. only check in first pass - //second pass to clear the overlaps arrray(reduces precision errors) - if(firstpass) { - overlap = checkTriOverlaps(prevV, currentVertex, nextV); + final Vertex overlap; + + // check for overlap even if already set for subdivision + // ensuring both triangular overlaps get divided + // for pref. only check in first pass + // second pass to clear the overlaps array(reduces precision errors) + if( firstpass ) { + overlap = checkTriOverlaps0(prevV, currentVertex, nextV); + } else { + overlap = null; } - if(overlaps.contains(currentVertex) || overlap != null) { + if( overlaps.contains(currentVertex) || overlap != null ) { overlaps.remove(currentVertex); subdivideTriangle(outline, prevV, currentVertex, nextV, i); i+=3; vertexCount+=2; + addedVerticeCount+=2; if(overlap != null && !overlap.isOnCurve()) { if(!overlaps.contains(overlap)) { @@ -496,11 +509,11 @@ public class OutlineShape implements Comparable<OutlineShape> { } } firstpass = false; - }while(!overlaps.isEmpty()); + } while( !overlaps.isEmpty() ); } - private Vertex checkTriOverlaps(Vertex a, Vertex b, Vertex c) { - int count = getOutlineNumber(); + private Vertex checkTriOverlaps0(final Vertex a, final Vertex b, final Vertex c) { + final int count = getOutlineNumber(); for (int cc = 0; cc < count; cc++) { final Outline outline = getOutline(cc); int vertexCount = outline.getVertexCount(); @@ -524,45 +537,81 @@ public class OutlineShape implements Comparable<OutlineShape> { } if(VectorUtil.testTri2SegIntersection(a, b, c, prevV, current) || VectorUtil.testTri2SegIntersection(a, b, c, current, nextV) || - VectorUtil.testTri2SegIntersection(a, b, c, prevV, nextV)) { + VectorUtil.testTri2SegIntersection(a, b, c, prevV, nextV) ) { return current; } } } return null; } + @SuppressWarnings("unused") + private Vertex checkTriOverlaps1(final Vertex a, final Vertex b, final Vertex c) { + final int count = getOutlineNumber(); + for (int cc = 0; cc < count; cc++) { + final Outline outline = getOutline(cc); + int vertexCount = outline.getVertexCount(); + for(int i=0; i < vertexCount; i++) { + final Vertex current = outline.getVertex(i); + if(current.isOnCurve() || current == a || current == b || current == c) { + continue; + } + final Vertex nextV = outline.getVertex((i+1)%vertexCount); + final Vertex prevV = outline.getVertex((i+vertexCount-1)%vertexCount); - private void transformOutlines2Quadratic() { + //skip neighboring triangles + if(prevV == c || nextV == a) { + continue; + } + + if( VectorUtil.isVec3InTriangle3(a.getCoord(), b.getCoord(), c.getCoord(), + current.getCoord(), nextV.getCoord(), prevV.getCoord(), + tmpV1, tmpV2, tmpV3, FloatUtil.EPSILON) ) { + return current; + } + if(VectorUtil.testTri2SegIntersection(a, b, c, prevV, current, FloatUtil.EPSILON) || + VectorUtil.testTri2SegIntersection(a, b, c, current, nextV, FloatUtil.EPSILON) || + VectorUtil.testTri2SegIntersection(a, b, c, prevV, nextV, FloatUtil.EPSILON) ) { + return current; + } + } + } + return null; + } + + private void cleanupOutlines() { + final boolean transformOutlines2Quadratic = VerticesState.QUADRATIC_NURBS != outlineState; int count = getOutlineNumber(); for (int cc = 0; cc < count; cc++) { final Outline outline = getOutline(cc); int vertexCount = outline.getVertexCount(); - for(int i=0; i < vertexCount; i++) { - final Vertex currentVertex = outline.getVertex(i); - final Vertex nextVertex = outline.getVertex((i+1)%vertexCount); - if ( !currentVertex.isOnCurve() && !nextVertex.isOnCurve() ) { - VectorUtil.midVec3(tmpV1, currentVertex.getCoord(), nextVertex.getCoord()); - final Vertex v = vertexFactory.create(tmpV1, 0, 3, true); - i++; - vertexCount++; - outline.addVertex(i, v); + if( transformOutlines2Quadratic ) { + for(int i=0; i < vertexCount; i++) { + final Vertex currentVertex = outline.getVertex(i); + final int j = (i+1)%vertexCount; + final Vertex nextVertex = outline.getVertex(j); + if ( !currentVertex.isOnCurve() && !nextVertex.isOnCurve() ) { + VectorUtil.midVec3(tmpV1, currentVertex.getCoord(), nextVertex.getCoord()); + System.err.println("XXX: Cubic: "+i+": "+currentVertex+", "+j+": "+nextVertex); + final Vertex v = vertexFactory.create(tmpV1, 0, 3, true); + i++; + vertexCount++; + addedVerticeCount++; + outline.addVertex(i, v); + } } } - if(vertexCount <= 0) { + if( 0 >= vertexCount ) { outlines.remove(outline); cc--; count--; - continue; - } - - if( vertexCount > 0 ) { - if(VectorUtil.isVec3Equal( outline.getVertex(0).getCoord(), 0, outline.getLastVertex().getCoord(), 0, FloatUtil.EPSILON )) { - outline.removeVertex(vertexCount-1); - } + } else if( 0 < vertexCount && + VectorUtil.isVec3Equal( outline.getVertex(0).getCoord(), 0, outline.getLastVertex().getCoord(), 0, FloatUtil.EPSILON )) { + outline.removeVertex(vertexCount-1); } } outlineState = VerticesState.QUADRATIC_NURBS; + checkOverlaps(); } private int generateVertexIds() { @@ -616,6 +665,7 @@ public class OutlineShape implements Comparable<OutlineShape> { triangulator2d.addCurve(triangles, outlines.get(index), sharpness); } triangulator2d.generate(triangles); + addedVerticeCount += triangulator2d.getAddedVerticeCount(); triangulator2d.reset(); } } @@ -631,8 +681,11 @@ public class OutlineShape implements Comparable<OutlineShape> { */ public ArrayList<Triangle> getTriangles(VerticesState destinationType) { final boolean updated; + if(destinationType != VerticesState.QUADRATIC_NURBS) { + throw new IllegalStateException("destinationType "+destinationType.name()+" not supported (currently "+outlineState.name()+")"); + } if( 0 != ( DIRTY_TRIANGLES & dirtyBits ) ) { - transformOutlines(destinationType); + cleanupOutlines(); triangulateImpl(); updated = true; dirtyBits |= DIRTY_VERTICES; diff --git a/src/jogl/classes/com/jogamp/graph/curve/OutlineShapeXForm.java b/src/jogl/classes/com/jogamp/graph/curve/OutlineShapeXForm.java index b1c99f5ed..cf4d38450 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/OutlineShapeXForm.java +++ b/src/jogl/classes/com/jogamp/graph/curve/OutlineShapeXForm.java @@ -4,10 +4,13 @@ import jogamp.graph.geom.plane.AffineTransform; public class OutlineShapeXForm { public final OutlineShape shape; - public final AffineTransform t; + private AffineTransform t; public OutlineShapeXForm(final OutlineShape shape, final AffineTransform t) { this.shape = shape; this.t = t; } + + public final AffineTransform getTransform() { return t; } + public final void setTransform(final AffineTransform t) { this.t = t; } }
\ No newline at end of file diff --git a/src/jogl/classes/com/jogamp/graph/curve/Region.java b/src/jogl/classes/com/jogamp/graph/curve/Region.java index 15a0d6bff..2cd68a806 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/Region.java +++ b/src/jogl/classes/com/jogamp/graph/curve/Region.java @@ -78,11 +78,31 @@ public abstract class Region { * being applied. * </p> */ - public static final int VARIABLE_CURVE_WEIGHT_BIT = 1 << 8; + public static final int VARWEIGHT_RENDERING_BIT = 1 << 8; + + /** + * Rendering-Mode bit for {@link Region#getRenderModes() Region} and {@link com.jogamp.graph.curve.opengl.RegionRenderer#getRenderModes() RegionRenderer}. + * <p> + * If set, a color channel attribute per vertex is added to the stream, + * otherwise only the + * {@link com.jogamp.graph.curve.opengl.RegionRenderer#setColorStatic(javax.media.opengl.GL2ES2, float, float, float, float) static color} + * is being used. + * </p> + */ + public static final int COLORCHANNEL_RENDERING_BIT = 1 << 9; + + /** + * Rendering-Mode bit for {@link Region#getRenderModes() Region} and {@link com.jogamp.graph.curve.opengl.RegionRenderer#getRenderModes() RegionRenderer}. + * <p> + * If set, a color texture is used to determine the color. + * </p> + */ + public static final int COLORTEXTURE_RENDERING_BIT = 1 << 10; public static final int TWO_PASS_DEFAULT_TEXTURE_UNIT = 0; private final int renderModes; + private int quality; private boolean dirty = true; private int numVertices = 0; protected final AABBox box = new AABBox(); @@ -91,48 +111,73 @@ public abstract class Region { public static boolean isVBAA(int renderModes) { return 0 != (renderModes & Region.VBAA_RENDERING_BIT); } + public static boolean isMSAA(int renderModes) { return 0 != (renderModes & Region.MSAA_RENDERING_BIT); } + public static boolean isTwoPass(int renderModes) { + return 0 != ( renderModes & ( Region.VBAA_RENDERING_BIT | Region.MSAA_RENDERING_BIT) ); + } + /** - * Check if render mode capable of non uniform weights - * - * @param renderModes - * bit-field of modes, e.g. - * {@link Region#VARIABLE_CURVE_WEIGHT_BIT}, - * {@link Region#VBAA_RENDERING_BIT} - * @return true of capable of non uniform weights */ - public static boolean isNonUniformWeight(int renderModes) { - return 0 != (renderModes & Region.VARIABLE_CURVE_WEIGHT_BIT); + * Returns true if render mode capable of variable weights, + * i.e. the bit {@link #VARWEIGHT_RENDERING_BIT} is set, + * otherwise false. + */ + public static boolean hasVariableWeight(int renderModes) { + return 0 != (renderModes & Region.VARWEIGHT_RENDERING_BIT); + } + + /** + * Returns true if render mode has a color channel, + * i.e. the bit {@link #COLORCHANNEL_RENDERING_BIT} is set, + * otherwise false. + */ + public static boolean hasColorChannel(int renderModes) { + return 0 != (renderModes & Region.COLORCHANNEL_RENDERING_BIT); + } + + /** + * Returns true if render mode has a color texture, + * i.e. the bit {@link #COLORTEXTURE_RENDERING_BIT} is set, + * otherwise false. + */ + public static boolean hasColorTexture(int renderModes) { + return 0 != (renderModes & Region.COLORTEXTURE_RENDERING_BIT); } public static String getRenderModeString(int renderModes) { - final String curveS = isNonUniformWeight(renderModes) ? "-curve" : ""; + final String curveS = hasVariableWeight(renderModes) ? "-curve" : ""; + final String cChanS = hasColorChannel(renderModes) ? "-cols" : ""; + final String cTexS = hasColorTexture(renderModes) ? "-ctex" : ""; if( Region.isVBAA(renderModes) ) { - return "vbaa"+curveS; + return "vbaa"+curveS+cChanS+cTexS; } else if( Region.isMSAA(renderModes) ) { - return "msaa"+curveS; + return "msaa"+curveS+cChanS+cTexS; } else { - return "norm"+curveS; + return "norm"+curveS+cChanS+cTexS; } } protected Region(int regionRenderModes) { this.renderModes = regionRenderModes; + this.quality = 99; } // FIXME: Better handling of impl. buffer growth .. ! + // protected abstract void setupInitialComponentCount(int attributeCount, int indexCount); - protected abstract void pushVertex(float[] coords, float[] texParams); + protected abstract void pushVertex(final float[] coords, final float[] texParams, float[] rgba); protected abstract void pushIndex(int idx); /** * Return bit-field of render modes, see {@link #create(int)}. */ - public final int getRenderModes() { - return renderModes; - } + public final int getRenderModes() { return renderModes; } + + public final int getQuality() { return quality; } + public final void setQuality(int q) { quality=q; } protected void clearImpl() { dirty = true; @@ -141,31 +186,50 @@ public abstract class Region { } /** - * Return true if capable of two pass rendering - VBAA, otherwise false. + * Returns true if capable of two pass rendering - VBAA, otherwise false. */ public final boolean isVBAA() { - return isVBAA(renderModes); + return Region.isVBAA(renderModes); } /** - * Return true if capable of two pass rendering - MSAA, otherwise false. + * Returns true if capable of two pass rendering - MSAA, otherwise false. */ public final boolean isMSAA() { - return isMSAA(renderModes); + return Region.isMSAA(renderModes); + } + + /** + * Returns true if capable of variable weights, otherwise false. + */ + public final boolean hasVariableWeight() { + return Region.hasVariableWeight(renderModes); } /** - * Return true if capable of nonuniform weights, otherwise false. + * Returns true if render mode has a color channel, + * i.e. the bit {@link #COLORCHANNEL_RENDERING_BIT} is set, + * otherwise false. */ - public final boolean isNonUniformWeight() { - return Region.isNonUniformWeight(renderModes); + public boolean hasColorChannel() { + return Region.hasColorChannel(renderModes); } + /** + * Returns true if render mode has a color texture, + * i.e. the bit {@link #COLORTEXTURE_RENDERING_BIT} is set, + * otherwise false. + */ + public boolean hasColorTexture() { + return Region.hasColorTexture(renderModes); + } + + /** See {@link #setFrustum(Frustum)} */ public final Frustum getFrustum() { return frustum; } /** - * Set {@link Frustum} culling for {@link #addOutlineShape(OutlineShape, AffineTransform)}. + * Set {@link Frustum} culling for {@link #addOutlineShape(OutlineShape, AffineTransform, float[])}. */ public final void setFrustum(Frustum frustum) { this.frustum = frustum; @@ -173,23 +237,23 @@ public abstract class Region { final float[] coordsEx = new float[3]; - private void pushNewVertexImpl(final Vertex vertIn, final AffineTransform transform) { + private void pushNewVertexImpl(final Vertex vertIn, final AffineTransform transform, float[] rgba) { if( null != transform ) { final float[] coordsIn = vertIn.getCoord(); transform.transform(coordsIn, coordsEx); coordsEx[2] = coordsIn[2]; box.resize(coordsEx[0], coordsEx[1], coordsEx[2]); - pushVertex(coordsEx, vertIn.getTexCoord()); + pushVertex(coordsEx, vertIn.getTexCoord(), rgba); } else { box.resize(vertIn.getX(), vertIn.getY(), vertIn.getZ()); - pushVertex(vertIn.getCoord(), vertIn.getTexCoord()); + pushVertex(vertIn.getCoord(), vertIn.getTexCoord(), rgba); } numVertices++; } - private void pushNewVertexIdxImpl(final Vertex vertIn, final AffineTransform transform) { + private void pushNewVertexIdxImpl(final Vertex vertIn, final AffineTransform transform, float[] rgba) { pushIndex(numVertices); - pushNewVertexImpl(vertIn, transform); + pushNewVertexImpl(vertIn, transform, rgba); } private final AABBox tmpBox = new AABBox(); @@ -201,8 +265,9 @@ public abstract class Region { * is dropped if it's {@link OutlineShape#getBounds() bounding-box} is fully outside of the frustum. * The optional {@link AffineTransform} is applied to the bounding-box beforehand. * </p> + * @param rgbaColor TODO */ - public final void addOutlineShape(final OutlineShape shape, final AffineTransform t) { + public final void addOutlineShape(final OutlineShape shape, final AffineTransform t, final float[] rgbaColor) { if( null != frustum ) { final AABBox shapeBox = shape.getBounds(); final AABBox shapeBoxT; @@ -222,8 +287,15 @@ public abstract class Region { final List<Triangle> trisIn = shape.getTriangles(OutlineShape.VerticesState.QUADRATIC_NURBS); final ArrayList<Vertex> vertsIn = shape.getVertices(); if(DEBUG_INSTANCE) { + final int addedVerticeCount = shape.getAddedVerticeCount(); + final int verticeCount = vertsIn.size() + addedVerticeCount; + final int indexCount = trisIn.size() * 3; System.err.println("Region.addOutlineShape().0: tris: "+trisIn.size()+", verts "+vertsIn.size()+", transform "+t); + System.err.println("Region.addOutlineShape().0: VerticeCount "+vertsIn.size()+" + "+addedVerticeCount+" = "+verticeCount); + System.err.println("Region.addOutlineShape().0: IndexCount "+indexCount); } + // setupInitialComponentCount(verticeCount, indexCount); // FIXME: Use it ? + final int idxOffset = numVertices; int vertsVNewIdxCount = 0, vertsTMovIdxCount = 0, vertsTNewIdxCount = 0, tris = 0; int vertsDupCountV = 0, vertsDupCountT = 0, vertsKnownMovedT = 0; @@ -232,7 +304,7 @@ public abstract class Region { System.err.println("Region.addOutlineShape(): Processing Vertices"); } for(int i=0; i<vertsIn.size(); i++) { - pushNewVertexImpl(vertsIn.get(i), t); + pushNewVertexImpl(vertsIn.get(i), t, rgbaColor); vertsVNewIdxCount++; } if(DEBUG_INSTANCE) { @@ -261,9 +333,9 @@ public abstract class Region { if(Region.DEBUG_INSTANCE) { System.err.println("T["+i+"]: New Idx "+numVertices); } - pushNewVertexIdxImpl(triInVertices[0], t); - pushNewVertexIdxImpl(triInVertices[1], t); - pushNewVertexIdxImpl(triInVertices[2], t); + pushNewVertexIdxImpl(triInVertices[0], t, rgbaColor); + pushNewVertexIdxImpl(triInVertices[1], t, rgbaColor); + pushNewVertexIdxImpl(triInVertices[2], t, rgbaColor); vertsTNewIdxCount+=3; } tris++; @@ -280,9 +352,9 @@ public abstract class Region { setDirty(true); } - public final void addOutlineShapes(final List<OutlineShape> shapes, final AffineTransform transform) { + public final void addOutlineShapes(final List<OutlineShape> shapes, final AffineTransform transform, final float[] rgbaColor) { for (int i = 0; i < shapes.size(); i++) { - addOutlineShape(shapes.get(i), transform); + addOutlineShape(shapes.get(i), transform, rgbaColor); } } @@ -306,6 +378,6 @@ public abstract class Region { } public String toString() { - return "Region["+getRenderModeString(this.renderModes)+", dirty "+dirty+", vertices "+numVertices+", box "+box+"]"; + return "Region["+getRenderModeString(this.renderModes)+", q "+quality+", dirty "+dirty+", vertices "+numVertices+", box "+box+"]"; } }
\ No newline at end of file diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java index 96d285898..e305cc336 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java @@ -56,7 +56,7 @@ public abstract class GLRegion extends Region { * {@link Region#TWO_PASS_DEFAULT_TEXTURE_UNIT} is being used.</p>
*
* @param rs the RenderState to be used
- * @param renderModes bit-field of modes, e.g. {@link Region#VARIABLE_CURVE_WEIGHT_BIT}, {@link Region#VBAA_RENDERING_BIT}
+ * @param renderModes bit-field of modes, e.g. {@link Region#VARWEIGHT_RENDERING_BIT}, {@link Region#VBAA_RENDERING_BIT}
*/
public static GLRegion create(int renderModes) {
if( isVBAA(renderModes) ) {
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 8233d4262..8df34ead5 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java @@ -27,16 +27,21 @@ */ package com.jogamp.graph.curve.opengl; -import java.nio.FloatBuffer; +import java.io.IOException; +import java.util.Iterator; import javax.media.opengl.GL; import javax.media.opengl.GL2ES2; import javax.media.opengl.GLException; import javax.media.opengl.fixedfunc.GLMatrixFunc; +import jogamp.graph.curve.opengl.shader.AttributeNames; + +import com.jogamp.opengl.GLExtensions; import com.jogamp.opengl.util.glsl.ShaderCode; -import com.jogamp.opengl.util.glsl.ShaderState; +import com.jogamp.opengl.util.glsl.ShaderProgram; import com.jogamp.opengl.util.PMVMatrix; +import com.jogamp.common.util.IntObjectHashMap; import com.jogamp.graph.curve.Region; /** @@ -46,7 +51,7 @@ import com.jogamp.graph.curve.Region; * are passed through an instance of this class. * </p> */ -public abstract class RegionRenderer { +public class RegionRenderer { protected static final boolean DEBUG = Region.DEBUG; protected static final boolean DEBUG_INSTANCE = Region.DEBUG_INSTANCE; @@ -95,10 +100,6 @@ public abstract class RegionRenderer { } }; - public static boolean isWeightValid(float v) { - return 0.0f <= v && v <= 1.9f ; - } - /** * Create a Hardware accelerated Region Renderer. * <p> @@ -108,7 +109,7 @@ public abstract class RegionRenderer { * can be utilized to enable and disable {@link GL#GL_BLEND}. * </p> * @param rs the used {@link RenderState} - * @param renderModes bit-field of modes, e.g. {@link Region#VARIABLE_CURVE_WEIGHT_BIT}, {@link Region#VBAA_RENDERING_BIT} + * @param renderModes bit-field of modes, e.g. {@link Region#VARWEIGHT_RENDERING_BIT}, {@link Region#VBAA_RENDERING_BIT} * @param enableCallback optional {@link GLCallback}, if not <code>null</code> will be issued at * {@link #init(GL2ES2) init(gl)} and {@link #enable(GL2ES2, boolean) enable(gl, true)}. * @param disableCallback optional {@link GLCallback}, if not <code>null</code> will be issued at @@ -118,7 +119,7 @@ public abstract class RegionRenderer { */ public static RegionRenderer create(final RenderState rs, final int renderModes, final GLCallback enableCallback, final GLCallback disableCallback) { - return new jogamp.graph.curve.opengl.RegionRendererImpl01(rs, renderModes, enableCallback, disableCallback); + return new RegionRenderer(rs, renderModes, enableCallback, disableCallback); } private final int renderModes; @@ -139,19 +140,10 @@ public abstract class RegionRenderer { /** Return height of current viewport */ public final int getHeight() { return vp_height; } - public final float getWeight() { return rs.getWeight().floatValue(); } - public final float getAlpha() { return rs.getAlpha().floatValue(); } - public final PMVMatrix getMatrix() { return rs.pmvMatrix(); } - - /** - * Implementation shall load, compile and link the shader program and leave it active. - * @param gl referencing the current GLContext to which the ShaderState is bound to - * @return - */ - protected abstract boolean initImpl(GL2ES2 gl); - - /** Delete and clean the associated OGL objects */ - protected abstract void destroyImpl(GL2ES2 gl); + 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(); } ////////////////////////////////////// @@ -170,14 +162,14 @@ public abstract class RegionRenderer { return renderModes; } - public final boolean usesVariableCurveWeight() { return Region.isNonUniformWeight(renderModes); } + public final boolean usesVariableCurveWeight() { return Region.hasVariableWeight(renderModes); } /** * @return true if Region's renderModes contains all bits as this Renderer's renderModes - * except {@link Region#VARIABLE_CURVE_WEIGHT_BIT}, otherwise false. + * except {@link Region#VARWEIGHT_RENDERING_BIT}, otherwise false. */ public final boolean areRenderModesCompatible(final Region region) { - final int cleanRenderModes = getRenderModes() & ( Region.VARIABLE_CURVE_WEIGHT_BIT ); + final int cleanRenderModes = getRenderModes() & ( Region.VARWEIGHT_RENDERING_BIT ); return cleanRenderModes == ( region.getRenderModes() & cleanRenderModes ); } @@ -217,28 +209,11 @@ public abstract class RegionRenderer { enableCallback.run(gl, this); } - initialized = initImpl(gl); + useShaderProgram(gl, renderModes, true, 0, 0); + initialized = rs.update(gl, true, renderModes, true); if(!initialized) { throw new GLException("Shader initialization failed"); } - - if(!rs.getShaderState().uniform(gl, rs.getPMVMatrix())) { - throw new GLException("Error setting PMVMatrix in shader: "+rs.getShaderState()); - } - - if( Region.isNonUniformWeight( getRenderModes() ) ) { - if(!rs.getShaderState().uniform(gl, rs.getWeight())) { - throw new GLException("Error setting weight in shader: "+rs.getShaderState()); - } - } - - if(!rs.getShaderState().uniform(gl, rs.getAlpha())) { - throw new GLException("Error setting global alpha in shader: "+rs.getShaderState()); - } - - if(!rs.getShaderState().uniform(gl, rs.getColorStatic())) { - throw new GLException("Error setting global color in shader: "+rs.getShaderState()); - } } public final void destroy(GL2ES2 gl) { @@ -248,18 +223,19 @@ public abstract class RegionRenderer { } return; } - rs.getShaderState().useProgram(gl, false); - destroyImpl(gl); + for(final Iterator<IntObjectHashMap.Entry> i = shaderPrograms.iterator(); i.hasNext(); ) { + final ShaderProgram sp = (ShaderProgram) i.next().getValue(); + sp.destroy(gl); + } rs.destroy(gl); initialized = false; } public final RenderState getRenderState() { return rs; } - public final ShaderState getShaderState() { return rs.getShaderState(); } /** - * Enabling or disabling the {@link RenderState#getShaderState() RenderState}'s - * {@link ShaderState#useProgram(GL2ES2, boolean) ShaderState program}. + * Enabling or disabling the {@link #getRenderState() RenderState}'s + * {@link RenderState#getShaderProgram() shader program}. * <p> * In case enable and disable {@link GLCallback}s are setup via {@link #create(RenderState, int, GLCallback, GLCallback)}, * they will be called before toggling the shader program. @@ -276,103 +252,59 @@ public abstract class RegionRenderer { disableCallback.run(gl, this); } } - rs.getShaderState().useProgram(gl, enable); - } - - public final void setWeight(GL2ES2 gl, float v) { - if( !isWeightValid(v) ) { - throw new IllegalArgumentException("Weight out of range"); - } - rs.getWeight().setData(v); - if(null != gl && rs.getShaderState().inUse() && Region.isNonUniformWeight( getRenderModes() ) ) { - rs.getShaderState().uniform(gl, rs.getWeight()); - } - } - - public final void setAlpha(GL2ES2 gl, float alpha_t) { - rs.getAlpha().setData(alpha_t); - if(null != gl && rs.getShaderState().inUse()) { - rs.getShaderState().uniform(gl, rs.getAlpha()); - } - - } - - public final void getColorStatic(float[] rgb) { - FloatBuffer fb = (FloatBuffer) rs.getColorStatic().getBuffer(); - rgb[0] = fb.get(0); - rgb[1] = fb.get(1); - rgb[2] = fb.get(2); - } - - public final void setColorStatic(GL2ES2 gl, float r, float g, float b){ - FloatBuffer fb = (FloatBuffer) rs.getColorStatic().getBuffer(); - fb.put(0, r); - fb.put(1, g); - fb.put(2, b); - if(null != gl && rs.getShaderState().inUse()) { - rs.getShaderState().uniform(gl, rs.getColorStatic()); - } - } - - public final void updateMatrix(GL2ES2 gl) { - if(initialized && null != gl && rs.getShaderState().inUse()) { - rs.getShaderState().uniform(gl, rs.getPMVMatrix()); + if( !enable ) { + final ShaderProgram sp = rs.getShaderProgram(); + if( null != sp ) { + sp.useProgram(gl, false); + } } } - /** No PMVMatrix operation is performed here. PMVMatrix will be updated if gl is not null. */ - public final boolean reshapeNotify(GL2ES2 gl, int width, int height) { + /** No PMVMatrix operation is performed here. PMVMatrix is marked dirty. */ + public final void reshapeNotify(int width, int height) { this.vp_width = width; this.vp_height = height; - updateMatrix(gl); - return true; + rs.setMatrixDirty(); } - public final boolean reshapePerspective(GL2ES2 gl, float angle, int width, int height, float near, float far) { + 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.pmvMatrix(); + final PMVMatrix p = rs.getMatrixMutable(); p.glMatrixMode(GLMatrixFunc.GL_PROJECTION); p.glLoadIdentity(); p.gluPerspective(angle, ratio, near, far); - updateMatrix(gl); - return true; } - public final boolean reshapeOrtho(GL2ES2 gl, int width, int height, float near, float far) { + public final void reshapeOrtho(int width, int height, float near, float far) { this.vp_width = width; this.vp_height = height; - final PMVMatrix p = rs.pmvMatrix(); + final PMVMatrix p = rs.getMatrixMutable(); p.glMatrixMode(GLMatrixFunc.GL_PROJECTION); p.glLoadIdentity(); p.glOrthof(0, width, 0, height, near, far); - updateMatrix(gl); - return true; } - protected String getVertexShaderName() { - return "curverenderer" + getImplVersion(); - } + // + // Shader Management + // - protected String getFragmentShaderName() { - final String version = getImplVersion(); - final String pass; - if( Region.isVBAA(renderModes) ) { - pass = "-2pass_vbaa"; - } else if( Region.isMSAA(renderModes) ) { - pass = "-2pass_msaa"; - } else { - pass = "-1pass_norm" ; - } - final String weight = Region.isNonUniformWeight(renderModes) ? "-weight" : "" ; - return "curverenderer" + version + pass + weight; + private static final String SHADER_SRC_SUB = ""; + private static final String SHADER_BIN_SUB = "bin"; + + private static String USE_COLOR_CHANNEL = "#define USE_COLOR_CHANNEL 1\n"; + private static String USE_COLOR_TEXTURE = "#define USE_COLOR_TEXTURE 1\n"; + private static String DEF_SAMPLE_COUNT = "#define SAMPLE_COUNT "; + + private String getVersionedShaderName() { + return "curverenderer01"; } // FIXME: Really required to have sampler2D def. precision ? If not, we can drop getFragmentShaderPrecision(..) and use default ShaderCode .. - public static final String es2_precision_fp = "\nprecision mediump float;\nprecision mediump int;\nprecision mediump sampler2D;\n"; + private static final String es2_precision_fp = "\nprecision mediump float;\nprecision mediump int;\nprecision mediump sampler2D;\n"; - protected String getFragmentShaderPrecision(GL2ES2 gl) { + private final String getFragmentShaderPrecision(GL2ES2 gl) { if( gl.isGLES() ) { return es2_precision_fp; } @@ -382,7 +314,173 @@ public abstract class RegionRenderer { return null; } - protected String getImplVersion() { - return "01"; + private static enum ShaderModeSelector1 { + /** Pass-1: Curve Simple */ + PASS1_SIMPLE("curve", "_simple", 0), + /** Pass-1: Curve Varying Weight */ + PASS1_WEIGHT("curve", "_weight", 0), + /** Pass-2: MSAA */ + PASS2_MSAA("msaa", "", 0), + /** Pass-2: VBAA Flipquad3, 1 sample */ + PASS2_VBAA_QUAL0_SAMPLES1("vbaa", "_flipquad3", 1), + /** Pass-2: VBAA Flipquad3, 2 samples */ + PASS2_VBAA_QUAL0_SAMPLES2("vbaa", "_flipquad3", 2), + /** Pass-2: VBAA Flipquad3, 4 samples */ + PASS2_VBAA_QUAL0_SAMPLES4("vbaa", "_flipquad3", 4), + /** Pass-2: VBAA Flipquad3, 8 samples */ + PASS2_VBAA_QUAL0_SAMPLES8("vbaa", "_flipquad3", 8), + /** Pass-2: VBAA All-Equal, 2 samples */ + PASS2_VBAA_QUAL1_SAMPLES2("vbaa", "_allequal", 2), + /** Pass-2: VBAA All-Equal, 4 samples */ + PASS2_VBAA_QUAL1_SAMPLES4("vbaa", "_allequal", 4), + /** Pass-2: VBAA All-Equal, 6 samples */ + PASS2_VBAA_QUAL1_SAMPLES6("vbaa", "_allequal", 6), + /** Pass-2: VBAA All-Equal, 8 samples */ + PASS2_VBAA_QUAL1_SAMPLES8("vbaa", "_allequal", 8); + + public final String tech; + public final String sub; + public final int sampleCount; + + ShaderModeSelector1(final String tech, final String sub, final int sampleCount) { + this.tech = tech; + this.sub= sub; + this.sampleCount = sampleCount; + } + + public static ShaderModeSelector1 selectPass1(final int renderModes) { + return Region.hasVariableWeight(renderModes) ? PASS1_WEIGHT : PASS1_SIMPLE; + } + + public static ShaderModeSelector1 selectPass2(final int renderModes, final int quality, final int sampleCount) { + if( Region.isMSAA(renderModes) ) { + return PASS2_MSAA; + } else if( Region.isVBAA(renderModes) ) { + if( 0 == quality ) { + if( sampleCount < 2 ) { + return PASS2_VBAA_QUAL0_SAMPLES1; + } else if( sampleCount < 4 ) { + return PASS2_VBAA_QUAL0_SAMPLES2; + } else if( sampleCount < 8 ) { + return PASS2_VBAA_QUAL0_SAMPLES4; + } else { + return PASS2_VBAA_QUAL0_SAMPLES8; + } + } else { + if( sampleCount < 4 ) { + return PASS2_VBAA_QUAL1_SAMPLES2; + } else if( sampleCount < 6 ) { + return PASS2_VBAA_QUAL1_SAMPLES4; + } else if( sampleCount < 8 ) { + return PASS2_VBAA_QUAL1_SAMPLES6; + } else { + return PASS2_VBAA_QUAL1_SAMPLES8; + } + } + } else { + return null; + } + } } + private final IntObjectHashMap shaderPrograms = new IntObjectHashMap(); + + private static final int HIGH_MASK = Region.COLORCHANNEL_RENDERING_BIT | Region.COLORTEXTURE_RENDERING_BIT; + + /** + * @param gl + * @param renderModes + * @param pass1 + * @param quality + * @param sampleCount + * @return true if a new shader program is being used and hence external uniform-data and -location, + * as well as the attribute-location must be updated, otherwise false. + */ + public final boolean useShaderProgram(final GL2ES2 gl, final int renderModes, + 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 ); + + /** + if(DEBUG) { + System.err.printf("RegionRendererImpl01.useShaderProgram.0: renderModes %s, sel1 %s, key 0x%X (pass1 %b, q %d, samples %d) - Thread %s%n", + Region.getRenderModeString(renderModes), sel1, shaderKey, pass1, quality, sampleCount, Thread.currentThread()); + } */ + + ShaderProgram sp = (ShaderProgram) shaderPrograms.get( shaderKey ); + if( null != sp ) { + 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); + } + } + return spChanged; + } + final String versionedBaseName = getVersionedShaderName(); + final String vertexShaderName; + if( Region.isTwoPass( renderModes ) ) { + vertexShaderName = versionedBaseName+"-pass"+(pass1?1:2); + } else { + vertexShaderName = versionedBaseName+"-single"; + } + final ShaderCode rsVp = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, AttributeNames.class, SHADER_SRC_SUB, SHADER_BIN_SUB, vertexShaderName, true); + final ShaderCode rsFp = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, AttributeNames.class, SHADER_SRC_SUB, SHADER_BIN_SUB, versionedBaseName+"-segment-head", true); + int posVp = rsVp.defaultShaderCustomization(gl, true, true); + // rsFp.defaultShaderCustomization(gl, true, true); + int posFp = rsFp.addGLSLVersion(gl); + if( gl.isGLES2() && ! gl.isGLES3() ) { + posFp = rsFp.insertShaderSource(0, posFp, ShaderCode.createExtensionDirective(GLExtensions.OES_standard_derivatives, ShaderCode.ENABLE)); + } + final String rsFpDefPrecision = getFragmentShaderPrecision(gl); + if( null != rsFpDefPrecision ) { + rsFp.insertShaderSource(0, posFp, rsFpDefPrecision); + } + if( Region.hasColorChannel( renderModes ) ) { + posVp = rsVp.insertShaderSource(0, posVp, USE_COLOR_CHANNEL); + posFp = rsFp.insertShaderSource(0, posFp, USE_COLOR_CHANNEL); + } + if( Region.hasColorTexture( renderModes ) ) { + posVp = rsVp.insertShaderSource(0, posVp, USE_COLOR_TEXTURE); + posFp = rsFp.insertShaderSource(0, posFp, USE_COLOR_TEXTURE); + } + if( !pass1 ) { + posFp = rsFp.insertShaderSource(0, posFp, DEF_SAMPLE_COUNT+sel1.sampleCount+"\n"); + } + + final String passS = pass1 ? "-pass1-" : "-pass2-"; + final String shaderSegment = versionedBaseName+passS+sel1.tech+sel1.sub+".glsl"; + if(DEBUG) { + System.err.printf("RegionRendererImpl01.useShaderProgram.1: segment %s%n", shaderSegment); + } + try { + posFp = rsFp.insertShaderSource(0, -1, AttributeNames.class, shaderSegment); + } catch (IOException ioe) { + throw new RuntimeException("Failed to read: "+shaderSegment, ioe); + } + if( 0 > posFp ) { + throw new RuntimeException("Failed to read: "+shaderSegment); + } + posFp = rsFp.insertShaderSource(0, -1, "}\n"); + + sp = new ShaderProgram(); + sp.add(rsVp); + sp.add(rsFp); + + 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); + } + getRenderState().setShaderProgram(gl, sp); + + 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); + } + return true; + } + }
\ No newline at end of file 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 490af140a..f915b7d49 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java @@ -27,20 +27,22 @@ */ package com.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.RenderStateImpl; import jogamp.graph.curve.opengl.shader.UniformNames; import com.jogamp.common.os.Platform; import com.jogamp.graph.curve.Region; import com.jogamp.graph.geom.Vertex; +import com.jogamp.opengl.util.GLArrayDataServer; import com.jogamp.opengl.util.PMVMatrix; -import com.jogamp.opengl.util.glsl.ShaderState; +import com.jogamp.opengl.util.glsl.ShaderProgram; -public abstract class RenderState { +public class RenderState { private static final String thisKey = "jogamp.graph.curve.RenderState" ; /** @@ -51,7 +53,7 @@ public abstract class RenderState { * </p> * <p> * Due to alpha blending and multipass rendering, e.g. {@link Region#VBAA_RENDERING_BIT}, - * the clear-color shall be set to the {@link #getColorStatic() foreground color} and <i>zero alpha</i>, + * the clear-color shall be set to the {@link #getColorStaticUniform() foreground color} and <i>zero alpha</i>, * otherwise blending will amplify the scene's clear-color. * </p> * <p> @@ -62,37 +64,192 @@ public abstract class RenderState { */ public static final int BITHINT_BLENDING_ENABLED = 1 << 0 ; - public static RenderState createRenderState(ShaderState st, Vertex.Factory<? extends Vertex> pointFactory) { - return new RenderStateImpl(st, pointFactory, null); + public static RenderState createRenderState(Vertex.Factory<? extends Vertex> pointFactory) { + return new RenderState(pointFactory, null); } - public static RenderState createRenderState(ShaderState st, Vertex.Factory<? extends Vertex> pointFactory, PMVMatrix pmvMatrix) { - return new RenderStateImpl(st, pointFactory, pmvMatrix); + public static RenderState createRenderState(Vertex.Factory<? extends Vertex> pointFactory, PMVMatrix pmvMatrix) { + return new RenderState(pointFactory, pmvMatrix); } public static final RenderState getRenderState(GL2ES2 gl) { return (RenderState) gl.getContext().getAttachedObject(thisKey); } - protected final ShaderState st; - protected final Vertex.Factory<? extends Vertex> vertexFactory; - protected final PMVMatrix pmvMatrix; - protected final GLUniformData gcu_PMVMatrix; - protected int hintBitfield; + 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 ShaderProgram sp; + private int hintBitfield; - protected RenderState(ShaderState st, Vertex.Factory<? extends Vertex> vertexFactory, PMVMatrix pmvMatrix) { - this.st = st; + protected RenderState(Vertex.Factory<? extends Vertex> vertexFactory, PMVMatrix pmvMatrix) { + this.sp = null; this.vertexFactory = vertexFactory; this.pmvMatrix = null != pmvMatrix ? pmvMatrix : new PMVMatrix(); - this.gcu_PMVMatrix = new GLUniformData(UniformNames.gcu_PMVMatrix, 4, 4, this.pmvMatrix.glGetPMvMatrixf()); - st.ownUniform(gcu_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.hintBitfield = 0; } - public final ShaderState getShaderState() { return st; } + public final ShaderProgram getShaderProgram() { return sp; } + public final boolean isShaderProgramInUse() { return null != sp ? sp.inUse() : false; } + + /** + * Set a {@link ShaderProgram} and enable it. If the given {@link ShaderProgram} is new, + * method returns true, otherwise false. + * @param gl + * @param sp + * @return true if a new shader program is being used and hence external uniform-data and -location, + * as well as the attribute-location must be updated, otherwise false. + */ + public final boolean setShaderProgram(final GL2ES2 gl, final ShaderProgram sp) { + if( sp.equals(this.sp) ) { + sp.useProgram(gl, true); + return false; + } + this.sp = sp; + sp.useProgram(gl, true); + return true; + } + public final Vertex.Factory<? extends Vertex> getVertexFactory() { return vertexFactory; } - public final PMVMatrix pmvMatrix() { return pmvMatrix; } - public final GLUniformData getPMVMatrix() { return gcu_PMVMatrix; } + + 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 final void updateMatrix(GL2ES2 gl) { + if( gcu_PMVMatrix01_dirty && sp.inUse() ) { + gl.glUniform( gcu_PMVMatrix01 ); + gcu_PMVMatrix01_dirty = false; + } + } + + public static boolean isWeightValid(float v) { + return 0.0f <= v && v <= 1.9f ; + } + public final float getWeight() { return gcu_Weight.floatValue(); } + public final void setWeight(float v) { + if( !isWeightValid(v) ) { + throw new IllegalArgumentException("Weight out of range"); + } + gcu_Weight_dirty = true; + gcu_Weight.setData(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); + 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; + } + + + /** + * + * @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); + System.err.println("XXX gcu_PMVMatrix01.update: "+r0); + 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); + System.err.println("XXX gcu_Weight.update: "+r0); + res = res && r0; + gcu_Weight_dirty = !r0; + } + if( gcu_ColorStatic_dirty || updateLocation ) { + final boolean r0 = updateUniformDataLoc(gl, updateLocation, gcu_ColorStatic_dirty, gcu_ColorStatic); + System.err.println("XXX gcu_ColorStatic.update: "+r0); + res = res && r0; + gcu_ColorStatic_dirty = false; + } + } + } + return res; + } + + /** + * + * @param gl + * @param updateLocation + * @param data + * @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) { + if( updateLocation || 0 > data.getLocation() ) { + return 0 <= data.setLocation(gl, sp.program()); + } else { + return true; + } + } + + /** + * + * @param gl + * @param updateLocation + * @param updateData TODO + * @param data + * @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) { + updateLocation = updateLocation || 0 > data.getLocation(); + if( updateLocation ) { + updateData = 0 <= data.setLocation(gl, sp.program()); + } + if( updateData ){ + gl.glUniform(data); + return true; + } else { + return !updateLocation; + } + } + + /** + * @param gl + * @param data + * @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) { + if( updateLocation || 0 > data.getLocation() ) { + return 0 <= data.setLocation(gl, sp.program()); + } else { + return true; + } + } + public final boolean isHintMaskSet(int mask) { return mask == ( hintBitfield & mask ); @@ -105,14 +262,12 @@ public abstract class RenderState { } public void destroy(GL2ES2 gl) { - st.destroy(gl); + if( null != sp ) { + sp.destroy(gl); + sp = null; + } } - public abstract GLUniformData getWeight(); - public abstract GLUniformData getAlpha(); - public abstract GLUniformData getColorStatic(); - // public abstract GLUniformData getStrength(); - public final RenderState attachTo(GL2ES2 gl) { return (RenderState) gl.getContext().attachObject(thisKey, this); } @@ -130,11 +285,12 @@ public abstract class RenderState { if(null==sb) { sb = new StringBuilder(); } - - sb.append("RenderState["); - st.toString(sb, alsoUnlocated).append(Platform.getNewline()); - sb.append("]"); - + 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; } 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 140e03cfb..6d9fdab0b 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java @@ -68,7 +68,7 @@ public class TextRegionUtil { * additionally passing the progressed {@link AffineTransform}. * The latter reflects the given font metric, pixelSize and hence character position. * @param visitor - * @param transform + * @param transform optional given transform * @param font the target {@link Font} * @param pixelSize Use {@link Font#getPixelSize(float, float)} for resolution correct pixel-size. * @param str string text @@ -82,7 +82,7 @@ public class TextRegionUtil { final float lineHeight = font.getLineHeight(pixelSize); final float scale = metrics.getScale(pixelSize); - final AffineTransform t = new AffineTransform(transform); + final AffineTransform t = null != transform ? new AffineTransform(transform) : new AffineTransform(); float y = 0; float advanceTotal = 0; @@ -98,7 +98,12 @@ public class TextRegionUtil { if(Region.DEBUG_INSTANCE) { System.err.println("XXXXXXXXXXXXXXx char: "+character+", scale: "+scale+"; translate: "+advanceTotal+", "+y); } - t.setTransform(transform); // reset transform + // reset transform + if( null != transform ) { + t.setTransform(transform); + } else { + t.setToIdentity(); + } t.translate(advanceTotal, y); t.scale(scale, scale); @@ -121,14 +126,15 @@ public class TextRegionUtil { * @param font the target {@link Font} * @param pixelSize Use {@link Font#getPixelSize(float, float)} for resolution correct pixel-size. * @param str string text + * @param rgbaColor if {@link Region#hasColorChannel()} RGBA color must be passed, otherwise value is ignored. */ public static void addStringToRegion(final GLRegion region, final Factory<? extends Vertex> vertexFactory, - final Font font, final float pixelSize, final CharSequence str) { + final Font font, final float pixelSize, final CharSequence str, final float[] rgbaColor) { final ShapeVisitor visitor = new ShapeVisitor() { public final void visit(final OutlineShape shape, final AffineTransform t) { - region.addOutlineShape(shape, t); + region.addOutlineShape(shape, t, region.hasColorChannel() ? rgbaColor : null); } }; - processString(visitor, new AffineTransform(), font, pixelSize, str); + processString(visitor, null, font, pixelSize, str); } /** @@ -141,13 +147,14 @@ public class TextRegionUtil { * @param font {@link Font} to be used * @param pixelSize Use {@link Font#getPixelSize(float, float)} for resolution correct pixel-size. * @param str text to be rendered + * @param rgbaColor if {@link Region#hasColorChannel()} RGBA color must be passed, otherwise value is ignored. * @param sampleCount desired multisampling sample count for msaa-rendering. * The actual used scample-count is written back when msaa-rendering is enabled, otherwise the store is untouched. * @throws Exception if TextRenderer not initialized */ public void drawString3D(final GL2ES2 gl, final Font font, final float pixelSize, final CharSequence str, - final int[/*1*/] sampleCount) { + final float[] rgbaColor, final int[/*1*/] sampleCount) { if( !renderer.isInitialized() ) { throw new GLException("TextRendererImpl01: not initialized!"); } @@ -155,7 +162,7 @@ public class TextRegionUtil { GLRegion region = getCachedRegion(font, str, pixelSize, special); if(null == region) { region = GLRegion.create(renderer.getRenderModes()); - addStringToRegion(region, renderer.getRenderState().getVertexFactory(), font, pixelSize, str); + addStringToRegion(region, renderer.getRenderState().getVertexFactory(), font, pixelSize, str, rgbaColor); addCachedRegion(gl, font, str, pixelSize, special, region); } region.draw(gl, renderer, sampleCount); @@ -167,25 +174,26 @@ public class TextRegionUtil { * <p> * In case of a multisampling region renderer, i.e. {@link Region#VBAA_RENDERING_BIT}, recreating the {@link GLRegion} * is a huge performance impact. - * In such case better use {@link #drawString3D(GLRegion, RegionRenderer, GL2ES2, Font, float, CharSequence, int[])} + * In such case better use {@link #drawString3D(GLRegion, RegionRenderer, GL2ES2, Font, float, CharSequence, float[], int[])} * instead. * </p> * @param gl the current GL state * @param font {@link Font} to be used * @param pixelSize Use {@link Font#getPixelSize(float, float)} for resolution correct pixel-size. * @param str text to be rendered + * @param rgbaColor if {@link Region#hasColorChannel()} RGBA color must be passed, otherwise value is ignored. * @param sampleCount desired multisampling sample count for msaa-rendering. * The actual used scample-count is written back when msaa-rendering is enabled, otherwise the store is untouched. * @throws Exception if TextRenderer not initialized */ public static void drawString3D(final RegionRenderer renderer, final GL2ES2 gl, final Font font, final float pixelSize, final CharSequence str, - final int[/*1*/] sampleCount) { + final float[] rgbaColor, final int[/*1*/] sampleCount) { if(!renderer.isInitialized()){ throw new GLException("TextRendererImpl01: not initialized!"); } final GLRegion region = GLRegion.create(renderer.getRenderModes()); - addStringToRegion(region, renderer.getRenderState().getVertexFactory(), font, pixelSize, str); + addStringToRegion(region, renderer.getRenderState().getVertexFactory(), font, pixelSize, str, rgbaColor); region.draw(gl, renderer, sampleCount); region.destroy(gl, renderer); } @@ -197,18 +205,19 @@ public class TextRegionUtil { * @param font {@link Font} to be used * @param pixelSize Use {@link Font#getPixelSize(float, float)} for resolution correct pixel-size. * @param str text to be rendered + * @param rgbaColor if {@link Region#hasColorChannel()} RGBA color must be passed, otherwise value is ignored. * @param sampleCount desired multisampling sample count for msaa-rendering. * The actual used scample-count is written back when msaa-rendering is enabled, otherwise the store is untouched. * @throws Exception if TextRenderer not initialized */ public static void drawString3D(final GLRegion region, final RegionRenderer renderer, final GL2ES2 gl, final Font font, final float pixelSize, final CharSequence str, - final int[/*1*/] sampleCount) { + final float[] rgbaColor, final int[/*1*/] sampleCount) { if(!renderer.isInitialized()){ throw new GLException("TextRendererImpl01: not initialized!"); } region.clear(gl, renderer); - addStringToRegion(region, renderer.getRenderState().getVertexFactory(), font, pixelSize, str); + addStringToRegion(region, renderer.getRenderState().getVertexFactory(), font, pixelSize, str, rgbaColor); region.draw(gl, renderer, sampleCount); } diff --git a/src/jogl/classes/com/jogamp/graph/curve/tess/Triangulator.java b/src/jogl/classes/com/jogamp/graph/curve/tess/Triangulator.java index 96ff4bbb8..20fe9bfd9 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/tess/Triangulator.java +++ b/src/jogl/classes/com/jogamp/graph/curve/tess/Triangulator.java @@ -64,8 +64,14 @@ public interface Triangulator { */ public void generate(List<Triangle> sink); - /** Reset the triangulation to initial state - * Clearing cached data + /** + * Reset the triangulation to initial state + * Clearing cached data */ public void reset(); + + /** + * Return the number of newly added vertices during {@link #addCurve(List, Outline, float)}. + */ + public int getAddedVerticeCount(); } diff --git a/src/jogl/classes/com/jogamp/graph/font/Font.java b/src/jogl/classes/com/jogamp/graph/font/Font.java index ac7a904e7..811ab9d94 100644 --- a/src/jogl/classes/com/jogamp/graph/font/Font.java +++ b/src/jogl/classes/com/jogamp/graph/font/Font.java @@ -27,7 +27,10 @@ */ package com.jogamp.graph.font; +import jogamp.graph.geom.plane.AffineTransform; + import com.jogamp.graph.curve.OutlineShape; +import com.jogamp.graph.curve.opengl.TextRegionUtil.ShapeVisitor; import com.jogamp.opengl.math.geom.AABBox; /** @@ -155,9 +158,26 @@ public interface Font { public int getNumGlyphs(); public float getLineHeight(float pixelSize); - public float getStringWidth(CharSequence string, float pixelSize); - public float getStringHeight(CharSequence string, float pixelSize); - public AABBox getStringBounds(CharSequence string, float pixelSize); + public float getMetricWidth(CharSequence string, float pixelSize); + public float getMetricHeight(CharSequence string, float pixelSize); + /** + * Return the <i>layout</i> bounding box as computed by each glyph's metrics. + * The result is not pixel correct, bit reflects layout specific metrics. + * <p> + * See {@link #getPointsBounds(AffineTransform, CharSequence, float)} for pixel correct results. + * </p> + * @param string string text + * @param pixelSize Use {@link Font#getPixelSize(float, float)} for resolution correct pixel-size. + */ + public AABBox getMetricBounds(CharSequence string, float pixelSize); + + /** + * Return the bounding box by taking each glyph's point-based bounding box into account. + * @param transform optional given transform + * @param string string text + * @param pixelSize Use {@link Font#getPixelSize(float, float)} for resolution correct pixel-size. + */ + public AABBox getPointsBounds(final AffineTransform transform, CharSequence string, float pixelSize); public boolean isPrintableChar( char c ); diff --git a/src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java b/src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java index 7fa6f2d60..557884c66 100644 --- a/src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java +++ b/src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java @@ -517,16 +517,16 @@ public class VectorUtil { subVec3(ap, p, a); //v2 // Compute dot products - final float dot00 = vec3Dot(ac, ac); - final float dot01 = vec3Dot(ac, ab); - final float dot02 = vec3Dot(ac, ap); - final float dot11 = vec3Dot(ab, ab); - final float dot12 = vec3Dot(ab, ap); + final float dotAC_AC = vec3Dot(ac, ac); + final float dotAC_AB = vec3Dot(ac, ab); + final float dotAB_AB = vec3Dot(ab, ab); + final float dotAC_AP = vec3Dot(ac, ap); + final float dotAB_AP = vec3Dot(ab, ap); // Compute barycentric coordinates - final float invDenom = 1 / (dot00 * dot11 - dot01 * dot01); - final float u = (dot11 * dot02 - dot01 * dot12) * invDenom; - final float v = (dot00 * dot12 - dot01 * dot02) * invDenom; + final float invDenom = 1 / (dotAC_AC * dotAB_AB - dotAC_AB * dotAC_AB); + final float u = (dotAB_AB * dotAC_AP - dotAC_AB * dotAB_AP) * invDenom; + final float v = (dotAC_AC * dotAB_AP - dotAC_AB * dotAC_AP) * invDenom; // Check if point is in triangle return (u >= 0) && (v >= 0) && (u + v < 1); @@ -564,11 +564,11 @@ public class VectorUtil { subVec3(tmpAP, p1, a); //v2 final float dotAC_AP1 = vec3Dot(tmpAC, tmpAP); final float dotAB_AP1 = vec3Dot(tmpAB, tmpAP); - final float u1 = (dotAB_AB * dotAC_AP1 - dotAC_AB * dotAB_AP1) * invDenom; - final float v1 = (dotAC_AC * dotAB_AP1 - dotAC_AB * dotAC_AP1) * invDenom; + final float u = (dotAB_AB * dotAC_AP1 - dotAC_AB * dotAB_AP1) * invDenom; + final float v = (dotAC_AC * dotAB_AP1 - dotAC_AB * dotAC_AP1) * invDenom; // Check if point is in triangle - if ( (u1 >= 0) && (v1 >= 0) && (u1 + v1 < 1) ) { + if ( (u >= 0) && (v >= 0) && (u + v < 1) ) { return true; } } @@ -598,6 +598,81 @@ public class VectorUtil { return true; } } + return false; + } + /** + * Check if one of three vertices are in triangle using + * barycentric coordinates computation, using given epsilon for comparison. + * @param a first triangle vertex + * @param b second triangle vertex + * @param c third triangle vertex + * @param p1 the vertex in question + * @param p2 the vertex in question + * @param p3 the vertex in question + * @param tmpAC + * @param tmpAB + * @param tmpAP + * @return true if p1 or p2 or p3 is in triangle (a, b, c), false otherwise. + */ + public static boolean isVec3InTriangle3(final float[] a, final float[] b, final float[] c, + final float[] p1, final float[] p2, final float[] p3, + final float[] tmpAC, final float[] tmpAB, final float[] tmpAP, + final float epsilon){ + // Compute vectors + subVec3(tmpAC, c, a); //v0 + subVec3(tmpAB, b, a); //v1 + + // Compute dot products + final float dotAC_AC = vec3Dot(tmpAC, tmpAC); + final float dotAC_AB = vec3Dot(tmpAC, tmpAB); + final float dotAB_AB = vec3Dot(tmpAB, tmpAB); + + // Compute barycentric coordinates + final float invDenom = 1 / (dotAC_AC * dotAB_AB - dotAC_AB * dotAC_AB); + { + subVec3(tmpAP, p1, a); //v2 + final float dotAC_AP1 = vec3Dot(tmpAC, tmpAP); + final float dotAB_AP1 = vec3Dot(tmpAB, tmpAP); + final float u = (dotAB_AB * dotAC_AP1 - dotAC_AB * dotAB_AP1) * invDenom; + final float v = (dotAC_AC * dotAB_AP1 - dotAC_AB * dotAC_AP1) * invDenom; + + // Check if point is in triangle + if( FloatUtil.compare(u, 0.0f, epsilon) >= 0 && + FloatUtil.compare(v, 0.0f, epsilon) >= 0 && + FloatUtil.compare(u+v, 1.0f, epsilon) < 0 ) { + return true; + } + } + + { + subVec3(tmpAP, p1, a); //v2 + final float dotAC_AP2 = vec3Dot(tmpAC, tmpAP); + final float dotAB_AP2 = vec3Dot(tmpAB, tmpAP); + final float u = (dotAB_AB * dotAC_AP2 - dotAC_AB * dotAB_AP2) * invDenom; + final float v = (dotAC_AC * dotAB_AP2 - dotAC_AB * dotAC_AP2) * invDenom; + + // Check if point is in triangle + if( FloatUtil.compare(u, 0.0f, epsilon) >= 0 && + FloatUtil.compare(v, 0.0f, epsilon) >= 0 && + FloatUtil.compare(u+v, 1.0f, epsilon) < 0 ) { + return true; + } + } + + { + subVec3(tmpAP, p2, a); //v2 + final float dotAC_AP3 = vec3Dot(tmpAC, tmpAP); + final float dotAB_AP3 = vec3Dot(tmpAB, tmpAP); + final float u = (dotAB_AB * dotAC_AP3 - dotAC_AB * dotAB_AP3) * invDenom; + final float v = (dotAC_AC * dotAB_AP3 - dotAC_AB * dotAC_AP3) * invDenom; + + // Check if point is in triangle + if( FloatUtil.compare(u, 0.0f, epsilon) >= 0 && + FloatUtil.compare(v, 0.0f, epsilon) >= 0 && + FloatUtil.compare(u+v, 1.0f, epsilon) < 0 ) { + return true; + } + } return false; } @@ -701,16 +776,58 @@ public class VectorUtil { final float beta = (C[0]*D[1]-C[1]*D[1]); final float xi = ((C[0]-D[0])*alpha-(A[0]-B[0])*beta)/determinant; - final float gamma = (xi - A[0])/(B[0] - A[0]); + final float gamma0 = (xi - A[0])/(B[0] - A[0]); final float gamma1 = (xi - C[0])/(D[0] - C[0]); - if(gamma <= 0 || gamma >= 1 || gamma1 <= 0 || gamma1 >= 1) { + if(gamma0 <= 0 || gamma0 >= 1 || gamma1 <= 0 || gamma1 >= 1) { return false; } return true; } + /** + * Compute intersection between two segments, using given epsilon for comparison. + * @param a vertex 1 of first segment + * @param b vertex 2 of first segment + * @param c vertex 1 of second segment + * @param d vertex 2 of second segment + * @return true if the segments intersect, otherwise returns false + */ + public static boolean testSeg2SegIntersection(final Vert2fImmutable a, final Vert2fImmutable b, + final Vert2fImmutable c, final Vert2fImmutable d, + final float epsilon) { + final float[] A = a.getCoord(); + final float[] B = b.getCoord(); + final float[] C = c.getCoord(); + final float[] D = d.getCoord(); + + final float determinant = (A[0]-B[0])*(C[1]-D[1]) - (A[1]-B[1])*(C[0]-D[0]); + + if ( FloatUtil.isZero(determinant, epsilon) ) { + return false; + } - /** Compute intersection between two lines + final float alpha = (A[0]*B[1]-A[1]*B[0]); + final float beta = (C[0]*D[1]-C[1]*D[1]); + final float xi = ((C[0]-D[0])*alpha-(A[0]-B[0])*beta)/determinant; + + final float gamma0 = (xi - A[0])/(B[0] - A[0]); + final float gamma1 = (xi - C[0])/(D[0] - C[0]); + if( FloatUtil.compare(gamma0, 0.0f, epsilon) <= 0 || + FloatUtil.compare(gamma0, 1.0f, epsilon) >= 0 || + FloatUtil.compare(gamma1, 0.0f, epsilon) <= 0 || + FloatUtil.compare(gamma1, 1.0f, epsilon) >= 0 ) { + return false; + } + + if(gamma0 <= 0 || gamma0 >= 1 || gamma1 <= 0 || gamma1 >= 1) { + return false; + } + + return true; + } + + /** + * Compute intersection between two lines * @param a vertex 1 of first line * @param b vertex 2 of first line * @param c vertex 1 of second line @@ -737,7 +854,8 @@ public class VectorUtil { return result; } - /** Check if a segment intersects with a triangle + /** + * Check if a segment intersects with a triangle * @param a vertex 1 of the triangle * @param b vertex 2 of the triangle * @param c vertex 3 of the triangle @@ -751,4 +869,20 @@ public class VectorUtil { testSeg2SegIntersection(b, c, d, e) || testSeg2SegIntersection(a, c, d, e) ; } + /** + * Check if a segment intersects with a triangle, using given epsilon for comparison. + * @param a vertex 1 of the triangle + * @param b vertex 2 of the triangle + * @param c vertex 3 of the triangle + * @param d vertex 1 of first segment + * @param e vertex 2 of first segment + * @return true if the segment intersects at least one segment of the triangle, false otherwise + */ + public static boolean testTri2SegIntersection(final Vert2fImmutable a, final Vert2fImmutable b, final Vert2fImmutable c, + final Vert2fImmutable d, final Vert2fImmutable e, + final float epsilon){ + return testSeg2SegIntersection(a, b, d, e, epsilon) || + testSeg2SegIntersection(b, c, d, e, epsilon) || + testSeg2SegIntersection(a, c, d, e, epsilon) ; + } } diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java index 264b9e2a6..812cbcc9d 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java +++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java @@ -686,13 +686,13 @@ public class ShaderCode { } /** - * Adds <code>data</code> at <code>offset</code> in shader source for shader <code>shaderIdx</code>. + * Adds <code>data</code> at <code>position</code> in shader source for shader <code>shaderIdx</code>. * <p> * Note: The shader source to be edit must be created using a mutable StringBuilder. * </p> * * @param shaderIdx the shader index to be used. - * @param position in shader source segments of shader <code>shaderIdx</code> + * @param position in shader source segments of shader <code>shaderIdx</code>, -1 will append data * @param data the text to be inserted. Shall end with an EOL '\n' character * @return index after the inserted <code>data</code> * @@ -718,7 +718,10 @@ public class ShaderCode { } final StringBuilder sb = (StringBuilder)src[j]; curEndIndex += sb.length(); - if(position < curEndIndex) { + if( 0 > position && j == src.length - 1 ) { + position = curEndIndex; + } + if(0 <= position && position <= curEndIndex ) { sb.insert(position, data); return position+data.length(); } @@ -726,6 +729,36 @@ public class ShaderCode { return -1; } + /** + * Adds shader source located in <code>path</code>, + * either relative to the <code>context</code> class or absolute <i>as-is</i> + * at <code>position</code> in shader source for shader <code>shaderIdx</code>. + * <p> + * Final location lookup is performed via {@link ClassLoader#getResource(String)} and {@link ClassLoader#getSystemResource(String)}, + * see {@link IOUtil#getResource(Class, String)}. + * </p> + * <p> + * Note: The shader source to be edit must be created using a mutable StringBuilder. + * </p> + * + * @param shaderIdx the shader index to be used. + * @param position in shader source segments of shader <code>shaderIdx</code>, -1 will append data + * @param context class used to help resolve the source location + * @param path location of shader source + * @return index after the inserted code. + * @throws IOException + * @throws IllegalStateException if the shader source's CharSequence is immutable, i.e. not of type <code>StringBuilder</code> + * @see IOUtil#getResource(Class, String) + */ + public int insertShaderSource(int shaderIdx, int position, Class<?> context, String path) throws IOException { + final CharSequence data = readShaderSource(context, path, true); + if( null != data ) { + return insertShaderSource(shaderIdx, position, data); + } else { + return position; + } + } + @SuppressWarnings("resource") private static int readShaderSource(Class<?> context, URLConnection conn, StringBuilder result, int lineno) throws IOException { if(DEBUG_CODE) { @@ -869,7 +902,7 @@ public class ShaderCode { * @return the complete extension directive */ public static String createExtensionDirective(String extensionName, String behavior) { - return "#extension " + extensionName + " : " + behavior; + return "#extension " + extensionName + " : " + behavior + "\n"; } /** diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java index f60cb6088..ce4c2615d 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java +++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java @@ -766,7 +766,7 @@ public class ShaderState { activeAttribLocationMap.clear(); for(int i=0; i<managedAttributes.size(); i++) { - ((GLArrayData)managedAttributes.get(i)).setLocation(-1); + managedAttributes.get(i).setLocation(-1); } for(Iterator<GLArrayData> iter = activeAttribDataMap.values().iterator(); iter.hasNext(); ) { relocateAttribute(gl, iter.next()); @@ -816,7 +816,7 @@ public class ShaderState { * otherwise >= 0 */ public final int getCachedUniformLocation(String name) { - Integer idx = (Integer) activeUniformLocationMap.get(name); + Integer idx = activeUniformLocationMap.get(name); return (null!=idx)?idx.intValue():-1; } @@ -1075,16 +1075,16 @@ public class ShaderState { private boolean verbose = DEBUG; private ShaderProgram shaderProgram=null; - private HashMap<String, Boolean> activedAttribEnabledMap = new HashMap<String, Boolean>(); - private HashMap<String, Integer> activeAttribLocationMap = new HashMap<String, Integer>(); - private HashMap<String, GLArrayData> activeAttribDataMap = new HashMap<String, GLArrayData>(); - private ArrayList<GLArrayData> managedAttributes = new ArrayList<GLArrayData>(); + private final HashMap<String, Boolean> activedAttribEnabledMap = new HashMap<String, Boolean>(); + private final HashMap<String, Integer> activeAttribLocationMap = new HashMap<String, Integer>(); + private final HashMap<String, GLArrayData> activeAttribDataMap = new HashMap<String, GLArrayData>(); + private final ArrayList<GLArrayData> managedAttributes = new ArrayList<GLArrayData>(); - private HashMap<String, Integer> activeUniformLocationMap = new HashMap<String, Integer>(); - private HashMap<String, GLUniformData> activeUniformDataMap = new HashMap<String, GLUniformData>(); - private ArrayList<GLUniformData> managedUniforms = new ArrayList<GLUniformData>(); + private final HashMap<String, Integer> activeUniformLocationMap = new HashMap<String, Integer>(); + private final HashMap<String, GLUniformData> activeUniformDataMap = new HashMap<String, GLUniformData>(); + private final ArrayList<GLUniformData> managedUniforms = new ArrayList<GLUniformData>(); - private HashMap<String, Object> attachedObjectsByString = new HashMap<String, Object>(); + private final HashMap<String, Object> attachedObjectsByString = new HashMap<String, Object>(); private boolean resetAllShaderData = false; } diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java b/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java deleted file mode 100644 index 9a5ed62d8..000000000 --- a/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java +++ /dev/null @@ -1,106 +0,0 @@ -/** - * Copyright 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ -package jogamp.graph.curve.opengl; - -import javax.media.opengl.GL2ES2; -import javax.media.opengl.GLException; - -import jogamp.graph.curve.opengl.shader.AttributeNames; -import jogamp.opengl.Debug; - -import com.jogamp.graph.curve.opengl.RenderState; -import com.jogamp.graph.curve.opengl.RegionRenderer; -import com.jogamp.opengl.GLExtensions; -import com.jogamp.opengl.util.glsl.ShaderCode; -import com.jogamp.opengl.util.glsl.ShaderProgram; -import com.jogamp.opengl.util.glsl.ShaderState; - -public class RegionRendererImpl01 extends RegionRenderer { - private static final String CUSTOM_FP, CUSTOM_VP; - static { - Debug.initSingleton(); - CUSTOM_VP = Debug.getProperty("jogl.debug.graph.curve.vp", false); - CUSTOM_FP = Debug.getProperty("jogl.debug.graph.curve.fp", false); - } - - public RegionRendererImpl01(final RenderState rs, final int renderModes, final GLCallback enableCallback, final GLCallback disableCallback) { - super(rs, renderModes, enableCallback, disableCallback); - } - - @Override - protected final boolean initImpl(GL2ES2 gl) { - final ShaderState st = getShaderState(); - final ShaderCode rsVp, rsFp; - if( null != CUSTOM_VP ) { - rsVp = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, RegionRendererImpl01.class, null, null, CUSTOM_VP, true); - } else { - rsVp = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, RegionRendererImpl01.class, "shader", "shader/bin", getVertexShaderName(), true); - } - if( null != CUSTOM_FP ) { - rsFp = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, RegionRendererImpl01.class, null, null, CUSTOM_FP, true); - } else { - rsFp = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, RegionRendererImpl01.class, "shader", "shader/bin", getFragmentShaderName(), true); - } - rsVp.defaultShaderCustomization(gl, true, true); - // rsFp.defaultShaderCustomization(gl, true, true); - int pos = rsFp.addGLSLVersion(gl); - if( gl.isGLES2() && ! gl.isGLES3() ) { - pos = rsFp.insertShaderSource(0, pos, ShaderCode.createExtensionDirective(GLExtensions.OES_standard_derivatives, ShaderCode.ENABLE)); - } - final String rsFpDefPrecision = getFragmentShaderPrecision(gl); - if( null != rsFpDefPrecision ) { - rsFp.insertShaderSource(0, pos, rsFpDefPrecision); - } - - final ShaderProgram sp = new ShaderProgram(); - sp.add(rsVp); - sp.add(rsFp); - - if( !sp.init(gl) ) { - throw new GLException("RegionRenderer: Couldn't init program: "+sp); - } - st.attachShaderProgram(gl, sp, false); - st.bindAttribLocation(gl, AttributeNames.VERTEX_ATTR_IDX, AttributeNames.VERTEX_ATTR_NAME); - st.bindAttribLocation(gl, AttributeNames.TEXCOORD_ATTR_IDX, AttributeNames.TEXCOORD_ATTR_NAME); - - if(!sp.link(gl, System.err)) { - throw new GLException("RegionRenderer: Couldn't link program: "+sp); - } - st.useProgram(gl, true); - - if(DEBUG) { - System.err.println("RegionRendererImpl01 initialized: " + Thread.currentThread()+" "+st); - } - return true; - } - - @Override - protected final void destroyImpl(GL2ES2 gl) { - // NOP .. all will be destroyed via RenderState - } -} diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/RenderStateImpl.java b/src/jogl/classes/jogamp/graph/curve/opengl/RenderStateImpl.java deleted file mode 100644 index 68f926b0a..000000000 --- a/src/jogl/classes/jogamp/graph/curve/opengl/RenderStateImpl.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * Copyright 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ -package jogamp.graph.curve.opengl; - -import java.nio.FloatBuffer; - -import javax.media.opengl.GLUniformData; - -import jogamp.graph.curve.opengl.shader.UniformNames; - -import com.jogamp.graph.curve.opengl.RenderState; -import com.jogamp.graph.geom.Vertex; -import com.jogamp.opengl.util.PMVMatrix; -import com.jogamp.opengl.util.glsl.ShaderState; - -public class RenderStateImpl extends RenderState { - /** - * weight is equivalent to the - * global off-curve vertex weight. - * TODO: change to per vertex - */ - private final GLUniformData gcu_Weight; - private final GLUniformData gcu_Alpha; - private final GLUniformData gcu_ColorStatic; - - public RenderStateImpl(ShaderState st, Vertex.Factory<? extends Vertex> pointFactory, PMVMatrix pmvMatrix) { - super(st, pointFactory, pmvMatrix); - - gcu_Weight = new GLUniformData(UniformNames.gcu_Weight, 1.0f); - st.ownUniform(gcu_PMVMatrix); - gcu_Alpha = new GLUniformData(UniformNames.gcu_Alpha, 1.0f); - st.ownUniform(gcu_Alpha); - gcu_ColorStatic = new GLUniformData(UniformNames.gcu_ColorStatic, 3, FloatBuffer.allocate(3)); - st.ownUniform(gcu_ColorStatic); -// gcu_Strength = new GLUniformData(UniformNames.gcu_Strength, 3.0f); -// st.ownUniform(gcu_Strength); - } - - @Override - public final GLUniformData getWeight() { return gcu_Weight; } - @Override - public final GLUniformData getAlpha() { return gcu_Alpha; } - @Override - public final GLUniformData getColorStatic() { return gcu_ColorStatic; } - //public final GLUniformData getStrength() { return gcu_Strength; } - - -} diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java index e36f46878..4649a2714 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java @@ -33,13 +33,10 @@ import javax.media.opengl.GL2ES2; // FIXME: Subsume GL2GL3.GL_DRAW_FRAMEBUFFER -> GL2ES2.GL_DRAW_FRAMEBUFFER ! import javax.media.opengl.GL; import javax.media.opengl.GLUniformData; -import javax.media.opengl.fixedfunc.GLMatrixFunc; import jogamp.graph.curve.opengl.shader.AttributeNames; import jogamp.graph.curve.opengl.shader.UniformNames; -import com.jogamp.common.nio.Buffers; -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; @@ -48,128 +45,171 @@ import com.jogamp.opengl.FBObject.Attachment; import com.jogamp.opengl.math.geom.AABBox; import com.jogamp.opengl.util.GLArrayDataServer; import com.jogamp.opengl.util.PMVMatrix; -import com.jogamp.opengl.util.glsl.ShaderState; +import com.jogamp.opengl.util.glsl.ShaderProgram; public class VBORegion2PMSAAES2 extends GLRegion { private static final boolean DEBUG_FBO_1 = false; private static final boolean DEBUG_FBO_2 = false; - private GLArrayDataServer verticeTxtAttr; - private GLArrayDataServer texCoordTxtAttr; - private GLArrayDataServer indicesTxtBuffer; - private GLArrayDataServer verticeFboAttr; - private GLArrayDataServer texCoordFboAttr; + + // Pass-1: + private GLArrayDataServer gca_VerticesAttr; + private GLArrayDataServer gca_CurveParamsAttr; + private GLArrayDataServer gca_ColorsAttr; + private GLArrayDataServer indicesBuffer; + private ShaderProgram spPass1 = null; + + // Pass-2: + private GLArrayDataServer gca_FboVerticesAttr; + private GLArrayDataServer gca_FboTexCoordsAttr; private GLArrayDataServer indicesFbo; + private final GLUniformData gcu_FboTexUnit; + private GLUniformData gcu_FboTexSize; + private final PMVMatrix fboPMVMatrix; + private final GLUniformData gcu_PMVMatrix02; + private boolean gcu_FboTexSize_dirty = true; + private boolean gcu_PMVMatrix02_dirty = true; + private ShaderProgram spPass2 = null; private FBObject fbo; - private final PMVMatrix fboPMVMatrix; - GLUniformData mgl_fboPMVMatrix; private int fboWidth = 0; private int fboHeight = 0; private boolean fboDirty = true; - GLUniformData mgl_ActiveTexture; - GLUniformData mgl_TextureSize; final int[] maxTexSize = new int[] { -1 } ; + 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(); + final boolean updateLocation0 = renderer.useShaderProgram(gl, renderModes, pass1, quality, sampleCount); + final ShaderProgram sp = renderer.getRenderState().getShaderProgram(); + final boolean updateLocation; + if( pass1 ) { + updateLocation = !sp.equals(spPass1); + spPass1 = sp; + rs.update(gl, updateLocation, renderModes, true); + if( updateLocation ) { + gcu_PMVMatrix02.setLocation(gl, sp.program()); + } + rs.updateAttributeLoc(gl, updateLocation, gca_VerticesAttr); + rs.updateAttributeLoc(gl, updateLocation, gca_CurveParamsAttr); + if( null != gca_ColorsAttr ) { + rs.updateAttributeLoc(gl, updateLocation, gca_ColorsAttr); + } + System.err.println("XXX changedSP.p1 "+updateLocation+" / "+updateLocation0+", "+rs); + } else { + updateLocation = !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_FboTexSize); + if( updateLocation ) { + gcu_FboTexSize.setLocation(gl, sp.program()); + } + System.err.println("XXX changedSP.p2 "+updateLocation+" / "+updateLocation0+", "+rs); + } + } + public VBORegion2PMSAAES2(final int renderModes, final int textureUnit) { super(renderModes); final int initialElementCount = 256; - fboPMVMatrix = new PMVMatrix(); - mgl_fboPMVMatrix = new GLUniformData(UniformNames.gcu_PMVMatrix, 4, 4, fboPMVMatrix.glGetPMvMatrixf()); - mgl_ActiveTexture = new GLUniformData(UniformNames.gcu_TextureUnit, textureUnit); - indicesTxtBuffer = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialElementCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER); - verticeTxtAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT, + // Pass 1: + indicesBuffer = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialElementCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER); + + gca_VerticesAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT, false, initialElementCount, GL.GL_STATIC_DRAW); - texCoordTxtAttr = GLArrayDataServer.createGLSL(AttributeNames.TEXCOORD_ATTR_NAME, 3, GL2ES2.GL_FLOAT, + + gca_CurveParamsAttr = GLArrayDataServer.createGLSL(AttributeNames.CURVEPARAMS_ATTR_NAME, 3, GL2ES2.GL_FLOAT, false, initialElementCount, GL.GL_STATIC_DRAW); + + if( hasColorChannel() ) { + gca_ColorsAttr = GLArrayDataServer.createGLSL(AttributeNames.COLOR_ATTR_NAME, 4, GL2ES2.GL_FLOAT, + false, initialElementCount, GL.GL_STATIC_DRAW); + } else { + gca_ColorsAttr = null; + } + + // Pass 2: + fboPMVMatrix = new PMVMatrix(); + gcu_PMVMatrix02 = new GLUniformData(UniformNames.gcu_PMVMatrix01, 4, 4, fboPMVMatrix.glGetPMvMatrixf()); + gcu_FboTexUnit = new GLUniformData(UniformNames.gcu_FboTexUnit, textureUnit); + + 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); + indicesFbo.puts((short) 1); indicesFbo.puts((short) 2); indicesFbo.puts((short) 3); + indicesFbo.seal(true); + + gca_FboTexCoordsAttr = GLArrayDataServer.createGLSL(AttributeNames.CURVEPARAMS_ATTR_NAME, 2, GL2ES2.GL_FLOAT, + false, 4, GL.GL_STATIC_DRAW); + gca_FboTexCoordsAttr.putf(0); gca_FboTexCoordsAttr.putf(0); + gca_FboTexCoordsAttr.putf(0); gca_FboTexCoordsAttr.putf(1); + gca_FboTexCoordsAttr.putf(1); gca_FboTexCoordsAttr.putf(1); + gca_FboTexCoordsAttr.putf(1); gca_FboTexCoordsAttr.putf(0); + gca_FboTexCoordsAttr.seal(true); + + gca_FboVerticesAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT, + false, 4, GL.GL_STATIC_DRAW); } @Override protected final void clearImpl(final GL2ES2 gl, final RegionRenderer renderer) { - if( null != indicesTxtBuffer ) { - indicesTxtBuffer.seal(gl, false); - indicesTxtBuffer.rewind(); + if( null != indicesBuffer ) { + indicesBuffer.seal(gl, false); + indicesBuffer.rewind(); } - if( null != verticeTxtAttr ) { - verticeTxtAttr.seal(gl, false); - verticeTxtAttr.rewind(); + if( null != gca_VerticesAttr ) { + gca_VerticesAttr.seal(gl, false); + gca_VerticesAttr.rewind(); } - if( null != texCoordTxtAttr ) { - texCoordTxtAttr.seal(gl, false); - texCoordTxtAttr.rewind(); + if( null != gca_CurveParamsAttr ) { + gca_CurveParamsAttr.seal(gl, false); + gca_CurveParamsAttr.rewind(); } fboDirty = true; } @Override - protected final void pushVertex(float[] coords, float[] texParams) { - verticeTxtAttr.putf(coords[0]); - verticeTxtAttr.putf(coords[1]); - verticeTxtAttr.putf(coords[2]); - - texCoordTxtAttr.putf(texParams[0]); - texCoordTxtAttr.putf(texParams[1]); - texCoordTxtAttr.putf(texParams[2]); + protected final void pushVertex(float[] coords, float[] texParams, float[] color) { + gca_VerticesAttr.putf(coords[0]); + gca_VerticesAttr.putf(coords[1]); + gca_VerticesAttr.putf(coords[2]); + + gca_CurveParamsAttr.putf(texParams[0]); + gca_CurveParamsAttr.putf(texParams[1]); + gca_CurveParamsAttr.putf(texParams[2]); } @Override protected final void pushIndex(int idx) { - indicesTxtBuffer.puts((short)idx); + indicesBuffer.puts((short)idx); } @Override protected void updateImpl(final GL2ES2 gl, final RegionRenderer renderer) { - if(null == indicesFbo) { - final ShaderState st = renderer.getShaderState(); - - 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); - indicesFbo.puts((short) 1); indicesFbo.puts((short) 2); indicesFbo.puts((short) 3); - indicesFbo.seal(true); - - texCoordFboAttr = GLArrayDataServer.createGLSL(AttributeNames.TEXCOORD_ATTR_NAME, 2, GL2ES2.GL_FLOAT, - false, 4, GL.GL_STATIC_DRAW); - st.ownAttribute(texCoordFboAttr, true); - texCoordFboAttr.putf(0); texCoordFboAttr.putf(0); - texCoordFboAttr.putf(0); texCoordFboAttr.putf(1); - texCoordFboAttr.putf(1); texCoordFboAttr.putf(1); - texCoordFboAttr.putf(1); texCoordFboAttr.putf(0); - texCoordFboAttr.seal(true); - - verticeFboAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT, - false, 4, GL.GL_STATIC_DRAW); - st.ownAttribute(verticeFboAttr, true); - - st.ownAttribute(verticeTxtAttr, true); - st.ownAttribute(texCoordTxtAttr, true); - - if(Region.DEBUG_INSTANCE) { - System.err.println("VBORegion2PMSAAES2 Create: " + this); - } - } // seal buffers - indicesTxtBuffer.seal(gl, true); - indicesTxtBuffer.enableBuffer(gl, false); - texCoordTxtAttr.seal(gl, true); - texCoordTxtAttr.enableBuffer(gl, false); - verticeTxtAttr.seal(gl, true); - verticeTxtAttr.enableBuffer(gl, false); + indicesBuffer.seal(gl, true); + indicesBuffer.enableBuffer(gl, false); + gca_CurveParamsAttr.seal(gl, true); + gca_CurveParamsAttr.enableBuffer(gl, false); + gca_VerticesAttr.seal(gl, true); + gca_VerticesAttr.enableBuffer(gl, false); // update all bbox related data - verticeFboAttr.seal(gl, false); - verticeFboAttr.rewind(); - verticeFboAttr.putf(box.getMinX()); verticeFboAttr.putf(box.getMinY()); verticeFboAttr.putf(box.getMinZ()); - verticeFboAttr.putf(box.getMinX()); verticeFboAttr.putf(box.getMaxY()); verticeFboAttr.putf(box.getMinZ()); - verticeFboAttr.putf(box.getMaxX()); verticeFboAttr.putf(box.getMaxY()); verticeFboAttr.putf(box.getMinZ()); - verticeFboAttr.putf(box.getMaxX()); verticeFboAttr.putf(box.getMinY()); verticeFboAttr.putf(box.getMinZ()); - verticeFboAttr.seal(gl, true); - verticeFboAttr.enableBuffer(gl, false); - - fboPMVMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION); - fboPMVMatrix.glLoadIdentity(); - fboPMVMatrix.glOrthof(box.getMinX(), box.getMaxX(), box.getMinY(), box.getMaxY(), -1, 1); + gca_FboVerticesAttr.seal(gl, false); + { + final FloatBuffer fb = (FloatBuffer)gca_FboVerticesAttr.getBuffer(); + fb.put( 2, box.getMinZ()); + fb.put( 5, box.getMinZ()); + fb.put( 8, box.getMinZ()); + fb.put(11, box.getMinZ()); + } + // Pending .. (follow fboDirty) + // gca_FboVerticesAttr.seal(gl, true); + // gca_FboVerticesAttr.enableBuffer(gl, false); + // fboPMVMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION); + // fboPMVMatrix.glLoadIdentity(); + // fboPMVMatrix.glOrthof(box.getMinX(), box.getMaxX(), box.getMinY(), box.getMaxY(), -1, 1); // push data 2 GPU .. indicesFbo.seal(gl, true); @@ -187,7 +227,7 @@ public class VBORegion2PMSAAES2 extends GLRegion { @Override protected void drawImpl(final GL2ES2 gl, final RegionRenderer renderer, final int[/*1*/] sampleCount) { - if( 0 >= indicesTxtBuffer.getElementCount() ) { + if( 0 >= indicesBuffer.getElementCount() ) { if(DEBUG_INSTANCE) { System.err.printf("VBORegion2PMSAAES2.drawImpl: Empty%n"); } @@ -277,58 +317,51 @@ public class VBORegion2PMSAAES2 extends GLRegion { final float minY = box.getMinY()-diffObjBorderHeight; final float maxX = box.getMaxX()+diffObjBorderWidth+diffObjWidth; final float maxY = box.getMaxY()+diffObjBorderHeight+diffObjHeight; - verticeFboAttr.seal(false); + gca_FboVerticesAttr.seal(false); { - final FloatBuffer fb = (FloatBuffer)verticeFboAttr.getBuffer(); + final FloatBuffer fb = (FloatBuffer)gca_FboVerticesAttr.getBuffer(); fb.put(0, minX); fb.put( 1, minY); fb.put(3, minX); fb.put( 4, maxY); fb.put(6, maxX); fb.put( 7, maxY); fb.put(9, maxX); fb.put(10, minY); } - verticeFboAttr.seal(true); + gca_FboVerticesAttr.seal(true); fboPMVMatrix.glLoadIdentity(); fboPMVMatrix.glOrthof(minX, maxX, minY, maxY, -1, 1); + gcu_PMVMatrix02_dirty = true; renderRegion2FBO(gl, rs, targetFboWidth, targetFboHeight, vpWidth, vpHeight, sampleCount); } else { - texCoordFboAttr.setVBOWritten(false); + gca_FboTexCoordsAttr.setVBOWritten(false); } // System.out.println("Scale: " + matrix.glGetMatrixf().get(1+4*3) +" " + matrix.glGetMatrixf().get(2+4*3)); renderFBO(gl, rs, vpWidth, vpHeight, sampleCount[0]); } } - private void setTexSize(final GL2ES2 gl, final ShaderState st, final boolean firstPass, final int width, final int height, final int sampleCount) { - if(null == mgl_TextureSize) { - mgl_TextureSize = new GLUniformData(UniformNames.gcu_TextureSize, 3, Buffers.newDirectFloatBuffer(3)); - } - final FloatBuffer texSize = (FloatBuffer) mgl_TextureSize.getBuffer(); - texSize.put(0, width); - texSize.put(1, height); - if( firstPass ) { - texSize.put(2, 0f); - } else { - texSize.put(2, 1f+sampleCount); - } - st.uniform(gl, mgl_TextureSize); - } private void renderFBO(final GL2ES2 gl, final RenderState rs, final int width, final int height, final int sampleCount) { - final ShaderState st = rs.getShaderState(); - gl.glViewport(0, 0, width, height); - st.uniform(gl, mgl_ActiveTexture); - gl.glActiveTexture(GL.GL_TEXTURE0 + mgl_ActiveTexture.intValue()); - setTexSize(gl, st, false, fboWidth, fboHeight, sampleCount); + + if( gcu_FboTexSize_dirty ) { + gl.glUniform(gcu_FboTexSize); + gcu_FboTexSize_dirty = false; + } + if( gcu_PMVMatrix02_dirty ) { + gl.glUniform(gcu_PMVMatrix02); + gcu_PMVMatrix02_dirty = false; + } + + gl.glActiveTexture(GL.GL_TEXTURE0 + gcu_FboTexUnit.intValue()); fbo.use(gl, fbo.getSamplingSink()); - verticeFboAttr.enableBuffer(gl, true); - texCoordFboAttr.enableBuffer(gl, true); + gca_FboVerticesAttr.enableBuffer(gl, true); + gca_FboTexCoordsAttr.enableBuffer(gl, true); indicesFbo.bindBuffer(gl, true); // keeps VBO binding gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesFbo.getElementCount() * indicesFbo.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0); indicesFbo.bindBuffer(gl, false); - texCoordFboAttr.enableBuffer(gl, false); - verticeFboAttr.enableBuffer(gl, false); + gca_FboTexCoordsAttr.enableBuffer(gl, false); + gca_FboVerticesAttr.enableBuffer(gl, false); fbo.unuse(gl); // setback: gl.glActiveTexture(currentActiveTextureEngine[0]); @@ -336,8 +369,6 @@ public class VBORegion2PMSAAES2 extends GLRegion { private void renderRegion2FBO(final GL2ES2 gl, final RenderState rs, final int targetFboWidth, final int targetFboHeight, final int vpWidth, final int vpHeight, final int[] sampleCount) { - final ShaderState st = rs.getShaderState(); - if( 0 >= targetFboWidth || 0 >= targetFboHeight ) { throw new IllegalArgumentException("fboSize must be greater than 0: "+targetFboWidth+"x"+targetFboHeight); } @@ -373,29 +404,26 @@ public class VBORegion2PMSAAES2 extends GLRegion { fboHeight = targetFboHeight; } fbo.bind(gl); - setTexSize(gl, st, true, vpWidth, vpHeight, sampleCount[0]); //render texture gl.glViewport(0, 0, fboWidth, fboHeight); - st.uniform(gl, mgl_fboPMVMatrix); // use orthogonal matrix gl.glClear(GL2ES2.GL_COLOR_BUFFER_BIT | GL2ES2.GL_DEPTH_BUFFER_BIT); renderRegion(gl); fbo.unbind(gl); - - st.uniform(gl, rs.getPMVMatrix()); // switch back to real PMV matrix + fboDirty = false; } private void renderRegion(final GL2ES2 gl) { - verticeTxtAttr.enableBuffer(gl, true); - texCoordTxtAttr.enableBuffer(gl, true); - indicesTxtBuffer.bindBuffer(gl, true); // keeps VBO binding + gca_VerticesAttr.enableBuffer(gl, true); + gca_CurveParamsAttr.enableBuffer(gl, true); + indicesBuffer.bindBuffer(gl, true); // keeps VBO binding - gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesTxtBuffer.getElementCount() * indicesTxtBuffer.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0); + gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesBuffer.getElementCount() * indicesBuffer.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0); - indicesTxtBuffer.bindBuffer(gl, false); - texCoordTxtAttr.enableBuffer(gl, false); - verticeTxtAttr.enableBuffer(gl, false); + indicesBuffer.bindBuffer(gl, false); + gca_CurveParamsAttr.enableBuffer(gl, false); + gca_VerticesAttr.enableBuffer(gl, false); } @Override @@ -403,34 +431,29 @@ public class VBORegion2PMSAAES2 extends GLRegion { if(DEBUG_INSTANCE) { System.err.println("VBORegion2PES2 Destroy: " + this); } - final ShaderState st = renderer.getShaderState(); if(null != fbo) { fbo.destroy(gl); fbo = null; } - if(null != verticeTxtAttr) { - st.ownAttribute(verticeTxtAttr, false); - verticeTxtAttr.destroy(gl); - verticeTxtAttr = null; + if(null != gca_VerticesAttr) { + gca_VerticesAttr.destroy(gl); + gca_VerticesAttr = null; } - if(null != texCoordTxtAttr) { - st.ownAttribute(texCoordTxtAttr, false); - texCoordTxtAttr.destroy(gl); - texCoordTxtAttr = null; + if(null != gca_CurveParamsAttr) { + gca_CurveParamsAttr.destroy(gl); + gca_CurveParamsAttr = null; } - if(null != indicesTxtBuffer) { - indicesTxtBuffer.destroy(gl); - indicesTxtBuffer = null; + if(null != indicesBuffer) { + indicesBuffer.destroy(gl); + indicesBuffer = null; } - if(null != verticeFboAttr) { - st.ownAttribute(verticeFboAttr, false); - verticeFboAttr.destroy(gl); - verticeFboAttr = null; + if(null != gca_FboVerticesAttr) { + gca_FboVerticesAttr.destroy(gl); + gca_FboVerticesAttr = null; } - if(null != texCoordFboAttr) { - st.ownAttribute(texCoordFboAttr, false); - texCoordFboAttr.destroy(gl); - texCoordFboAttr = null; + if(null != gca_FboTexCoordsAttr) { + gca_FboTexCoordsAttr.destroy(gl); + gca_FboTexCoordsAttr = null; } if(null != indicesFbo) { indicesFbo.destroy(gl); diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java index 4a12ed8d9..afaae3679 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java @@ -32,7 +32,6 @@ import java.nio.FloatBuffer; import javax.media.opengl.GL2ES2; import javax.media.opengl.GL; import javax.media.opengl.GLUniformData; -import javax.media.opengl.fixedfunc.GLMatrixFunc; import jogamp.graph.curve.opengl.shader.AttributeNames; import jogamp.graph.curve.opengl.shader.UniformNames; @@ -49,7 +48,7 @@ import com.jogamp.opengl.FBObject.TextureAttachment; import com.jogamp.opengl.math.geom.AABBox; import com.jogamp.opengl.util.GLArrayDataServer; import com.jogamp.opengl.util.PMVMatrix; -import com.jogamp.opengl.util.glsl.ShaderState; +import com.jogamp.opengl.util.glsl.ShaderProgram; public class VBORegion2PVBAAES2 extends GLRegion { private static final boolean DEBUG_FBO_1 = false; @@ -85,38 +84,102 @@ public class VBORegion2PVBAAES2 extends GLRegion { } - private GLArrayDataServer verticeTxtAttr; - private GLArrayDataServer texCoordTxtAttr; - private GLArrayDataServer indicesTxtBuffer; - private GLArrayDataServer verticeFboAttr; - private GLArrayDataServer texCoordFboAttr; + // Pass-1: + private GLArrayDataServer gca_VerticesAttr; + private GLArrayDataServer gca_CurveParamsAttr; + private GLArrayDataServer gca_ColorsAttr; + private GLArrayDataServer indicesBuffer; + private ShaderProgram spPass1 = null; + + // Pass-2: + private GLArrayDataServer gca_FboVerticesAttr; + private GLArrayDataServer gca_FboTexCoordsAttr; private GLArrayDataServer indicesFbo; + private final GLUniformData gcu_FboTexUnit; + private final GLUniformData gcu_FboTexSize; + private final PMVMatrix fboPMVMatrix; + private final GLUniformData gcu_PMVMatrix02; + private boolean gcu_FboTexSize_dirty = true; + private boolean gcu_PMVMatrix02_dirty = true; + private ShaderProgram spPass2 = null; private FBObject fbo; private TextureAttachment texA; - private final PMVMatrix fboPMVMatrix; - GLUniformData mgl_fboPMVMatrix; private int fboWidth = 0; private int fboHeight = 0; private boolean fboDirty = true; - GLUniformData mgl_ActiveTexture; - GLUniformData mgl_TextureSize; final int[] maxTexSize = new int[] { -1 } ; + 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(); + final boolean updateLocation0 = renderer.useShaderProgram(gl, renderModes, pass1, quality, sampleCount); + final ShaderProgram sp = renderer.getRenderState().getShaderProgram(); + final boolean updateLocation; + if( pass1 ) { + updateLocation = !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); + } + System.err.println("XXX changedSP.p1 "+updateLocation+" / "+updateLocation0+", "+rs); + } else { + updateLocation = !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); + System.err.println("XXX changedSP.p2 "+updateLocation+" / "+updateLocation0+", "+rs); + } + } + public VBORegion2PVBAAES2(final int renderModes, final int textureUnit) { super(renderModes); final int initialElementCount = 256; - fboPMVMatrix = new PMVMatrix(); - mgl_fboPMVMatrix = new GLUniformData(UniformNames.gcu_PMVMatrix, 4, 4, fboPMVMatrix.glGetPMvMatrixf()); - mgl_ActiveTexture = new GLUniformData(UniformNames.gcu_TextureUnit, textureUnit); - indicesTxtBuffer = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialElementCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER); - verticeTxtAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT, + // Pass 1: + indicesBuffer = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialElementCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER); + + gca_VerticesAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT, false, initialElementCount, GL.GL_STATIC_DRAW); - texCoordTxtAttr = GLArrayDataServer.createGLSL(AttributeNames.TEXCOORD_ATTR_NAME, 3, GL2ES2.GL_FLOAT, + + gca_CurveParamsAttr = GLArrayDataServer.createGLSL(AttributeNames.CURVEPARAMS_ATTR_NAME, 3, GL2ES2.GL_FLOAT, false, initialElementCount, GL.GL_STATIC_DRAW); + if( hasColorChannel() ) { + gca_ColorsAttr = GLArrayDataServer.createGLSL(AttributeNames.COLOR_ATTR_NAME, 4, GL2ES2.GL_FLOAT, + false, initialElementCount, GL.GL_STATIC_DRAW); + } else { + gca_ColorsAttr = null; + } + + // Pass 2: + fboPMVMatrix = new PMVMatrix(); + gcu_PMVMatrix02 = new GLUniformData(UniformNames.gcu_PMVMatrix02, 4, 4, fboPMVMatrix.glGetPMvMatrixf()); + gcu_FboTexUnit = new GLUniformData(UniformNames.gcu_FboTexUnit, textureUnit); + gcu_FboTexSize = new GLUniformData(UniformNames.gcu_FboTexSize, 2, Buffers.newDirectFloatBuffer(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); + indicesFbo.puts((short) 1); indicesFbo.puts((short) 2); indicesFbo.puts((short) 3); + indicesFbo.seal(true); + + gca_FboTexCoordsAttr = GLArrayDataServer.createGLSL(AttributeNames.FBO_TEXCOORDS_ATTR_NAME, 2, GL2ES2.GL_FLOAT, + false, 4, GL.GL_STATIC_DRAW); + gca_FboTexCoordsAttr.putf(0); gca_FboTexCoordsAttr.putf(0); + gca_FboTexCoordsAttr.putf(0); gca_FboTexCoordsAttr.putf(1); + gca_FboTexCoordsAttr.putf(1); gca_FboTexCoordsAttr.putf(1); + gca_FboTexCoordsAttr.putf(1); gca_FboTexCoordsAttr.putf(0); + gca_FboTexCoordsAttr.seal(true); + + gca_FboVerticesAttr = GLArrayDataServer.createGLSL(AttributeNames.FBO_VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT, + false, 4, GL.GL_STATIC_DRAW); } @Override @@ -125,88 +188,86 @@ public class VBORegion2PVBAAES2 extends GLRegion { System.err.println("VBORegion2PES2 Clear: " + this); // Thread.dumpStack(); } - if( null != indicesTxtBuffer ) { - indicesTxtBuffer.seal(gl, false); - indicesTxtBuffer.rewind(); + if( null != indicesBuffer ) { + indicesBuffer.seal(gl, false); + indicesBuffer.rewind(); } - if( null != verticeTxtAttr ) { - verticeTxtAttr.seal(gl, false); - verticeTxtAttr.rewind(); + if( null != gca_VerticesAttr ) { + gca_VerticesAttr.seal(gl, false); + gca_VerticesAttr.rewind(); } - if( null != texCoordTxtAttr ) { - texCoordTxtAttr.seal(gl, false); - texCoordTxtAttr.rewind(); + if( null != gca_CurveParamsAttr ) { + gca_CurveParamsAttr.seal(gl, false); + gca_CurveParamsAttr.rewind(); + } + if( null != gca_ColorsAttr ) { + gca_ColorsAttr.seal(gl, false); + gca_ColorsAttr.rewind(); } fboDirty = true; } @Override - protected final void pushVertex(float[] coords, float[] texParams) { - verticeTxtAttr.putf(coords[0]); - verticeTxtAttr.putf(coords[1]); - verticeTxtAttr.putf(coords[2]); - - texCoordTxtAttr.putf(texParams[0]); - texCoordTxtAttr.putf(texParams[1]); - texCoordTxtAttr.putf(texParams[2]); + protected final void pushVertex(final float[] coords, final float[] texParams, float[] rgba) { + gca_VerticesAttr.putf(coords[0]); + gca_VerticesAttr.putf(coords[1]); + gca_VerticesAttr.putf(coords[2]); + + gca_CurveParamsAttr.putf(texParams[0]); + gca_CurveParamsAttr.putf(texParams[1]); + gca_CurveParamsAttr.putf(texParams[2]); + + if( null != gca_ColorsAttr ) { + if( null != rgba ) { + gca_ColorsAttr.putf(rgba[0]); + gca_ColorsAttr.putf(rgba[1]); + gca_ColorsAttr.putf(rgba[2]); + gca_ColorsAttr.putf(rgba[3]); + } else { + throw new IllegalArgumentException("Null color given for COLOR_CHANNEL rendering mode"); + } + } } @Override protected final void pushIndex(int idx) { - indicesTxtBuffer.puts((short)idx); + indicesBuffer.puts((short)idx); } @Override protected void updateImpl(final GL2ES2 gl, final RegionRenderer renderer) { if(null == indicesFbo) { - final ShaderState st = renderer.getShaderState(); - - 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); - indicesFbo.puts((short) 1); indicesFbo.puts((short) 2); indicesFbo.puts((short) 3); - indicesFbo.seal(true); - - texCoordFboAttr = GLArrayDataServer.createGLSL(AttributeNames.TEXCOORD_ATTR_NAME, 2, GL2ES2.GL_FLOAT, - false, 4, GL.GL_STATIC_DRAW); - st.ownAttribute(texCoordFboAttr, true); - texCoordFboAttr.putf(0); texCoordFboAttr.putf(0); - texCoordFboAttr.putf(0); texCoordFboAttr.putf(1); - texCoordFboAttr.putf(1); texCoordFboAttr.putf(1); - texCoordFboAttr.putf(1); texCoordFboAttr.putf(0); - texCoordFboAttr.seal(true); - - verticeFboAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT, - false, 4, GL.GL_STATIC_DRAW); - st.ownAttribute(verticeFboAttr, true); - - st.ownAttribute(verticeTxtAttr, true); - st.ownAttribute(texCoordTxtAttr, true); - if(Region.DEBUG_INSTANCE) { System.err.println("VBORegion2PVBAAES2 Create: " + this); } } // seal buffers - indicesTxtBuffer.seal(gl, true); - indicesTxtBuffer.enableBuffer(gl, false); - texCoordTxtAttr.seal(gl, true); - texCoordTxtAttr.enableBuffer(gl, false); - verticeTxtAttr.seal(gl, true); - verticeTxtAttr.enableBuffer(gl, false); + indicesBuffer.seal(gl, true); + indicesBuffer.enableBuffer(gl, false); + gca_CurveParamsAttr.seal(gl, true); + gca_CurveParamsAttr.enableBuffer(gl, false); + gca_VerticesAttr.seal(gl, true); + gca_VerticesAttr.enableBuffer(gl, false); + if( null != gca_ColorsAttr ) { + gca_ColorsAttr.seal(gl, true); + gca_ColorsAttr.enableBuffer(gl, false); + } // update all bbox related data - verticeFboAttr.seal(gl, false); - verticeFboAttr.rewind(); - verticeFboAttr.putf(box.getMinX()); verticeFboAttr.putf(box.getMinY()); verticeFboAttr.putf(box.getMinZ()); - verticeFboAttr.putf(box.getMinX()); verticeFboAttr.putf(box.getMaxY()); verticeFboAttr.putf(box.getMinZ()); - verticeFboAttr.putf(box.getMaxX()); verticeFboAttr.putf(box.getMaxY()); verticeFboAttr.putf(box.getMinZ()); - verticeFboAttr.putf(box.getMaxX()); verticeFboAttr.putf(box.getMinY()); verticeFboAttr.putf(box.getMinZ()); - verticeFboAttr.seal(gl, true); - verticeFboAttr.enableBuffer(gl, false); - - fboPMVMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION); - fboPMVMatrix.glLoadIdentity(); - fboPMVMatrix.glOrthof(box.getMinX(), box.getMaxX(), box.getMinY(), box.getMaxY(), -1, 1); + gca_FboVerticesAttr.seal(gl, false); + { + final FloatBuffer fb = (FloatBuffer)gca_FboVerticesAttr.getBuffer(); + fb.put( 2, box.getMinZ()); + fb.put( 5, box.getMinZ()); + fb.put( 8, box.getMinZ()); + fb.put(11, box.getMinZ()); + } + // Pending .. (follow fboDirty) + // gca_FboVerticesAttr.seal(gl, true); + // gca_FboVerticesAttr.enableBuffer(gl, false); + // fboPMVMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION); + // fboPMVMatrix.glLoadIdentity(); + // fboPMVMatrix.glOrthof(box.getMinX(), box.getMaxX(), box.getMinY(), box.getMaxY(), -1, 1); // push data 2 GPU .. indicesFbo.seal(gl, true); @@ -223,7 +284,7 @@ public class VBORegion2PVBAAES2 extends GLRegion { @Override protected void drawImpl(final GL2ES2 gl, final RegionRenderer renderer, final int[/*1*/] sampleCount) { - if( 0 >= indicesTxtBuffer.getElementCount() ) { + if( 0 >= indicesBuffer.getElementCount() ) { if(DEBUG_INSTANCE) { System.err.printf("VBORegion2PVBAAES2.drawImpl: Empty%n"); } @@ -387,56 +448,47 @@ public class VBORegion2PVBAAES2 extends GLRegion { final float minY = box.getMinY()-diffObjBorderHeight; final float maxX = box.getMaxX()+diffObjBorderWidth+diffObjWidth+diffObjResizeWidth; final float maxY = box.getMaxY()+diffObjBorderHeight+diffObjHeight+diffObjResizeHeight; - verticeFboAttr.seal(false); + gca_FboVerticesAttr.seal(false); { - final FloatBuffer fb = (FloatBuffer)verticeFboAttr.getBuffer(); + final FloatBuffer fb = (FloatBuffer)gca_FboVerticesAttr.getBuffer(); fb.put(0, minX); fb.put( 1, minY); fb.put(3, minX); fb.put( 4, maxY); fb.put(6, maxX); fb.put( 7, maxY); fb.put(9, maxX); fb.put(10, minY); } - verticeFboAttr.seal(true); + gca_FboVerticesAttr.seal(true); fboPMVMatrix.glLoadIdentity(); fboPMVMatrix.glOrthof(minX, maxX, minY, maxY, -1, 1); + gcu_PMVMatrix02_dirty = true; + useShaderProgram(gl, renderer, getRenderModes(), true, getQuality(), sampleCount[0]); renderRegion2FBO(gl, rs, targetFboWidth, targetFboHeight, newFboWidth, newFboHeight, vpWidth, vpHeight, sampleCount[0]); } + useShaderProgram(gl, renderer, getRenderModes(), false, getQuality(), sampleCount[0]); renderFBO(gl, rs, targetFboWidth, targetFboHeight, vpWidth, vpHeight, sampleCount[0]); } } - private void setTexSize(final GL2ES2 gl, final ShaderState st, final boolean firstPass, final int width, final int height, final int sampleCount) { - if(null == mgl_TextureSize) { - mgl_TextureSize = new GLUniformData(UniformNames.gcu_TextureSize, 3, Buffers.newDirectFloatBuffer(3)); - } - final FloatBuffer texSize = (FloatBuffer) mgl_TextureSize.getBuffer(); - texSize.put(0, width); - texSize.put(1, height); - if( firstPass ) { - texSize.put(2, 0f); - } else { - texSize.put(2, sampleCount); - } - st.uniform(gl, mgl_TextureSize); - } private void renderFBO(final GL2ES2 gl, final RenderState rs, final int targetFboWidth, final int targetFboHeight, final int vpWidth, final int vpHeight, final int sampleCount) { - final ShaderState st = rs.getShaderState(); - gl.glViewport(0, 0, vpWidth, vpHeight); - st.uniform(gl, mgl_ActiveTexture); - gl.glActiveTexture(GL.GL_TEXTURE0 + mgl_ActiveTexture.intValue()); - setTexSize(gl, st, false, fboWidth, fboHeight, sampleCount); + + if( gcu_FboTexSize_dirty ) { + gl.glUniform(gcu_FboTexSize); + gcu_FboTexSize_dirty = false; + } + + gl.glActiveTexture(GL.GL_TEXTURE0 + gcu_FboTexUnit.intValue()); fbo.use(gl, texA); - verticeFboAttr.enableBuffer(gl, true); - texCoordFboAttr.enableBuffer(gl, true); + gca_FboVerticesAttr.enableBuffer(gl, true); + gca_FboTexCoordsAttr.enableBuffer(gl, true); indicesFbo.bindBuffer(gl, true); // keeps VBO binding gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesFbo.getElementCount() * indicesFbo.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0); indicesFbo.bindBuffer(gl, false); - texCoordFboAttr.enableBuffer(gl, false); - verticeFboAttr.enableBuffer(gl, false); + gca_FboTexCoordsAttr.enableBuffer(gl, false); + gca_FboVerticesAttr.enableBuffer(gl, false); fbo.unuse(gl); // setback: gl.glActiveTexture(currentActiveTextureEngine[0]); @@ -445,8 +497,6 @@ public class VBORegion2PVBAAES2 extends GLRegion { private void renderRegion2FBO(final GL2ES2 gl, final RenderState rs, final int targetFboWidth, final int targetFboHeight, final int newFboWidth, final int newFboHeight, final int vpWidth, final int vpHeight, final int sampleCount) { - final ShaderState st = rs.getShaderState(); - if( 0 >= targetFboWidth || 0 >= targetFboHeight ) { throw new IllegalArgumentException("fboSize must be greater than 0: "+targetFboWidth+"x"+targetFboHeight); } @@ -454,6 +504,12 @@ public class VBORegion2PVBAAES2 extends GLRegion { if(null == fbo) { fboWidth = newFboWidth; fboHeight = newFboHeight; + final FloatBuffer fboTexSize = (FloatBuffer) gcu_FboTexSize.getBuffer(); + { + fboTexSize.put(0, fboWidth); + fboTexSize.put(1, fboHeight); + gcu_FboTexSize_dirty=true; + } fbo = new FBObject(); fbo.reset(gl, fboWidth, fboHeight); // Shall not use bilinear (GL_LINEAR), due to own VBAA. Result is smooth w/o it now! @@ -472,33 +528,46 @@ public class VBORegion2PVBAAES2 extends GLRegion { } fboWidth = newFboWidth; fboHeight = newFboHeight; + final FloatBuffer fboTexSize = (FloatBuffer) gcu_FboTexSize.getBuffer(); + { + fboTexSize.put(0, fboWidth); + fboTexSize.put(1, fboHeight); + gcu_FboTexSize_dirty=true; + } } else { fbo.bind(gl); } - setTexSize(gl, st, true, vpWidth, vpHeight, sampleCount); //render texture gl.glViewport(0, 0, fboWidth, fboHeight); - st.uniform(gl, mgl_fboPMVMatrix); // use orthogonal matrix + + if( gcu_PMVMatrix02_dirty ) { + gl.glUniform(gcu_PMVMatrix02); + gcu_PMVMatrix02_dirty = false; + } gl.glClear(GL2ES2.GL_COLOR_BUFFER_BIT | GL2ES2.GL_DEPTH_BUFFER_BIT); renderRegion(gl); fbo.unbind(gl); fboDirty = false; - - st.uniform(gl, rs.getPMVMatrix()); // switch back to real PMV matrix } private void renderRegion(final GL2ES2 gl) { - verticeTxtAttr.enableBuffer(gl, true); - texCoordTxtAttr.enableBuffer(gl, true); - indicesTxtBuffer.bindBuffer(gl, true); // keeps VBO binding + 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, indicesTxtBuffer.getElementCount() * indicesTxtBuffer.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0); + gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesBuffer.getElementCount() * indicesBuffer.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0); - indicesTxtBuffer.bindBuffer(gl, false); - texCoordTxtAttr.enableBuffer(gl, false); - verticeTxtAttr.enableBuffer(gl, false); + indicesBuffer.bindBuffer(gl, false); + if( null != gca_ColorsAttr ) { + gca_ColorsAttr.enableBuffer(gl, false); + } + gca_CurveParamsAttr.enableBuffer(gl, false); + gca_VerticesAttr.enableBuffer(gl, false); } @Override @@ -507,35 +576,35 @@ public class VBORegion2PVBAAES2 extends GLRegion { System.err.println("VBORegion2PES2 Destroy: " + this); // Thread.dumpStack(); } - final ShaderState st = renderer.getShaderState(); if(null != fbo) { fbo.destroy(gl); fbo = null; texA = null; } - if(null != verticeTxtAttr) { - st.ownAttribute(verticeTxtAttr, false); - verticeTxtAttr.destroy(gl); - verticeTxtAttr = null; + if(null != gca_VerticesAttr) { + gca_VerticesAttr.destroy(gl); + gca_VerticesAttr = null; + } + if(null != gca_CurveParamsAttr) { + gca_CurveParamsAttr.destroy(gl); + gca_CurveParamsAttr = null; } - if(null != texCoordTxtAttr) { - st.ownAttribute(texCoordTxtAttr, false); - texCoordTxtAttr.destroy(gl); - texCoordTxtAttr = null; + if(null != gca_ColorsAttr) { + gca_ColorsAttr.destroy(gl); + gca_ColorsAttr = null; } - if(null != indicesTxtBuffer) { - indicesTxtBuffer.destroy(gl); - indicesTxtBuffer = null; + if(null != indicesBuffer) { + indicesBuffer.destroy(gl); + indicesBuffer = null; } - if(null != verticeFboAttr) { - st.ownAttribute(verticeFboAttr, false); - verticeFboAttr.destroy(gl); - verticeFboAttr = null; + + if(null != gca_FboVerticesAttr) { + gca_FboVerticesAttr.destroy(gl); + gca_FboVerticesAttr = null; } - if(null != texCoordFboAttr) { - st.ownAttribute(texCoordFboAttr, false); - texCoordFboAttr.destroy(gl); - texCoordFboAttr = null; + if(null != gca_FboTexCoordsAttr) { + gca_FboTexCoordsAttr.destroy(gl); + gca_FboTexCoordsAttr = null; } if(null != indicesFbo) { indicesFbo.destroy(gl); diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java index cf85628ad..659f64847 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java @@ -34,25 +34,33 @@ import jogamp.graph.curve.opengl.shader.AttributeNames; 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.ShaderState; +import com.jogamp.opengl.util.glsl.ShaderProgram; public class VBORegionSPES2 extends GLRegion { - private GLArrayDataServer verticeAttr = null; - private GLArrayDataServer texCoordAttr = null; + private GLArrayDataServer gca_VerticesAttr = null; + private GLArrayDataServer gca_CurveParamsAttr = null; + private GLArrayDataServer gca_ColorsAttr; private GLArrayDataServer indicesBuffer = null; - private boolean buffersAttached = false; public VBORegionSPES2(final int renderModes) { super(renderModes); final int initialElementCount = 256; indicesBuffer = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialElementCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER); - verticeAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT, - false, initialElementCount, GL.GL_STATIC_DRAW); + gca_VerticesAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT, + false, initialElementCount, GL.GL_STATIC_DRAW); - texCoordAttr = GLArrayDataServer.createGLSL(AttributeNames.TEXCOORD_ATTR_NAME, 3, GL2ES2.GL_FLOAT, - false, initialElementCount, GL.GL_STATIC_DRAW); + gca_CurveParamsAttr = GLArrayDataServer.createGLSL(AttributeNames.CURVEPARAMS_ATTR_NAME, 3, GL2ES2.GL_FLOAT, + false, initialElementCount, GL.GL_STATIC_DRAW); + + if( hasColorChannel() ) { + gca_ColorsAttr = GLArrayDataServer.createGLSL(AttributeNames.COLOR_ATTR_NAME, 4, GL2ES2.GL_FLOAT, + false, initialElementCount, GL.GL_STATIC_DRAW); + } else { + gca_ColorsAttr = null; + } } @Override @@ -64,25 +72,40 @@ public class VBORegionSPES2 extends GLRegion { indicesBuffer.seal(gl, false); indicesBuffer.rewind(); } - if( null != verticeAttr ) { - verticeAttr.seal(gl, false); - verticeAttr.rewind(); + if( null != gca_VerticesAttr ) { + gca_VerticesAttr.seal(gl, false); + gca_VerticesAttr.rewind(); } - if( null != texCoordAttr ) { - texCoordAttr.seal(gl, false); - texCoordAttr.rewind(); + if( null != gca_CurveParamsAttr ) { + gca_CurveParamsAttr.seal(gl, false); + gca_CurveParamsAttr.rewind(); + } + if( null != gca_ColorsAttr ) { + gca_ColorsAttr.seal(gl, false); + gca_ColorsAttr.rewind(); } } @Override - protected final void pushVertex(float[] coords, float[] texParams) { - verticeAttr.putf(coords[0]); - verticeAttr.putf(coords[1]); - verticeAttr.putf(coords[2]); - - texCoordAttr.putf(texParams[0]); - texCoordAttr.putf(texParams[1]); - texCoordAttr.putf(texParams[2]); + protected final void pushVertex(float[] coords, float[] texParams, float[] rgba) { + gca_VerticesAttr.putf(coords[0]); + gca_VerticesAttr.putf(coords[1]); + gca_VerticesAttr.putf(coords[2]); + + gca_CurveParamsAttr.putf(texParams[0]); + gca_CurveParamsAttr.putf(texParams[1]); + gca_CurveParamsAttr.putf(texParams[2]); + + if( null != gca_ColorsAttr ) { + if( null != rgba ) { + gca_ColorsAttr.putf(rgba[0]); + gca_ColorsAttr.putf(rgba[1]); + gca_ColorsAttr.putf(rgba[2]); + gca_ColorsAttr.putf(rgba[3]); + } else { + throw new IllegalArgumentException("Null color given for COLOR_CHANNEL rendering mode"); + } + } } @Override @@ -92,43 +115,67 @@ public class VBORegionSPES2 extends GLRegion { @Override protected void updateImpl(final GL2ES2 gl, final RegionRenderer renderer) { - if( !buffersAttached ) { - final ShaderState st = renderer.getShaderState(); - st.ownAttribute(verticeAttr, true); - st.ownAttribute(texCoordAttr, true); - buffersAttached = true; - } // seal buffers indicesBuffer.seal(gl, true); indicesBuffer.enableBuffer(gl, false); - verticeAttr.seal(gl, true); - verticeAttr.enableBuffer(gl, false); - texCoordAttr.seal(gl, true); - texCoordAttr.enableBuffer(gl, false); + gca_VerticesAttr.seal(gl, true); + gca_VerticesAttr.enableBuffer(gl, false); + gca_CurveParamsAttr.seal(gl, true); + gca_CurveParamsAttr.enableBuffer(gl, false); + if( null != gca_ColorsAttr ) { + gca_ColorsAttr.seal(gl, true); + gca_ColorsAttr.enableBuffer(gl, false); + } if(DEBUG_INSTANCE) { System.err.println("VBORegionSPES2 idx "+indicesBuffer); - System.err.println("VBORegionSPES2 ver "+verticeAttr); - System.err.println("VBORegionSPES2 tex "+texCoordAttr); + System.err.println("VBORegionSPES2 ver "+gca_VerticesAttr); + System.err.println("VBORegionSPES2 tex "+gca_CurveParamsAttr); } } + private ShaderProgram spPass1 = null; + + 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 ShaderProgram sp = renderer.getRenderState().getShaderProgram(); + final boolean updateLocation = !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); + } + System.err.println("XXX changedSP "+updateLocation+", "+rs); + System.err.println("XXX gca_VerticesAttr "+gca_VerticesAttr); + System.err.println("XXX gca_CurveParamsAttr "+gca_CurveParamsAttr); + System.err.println("XXX gca_ColorsAttr "+gca_ColorsAttr); + } + + @Override protected void drawImpl(final GL2ES2 gl, final RegionRenderer renderer, final int[/*1*/] sampleCount) { + final int renderModes = getRenderModes(); + useShaderProgram(gl, renderer, renderModes, getQuality()); + if( 0 >= indicesBuffer.getElementCount() ) { if(DEBUG_INSTANCE) { System.err.printf("VBORegionSPES2.drawImpl: Empty%n"); } return; // empty! } - verticeAttr.enableBuffer(gl, true); - texCoordAttr.enableBuffer(gl, true); + gca_VerticesAttr.enableBuffer(gl, true); + gca_CurveParamsAttr.enableBuffer(gl, true); indicesBuffer.bindBuffer(gl, true); // keeps VBO binding gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesBuffer.getElementCount() * indicesBuffer.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0); indicesBuffer.bindBuffer(gl, false); - texCoordAttr.enableBuffer(gl, false); - verticeAttr.enableBuffer(gl, false); + gca_CurveParamsAttr.enableBuffer(gl, false); + gca_VerticesAttr.enableBuffer(gl, false); } @Override @@ -136,16 +183,17 @@ public class VBORegionSPES2 extends GLRegion { if(DEBUG_INSTANCE) { System.err.println("VBORegionSPES2 Destroy: " + this); } - final ShaderState st = renderer.getShaderState(); - if(null != verticeAttr) { - st.ownAttribute(verticeAttr, false); - verticeAttr.destroy(gl); - verticeAttr = null; + if(null != gca_VerticesAttr) { + gca_VerticesAttr.destroy(gl); + gca_VerticesAttr = null; + } + if(null != gca_CurveParamsAttr) { + gca_CurveParamsAttr.destroy(gl); + gca_CurveParamsAttr = null; } - if(null != texCoordAttr) { - st.ownAttribute(texCoordAttr, false); - texCoordAttr.destroy(gl); - texCoordAttr = null; + if(null != gca_ColorsAttr) { + gca_ColorsAttr.destroy(gl); + gca_ColorsAttr = null; } if(null != indicesBuffer) { indicesBuffer.destroy(gl); 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 b46661778..b2c73a2e4 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/AttributeNames.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/AttributeNames.java @@ -28,18 +28,22 @@ package jogamp.graph.curve.opengl.shader; public class AttributeNames { - /** The vertices index in an OGL object + /** + * The vertices index in an OGL object */ - public static final int VERTEX_ATTR_IDX = 0; // FIXME: AMD needs this to be location 0 ? hu ? public static final String VERTEX_ATTR_NAME = "gca_Vertices"; - /** The Texture Coord index in an OGL object + /** + * The Texture Coord index in an OGL object */ - public static final int TEXCOORD_ATTR_IDX = 1; - public static final String TEXCOORD_ATTR_NAME = "gca_TexCoords"; + public static final String CURVEPARAMS_ATTR_NAME = "gca_CurveParams"; - /** The color index in an OGL object + /** + * The color index in an OGL object */ - public static final int COLOR_ATTR_IDX = 2; 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 ce23aadac..df5ba35f2 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/UniformNames.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/UniformNames.java @@ -1,10 +1,11 @@ package jogamp.graph.curve.opengl.shader; public class UniformNames { - public static final String gcu_PMVMatrix = "gcu_PMVMatrix"; // gcu_PMVMatrix[3]; // P, Mv, and Mvi + public static final String gcu_PMVMatrix01 = "gcu_PMVMatrix01"; // gcu_PMVMatrix[3]; // P, Mv, and Mvi public static final String gcu_ColorStatic = "gcu_ColorStatic"; - public static final String gcu_Alpha = "gcu_Alpha"; public static final String gcu_Weight = "gcu_Weight"; - public static final String gcu_TextureUnit = "gcu_TextureUnit"; - public static final String gcu_TextureSize = "gcu_TextureSize"; + + public static final String gcu_PMVMatrix02 = "gcu_PMVMatrix01"; // gcu_PMVMatrix[3]; // P, Mv, and Mvi + public static final String gcu_FboTexUnit = "gcu_FboTexUnit"; + public static final String gcu_FboTexSize = "gcu_FboTexSize"; } diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/attributes.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/attributes.glsl index c4d9db535..b8c68a924 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/attributes.glsl +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/attributes.glsl @@ -12,13 +12,19 @@ attribute vec4 gca_Vertices; * hole or holeLike: 0 > y * !hole : 0 < y * - * 0 == gcv_TexCoord.x : vertex-0 of triangle - * 0.5 == gcv_TexCoord.x : vertex-1 of triangle - * 1 == gcv_TexCoord.x : vertex-2 of triangle + * 0 == gcv_CurveParams.x : vertex-0 of triangle + * 0.5 == gcv_CurveParams.x : vertex-1 of triangle + * 1 == gcv_CurveParams.x : vertex-2 of triangle */ -attribute vec3 gca_TexCoords; +attribute vec3 gca_CurveParams; + +attribute vec4 gca_FboVertices; +attribute vec2 gca_FboTexCoords; + +#ifdef USE_COLOR_CHANNEL + attribute vec4 gca_Colors; +#endif -//attribute vec4 gca_Colors; //attribute vec3 gca_Normals; #endif // attributes_glsl diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-1pass_norm-weight.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-1pass_norm-weight.fp index 20acfbac6..6e60fc044 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-1pass_norm-weight.fp +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-1pass_norm-weight.fp @@ -14,15 +14,10 @@ #include uniforms.glsl #include varyings.glsl -const vec3 zero3 = vec3(0); - void main (void) { - vec3 color; - float alpha; // #include curverenderer01-pass1-curve-lineAA.glsl #include curverenderer01-pass1-curve-weight.glsl - mgl_FragColor = vec4(color, gcu_Alpha * alpha); } diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-1pass_norm.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-1pass_norm.fp index 03d2f9408..18f06fff0 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-1pass_norm.fp +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-1pass_norm.fp @@ -14,15 +14,10 @@ #include uniforms.glsl #include varyings.glsl -const vec3 zero3 = vec3(0); - void main (void) { - vec3 color; - float alpha; // #include curverenderer01-pass1-curve-lineAA.glsl #include curverenderer01-pass1-curve-simple.glsl - mgl_FragColor = vec4(color, gcu_Alpha * alpha); } diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_msaa-weight.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_msaa-weight.fp index fba66c398..0a4f7b331 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_msaa-weight.fp +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_msaa-weight.fp @@ -15,28 +15,21 @@ #include uniforms.glsl #include varyings.glsl -const vec3 zero3 = vec3(0); - void main (void) { - vec3 color; - float alpha; - - if( 0.0 < gcu_TextureSize.z ) { + if( 0.0 < gcu_FboTexSize.z ) { // Pass-2: Dump Texture - vec4 t = texture2D(gcu_TextureUnit, gcv_TexCoord.st); + vec4 t = texture2D(gcu_FboTexUnit, gcv_FboTexCoord.st); #if 0 if( 0.0 == t.a ) { discard; // discard freezes NV tegra2 compiler } #endif - color = t.rgb; - alpha = gcu_Alpha * t.a; + mgl_FragColor = t; } else { #include curverenderer01-pass1-curve-weight.glsl } - mgl_FragColor = vec4(color, alpha); } diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_msaa.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_msaa.fp index e573bb347..c5cbb99b0 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_msaa.fp +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_msaa.fp @@ -15,36 +15,22 @@ #include uniforms.glsl #include varyings.glsl -const vec3 zero3 = vec3(0); - void main (void) { - vec3 color; - float alpha; - - if( 0.0 < gcu_TextureSize.z ) { + if( 0.0 < gcu_FboTexSize.z ) { // Pass-2: Dump Texture - vec4 t = texture2D(gcu_TextureUnit, gcv_TexCoord.st); + vec4 t = texture2D(gcu_FboTexUnit, gcv_FboTexCoord.st); #if 0 if( 0.0 == t.a ) { discard; // discard freezes NV tegra2 compiler } #endif - color = t.rgb; - #ifdef PREALPHA - // alpha = mix(0.0, gcu_Alpha, t.a); // t.a one of [ 0.0, 1.0 ] - // ^^ for = 0.0 == t.a ? 0.0 : gcu_Alpha; - // mix(x, y, a) := x * ( 1 - a ) + y * a - alpha = gcu_Alpha; - #else - alpha = gcu_Alpha * t.a; - #endif + mgl_FragColor = t; } else { #include curverenderer01-pass1-curve-simple.glsl } - mgl_FragColor = vec4(color, alpha); } diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_vbaa-weight.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_vbaa-weight.fp index cca67a219..e3bcd20ae 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_vbaa-weight.fp +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_vbaa-weight.fp @@ -15,18 +15,11 @@ #include uniforms.glsl #include varyings.glsl -const vec3 zero3 = vec3(0); - #define GetSample(texUnit, texCoord, psize, cx, cy, offX, offY) texture2D(texUnit, texCoord + psize * vec2(cx+offX, cy+offY)) void main (void) { - vec3 color; - float alpha; - - // Note: gcu_Alpha is multiplied in pass2! - - if( 0.0 < gcu_TextureSize.z ) { + if( 0.0 < gcu_FboTexSize.z ) { // Quality: allsamples > [flipquad,rgss, quincunx] > poles #include curverenderer01-pass2-vbaa_allsamples_equal.glsl @@ -48,5 +41,4 @@ void main (void) #include curverenderer01-pass1-curve-weight.glsl } - mgl_FragColor = vec4(color, alpha); } diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_vbaa.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_vbaa.fp index e4dca15cb..52c719e46 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_vbaa.fp +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_vbaa.fp @@ -15,23 +15,19 @@ #include uniforms.glsl #include varyings.glsl -const vec3 zero3 = vec3(0); - #define GetSample(texUnit, texCoord, psize, cx, cy, offX, offY) texture2D(texUnit, texCoord + psize * vec2(cx+offX, cy+offY)) void main (void) { - vec3 color; - float alpha; - - // Note: gcu_Alpha is multiplied in pass2! - - if( 0.0 < gcu_TextureSize.z ) { + if( 0.0 < gcu_FboTexSize.z ) { // Quality: allsamples > [flipquad,rgss, quincunx] > poles -#include curverenderer01-pass2-vbaa_allsamples_equal.glsl -// #include curverenderer01-pass2-vbaa_flipquad3.glsl + if( 0.0 >= gcu_FboTexSize.w ) { +#include curverenderer01-pass2-vbaa_flipquad3.glsl + } else { +#include curverenderer01-pass2-vbaa_allsamples_equal.glsl + } // #include curverenderer01-pass2-vbaa_flipquad2.glsl // #include curverenderer01-pass2-vbaa_flipquad.glsl // #include curverenderer01-pass2-vbaa_rgss.glsl @@ -48,5 +44,4 @@ void main (void) #include curverenderer01-pass1-curve-simple.glsl } - mgl_FragColor = vec4(color, alpha); } diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve-lineAA.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve-lineAA.glsl deleted file mode 100644 index 770ab3d71..000000000 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve-lineAA.glsl +++ /dev/null @@ -1,20 +0,0 @@ - - // if( gcv_TexCoord.x == 10.0 && gcv_TexCoord.y == 10.0 ) { - if( gcv_TexCoord.z > 0.0 ) { - // pass-1: AA Lines - #if 1 - // float dist = sqrt( gcv_TexCoord.x*gcv_TexCoord.x + gcv_TexCoord.y*gcv_TexCoord.y ); // magnitude - float dist = sqrt( gcv_TexCoord.y*gcv_TexCoord.y ); // magnitude - // float a = 1.0 - smoothstep (gcv_TexCoord.y-gcv_TexCoord.z, gcv_TexCoord.y, dist); - float r = gcv_TexCoord.x/3.0; - float wa = gcv_TexCoord.x+r; - float waHalf = wa/2.0; - float a = 1.0 - smoothstep (waHalf-2.0*r, waHalf, dist); - color = vec3(0, 0, 1.0); // gcu_ColorStatic.rgb; - alpha = a; - #else - color = vec3(0, 0, 1.0); - alpha = 1.0; - #endif - } else - 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 deleted file mode 100644 index cfa1b9000..000000000 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve-simple.glsl +++ /dev/null @@ -1,21 +0,0 @@ - - if( gcv_TexCoord.x == 0.0 && gcv_TexCoord.y == 0.0 ) { - // pass-1: Lines - // color = vec3(0, 1.0, 0); - color = gcu_ColorStatic.rgb; - alpha = 1.0; - } else { - // pass-1: curves - vec2 rtex = vec2( abs(gcv_TexCoord.x), abs(gcv_TexCoord.y) - 0.1 ); - - vec2 dtx = dFdx(rtex); - vec2 dty = dFdy(rtex); - - vec2 f = vec2((dtx.y - dtx.x + 2.0*rtex.x*dtx.x), (dty.y - dty.x + 2.0*rtex.x*dty.x)); - float position = rtex.y - (rtex.x * (1.0 - rtex.x)); - - // color = vec3(1.0, 0, 0); - color = gcu_ColorStatic.rgb; - alpha = clamp(0.5 - ( position/length(f) ) * sign(gcv_TexCoord.y), 0.0, 1.0); - } - diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve-simple.orig.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve-simple.orig.glsl deleted file mode 100644 index f73f24f12..000000000 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve-simple.orig.glsl +++ /dev/null @@ -1,32 +0,0 @@ - - vec2 rtex = vec2( abs(gcv_TexCoord.x), abs(gcv_TexCoord.y) ); - - if( gcv_TexCoord.x == 0.0 && gcv_TexCoord.y == 0.0 ) { - // pass-1: Lines - color = gcu_ColorStatic.rgb; - alpha = 1.0; - } else if ( gcv_TexCoord.x > 0.0 && ( rtex.y > 0.0 || rtex.x == 1.0 ) ) { - // pass-1: curves - rtex.y -= 0.1; - - if(rtex.y < 0.0 && gcv_TexCoord.y < 0.0) { - // discard; // freezes NV tegra2 compiler - color = zero3; - alpha = 0.0; - } else { - rtex.y = max(rtex.y, 0.0); // always >= 0 - - vec2 dtx = dFdx(rtex); - vec2 dty = dFdy(rtex); - - vec2 f = vec2((dtx.y - dtx.x + 2.0*rtex.x*dtx.x), (dty.y - dty.x + 2.0*rtex.x*dty.x)); - float position = rtex.y - (rtex.x * (1.0 - rtex.x)); - - color = gcu_ColorStatic.rgb; - alpha = clamp(0.5 - ( position/length(f) ) * sign(gcv_TexCoord.y), 0.0, 1.0); - } - } else { - color = zero3; - alpha = 0.0; - } - diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve-weight.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve-weight.glsl deleted file mode 100644 index 21e44a23f..000000000 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve-weight.glsl +++ /dev/null @@ -1,25 +0,0 @@ - - if( gcv_TexCoord.x == 0.0 && gcv_TexCoord.y == 0.0 ) { - // pass-1: Lines - color = gcu_ColorStatic.rgb; - alpha = 1.0; - } else { - // pass-1: curves - vec2 rtex = vec2( abs(gcv_TexCoord.x), abs(gcv_TexCoord.y) - 0.1 ); - - vec2 dtx = dFdx(rtex); - vec2 dty = dFdy(rtex); - - float w = gcu_Weight; - float pd = ((2.0 - (2.0*w))*rtex.x*rtex.x) + 2.0*(w-1.0)*rtex.x + 1.0; - float position = rtex.y - ((w*rtex.x*(1.0 - rtex.x))/pd); - - float aph = 2.0 - 2.0*w; - - float gd = (aph*rtex.x*rtex.x + 2.0*rtex.x + 1.0)*(aph*rtex.x*rtex.x + 2.0*rtex.x + 1.0); - vec2 f = vec2((dtx.y - (w*dtx.x*(1.0 - 2.0*rtex.x))/gd), (dty.y - (w*dty.x*(1.0 - 2.0*rtex.x))/gd)); - - color = gcu_ColorStatic.rgb; - alpha = clamp(0.5 - ( position/length(f) ) * sign(gcv_TexCoord.y), 0.0, 1.0); - } - diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_lineAA.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_lineAA.glsl new file mode 100644 index 000000000..79b3dd6fd --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_lineAA.glsl @@ -0,0 +1,19 @@ + + // if( gcv_CurveParam.x == 10.0 && gcv_CurveParam.y == 10.0 ) { + if( gcv_CurveParam.z > 0.0 ) { + // pass-1: AA Lines + #if 1 + // float dist = sqrt( gcv_CurveParam.x*gcv_CurveParam.x + gcv_CurveParam.y*gcv_CurveParam.y ); // magnitude + float dist = sqrt( gcv_CurveParam.y*gcv_CurveParam.y ); // magnitude + // float a = 1.0 - smoothstep (gcv_CurveParam.y-gcv_CurveParam.z, gcv_CurveParam.y, dist); + float r = gcv_CurveParam.x/3.0; + float wa = gcv_CurveParam.x+r; + float waHalf = wa/2.0; + float a = 1.0 - smoothstep (waHalf-2.0*r, waHalf, dist); + // mgl_FragColor = vec4(gcu_ColorStatic.rgb, gcu_ColorStatic.a * a); + mgl_FragColor = vec4(0, 0, 1.0, gcu_ColorStatic.a * a); + #else + mgl_FragColor = vec4(0, 0, 1.0, 1.0); + #endif + } else + 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 new file mode 100644 index 000000000..373e8d575 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_simple.glsl @@ -0,0 +1,26 @@ + + if( gcv_CurveParam.x == 0.0 && gcv_CurveParam.y == 0.0 ) { + // pass-1: Lines +#ifdef USE_COLOR_CHANNEL + mgl_FragColor = gcv_Color * gcu_ColorStatic; +#else + mgl_FragColor = gcu_ColorStatic; +#endif + } else { + // pass-1: curves + vec2 rtex = vec2( abs(gcv_CurveParam.x), abs(gcv_CurveParam.y) - 0.1 ); + + vec2 dtx = dFdx(rtex); + vec2 dty = dFdy(rtex); + + vec2 f = vec2((dtx.y - dtx.x + 2.0*rtex.x*dtx.x), (dty.y - dty.x + 2.0*rtex.x*dty.x)); + float position = rtex.y - (rtex.x * (1.0 - rtex.x)); + + float a = clamp(0.5 - ( position/length(f) ) * sign(gcv_CurveParam.y), 0.0, 1.0); +#ifdef 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); +#endif + } + diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_simple.orig.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_simple.orig.glsl new file mode 100644 index 000000000..92f0fc07b --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_simple.orig.glsl @@ -0,0 +1,37 @@ + + vec2 rtex = vec2( abs(gcv_CurveParam.x), abs(gcv_CurveParam.y) ); + + if( gcv_CurveParam.x == 0.0 && gcv_CurveParam.y == 0.0 ) { + // pass-1: Lines +#ifdef USE_COLOR_CHANNEL + mgl_FragColor = gcv_Color * gcu_ColorStatic; +#else + mgl_FragColor = gcu_ColorStatic; +#endif + } else if ( gcv_CurveParam.x > 0.0 && ( rtex.y > 0.0 || rtex.x == 1.0 ) ) { + // pass-1: curves + rtex.y -= 0.1; + + if(rtex.y < 0.0 && gcv_CurveParam.y < 0.0) { + // discard; // freezes NV tegra2 compiler + mgl_FragColor = vec4(0); + } else { + rtex.y = max(rtex.y, 0.0); // always >= 0 + + vec2 dtx = dFdx(rtex); + vec2 dty = dFdy(rtex); + + vec2 f = vec2((dtx.y - dtx.x + 2.0*rtex.x*dtx.x), (dty.y - dty.x + 2.0*rtex.x*dty.x)); + float position = rtex.y - (rtex.x * (1.0 - rtex.x)); + + float a = clamp(0.5 - ( position/length(f) ) * sign(gcv_CurveParam.y), 0.0, 1.0); +#ifdef 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); +#endif + } + } else { + mgl_FragColor = vec4(0); + } + diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_weight.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_weight.glsl new file mode 100644 index 000000000..1620a9532 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_weight.glsl @@ -0,0 +1,32 @@ + + if( gcv_CurveParam.x == 0.0 && gcv_CurveParam.y == 0.0 ) { + // pass-1: Lines +#ifdef USE_COLOR_CHANNEL + mgl_FragColor = gcv_Color * gcu_ColorStatic; +#else + mgl_FragColor = gcu_ColorStatic; +#endif + } else { + // pass-1: curves + vec2 rtex = vec2( abs(gcv_CurveParam.x), abs(gcv_CurveParam.y) - 0.1 ); + + vec2 dtx = dFdx(rtex); + vec2 dty = dFdy(rtex); + + float w = gcu_Weight; + float pd = ((2.0 - (2.0*w))*rtex.x*rtex.x) + 2.0*(w-1.0)*rtex.x + 1.0; + float position = rtex.y - ((w*rtex.x*(1.0 - rtex.x))/pd); + + float aph = 2.0 - 2.0*w; + + float gd = (aph*rtex.x*rtex.x + 2.0*rtex.x + 1.0)*(aph*rtex.x*rtex.x + 2.0*rtex.x + 1.0); + vec2 f = vec2((dtx.y - (w*dtx.x*(1.0 - 2.0*rtex.x))/gd), (dty.y - (w*dty.x*(1.0 - 2.0*rtex.x))/gd)); + + float a = clamp(0.5 - ( position/length(f) ) * sign(gcv_CurveParam.y), 0.0, 1.0); +#ifdef 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); +#endif + } + 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 new file mode 100644 index 000000000..46729cfd0 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1.vp @@ -0,0 +1,30 @@ +//Copyright 2010 JogAmp Community. All rights reserved. + +#if __VERSION__ >= 130 + #define attribute in + #define varying out +#endif + +#include uniforms.glsl +#include attributes.glsl +#include varyings.glsl + +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; +#else + if( gcv_CurveParams.x <= -10.0 ) { + // vec4 tc = gcu_PMVMatrix02[0] * gcu_PMVMatrix02[1] * vec4(gca_CurveParams.xy, gca_Vertices.z, 1); + // gcv_CurveParams = vec3(tc.xy, gca_CurveParams.z); + gcv_CurveParam = gca_CurveParams; + } else { + gcv_CurveParam = gca_CurveParams; + } +#endif +#ifdef USE_COLOR_CHANNEL + gcv_Color = gca_Colors; +#endif +} diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_allequal.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_allequal.glsl new file mode 100644 index 000000000..da7feeaa7 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_allequal.glsl @@ -0,0 +1,96 @@ + // Pass-2: AA on Texture + // Note: gcv_FboTexCoord is in center of sample pixels. + + // float sampleCount = gcu_FboTexSize.z; + vec2 psize = 1.0 / gcu_FboTexSize.xy; // pixel size + + // Not only the poles (NW, SW, ..) but the whole edge! + const float sample_weight = 1.0 / ( SAMPLE_COUNT * SAMPLE_COUNT ); + + // const vec4 tex_weights = vec4(0.075, 0.06, 0.045, 0.025); + vec2 texCoord = gcv_FboTexCoord.st; + + vec4 t; + + // SampleCount 2 -> 4x + t = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-0.5, -0.5)))*sample_weight; // NW + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-0.5, 0.5)))*sample_weight; // SW + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 0.5, 0.5)))*sample_weight; // SE + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 0.5, -0.5)))*sample_weight; // NE + #if SAMPLE_COUNT > 2 + // SampleCount 4 -> +12x = 16p + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-1.5, -1.5)))*sample_weight; // NW -> SW Edge + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-1.5, -0.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-1.5, 0.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-1.5, 1.5)))*sample_weight; // SW -> SE Edge + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-0.5, 1.5)))*sample_weight; // + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 0.5, 1.5)))*sample_weight; // + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 1.5, 1.5)))*sample_weight; // SE -> NE Edge + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 1.5, 0.5)))*sample_weight; // + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 1.5, -0.5)))*sample_weight; // + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 1.5, -1.5)))*sample_weight; // NE -> NW Edge + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 0.5, -1.5)))*sample_weight; // + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-0.5, -1.5)))*sample_weight; // NW - 1 (closed) + + #if SAMPLE_COUNT > 4 + // SampleCount 6 -> +20x = 36p + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-2.5, -2.5)))*sample_weight; // NW -> SW Edge + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-2.5, -1.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-2.5, -0.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-2.5, 0.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-2.5, 1.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-2.5, 2.5)))*sample_weight; // SW -> SE Edge + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-1.5, 2.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-0.5, 2.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 0.5, 2.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 1.5, 2.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 2.5, 2.5)))*sample_weight; // SE -> NE Edge + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 2.5, 1.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 2.5, 0.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 2.5, -0.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 2.5, -1.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 2.5, -2.5)))*sample_weight; // NE -> NW Edge + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 1.5, -2.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 0.5, -2.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-0.5, -2.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-1.5, -2.5)))*sample_weight; // NW - 1 (closed) + #if SAMPLE_COUNT > 6 + // SampleCount 8 -> +28x = 64p + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-3.5, -3.5)))*sample_weight; // NW -> SW Edge + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-3.5, -2.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-3.5, -1.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-3.5, -0.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-3.5, 0.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-3.5, 1.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-3.5, 2.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-3.5, 3.5)))*sample_weight; // SW -> SE Edge + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-2.5, 3.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-1.5, 3.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-0.5, 3.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 0.5, 3.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 1.5, 3.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 2.5, 3.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 3.5, 3.5)))*sample_weight; // SE -> NE Edge + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 3.5, 2.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 3.5, 1.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 3.5, 0.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 3.5, -0.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 3.5, -1.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 3.5, -2.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 3.5, -3.5)))*sample_weight; // NE -> NW Edge + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 2.5, -3.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 1.5, -3.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 0.5, -3.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-0.5, -3.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-1.5, -3.5)))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-2.5, -3.5)))*sample_weight; // NW - 1 (closed) + #endif + #endif + #endif + #if 0 + if(t.w == 0.0){ + discard; // discard freezes NV tegra2 compiler + } + #endif + + mgl_FragColor = t; diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_allprop01.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_allprop01.glsl new file mode 100644 index 000000000..436dd4ed4 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_allprop01.glsl @@ -0,0 +1,113 @@ + // Pass-2: AA on Texture + // Note: gcv_FboTexCoord is in center of sample pixels. + + float sampleCount = gcu_FboTexSize.z; + vec2 psize = 1.0 / gcu_FboTexSize.xy; // pixel size + + // Not only the poles (NW, SW, ..) but the whole edge! + float pixelCount = sampleCount * sampleCount; + + // sampleCount [0, 1, 3, 5, 7] are undefined! + float layerCount = ( sampleCount / 2.0 ); + + // sum of all integer [layerCount .. 1] -> Gauss + float denom = ( layerCount / 2.0 ) * ( layerCount + 1.0 ); + + vec2 texCoord = gcv_FboTexCoord.st; + + vec4 t; + + // Layer-1: SampleCount 2 -> 4x + t = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-0.5, -0.5))); // NW + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-0.5, 0.5))); // SW + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 0.5, 0.5))); // SE + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 0.5, -0.5))); // NE + + t *= (layerCount - 0.0) / ( denom * 4.0 ); // weight layer 1 + + if( sampleCount > 2.0 ) { + // Layer-2: SampleCount 4 -> +12x = 16p + vec4 tn = vec4(0); + tn = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-1.5, -1.5))); // NW -> SW Edge + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-1.5, -0.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-1.5, 0.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-1.5, 1.5))); // SW -> SE Edge + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-0.5, 1.5))); // + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 0.5, 1.5))); // + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 1.5, 1.5))); // SE -> NE Edge + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 1.5, 0.5))); // + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 1.5, -0.5))); // + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 1.5, -1.5))); // NE -> NW Edge + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 0.5, -1.5))); // + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-0.5, -1.5))); // NW - 1 (closed) + + t += tn * (layerCount - 1) / ( denom * 12.0 ); // weight layer 2 + + if( sampleCount > 4.0 ) { + // Layer-3: SampleCount 6 -> +20x = 36p + tn = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-2.5, -2.5))); // NW -> SW Edge + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-2.5, -1.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-2.5, -0.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-2.5, 0.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-2.5, 1.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-2.5, 2.5))); // SW -> SE Edge + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-1.5, 2.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-0.5, 2.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 0.5, 2.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 1.5, 2.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 2.5, 2.5))); // SE -> NE Edge + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 2.5, 1.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 2.5, 0.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 2.5, -0.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 2.5, -1.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 2.5, -2.5))); // NE -> NW Edge + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 1.5, -2.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 0.5, -2.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-0.5, -2.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-1.5, -2.5))); // NW - 1 (closed) + + t += tn * (layerCount - 2) / ( denom * 20.0 ); // weight layer 3 + + if( sampleCount > 6.0 ) { + // Layer-4: SampleCount 8 -> +28x = 64p + tn = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-3.5, -3.5))); // NW -> SW Edge + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-3.5, -2.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-3.5, -1.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-3.5, -0.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-3.5, 0.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-3.5, 1.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-3.5, 2.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-3.5, 3.5))); // SW -> SE Edge + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-2.5, 3.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-1.5, 3.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-0.5, 3.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 0.5, 3.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 1.5, 3.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 2.5, 3.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 3.5, 3.5))); // SE -> NE Edge + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 3.5, 2.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 3.5, 1.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 3.5, 0.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 3.5, -0.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 3.5, -1.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 3.5, -2.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 3.5, -3.5))); // NE -> NW Edge + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 2.5, -3.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 1.5, -3.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 0.5, -3.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-0.5, -3.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-1.5, -3.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-2.5, -3.5))); // NW - 1 (closed) + + t += tn * (layerCount - 3) / ( denom * 28.0 ); // weight layer 4 + } + } + } + + #if 0 + if(t.w == 0.0){ + discard; // discard freezes NV tegra2 compiler + } + #endif + + mgl_FragColor = t; diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_allsamples_equal.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_allsamples_equal.glsl deleted file mode 100644 index 1d2451755..000000000 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_allsamples_equal.glsl +++ /dev/null @@ -1,97 +0,0 @@ - // Pass-2: AA on Texture - // Note: gcv_TexCoord is in center of sample pixels. - - float sampleCount = gcu_TextureSize.z; - vec2 psize = 1.0 / gcu_TextureSize.xy; // pixel size - - // Not only the poles (NW, SW, ..) but the whole edge! - float sample_weight = 1.0 / ( sampleCount * sampleCount ); - - // const vec4 tex_weights = vec4(0.075, 0.06, 0.045, 0.025); - vec2 texCoord = gcv_TexCoord.st; - - vec4 t; - - // SampleCount 2 -> 4x - t = texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-0.5, -0.5)))*sample_weight; // NW - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-0.5, 0.5)))*sample_weight; // SW - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 0.5, 0.5)))*sample_weight; // SE - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 0.5, -0.5)))*sample_weight; // NE - if( sampleCount > 2.0 ) { - // SampleCount 4 -> +12x = 16p - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-1.5, -1.5)))*sample_weight; // NW -> SW Edge - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-1.5, -0.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-1.5, 0.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-1.5, 1.5)))*sample_weight; // SW -> SE Edge - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-0.5, 1.5)))*sample_weight; // - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 0.5, 1.5)))*sample_weight; // - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 1.5, 1.5)))*sample_weight; // SE -> NE Edge - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 1.5, 0.5)))*sample_weight; // - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 1.5, -0.5)))*sample_weight; // - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 1.5, -1.5)))*sample_weight; // NE -> NW Edge - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 0.5, -1.5)))*sample_weight; // - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-0.5, -1.5)))*sample_weight; // NW - 1 (closed) - - if( sampleCount > 4.0 ) { - // SampleCount 6 -> +20x = 36p - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-2.5, -2.5)))*sample_weight; // NW -> SW Edge - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-2.5, -1.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-2.5, -0.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-2.5, 0.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-2.5, 1.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-2.5, 2.5)))*sample_weight; // SW -> SE Edge - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-1.5, 2.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-0.5, 2.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 0.5, 2.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 1.5, 2.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 2.5, 2.5)))*sample_weight; // SE -> NE Edge - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 2.5, 1.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 2.5, 0.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 2.5, -0.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 2.5, -1.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 2.5, -2.5)))*sample_weight; // NE -> NW Edge - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 1.5, -2.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 0.5, -2.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-0.5, -2.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-1.5, -2.5)))*sample_weight; // NW - 1 (closed) - if( sampleCount > 6.0 ) { - // SampleCount 8 -> +28x = 64p - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-3.5, -3.5)))*sample_weight; // NW -> SW Edge - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-3.5, -2.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-3.5, -1.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-3.5, -0.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-3.5, 0.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-3.5, 1.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-3.5, 2.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-3.5, 3.5)))*sample_weight; // SW -> SE Edge - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-2.5, 3.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-1.5, 3.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-0.5, 3.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 0.5, 3.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 1.5, 3.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 2.5, 3.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 3.5, 3.5)))*sample_weight; // SE -> NE Edge - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 3.5, 2.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 3.5, 1.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 3.5, 0.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 3.5, -0.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 3.5, -1.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 3.5, -2.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 3.5, -3.5)))*sample_weight; // NE -> NW Edge - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 2.5, -3.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 1.5, -3.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 0.5, -3.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-0.5, -3.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-1.5, -3.5)))*sample_weight; - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-2.5, -3.5)))*sample_weight; // NW - 1 (closed) - } - } - } - #if 0 - if(t.w == 0.0){ - discard; // discard freezes NV tegra2 compiler - } - #endif - - color = t.rgb; - alpha = gcu_Alpha * t.a; diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_allsamples_prop01.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_allsamples_prop01.glsl deleted file mode 100644 index 79c89a444..000000000 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_allsamples_prop01.glsl +++ /dev/null @@ -1,114 +0,0 @@ - // Pass-2: AA on Texture - // Note: gcv_TexCoord is in center of sample pixels. - - float sampleCount = gcu_TextureSize.z; - vec2 psize = 1.0 / gcu_TextureSize.xy; // pixel size - - // Not only the poles (NW, SW, ..) but the whole edge! - float pixelCount = sampleCount * sampleCount; - - // sampleCount [0, 1, 3, 5, 7] are undefined! - float layerCount = ( sampleCount / 2.0 ); - - // sum of all integer [layerCount .. 1] -> Gauss - float denom = ( layerCount / 2.0 ) * ( layerCount + 1.0 ); - - vec2 texCoord = gcv_TexCoord.st; - - vec4 t; - - // Layer-1: SampleCount 2 -> 4x - t = texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-0.5, -0.5))); // NW - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-0.5, 0.5))); // SW - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 0.5, 0.5))); // SE - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 0.5, -0.5))); // NE - - t *= (layerCount - 0.0) / ( denom * 4.0 ); // weight layer 1 - - if( sampleCount > 2.0 ) { - // Layer-2: SampleCount 4 -> +12x = 16p - vec4 tn = vec4(0); - tn = texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-1.5, -1.5))); // NW -> SW Edge - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-1.5, -0.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-1.5, 0.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-1.5, 1.5))); // SW -> SE Edge - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-0.5, 1.5))); // - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 0.5, 1.5))); // - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 1.5, 1.5))); // SE -> NE Edge - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 1.5, 0.5))); // - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 1.5, -0.5))); // - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 1.5, -1.5))); // NE -> NW Edge - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 0.5, -1.5))); // - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-0.5, -1.5))); // NW - 1 (closed) - - t += tn * (layerCount - 1) / ( denom * 12.0 ); // weight layer 2 - - if( sampleCount > 4.0 ) { - // Layer-3: SampleCount 6 -> +20x = 36p - tn = texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-2.5, -2.5))); // NW -> SW Edge - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-2.5, -1.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-2.5, -0.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-2.5, 0.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-2.5, 1.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-2.5, 2.5))); // SW -> SE Edge - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-1.5, 2.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-0.5, 2.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 0.5, 2.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 1.5, 2.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 2.5, 2.5))); // SE -> NE Edge - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 2.5, 1.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 2.5, 0.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 2.5, -0.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 2.5, -1.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 2.5, -2.5))); // NE -> NW Edge - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 1.5, -2.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 0.5, -2.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-0.5, -2.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-1.5, -2.5))); // NW - 1 (closed) - - t += tn * (layerCount - 2) / ( denom * 20.0 ); // weight layer 3 - - if( sampleCount > 6.0 ) { - // Layer-4: SampleCount 8 -> +28x = 64p - tn = texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-3.5, -3.5))); // NW -> SW Edge - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-3.5, -2.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-3.5, -1.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-3.5, -0.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-3.5, 0.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-3.5, 1.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-3.5, 2.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-3.5, 3.5))); // SW -> SE Edge - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-2.5, 3.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-1.5, 3.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-0.5, 3.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 0.5, 3.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 1.5, 3.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 2.5, 3.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 3.5, 3.5))); // SE -> NE Edge - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 3.5, 2.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 3.5, 1.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 3.5, 0.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 3.5, -0.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 3.5, -1.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 3.5, -2.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 3.5, -3.5))); // NE -> NW Edge - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 2.5, -3.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 1.5, -3.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 0.5, -3.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-0.5, -3.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-1.5, -3.5))); - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-2.5, -3.5))); // NW - 1 (closed) - - t += tn * (layerCount - 3) / ( denom * 28.0 ); // weight layer 4 - } - } - } - - #if 0 - if(t.w == 0.0){ - discard; // discard freezes NV tegra2 compiler - } - #endif - - color = t.rgb; - alpha = gcu_Alpha * t.a; diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_flipquad.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_flipquad.glsl index b5c1494f8..3e74fb9a6 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_flipquad.glsl +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_flipquad.glsl @@ -1,9 +1,9 @@ // Pass-2: AA on Texture - // Note: gcv_TexCoord is in center of sample pixels, origin is bottom left! + // Note: gcv_FboTexCoord is in center of sample pixels, origin is bottom left! - float sampleCount = gcu_TextureSize.z; - vec2 psize = 1.0 / gcu_TextureSize.xy; // pixel size + float sampleCount = gcu_FboTexSize.z; + vec2 psize = 1.0 / gcu_FboTexSize.xy; // pixel size // Just poles (NW, SW, ..) float edge1H = sampleCount / 2.0; @@ -14,20 +14,20 @@ vec2 modPos = mod(normFragCoord, 2.0); float orient = mod(modPos.x + modPos.y, 2.0); // mirrored on all odd columns, alternating each row (checker-board pattern) - vec2 texCoord = gcv_TexCoord.st; + vec2 texCoord = gcv_FboTexCoord.st; vec4 t; if( 0.0 == orient ) { // SWIPE LEFT -> RIGHT - t = GetSample(gcu_TextureUnit, texCoord, psize, -edge1H, edgeTH, 0.0, 0.0)*0.25; // upper-left [p1] - t += GetSample(gcu_TextureUnit, texCoord, psize, -edgeTH, -edge1H, 0.0, 0.0)*0.25; // lower-left [p3] - t += GetSample(gcu_TextureUnit, texCoord, psize, edgeTH, edge1H, 0.0, 0.0)*0.25; // upper-right [p2] - t += GetSample(gcu_TextureUnit, texCoord, psize, edge1H, -edgeTH, 0.0, 0.0)*0.25; // lower-right [p4] + t = GetSample(gcu_FboTexUnit, texCoord, psize, -edge1H, edgeTH, 0.0, 0.0)*0.25; // upper-left [p1] + t += GetSample(gcu_FboTexUnit, texCoord, psize, -edgeTH, -edge1H, 0.0, 0.0)*0.25; // lower-left [p3] + t += GetSample(gcu_FboTexUnit, texCoord, psize, edgeTH, edge1H, 0.0, 0.0)*0.25; // upper-right [p2] + t += GetSample(gcu_FboTexUnit, texCoord, psize, edge1H, -edgeTH, 0.0, 0.0)*0.25; // lower-right [p4] } else { - t = GetSample(gcu_TextureUnit, texCoord, psize, -edge1H, -edgeTH, 0.0, 0.0)*0.25; // lower-left [p4] - t += GetSample(gcu_TextureUnit, texCoord, psize, -edgeTH, edge1H, 0.0, 0.0)*0.25; // upper-left [p3] - t += GetSample(gcu_TextureUnit, texCoord, psize, edgeTH, -edge1H, 0.0, 0.0)*0.25; // lower-right [p2] - t += GetSample(gcu_TextureUnit, texCoord, psize, edge1H, edgeTH, 0.0, 0.0)*0.25; // upper-right [p1] + t = GetSample(gcu_FboTexUnit, texCoord, psize, -edge1H, -edgeTH, 0.0, 0.0)*0.25; // lower-left [p4] + t += GetSample(gcu_FboTexUnit, texCoord, psize, -edgeTH, edge1H, 0.0, 0.0)*0.25; // upper-left [p3] + t += GetSample(gcu_FboTexUnit, texCoord, psize, edgeTH, -edge1H, 0.0, 0.0)*0.25; // lower-right [p2] + t += GetSample(gcu_FboTexUnit, texCoord, psize, edge1H, edgeTH, 0.0, 0.0)*0.25; // upper-right [p1] } @@ -37,6 +37,5 @@ } #endif - color = t.rgb; - alpha = gcu_Alpha * t.a; + mgl_FragColor = t; diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_flipquad2.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_flipquad2.glsl index 98812861d..9e31e6bb7 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_flipquad2.glsl +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_flipquad2.glsl @@ -1,17 +1,17 @@ // Pass-2: AA on Texture - // Note: gcv_TexCoord is in center of sample pixels, origin is bottom left! + // Note: gcv_FboTexCoord is in center of sample pixels, origin is bottom left! // // Same as flipquad - but w/ rgss coordinates - float sampleCount = gcu_TextureSize.z; - vec2 psize = 1.0 / gcu_TextureSize.xy; // pixel size + float sampleCount = gcu_FboTexSize.z; + vec2 psize = 1.0 / gcu_FboTexSize.xy; // pixel size vec2 normFragCoord = gl_FragCoord.xy - vec2(0.5, 0.5); // normalize center 0.5/0.5 -> 0/0 vec2 modPos = mod(normFragCoord, 2.0); float orient = mod(modPos.x + modPos.y, 2.0); // mirrored on all odd columns, alternating each row (checker-board pattern) - vec2 texCoord = gcv_TexCoord.st; + vec2 texCoord = gcv_FboTexCoord.st; float edge1Q = ( sampleCount / 2.0 ) - 1.0; vec4 t; @@ -20,15 +20,15 @@ if( 0.0 == orient ) { // SWIPE LEFT -> RIGHT - t = GetSample(gcu_TextureUnit, texCoord, psize, -edge1Q, 0.0, -0.5, 0.5)*0.25; // upper-left [p1] - t += GetSample(gcu_TextureUnit, texCoord, psize, 0.0, -edge1Q, -0.5, -0.5)*0.25; // lower-left [p3] - t += GetSample(gcu_TextureUnit, texCoord, psize, 0.0, edge1Q, 0.5, 0.5)*0.25; // upper-right [p2] - t += GetSample(gcu_TextureUnit, texCoord, psize, edge1Q, 0.0, 0.5, -0.5)*0.25; // lower-right [p4] + t = GetSample(gcu_FboTexUnit, texCoord, psize, -edge1Q, 0.0, -0.5, 0.5)*0.25; // upper-left [p1] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, -edge1Q, -0.5, -0.5)*0.25; // lower-left [p3] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, edge1Q, 0.5, 0.5)*0.25; // upper-right [p2] + t += GetSample(gcu_FboTexUnit, texCoord, psize, edge1Q, 0.0, 0.5, -0.5)*0.25; // lower-right [p4] } else { - t = GetSample(gcu_TextureUnit, texCoord, psize, -edge1Q, 0.0, -0.5, -0.5)*0.25; // lower-left [p4] - t += GetSample(gcu_TextureUnit, texCoord, psize, 0.0, edge1Q, -0.5, 0.5)*0.25; // upper-left [p3] - t += GetSample(gcu_TextureUnit, texCoord, psize, 0.0, -edge1Q, 0.5, -0.5)*0.25; // lower-right [p2] - t += GetSample(gcu_TextureUnit, texCoord, psize, edge1Q, 0.0, 0.5, 0.5)*0.25; // upper-right [p1] + t = GetSample(gcu_FboTexUnit, texCoord, psize, -edge1Q, 0.0, -0.5, -0.5)*0.25; // lower-left [p4] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, edge1Q, -0.5, 0.5)*0.25; // upper-left [p3] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, -edge1Q, 0.5, -0.5)*0.25; // lower-right [p2] + t += GetSample(gcu_FboTexUnit, texCoord, psize, edge1Q, 0.0, 0.5, 0.5)*0.25; // upper-right [p1] } #if 0 @@ -37,6 +37,5 @@ } #endif - color = t.rgb; - alpha = gcu_Alpha * t.a; + mgl_FragColor = t; diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_flipquad3.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_flipquad3.glsl index edfbd9deb..7a2cb0358 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_flipquad3.glsl +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_flipquad3.glsl @@ -1,97 +1,103 @@ // Pass-2: AA on Texture - // Note: gcv_TexCoord is in center of sample pixels, origin is bottom left! + // Note: gcv_FboTexCoord is in center of sample pixels, origin is bottom left! // // Same as flipquad - but w/ rgss coordinates - float sampleCount = gcu_TextureSize.z; - vec2 psize = 1.0 / gcu_TextureSize.xy; // pixel size + // float sampleCount = gcu_FboTexSize.z; + vec2 psize = 1.0 / gcu_FboTexSize.xy; // pixel size vec2 normFragCoord = gl_FragCoord.xy - vec2(0.5, 0.5); // normalize center 0.5/0.5 -> 0/0 vec2 modPos = mod(normFragCoord, 2.0); float orient = mod(modPos.x + modPos.y, 2.0); // mirrored on all odd columns, alternating each row (checker-board pattern) - vec2 texCoord = gcv_TexCoord.st; + vec2 texCoord = gcv_FboTexCoord.st; vec4 t; // #define GetSample(texUnit, texCoord, psize, cx, cy, offX, offY) texture2D(texUnit, texCoord + psize * vec2(cx+offX, cy+offY)) - if( 1.0 == sampleCount ) { - t = texture2D(gcu_TextureUnit, texCoord); + #if SAMPLE_COUNT == 1 + + t = texture2D(gcu_FboTexUnit, texCoord); + + #elif SAMPLE_COUNT < 4 - } else if( 4.0 > sampleCount ) { // SampleCount 2 -> 2p const float weight = 1.0 / 2.0; - float edge = ( sampleCount / 2.0 ) - 1.0; + const float edge = ( SAMPLE_COUNT / 2.0 ) - 1.0; - t = GetSample(gcu_TextureUnit, texCoord, psize, -edge, edge, -0.5, 0.5)*weight; // center - t += GetSample(gcu_TextureUnit, texCoord, psize, edge, -edge, 0.5, -0.5)*weight; // center + t = GetSample(gcu_FboTexUnit, texCoord, psize, -edge, edge, -0.5, 0.5)*weight; // center + t += GetSample(gcu_FboTexUnit, texCoord, psize, edge, -edge, 0.5, -0.5)*weight; // center + + #elif SAMPLE_COUNT < 8 - } else if( 8.0 > sampleCount ) { // SampleCount 4 -> 4p const float weight = 1.0 / 4.0; - float edgeS4_1Q = ( sampleCount / 2.0 ) - 1.0; + const float edgeS4_1Q = ( SAMPLE_COUNT / 2.0 ) - 1.0; if( 0.0 == orient ) { // SWIPE LEFT -> RIGHT - t = GetSample(gcu_TextureUnit, texCoord, psize, -edgeS4_1Q, 0.0, -0.5, 0.5)*weight; // upper-left [p1] - t += GetSample(gcu_TextureUnit, texCoord, psize, 0.0, -edgeS4_1Q, -0.5, -0.5)*weight; // lower-left [p3] - t += GetSample(gcu_TextureUnit, texCoord, psize, 0.0, edgeS4_1Q, 0.5, 0.5)*weight; // upper-right [p2] - t += GetSample(gcu_TextureUnit, texCoord, psize, edgeS4_1Q, 0.0, 0.5, -0.5)*weight; // lower-right [p4] + t = GetSample(gcu_FboTexUnit, texCoord, psize, -edgeS4_1Q, 0.0, -0.5, 0.5)*weight; // upper-left [p1] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, -edgeS4_1Q, -0.5, -0.5)*weight; // lower-left [p3] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, edgeS4_1Q, 0.5, 0.5)*weight; // upper-right [p2] + t += GetSample(gcu_FboTexUnit, texCoord, psize, edgeS4_1Q, 0.0, 0.5, -0.5)*weight; // lower-right [p4] } else { - t = GetSample(gcu_TextureUnit, texCoord, psize, -edgeS4_1Q, 0.0, -0.5, -0.5)*weight; // lower-left [p4] - t += GetSample(gcu_TextureUnit, texCoord, psize, 0.0, edgeS4_1Q, -0.5, 0.5)*weight; // upper-left [p3] - t += GetSample(gcu_TextureUnit, texCoord, psize, 0.0, -edgeS4_1Q, 0.5, -0.5)*weight; // lower-right [p2] - t += GetSample(gcu_TextureUnit, texCoord, psize, edgeS4_1Q, 0.0, 0.5, 0.5)*weight; // upper-right [p1] + t = GetSample(gcu_FboTexUnit, texCoord, psize, -edgeS4_1Q, 0.0, -0.5, -0.5)*weight; // lower-left [p4] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, edgeS4_1Q, -0.5, 0.5)*weight; // upper-left [p3] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, -edgeS4_1Q, 0.5, -0.5)*weight; // lower-right [p2] + t += GetSample(gcu_FboTexUnit, texCoord, psize, edgeS4_1Q, 0.0, 0.5, 0.5)*weight; // upper-right [p1] } - } else { + + #else + // SampleCount 8 -> 16p const float weight = 1.0 / 16.0; const float edgeS4_1Q = 1.0; if( 0.0 == orient ) { // SWIPE LEFT -> RIGHT - t = GetSample(gcu_TextureUnit, texCoord, psize, -edgeS4_1Q, 0.0, -2.0-0.5, -2.0+0.5)*weight; // upper-left [p1] - t += GetSample(gcu_TextureUnit, texCoord, psize, 0.0, -edgeS4_1Q, -2.0-0.5, -2.0-0.5)*weight; // lower-left [p3] - t += GetSample(gcu_TextureUnit, texCoord, psize, 0.0, edgeS4_1Q, -2.0-0.5, -2.0-0.5)*weight; // upper-right [p2] - t += GetSample(gcu_TextureUnit, texCoord, psize, edgeS4_1Q, 0.0, -2.0-0.5, -2.0-0.5)*weight; // lower-right [p4] - - t += GetSample(gcu_TextureUnit, texCoord, psize, -edgeS4_1Q, 0.0, -2.0-0.5, 2.0-0.5)*weight; // lower-left [p4] - t += GetSample(gcu_TextureUnit, texCoord, psize, 0.0, edgeS4_1Q, -2.0-0.5, 2.0+0.5)*weight; // upper-left [p3] - t += GetSample(gcu_TextureUnit, texCoord, psize, 0.0, -edgeS4_1Q, -2.0+0.5, 2.0-0.5)*weight; // lower-right [p2] - t += GetSample(gcu_TextureUnit, texCoord, psize, edgeS4_1Q, 0.0, -2.0+0.5, 2.0+0.5)*weight; // upper-right [p1] - - t += GetSample(gcu_TextureUnit, texCoord, psize, -edgeS4_1Q, 0.0, 2.0-0.5, -2.0-0.5)*weight; // lower-left [p4] - t += GetSample(gcu_TextureUnit, texCoord, psize, 0.0, edgeS4_1Q, 2.0-0.5, -2.0+0.5)*weight; // upper-left [p3] - t += GetSample(gcu_TextureUnit, texCoord, psize, 0.0, -edgeS4_1Q, 2.0+0.5, -2.0-0.5)*weight; // lower-right [p2] - t += GetSample(gcu_TextureUnit, texCoord, psize, edgeS4_1Q, 0.0, 2.0+0.5, -2.0+0.5)*weight; // upper-right [p1] - - t += GetSample(gcu_TextureUnit, texCoord, psize, -edgeS4_1Q, 0.0, 2.0-0.5, 2.0+0.5)*weight; // upper-left [p1] - t += GetSample(gcu_TextureUnit, texCoord, psize, 0.0, -edgeS4_1Q, 2.0-0.5, 2.0-0.5)*weight; // lower-left [p3] - t += GetSample(gcu_TextureUnit, texCoord, psize, 0.0, edgeS4_1Q, 2.0-0.5, 2.0-0.5)*weight; // upper-right [p2] - t += GetSample(gcu_TextureUnit, texCoord, psize, edgeS4_1Q, 0.0, 2.0-0.5, 2.0-0.5)*weight; // lower-right [p4] + t = GetSample(gcu_FboTexUnit, texCoord, psize, -edgeS4_1Q, 0.0, -2.0-0.5, -2.0+0.5)*weight; // upper-left [p1] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, -edgeS4_1Q, -2.0-0.5, -2.0-0.5)*weight; // lower-left [p3] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, edgeS4_1Q, -2.0-0.5, -2.0-0.5)*weight; // upper-right [p2] + t += GetSample(gcu_FboTexUnit, texCoord, psize, edgeS4_1Q, 0.0, -2.0-0.5, -2.0-0.5)*weight; // lower-right [p4] + + t += GetSample(gcu_FboTexUnit, texCoord, psize, -edgeS4_1Q, 0.0, -2.0-0.5, 2.0-0.5)*weight; // lower-left [p4] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, edgeS4_1Q, -2.0-0.5, 2.0+0.5)*weight; // upper-left [p3] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, -edgeS4_1Q, -2.0+0.5, 2.0-0.5)*weight; // lower-right [p2] + t += GetSample(gcu_FboTexUnit, texCoord, psize, edgeS4_1Q, 0.0, -2.0+0.5, 2.0+0.5)*weight; // upper-right [p1] + + t += GetSample(gcu_FboTexUnit, texCoord, psize, -edgeS4_1Q, 0.0, 2.0-0.5, -2.0-0.5)*weight; // lower-left [p4] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, edgeS4_1Q, 2.0-0.5, -2.0+0.5)*weight; // upper-left [p3] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, -edgeS4_1Q, 2.0+0.5, -2.0-0.5)*weight; // lower-right [p2] + t += GetSample(gcu_FboTexUnit, texCoord, psize, edgeS4_1Q, 0.0, 2.0+0.5, -2.0+0.5)*weight; // upper-right [p1] + + t += GetSample(gcu_FboTexUnit, texCoord, psize, -edgeS4_1Q, 0.0, 2.0-0.5, 2.0+0.5)*weight; // upper-left [p1] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, -edgeS4_1Q, 2.0-0.5, 2.0-0.5)*weight; // lower-left [p3] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, edgeS4_1Q, 2.0-0.5, 2.0-0.5)*weight; // upper-right [p2] + t += GetSample(gcu_FboTexUnit, texCoord, psize, edgeS4_1Q, 0.0, 2.0-0.5, 2.0-0.5)*weight; // lower-right [p4] } else { - t = GetSample(gcu_TextureUnit, texCoord, psize, -edgeS4_1Q, 0.0, -2.0-0.5, -2.0-0.5)*weight; // lower-left [p4] - t += GetSample(gcu_TextureUnit, texCoord, psize, 0.0, edgeS4_1Q, -2.0-0.5, -2.0+0.5)*weight; // upper-left [p3] - t += GetSample(gcu_TextureUnit, texCoord, psize, 0.0, -edgeS4_1Q, -2.0+0.5, -2.0-0.5)*weight; // lower-right [p2] - t += GetSample(gcu_TextureUnit, texCoord, psize, edgeS4_1Q, 0.0, -2.0+0.5, -2.0+0.5)*weight; // upper-right [p1] - - t += GetSample(gcu_TextureUnit, texCoord, psize, -edgeS4_1Q, 0.0, -2.0-0.5, 2.0+0.5)*weight; // upper-left [p1] - t += GetSample(gcu_TextureUnit, texCoord, psize, 0.0, -edgeS4_1Q, -2.0-0.5, 2.0-0.5)*weight; // lower-left [p3] - t += GetSample(gcu_TextureUnit, texCoord, psize, 0.0, edgeS4_1Q, -2.0-0.5, 2.0-0.5)*weight; // upper-right [p2] - t += GetSample(gcu_TextureUnit, texCoord, psize, edgeS4_1Q, 0.0, -2.0-0.5, 2.0-0.5)*weight; // lower-right [p4] - - t += GetSample(gcu_TextureUnit, texCoord, psize, -edgeS4_1Q, 0.0, 2.0-0.5, -2.0+0.5)*weight; // upper-left [p1] - t += GetSample(gcu_TextureUnit, texCoord, psize, 0.0, -edgeS4_1Q, 2.0-0.5, -2.0-0.5)*weight; // lower-left [p3] - t += GetSample(gcu_TextureUnit, texCoord, psize, 0.0, edgeS4_1Q, 2.0-0.5, -2.0-0.5)*weight; // upper-right [p2] - t += GetSample(gcu_TextureUnit, texCoord, psize, edgeS4_1Q, 0.0, 2.0-0.5, -2.0-0.5)*weight; // lower-right [p4] - - t += GetSample(gcu_TextureUnit, texCoord, psize, -edgeS4_1Q, 0.0, 2.0-0.5, 2.0-0.5)*weight; // lower-left [p4] - t += GetSample(gcu_TextureUnit, texCoord, psize, 0.0, edgeS4_1Q, 2.0-0.5, 2.0+0.5)*weight; // upper-left [p3] - t += GetSample(gcu_TextureUnit, texCoord, psize, 0.0, -edgeS4_1Q, 2.0+0.5, 2.0-0.5)*weight; // lower-right [p2] - t += GetSample(gcu_TextureUnit, texCoord, psize, edgeS4_1Q, 0.0, 2.0+0.5, 2.0+0.5)*weight; // upper-right [p1] + t = GetSample(gcu_FboTexUnit, texCoord, psize, -edgeS4_1Q, 0.0, -2.0-0.5, -2.0-0.5)*weight; // lower-left [p4] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, edgeS4_1Q, -2.0-0.5, -2.0+0.5)*weight; // upper-left [p3] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, -edgeS4_1Q, -2.0+0.5, -2.0-0.5)*weight; // lower-right [p2] + t += GetSample(gcu_FboTexUnit, texCoord, psize, edgeS4_1Q, 0.0, -2.0+0.5, -2.0+0.5)*weight; // upper-right [p1] + + t += GetSample(gcu_FboTexUnit, texCoord, psize, -edgeS4_1Q, 0.0, -2.0-0.5, 2.0+0.5)*weight; // upper-left [p1] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, -edgeS4_1Q, -2.0-0.5, 2.0-0.5)*weight; // lower-left [p3] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, edgeS4_1Q, -2.0-0.5, 2.0-0.5)*weight; // upper-right [p2] + t += GetSample(gcu_FboTexUnit, texCoord, psize, edgeS4_1Q, 0.0, -2.0-0.5, 2.0-0.5)*weight; // lower-right [p4] + + t += GetSample(gcu_FboTexUnit, texCoord, psize, -edgeS4_1Q, 0.0, 2.0-0.5, -2.0+0.5)*weight; // upper-left [p1] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, -edgeS4_1Q, 2.0-0.5, -2.0-0.5)*weight; // lower-left [p3] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, edgeS4_1Q, 2.0-0.5, -2.0-0.5)*weight; // upper-right [p2] + t += GetSample(gcu_FboTexUnit, texCoord, psize, edgeS4_1Q, 0.0, 2.0-0.5, -2.0-0.5)*weight; // lower-right [p4] + + t += GetSample(gcu_FboTexUnit, texCoord, psize, -edgeS4_1Q, 0.0, 2.0-0.5, 2.0-0.5)*weight; // lower-left [p4] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, edgeS4_1Q, 2.0-0.5, 2.0+0.5)*weight; // upper-left [p3] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, -edgeS4_1Q, 2.0+0.5, 2.0-0.5)*weight; // lower-right [p2] + t += GetSample(gcu_FboTexUnit, texCoord, psize, edgeS4_1Q, 0.0, 2.0+0.5, 2.0+0.5)*weight; // upper-right [p1] } - } + + #endif #if 0 if(t.w == 0.0){ @@ -99,6 +105,5 @@ } #endif - color = t.rgb; - alpha = gcu_Alpha * t.a; + mgl_FragColor = t; diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_fxaa3.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_fxaa3.glsl index 6a2040577..015dc1b24 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_fxaa3.glsl +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_fxaa3.glsl @@ -1,24 +1,24 @@ // Pass-2: AA on Texture - // Note: gcv_TexCoord is in center of sample pixels. + // Note: gcv_FboTexCoord is in center of sample pixels. - if( gcu_TextureSize.z < 4.0 ) { + if( gcu_FboTexSize.z < 4.0 ) { // FXAA-2 const float FXAA_REDUCE_MIN = (1.0/128.0); const float FXAA_REDUCE_MUL = (1.0/8.0); const float FXAA_SPAN_MAX = 8.0; - float sampleCount = gcu_TextureSize.z; + float sampleCount = gcu_FboTexSize.z; - vec2 texCoord = gcv_TexCoord.st; + vec2 texCoord = gcv_FboTexCoord.st; const float poff = 1.0; vec2 psize = 1.0 / texCoord; // pixel size - vec3 rgbNW = texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-poff, -poff))).rgb; - vec3 rgbSW = texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-poff, poff))).rgb; - vec3 rgbSE = texture2D(gcu_TextureUnit, texCoord + psize*(vec2( poff, poff))).rgb; - vec3 rgbNE = texture2D(gcu_TextureUnit, texCoord + psize*(vec2( poff, -poff))).rgb; - vec4 rgbM = texture2D(gcu_TextureUnit, texCoord); + vec3 rgbNW = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-poff, -poff))).rgb; + vec3 rgbSW = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-poff, poff))).rgb; + vec3 rgbSE = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( poff, poff))).rgb; + vec3 rgbNE = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( poff, -poff))).rgb; + vec4 rgbM = texture2D(gcu_FboTexUnit, texCoord); const vec3 luma = vec3(0.299, 0.587, 0.114); float lumaNW = dot(rgbNW, luma); @@ -37,17 +37,17 @@ max( vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),dir * rcpDirMin) ) * psize; - vec3 rgbA = 0.5 * ( texture2D(gcu_TextureUnit, texCoord + dir * (1.0/3.0 - 0.5)).rgb + - texture2D(gcu_TextureUnit, texCoord + dir * (2.0/3.0 - 0.5)).rgb ); - vec3 rgbB = rgbA * 0.5 + 0.25 * ( texture2D(gcu_TextureUnit, texCoord + (dir * - 0.5)).rgb + - texture2D(gcu_TextureUnit, texCoord + (dir * 0.5)).rgb ); + vec3 rgbA = 0.5 * ( texture2D(gcu_FboTexUnit, texCoord + dir * (1.0/3.0 - 0.5)).rgb + + texture2D(gcu_FboTexUnit, texCoord + dir * (2.0/3.0 - 0.5)).rgb ); + vec3 rgbB = rgbA * 0.5 + 0.25 * ( texture2D(gcu_FboTexUnit, texCoord + (dir * - 0.5)).rgb + + texture2D(gcu_FboTexUnit, texCoord + (dir * 0.5)).rgb ); float lumaB = dot(rgbB, luma); if((lumaB < lumaMin) || (lumaB > lumaMax)) { - color = rgbA; + mgl_FragColor.rgb = rgbA; } else { - color = rgbB; + mgl_FragColor.rgb = rgbB; } - alpha = gcu_Alpha * rgbM.a; // mix(0.0, gcu_Alpha, rgbM.a); // t.a one of [ 0.0, 1.0 ] + mgl_FragColor.a = gcu_Alpha * rgbM.a; // mix(0.0, gcu_Alpha, rgbM.a); // t.a one of [ 0.0, 1.0 ] } else { #include curverenderer01-pass2-vbaa_poles_equalweight.glsl diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_poles_bilin1.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_poles_bilin1.glsl index 08475317e..d634c1f9b 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_poles_bilin1.glsl +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_poles_bilin1.glsl @@ -1,11 +1,11 @@ // Pass-2: AA on Texture - // Note: gcv_TexCoord is in center of sample pixels. + // Note: gcv_FboTexCoord is in center of sample pixels. - vec2 texCoord = gcv_TexCoord.st; + vec2 texCoord = gcv_FboTexCoord.st; - float sampleCount = gcu_TextureSize.z; - vec2 tsize = gcu_TextureSize.xy; // tex size - vec2 psize = 1.0 / gcu_TextureSize.xy; // pixel size + float sampleCount = gcu_FboTexSize.z; + vec2 tsize = gcu_FboTexSize.xy; // tex size + vec2 psize = 1.0 / gcu_FboTexSize.xy; // pixel size // mix(x,y,a): x*(1-a) + y*a // @@ -31,10 +31,10 @@ vec4 t, p1, p2, p3, p4; // Layer-1: SampleCount 2 -> 4x - p1 = texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-0.5, -0.5))); // NW - p2 = texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-0.5, 0.5))); // SW - p3 = texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 0.5, 0.5))); // SE - p4 = texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 0.5, -0.5))); // NE + p1 = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-0.5, -0.5))); // NW + p2 = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-0.5, 0.5))); // SW + p3 = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 0.5, 0.5))); // SE + p4 = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 0.5, -0.5))); // NE p1 = mix( p1, p4, uv_ratio.x); p2 = mix( p2, p3, uv_ratio.x); @@ -44,10 +44,10 @@ if( sampleCount > 2.0 ) { // Layer-2: SampleCount 4 -> +4x = 8p - p1 = texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-1.5, -1.5))); // NW - p2 = texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-1.5, 1.5))); // SW - p3 = texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 1.5, 1.5))); // SE - p4 = texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 1.5, -1.5))); // NE + p1 = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-1.5, -1.5))); // NW + p2 = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-1.5, 1.5))); // SW + p3 = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 1.5, 1.5))); // SE + p4 = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 1.5, -1.5))); // NE p1 = mix( p1, p4, uv_ratio.x); p2 = mix( p2, p3, uv_ratio.x); @@ -56,10 +56,10 @@ if( sampleCount > 4.0 ) { // Layer-3: SampleCount 6 -> +4 = 12p - p1 = texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-2.5, -2.5))); // NW - p2 = texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-2.5, 2.5))); // SW - p3 = texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 2.5, 2.5))); // SE - p4 = texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 2.5, -2.5))); // NE + p1 = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-2.5, -2.5))); // NW + p2 = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-2.5, 2.5))); // SW + p3 = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 2.5, 2.5))); // SE + p4 = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 2.5, -2.5))); // NE p1 = mix( p1, p4, uv_ratio.x); p2 = mix( p2, p3, uv_ratio.x); @@ -68,10 +68,10 @@ if( sampleCount > 6.0 ) { // Layer-4: SampleCount 8 -> +4 = 16p - p1 = texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-3.5, -3.5))); // NW - p2 = texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-3.5, 3.5))); // SW - p3 = texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 3.5, 3.5))); // SE - p4 = texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 3.5, -3.5))); // NE + p1 = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-3.5, -3.5))); // NW + p2 = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-3.5, 3.5))); // SW + p3 = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 3.5, 3.5))); // SE + p4 = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 3.5, -3.5))); // NE p1 = mix( p1, p4, uv_ratio.x); p2 = mix( p2, p3, uv_ratio.x); @@ -88,5 +88,4 @@ } #endif - color = t.rgb; - alpha = gcu_Alpha * t.a; + mgl_FragColor = t; diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_poles_equalweight.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_poles_equalweight.glsl deleted file mode 100644 index a03294034..000000000 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_poles_equalweight.glsl +++ /dev/null @@ -1,50 +0,0 @@ - - // Pass-2: AA on Texture - // Note: gcv_TexCoord is in center of sample pixels. - - float sampleCount = gcu_TextureSize.z; - vec2 psize = 1.0 / gcu_TextureSize.xy; // pixel size - - // Just poles (NW, SW, ..) - float sample_weight = 1 / ( 2 * sampleCount ); - - vec2 texCoord = gcv_TexCoord.st; - - vec4 t; - - // SampleCount 2 -> 4x - t = texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-0.5, -0.5)))*sample_weight; // NW - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-0.5, 0.5)))*sample_weight; // SW - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 0.5, 0.5)))*sample_weight; // SE - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 0.5, -0.5)))*sample_weight; // NE - if( sampleCount > 2.0 ) { - // SampleCount 4 -> +4 = 8p - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-1.5, -1.5)))*sample_weight; // NW - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-1.5, 1.5)))*sample_weight; // SW - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 1.5, 1.5)))*sample_weight; // SE - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 1.5, -1.5)))*sample_weight; // NE - - if( sampleCount > 4.0 ) { - // SampleCount 6 -> +4 = 12p - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-2.5, -2.5)))*sample_weight; // NW - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-2.5, 2.5)))*sample_weight; // SW - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 2.5, 2.5)))*sample_weight; // SE - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 2.5, -2.5)))*sample_weight; // NE - if( sampleCount > 6.0 ) { - // SampleCount 8 -> +4 = 16p - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-3.5, -3.5)))*sample_weight; // NW - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-3.5, 3.5)))*sample_weight; // SW - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 3.5, 3.5)))*sample_weight; // SE - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 3.5, -3.5)))*sample_weight; // NE - } - } - } - #if 0 - if(t.w == 0.0){ - discard; // discard freezes NV tegra2 compiler - } - #endif - - color = t.rgb; - alpha = gcu_Alpha * t.a; - diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_poles_propweight1.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_poles_propweight1.glsl deleted file mode 100644 index d63dda7cc..000000000 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_poles_propweight1.glsl +++ /dev/null @@ -1,66 +0,0 @@ - // Pass-2: AA on Texture - // Note: gcv_TexCoord is in center of sample pixels. - - float sampleCount = gcu_TextureSize.z; - vec2 psize = 1.0 / gcu_TextureSize.xy; // pixel size - - // Just poles (NW, SW, ..) - float pixelCount = 2 * sampleCount; - - // sampleCount [0, 1, 3, 5, 7] are undefined! - float layerCount = ( sampleCount / 2.0 ); - - // sum of all integer [layerCount .. 1] -> Gauss - float denom = ( layerCount / 2.0 ) * ( layerCount + 1.0 ); - - vec2 texCoord = gcv_TexCoord.st; - - vec4 t; - - // Layer-1: SampleCount 2 -> 4x - t = texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-0.5, -0.5))); // NW - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-0.5, 0.5))); // SW - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 0.5, 0.5))); // SE - t += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 0.5, -0.5))); // NE - - t *= (layerCount - 0.0) / ( denom * 4.0 ); // weight layer 1 - - if( sampleCount > 2.0 ) { - // Layer-2: SampleCount 4 -> +4x = 8p - vec4 tn = vec4(0); - tn = texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-1.5, -1.5))); // NW - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-1.5, 1.5))); // SW - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 1.5, 1.5))); // SE - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 1.5, -1.5))); // NE - - t += tn * (layerCount - 1) / ( denom * 4.0 ); // weight layer 2 - - if( sampleCount > 4.0 ) { - // Layer-3: SampleCount 6 -> +4 = 12p - tn = texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-2.5, -2.5))); // NW - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-2.5, 2.5))); // SW - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 2.5, 2.5))); // SE - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 2.5, -2.5))); // NE - - t += tn * (layerCount - 2) / ( denom * 4.0 ); // weight layer 3 - - if( sampleCount > 6.0 ) { - // Layer-4: SampleCount 8 -> +4 = 16p - tn = texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-3.5, -3.5))); // NW - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2(-3.5, 3.5))); // SW - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 3.5, 3.5))); // SE - tn += texture2D(gcu_TextureUnit, texCoord + psize*(vec2( 3.5, -3.5))); // NE - - t += tn * (layerCount - 3) / ( denom * 4.0 ); // weight layer 4 - } - } - } - - #if 0 - if(t.w == 0.0){ - discard; // discard freezes NV tegra2 compiler - } - #endif - - color = t.rgb; - alpha = gcu_Alpha * t.a; diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_polesequal.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_polesequal.glsl new file mode 100644 index 000000000..0e8b6f161 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_polesequal.glsl @@ -0,0 +1,49 @@ + + // Pass-2: AA on Texture + // Note: gcv_FboTexCoord is in center of sample pixels. + + float sampleCount = gcu_FboTexSize.z; + vec2 psize = 1.0 / gcu_FboTexSize.xy; // pixel size + + // Just poles (NW, SW, ..) + float sample_weight = 1 / ( 2 * sampleCount ); + + vec2 texCoord = gcv_FboTexCoord.st; + + vec4 t; + + // SampleCount 2 -> 4x + t = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-0.5, -0.5)))*sample_weight; // NW + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-0.5, 0.5)))*sample_weight; // SW + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 0.5, 0.5)))*sample_weight; // SE + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 0.5, -0.5)))*sample_weight; // NE + if( sampleCount > 2.0 ) { + // SampleCount 4 -> +4 = 8p + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-1.5, -1.5)))*sample_weight; // NW + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-1.5, 1.5)))*sample_weight; // SW + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 1.5, 1.5)))*sample_weight; // SE + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 1.5, -1.5)))*sample_weight; // NE + + if( sampleCount > 4.0 ) { + // SampleCount 6 -> +4 = 12p + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-2.5, -2.5)))*sample_weight; // NW + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-2.5, 2.5)))*sample_weight; // SW + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 2.5, 2.5)))*sample_weight; // SE + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 2.5, -2.5)))*sample_weight; // NE + if( sampleCount > 6.0 ) { + // SampleCount 8 -> +4 = 16p + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-3.5, -3.5)))*sample_weight; // NW + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-3.5, 3.5)))*sample_weight; // SW + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 3.5, 3.5)))*sample_weight; // SE + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 3.5, -3.5)))*sample_weight; // NE + } + } + } + #if 0 + if(t.w == 0.0){ + discard; // discard freezes NV tegra2 compiler + } + #endif + + mgl_FragColor = t; + diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_polesprop01.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_polesprop01.glsl new file mode 100644 index 000000000..6c263b9bd --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_polesprop01.glsl @@ -0,0 +1,65 @@ + // Pass-2: AA on Texture + // Note: gcv_FboTexCoord is in center of sample pixels. + + float sampleCount = gcu_FboTexSize.z; + vec2 psize = 1.0 / gcu_FboTexSize.xy; // pixel size + + // Just poles (NW, SW, ..) + float pixelCount = 2 * sampleCount; + + // sampleCount [0, 1, 3, 5, 7] are undefined! + float layerCount = ( sampleCount / 2.0 ); + + // sum of all integer [layerCount .. 1] -> Gauss + float denom = ( layerCount / 2.0 ) * ( layerCount + 1.0 ); + + vec2 texCoord = gcv_FboTexCoord.st; + + vec4 t; + + // Layer-1: SampleCount 2 -> 4x + t = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-0.5, -0.5))); // NW + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-0.5, 0.5))); // SW + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 0.5, 0.5))); // SE + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 0.5, -0.5))); // NE + + t *= (layerCount - 0.0) / ( denom * 4.0 ); // weight layer 1 + + if( sampleCount > 2.0 ) { + // Layer-2: SampleCount 4 -> +4x = 8p + vec4 tn = vec4(0); + tn = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-1.5, -1.5))); // NW + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-1.5, 1.5))); // SW + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 1.5, 1.5))); // SE + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 1.5, -1.5))); // NE + + t += tn * (layerCount - 1) / ( denom * 4.0 ); // weight layer 2 + + if( sampleCount > 4.0 ) { + // Layer-3: SampleCount 6 -> +4 = 12p + tn = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-2.5, -2.5))); // NW + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-2.5, 2.5))); // SW + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 2.5, 2.5))); // SE + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 2.5, -2.5))); // NE + + t += tn * (layerCount - 2) / ( denom * 4.0 ); // weight layer 3 + + if( sampleCount > 6.0 ) { + // Layer-4: SampleCount 8 -> +4 = 16p + tn = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-3.5, -3.5))); // NW + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-3.5, 3.5))); // SW + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 3.5, 3.5))); // SE + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 3.5, -3.5))); // NE + + t += tn * (layerCount - 3) / ( denom * 4.0 ); // weight layer 4 + } + } + } + + #if 0 + if(t.w == 0.0){ + discard; // discard freezes NV tegra2 compiler + } + #endif + + mgl_FragColor = t; diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_quincunx.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_quincunx.glsl index 545f1cc82..07a9adf46 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_quincunx.glsl +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_quincunx.glsl @@ -1,22 +1,22 @@ // Pass-2: AA on Texture - // Note: gcv_TexCoord is in center of sample pixels, origin is bottom left! + // Note: gcv_FboTexCoord is in center of sample pixels, origin is bottom left! - float sampleCount = gcu_TextureSize.z; - vec2 psize = 1.0 / gcu_TextureSize.xy; // pixel size + float sampleCount = gcu_FboTexSize.z; + vec2 psize = 1.0 / gcu_FboTexSize.xy; // pixel size // Just poles (NW, SW, ..) float edgeH = sampleCount / 2.0; - vec2 texCoord = gcv_TexCoord.st; + vec2 texCoord = gcv_FboTexCoord.st; vec4 t; - t = GetSample(gcu_TextureUnit, texCoord, psize, 0.0, 0.0, 0.0, 0.0)*0.5; // w1 - center - t += GetSample(gcu_TextureUnit, texCoord, psize, -edgeH, -edgeH, 0.0, 0.0)*0.125; // w2 - sharing - t += GetSample(gcu_TextureUnit, texCoord, psize, -edgeH, edgeH, 0.0, 0.0)*0.125; // w3 - edges - t += GetSample(gcu_TextureUnit, texCoord, psize, edgeH, -edgeH, 0.0, 0.0)*0.125; // w4 - w/ all pixels - t += GetSample(gcu_TextureUnit, texCoord, psize, edgeH, edgeH, 0.0, 0.0)*0.125; // w5 + t = GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, 0.0, 0.0, 0.0)*0.5; // w1 - center + t += GetSample(gcu_FboTexUnit, texCoord, psize, -edgeH, -edgeH, 0.0, 0.0)*0.125; // w2 - sharing + t += GetSample(gcu_FboTexUnit, texCoord, psize, -edgeH, edgeH, 0.0, 0.0)*0.125; // w3 - edges + t += GetSample(gcu_FboTexUnit, texCoord, psize, edgeH, -edgeH, 0.0, 0.0)*0.125; // w4 - w/ all pixels + t += GetSample(gcu_FboTexUnit, texCoord, psize, edgeH, edgeH, 0.0, 0.0)*0.125; // w5 #if 0 if(t.w == 0.0){ @@ -24,6 +24,5 @@ } #endif - color = t.rgb; - alpha = gcu_Alpha * t.a; + mgl_FragColor = t; diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_rgss.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_rgss.glsl index 804ab6013..27a5684a6 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_rgss.glsl +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_rgss.glsl @@ -1,19 +1,19 @@ // Pass-2: AA on Texture - // Note: gcv_TexCoord is in center of sample pixels, origin is bottom left! + // Note: gcv_FboTexCoord is in center of sample pixels, origin is bottom left! - float sampleCount = gcu_TextureSize.z; - vec2 psize = 1.0 / gcu_TextureSize.xy; // pixel size + float sampleCount = gcu_FboTexSize.z; + vec2 psize = 1.0 / gcu_FboTexSize.xy; // pixel size - vec2 texCoord = gcv_TexCoord.st; + vec2 texCoord = gcv_FboTexCoord.st; float edge1Q = ( sampleCount / 2.0 ) - 1.0; vec4 t; // SWIPE LEFT -> RIGHT - t = GetSample(gcu_TextureUnit, texCoord, psize, -edge1Q, 0.0, -0.5, 0.5)*0.25; // upper-left [p1] - t += GetSample(gcu_TextureUnit, texCoord, psize, 0.0, -edge1Q, -0.5, -0.5)*0.25; // lower-left [p3] - t += GetSample(gcu_TextureUnit, texCoord, psize, 0.0, edge1Q, 0.5, 0.5)*0.25; // upper-right [p2] - t += GetSample(gcu_TextureUnit, texCoord, psize, edge1Q, 0.0, 0.5, -0.5)*0.25; // lower-right [p4] + t = GetSample(gcu_FboTexUnit, texCoord, psize, -edge1Q, 0.0, -0.5, 0.5)*0.25; // upper-left [p1] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, -edge1Q, -0.5, -0.5)*0.25; // lower-left [p3] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, edge1Q, 0.5, 0.5)*0.25; // upper-right [p2] + t += GetSample(gcu_FboTexUnit, texCoord, psize, edge1Q, 0.0, 0.5, -0.5)*0.25; // lower-right [p4] #if 0 if(t.w == 0.0){ @@ -21,6 +21,5 @@ } #endif - color = t.rgb; - alpha = gcu_Alpha * t.a; + mgl_FragColor = t; diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2.vp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2.vp new file mode 100644 index 000000000..64857c9ce --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2.vp @@ -0,0 +1,17 @@ +//Copyright 2010 JogAmp Community. All rights reserved. + +#if __VERSION__ >= 130 + #define attribute in + #define varying out +#endif + +#include uniforms.glsl +#include attributes.glsl +#include varyings.glsl + +void main(void) +{ + // gl_Position = gcu_PMVMatrix01[0] * gcu_PMVMatrix01[1] * vec4(gca_FboVertices, 1); + gl_Position = gcu_PMVMatrix01[0] * gcu_PMVMatrix01[1] * gca_FboVertices; + gcv_FboTexCoord = gca_FboTexCoords; +} diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-segment-head.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-segment-head.fp new file mode 100644 index 000000000..74a1dea4e --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-segment-head.fp @@ -0,0 +1,22 @@ +//Copyright 2010 JogAmp Community. All rights reserved. + +// +// 2-pass shader w/o weight +// + +#if __VERSION__ >= 130 + #define varying in + out vec4 mgl_FragColor; + #define texture2D texture +#else + #define mgl_FragColor gl_FragColor +#endif + +#include uniforms.glsl +#include varyings.glsl + +#define GetSample(texUnit, texCoord, psize, cx, cy, offX, offY) texture2D(texUnit, texCoord + psize * vec2(cx+offX, cy+offY)) + +void main (void) +{ + 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 new file mode 100644 index 000000000..7598c23f8 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-single.vp @@ -0,0 +1,30 @@ +//Copyright 2010 JogAmp Community. All rights reserved. + +#if __VERSION__ >= 130 + #define attribute in + #define varying out +#endif + +#include uniforms.glsl +#include attributes.glsl +#include varyings.glsl + +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; +#else + if( gcv_CurveParams.x <= -10.0 ) { + // vec4 tc = gcu_PMVMatrix01[0] * gcu_PMVMatrix01[1] * vec4(gca_CurveParams.xy, gca_Vertices.z, 1); + // gcv_CurveParams = vec3(tc.xy, gca_CurveParams.z); + gcv_CurveParam = gca_CurveParams; + } else { + gcv_CurveParam = gca_CurveParams; + } +#endif +#ifdef USE_COLOR_CHANNEL + gcv_Color = gca_Colors; +#endif +} diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.vp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.vp deleted file mode 100644 index 5ab82ad40..000000000 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.vp +++ /dev/null @@ -1,23 +0,0 @@ -//Copyright 2010 JogAmp Community. All rights reserved. - -#if __VERSION__ >= 130 - #define attribute in - #define varying out -#endif - -#include uniforms.glsl -#include attributes.glsl -#include varyings.glsl - -void main(void) -{ - // gl_Position = gcu_PMVMatrix[0] * gcu_PMVMatrix[1] * vec4(gca_Vertices, 1); - gl_Position = gcu_PMVMatrix[0] * gcu_PMVMatrix[1] * gca_Vertices; - if( gcv_TexCoord.x <= -10.0 ) { - // vec4 tc = gcu_PMVMatrix[0] * gcu_PMVMatrix[1] * vec4(gca_TexCoords.xy, gca_Vertices.z, 1); - // gcv_TexCoord = vec3(tc.xy, gca_TexCoords.z); - gcv_TexCoord = gca_TexCoords; - } else { - gcv_TexCoord = gca_TexCoords; - } -} 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 92e78d5de..848c26819 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl @@ -2,14 +2,17 @@ #ifndef uniforms_glsl #define uniforms_glsl -uniform mat4 gcu_PMVMatrix[3]; // P, Mv, and Mvi -uniform vec3 gcu_ColorStatic; -uniform float gcu_Alpha; +uniform mat4 gcu_PMVMatrix01[3]; // P, Mv, and Mvi +uniform vec4 gcu_ColorStatic; uniform float gcu_Weight; -uniform sampler2D gcu_TextureUnit; -/** 3rd component: 0: pass-1, >0: pass-2, sampleCount */ -uniform vec3 gcu_TextureSize; +uniform mat4 gcu_PMVMatrix02[3]; // P, Mv, and Mvi +uniform sampler2D gcu_FboTexUnit; + +/** + * .x .y : texture-, fbo- or screen-size + */ +uniform vec2 gcu_FboTexSize; // const int MAX_TEXTURE_UNITS = 8; // <= gl_MaxTextureImageUnits // const int MAX_LIGHTS = 8; 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 17f118bc8..2054c9c21 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/varyings.glsl +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/varyings.glsl @@ -2,8 +2,13 @@ #ifndef varyings_glsl #define varyings_glsl -//varying vec4 gcv_FrontColor; -varying vec3 gcv_TexCoord; +varying vec3 gcv_CurveParam; + +varying vec2 gcv_FboTexCoord; + +#ifdef USE_COLOR_CHANNEL + varying vec4 gcv_Color; +#endif #endif // varyings_glsl diff --git a/src/jogl/classes/jogamp/graph/curve/tess/CDTriangulator2D.java b/src/jogl/classes/jogamp/graph/curve/tess/CDTriangulator2D.java index ad01c24fa..d2cfa42a1 100644 --- a/src/jogl/classes/jogamp/graph/curve/tess/CDTriangulator2D.java +++ b/src/jogl/classes/jogamp/graph/curve/tess/CDTriangulator2D.java @@ -54,7 +54,8 @@ public class CDTriangulator2D implements Triangulator { private final ArrayList<Loop> loops = new ArrayList<Loop>(); - private int maxTriID = 0; + private int addedVerticeCount; + private int maxTriID; /** Constructor for a new Delaunay triangulator @@ -66,10 +67,17 @@ public class CDTriangulator2D implements Triangulator { @Override public final void reset() { maxTriID = 0; + addedVerticeCount = 0; loops.clear(); } @Override + public final int getAddedVerticeCount() { + return addedVerticeCount; + } + + + @Override public final void addCurve(final List<Triangle> sink, final Outline polyline, final float sharpness) { Loop loop = null; @@ -164,6 +172,7 @@ public class CDTriangulator2D implements Triangulator { final Vertex v0 = gv0.getPoint().clone(); final Vertex v2 = gv2.getPoint().clone(); final Vertex v1 = gv1.getPoint().clone(); + addedVerticeCount += 3; final boolean[] boundaryVertices = { true, true, true }; gv0.setBoundaryContained(true); diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java index a75c5e02c..cd48cd8d6 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java @@ -34,11 +34,14 @@ import jogamp.graph.font.typecast.ot.table.CmapIndexEntry; import jogamp.graph.font.typecast.ot.table.CmapTable; import jogamp.graph.font.typecast.ot.table.HdmxTable; import jogamp.graph.font.typecast.ot.table.ID; +import jogamp.graph.geom.plane.AffineTransform; import com.jogamp.common.util.IntObjectHashMap; import com.jogamp.graph.curve.OutlineShape; +import com.jogamp.graph.curve.Region; import com.jogamp.graph.font.Font; import com.jogamp.graph.font.FontFactory; +import com.jogamp.graph.font.Font.Glyph; import com.jogamp.graph.geom.SVertex; import com.jogamp.graph.geom.Vertex; import com.jogamp.opengl.math.geom.AABBox; @@ -203,6 +206,8 @@ class TypecastFont implements Font { if(DEBUG) { System.err.println("New glyph: " + (int)symbol + " ( " + symbol +" ) -> " + code + ", contours " + glyph.getPointCount() + ": " + shape); } + glyph.clearPointData(); + final HdmxTable hdmx = font.getHdmxTable(); if (null!= result && null != hdmx) { /*if(DEBUG) { @@ -238,7 +243,7 @@ class TypecastFont implements Font { } @Override - public float getStringWidth(CharSequence string, float pixelSize) { + public float getMetricWidth(CharSequence string, float pixelSize) { float width = 0; final int len = string.length(); for (int i=0; i< len; i++) { @@ -254,7 +259,7 @@ class TypecastFont implements Font { } @Override - public float getStringHeight(CharSequence string, float pixelSize) { + public float getMetricHeight(CharSequence string, float pixelSize) { int height = 0; for (int i=0; i<string.length(); i++) { @@ -269,16 +274,16 @@ class TypecastFont implements Font { } @Override - public AABBox getStringBounds(CharSequence string, float pixelSize) { + public AABBox getMetricBounds(CharSequence string, float pixelSize) { if (string == null) { return new AABBox(); } + final int charCount = string.length(); final float lineHeight = getLineHeight(pixelSize); - float totalHeight = 0; float totalWidth = 0; float curLineWidth = 0; - for (int i=0; i<string.length(); i++) { + for (int i=0; i<charCount; i++) { char character = string.charAt(i); if (character == '\n') { totalWidth = Math.max(curLineWidth, totalWidth); @@ -295,6 +300,51 @@ class TypecastFont implements Font { } return new AABBox(0, 0, 0, totalWidth, totalHeight,0); } + @Override + public AABBox getPointsBounds(final AffineTransform transform, CharSequence string, float pixelSize) { + if (string == null) { + return new AABBox(); + } + final int charCount = string.length(); + final float lineHeight = getLineHeight(pixelSize); + final float scale = getMetrics().getScale(pixelSize); + final AffineTransform t = null != transform ? new AffineTransform(transform) : new AffineTransform(); + final AABBox tbox = new AABBox(); + final AABBox res = new AABBox(); + + float y = 0; + float advanceTotal = 0; + + for(int i=0; i< charCount; i++) { + final char character = string.charAt(i); + if( '\n' == character ) { + y -= lineHeight; + advanceTotal = 0; + } else if (character == ' ') { + advanceTotal += getAdvanceWidth(Glyph.ID_SPACE, pixelSize); + } else { + // reset transform + if( null != transform ) { + t.setTransform(transform); + } else { + t.setToIdentity(); + } + t.translate(advanceTotal, y); + t.scale(scale, scale); + tbox.reset(); + + final Font.Glyph glyph = getGlyph(character); + res.resize(t.transform(glyph.getBBox(), tbox)); + + final OutlineShape glyphShape = glyph.getShape(); + if( null == glyphShape ) { + continue; + } + advanceTotal += glyph.getAdvance(pixelSize, true); + } + } + return res; + } @Override final public int getNumGlyphs() { diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java index c540f7ddb..b6e9925d4 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java @@ -84,7 +84,7 @@ public class TypecastRenderer { final OutlineShape shape = new OutlineShape(vertexFactory); buildShapeImpl(shape, symbol, glyph, vertexFactory); - shape.closeLastOutline(false); + shape.setIsQuadraticNurbs(); return shape; } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/OTGlyph.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/OTGlyph.java index e0d652bd4..270507fec 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/OTGlyph.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/OTGlyph.java @@ -102,6 +102,10 @@ public class OTGlyph { } } + public void clearPointData() { + _points = null; + } + public AABBox getBBox() { return _bbox; } @@ -119,13 +123,7 @@ public class OTGlyph { } public int getPointCount() { - return _points.length; - } - - /** - * Resets the glyph to the TrueType table settings - */ - public void reset() { + return null != _points ? _points.length : 0; } /** diff --git a/src/jogl/classes/jogamp/graph/geom/plane/AffineTransform.java b/src/jogl/classes/jogamp/graph/geom/plane/AffineTransform.java index c6efae883..04b9d3bcd 100644 --- a/src/jogl/classes/jogamp/graph/geom/plane/AffineTransform.java +++ b/src/jogl/classes/jogamp/graph/geom/plane/AffineTransform.java @@ -319,24 +319,24 @@ public class AffineTransform implements Cloneable { return t; } - public final void translate(float mx, float my) { - concatenate(AffineTransform.getTranslateInstance(mx, my)); + public final AffineTransform translate(float mx, float my) { + return concatenate(AffineTransform.getTranslateInstance(mx, my)); } - public final void scale(float scx, float scy) { - concatenate(AffineTransform.getScaleInstance(scx, scy)); + public final AffineTransform scale(float scx, float scy) { + return concatenate(AffineTransform.getScaleInstance(scx, scy)); } - public final void shear(float shx, float shy) { - concatenate(AffineTransform.getShearInstance(shx, shy)); + public final AffineTransform shear(float shx, float shy) { + return concatenate(AffineTransform.getShearInstance(shx, shy)); } - public final void rotate(float angle) { - concatenate(AffineTransform.getRotateInstance(angle)); + public final AffineTransform rotate(float angle) { + return concatenate(AffineTransform.getRotateInstance(angle)); } - public final void rotate(float angle, float px, float py) { - concatenate(AffineTransform.getRotateInstance(angle, px, py)); + public final AffineTransform rotate(float angle, float px, float py) { + return concatenate(AffineTransform.getRotateInstance(angle, px, py)); } /** |