diff options
author | Sven Gothel <[email protected]> | 2014-05-27 23:45:52 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-05-27 23:45:52 +0200 |
commit | c142f237d171e1cd16918a2f897447444a709b56 (patch) | |
tree | 0f40edc26ad3e9630653b68b585581cf393b37a9 /src | |
parent | 8b255eb303bba045b4eb087da1d1cb33b2e89e96 (diff) |
GraphUI: Fix label layout (absolute), add auto no-aa dpi threshold (200 dpi), add all modes to applet test-page
Diffstat (limited to 'src')
4 files changed, 237 insertions, 19 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener04.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener04.java new file mode 100644 index 000000000..461e2c114 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener04.java @@ -0,0 +1,7 @@ +package com.jogamp.opengl.test.junit.graph.demos; + +public class GPUUISceneGLListener04 extends GPUUISceneGLListener0A { + public GPUUISceneGLListener04() { + super(GPUUISceneGLListener0A.DefaultNoAADPIThreshold /* noAADPIThreshold */); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java index b52668294..6a1f60de7 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java @@ -5,6 +5,7 @@ import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import javax.media.opengl.GL; @@ -52,10 +53,12 @@ public class GPUUISceneGLListener0A implements GLEventListener { private boolean debug = false; private boolean trace = false; - private final int renderModes; + private final float noAADPIThreshold; private final RenderState rs; private final SceneUIController sceneUIController; + /** -1 == AUTO, TBD @ init(..) */ + private int renderModes; private RegionRenderer renderer; private final int fontSet = FontFactory.UBUNTU; @@ -78,6 +81,13 @@ public class GPUUISceneGLListener0A implements GLEventListener { private final float fontSizeFpsPVP = 0.038f; private float dpiH = 96; + /** + * Default DPI threshold value to disable {@link Region#VBAA_RENDERING_BIT VBAA}: {@value} dpi + * @see #GPUUISceneGLListener0A(float) + * @see #GPUUISceneGLListener0A(float, boolean, boolean) + */ + public static final float DefaultNoAADPIThreshold = 180f; + private int currentText = 0; private String actionText = null; @@ -102,16 +112,46 @@ public class GPUUISceneGLListener0A implements GLEventListener { this(0); } + /** + * @param noAADPIThreshold see {@link #DefaultNoAADPIThreshold} + */ + public GPUUISceneGLListener0A(final float noAADPIThreshold) { + this(noAADPIThreshold, false, false); + } + + /** + * @param renderModes + */ public GPUUISceneGLListener0A(int renderModes) { - this(RenderState.createRenderState(SVertex.factory()), renderModes, false, false); + this(renderModes, false, false); } - public GPUUISceneGLListener0A(RenderState rs, int renderModes, boolean debug, boolean trace) { - this.rs = rs; - this.renderModes = renderModes; + /** + * @param renderModes + * @param debug + * @param trace + */ + public GPUUISceneGLListener0A(int renderModes, boolean debug, boolean trace) { + this(0f, renderModes, debug, trace); + } + + /** + * @param noAADPIThreshold see {@link #DefaultNoAADPIThreshold} + * @param debug + * @param trace + */ + public GPUUISceneGLListener0A(final float noAADPIThreshold, boolean debug, boolean trace) { + this(noAADPIThreshold, -1, debug, trace); + } + private GPUUISceneGLListener0A(final float noAADPIThreshold, int renderModes, boolean debug, boolean trace) { + this.noAADPIThreshold = noAADPIThreshold; + this.rs = RenderState.createRenderState(SVertex.factory()); this.debug = debug; this.trace = trace; + + this.renderModes = renderModes; + try { font = FontFactory.get(FontFactory.UBUNTU).getDefault(); } catch (IOException ioe) { @@ -593,6 +633,12 @@ public class GPUUISceneGLListener0A implements GLEventListener { } else { System.err.println("Using default DPI of "+dpiH); } + if( 0 > renderModes ) { + final boolean noAA = dpiH >= noAADPIThreshold; + final String noAAs = noAA ? " >= " : " < "; + System.err.println("AUTO RenderMode: dpi "+dpiH+noAAs+noAADPIThreshold+" -> noAA "+noAA); + renderModes = noAA ? 0 : Region.VBAA_RENDERING_BIT; + } if(drawable instanceof GLWindow) { System.err.println("GPUUISceneGLListener0A: init (1)"); final GLWindow glw = (GLWindow) drawable; @@ -715,15 +761,17 @@ public class GPUUISceneGLListener0A implements GLEventListener { if(null == labels[currentText]) { final float pixelSizeFixed = fontSizeFixedPVP * drawable.getSurfaceHeight(); final float dyTop = drawable.getSurfaceHeight() - 2f*jogampLabel.getLineHeight(); - final float dxRight = drawable.getSurfaceWidth() * relMiddle; + final float dxMiddle = drawable.getSurfaceWidth() * relMiddle; labels[currentText] = new Label(renderer.getRenderState().getVertexFactory(), renderModes, font, pixelSizeFixed, strings[currentText]); labels[currentText].setColor(0.1f, 0.1f, 0.1f, 1.0f); labels[currentText].setEnabled(enableOthers); - labels[currentText].translate(dxRight, + labels[currentText].translate(dxMiddle, dyTop - 1.5f * jogampLabel.getLineHeight() - 1.5f * truePtSizeLabel.getLineHeight(), 0f); labels[currentText].addMouseListener(dragZoomRotateListener); sceneUIController.addShape(labels[currentText]); + System.err.println("Label["+currentText+"] CTOR: "+labels[currentText]); + System.err.println("Label["+currentText+"] CTOR: "+Arrays.toString(labels[currentText].getTranslate())); } if( fpsLabel.isEnabled() ) { final float lfps, tfps, td; @@ -741,8 +789,8 @@ public class GPUUISceneGLListener0A implements GLEventListener { final String text; if( null == actionText ) { final String timePrec = gl.isGLES() ? "4.0" : "4.1"; - text = String.format("%03.1f/%03.1f fps, v-sync %d, fontSize %.1f, %s-samples %d, q %d, td %"+timePrec+"f, blend %b, alpha-bits %d, msaa-bits %d", - lfps, tfps, gl.getSwapInterval(), fontSizeFixedPVP, modeS, sceneUIController.getSampleCount(), fpsLabel.getQuality(), td, + text = String.format("%03.1f/%03.1f fps, v-sync %d, dpi %.1f, fontSize %.1f, %s-samples %d, q %d, td %"+timePrec+"f, blend %b, alpha %d, msaa %d", + lfps, tfps, gl.getSwapInterval(), dpiH, fontSizeFixedPVP, modeS, sceneUIController.getSampleCount(), fpsLabel.getQuality(), td, renderer.getRenderState().isHintMaskSet(RenderState.BITHINT_BLENDING_ENABLED), drawable.getChosenGLCapabilities().getAlphaBits(), drawable.getChosenGLCapabilities().getNumSamples()); @@ -780,12 +828,18 @@ public class GPUUISceneGLListener0A implements GLEventListener { for(int i=buttonsLeftCount; i<buttons.size(); i++) { buttons.get(i).translate(dxRight, dyTop, dz); } - final float dyTopLabel = drawable.getSurfaceHeight() - 2f*jogampLabel.getLineHeight(); - jogampLabel.translate(dxMiddle, dyTopLabel, dz); - truePtSizeLabel.translate(dxMiddle, dyTopLabel, dz); + final float dxMiddleAbs = width * relMiddle; + final float dyTopLabelAbs = drawable.getSurfaceHeight() - 2f*jogampLabel.getLineHeight(); + jogampLabel.setTranslate(dxMiddleAbs, dyTopLabelAbs, dz); + truePtSizeLabel.setTranslate(dxMiddleAbs, dyTopLabelAbs, dz); + truePtSizeLabel.setTranslate(dxMiddleAbs, dyTopLabelAbs - 1.5f * jogampLabel.getLineHeight(), 0f); fpsLabel.translate(0f, 0f, 0f); if( null != labels[currentText] ) { - labels[currentText].translate(dxMiddle, dyTopLabel, 0f); + labels[currentText].setTranslate(dxMiddleAbs, + dyTopLabelAbs - 1.5f * jogampLabel.getLineHeight() + - 1.5f * truePtSizeLabel.getLineHeight(), 0f); + System.err.println("Label["+currentText+"] MOVE: "+labels[currentText]); + System.err.println("Label["+currentText+"] MOVE: "+Arrays.toString(labels[currentText].getTranslate())); } crossHairCtr.translate(dw/2f, dh/2f, 0f); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtCanvasAWTDemo.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtCanvasAWTDemo.java new file mode 100644 index 000000000..a80b70830 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtCanvasAWTDemo.java @@ -0,0 +1,147 @@ +package com.jogamp.opengl.test.junit.graph.demos; + +import java.awt.Component; +import java.awt.Frame; +import java.lang.reflect.InvocationTargetException; + +import javax.media.nativewindow.util.Dimension; +import javax.media.nativewindow.util.DimensionImmutable; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; +import javax.swing.SwingUtilities; + +import org.junit.Assume; + +import com.jogamp.graph.curve.Region; +import com.jogamp.newt.awt.NewtCanvasAWT; +import com.jogamp.newt.event.WindowAdapter; +import com.jogamp.newt.event.WindowEvent; +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.test.junit.util.MiscUtils; +import com.jogamp.opengl.util.Animator; + +public class GPUUISceneNewtCanvasAWTDemo { + static final boolean DEBUG = false; + static final boolean TRACE = false; + + static int SceneMSAASamples = 0; + static boolean GraphVBAAMode = false; + static boolean GraphMSAAMode = false; + static float GraphAutoMode = GPUUISceneGLListener0A.DefaultNoAADPIThreshold; + + static void setComponentSize(final Component comp, final DimensionImmutable new_sz) { + try { + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + java.awt.Dimension d = new java.awt.Dimension(new_sz.getWidth(), new_sz.getHeight()); + comp.setMinimumSize(d); + comp.setPreferredSize(d); + comp.setSize(d); + } } ); + } catch( Throwable throwable ) { + throwable.printStackTrace(); + Assume.assumeNoException( throwable ); + } + } + + public static void main(String[] args) throws InterruptedException, InvocationTargetException { + int width = 800, height = 400; + int x = 10, y = 10; + if( 0 != args.length ) { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-smsaa")) { + i++; + SceneMSAASamples = MiscUtils.atoi(args[i], SceneMSAASamples); + GraphMSAAMode = false; + GraphVBAAMode = false; + GraphAutoMode = 0f; + } else if(args[i].equals("-gmsaa")) { + GraphMSAAMode = true; + GraphVBAAMode = false; + GraphAutoMode = 0f; + } else if(args[i].equals("-gvbaa")) { + GraphMSAAMode = false; + GraphVBAAMode = true; + GraphAutoMode = 0f; + } else if(args[i].equals("-gauto")) { + GraphMSAAMode = false; + GraphVBAAMode = true; + i++; + GraphAutoMode = MiscUtils.atof(args[i], GraphAutoMode); + } else if(args[i].equals("-width")) { + i++; + width = MiscUtils.atoi(args[i], width); + } else if(args[i].equals("-height")) { + i++; + height = MiscUtils.atoi(args[i], height); + } else if(args[i].equals("-x")) { + i++; + x = MiscUtils.atoi(args[i], x); + } else if(args[i].equals("-y")) { + i++; + y = MiscUtils.atoi(args[i], y); + } + } + } + System.err.println("Desired win size "+width+"x"+height); + System.err.println("Desired win pos "+x+"/"+y); + System.err.println("Scene MSAA Samples "+SceneMSAASamples); + System.err.println("Graph MSAA Mode "+GraphMSAAMode); + System.err.println("Graph VBAA Mode "+GraphVBAAMode); + System.err.println("Graph Auto Mode "+GraphAutoMode+" no-AA dpi threshold"); + + GLProfile glp = GLProfile.getGL2ES2(); + GLCapabilities caps = new GLCapabilities(glp); + caps.setAlphaBits(4); + if( SceneMSAASamples > 0 ) { + caps.setSampleBuffers(true); + caps.setNumSamples(SceneMSAASamples); + } + System.out.println("Requested: " + caps); + + final int rmode; + if( 0 < GraphAutoMode ) { + rmode = -1; + } else if( GraphVBAAMode ) { + rmode = Region.VBAA_RENDERING_BIT; + } else if( GraphMSAAMode ) { + rmode = Region.MSAA_RENDERING_BIT; + } else { + rmode = 0; + } + + final GLWindow window = GLWindow.create(caps); + window.setPosition(x, y); + window.setSize(width, height); + window.setTitle("GraphUI Newt Demo: graph["+Region.getRenderModeString(rmode)+"], msaa "+SceneMSAASamples); + + GPUUISceneGLListener0A sceneGLListener = 0 < GraphAutoMode ? new GPUUISceneGLListener0A(GraphAutoMode, DEBUG, TRACE) : + new GPUUISceneGLListener0A(rmode, DEBUG, TRACE); + + window.addGLEventListener(sceneGLListener); + sceneGLListener.attachInputListenerTo(window); + + final Animator animator = new Animator(); + animator.setUpdateFPSFrames(60, System.err); + animator.add(window); + + window.addWindowListener(new WindowAdapter() { + public void windowDestroyed(WindowEvent e) { + animator.stop(); + } + }); + + final NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(window); + final Frame frame = new Frame("GraphUI Newt Demo: graph["+Region.getRenderModeString(rmode)+"], msaa "+SceneMSAASamples); + + setComponentSize(newtCanvasAWT, new Dimension(width, height)); + frame.add(newtCanvasAWT); + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame.pack(); + frame.setVisible(true); + } + }); + animator.start(); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo.java index 9e5ecb648..dbf0838eb 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo.java @@ -4,8 +4,6 @@ import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLProfile; import com.jogamp.graph.curve.Region; -import com.jogamp.graph.curve.opengl.RenderState; -import com.jogamp.graph.geom.SVertex; import com.jogamp.newt.event.WindowAdapter; import com.jogamp.newt.event.WindowEvent; import com.jogamp.newt.opengl.GLWindow; @@ -17,8 +15,9 @@ public class GPUUISceneNewtDemo { static final boolean TRACE = false; static int SceneMSAASamples = 0; - static boolean GraphVBAAMode = true; + static boolean GraphVBAAMode = false; static boolean GraphMSAAMode = false; + static float GraphAutoMode = GPUUISceneGLListener0A.DefaultNoAADPIThreshold; public static void main(String[] args) { int width = 800, height = 400; @@ -30,12 +29,20 @@ public class GPUUISceneNewtDemo { SceneMSAASamples = MiscUtils.atoi(args[i], SceneMSAASamples); GraphMSAAMode = false; GraphVBAAMode = false; + GraphAutoMode = 0f; } else if(args[i].equals("-gmsaa")) { GraphMSAAMode = true; GraphVBAAMode = false; + GraphAutoMode = 0f; } else if(args[i].equals("-gvbaa")) { GraphMSAAMode = false; GraphVBAAMode = true; + GraphAutoMode = 0f; + } else if(args[i].equals("-gauto")) { + GraphMSAAMode = false; + GraphVBAAMode = true; + i++; + GraphAutoMode = MiscUtils.atof(args[i], GraphAutoMode); } else if(args[i].equals("-width")) { i++; width = MiscUtils.atoi(args[i], width); @@ -56,6 +63,7 @@ public class GPUUISceneNewtDemo { System.err.println("Scene MSAA Samples "+SceneMSAASamples); System.err.println("Graph MSAA Mode "+GraphMSAAMode); System.err.println("Graph VBAA Mode "+GraphVBAAMode); + System.err.println("Graph Auto Mode "+GraphAutoMode+" no-AA dpi threshold"); GLProfile glp = GLProfile.getGL2ES2(); GLCapabilities caps = new GLCapabilities(glp); @@ -67,7 +75,9 @@ public class GPUUISceneNewtDemo { System.out.println("Requested: " + caps); final int rmode; - if( GraphVBAAMode ) { + if( 0 < GraphAutoMode ) { + rmode = -1; + } else if( GraphVBAAMode ) { rmode = Region.VBAA_RENDERING_BIT; } else if( GraphMSAAMode ) { rmode = Region.MSAA_RENDERING_BIT; @@ -80,8 +90,8 @@ public class GPUUISceneNewtDemo { window.setSize(width, height); window.setTitle("GraphUI Newt Demo: graph["+Region.getRenderModeString(rmode)+"], msaa "+SceneMSAASamples); - final RenderState rs = RenderState.createRenderState(SVertex.factory()); - GPUUISceneGLListener0A sceneGLListener = new GPUUISceneGLListener0A(rs, rmode, DEBUG, TRACE); + GPUUISceneGLListener0A sceneGLListener = 0 < GraphAutoMode ? new GPUUISceneGLListener0A(GraphAutoMode, DEBUG, TRACE) : + new GPUUISceneGLListener0A(rmode, DEBUG, TRACE); window.addGLEventListener(sceneGLListener); sceneGLListener.attachInputListenerTo(window); |