From 41f73bf3bb8127dcfbbfb815bc7487007b47253c Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 25 Apr 2011 15:38:35 +0200 Subject: Fix GLSL Shader tests .. --- .../test/junit/jogl/glsl/GLSLMiscHelper.java | 84 ++++++++++++++++------ .../junit/jogl/glsl/TestGLSLShaderState01NEWT.java | 69 +++++++++--------- .../junit/jogl/glsl/TestGLSLShaderState02NEWT.java | 82 +++++++++++++-------- 3 files changed, 146 insertions(+), 89 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 0656b6338..ebe24cb00 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,7 +27,10 @@ */ package com.jogamp.opengl.test.junit.jogl.glsl; -import com.jogamp.newt.opengl.GLWindow; +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; @@ -35,6 +38,8 @@ 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; @@ -43,27 +48,62 @@ public class GLSLMiscHelper { public static final int frames_perftest = 10000; // frames public static final int frames_warmup = 500; // frames - public static GLWindow createWindow() throws InterruptedException { - GLProfile glp = GLProfile.get(GLProfile.GL2ES2); + 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); - GLWindow window = GLWindow.create(caps); - window.setSize(800, 600); + // + // 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); - Assert.assertTrue(window.isNativeValid()); - Assert.assertTrue(window.isRealized()); - GLContext context = window.getContext(); + + 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.setSynchronized(true); - while(!context.isCreated()) { - // wait for context creation via above setVisible - Thread.sleep(100); - } - context.makeCurrent(); // native context creation - context.release(); - Assert.assertTrue(context.isCreated()); - return window; + + 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) { @@ -89,7 +129,7 @@ public class GLSLMiscHelper { } } - public static void displayVCArrays(GLWindow window, GL2ES2 gl, ShaderState st, boolean preEnable, GLArrayDataServer vertices, GLArrayDataServer colors, boolean postDisable, int num, long postDelay) throws InterruptedException { + public static void displayVCArrays(GLDrawable drawable, GL2ES2 gl, ShaderState st, boolean preEnable, GLArrayDataServer vertices, GLArrayDataServer colors, boolean postDisable, int num, long postDelay) throws InterruptedException { System.err.println("screen #"+num); if(preEnable) { vertices.enableBuffer(gl, true); @@ -116,11 +156,11 @@ public class GLSLMiscHelper { Assert.assertTrue(!colors.enabled()); } Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - window.swapBuffers(); + drawable.swapBuffers(); if(postDelay>0) { pause(postDelay); } } - public static void displayVCArraysNoChecks(GLWindow window, GL2ES2 gl, boolean preEnable, GLArrayDataServer vertices, GLArrayDataServer colors, boolean postDisable) throws InterruptedException { + public static void displayVCArraysNoChecks(GLDrawable drawable, GL2ES2 gl, boolean preEnable, GLArrayDataServer vertices, GLArrayDataServer colors, boolean postDisable) throws InterruptedException { if(preEnable) { vertices.enableBuffer(gl, true); colors.enableBuffer(gl, true); @@ -131,7 +171,7 @@ public class GLSLMiscHelper { vertices.enableBuffer(gl, false); colors.enableBuffer(gl, false); } - window.swapBuffers(); + drawable.swapBuffers(); } public static GLArrayDataServer createRSVertices0(GL2ES2 gl, ShaderState st, int location) { 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 ea5680d42..f357113d3 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 @@ -27,7 +27,6 @@ */ package com.jogamp.opengl.test.junit.jogl.glsl; -import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opengl.util.GLArrayDataServer; import com.jogamp.opengl.util.PMVMatrix; import com.jogamp.opengl.util.glsl.ShaderCode; @@ -40,7 +39,8 @@ import com.jogamp.opengl.test.junit.util.UITestCase; import java.io.IOException; import javax.media.opengl.GL; import javax.media.opengl.GL2ES2; -import javax.media.opengl.GLContext; +import javax.media.opengl.GLDrawable; +import javax.media.opengl.GLProfile; import javax.media.opengl.GLUniformData; import org.junit.Assert; @@ -59,10 +59,9 @@ public class TestGLSLShaderState01NEWT extends UITestCase { @Test public void testShaderState01Validation() throws InterruptedException { // preset .. - GLWindow window = GLSLMiscHelper.createWindow(); - GLContext context = window.getContext(); - context.makeCurrent(); - GL2ES2 gl = context.getGL().getGL2ES2(); + GLSLMiscHelper.WindowContext winctx = GLSLMiscHelper.createWindow(GLProfile.getGL2ES2(), true); + GLDrawable drawable = winctx.context.getGLDrawable(); + GL2ES2 gl = winctx.context.getGL().getGL2ES2(); Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); @@ -144,7 +143,7 @@ public class TestGLSLShaderState01NEWT extends UITestCase { // reshape pmvMatrix.glMatrixMode(PMVMatrix.GL_PROJECTION); pmvMatrix.glLoadIdentity(); - pmvMatrix.gluPerspective(45.0F, (float) window.getWidth() / (float) window.getHeight(), 1.0F, 100.0F); + pmvMatrix.gluPerspective(45.0F, (float) drawable.getWidth() / (float) drawable.getHeight(), 1.0F, 100.0F); pmvMatrix.glMatrixMode(PMVMatrix.GL_MODELVIEW); pmvMatrix.glLoadIdentity(); pmvMatrix.glTranslatef(0, 0, -10); @@ -152,13 +151,13 @@ public class TestGLSLShaderState01NEWT extends UITestCase { Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); // display #1 vertices0 / colors0 (post-disable) - GLSLMiscHelper.displayVCArrays(window, gl, st, true, vertices0, colors0, true, 1, durationPerTest); + GLSLMiscHelper.displayVCArrays(drawable, gl, st, true, vertices0, colors0, true, 1, durationPerTest); // display #2 #1 vertices1 / colors1 (post-disable) - GLSLMiscHelper.displayVCArrays(window, gl, st, true, vertices1, colors1, true, 2, durationPerTest); + GLSLMiscHelper.displayVCArrays(drawable, gl, st, true, vertices1, colors1, true, 2, durationPerTest); // display #3 vertices0 / colors0 (post-disable) - GLSLMiscHelper.displayVCArrays(window, gl, st, true, vertices0, colors0, true, 3, durationPerTest); + GLSLMiscHelper.displayVCArrays(drawable, gl, st, true, vertices0, colors0, true, 3, durationPerTest); // cleanup vertices1.destroy(gl); @@ -167,8 +166,8 @@ public class TestGLSLShaderState01NEWT extends UITestCase { colors1.destroy(gl); st.glUseProgram(gl, false); sp.release(gl, true); - context.release(); - window.destroy(); + + GLSLMiscHelper.destroyWindow(winctx); } @Test @@ -182,11 +181,10 @@ public class TestGLSLShaderState01NEWT extends UITestCase { void testShaderState00PerformanceSingle(boolean toggleEnable) throws InterruptedException { // preset .. - GLWindow window = GLSLMiscHelper.createWindow(); - GLContext context = window.getContext(); - context.makeCurrent(); - GL2ES2 gl = context.getGL().getGL2ES2(); - + GLSLMiscHelper.WindowContext winctx = GLSLMiscHelper.createWindow(GLProfile.getGL2ES2(), false); + GLDrawable drawable = winctx.context.getGLDrawable(); + GL2ES2 gl = winctx.context.getGL().getGL2ES2(); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); // test code .. @@ -227,7 +225,7 @@ public class TestGLSLShaderState01NEWT extends UITestCase { // reshape pmvMatrix.glMatrixMode(PMVMatrix.GL_PROJECTION); pmvMatrix.glLoadIdentity(); - pmvMatrix.gluPerspective(45.0F, (float) window.getWidth() / (float) window.getHeight(), 1.0F, 100.0F); + pmvMatrix.gluPerspective(45.0F, (float) drawable.getWidth() / (float) drawable.getHeight(), 1.0F, 100.0F); pmvMatrix.glMatrixMode(PMVMatrix.GL_MODELVIEW); pmvMatrix.glLoadIdentity(); pmvMatrix.glTranslatef(0, 0, -10); @@ -237,15 +235,15 @@ public class TestGLSLShaderState01NEWT extends UITestCase { int frames; // validation .. - GLSLMiscHelper.displayVCArrays(window, gl, st, toggleEnable, vertices0, colors0, toggleEnable, 1, 0); + GLSLMiscHelper.displayVCArrays(drawable, gl, st, toggleEnable, vertices0, colors0, toggleEnable, 1, 0); // warmup .. for(frames=0; frames