summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/graph
diff options
context:
space:
mode:
Diffstat (limited to 'src/jogl/classes/com/jogamp/graph')
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/Region.java155
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java52
2 files changed, 184 insertions, 23 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/curve/Region.java b/src/jogl/classes/com/jogamp/graph/curve/Region.java
index 8843188b4..01bdba633 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/Region.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/Region.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2010 JogAmp Community. All rights reserved.
+ * Copyright 2010-2023 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:
@@ -30,6 +30,7 @@ package com.jogamp.graph.curve;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.TimeUnit;
import jogamp.opengl.Debug;
@@ -193,10 +194,18 @@ public abstract class Region {
*/
public final boolean usesI32Idx() { return this.use_int32_idx; }
- protected abstract void growBufferSize(int verticeCount, int indexCount);
+ /**
+ * Allow the renderer buffers to pre-emptively grow for given vertices- and index counts.
+ * @param verticeCount number of vertices to hold
+ * @param indexCount number of indices to hold
+ */
+ public abstract void growBufferSize(int verticeCount, int indexCount);
protected abstract void pushVertex(final float[] coords, final float[] texParams, float[] rgba);
+ protected abstract void pushVertices(final float[] coords1, final float[] coords2, final float[] coords3,
+ final float[] texParams1, final float[] texParams2, final float[] texParams3, float[] rgba);
protected abstract void pushIndex(int idx);
+ protected abstract void pushIndices(int idx1, int idx2, int idx3);
/**
* Return bit-field of render modes, see {@link GLRegion#create(GLProfile, int, TextureSequence)}.
@@ -265,32 +274,121 @@ public abstract class Region {
this.frustum = frustum;
}
- final float[] coordsEx = new float[3];
-
private void pushNewVertexImpl(final Vertex vertIn, final AffineTransform transform, final float[] rgba) {
if( null != transform ) {
+ final float[] coordsEx1 = new float[3];
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(), rgba);
+ transform.transform(coordsIn, coordsEx1);
+ coordsEx1[2] = coordsIn[2];
+ box.resize(coordsEx1);
+ pushVertex(coordsEx1, vertIn.getTexCoord(), rgba);
} else {
- box.resize(vertIn.getX(), vertIn.getY(), vertIn.getZ());
+ box.resize(vertIn.getCoord());
pushVertex(vertIn.getCoord(), vertIn.getTexCoord(), rgba);
}
numVertices++;
}
+ private void pushNewVerticesImpl(final Vertex vertIn1, final Vertex vertIn2, final Vertex vertIn3, final AffineTransform transform, final float[] rgba) {
+ if( null != transform ) {
+ final float[] coordsEx1 = new float[3];
+ final float[] coordsEx2 = new float[3];
+ final float[] coordsEx3 = new float[3];
+ final float[] coordsIn1 = vertIn1.getCoord();
+ final float[] coordsIn2 = vertIn2.getCoord();
+ final float[] coordsIn3 = vertIn3.getCoord();
+ transform.transform(coordsIn1, coordsEx1);
+ transform.transform(coordsIn2, coordsEx2);
+ transform.transform(coordsIn3, coordsEx3);
+ coordsEx1[2] = coordsIn1[2];
+ coordsEx2[2] = coordsIn2[2];
+ coordsEx3[2] = coordsIn3[2];
+ box.resize(coordsEx1);
+ box.resize(coordsEx2);
+ box.resize(coordsEx3);
+ pushVertices(coordsEx1, coordsEx2, coordsEx3,
+ vertIn1.getTexCoord(), vertIn2.getTexCoord(), vertIn3.getTexCoord(), rgba);
+ } else {
+ box.resize(vertIn1.getCoord());
+ box.resize(vertIn2.getCoord());
+ box.resize(vertIn3.getCoord());
+ pushVertices(vertIn1.getCoord(), vertIn2.getCoord(), vertIn3.getCoord(),
+ vertIn1.getTexCoord(), vertIn2.getTexCoord(), vertIn3.getTexCoord(), rgba);
+ }
+ numVertices+=3;
+ }
+
+ @SuppressWarnings("unused")
private void pushNewVertexIdxImpl(final Vertex vertIn, final AffineTransform transform, final float[] rgba) {
pushIndex(numVertices);
pushNewVertexImpl(vertIn, transform, rgba);
}
+ private void pushNewVerticesIdxImpl(final Vertex vertIn1, final Vertex vertIn2, final Vertex vertIn3, final AffineTransform transform, final float[] rgba) {
+ pushIndices(numVertices, numVertices+1, numVertices+2);
+ pushNewVerticesImpl(vertIn1, vertIn2, vertIn3, transform, rgba);
+ }
private final AABBox tmpBox = new AABBox();
protected static final int GL_UINT16_MAX = 0xffff; // 65,535
protected static final int GL_INT32_MAX = 0x7fffffff; // 2,147,483,647
+ static class Perf {
+ long t0, t1;
+ long tac_ns_vertices = 0;
+ long tac_ns_push_idx = 0;
+ long tac_ns_push_vertidx = 0;
+ long tac_ns_triangles = 0;
+ long tac_ns_total = 0;
+ long tac_count = 0;
+
+ public void print(final PrintStream out) {
+ out.printf("Region.add(): count %3d, total %5d [ms], per-add %4.2f [ns]%n", tac_count, TimeUnit.NANOSECONDS.toMillis(tac_ns_total), ((double)tac_ns_total/(double)tac_count));
+ out.printf(" vertices %5d [ms], per-add %4.2f [ns]%n", TimeUnit.NANOSECONDS.toMillis(tac_ns_vertices), ((double)tac_ns_vertices/(double)tac_count));
+ out.printf(" push_idx %5d [ms], per-add %4.2f [ns]%n", TimeUnit.NANOSECONDS.toMillis(tac_ns_push_idx), ((double)tac_ns_push_idx/(double)tac_count));
+ out.printf(" push_vertidx %5d [ms], per-add %4.2f [ns]%n", TimeUnit.NANOSECONDS.toMillis(tac_ns_push_vertidx), ((double)tac_ns_push_vertidx/(double)tac_count));
+ out.printf(" triangles %5d [ms], per-add %4.2f [ns]%n", TimeUnit.NANOSECONDS.toMillis(tac_ns_triangles), ((double)tac_ns_triangles/(double)tac_count));
+ }
+
+ public void clear() {
+ t0 = 0; t1 = 0;
+ tac_ns_vertices = 0;
+ tac_ns_push_idx = 0;
+ tac_ns_push_vertidx = 0;
+ tac_ns_triangles = 0;
+ tac_ns_total = 0;
+ tac_count = 0;
+ }
+ }
+ Perf perf = null;
+
+ /** Enable or disable performance counter for {@link #addOutlineShape(OutlineShape, AffineTransform, float[])}. */
+ public void enablePerf(final boolean enable) {
+ if( enable ) {
+ if( null != perf ) {
+ perf.clear();
+ } else {
+ perf = new Perf();
+ }
+ } else {
+ perf = null;
+ }
+ }
+
+ /** Clear performance counter for {@link #addOutlineShape(OutlineShape, AffineTransform, float[])}. */
+ public void clearPerf() {
+ if( null != perf ) {
+ perf.clear();
+ }
+ }
+
+ /** Print performance counter for {@link #addOutlineShape(OutlineShape, AffineTransform, float[])}. */
+ public void printPerf(final PrintStream out) {
+ if( null != perf ) {
+ perf.print(out);
+ }
+ }
+
/**
* Add the given {@link OutlineShape} to this region with the given optional {@link AffineTransform}.
* <p>
@@ -301,6 +399,10 @@ public abstract class Region {
* @param rgbaColor TODO
*/
public final void addOutlineShape(final OutlineShape shape, final AffineTransform t, final float[] rgbaColor) {
+ if( null != perf ) {
+ ++perf.tac_count;
+ perf.t0 = System.nanoTime();
+ }
if( null != frustum ) {
final AABBox shapeBox = shape.getBounds();
final AABBox shapeBoxT;
@@ -342,6 +444,10 @@ public abstract class Region {
pushNewVertexImpl(vertsIn.get(i), t, rgbaColor);
vertsVNewIdxCount++;
}
+ if( null != perf ) {
+ perf.t1 = System.nanoTime();
+ perf.tac_ns_vertices += perf.t1-perf.t0;
+ }
if(DEBUG_INSTANCE) {
System.err.println("Region.addOutlineShape(): Processing Triangles");
}
@@ -359,22 +465,39 @@ public abstract class Region {
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);
+ if( null != perf ) {
+ final long tpi = System.nanoTime();
+ pushIndices(tv0Idx+idxOffset,
+ triInVertices[1].getId()+idxOffset,
+ triInVertices[2].getId()+idxOffset);
+ perf.tac_ns_push_idx += System.nanoTime() - tpi;
+ } else {
+ pushIndices(tv0Idx+idxOffset,
+ triInVertices[1].getId()+idxOffset,
+ triInVertices[2].getId()+idxOffset);
+ }
vertsTMovIdxCount+=3;
} else {
// FIXME: Invalid idx - generate new one
- if(Region.DEBUG_INSTANCE) {
+ if( Region.DEBUG_INSTANCE) {
System.err.println("T["+i+"]: New Idx "+numVertices);
}
- pushNewVertexIdxImpl(triInVertices[0], t, rgbaColor);
- pushNewVertexIdxImpl(triInVertices[1], t, rgbaColor);
- pushNewVertexIdxImpl(triInVertices[2], t, rgbaColor);
+ if( null != perf ) {
+ final long tpvi = System.nanoTime();
+ pushNewVerticesIdxImpl(triInVertices[0], triInVertices[1], triInVertices[2], t, rgbaColor);
+ perf.tac_ns_push_vertidx += System.nanoTime() - tpvi;
+ } else {
+ pushNewVerticesIdxImpl(triInVertices[0], triInVertices[1], triInVertices[2], t, rgbaColor);
+ }
vertsTNewIdxCount+=3;
}
tris++;
}
+ if( null != perf ) {
+ final long t2 = System.nanoTime();
+ perf.tac_ns_triangles += t2-perf.t1;
+ perf.tac_ns_total += t2-perf.t0;
+ }
}
if(DEBUG_INSTANCE) {
System.err.println("Region.addOutlineShape().X: idx[ui32 "+usesI32Idx()+", offset "+idxOffset+"], tris: "+tris+", verts [idx "+vertsTNewIdxCount+", add "+vertsTNewIdxCount+" = "+(vertsVNewIdxCount+vertsTNewIdxCount)+"]");
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 69638f60e..9baa99420 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2010 JogAmp Community. All rights reserved.
+ * Copyright 2010-2023 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:
@@ -30,6 +30,7 @@ package com.jogamp.graph.curve.opengl;
import com.jogamp.opengl.GL;
import com.jogamp.opengl.GL2ES2;
import com.jogamp.opengl.GLArrayData;
+import com.jogamp.opengl.util.GLArrayDataEditable;
import com.jogamp.opengl.GLProfile;
import jogamp.graph.curve.opengl.VBORegion2PMSAAES2;
@@ -42,7 +43,6 @@ import com.jogamp.graph.curve.Region;
import java.io.PrintStream;
-import com.jogamp.common.nio.Buffers;
import com.jogamp.graph.curve.OutlineShape;
/** A GLRegion is the OGL binding of one or more OutlineShapes
@@ -59,6 +59,25 @@ import com.jogamp.graph.curve.OutlineShape;
public abstract class GLRegion extends Region {
/**
+ * Heuristics with TestTextRendererNEWT00 text_1 + text_2 = 1334 chars
+ * - FreeSans ~ vertices 64/char, indices 33/char
+ * - Ubuntu Light ~ vertices 100/char, indices 50/char
+ * - FreeSerif ~ vertices 115/char, indices 61/char
+ *
+ * Now let's assume a minimum of 10 chars will be rendered
+ */
+
+ /**
+ * Default initial vertices count based on 10 chars w/ FreeSans @ 64 vertices/char avg.
+ */
+ public static final int defaultVerticesCount = 10*64;
+
+ /**
+ * Default initial indices count based on 10 chars w/ FreeSans @ 33 indices/char avg.
+ */
+ public static final int defaultIndicesCount = 10*33;
+
+ /**
* Create a GLRegion using the passed render mode
*
* <p> In case {@link Region#VBAA_RENDERING_BIT} is being requested the default texture unit
@@ -66,22 +85,37 @@ public abstract class GLRegion extends Region {
* @param glp intended GLProfile to use. Instance may use higher OpenGL features if indicated by GLProfile.
* @param renderModes bit-field of modes, e.g. {@link Region#VARWEIGHT_RENDERING_BIT}, {@link Region#VBAA_RENDERING_BIT}
* @param colorTexSeq optional {@link TextureSequence} for {@link Region#COLORTEXTURE_RENDERING_BIT} rendering mode.
+ * @param initialVerticesCount initial number of vertices in the render-buffer
+ * @param initialIndicesCount initial number of indices in the render-buffer
*/
- public static GLRegion create(final GLProfile glp, int renderModes, final TextureSequence colorTexSeq) {
+ public static GLRegion create(final GLProfile glp, int renderModes, final TextureSequence colorTexSeq, final int initialVerticesCount, final int initialIndicesCount) {
if( null != colorTexSeq ) {
renderModes |= Region.COLORTEXTURE_RENDERING_BIT;
} else if( Region.hasColorTexture(renderModes) ) {
throw new IllegalArgumentException("COLORTEXTURE_RENDERING_BIT set but null TextureSequence");
}
if( isVBAA(renderModes) ) {
- return new VBORegion2PVBAAES2(glp, renderModes, colorTexSeq, Region.DEFAULT_TWO_PASS_TEXTURE_UNIT);
+ return new VBORegion2PVBAAES2(glp, renderModes, colorTexSeq, Region.DEFAULT_TWO_PASS_TEXTURE_UNIT, initialVerticesCount, initialIndicesCount);
} else if( isMSAA(renderModes) ) {
- return new VBORegion2PMSAAES2(glp, renderModes, colorTexSeq, Region.DEFAULT_TWO_PASS_TEXTURE_UNIT);
+ return new VBORegion2PMSAAES2(glp, renderModes, colorTexSeq, Region.DEFAULT_TWO_PASS_TEXTURE_UNIT, initialVerticesCount, initialIndicesCount);
} else {
- return new VBORegionSPES2(glp, renderModes, colorTexSeq);
+ return new VBORegionSPES2(glp, renderModes, colorTexSeq, initialVerticesCount, initialIndicesCount);
}
}
+ /**
+ * Create a GLRegion using the passed render mode
+ *
+ * <p> In case {@link Region#VBAA_RENDERING_BIT} is being requested the default texture unit
+ * {@link Region#DEFAULT_TWO_PASS_TEXTURE_UNIT} is being used.</p>
+ * @param glp intended GLProfile to use. Instance may use higher OpenGL features if indicated by GLProfile.
+ * @param renderModes bit-field of modes, e.g. {@link Region#VARWEIGHT_RENDERING_BIT}, {@link Region#VBAA_RENDERING_BIT}
+ * @param colorTexSeq optional {@link TextureSequence} for {@link Region#COLORTEXTURE_RENDERING_BIT} rendering mode.
+ */
+ public static GLRegion create(final GLProfile glp, final int renderModes, final TextureSequence colorTexSeq) {
+ return GLRegion.create(glp, renderModes, colorTexSeq, defaultVerticesCount, defaultIndicesCount);
+ }
+
private final int gl_idx_type;
protected final TextureSequence colorTexSeq;
@@ -118,10 +152,14 @@ public abstract class GLRegion extends Region {
}
/**
- * Clears all data, i.e. triangles, vertices etc.
+ * Clears all buffers, i.e. triangles, vertices etc and and resets states accordingly, see {@link GLArrayDataEditable#clear(GL)}.
+ * <p>
+ * This method does not actually erase the data in the buffer and will most often be used when erasing the underlying memory is suitable.
+ * </p>
*
* @param gl the current {@link GL2ES2} object
* @return this {@link GLRegion} for chaining.
+ * @see GLArrayDataEditable#clear(GL)
*/
public GLRegion clear(final GL2ES2 gl) {
clearImpl(gl);