From cf36398314270c2c50d55b23736e5bff8b62337d Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 7 Jun 2011 18:28:22 +0200 Subject: Using GlueGen IOUtil (dropped StreamUtil, FileUtil); Public GLReadBufferUtil (screenshot etc) and GLPixelStorageModes - Using GlueGen IOUtil, dropping StreamUtil and FileUtil - Public (util) GLReadBufferUtil for screenshots and slow r2t (AWT less), as well as GLPixelStorageModes --- .../graph/demos/GPURendererListenerBase01.java | 11 ++- .../test/junit/graph/demos/ReadBufferUtil.java | 108 --------------------- .../opengl/test/junit/graph/demos/Screenshot.java | 39 -------- .../junit/graph/demos/ui/UIListenerBase01.java | 13 +-- .../test/junit/jogl/offscreen/ReadBuffer2File.java | 5 +- .../junit/jogl/offscreen/ReadBuffer2Screen.java | 2 +- .../test/junit/jogl/offscreen/ReadBufferBase.java | 9 +- .../test/junit/jogl/offscreen/ReadBufferUtil.java | 106 -------------------- .../test/junit/jogl/offscreen/Surface2File.java | 8 +- 9 files changed, 27 insertions(+), 274 deletions(-) delete mode 100644 src/test/com/jogamp/opengl/test/junit/graph/demos/ReadBufferUtil.java delete mode 100644 src/test/com/jogamp/opengl/test/junit/graph/demos/Screenshot.java delete mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBufferUtil.java (limited to 'src/test/com/jogamp') 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 9587a672d..ed6bb3cde 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 @@ -27,6 +27,7 @@ */ package com.jogamp.opengl.test.junit.graph.demos; +import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; @@ -48,6 +49,7 @@ import com.jogamp.graph.curve.opengl.Renderer; import com.jogamp.newt.event.KeyEvent; import com.jogamp.newt.event.KeyListener; import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.util.GLReadBufferUtil; /** * @@ -60,7 +62,7 @@ import com.jogamp.newt.opengl.GLWindow; * - s: screenshot */ public abstract class GPURendererListenerBase01 implements GLEventListener { - private Screenshot screenshot; + private GLReadBufferUtil screenshot; private Renderer renderer; private int renderModes; private boolean debug; @@ -88,7 +90,7 @@ public abstract class GPURendererListenerBase01 implements GLEventListener { this.renderModes = renderModes; this.debug = debug; this.trace = trace; - this.screenshot = new Screenshot(); + this.screenshot = new GLReadBufferUtil(false, false); } public final Renderer getRenderer() { return renderer; } @@ -191,8 +193,9 @@ public abstract class GPURendererListenerBase01 implements GLEventListener { PrintWriter pw = new PrintWriter(sw); pw.printf("-%03dx%03d-Z%04d-T%04d-%s", drawable.getWidth(), drawable.getHeight(), (int)Math.abs(zoom), texSize, objName); - String filename = dir + tech + sw +".tga"; - screenshot.surface2File(drawable, filename /*, exportAlpha */); + final String filename = dir + tech + sw +".tga"; + screenshot.readPixels(drawable.getGL(), drawable, false); + screenshot.write(new File(filename)); } int screenshot_num = 0; diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ReadBufferUtil.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ReadBufferUtil.java deleted file mode 100644 index dc1ea2da3..000000000 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ReadBufferUtil.java +++ /dev/null @@ -1,108 +0,0 @@ -/** - * Copyright 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ - -package com.jogamp.opengl.test.junit.graph.demos; - -import com.jogamp.opengl.util.GLBuffers; -import java.nio.*; -import javax.media.opengl.*; - -import com.jogamp.opengl.util.texture.Texture; -import com.jogamp.opengl.util.texture.TextureData; - -public class ReadBufferUtil { - protected int readPixelSizeLast = 0; - protected Buffer readPixelBuffer = null; - protected TextureData readTextureData = null; - protected Texture readTexture = new Texture(GL.GL_TEXTURE_2D); - - public Buffer getPixelBuffer() { return readPixelBuffer; } - public void rewindPixelBuffer() { readPixelBuffer.rewind(); } - - public TextureData getTextureData() { return readTextureData; } - public Texture getTexture() { return readTexture; } - - public boolean isValid() { - return null!=readTexture && null!=readTextureData && null!=readPixelBuffer ; - } - - public void fetchOffscreenTexture(GLDrawable drawable, GL gl) { - int readPixelSize = drawable.getWidth() * drawable.getHeight() * 3 ; // RGB - boolean newData = false; - if(readPixelSize>readPixelSizeLast) { - readPixelBuffer = GLBuffers.newDirectGLBuffer(GL.GL_UNSIGNED_BYTE, readPixelSize); - readPixelSizeLast = readPixelSize ; - try { - readTextureData = new TextureData( - gl.getGLProfile(), - // gl.isGL2GL3()?gl.GL_RGBA:gl.GL_RGB, - GL.GL_RGB, - drawable.getWidth(), drawable.getHeight(), - 0, - GL.GL_RGB, - GL.GL_UNSIGNED_BYTE, - false, false, - false /* flip */, - readPixelBuffer, - null /* Flusher */); - newData = true; - } catch (Exception e) { - readTextureData = null; - readPixelBuffer = null; - readPixelSizeLast = 0; - throw new RuntimeException("can not fetch offscreen texture", e); - } - } - if(null!=readPixelBuffer) { - readPixelBuffer.clear(); - gl.glReadPixels(0, 0, drawable.getWidth(), drawable.getHeight(), GL.GL_RGB, GL.GL_UNSIGNED_BYTE, readPixelBuffer); - readPixelBuffer.rewind(); - if(newData) { - readTexture.updateImage(gl, readTextureData); - } else { - readTexture.updateSubImage(gl, readTextureData, 0, - 0, 0, // src offset - 0, 0, // dst offset - drawable.getWidth(), drawable.getHeight()); - } - readPixelBuffer.rewind(); - } - } - - public void dispose(GL gl) { - readTexture.destroy(gl); - readTextureData = null; - if(null != readPixelBuffer) { - readPixelBuffer.clear(); - readPixelBuffer = null; - } - readPixelSizeLast = 0; - } - -} - diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/Screenshot.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/Screenshot.java deleted file mode 100644 index f4b6f6dd9..000000000 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/Screenshot.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.jogamp.opengl.test.junit.graph.demos; - -import java.io.File; -import java.io.IOException; - -import javax.media.opengl.GL; -import javax.media.opengl.GLAutoDrawable; - -import com.jogamp.opengl.util.texture.TextureIO; - -public class Screenshot { - - ReadBufferUtil readBufferUtil = new ReadBufferUtil(); - - public void dispose(GL gl) { - readBufferUtil.dispose(gl); - } - - public void surface2File(GLAutoDrawable drawable, String filename) { - GL gl = drawable.getGL(); - // FIXME glFinish() is an expensive paranoia sync, should not be necessary due to spec - gl.glFinish(); - readBufferUtil.fetchOffscreenTexture(drawable, gl); - gl.glFinish(); - try { - surface2File(filename); - } catch (IOException ex) { - throw new RuntimeException("can not write survace to file", ex); - } - } - - void surface2File(String filename) throws IOException { - File file = new File(filename); - TextureIO.write(readBufferUtil.getTextureData(), file); - System.err.println("Wrote: " + file.getAbsolutePath() + ", ..."); - readBufferUtil.rewindPixelBuffer(); - } - -} diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIListenerBase01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIListenerBase01.java index df2dca4fb..b89f87be4 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIListenerBase01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIListenerBase01.java @@ -27,6 +27,7 @@ */ package com.jogamp.opengl.test.junit.graph.demos.ui; +import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; @@ -41,13 +42,12 @@ import javax.media.opengl.GLPipelineFactory; import javax.media.opengl.GLRunnable; import com.jogamp.graph.curve.opengl.RegionRenderer; -import com.jogamp.graph.curve.opengl.TextRenderer; import com.jogamp.newt.event.KeyEvent; import com.jogamp.newt.event.KeyListener; import com.jogamp.newt.event.MouseEvent; import com.jogamp.newt.event.MouseListener; import com.jogamp.newt.opengl.GLWindow; -import com.jogamp.opengl.test.junit.graph.demos.Screenshot; +import com.jogamp.opengl.util.GLReadBufferUtil; /** * @@ -60,7 +60,7 @@ import com.jogamp.opengl.test.junit.graph.demos.Screenshot; * - s: screenshot */ public abstract class UIListenerBase01 implements GLEventListener { - private Screenshot screenshot; + private GLReadBufferUtil screenshot; private RegionRenderer rRenderer; private boolean debug; private boolean trace; @@ -85,7 +85,7 @@ public abstract class UIListenerBase01 implements GLEventListener { this.rRenderer = rRenderer; this.debug = debug; this.trace = trace; - this.screenshot = new Screenshot(); + this.screenshot = new GLReadBufferUtil(false, false); } public final RegionRenderer getRegionRenderer() { return rRenderer; } @@ -179,8 +179,9 @@ public abstract class UIListenerBase01 implements GLEventListener { PrintWriter pw = new PrintWriter(sw); pw.printf("-%03dx%03d-Z%04d-T%04d-%s", drawable.getWidth(), drawable.getHeight(), (int)Math.abs(zoom), 0, objName); - String filename = dir + tech + sw +".tga"; - screenshot.surface2File(drawable, filename /*, exportAlpha */); + final String filename = dir + tech + sw +".tga"; + screenshot.readPixels(drawable.getGL(), drawable, false); + screenshot.write(new File(filename)); } int screenshot_num = 0; diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBuffer2File.java b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBuffer2File.java index 95e7d6e53..b829c8deb 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBuffer2File.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBuffer2File.java @@ -37,7 +37,7 @@ import java.io.File; public class ReadBuffer2File extends ReadBufferBase { public ReadBuffer2File(GLDrawable externalRead) { - super(externalRead); + super(externalRead, false); } @Override @@ -52,10 +52,9 @@ public class ReadBuffer2File extends ReadBufferBase { } File file = File.createTempFile("shot" + shotNum + "-", ".ppm"); - TextureIO.write(readBufferUtil.getTextureData(), file); + readBufferUtil.write(file); System.out.println("Wrote: " + file.getAbsolutePath() + ", ..."); shotNum++; - readBufferUtil.rewindPixelBuffer(); } @Override diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBuffer2Screen.java b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBuffer2Screen.java index 23271dde2..8c315e97f 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBuffer2Screen.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBuffer2Screen.java @@ -47,7 +47,7 @@ public class ReadBuffer2Screen extends ReadBufferBase { boolean enableBufferVBO = true; // FIXME public ReadBuffer2Screen (GLDrawable externalRead) { - super(externalRead); + super(externalRead, true); } @Override diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBufferBase.java b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBufferBase.java index 53675bc31..e3ca25ae6 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBufferBase.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBufferBase.java @@ -30,16 +30,19 @@ package com.jogamp.opengl.test.junit.jogl.offscreen; import javax.media.opengl.*; +import com.jogamp.opengl.util.GLReadBufferUtil; + public class ReadBufferBase implements GLEventListener { public boolean glDebug = false ; public boolean glTrace = false ; protected GLDrawable externalRead; - ReadBufferUtil readBufferUtil = new ReadBufferUtil(); + GLReadBufferUtil readBufferUtil; - public ReadBufferBase (GLDrawable externalRead) { + public ReadBufferBase (GLDrawable externalRead, boolean write2Texture) { this.externalRead = externalRead ; + this.readBufferUtil = new GLReadBufferUtil(false, write2Texture); } public void init(GLAutoDrawable drawable) { @@ -84,7 +87,7 @@ public class ReadBufferBase implements GLEventListener { public void display(GLAutoDrawable drawable) { GL gl = drawable.getGL(); - readBufferUtil.fetchOffscreenTexture(drawable, gl); + readBufferUtil.readPixels(gl, drawable, false); } } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBufferUtil.java b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBufferUtil.java deleted file mode 100644 index 5a2c73cf4..000000000 --- a/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBufferUtil.java +++ /dev/null @@ -1,106 +0,0 @@ -/** - * Copyright 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ - -package com.jogamp.opengl.test.junit.jogl.offscreen; - -import com.jogamp.opengl.util.GLBuffers; -import java.nio.*; -import javax.media.opengl.*; - -import com.jogamp.opengl.util.texture.Texture; -import com.jogamp.opengl.util.texture.TextureData; - -public class ReadBufferUtil { - protected int readPixelSizeLast = 0; - protected Buffer readPixelBuffer = null; - protected TextureData readTextureData = null; - protected Texture readTexture = new Texture(GL.GL_TEXTURE_2D); - - public Buffer getPixelBuffer() { return readPixelBuffer; } - public void rewindPixelBuffer() { readPixelBuffer.rewind(); } - - public TextureData getTextureData() { return readTextureData; } - public Texture getTexture() { return readTexture; } - - public boolean isValid() { - return null!=readTexture && null!=readTextureData && null!=readPixelBuffer ; - } - - public void fetchOffscreenTexture(GLDrawable drawable, GL gl) { - int readPixelSize = drawable.getWidth() * drawable.getHeight() * 3 ; // RGB - boolean newData = false; - if(readPixelSize>readPixelSizeLast) { - readPixelBuffer = GLBuffers.newDirectGLBuffer(GL.GL_UNSIGNED_BYTE, readPixelSize); - readPixelSizeLast = readPixelSize ; - try { - readTextureData = new TextureData( - gl.getGLProfile(), - // gl.isGL2GL3()?gl.GL_RGBA:gl.GL_RGB, - gl.GL_RGB, - drawable.getWidth(), drawable.getHeight(), - 0, - gl.GL_RGB, - gl.GL_UNSIGNED_BYTE, - false, false, - false /* flip */, - readPixelBuffer, - null /* Flusher */); - newData = true; - } catch (Exception e) { - readTextureData = null; - readPixelBuffer = null; - readPixelSizeLast = 0; - throw new RuntimeException("can not fetch offscreen texture", e); - } - } - if(null!=readPixelBuffer) { - readPixelBuffer.clear(); - gl.glReadPixels(0, 0, drawable.getWidth(), drawable.getHeight(), GL.GL_RGB, GL.GL_UNSIGNED_BYTE, readPixelBuffer); - readPixelBuffer.rewind(); - if(newData) { - readTexture.updateImage(gl, readTextureData); - } else { - readTexture.updateSubImage(gl, readTextureData, 0, - 0, 0, // src offset - 0, 0, // dst offset - drawable.getWidth(), drawable.getHeight()); - } - readPixelBuffer.rewind(); - } - } - - public void dispose(GL gl) { - readTexture.destroy(gl); - readTextureData = null; - readPixelBuffer.clear(); - readPixelBuffer = null; - readPixelSizeLast = 0; - } - -} - diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/Surface2File.java b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/Surface2File.java index 77fd40181..8ca1f3ef8 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/Surface2File.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/Surface2File.java @@ -30,6 +30,7 @@ package com.jogamp.opengl.test.junit.jogl.offscreen; import javax.media.opengl.*; +import com.jogamp.opengl.util.GLReadBufferUtil; import com.jogamp.opengl.util.texture.TextureIO; import java.io.File; @@ -39,7 +40,7 @@ import javax.media.nativewindow.*; public class Surface2File implements SurfaceUpdatedListener { - ReadBufferUtil readBufferUtil = new ReadBufferUtil(); + GLReadBufferUtil readBufferUtil = new GLReadBufferUtil(false, false); int shotNum = 0; public void dispose(GL gl) { @@ -54,7 +55,7 @@ public class Surface2File implements SurfaceUpdatedListener { GL gl = ctx.getGL(); // FIXME glFinish() is an expensive paranoia sync, should not be necessary due to spec gl.glFinish(); - readBufferUtil.fetchOffscreenTexture(drawable, gl); + readBufferUtil.readPixels(gl, drawable, false); gl.glFinish(); try { surface2File("shot"); @@ -71,9 +72,8 @@ public class Surface2File implements SurfaceUpdatedListener { } File file = File.createTempFile(basename + shotNum + "-", ".ppm"); - TextureIO.write(readBufferUtil.getTextureData(), file); + readBufferUtil.write(file); System.err.println("Wrote: " + file.getAbsolutePath() + ", ..."); shotNum++; - readBufferUtil.rewindPixelBuffer(); } } -- cgit v1.2.3