summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-03-06 11:21:45 +0100
committerSven Gothel <[email protected]>2023-03-06 11:21:45 +0100
commit2920be3622adf2b14cfad7d0261c11dc7e8151db (patch)
treef4f9372f9c74dd17e5c2f8b6281f9588d5fcd1a5 /src
parent8c441b4fc5a63967cfded3ec58cc0736a0aadb0f (diff)
Graph: Use PerfCounterCtrl interface and Instant/Duration & Clock.getMonotonicTime() ...
Diffstat (limited to 'src')
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/Region.java149
-rw-r--r--src/jogl/classes/com/jogamp/graph/font/Font.java10
-rw-r--r--src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java93
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java142
4 files changed, 223 insertions, 171 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/curve/Region.java b/src/jogl/classes/com/jogamp/graph/curve/Region.java
index 01bdba633..068e0aabd 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/Region.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/Region.java
@@ -28,6 +28,8 @@
package com.jogamp.graph.curve;
import java.io.PrintStream;
+import java.time.Duration;
+import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
@@ -38,6 +40,8 @@ import com.jogamp.graph.geom.Triangle;
import com.jogamp.graph.geom.Vertex;
import com.jogamp.graph.geom.plane.AffineTransform;
import com.jogamp.common.nio.Buffers;
+import com.jogamp.common.os.Clock;
+import com.jogamp.common.util.PerfCounterCtrl;
import com.jogamp.graph.curve.opengl.GLRegion;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.math.geom.AABBox;
@@ -334,60 +338,79 @@ public abstract class Region {
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;
+ Instant t0 = null, t1 = null, t2 = null;
+ // all td_ values are in [ns]
+ long td_vertices = 0;
+ long td_tri_push_idx = 0;
+ long td_tri_push_vertidx = 0;
+ long td_tri_misc = 0;
+ long td_tri_total = 0; // incl tac_ns_tri_push_vertidx + tac_ns_tri_push_idx + tac_ns_tri_misc
+ long td_total = 0; // incl tac_ns_triangles + tac_ns_vertices
+ long 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));
+ final long tac_ns_triangles_self = td_tri_total - td_tri_push_vertidx - td_tri_push_idx - td_tri_misc;
+ final long tac_ns_total_self = td_total - td_tri_total - td_vertices;
+ out.printf("Region.add(): count %,3d, total %,5d [ms], per-add %,4.2f [ns]%n", count, TimeUnit.NANOSECONDS.toMillis(td_total), ((double)td_total/count));
+ out.printf(" total self %,5d [ms], per-add %,4.2f [ns]%n", TimeUnit.NANOSECONDS.toMillis(tac_ns_total_self), ((double)tac_ns_total_self/count));
+ out.printf(" vertices %,5d [ms], per-add %,4.2f [ns]%n", TimeUnit.NANOSECONDS.toMillis(td_vertices), ((double)td_vertices/count));
+ out.printf(" triangles total %,5d [ms], per-add %,4.2f [ns]%n", TimeUnit.NANOSECONDS.toMillis(td_tri_total), ((double)td_tri_total/count));
+ out.printf(" triangles self %,5d [ms], per-add %,4.2f [ns]%n", TimeUnit.NANOSECONDS.toMillis(tac_ns_triangles_self), ((double)tac_ns_triangles_self/count));
+ out.printf(" tri misc %,5d [ms], per-add %,4.2f [ns]%n", TimeUnit.NANOSECONDS.toMillis(td_tri_misc), ((double)td_tri_misc/count));
+ out.printf(" tri p-idx %,5d [ms], per-add %,4.2f [ns]%n", TimeUnit.NANOSECONDS.toMillis(td_tri_push_idx), ((double)td_tri_push_idx/count));
+ out.printf(" tri p-vertidx %,5d [ms], per-add %,4.2f [ns]%n", TimeUnit.NANOSECONDS.toMillis(td_tri_push_vertidx), ((double)td_tri_push_vertidx/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;
+ t0 = null; t1 = null; t2 = null;
+ td_vertices = 0;
+ td_tri_push_idx = 0;
+ td_tri_push_vertidx = 0;
+ td_tri_misc = 0;
+ td_tri_total = 0;
+ td_total = 0;
+ count = 0;
}
}
- Perf perf = null;
+ private 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();
+ private final PerfCounterCtrl perfCounterCtrl = new PerfCounterCtrl() {
+ @Override
+ public void enable(final boolean enable) {
+ if( enable ) {
+ if( null != perf ) {
+ perf.clear();
+ } else {
+ perf = new Perf();
+ }
} else {
- perf = new Perf();
+ perf = null;
}
- } else {
- perf = null;
}
- }
- /** Clear performance counter for {@link #addOutlineShape(OutlineShape, AffineTransform, float[])}. */
- public void clearPerf() {
- if( null != perf ) {
- perf.clear();
+ @Override
+ public void clear() {
+ 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);
+ @Override
+ public Duration getTotalDuration() {
+ if( null != perf ) {
+ return Duration.ofNanos(perf.td_total);
+ } else {
+ return Duration.ZERO;
+ }
}
- }
+
+ @Override
+ public void print(final PrintStream out) {
+ if( null != perf ) {
+ perf.print(out);
+ }
+ } };
+ public PerfCounterCtrl perfCounter() { return perfCounterCtrl; }
/**
* Add the given {@link OutlineShape} to this region with the given optional {@link AffineTransform}.
@@ -400,8 +423,8 @@ public abstract class Region {
*/
public final void addOutlineShape(final OutlineShape shape, final AffineTransform t, final float[] rgbaColor) {
if( null != perf ) {
- ++perf.tac_count;
- perf.t0 = System.nanoTime();
+ ++perf.count;
+ perf.t0 = Clock.getMonotonicTime();
}
if( null != frustum ) {
final AABBox shapeBox = shape.getBounds();
@@ -445,32 +468,38 @@ public abstract class Region {
vertsVNewIdxCount++;
}
if( null != perf ) {
- perf.t1 = System.nanoTime();
- perf.tac_ns_vertices += perf.t1-perf.t0;
+ perf.t1 = Clock.getMonotonicTime();
+ perf.td_vertices += Duration.between(perf.t0, perf.t1).toNanos();
}
if(DEBUG_INSTANCE) {
System.err.println("Region.addOutlineShape(): Processing Triangles");
}
- for(int i=0; i<trisIn.size(); i++) {
- final Triangle triIn = trisIn.get(i);
- if(Region.DEBUG_INSTANCE) {
- System.err.println("T["+i+"]: "+triIn);
+ for(final Triangle triIn : trisIn) {
+ if( null != perf ) {
+ perf.t2 = Clock.getMonotonicTime();
}
+ // 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( null != perf ) {
+ perf.td_tri_misc += Duration.between(perf.t2, Clock.getMonotonicTime()).toNanos();
+ }
if ( max_indices - idxOffset > tv0Idx ) {
// valid 'known' idx - move by offset
- if(Region.DEBUG_INSTANCE) {
- System.err.println("T["+i+"]: Moved "+tv0Idx+" + "+idxOffset+" -> "+(tv0Idx+idxOffset));
- }
+ // if(Region.DEBUG_INSTANCE) {
+ // System.err.println("T["+i+"]: Moved "+tv0Idx+" + "+idxOffset+" -> "+(tv0Idx+idxOffset));
+ // }
if( null != perf ) {
- final long tpi = System.nanoTime();
+ final Instant tpi = Clock.getMonotonicTime();
pushIndices(tv0Idx+idxOffset,
triInVertices[1].getId()+idxOffset,
triInVertices[2].getId()+idxOffset);
- perf.tac_ns_push_idx += System.nanoTime() - tpi;
+ perf.td_tri_push_idx += Duration.between(tpi, Clock.getMonotonicTime()).toNanos();
} else {
pushIndices(tv0Idx+idxOffset,
triInVertices[1].getId()+idxOffset,
@@ -479,13 +508,13 @@ public abstract class Region {
vertsTMovIdxCount+=3;
} else {
// FIXME: Invalid idx - generate new one
- if( Region.DEBUG_INSTANCE) {
- System.err.println("T["+i+"]: New Idx "+numVertices);
- }
+ // if( Region.DEBUG_INSTANCE) {
+ // System.err.println("T["+i+"]: New Idx "+numVertices);
+ // }
if( null != perf ) {
- final long tpvi = System.nanoTime();
+ final Instant tpvi = Clock.getMonotonicTime();
pushNewVerticesIdxImpl(triInVertices[0], triInVertices[1], triInVertices[2], t, rgbaColor);
- perf.tac_ns_push_vertidx += System.nanoTime() - tpvi;
+ perf.td_tri_push_vertidx += Duration.between(tpvi, Clock.getMonotonicTime()).toNanos();
} else {
pushNewVerticesIdxImpl(triInVertices[0], triInVertices[1], triInVertices[2], t, rgbaColor);
}
@@ -494,9 +523,9 @@ public abstract class Region {
tris++;
}
if( null != perf ) {
- final long t2 = System.nanoTime();
- perf.tac_ns_triangles += t2-perf.t1;
- perf.tac_ns_total += t2-perf.t0;
+ final Instant ttriX = Clock.getMonotonicTime();
+ perf.td_tri_total += Duration.between(perf.t1, ttriX).toNanos();
+ perf.td_total += Duration.between(perf.t0, ttriX).toNanos();
}
}
if(DEBUG_INSTANCE) {
diff --git a/src/jogl/classes/com/jogamp/graph/font/Font.java b/src/jogl/classes/com/jogamp/graph/font/Font.java
index c9571da75..907bbde8a 100644
--- a/src/jogl/classes/com/jogamp/graph/font/Font.java
+++ b/src/jogl/classes/com/jogamp/graph/font/Font.java
@@ -29,6 +29,7 @@ package com.jogamp.graph.font;
import java.io.PrintStream;
+import com.jogamp.common.util.PerfCounterCtrl;
import com.jogamp.graph.curve.OutlineShape;
import com.jogamp.graph.geom.plane.AffineTransform;
import com.jogamp.opengl.math.geom.AABBox;
@@ -419,14 +420,7 @@ public interface Font {
final CharSequence string,
final AffineTransform temp1, final AffineTransform temp2);
- /** Enable or disable performance counter for {@link #processString(com.jogamp.graph.curve.OutlineShape.Visitor, AffineTransform, CharSequence, AffineTransform, AffineTransform)}. */
- void enablePerf(final boolean enable);
-
- /** Clear performance counter for {@link #processString(com.jogamp.graph.curve.OutlineShape.Visitor, AffineTransform, CharSequence, AffineTransform, AffineTransform)}. */
- void clearPerf();
-
- /** Print performance counter for {@link #processString(com.jogamp.graph.curve.OutlineShape.Visitor, AffineTransform, CharSequence, AffineTransform, AffineTransform)}. */
- void printPerf(final PrintStream out);
+ PerfCounterCtrl perfCounter();
/** Returns {@link #getFullFamilyName()} */
@Override
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java
index df138814f..ebc3eeacc 100644
--- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java
+++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java
@@ -43,9 +43,13 @@ import jogamp.graph.font.typecast.ot.table.KerningPair;
import jogamp.graph.font.typecast.ot.table.PostTable;
import java.io.PrintStream;
+import java.time.Duration;
+import java.time.Instant;
import java.util.concurrent.TimeUnit;
+import com.jogamp.common.os.Clock;
import com.jogamp.common.util.IntObjectHashMap;
+import com.jogamp.common.util.PerfCounterCtrl;
import com.jogamp.graph.curve.OutlineShape;
import com.jogamp.graph.font.Font;
import com.jogamp.graph.font.FontFactory;
@@ -364,53 +368,66 @@ class TypecastFont implements Font {
}
static class Perf {
- long t0;
- long tac_ns_visitor = 0;
- long tac_ns_total = 0;
- long tac_count = 0;
+ Instant t0 = null;
+ // all td_ values are in [ns]
+ long td_visitor = 0;
+ long td_total = 0;
+ long count = 0;
public void print(final PrintStream out) {
- out.printf("TypecastFont.process(): 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(" visitor %5d [ms], per-add %4.2f [ns]%n", TimeUnit.NANOSECONDS.toMillis(tac_ns_visitor),
- ((double)tac_ns_visitor/(double)tac_count));
+ out.printf("TypecastFont.process(): count %,3d, total %,5d [ms], per-add %,4.2f [ns]%n", count, TimeUnit.NANOSECONDS.toMillis(td_total),
+ ((double)td_total/(double)count));
+ out.printf(" visitor %,5d [ms], per-add %,4.2f [ns]%n", TimeUnit.NANOSECONDS.toMillis(td_visitor),
+ ((double)td_visitor/(double)count));
}
public void clear() {
- t0 = 0;
- tac_ns_visitor = 0;
- tac_ns_total = 0;
- tac_count = 0;
+ t0 = null;
+ td_visitor = 0;
+ td_total = 0;
+ count = 0;
}
}
- Perf perf = null;
+ private Perf perf = null;
- @Override
- public void enablePerf(final boolean enable) {
- if( enable ) {
+ private final PerfCounterCtrl perfCounterCtrl = new PerfCounterCtrl() {
+ @Override
+ public void enable(final boolean enable) {
+ if( enable ) {
+ if( null != perf ) {
+ perf.clear();
+ } else {
+ perf = new Perf();
+ }
+ } else {
+ perf = null;
+ }
+ }
+
+ @Override
+ public void clear() {
if( null != perf ) {
perf.clear();
- } else {
- perf = new Perf();
}
- } else {
- perf = null;
}
- }
- @Override
- public void clearPerf() {
- if( null != perf ) {
- perf.clear();
+ @Override
+ public Duration getTotalDuration() {
+ if( null != perf ) {
+ return Duration.ofNanos(perf.td_total);
+ } else {
+ return Duration.ZERO;
+ }
}
- }
+ @Override
+ public void print(final PrintStream out) {
+ if( null != perf ) {
+ perf.print(out);
+ }
+ } };
@Override
- public void printPerf(final PrintStream out) {
- if( null != perf ) {
- perf.print(out);
- }
- }
+ public PerfCounterCtrl perfCounter() { return perfCounterCtrl; }
@Override
public AABBox processString(final OutlineShape.Visitor visitor, final AffineTransform transform,
@@ -420,8 +437,8 @@ class TypecastFont implements Font {
return new AABBox();
}
if( null != perf ) {
- ++perf.tac_count;
- perf.t0 = System.nanoTime();
+ ++perf.count;
+ perf.t0 = Clock.getMonotonicTime();
}
final AABBox res = new AABBox();
final int charCount = string.length();
@@ -463,10 +480,10 @@ class TypecastFont implements Font {
temp1.translate(advanceTotal, y, temp2);
res.resize(temp1.transform(glyphShape.getBounds(), temp_box));
if( null != perf ) {
- final long t1 = System.nanoTime();
+ final Instant t1 = Clock.getMonotonicTime();
visitor.visit(glyphShape, temp1);
- final long t2 = System.nanoTime();
- perf.tac_ns_visitor += t2-t1;
+ final Instant t2 = Clock.getMonotonicTime();
+ perf.td_visitor += Duration.between(t1, t2).toNanos();
} else {
visitor.visit(glyphShape, temp1);
}
@@ -475,8 +492,8 @@ class TypecastFont implements Font {
}
}
if( null != perf ) {
- final long tX = System.nanoTime();
- perf.tac_ns_total += tX-perf.t0;
+ final Instant tX = Clock.getMonotonicTime();
+ perf.td_total += Duration.between(perf.t0, tX).toNanos();
}
return res;
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java
index 5f4527e7a..84909298d 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java
@@ -30,6 +30,8 @@ package com.jogamp.opengl.test.junit.graph;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
+import java.time.Duration;
+import java.time.Instant;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
@@ -47,6 +49,7 @@ import org.junit.Test;
import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
+import com.jogamp.common.os.Clock;
import com.jogamp.common.util.IOUtil;
import com.jogamp.graph.curve.Region;
import com.jogamp.graph.curve.opengl.RenderState;
@@ -55,7 +58,6 @@ import com.jogamp.graph.curve.opengl.RegionRenderer;
import com.jogamp.graph.curve.opengl.TextRegionUtil;
import com.jogamp.graph.font.Font;
import com.jogamp.graph.font.FontFactory;
-import com.jogamp.graph.font.FontSet;
import com.jogamp.graph.geom.SVertex;
import com.jogamp.graph.geom.plane.AffineTransform;
import com.jogamp.junit.util.JunitTracer;
@@ -78,7 +80,7 @@ import com.jogamp.opengl.util.PMVMatrix;
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TestTextRendererNEWT00 extends UITestCase {
- static long t0;
+ final Instant t0 = Clock.getMonotonicTime();
static final boolean DEBUG = false;
static final boolean TRACE = false;
static long duration = 100; // ms
@@ -111,8 +113,6 @@ public class TestTextRendererNEWT00 extends UITestCase {
}
public static void main(final String args[]) throws IOException {
- t0 = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
-
boolean wait = false;
mainRun = true;
for(int i=0; i<args.length; i++) {
@@ -165,30 +165,34 @@ public class TestTextRendererNEWT00 extends UITestCase {
}
static class Perf {
- public long ta_graph = 0;
- public long ta_txt1 = 0;
- public long ta_txt2 = 0;
- public long ta_txt = 0;
- public long ta_draw = 0;
- public long ta_txt_draw = 0;
- public long ta_count = 0;
+ // all td_ values are in [ns]
+ public long td_graph = 0;
+ public long td_txt1 = 0;
+ public long td_txt2 = 0;
+ public long td_txt = 0;
+ public long td_draw = 0;
+ public long td_txt_draw = 0;
+ public long count = 0;
public void clear() {
- ta_graph = 0;
- ta_txt1 = 0;
- ta_txt2 = 0;
- ta_txt = 0;
- ta_draw = 0;
- ta_txt_draw = 0;
- ta_count = 0;
+ td_graph = 0;
+ td_txt1 = 0;
+ td_txt2 = 0;
+ td_txt = 0;
+ td_draw = 0;
+ td_txt_draw = 0;
+ count = 0;
}
public void print(final PrintStream out, final long frame, final String msg) {
- out.printf("%3d / %3d: Perf %s: Total: graph %2d, txt[1 %2d, 2 %2d, all %2d], draw %2d, txt+draw %2d [ms]%n",
- ta_count, frame, msg, ta_graph, ta_txt1, ta_txt2, ta_txt, ta_draw, ta_txt_draw);
- out.printf("%3d / %3d: Perf %s: PerLoop: graph %2.2f, txt[1 %2.2f, 2 %2.2f, all %2.2f], draw %2.2f, txt+draw %2.2f [ms]%n",
- ta_count, frame, msg, ta_graph/(double)ta_count, ta_txt1/(double)ta_count, ta_txt2/(double)ta_count,
- ta_txt/(double)ta_count, ta_draw/(double)ta_count, ta_txt_draw/(double)ta_count);
+ out.printf("%3d / %3d: Perf %s: Total: graph %,2d, txt[1 %,2d, 2 %,2d, all %,2d], draw %,2d, txt+draw %,2d [ms]%n",
+ count, frame, msg,
+ TimeUnit.NANOSECONDS.toMillis(td_graph), TimeUnit.NANOSECONDS.toMillis(td_txt1),
+ TimeUnit.NANOSECONDS.toMillis(td_txt2), TimeUnit.NANOSECONDS.toMillis(td_txt),
+ TimeUnit.NANOSECONDS.toMillis(td_draw), TimeUnit.NANOSECONDS.toMillis(td_txt_draw));
+ out.printf("%3d / %3d: Perf %s: PerLoop: graph %,4d, txt[1 %,4d, 2 %,4d, all %,4d], draw %,4d, txt+draw %,4d [ns]%n",
+ count, frame, msg,
+ td_graph/count, td_txt1/count, td_txt2/count, td_txt/count, td_draw/count, td_txt_draw/count );
}
}
@@ -205,7 +209,7 @@ public class TestTextRendererNEWT00 extends UITestCase {
glp = GLProfile.getGL2ES2();
}
- final long t1 = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
+ final Instant t1 = Clock.getMonotonicTime();
final GLCapabilities caps = new GLCapabilities( glp );
caps.setAlphaBits(4);
@@ -236,11 +240,12 @@ public class TestTextRendererNEWT00 extends UITestCase {
// FreeSerif ~ vertices 115/char, indices 61/char
final int vertices_per_char = 64; // 100;
final int indices_per_char = 33; // 50;
- final int char_count = text_1.length()+text_2.length(); // 1334
final GLRegion region;
if( do_perf ) {
+ final int char_count = text_1.length()+text_2.length(); // 664 + 670 = 1334
region = GLRegion.create(gl.getGLProfile(), renderModes, null, char_count*vertices_per_char, char_count*indices_per_char);
} else {
+ // final int char_count = text_1.length()+text_2.length(); // 664 + 670 = 1334
region = GLRegion.create(gl.getGLProfile(), renderModes, null);
// region.growBufferSize(char_count*vertices_per_char, char_count*indices_per_char);
}
@@ -248,16 +253,16 @@ public class TestTextRendererNEWT00 extends UITestCase {
final Perf perf;
if( do_perf ) {
perf = new Perf();
- region.enablePerf(true);
- font.enablePerf(true);
+ region.perfCounter().enable(true);
+ font.perfCounter().enable(true);
} else {
perf = null;
}
for(int loop_i=0; loop_i < loop_count; ++loop_i) {
- final long t2 = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); // all initialized but graph
+ final Instant t2 = Clock.getMonotonicTime(); // all initialized but graph
if( null != perf ) {
- ++perf.ta_count;
+ ++perf.count;
}
// init
@@ -279,11 +284,11 @@ public class TestTextRendererNEWT00 extends UITestCase {
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
region.clear(gl);
- final long t3 = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); // all initialized w/ graph
+ final Instant t3 = Clock.getMonotonicTime(); // all initialized w/ graph
final float dx = 0;
final float dy = drawable.getSurfaceHeight() - 3 * fontSize * font.getLineHeight();
- final long t4, t5;
+ final Instant t4, t5;
{
// all sizes in em
final float x_width = font.getAdvanceWidth( font.getGlyphID('X') );
@@ -292,19 +297,23 @@ public class TestTextRendererNEWT00 extends UITestCase {
t.setToTranslation(3*x_width, 0f);
final AABBox tbox_1 = font.getGlyphBounds(text_1);
final AABBox rbox_1 = TextRegionUtil.addStringToRegion(region, font, t, text_1, fg_color);
- t4 = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); // text_1 added to region
+ t4 = Clock.getMonotonicTime(); // text_1 added to region
if( 0 == loop_i && !do_perf ) {
System.err.println("Text_1: tbox "+tbox_1);
System.err.println("Text_1: rbox "+rbox_1);
}
- t.setToTranslation(3*x_width, -1f*(rbox_1.getHeight()+font.getLineHeight()));
- final AABBox tbox_2 = font.getGlyphBounds(text_2);
- final AABBox rbox_2 = TextRegionUtil.addStringToRegion(region, font, t, text_2, fg_color);
- t5 = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); // text_2 added to region
- if( 0 == loop_i && !do_perf ) {
- System.err.println("Text_1: tbox "+tbox_2);
- System.err.println("Text_1: rbox "+rbox_2);
+ if( true || !do_perf ) {
+ t.setToTranslation(3*x_width, -1f*(rbox_1.getHeight()+font.getLineHeight()));
+ final AABBox tbox_2 = font.getGlyphBounds(text_2);
+ final AABBox rbox_2 = TextRegionUtil.addStringToRegion(region, font, t, text_2, fg_color);
+ t5 = Clock.getMonotonicTime(); // text_2 added to region
+ if( 0 == loop_i && !do_perf ) {
+ System.err.println("Text_1: tbox "+tbox_2);
+ System.err.println("Text_1: rbox "+rbox_2);
+ }
+ } else {
+ t5 = t4;
}
}
@@ -314,32 +323,35 @@ public class TestTextRendererNEWT00 extends UITestCase {
pmv.glTranslatef(dx, dy, z0);
pmv.glScalef(fontSize, fontSize, 1f);
region.draw(gl, renderer, sampleCountIO);
- final long t6 = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); // text_1 added to region
+ final Instant t6 = Clock.getMonotonicTime(); // text_1 added to region
if( null != perf ) {
- final long td_graph = t3-t2;
- final long td_txt1 = t4-t3;
- final long td_txt2 = t5-t4;
- final long td_txt = t5-t3;
- final long td_draw = t6-t5;
- final long td_txt_draw = t6-t3;
- perf.ta_graph += td_graph;
- perf.ta_txt1 += td_txt1;
- perf.ta_txt2 += td_txt2;
- perf.ta_txt += td_txt;
- perf.ta_draw += td_draw;
- perf.ta_txt_draw += td_txt_draw;
+ final long td_graph = Duration.between(t2, t3).toNanos();
+ final long td_txt1 = Duration.between(t3, t4).toNanos();
+ final long td_txt2 = Duration.between(t4, t5).toNanos();
+ final long td_txt = Duration.between(t3, t5).toNanos();
+ final long td_draw = Duration.between(t5, t6).toNanos();
+ final long td_txt_draw = Duration.between(t3, t6).toNanos();
+ perf.td_graph += td_graph;
+ perf.td_txt1 += td_txt1;
+ perf.td_txt2 += td_txt2;
+ perf.td_txt += td_txt;
+ perf.td_draw += td_draw;
+ perf.td_txt_draw += td_txt_draw;
if( 0 == loop_i ) {
- final long td_launch0 = t1-t0; // raw
- final long td_launch1 = t2-t0; // gl
- final long td_launch2 = t3-t0; // w/ graph
- final long td_launch_txt = t5-t0;
- final long td_launch_draw = t6-t0;
- System.err.printf("%3d: Perf Launch: raw %4d, gl %4d, graph %4d, txt %4d, draw %4d [ms]%n",
+ final long td_launch0 = Duration.between(t0, t1).toMillis(); // raw
+ final long td_launch1 = Duration.between(t0, t2).toMillis(); // gl
+ final long td_launch2 = Duration.between(t0, t3).toMillis(); // w/ graph
+ final long td_launch_txt = Duration.between(t0, t5).toMillis();
+ final long td_launch_draw = Duration.between(t0, t6).toMillis();
+ System.err.printf("%3d: Perf Launch: raw %,4d, gl %,4d, graph %,4d, txt %,4d, draw %,4d [ms]%n",
loop_i+1, td_launch0, td_launch1, td_launch2, td_launch_txt, td_launch_draw);
perf.print(System.err, loop_i+1, "Launch");
} else {
System.err.printf("%3d: Perf: graph %2d, txt[1 %2d, 2 %2d, all %2d], draw %2d, txt+draw %2d [ms]%n",
- loop_i+1, td_graph, td_txt1, td_txt2, td_txt, td_draw, td_txt_draw);
+ loop_i+1,
+ TimeUnit.NANOSECONDS.toMillis(td_graph), TimeUnit.NANOSECONDS.toMillis(td_txt1),
+ TimeUnit.NANOSECONDS.toMillis(td_txt2), TimeUnit.NANOSECONDS.toMillis(td_txt),
+ TimeUnit.NANOSECONDS.toMillis(td_draw), TimeUnit.NANOSECONDS.toMillis(td_txt_draw) );
}
}
if( loop_count - 1 == loop_i && !do_perf ) {
@@ -350,12 +362,12 @@ public class TestTextRendererNEWT00 extends UITestCase {
drawable.swapBuffers();
if( null != perf && loop_count/3-1 == loop_i ) {
// print + reset counter @ 1/3 loops
- region.printPerf(System.err);
- font.printPerf(System.err);
+ region.perfCounter().print(System.err);
+ font.perfCounter().print(System.err);
perf.print(System.err, loop_i+1, "Frame"+(loop_count/3));
perf.clear();
- region.clearPerf();
- font.clearPerf();
+ region.perfCounter().clear();
+ font.perfCounter().clear();
}
if( 0 == loop_i || loop_count - 1 == loop_i) {
// print counter @ start and end
@@ -363,8 +375,8 @@ public class TestTextRendererNEWT00 extends UITestCase {
System.err.println("GLRegion: "+region);
System.err.println("Text length: text_1 "+text_1.length()+", text_2 "+text_2.length()+", total "+(text_1.length()+text_2.length()));
region.printBufferStats(System.err);
- region.printPerf(System.err);
- font.printPerf(System.err);
+ region.perfCounter().print(System.err);
+ font.perfCounter().print(System.err);
}
// region.destroy(gl);
}