diff options
author | Sven Gothel <[email protected]> | 2023-03-07 04:05:10 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-03-07 04:05:10 +0100 |
commit | 14a47f60d2dc7c4f6b2d910fcc8489726443db22 (patch) | |
tree | 22a766ffe9424cd60855c4b5502afa10349966ae /src/test/com/jogamp/opengl | |
parent | fb03e913c0c55a9a96e93a00ef6590b9bea9a62a (diff) |
Graph Perf Test: {Test->Perf}TextRendererNEWT00: Drop junit, ... (WIP)
Also tested w/ alternative JVM (Azul) .. works well, no big difference (but slower startup time, but might be OpenJDK 17->19 related as well).
Printing usual system infos to make the test record useful.
Cmdline is: com.jogamp.opengl.test.junit.graph.PerfTextRendererNEWT00 -es2 -Nperf -long_text -loop 40
Diffstat (limited to 'src/test/com/jogamp/opengl')
-rw-r--r-- | src/test/com/jogamp/opengl/test/junit/graph/PerfTextRendererNEWT00.java (renamed from src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java) | 122 | ||||
-rw-r--r-- | src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java | 8 |
2 files changed, 58 insertions, 72 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java b/src/test/com/jogamp/opengl/test/junit/graph/PerfTextRendererNEWT00.java index 353b21e1f..f8fd06695 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/PerfTextRendererNEWT00.java @@ -41,16 +41,13 @@ import com.jogamp.opengl.GLCapabilities; import com.jogamp.opengl.GLDrawable; import com.jogamp.opengl.GLException; import com.jogamp.opengl.GLProfile; +import com.jogamp.opengl.JoglVersion; import com.jogamp.opengl.fixedfunc.GLMatrixFunc; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.FixMethodOrder; -import org.junit.runners.MethodSorters; - import com.jogamp.common.os.Clock; +import com.jogamp.common.os.Platform; import com.jogamp.common.util.IOUtil; +import com.jogamp.common.util.VersionUtil; import com.jogamp.graph.curve.Region; import com.jogamp.graph.curve.opengl.RenderState; import com.jogamp.graph.curve.opengl.GLRegion; @@ -60,11 +57,9 @@ import com.jogamp.graph.font.Font; import com.jogamp.graph.font.FontFactory; import com.jogamp.graph.geom.SVertex; import com.jogamp.graph.geom.plane.AffineTransform; -import com.jogamp.junit.util.JunitTracer; import com.jogamp.opengl.math.geom.AABBox; import com.jogamp.opengl.test.junit.util.MiscUtils; import com.jogamp.opengl.test.junit.util.NEWTGLContext; -import com.jogamp.opengl.test.junit.util.UITestCase; import com.jogamp.opengl.util.GLReadBufferUtil; import com.jogamp.opengl.util.PMVMatrix; @@ -78,8 +73,7 @@ import com.jogamp.opengl.util.PMVMatrix; * - Using a single GLRegion instantiation * - Single GLRegion is filled once with shapes from text */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class TestTextRendererNEWT00 extends UITestCase { +public class PerfTextRendererNEWT00 { static final Instant t0i = Clock.getMonotonicTime(); static final long t0 = Clock.currentNanos(); static final boolean DEBUG = false; @@ -87,51 +81,46 @@ public class TestTextRendererNEWT00 extends UITestCase { static long duration = 100; // ms static boolean forceES2 = false; static boolean forceGL3 = false; - static boolean mainRun = false; static int win_width = 1280; static int win_height = 720; static int loop_count = 1; static boolean do_perf = false; + static boolean do_snap = false; static Font font; static float fontSize = 24; // in pixel private final float[] fg_color = new float[] { 0, 0, 0, 1 }; - @BeforeClass - public static void setup() throws IOException { - if( null == font ) { + static { + try { font = FontFactory.get(IOUtil.getResource("fonts/freefont/FreeSans.ttf", - FontSet01.class.getClassLoader(), FontSet01.class).getInputStream(), true); + FontSet01.class.getClassLoader(), FontSet01.class).getInputStream(), true); // font = FontFactory.get(FontFactory.UBUNTU).get(FontSet.FAMILY_LIGHT, FontSet.STYLE_NONE); + } catch (final IOException e) { + e.printStackTrace(); } } - static int atoi(final String a) { - try { - return Integer.parseInt(a); - } catch (final Exception ex) { throw new RuntimeException(ex); } - } - - public static void main(final String args[]) throws IOException { + public static void main(final String args[]) throws IOException, GLException, InterruptedException { + String text = PerfTextRendererNEWT00.text_1; boolean wait = false; - mainRun = true; for(int i=0; i<args.length; i++) { if(args[i].equals("-time")) { i++; - duration = atoi(args[i]); + duration = MiscUtils.atol(args[i], duration); } else if(args[i].equals("-width")) { i++; - win_width = atoi(args[i]); + win_width = MiscUtils.atoi(args[i], win_width); } else if(args[i].equals("-height")) { i++; - win_height = atoi(args[i]); + win_height = MiscUtils.atoi(args[i], win_height); } else if(args[i].equals("-es2")) { forceES2 = true; } else if(args[i].equals("-gl3")) { forceGL3 = true; } else if(args[i].equals("-font")) { i++; - font = FontFactory.get(IOUtil.getResource(args[i], TestTextRendererNEWT00.class.getClassLoader(), TestTextRendererNEWT00.class).getInputStream(), true); + font = FontFactory.get(IOUtil.getResource(args[i], PerfTextRendererNEWT00.class.getClassLoader(), PerfTextRendererNEWT00.class).getInputStream(), true); } else if(args[i].equals("-fontSize")) { i++; fontSize = MiscUtils.atof(args[i], fontSize); @@ -143,16 +132,23 @@ public class TestTextRendererNEWT00 extends UITestCase { if( 0 >= loop_count ) { loop_count = Integer.MAX_VALUE; } + } else if(args[i].equals("-long_text")) { + text = PerfTextRendererNEWT00.text_long; } else if(args[i].equals("-perf")) { do_perf = true; + } else if(args[i].equals("-snap")) { + do_snap = true; } } System.err.println("Performance test enabled: "+do_perf); if( wait ) { - JunitTracer.waitForKey("Start"); + MiscUtils.waitForKey("Start"); } - final String tstname = TestTextRendererNEWT00.class.getName(); - org.junit.runner.JUnitCore.main(tstname); + final int renderModes = Region.VBAA_RENDERING_BIT /* | Region.COLORCHANNEL_RENDERING_BIT */; + final int sampleCount = 4; + + final PerfTextRendererNEWT00 obj = new PerfTextRendererNEWT00(); + obj.test(renderModes, sampleCount, text); } static void sleep() { @@ -205,11 +201,7 @@ public class TestTextRendererNEWT00 extends UITestCase { } } - @SuppressWarnings("unused") - @Test - public void test02TextRendererVBAA04() throws InterruptedException, GLException, IOException { - final int renderModes = Region.VBAA_RENDERING_BIT /* | Region.COLORCHANNEL_RENDERING_BIT */; - final int sampleCount = 4; + public void test(final int renderModes, final int sampleCount, final String text) throws InterruptedException, GLException, IOException { final GLProfile glp; if(forceGL3) { glp = GLProfile.get(GLProfile.GL3); @@ -224,8 +216,6 @@ public class TestTextRendererNEWT00 extends UITestCase { final GLCapabilities caps = new GLCapabilities( glp ); caps.setAlphaBits(4); - System.err.println("Requested Caps: "+caps); - System.err.println("Requested Region-RenderModes: "+Region.getRenderModeString(renderModes)); final NEWTGLContext.WindowContext winctx = NEWTGLContext.createWindow(caps, win_width, win_height, false); // true); final GLDrawable drawable = winctx.context.getGLDrawable(); @@ -233,9 +223,19 @@ public class TestTextRendererNEWT00 extends UITestCase { if( do_perf ) { gl.setSwapInterval(0); } - Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + { + final int glerr = gl.glGetError(); + if( GL.GL_NO_ERROR != glerr ) { + System.err.println("Initial GL Error: "+glerr); + } + } + System.err.println(VersionUtil.getPlatformInfo()); + System.err.println(JoglVersion.getInstance().toString(winctx.context.getGL())); - System.err.println("Chosen: "+winctx.window.getChosenCapabilities()); + System.err.println("Requested Caps: "+caps); + System.err.println("Requested Region-RenderModes: "+Region.getRenderModeString(renderModes)); + System.err.println("Chosen Caps: "+winctx.window.getChosenCapabilities()); + System.err.println("Chosen Font: "+font.getFullFamilyName()); final GLReadBufferUtil screenshot = new GLReadBufferUtil(false, false); @@ -246,20 +246,12 @@ public class TestTextRendererNEWT00 extends UITestCase { // Since we know about the size ... // final GLRegion region = GLRegion.create(gl.getGLProfile(), renderModes, null); // region.growBufferSize(123000, 62000); // hack-me - // FreeSans ~ vertices 64/char, indices 33/char + // FreeSans ~ vertices 68/char, indices 36/char // Ubuntu Light ~ vertices 100/char, indices 50/char // FreeSerif ~ vertices 115/char, indices 61/char - final int vertices_per_char = 64; // 100; - final int indices_per_char = 33; // 50; - final GLRegion region; - if( do_perf ) { - final int char_count = text_1.length(); // 1296 - 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(); // 1296 - region = GLRegion.create(gl.getGLProfile(), renderModes, null); - // region.growBufferSize(char_count*vertices_per_char, char_count*indices_per_char); - } + final int vertices_per_char = 68; // 100; + final int indices_per_char = 36; // 50; + final GLRegion region = GLRegion.create(gl.getGLProfile(), renderModes, null, text.length()*vertices_per_char, text.length()*indices_per_char); final Perf perf = new Perf(); if( do_perf ) { @@ -303,9 +295,9 @@ public class TestTextRendererNEWT00 extends UITestCase { final AffineTransform t = new AffineTransform(); 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 = Clock.currentNanos(); // text_1 added to region + final AABBox tbox_1 = font.getGlyphBounds(text); + final AABBox rbox_1 = TextRegionUtil.addStringToRegion(region, font, t, text, fg_color); + t4 = Clock.currentNanos(); // text 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); @@ -318,7 +310,7 @@ public class TestTextRendererNEWT00 extends UITestCase { pmv.glTranslatef(dx, dy, z0); pmv.glScalef(fontSize, fontSize, 1f); region.draw(gl, renderer, sampleCountIO); - final long t5 = Clock.currentNanos(); // text_1 added to region + final long t5 = Clock.currentNanos(); // text added to region if( null != perf ) { final long td_graph = t3 - t2; final long td_txt = t4 - t3; @@ -350,14 +342,9 @@ public class TestTextRendererNEWT00 extends UITestCase { TimeUnit.NANOSECONDS.toMillis(td_launch3), TimeUnit.NANOSECONDS.toMillis(td_launch_txt), TimeUnit.NANOSECONDS.toMillis(td_launch_draw)); perf.print(System.err, loop_i+1, "Launch"); - } else if( false && do_perf ) { - System.err.printf("%3d: Perf: graph %2d, txt %2d, draw %2d, txt+draw %2d [ms]%n", - loop_i+1, - TimeUnit.NANOSECONDS.toMillis(td_graph),TimeUnit.NANOSECONDS.toMillis(td_txt), - TimeUnit.NANOSECONDS.toMillis(td_draw), TimeUnit.NANOSECONDS.toMillis(td_txt_draw) ); } } - if( loop_count - 1 == loop_i && !do_perf ) { + if( loop_count - 1 == loop_i && do_snap ) { // print screen at end gl.glFinish(); printScreen(screenshot, renderModes, drawable, gl, false, sampleCount); @@ -380,7 +367,7 @@ public class TestTextRendererNEWT00 extends UITestCase { // print counter @ start and end System.err.println("GLRegion: for "+gl.getGLProfile()+" using int32_t indiced: "+region.usesI32Idx()); System.err.println("GLRegion: "+region); - System.err.println("Text length: "+text_1.length()); + System.err.println("Text length: "+text.length()); region.printBufferStats(System.err); if( do_perf ) { region.perfCounter().print(System.err); @@ -401,7 +388,7 @@ public class TestTextRendererNEWT00 extends UITestCase { NEWTGLContext.destroyWindow(winctx); } - public static final String text_1a = + public static final String text_long = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nec sapien tellus. \n"+ "Ut purus odio, rhoncus sit amet commodo eget, ullamcorper vel urna. Mauris ultricies \n"+ "quam iaculis urna cursus ornare. Nullam ut felis a ante ultrices ultricies nec a elit. \n"+ @@ -444,15 +431,6 @@ public class TestTextRendererNEWT00 extends UITestCase { "in lorem. Maecenas in ipsum ac justo scelerisque sollicitudin. Quisque sit amet neque lorem, \n" + "-------Press H to change text---------"; - public static final String text_2s = "JogAmp reborn ;-)"; - public static final String text_2 = - "I “Ask Jeff” or ‘Ask Jeff’. Take the chef d’œuvre! Two of [of] (of) ‘of’ “of” of? of! of*. X\n"+ - "Les Woëvres, the Fôret de Wœvres, the Voire and Vauvise. Yves is in heaven; D’Amboise is in jail. X\n"+ - "Lyford’s in Texas & L’Anse-aux-Griffons in Québec; the Łyna in Poland. Yriarte, Yciar and Ysaÿe are at Yale. X\n"+ - "Kyoto and Ryotsu are both in Japan, Kwikpak on the Yukon delta, Kvæven in Norway, Kyulu in Kenya, not in Rwanda.… X\n"+ - "Von-Vincke-Straße in Münster, Vdovino in Russia, Ytterbium in the periodic table. Are Toussaint L’Ouverture, Wölfflin, Wolfe, X\n"+ - "Miłosz and Wū Wŭ all in the library? 1510–1620, 11:00 pm, and the 1980s are over. X\n"+ - "-------Press H to change text---------"; public static void printScreen(final GLReadBufferUtil screenshot, final int renderModes, final GLDrawable drawable, final GL gl, final boolean exportAlpha, final int sampleCount) throws GLException, IOException { final int screenshot_num = 0; diff --git a/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java b/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java index bf656bb4d..7f35d7a86 100644 --- a/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java +++ b/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java @@ -97,6 +97,14 @@ public class MiscUtils { return "0x" + Long.toHexString( hex ); } + public static void waitForKey(final String preMessage) { + final BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); + System.err.println(preMessage+"> Press enter to continue"); + try { + System.err.println(stdin.readLine()); + } catch (final IOException e) { e.printStackTrace(); } + } + public static void assertFloatBufferEquals(final String errmsg, final FloatBuffer expected, final FloatBuffer actual, final float delta) { if(null == expected && null == actual) { return; |