diff options
Diffstat (limited to 'src/test/com')
15 files changed, 73 insertions, 285 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 e9df473ac..632b78d82 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/demos/gl2/gears/TestGearsAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/TestGearsAWT.java index 8b050374a..d0f73898f 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/TestGearsAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/TestGearsAWT.java @@ -104,7 +104,7 @@ public class TestGearsAWT extends UITestCase { @Test public void test01() throws InterruptedException { - GLCapabilities caps = new GLCapabilities(GLProfile.getDefault()); + GLCapabilities caps = new GLCapabilities(glp); runTestGL(caps); } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestFBOMRTNEWT01.java b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestFBOMRTNEWT01.java index 6c826c221..f3af56fb3 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestFBOMRTNEWT01.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestFBOMRTNEWT01.java @@ -56,7 +56,7 @@ public class TestFBOMRTNEWT01 extends UITestCase { @Test public void test01() throws InterruptedException { // preset .. - final NEWTGLContext.WindowContext winctx = NEWTGLContext.createWindow(GLProfile.getGL2ES2(), 640, 480, true); + final NEWTGLContext.WindowContext winctx = NEWTGLContext.createOnscreenWindow(GLProfile.getGL2ES2(), 640, 480, true); final GLDrawable drawable = winctx.context.getGLDrawable(); final GL _gl = winctx.context.getGL(); Assert.assertTrue(_gl.isGL2GL3()); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLShaderState01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLShaderState01NEWT.java index c29faf31d..1cd49a41f 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLShaderState01NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLShaderState01NEWT.java @@ -60,7 +60,7 @@ public class TestGLSLShaderState01NEWT extends UITestCase { @Test public void testShaderState01Validation() throws InterruptedException { // preset .. - final NEWTGLContext.WindowContext winctx = NEWTGLContext.createWindow(GLProfile.getGL2ES2(), 480, 480, true); + final NEWTGLContext.WindowContext winctx = NEWTGLContext.createOnscreenWindow(GLProfile.getGL2ES2(), 480, 480, true); final GLDrawable drawable = winctx.context.getGLDrawable(); final GL2ES2 gl = winctx.context.getGL().getGL2ES2(); System.err.println(winctx.context); @@ -184,7 +184,7 @@ public class TestGLSLShaderState01NEWT extends UITestCase { void testShaderState00PerformanceSingle(boolean toggleEnable) throws InterruptedException { // preset .. - final NEWTGLContext.WindowContext winctx = NEWTGLContext.createWindow(GLProfile.getGL2ES2(), 480, 480, false); + final NEWTGLContext.WindowContext winctx = NEWTGLContext.createOnscreenWindow(GLProfile.getGL2ES2(), 480, 480, false); final GLDrawable drawable = winctx.context.getGLDrawable(); final GL2ES2 gl = winctx.context.getGL().getGL2ES2(); System.err.println(winctx.context); @@ -270,7 +270,7 @@ public class TestGLSLShaderState01NEWT extends UITestCase { @Test public void testShaderState01PerformanceDouble() throws InterruptedException { // preset .. - final NEWTGLContext.WindowContext winctx = NEWTGLContext.createWindow(GLProfile.getGL2ES2(), 480, 480, false); + final NEWTGLContext.WindowContext winctx = NEWTGLContext.createOnscreenWindow(GLProfile.getGL2ES2(), 480, 480, false); final GLDrawable drawable = winctx.context.getGLDrawable(); final GL2ES2 gl = winctx.context.getGL().getGL2ES2(); System.err.println(winctx.context); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLShaderState02NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLShaderState02NEWT.java index 0d81db137..38fbabf72 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLShaderState02NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLShaderState02NEWT.java @@ -68,7 +68,7 @@ public class TestGLSLShaderState02NEWT extends UITestCase { private void testShaderState01Validation(boolean linkSP1) throws InterruptedException { // preset .. - final NEWTGLContext.WindowContext winctx = NEWTGLContext.createWindow(GLProfile.getGL2ES2(), 480, 480, true); + final NEWTGLContext.WindowContext winctx = NEWTGLContext.createOnscreenWindow(GLProfile.getGL2ES2(), 480, 480, true); final GLDrawable drawable = winctx.context.getGLDrawable(); final GL2ES2 gl = winctx.context.getGL().getGL2ES2(); System.err.println(winctx.context); @@ -232,7 +232,7 @@ public class TestGLSLShaderState02NEWT extends UITestCase { @Test public void testShaderState01PerformanceDouble() throws InterruptedException { // preset .. - final NEWTGLContext.WindowContext winctx = NEWTGLContext.createWindow(GLProfile.getGL2ES2(), 480, 480, false); + final NEWTGLContext.WindowContext winctx = NEWTGLContext.createOnscreenWindow(GLProfile.getGL2ES2(), 480, 480, false); final GLDrawable drawable = winctx.context.getGLDrawable(); final GL2ES2 gl = winctx.context.getGL().getGL2ES2(); System.err.println(winctx.context); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestRulerNEWT01.java b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestRulerNEWT01.java index 365596711..cc0ec4601 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestRulerNEWT01.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestRulerNEWT01.java @@ -58,7 +58,7 @@ public class TestRulerNEWT01 extends UITestCase { @Test public void test01() throws InterruptedException { // preset .. - final NEWTGLContext.WindowContext winctx = NEWTGLContext.createWindow(GLProfile.getGL2ES2(), 640, 480, true); + final NEWTGLContext.WindowContext winctx = NEWTGLContext.createOnscreenWindow(GLProfile.getGL2ES2(), 640, 480, true); final GLDrawable drawable = winctx.context.getGLDrawable(); final GL2ES2 gl = winctx.context.getGL().getGL2ES2(); System.err.println(winctx.context); 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(); } } diff --git a/src/test/com/jogamp/opengl/test/junit/util/NEWTGLContext.java b/src/test/com/jogamp/opengl/test/junit/util/NEWTGLContext.java index b8df88901..3992c0876 100644 --- a/src/test/com/jogamp/opengl/test/junit/util/NEWTGLContext.java +++ b/src/test/com/jogamp/opengl/test/junit/util/NEWTGLContext.java @@ -31,8 +31,6 @@ import com.jogamp.newt.Display; import com.jogamp.newt.NewtFactory; import com.jogamp.newt.Screen; import com.jogamp.newt.Window; -import com.jogamp.opengl.util.GLArrayDataServer; -import com.jogamp.opengl.util.glsl.ShaderState; import javax.media.opengl.GL; import javax.media.opengl.GL2ES2; @@ -56,7 +54,44 @@ public class NEWTGLContext { } } - public static WindowContext createWindow(GLProfile glp, int width, int height, boolean debugGL) throws InterruptedException { + public static WindowContext createOffscreenWindow(GLProfile glp, int width, int height, boolean debugGL) throws InterruptedException { + GLCapabilities caps = new GLCapabilities(glp); + caps.setOnscreen(false); + + // + // Create native windowing resources .. X11/Win/OSX + // + Display display = NewtFactory.createDisplay(null); // local display + Assert.assertNotNull(display); + + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + Assert.assertNotNull(screen); + + Window window = NewtFactory.createWindow(screen, caps); + Assert.assertNotNull(window); + window.setSize(width, height); + window.setVisible(true); + AWTRobotUtil.waitForVisible(window, true); + AWTRobotUtil.waitForRealized(window, true); + + GLDrawableFactory factory = GLDrawableFactory.getFactory(glp); + GLDrawable drawable = factory.createGLDrawable(window); + Assert.assertNotNull(drawable); + + drawable.setRealized(true); + + GLContext context = drawable.createContext(null); + Assert.assertNotNull(context); + + context.enableGLDebugMessage(debugGL); + + int res = context.makeCurrent(); + Assert.assertTrue(GLContext.CONTEXT_CURRENT_NEW==res || GLContext.CONTEXT_CURRENT==res); + + return new WindowContext(window, context); + } + + public static WindowContext createOnscreenWindow(GLProfile glp, int width, int height, boolean debugGL) throws InterruptedException { GLCapabilities caps = new GLCapabilities(glp); // // Create native windowing resources .. X11/Win/OSX |