diff options
author | Sven Gothel <[email protected]> | 2011-05-16 03:31:49 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-05-16 03:31:49 +0200 |
commit | b82a409135f3b79889499d77c8ecffc80e310a20 (patch) | |
tree | 00a37ba15c08467cd5c05d645094203926065c9a | |
parent | f3de07e479c7849d0172a03bb82ce9189da5679e (diff) |
JUnit Tests: Extract utility of creating a NEWT Window w/ GLContext w/o auto drawable (NEWTGLContext)
4 files changed, 118 insertions, 75 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/GLSLMiscHelper.java b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/GLSLMiscHelper.java index e75bd7bdd..e75f4ebe3 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/GLSLMiscHelper.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/GLSLMiscHelper.java @@ -27,20 +27,12 @@ */ package com.jogamp.opengl.test.junit.jogl.glsl; -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; -import javax.media.opengl.GLCapabilities; -import javax.media.opengl.GLContext; import javax.media.opengl.GLDrawable; -import javax.media.opengl.GLDrawableFactory; -import javax.media.opengl.GLProfile; import org.junit.Assert; @@ -48,62 +40,6 @@ public class GLSLMiscHelper { public static final int frames_perftest = 10000; // frames public static final int frames_warmup = 500; // frames - public static class WindowContext { - public final Window window; - public final GLContext context; - - public WindowContext(Window w, GLContext c) { - window = w; - context = c; - } - } - - public static WindowContext createWindow(GLProfile glp, boolean debugGL) { - GLCapabilities caps = new GLCapabilities(glp); - // - // 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(480, 480); - window.setVisible(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 void destroyWindow(WindowContext winctx) { - GLDrawable drawable = winctx.context.getGLDrawable(); - - Assert.assertNotNull(winctx.context); - winctx.context.destroy(); - - Assert.assertNotNull(drawable); - drawable.setRealized(false); - - Assert.assertNotNull(winctx.window); - winctx.window.destroy(); - } - public static void validateGLArrayDataServerState(GL2ES2 gl, ShaderState st, GLArrayDataServer data) { int[] qi = new int[1]; if(null != st) { 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 096496d87..54b8a4379 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 @@ -34,6 +34,7 @@ import com.jogamp.opengl.util.glsl.ShaderProgram; import com.jogamp.opengl.util.glsl.ShaderState; import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquare0; import com.jogamp.opengl.test.junit.util.MiscUtils; +import com.jogamp.opengl.test.junit.util.NEWTGLContext; import com.jogamp.opengl.test.junit.util.UITestCase; import java.io.IOException; @@ -59,7 +60,7 @@ public class TestGLSLShaderState01NEWT extends UITestCase { @Test public void testShaderState01Validation() throws InterruptedException { // preset .. - GLSLMiscHelper.WindowContext winctx = GLSLMiscHelper.createWindow(GLProfile.getGL2ES2(), true); + NEWTGLContext.WindowContext winctx = NEWTGLContext.createWindow(GLProfile.getGL2ES2(), 480, 480, true); GLDrawable drawable = winctx.context.getGLDrawable(); GL2ES2 gl = winctx.context.getGL().getGL2ES2(); System.err.println(winctx.context); @@ -169,7 +170,7 @@ public class TestGLSLShaderState01NEWT extends UITestCase { // cleanup st.destroy(gl); - GLSLMiscHelper.destroyWindow(winctx); + NEWTGLContext.destroyWindow(winctx); } @Test @@ -183,7 +184,7 @@ public class TestGLSLShaderState01NEWT extends UITestCase { void testShaderState00PerformanceSingle(boolean toggleEnable) throws InterruptedException { // preset .. - GLSLMiscHelper.WindowContext winctx = GLSLMiscHelper.createWindow(GLProfile.getGL2ES2(), false); + NEWTGLContext.WindowContext winctx = NEWTGLContext.createWindow(GLProfile.getGL2ES2(), 480, 480, false); GLDrawable drawable = winctx.context.getGLDrawable(); GL2ES2 gl = winctx.context.getGL().getGL2ES2(); System.err.println(winctx.context); @@ -263,13 +264,13 @@ public class TestGLSLShaderState01NEWT extends UITestCase { // cleanup st.destroy(gl); - GLSLMiscHelper.destroyWindow(winctx); + NEWTGLContext.destroyWindow(winctx); } @Test public void testShaderState01PerformanceDouble() throws InterruptedException { // preset .. - GLSLMiscHelper.WindowContext winctx = GLSLMiscHelper.createWindow(GLProfile.getGL2ES2(), false); + NEWTGLContext.WindowContext winctx = NEWTGLContext.createWindow(GLProfile.getGL2ES2(), 480, 480, false); GLDrawable drawable = winctx.context.getGLDrawable(); GL2ES2 gl = winctx.context.getGL().getGL2ES2(); System.err.println(winctx.context); @@ -361,7 +362,7 @@ public class TestGLSLShaderState01NEWT extends UITestCase { // cleanup st.destroy(gl); - GLSLMiscHelper.destroyWindow(winctx); + NEWTGLContext.destroyWindow(winctx); } public static void main(String args[]) throws IOException { 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 1c0f028a2..5701c1f4b 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 @@ -34,8 +34,9 @@ import com.jogamp.opengl.util.glsl.ShaderCode; import com.jogamp.opengl.util.glsl.ShaderProgram; import com.jogamp.opengl.util.glsl.ShaderState; import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquare0; -import com.jogamp.opengl.test.junit.jogl.glsl.GLSLMiscHelper.WindowContext; import com.jogamp.opengl.test.junit.util.MiscUtils; +import com.jogamp.opengl.test.junit.util.NEWTGLContext; +import com.jogamp.opengl.test.junit.util.NEWTGLContext.WindowContext; import com.jogamp.opengl.test.junit.util.UITestCase; import java.io.IOException; @@ -70,7 +71,7 @@ public class TestGLSLShaderState02NEWT extends UITestCase { private void testShaderState01Validation(boolean linkSP1) throws InterruptedException { // preset .. - GLSLMiscHelper.WindowContext winctx = GLSLMiscHelper.createWindow(GLProfile.getGL2ES2(), true); + NEWTGLContext.WindowContext winctx = NEWTGLContext.createWindow(GLProfile.getGL2ES2(), 480, 480, true); GLDrawable drawable = winctx.context.getGLDrawable(); GL2ES2 gl = winctx.context.getGL().getGL2ES2(); System.err.println(winctx.context); @@ -222,13 +223,13 @@ public class TestGLSLShaderState02NEWT extends UITestCase { // cleanup st.destroy(gl); - GLSLMiscHelper.destroyWindow(winctx); + NEWTGLContext.destroyWindow(winctx); } @Test public void testShaderState01PerformanceDouble() throws InterruptedException { // preset .. - GLSLMiscHelper.WindowContext winctx = GLSLMiscHelper.createWindow(GLProfile.getGL2ES2(), false); + NEWTGLContext.WindowContext winctx = NEWTGLContext.createWindow(GLProfile.getGL2ES2(), 480, 480, false); GLDrawable drawable = winctx.context.getGLDrawable(); GL2ES2 gl = winctx.context.getGL().getGL2ES2(); System.err.println(winctx.context); @@ -344,7 +345,7 @@ public class TestGLSLShaderState02NEWT extends UITestCase { // cleanup st.destroy(gl); - GLSLMiscHelper.destroyWindow(winctx); + NEWTGLContext.destroyWindow(winctx); } public static void main(String args[]) throws IOException { diff --git a/src/test/com/jogamp/opengl/test/junit/util/NEWTGLContext.java b/src/test/com/jogamp/opengl/test/junit/util/NEWTGLContext.java new file mode 100644 index 000000000..ac91b642d --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/util/NEWTGLContext.java @@ -0,0 +1,105 @@ +/** + * 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.util; + +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; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLContext; +import javax.media.opengl.GLDrawable; +import javax.media.opengl.GLDrawableFactory; +import javax.media.opengl.GLProfile; + +import org.junit.Assert; + +public class NEWTGLContext { + + public static class WindowContext { + public final Window window; + public final GLContext context; + + public WindowContext(Window w, GLContext c) { + window = w; + context = c; + } + } + + public static WindowContext createWindow(GLProfile glp, int width, int height, boolean debugGL) { + GLCapabilities caps = new GLCapabilities(glp); + // + // 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); + + 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 void destroyWindow(WindowContext winctx) { + GLDrawable drawable = winctx.context.getGLDrawable(); + + Assert.assertNotNull(winctx.context); + winctx.context.destroy(); + + Assert.assertNotNull(drawable); + drawable.setRealized(false); + + Assert.assertNotNull(winctx.window); + winctx.window.destroy(); + } + +} |