summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-02-27 10:53:06 +0100
committerSven Gothel <[email protected]>2014-02-27 10:53:06 +0100
commit2cafc01f08f9ab05748be6eeb82c417de38b31f7 (patch)
tree8fd55b032fa2585f75517287506604ca739bfed9
parent073ac5ab63af792d8468d8bf074b982f7c44ef33 (diff)
Bug 801: Graph TextRenderer Cleanup Part-3: Region.addOutlineShape(..) Push GL data directly incl. all index validations
Region: - Remove redundant methods to make OutlineShape the unique source. - addVertex(..) - addTriangles(..) - Perform all index validations in addOutlineShape(..) - Push OutlineShape's vertex data and it's triangle indices directly to VBO. GLRegion: Add clear(..) method, allowing to clear the region for new data, i.e. OutlineShapes
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java3
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/Region.java246
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java13
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderUtil.java31
-rw-r--r--src/jogl/classes/com/jogamp/graph/geom/Triangle.java16
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java108
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java101
-rw-r--r--src/jogl/classes/jogamp/graph/geom/plane/AffineTransform.java32
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener02.java2
9 files changed, 236 insertions, 316 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java b/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java
index ffaaca91c..50bd79e1c 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java
@@ -560,8 +560,6 @@ public class OutlineShape implements Comparable<OutlineShape> {
* Should always be called <i>after</i> {@link #getTriangles(VerticesState)},
* since the latter will mark all cached vertices dirty!
* </p>
- * FIXME: Add memory optimization, i.e. VBO layout
- * FIXME: Add Runnable task-per-vertices !
*/
public final ArrayList<Vertex> getVertices() {
final boolean updated;
@@ -604,7 +602,6 @@ public class OutlineShape implements Comparable<OutlineShape> {
* </p>
* @return an arraylist of triangles representing the filled region
* which is produced by the combination of the outlines
- * FIXME: Add memory optimization, i.e. VBO layout
*/
public ArrayList<Triangle> getTriangles(VerticesState destinationType) {
final boolean updated;
diff --git a/src/jogl/classes/com/jogamp/graph/curve/Region.java b/src/jogl/classes/com/jogamp/graph/curve/Region.java
index 79ec305d1..359c63c80 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/Region.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/Region.java
@@ -51,32 +51,33 @@ public abstract class Region {
public static final boolean DEBUG = Debug.debug("graph.curve");
public static final boolean DEBUG_INSTANCE = Debug.debug("graph.curve.instance");
- /** View based Anti-Aliasing, A Two pass region rendering, slower and more
+ /**
+ * View based Anti-Aliasing, A Two pass region rendering, slower and more
* resource hungry (FBO), but AA is perfect. Otherwise the default fast one
- * pass MSAA region rendering is being used. */
+ * pass MSAA region rendering is being used.
+ */
public static final int VBAA_RENDERING_BIT = 1 << 0;
- /** Use non uniform weights [0.0 .. 1.9] for curve region rendering.
+ /**
+ * Use non uniform weights [0.0 .. 1.9] for curve region rendering.
* Otherwise the default weight 1.0 for uniform curve region rendering is
- * being applied. */
+ * being applied.
+ */
public static final int VARIABLE_CURVE_WEIGHT_BIT = 1 << 1;
public static final int TWO_PASS_DEFAULT_TEXTURE_UNIT = 0;
private final int renderModes;
private boolean dirty = true;
- protected int numVertices = 0;
+ private int numVertices = 0;
protected final AABBox box = new AABBox();
- /** FIXME: Think about a rendering storage optimization (VBO ... )! */
- protected ArrayList<Triangle> triangles = new ArrayList<Triangle>();
- /** FIXME: Think about a rendering storage optimization (VBO ... )! */
- protected ArrayList<Vertex> vertices = new ArrayList<Vertex>();
public static boolean isVBAA(int renderModes) {
return 0 != (renderModes & Region.VBAA_RENDERING_BIT);
}
- /** Check if render mode capable of non uniform weights
+ /**
+ * Check if render mode capable of non uniform weights
*
* @param renderModes
* bit-field of modes, e.g.
@@ -109,165 +110,132 @@ public abstract class Region {
this.renderModes = regionRenderModes;
}
- /** Get current Models
- *
- * @return bit-field of render modes */
+ /**
+ * Returns true, if the implementation uses indices to render the vertices,
+ * otherwise false.
+ * <p>
+ * Impacts {@link #validateIndices()} and {@link #addOutlineShape(OutlineShape, AffineTransform)} ..,
+ * i.e. defines unique indices if this method returns true.
+ * </p>
+ */
+ public abstract boolean usesIndices();
+
+ public abstract void pushVertex(float[] coords, float[] texParams);
+ public abstract void pushIndex(int idx);
+
+ /**
+ * Return bit-field of render modes, see {@link #create(int)}.
+ */
public final int getRenderModes() {
return renderModes;
}
-
- public final ArrayList<Triangle> getTriangles() { return triangles; }
-
- public final ArrayList<Vertex> getVertices() { return vertices; }
-
- /** Check if current Region is using VBAA
- *
- * @return true if capable of two pass rendering - VBAA */
- public boolean isVBAA() {
- return Region.isVBAA(renderModes);
+ protected void clearImpl() {
+ dirty = true;
+ numVertices = 0;
+ box.reset();
}
- /** Check if current instance uses non uniform weights
- *
- * @return true if capable of nonuniform weights */
- public boolean isNonUniformWeight() {
- return Region.isNonUniformWeight(renderModes);
+ /**
+ * Return true if capable of two pass rendering - VBAA, otherwise false.
+ */
+ public final boolean isVBAA() {
+ return isVBAA(renderModes);
}
- /** Get the current number of vertices associated with this region. This
- * number is not necessary equal to the OGL bound number of vertices.
- *
- * @return vertices count */
- public final int getNumVertices() {
- return numVertices;
+ /**
+ * Return true if capable of nonuniform weights, otherwise false.
+ */
+ public final boolean isNonUniformWeight() {
+ return Region.isNonUniformWeight(renderModes);
}
- /** Adds a list of {@link Triangle} objects to the Region These triangles are
- * to be binded to OGL objects on the next call to {@code update}
- *
- * @param tris
- * a list of triangle objects
- * @param idxOffset TODO
- *
- * @see update(GL2ES2) */
- public void addTriangles(List<Triangle> tris, AffineTransform t, int idxOffset) {
- if( true && null != t ) {
- for(int i=0; i<tris.size(); i++) {
- final Triangle t2 = tris.get(i).transform(t);
- t2.addVertexIndicesOffset(idxOffset);
- triangles.add( t2 );
- }
+ private void pushNewVertexImpl(final Vertex vertIn, final AffineTransform transform) {
+ final float[] coordsEx = new float[3];
+ 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());
} else {
- for(int i=0; i<tris.size(); i++) {
- final Triangle t2 = new Triangle( tris.get(i) );
- t2.addVertexIndicesOffset(idxOffset);
- triangles.add( t2 );
- }
- // triangles.addAll(tris);
- }
- if(DEBUG_INSTANCE) {
- System.err.println("Region.addTriangles(): tris: "+triangles.size()+", verts "+vertices.size());
+ box.resize(vertIn.getX(), vertIn.getY(), vertIn.getZ());
+ pushVertex(vertIn.getCoord(), vertIn.getTexCoord());
}
- setDirty(true);
+ numVertices++;
}
- /** Adds a {@link Vertex} object to the Region This vertex will be bound to
- * OGL objects on the next call to {@code update}
- *
- * @param vert
- * a vertex objects
- *
- * @see update(GL2ES2) */
- public void addVertex(Vertex vert, AffineTransform t) {
- final Vertex svert = null != t ? t.transform(vert, null) : vert;
- vertices.add(svert);
- numVertices++;
- assert( vertices.size() == numVertices );
- if(DEBUG_INSTANCE) {
- System.err.println("Region.addVertex(): tris: "+triangles.size()+", verts "+vertices.size());
- }
- setDirty(true);
+ private void pushNewVertexIdxImpl(final Vertex vertIn, final AffineTransform transform) {
+ pushIndex(numVertices);
+ pushNewVertexImpl(vertIn, transform);
}
- /** Adds a list of {@link Vertex} objects to the Region These vertices are to
- * be binded to OGL objects on the next call to {@code update}
- *
- * @param verts
- * a list of vertex objects
- *
- * @see update(GL2ES2) */
- public void addVertices(List<Vertex> verts) {
- vertices.addAll(verts);
- numVertices = vertices.size();
+ public final void addOutlineShape(final OutlineShape shape, final AffineTransform transform) {
+ final List<Triangle> trisIn = shape.getTriangles(OutlineShape.VerticesState.QUADRATIC_NURBS);
+ final ArrayList<Vertex> vertsIn = shape.getVertices();
if(DEBUG_INSTANCE) {
- System.err.println("Region.addVertices(): tris: "+triangles.size()+", verts "+vertices.size());
+ System.err.println("Region.addOutlineShape().0: tris: "+trisIn.size()+", verts "+vertsIn.size()+", transform "+transform);
}
- setDirty(true);
- }
-
- public void addOutlineShape(OutlineShape shape, AffineTransform t) {
- final List<Triangle> tris = shape.getTriangles(OutlineShape.VerticesState.QUADRATIC_NURBS);
- if(null != tris) {
- if( false && null != t ) {
- for(int i=0; i<tris.size(); i++) {
- triangles.add( tris.get(i).transform(t) );
- }
- } else {
- triangles.addAll(tris);
+ final int idxOffset = numVertices;
+ int vertsVNewIdxCount = 0, vertsTMovIdxCount = 0, vertsTNewIdxCount = 0, tris = 0;
+ int vertsDupCountV = 0, vertsDupCountT = 0, vertsKnownMovedT = 0;
+ if( vertsIn.size() >= 3 ) {
+ if(DEBUG_INSTANCE) {
+ System.err.println("Region.addOutlineShape(): Processing Vertices");
+ }
+ for(int i=0; i<vertsIn.size(); i++) {
+ pushNewVertexImpl(vertsIn.get(i), transform);
+ vertsVNewIdxCount++;
+ }
+ if(DEBUG_INSTANCE) {
+ System.err.println("Region.addOutlineShape(): Processing Triangles");
}
- // final List<Vertex> verts = shape.getVertices();
- // vertices.addAll(verts);
- // FIXME: use OutlineShape.getVertices(Runnable task-per-vertex) !!
- for (int j = 0; j < shape.outlines.size(); j++) {
- final ArrayList<Vertex> sovs = shape.outlines.get(j).getVertices();
- for (int k = 0; k < sovs.size(); k++) {
- final Vertex v;
- if( null != t ) {
- v = t.transform(sovs.get(k), null);
- } else {
- v = sovs.get(k);
+ for(int i=0; i<trisIn.size(); i++) {
+ final Triangle triIn = trisIn.get(i);
+ if(Region.DEBUG_INSTANCE) {
+ System.err.println("T["+i+"]: "+triIn);
+ }
+ // triEx.addVertexIndicesOffset(idxOffset);
+ // triangles.add( triEx );
+ final Vertex[] triInVertices = triIn.getVertices();
+ final int tv0Idx = triInVertices[0].getId();
+ if( Integer.MAX_VALUE-idxOffset > tv0Idx ) { // Integer.MAX_VALUE != i0 // FIXME: renderer uses SHORT!
+ // valid 'known' idx - move by offset
+ if(Region.DEBUG_INSTANCE) {
+ System.err.println("T["+i+"]: Moved "+tv0Idx+" + "+idxOffset+" -> "+(tv0Idx+idxOffset));
+ }
+ pushIndex(tv0Idx+idxOffset);
+ pushIndex(triInVertices[1].getId()+idxOffset);
+ pushIndex(triInVertices[2].getId()+idxOffset);
+ vertsTMovIdxCount+=3;
+ } else {
+ // invalid idx - generate new one
+ if(Region.DEBUG_INSTANCE) {
+ System.err.println("T["+i+"]: New Idx "+numVertices);
}
- v.setId(numVertices++);
- vertices.add(v);
+ pushNewVertexIdxImpl(triInVertices[0], transform);
+ pushNewVertexIdxImpl(triInVertices[1], transform);
+ pushNewVertexIdxImpl(triInVertices[2], transform);
+ vertsTNewIdxCount+=3;
}
+ tris++;
}
- // numVertices = vertices.size();
}
if(DEBUG_INSTANCE) {
- System.err.println("Region.addOutlineShape(): tris: "+triangles.size()+", verts "+vertices.size());
+ System.err.println("Region.addOutlineShape().X: idxOffset "+idxOffset+", tris: "+tris+", verts [idx "+vertsTNewIdxCount+", add "+vertsTNewIdxCount+" = "+(vertsVNewIdxCount+vertsTNewIdxCount)+"]");
+ System.err.println("Region.addOutlineShape().X: verts: idx[v-new "+vertsVNewIdxCount+", t-new "+vertsTNewIdxCount+" = "+(vertsVNewIdxCount+vertsTNewIdxCount)+"]");
+ System.err.println("Region.addOutlineShape().X: verts: idx t-moved "+vertsTMovIdxCount+", numVertices "+numVertices);
+ System.err.println("Region.addOutlineShape().X: verts: v-dups "+vertsDupCountV+", t-dups "+vertsDupCountT+", t-known "+vertsKnownMovedT);
+ // int vertsDupCountV = 0, vertsDupCountT = 0;
+ System.err.println("Region.addOutlineShape().X: box "+box);
}
setDirty(true);
}
- public void validateIndices() {
- final int verticeCountPre = vertices.size();
- for(int i=0; i<triangles.size(); i++) {
- final Triangle t = triangles.get(i);
- final Vertex[] t_vertices = t.getVertices();
-
- if(t_vertices[0].getId() == Integer.MAX_VALUE){
- t_vertices[0].setId(numVertices++);
- t_vertices[1].setId(numVertices++);
- t_vertices[2].setId(numVertices++);
- vertices.add(t_vertices[0]);
- vertices.add(t_vertices[1]);
- vertices.add(t_vertices[2]);
- }
- }
- if( verticeCountPre < vertices.size() ) {
- setDirty(true);
- }
- }
-
- public void addOutlineShapes(List<OutlineShape> shapes) {
+ public final void addOutlineShapes(final List<OutlineShape> shapes, final AffineTransform transform) {
for (int i = 0; i < shapes.size(); i++) {
- addOutlineShape(shapes.get(i), null);
+ addOutlineShape(shapes.get(i), transform);
}
- if(DEBUG_INSTANCE) {
- System.err.println("Region.addOutlineShapes(): tris: "+triangles.size()+", verts "+vertices.size());
- }
- setDirty(true);
}
/** @return the AxisAligned bounding box of current region */
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 78c8660fa..7bf2ee6e1 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java
@@ -27,12 +27,9 @@
*/
package com.jogamp.graph.curve.opengl;
-import java.util.List;
-
import javax.media.opengl.GL2ES2;
import com.jogamp.opengl.util.PMVMatrix;
-import com.jogamp.graph.curve.OutlineShape;
import com.jogamp.graph.curve.Region;
/** A GLRegion is the OGL binding of one or more OutlineShapes
@@ -77,6 +74,16 @@ public abstract class GLRegion extends Region {
*/
public abstract void destroy(GL2ES2 gl, RegionRenderer renderer);
+ protected abstract void clearImpl(final GL2ES2 gl, final RegionRenderer renderer);
+
+ /**
+ * Clears all data, i.e. triangles, vertices etc.
+ */
+ public void clear(final GL2ES2 gl, final RegionRenderer renderer) {
+ clearImpl(gl, renderer);
+ clearImpl();
+ }
+
/**
* Renders the associated OGL objects specifying
* current width/hight of window for multi pass rendering
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderUtil.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderUtil.java
index b54fcd6a6..944050a14 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderUtil.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderUtil.java
@@ -74,7 +74,7 @@ public class TextRenderUtil {
final Font font, final CharSequence str, final int pixelSize) {
final int charCount = str.length();
- final GLRegion region = Region.create(renderModes);
+ final GLRegion region = GLRegion.create(renderModes);
// region.setFlipped(true);
final Font.Metrics metrics = font.getMetrics();
@@ -88,7 +88,6 @@ public class TextRenderUtil {
float y = 0;
float advanceTotal = 0;
- int numVertices = region.getNumVertices();
for(int i=0; i< charCount; i++) {
final char character = str.charAt(i);
@@ -110,33 +109,7 @@ public class TextRenderUtil {
if( null == glyphShape ) {
continue;
}
- // glyphShape.closeLastOutline();
-
- if( false ) {
- region.addOutlineShape(glyphShape, t);
- } else {
- // System.err.println("XXXXX Pre TRI");
- // glyphShape.getVertices();
- final ArrayList<Triangle> trisIn = glyphShape.getTriangles(OutlineShape.VerticesState.QUADRATIC_NURBS);
- final ArrayList<Vertex> gVertices = glyphShape.getVertices();
-
- if( gVertices.size() < 3 ) {
- continue;
- }
- region.addTriangles(trisIn, t, numVertices);
-
- for(int j=0; j<gVertices.size(); j++) {
- final Vertex vert = gVertices.get(j);
- final Vertex svert = t.transform(vert, null);
- svert.setId(numVertices++);
- if(Region.DEBUG_INSTANCE) {
- System.err.println("IN: "+vert);
- System.err.println("EX: "+svert);
- }
- region.addVertex(svert, null);
- }
- }
- assert( numVertices == region.getNumVertices() );
+ region.addOutlineShape(glyphShape, t);
advanceTotal += glyph.getAdvance(pixelSize, true);
}
diff --git a/src/jogl/classes/com/jogamp/graph/geom/Triangle.java b/src/jogl/classes/com/jogamp/graph/geom/Triangle.java
index 6de99c48b..e353dd061 100644
--- a/src/jogl/classes/com/jogamp/graph/geom/Triangle.java
+++ b/src/jogl/classes/com/jogamp/graph/geom/Triangle.java
@@ -83,20 +83,6 @@ public class Triangle {
this.id = id;
}
- public void addVertexIndicesOffset(int offset) {
- if( 0 < offset ) {
- final int i0 = vertices[0].getId();
- if( Integer.MAX_VALUE-offset > i0 ) { // Integer.MAX_VALUE != i0 // FIXME: renderer uses SHORT!
- if(Region.DEBUG_INSTANCE) {
- System.err.println("Triangle.addVertexIndicesOffset: "+i0+" + "+offset+" -> "+(i0+offset));
- }
- vertices[0].setId(i0+offset);
- vertices[1].setId(vertices[1].getId()+offset);
- vertices[2].setId(vertices[2].getId()+offset);
- }
- }
- }
-
/** Returns array of 3 vertices, denominating the triangle. */
public Vertex[] getVertices() {
return vertices;
@@ -124,6 +110,6 @@ public class Triangle {
@Override
public String toString() {
- return "Tri ID: " + id + "\n" + vertices[0] + "\n" + vertices[1] + "\n" + vertices[2];
+ return "Tri ID: " + id + "\n\t" + vertices[0] + "\n\t" + vertices[1] + "\n\t" + vertices[2];
}
}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java
index 22364c373..9c3e3f2c2 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java
@@ -39,8 +39,6 @@ import jogamp.graph.curve.opengl.shader.AttributeNames;
import jogamp.graph.curve.opengl.shader.UniformNames;
import com.jogamp.common.nio.Buffers;
-import com.jogamp.graph.geom.Triangle;
-import com.jogamp.graph.geom.Vertex;
import com.jogamp.graph.curve.opengl.GLRegion;
import com.jogamp.graph.curve.opengl.RegionRenderer;
import com.jogamp.graph.curve.opengl.RenderState;
@@ -54,12 +52,11 @@ import com.jogamp.opengl.util.glsl.ShaderState;
public class VBORegion2PES2 extends GLRegion {
private GLArrayDataServer verticeTxtAttr;
private GLArrayDataServer texCoordTxtAttr;
- private GLArrayDataServer indicesTxt;
+ private GLArrayDataServer indicesTxtBuffer;
private GLArrayDataServer verticeFboAttr;
private GLArrayDataServer texCoordFboAttr;
private GLArrayDataServer indicesFbo;
-
private FBObject fbo;
private TextureAttachment texA;
private final PMVMatrix fboPMVMatrix;
@@ -72,24 +69,58 @@ public class VBORegion2PES2 extends GLRegion {
public VBORegion2PES2(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,
+ false, initialElementCount, GL.GL_STATIC_DRAW);
+ texCoordTxtAttr = GLArrayDataServer.createGLSL(AttributeNames.TEXCOORD_ATTR_NAME, 2, GL2ES2.GL_FLOAT,
+ false, initialElementCount, GL.GL_STATIC_DRAW);
+ }
+
+ @Override
+ public final void clearImpl(final GL2ES2 gl, final RegionRenderer renderer) {
+ indicesTxtBuffer.seal(gl, false);
+ indicesTxtBuffer.rewind();
+ verticeTxtAttr.seal(gl, false);
+ verticeTxtAttr.rewind();
+ texCoordTxtAttr.seal(gl, false);
+ texCoordTxtAttr.rewind();
+ }
+
+ @Override
+ public final boolean usesIndices() { return true; }
+
+ @Override
+ public 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]);
+ }
+
+ @Override
+ public final void pushIndex(int idx) {
+ indicesTxtBuffer.puts((short)idx);
}
@Override
public void update(final GL2ES2 gl, final RegionRenderer renderer) {
if(null == indicesFbo) {
- final int initialElementCount = 256;
final ShaderState st = renderer.getShaderState();
- indicesFbo = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialElementCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
+ 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, initialElementCount, GL.GL_STATIC_DRAW);
+ false, 4, GL.GL_STATIC_DRAW);
st.ownAttribute(texCoordFboAttr, true);
texCoordFboAttr.putf(5); texCoordFboAttr.putf(5);
texCoordFboAttr.putf(5); texCoordFboAttr.putf(6);
@@ -98,60 +129,19 @@ public class VBORegion2PES2 extends GLRegion {
texCoordFboAttr.seal(true);
verticeFboAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT,
- false, initialElementCount, GL.GL_STATIC_DRAW);
+ false, 4, GL.GL_STATIC_DRAW);
st.ownAttribute(verticeFboAttr, true);
-
- indicesTxt = 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,
- false, initialElementCount, GL.GL_STATIC_DRAW);
st.ownAttribute(verticeTxtAttr, true);
-
- texCoordTxtAttr = GLArrayDataServer.createGLSL(AttributeNames.TEXCOORD_ATTR_NAME, 2, GL2ES2.GL_FLOAT,
- false, initialElementCount, GL.GL_STATIC_DRAW);
st.ownAttribute(texCoordTxtAttr, true);
if(DEBUG_INSTANCE) {
System.err.println("VBORegion2PES2 Create: " + this);
}
}
- validateIndices();
- // process triangles
- indicesTxt.seal(gl, false);
- indicesTxt.rewind();
- for(int i=0; i<triangles.size(); i++) {
- final Triangle t = triangles.get(i);
- final Vertex[] t_vertices = t.getVertices();
-
- if(t_vertices[0].getId() == Integer.MAX_VALUE){
- throw new RuntimeException("Ooops Triangle #"+i+" - has unindexed vertices");
- } else {
- indicesTxt.puts((short) t_vertices[0].getId());
- indicesTxt.puts((short) t_vertices[1].getId());
- indicesTxt.puts((short) t_vertices[2].getId());
- }
- }
- indicesTxt.seal(gl, true);
- indicesTxt.enableBuffer(gl, false);
-
- // process vertices and update bbox
- box.reset();
- verticeTxtAttr.seal(gl, false);
- verticeTxtAttr.rewind();
- texCoordTxtAttr.seal(gl, false);
- texCoordTxtAttr.rewind();
- for(int i=0; i<vertices.size(); i++) {
- final Vertex v = vertices.get(i);
- verticeTxtAttr.putf(v.getX());
- verticeTxtAttr.putf(v.getY());
- verticeTxtAttr.putf(v.getZ());
- box.resize(v.getX(), v.getY(), v.getZ());
-
- final float[] tex = v.getTexCoord();
- texCoordTxtAttr.putf(tex[0]);
- texCoordTxtAttr.putf(tex[1]);
- }
+ // seal buffers
+ indicesTxtBuffer.seal(gl, true);
+ indicesTxtBuffer.enableBuffer(gl, false);
texCoordTxtAttr.seal(gl, true);
texCoordTxtAttr.enableBuffer(gl, false);
verticeTxtAttr.seal(gl, true);
@@ -276,11 +266,11 @@ public class VBORegion2PES2 extends GLRegion {
private void renderRegion(final GL2ES2 gl) {
verticeTxtAttr.enableBuffer(gl, true);
texCoordTxtAttr.enableBuffer(gl, true);
- indicesTxt.bindBuffer(gl, true); // keeps VBO binding
+ indicesTxtBuffer.bindBuffer(gl, true); // keeps VBO binding
- gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesTxt.getElementCount() * indicesTxt.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0);
+ gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesTxtBuffer.getElementCount() * indicesTxtBuffer.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0);
- indicesTxt.bindBuffer(gl, false);
+ indicesTxtBuffer.bindBuffer(gl, false);
texCoordTxtAttr.enableBuffer(gl, false);
verticeTxtAttr.enableBuffer(gl, false);
}
@@ -306,9 +296,9 @@ public class VBORegion2PES2 extends GLRegion {
texCoordTxtAttr.destroy(gl);
texCoordTxtAttr = null;
}
- if(null != indicesTxt) {
- indicesTxt.destroy(gl);
- indicesTxt = null;
+ if(null != indicesTxtBuffer) {
+ indicesTxtBuffer.destroy(gl);
+ indicesTxtBuffer = null;
}
if(null != verticeFboAttr) {
st.ownAttribute(verticeFboAttr, false);
@@ -324,7 +314,5 @@ public class VBORegion2PES2 extends GLRegion {
indicesFbo.destroy(gl);
indicesFbo = null;
}
- triangles.clear();
- vertices.clear();
}
}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
index f7b9e73af..af0c4c980 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
@@ -34,8 +34,6 @@ 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.geom.Vertex;
-import com.jogamp.graph.geom.Triangle;
import com.jogamp.opengl.util.GLArrayDataServer;
import com.jogamp.opengl.util.glsl.ShaderState;
@@ -43,79 +41,68 @@ public class VBORegionSPES2 extends GLRegion {
private GLArrayDataServer verticeAttr = null;
private GLArrayDataServer texCoordAttr = null;
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);
+
+ texCoordAttr = GLArrayDataServer.createGLSL(AttributeNames.TEXCOORD_ATTR_NAME, 2, GL2ES2.GL_FLOAT,
+ false, initialElementCount, GL.GL_STATIC_DRAW);
}
@Override
- public void update(final GL2ES2 gl, final RegionRenderer renderer) {
- if(null == indicesBuffer) {
- final int initialElementCount = 256;
- final ShaderState st = renderer.getShaderState();
+ public final void clearImpl(final GL2ES2 gl, final RegionRenderer renderer) {
+ indicesBuffer.seal(gl, false);
+ indicesBuffer.rewind();
+ verticeAttr.seal(gl, false);
+ verticeAttr.rewind();
+ texCoordAttr.seal(gl, false);
+ texCoordAttr.rewind();
+ }
- indicesBuffer = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialElementCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
+ @Override
+ public final boolean usesIndices() { return true; }
- verticeAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT,
- false, initialElementCount, GL.GL_STATIC_DRAW);
- st.ownAttribute(verticeAttr, true);
+ @Override
+ public final void pushVertex(float[] coords, float[] texParams) {
+ verticeAttr.putf(coords[0]);
+ verticeAttr.putf(coords[1]);
+ verticeAttr.putf(coords[2]);
- texCoordAttr = GLArrayDataServer.createGLSL(AttributeNames.TEXCOORD_ATTR_NAME, 2, GL2ES2.GL_FLOAT,
- false, initialElementCount, GL.GL_STATIC_DRAW);
- st.ownAttribute(texCoordAttr, true);
+ texCoordAttr.putf(texParams[0]);
+ texCoordAttr.putf(texParams[1]);
+ }
- if(DEBUG_INSTANCE) {
- System.err.println("VBORegionSPES2 Create: " + this);
- }
- }
+ @Override
+ public final void pushIndex(int idx) {
+ indicesBuffer.puts((short)idx);
+ }
- if(DEBUG_INSTANCE) {
- System.err.println("VBORegionSPES2 Indices of "+triangles.size()+", triangles");
- }
- validateIndices();
- // process triangles
- indicesBuffer.seal(gl, false);
- indicesBuffer.rewind();
- for(int i=0; i<triangles.size(); i++) {
- final Triangle t = triangles.get(i);
- final Vertex[] t_vertices = t.getVertices();
-
- if(t_vertices[0].getId() == Integer.MAX_VALUE){
- throw new RuntimeException("Ooops Triangle #"+i+" - has unindexed vertices");
- } else {
- indicesBuffer.puts((short) t_vertices[0].getId());
- indicesBuffer.puts((short) t_vertices[1].getId());
- indicesBuffer.puts((short) t_vertices[2].getId());
- if(DEBUG_INSTANCE) {
- System.err.println("VBORegionSPES2.Indices.2: "+
- t_vertices[0].getId()+", "+t_vertices[1].getId()+", "+t_vertices[2].getId());
- }
- }
+ @Override
+ public void update(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);
-
- // process vertices and update bbox
- box.reset();
- verticeAttr.seal(gl, false);
- verticeAttr.rewind();
- texCoordAttr.seal(gl, false);
- texCoordAttr.rewind();
- for(int i=0; i<vertices.size(); i++) {
- final Vertex v = vertices.get(i);
- verticeAttr.putf(v.getX());
- verticeAttr.putf(v.getY());
- verticeAttr.putf(v.getZ());
- box.resize(v.getX(), v.getY(), v.getZ());
-
- final float[] tex = v.getTexCoord();
- texCoordAttr.putf(tex[0]);
- texCoordAttr.putf(tex[1]);
- }
verticeAttr.seal(gl, true);
verticeAttr.enableBuffer(gl, false);
texCoordAttr.seal(gl, true);
texCoordAttr.enableBuffer(gl, false);
+ if(DEBUG_INSTANCE) {
+ System.err.println("VBORegionSPES2 idx "+indicesBuffer);
+ System.err.println("VBORegionSPES2 ver "+verticeAttr);
+ System.err.println("VBORegionSPES2 tex "+texCoordAttr);
+ }
}
@Override
diff --git a/src/jogl/classes/jogamp/graph/geom/plane/AffineTransform.java b/src/jogl/classes/jogamp/graph/geom/plane/AffineTransform.java
index f5cf8dd95..5953ea89b 100644
--- a/src/jogl/classes/jogamp/graph/geom/plane/AffineTransform.java
+++ b/src/jogl/classes/jogamp/graph/geom/plane/AffineTransform.java
@@ -403,17 +403,17 @@ public class AffineTransform implements Cloneable, Serializable {
);
}
- public Vertex transform(Vertex src, Vertex dst) {
+ public final Vertex transform(final Vertex src, Vertex dst) {
if (dst == null) {
dst = pointFactory.create(src.getId(), src.isOnCurve(), src.getTexCoord());
}
final float x = src.getX();
final float y = src.getY();
- dst.setCoord(x * m00 + y * m01 + m02, x * m10 + y * m11 + m12, 0f);
+ dst.setCoord(x * m00 + y * m01 + m02, x * m10 + y * m11 + m12, src.getZ());
return dst;
}
- public void transform(Vertex[] src, int srcOff, Vertex[] dst, int dstOff, int length) {
+ public final void transform(Vertex[] src, int srcOff, Vertex[] dst, int dstOff, int length) {
while (--length >= 0) {
Vertex srcPoint = src[srcOff++];
Vertex dstPoint = dst[dstOff];
@@ -422,12 +422,26 @@ public class AffineTransform implements Cloneable, Serializable {
}
final float x = srcPoint.getX();
final float y = srcPoint.getY();
- dstPoint.setCoord(x * m00 + y * m01 + m02, x * m10 + y * m11 + m12, 0f);
+ dstPoint.setCoord(x * m00 + y * m01 + m02, x * m10 + y * m11 + m12, srcPoint.getZ());
dst[dstOff++] = dstPoint;
}
}
- public void transform(float[] src, int srcOff, float[] dst, int dstOff, int length) {
+ public final void transform(final float[] src, final float[] dst) {
+ final float x = src[0];
+ final float y = src[1];
+ dst[0] = x * m00 + y * m01 + m02;
+ dst[1] = x * m10 + y * m11 + m12;
+ }
+
+ public final void transform(final float[] src, final int srcOff, final float[] dst, final int dstOff) {
+ final float x = src[srcOff + 0];
+ final float y = src[srcOff + 1];
+ dst[dstOff + 0] = x * m00 + y * m01 + m02;
+ dst[dstOff + 1] = x * m10 + y * m11 + m12;
+ }
+
+ public final void transform(final float[] src, int srcOff, final float[] dst, int dstOff, int length) {
int step = 2;
if (src == dst && srcOff < dstOff && dstOff < srcOff + length * 2) {
srcOff = srcOff + length * 2 - 2;
@@ -435,8 +449,8 @@ public class AffineTransform implements Cloneable, Serializable {
step = -2;
}
while (--length >= 0) {
- float x = src[srcOff + 0];
- float y = src[srcOff + 1];
+ final float x = src[srcOff + 0];
+ final float y = src[srcOff + 1];
dst[dstOff + 0] = x * m00 + y * m01 + m02;
dst[dstOff + 1] = x * m10 + y * m11 + m12;
srcOff += step;
@@ -450,7 +464,7 @@ public class AffineTransform implements Cloneable, Serializable {
}
final float x = src.getX();
final float y = src.getY();
- dst.setCoord(x * m00 + y * m01, x * m10 + y * m11, 0f);
+ dst.setCoord(x * m00 + y * m01, x * m10 + y * m11, src.getZ());
return dst;
}
@@ -473,7 +487,7 @@ public class AffineTransform implements Cloneable, Serializable {
}
final float x = src.getX() - m02;
final float y = src.getY() - m12;
- dst.setCoord((x * m11 - y * m01) / det, (y * m00 - x * m10) / det, 0f);
+ dst.setCoord((x * m11 - y * m01) / det, (y * m00 - x * m10) / det, src.getZ());
return dst;
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener02.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener02.java
index 222265c37..0e92bd2b6 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener02.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener02.java
@@ -91,7 +91,7 @@ public class GPURegionGLListener02 extends GPURegionRendererListenerBase01 {
shape.closeLastOutline();
region = GLRegion.create(getRenderModes());
- region.addOutlineShapes(outlineShapes);
+ region.addOutlineShapes(outlineShapes, null);
}
public void init(GLAutoDrawable drawable) {