From eaa81d524e9be6af9867c8b6750505c8660a6651 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 5 Dec 2019 07:05:14 +0100 Subject: Bug 1406, Bug 1405: demos.Launcher0: Allow passing GLEventListener via '-demo classname' --- src/demos/com/jogamp/opengl/demos/Launcher0.java | 48 +++++++++++++++++------- 1 file changed, 34 insertions(+), 14 deletions(-) (limited to 'src/demos') diff --git a/src/demos/com/jogamp/opengl/demos/Launcher0.java b/src/demos/com/jogamp/opengl/demos/Launcher0.java index a9fb104c7..02bfa3c66 100644 --- a/src/demos/com/jogamp/opengl/demos/Launcher0.java +++ b/src/demos/com/jogamp/opengl/demos/Launcher0.java @@ -29,20 +29,20 @@ package com.jogamp.opengl.demos; import java.io.IOException; +import java.lang.reflect.Constructor; import com.jogamp.newt.Display; import com.jogamp.newt.Display.PointerIcon; import com.jogamp.newt.NewtFactory; import com.jogamp.newt.Screen; -import com.jogamp.newt.Window; import com.jogamp.newt.event.WindowEvent; import com.jogamp.newt.event.TraceMouseAdapter; import com.jogamp.newt.event.WindowAdapter; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.newt.opengl.util.NEWTDemoListener; -import com.jogamp.newt.util.EDTUtil; import com.jogamp.opengl.util.Animator; import com.jogamp.opengl.util.AnimatorBase; +import com.jogamp.common.util.ReflectionUtil; import com.jogamp.nativewindow.ScalableSurface; import com.jogamp.nativewindow.util.Dimension; import com.jogamp.nativewindow.util.Point; @@ -55,9 +55,7 @@ import com.jogamp.opengl.GLCapabilities; import com.jogamp.opengl.GLEventListener; import com.jogamp.opengl.GLPipelineFactory; import com.jogamp.opengl.GLProfile; -import com.jogamp.opengl.demos.es2.GearsES2; - -import jogamp.newt.DefaultEDTUtil; +import com.jogamp.opengl.demos.es2.RedSquareES2; /** *

@@ -73,6 +71,7 @@ public class Launcher0 { static DimensionImmutable wsize = new Dimension(640, 480), rwsize=null; static float[] reqSurfacePixelScale = new float[] { ScalableSurface.AUTOMAX_PIXELSCALE, ScalableSurface.AUTOMAX_PIXELSCALE }; + static String demoName = "com.jogamp.opengl.demos.es2.GearsES2"; static long duration = 500; // ms static boolean opaque = true; static int forceAlpha = -1; @@ -100,7 +99,6 @@ public class Launcher0 { static boolean traceMouse = false; static boolean exclusiveContext = false; static boolean useAnimator = true; - static boolean useMappedBuffers = false; public void runTest() throws InterruptedException { final GLProfile glp; @@ -145,11 +143,32 @@ public class Launcher0 { final GLEventListener demo; { - final GearsES2 gearsES2 = new GearsES2(swapInterval); - gearsES2.setUseMappedBuffers(useMappedBuffers); - gearsES2.setValidateBuffers(true); - demo = gearsES2; + GLEventListener _demo = null; + try { + final Class demoClazz = ReflectionUtil.getClass(demoName, true, Launcher0.class.getClassLoader()); + try { + // with swapInterval + System.err.println("Loading "+demoName+"("+swapInterval+")"); + final Constructor ctr = ReflectionUtil.getConstructor(demoClazz, int.class); + _demo = (GLEventListener) ReflectionUtil.createInstance(ctr, swapInterval); + } catch( final Exception e ) { + System.err.println(e.getMessage()+" using.0: <"+demoName+">"); + } + if( null == _demo ) { + // without swapInterval + System.err.println("Loading "+demoName+"()"); + _demo = (GLEventListener) ReflectionUtil.createInstance(demoClazz); + } + } catch( final Exception e ) { + System.err.println(e.getMessage()+" using.1: <"+demoName+">"); + } + if( null == _demo ) { + System.err.println("Loading RedSquareES2()"); + _demo = new RedSquareES2(); + } + demo = _demo; } + System.out.println("Choosen demo "+demo.getClass().getName()); if( forceDebug || forceTrace ) { glWindow.addGLEventListener(new GLEventListener() { @Override @@ -263,6 +282,7 @@ public class Launcher0 { while(!newtDemoListener.shouldQuit() && t1-t0