diff options
5 files changed, 80 insertions, 16 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java index b6b311ac9..47205a14a 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java @@ -29,8 +29,6 @@ package com.jogamp.opengl.test.junit.graph.demos; import java.io.File; import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringWriter; import com.jogamp.opengl.FPSCounter; import com.jogamp.opengl.GL; @@ -244,9 +242,7 @@ public abstract class GPURendererListenerBase01 implements GLEventListener { } public void printScreen(final GLAutoDrawable drawable, final String dir, final String tech, final String objName, final boolean exportAlpha) throws GLException, IOException { - final StringWriter sw = new StringWriter(); - final PrintWriter pw = new PrintWriter(sw); - pw.printf("-%s-S%02d-Z%04d-snap%02d-%03dx%03d", objName, sampleCount[0], (int)Math.abs(zTran), screenshot_num++, drawable.getSurfaceWidth(), drawable.getSurfaceHeight()); + final String sw = String.format("-%s-S%02d-Z%04d-snap%02d-%03dx%03d", objName, sampleCount[0], (int)Math.abs(zTran), screenshot_num++, drawable.getSurfaceWidth(), drawable.getSurfaceHeight()); final String filename = dir + tech + sw +".png"; if(screenshot.readPixels(drawable.getGL(), false)) { screenshot.write(new File(filename)); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/UIShapeDemo01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/UIShapeDemo01.java index 4b30b0c79..d09f00000 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/UIShapeDemo01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/UIShapeDemo01.java @@ -29,8 +29,6 @@ package com.jogamp.opengl.test.junit.graph.demos; import java.io.File; import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringWriter; import com.jogamp.opengl.FPSCounter; import com.jogamp.opengl.GL; @@ -334,9 +332,7 @@ public class UIShapeDemo01 implements GLEventListener { } public void printScreen(final GLAutoDrawable drawable, final String dir, final String tech, final String objName, final boolean exportAlpha) throws GLException, IOException { - final StringWriter sw = new StringWriter(); - final PrintWriter pw = new PrintWriter(sw); - pw.printf("-%03dx%03d-Z%04d-T%04d-%s", drawable.getSurfaceWidth(), drawable.getSurfaceHeight(), (int)Math.abs(zTran), 0, objName); + final String sw = String.format("-%03dx%03d-Z%04d-T%04d-%s", drawable.getSurfaceWidth(), drawable.getSurfaceHeight(), (int)Math.abs(zTran), 0, objName); final String filename = dir + tech + sw +".png"; if(screenshot.readPixels(drawable.getGL(), false)) { diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/UITypeDemo01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/UITypeDemo01.java index a2bd5c0c8..5c638f953 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/UITypeDemo01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/UITypeDemo01.java @@ -29,8 +29,6 @@ package com.jogamp.opengl.test.junit.graph.demos; import java.io.File; import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringWriter; import com.jogamp.opengl.FPSCounter; import com.jogamp.opengl.GL; @@ -414,9 +412,7 @@ public class UITypeDemo01 implements GLEventListener { final String tech="demo-"+Region.getRenderModeString(renderModes); final String objName = "snap"+screenshot_num; { - final StringWriter sw = new StringWriter(); - final PrintWriter pw = new PrintWriter(sw); - pw.printf("-%03dx%03d-Z%04d-T%04d-%s", drawable.getSurfaceWidth(), drawable.getSurfaceHeight(), (int)Math.abs(zTran), 0, objName); + final String sw = String.format("-%03dx%03d-Z%04d-T%04d-%s", drawable.getSurfaceWidth(), drawable.getSurfaceHeight(), (int)Math.abs(zTran), 0, objName); final String filename = dir + tech + sw +".png"; if(screenshot.readPixels(drawable.getGL(), false)) { diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java index 673b71081..c43d216dc 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java @@ -40,7 +40,7 @@ import com.jogamp.opengl.GLCapabilities; import com.jogamp.opengl.GLEventListener; import com.jogamp.opengl.GLException; import com.jogamp.opengl.GLProfile; - +import com.jogamp.opengl.GLRunnable; import com.jogamp.common.net.Uri; import com.jogamp.common.util.InterruptSource; import com.jogamp.graph.curve.Region; @@ -61,6 +61,7 @@ import com.jogamp.opengl.test.junit.graph.TextRendererGLELBase; import com.jogamp.opengl.test.junit.jogl.demos.es2.TextureSequenceCubeES2; import com.jogamp.opengl.test.junit.util.MiscUtils; import com.jogamp.opengl.util.Animator; +import com.jogamp.opengl.util.GLReadBufferUtil; import com.jogamp.opengl.util.av.GLMediaPlayer; import com.jogamp.opengl.util.av.GLMediaPlayer.GLMediaEventListener; import com.jogamp.opengl.util.av.GLMediaPlayer.StreamException; @@ -80,6 +81,7 @@ public class MovieCube implements GLEventListener { private boolean swapIntervalSet = true; private long lastPerfPos = 0; private volatile boolean resetGLState = false; + private volatile GLAutoDrawable autoDrawable = null; /** Blender's Big Buck Bunny: 24f 416p H.264, AAC 48000 Hz, 2 ch, mpeg stream. */ public static final Uri defURI; @@ -150,6 +152,7 @@ public class MovieCube implements GLEventListener { this.rotx = rotx; this.roty = roty; this.showText = showText; + screenshot = new GLReadBufferUtil(false, false); mPlayer = GLMediaPlayerFactory.createDefault(); } @@ -198,6 +201,8 @@ public class MovieCube implements GLEventListener { this.setSharedPMVMatrix(cube.pmvMatrix); super.init(drawable); + autoDrawable = drawable; + pixelSize1 = FontScale.toPixels(fontSize1, dpiH); pixelSize2 = FontScale.toPixels(fontSize2, dpiH); pixelScale = 1.0f / ( pixelSize1 * 20f ); @@ -211,6 +216,8 @@ public class MovieCube implements GLEventListener { @Override public void dispose(final GLAutoDrawable drawable) { + autoDrawable = null; + screenshot.dispose(drawable.getGL()); if( null != regionFPS ) { regionFPS.destroy(drawable.getGL().getGL2ES2()); } @@ -271,6 +278,31 @@ public class MovieCube implements GLEventListener { final boolean showText; private boolean displayOSD = true; + public void printScreen(final GLAutoDrawable drawable) throws GLException, IOException { + final String filename = String.format("MovieCube-snap%02d-%03dx%03d.png", screenshot_num++, drawable.getSurfaceWidth(), drawable.getSurfaceHeight()); + if(screenshot.readPixels(drawable.getGL(), false)) { + screenshot.write(new File(filename.toString())); + } + } + private final GLReadBufferUtil screenshot; + private int screenshot_num = 0; + + public void printScreenOnGLThread(final GLAutoDrawable drawable) { + drawable.invoke(false, new GLRunnable() { + @Override + public boolean run(final GLAutoDrawable drawable) { + try { + printScreen(drawable); + } catch (final GLException e) { + e.printStackTrace(); + } catch (final IOException e) { + e.printStackTrace(); + } + return true; + } + }); + } + private final KeyListener keyAction = new KeyAdapter() { @Override public void keyReleased(final KeyEvent e) { @@ -342,6 +374,11 @@ public class MovieCube implements GLEventListener { } mPlayer.setAudioVolume(audioVolume); } break; + case KeyEvent.VK_S: + if(null != autoDrawable) { + printScreenOnGLThread(autoDrawable); + } + break; } if( 0 != pts1 ) { diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java index 5e7ace02b..2b2bcbcc4 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java @@ -42,6 +42,7 @@ import com.jogamp.opengl.GLES2; import com.jogamp.opengl.GLEventListener; import com.jogamp.opengl.GLException; import com.jogamp.opengl.GLProfile; +import com.jogamp.opengl.GLRunnable; import com.jogamp.opengl.GLUniformData; import com.jogamp.opengl.fixedfunc.GLMatrixFunc; @@ -70,6 +71,7 @@ import com.jogamp.opengl.test.junit.graph.TextRendererGLELBase; import com.jogamp.opengl.test.junit.util.MiscUtils; import com.jogamp.opengl.util.Animator; import com.jogamp.opengl.util.GLArrayDataServer; +import com.jogamp.opengl.util.GLReadBufferUtil; import com.jogamp.opengl.util.PMVMatrix; import com.jogamp.opengl.util.av.GLMediaPlayer; import com.jogamp.opengl.util.av.GLMediaPlayer.GLMediaEventListener; @@ -116,6 +118,8 @@ public class MovieSimple implements GLEventListener { private GLArrayDataServer interleavedVBO; private volatile boolean resetGLState = false; + private volatile GLAutoDrawable autoDrawable = null; + private ShaderState st; private PMVMatrix pmvMatrix; private GLUniformData pmvMatrixUniform; @@ -213,6 +217,31 @@ public class MovieSimple implements GLEventListener { private InfoTextRendererGLELBase textRendererGLEL = null; private boolean displayOSD = true; + public void printScreen(final GLAutoDrawable drawable) throws GLException, IOException { + final String filename = String.format("MovieSimple-snap%02d-%03dx%03d.png", screenshot_num++, drawable.getSurfaceWidth(), drawable.getSurfaceHeight()); + if(screenshot.readPixels(drawable.getGL(), false)) { + screenshot.write(new File(filename.toString())); + } + } + private final GLReadBufferUtil screenshot; + private int screenshot_num = 0; + + public void printScreenOnGLThread(final GLAutoDrawable drawable) { + drawable.invoke(false, new GLRunnable() { + @Override + public boolean run(final GLAutoDrawable drawable) { + try { + printScreen(drawable); + } catch (final GLException e) { + e.printStackTrace(); + } catch (final IOException e) { + e.printStackTrace(); + } + return true; + } + }); + } + private final MouseListener mouseAction = new MouseAdapter() { @Override public void mousePressed(final MouseEvent e) { @@ -334,6 +363,11 @@ public class MovieSimple implements GLEventListener { } mPlayer.setAudioVolume(audioVolume); } break; + case KeyEvent.VK_S: + if(null != autoDrawable) { + printScreenOnGLThread(autoDrawable); + } + break; } if( 0 != pts1 ) { @@ -390,6 +424,7 @@ public class MovieSimple implements GLEventListener { /** Custom constructor, user needs to issue {@link #initStream(URI, int, int, int)} afterwards. */ public MovieSimple(final GLMediaPlayer sharedMediaPlayer) throws IllegalStateException { + screenshot = new GLReadBufferUtil(false, false); mPlayer = sharedMediaPlayer; mPlayerScaleOrig = false; mPlayerShared = null != mPlayer; @@ -490,6 +525,8 @@ public class MovieSimple implements GLEventListener { zoom1 = orthoProjection ? 0f : -5f; zoom = zoom0; + autoDrawable = drawable; + final GL2ES2 gl = drawable.getGL().getGL2ES2(); System.err.println(JoglVersion.getGLInfo(gl, null)); System.err.println("Alpha: "+alpha+", opaque "+drawable.getChosenGLCapabilities().isBackgroundOpaque()+ @@ -710,8 +747,10 @@ public class MovieSimple implements GLEventListener { @Override public void dispose(final GLAutoDrawable drawable) { + autoDrawable = null; drawable.disposeGLEventListener(textRendererGLEL, true); textRendererGLEL = null; + screenshot.dispose(drawable.getGL()); disposeImpl(drawable, true); } |