From 84a76425dd10933a7ad033920a1e0ce12a2a107b Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 13 Dec 2010 02:26:48 +0100 Subject: Cleanup test/junit structure. com.jogamp.test -> com.jogamp.opengl.text; Compile posted Issue* Bug* snippets --- .../jogamp/opengl/test/bugs/Bug427GLJPanel.java | 72 +++ .../com/jogamp/opengl/test/bugs/Issue326Test1.java | 94 +++ .../com/jogamp/opengl/test/bugs/Issue326Test2.java | 73 +++ .../com/jogamp/opengl/test/bugs/Issue344Base.java | 107 +++ .../com/jogamp/opengl/test/bugs/Issue344Test1.java | 12 + .../com/jogamp/opengl/test/bugs/Issue344Test2.java | 12 + .../com/jogamp/opengl/test/bugs/Issue344Test3.java | 12 + .../com/jogamp/opengl/test/bugs/Issue344Test4.java | 12 + .../test/junit/jogl/acore/TestGLProfile01NEWT.java | 160 +++++ .../junit/jogl/acore/TestSharedContextListAWT.java | 134 ++++ .../jogl/acore/TestSharedContextListNEWT.java | 133 ++++ .../opengl/test/junit/jogl/awt/TestAWT01GLn.java | 147 +++++ .../junit/jogl/awt/TestAWT02WindowClosing.java | 111 ++++ .../jogl/awt/TestAWT03GLCanvasRecreate01.java | 183 ++++++ .../test/junit/jogl/awt/TestSwingAWT01GLn.java | 159 +++++ .../test/junit/jogl/caps/MultisampleChooser01.java | 66 ++ .../test/junit/jogl/caps/MultisampleDemo01.java | 138 ++++ .../test/junit/jogl/caps/TestMultisampleAWT.java | 122 ++++ .../test/junit/jogl/caps/TestMultisampleNEWT.java | 100 +++ .../test/junit/jogl/demos/es1/RedSquare.java | 169 +++++ .../test/junit/jogl/demos/es2/RedSquare0.java | 198 ++++++ .../jogl/demos/es2/shader/RedSquareShader.java | 68 ++ .../test/junit/jogl/demos/gl2/gears/Gears.java | 353 ++++++++++ .../junit/jogl/demos/gl2/gears/TestGearsAWT.java | 122 ++++ .../jogl/demos/gl2/gears/TestGearsGLJPanelAWT.java | 130 ++++ .../jogl/demos/gl2/gears/newt/TestGearsNEWT.java | 126 ++++ .../gl2/gears/newt/TestGearsNewtAWTWrapper.java | 114 ++++ .../junit/jogl/drawable/TestDrawable01NEWT.java | 184 ++++++ .../test/junit/jogl/glsl/TestGLSLSimple01NEWT.java | 143 ++++ .../TestTransformFeedbackVaryingsBug407NEWT.java | 231 +++++++ ...TestSwingAWTRobotUsageBeforeJOGLInitBug411.java | 333 ++++++++++ .../test/junit/jogl/offscreen/ReadBuffer2File.java | 70 ++ .../junit/jogl/offscreen/ReadBuffer2Screen.java | 188 ++++++ .../test/junit/jogl/offscreen/ReadBufferBase.java | 91 +++ .../test/junit/jogl/offscreen/ReadBufferUtil.java | 107 +++ .../test/junit/jogl/offscreen/Surface2File.java | 79 +++ .../junit/jogl/offscreen/TestOffscreen01NEWT.java | 489 ++++++++++++++ .../test/junit/jogl/offscreen/WindowUtilNEWT.java | 110 ++++ .../test/junit/jogl/texture/TestTexture01AWT.java | 146 +++++ .../util/texture/gl2/TextureGL2ListenerDraw1.java | 109 ++++ .../opengl/test/junit/newt/TestCloseNewtAWT.java | 141 ++++ .../junit/newt/TestDisplayLifecycle01NEWT.java | 264 ++++++++ .../junit/newt/TestDisplayLifecycle02NEWT.java | 386 +++++++++++ .../test/junit/newt/TestEventSourceNotAWTBug.java | 110 ++++ .../test/junit/newt/TestFocus01SwingAWTRobot.java | 201 ++++++ .../test/junit/newt/TestFocus02SwingAWTRobot.java | 301 +++++++++ .../test/junit/newt/TestGLWindows00NEWT.java | 133 ++++ .../test/junit/newt/TestGLWindows01NEWT.java | 384 +++++++++++ .../junit/newt/TestGLWindows02NEWTAnimated.java | 303 +++++++++ .../test/junit/newt/TestListenerCom01AWT.java | 167 +++++ .../test/junit/newt/TestRemoteGLWindows01NEWT.java | 161 +++++ .../test/junit/newt/TestRemoteWindow01NEWT.java | 139 ++++ .../test/junit/newt/TestScreenMode00NEWT.java | 140 ++++ .../test/junit/newt/TestScreenMode01NEWT.java | 284 ++++++++ .../test/junit/newt/TestScreenMode02NEWT.java | 187 ++++++ .../opengl/test/junit/newt/TestWindows01NEWT.java | 179 ++++++ .../opengl/test/junit/newt/WindowEventCom1.java | 42 ++ .../opengl/test/junit/newt/WindowEventCom2.java | 48 ++ .../opengl/test/junit/newt/WindowEventCom3.java | 44 ++ .../test/junit/newt/parenting/GLRunnableDummy.java | 57 ++ .../test/junit/newt/parenting/KeyAction.java | 45 ++ .../junit/newt/parenting/TestParenting01NEWT.java | 716 +++++++++++++++++++++ .../junit/newt/parenting/TestParenting01aAWT.java | 443 +++++++++++++ .../junit/newt/parenting/TestParenting01bAWT.java | 205 ++++++ .../junit/newt/parenting/TestParenting01cAWT.java | 243 +++++++ .../newt/parenting/TestParenting01cSwingAWT.java | 365 +++++++++++ .../junit/newt/parenting/TestParenting02AWT.java | 267 ++++++++ .../junit/newt/parenting/TestParenting02NEWT.java | 235 +++++++ .../junit/newt/parenting/TestParenting03AWT.java | 203 ++++++ .../junit/newt/parenting/TestParenting03bAWT.java | 258 ++++++++ .../test/junit/newt/parenting/WindowAction.java | 44 ++ .../opengl/test/junit/util/AWTFocusAdapter.java | 73 +++ .../opengl/test/junit/util/AWTKeyAdapter.java | 54 ++ .../opengl/test/junit/util/AWTMouseAdapter.java | 53 ++ .../opengl/test/junit/util/AWTRobotUtil.java | 338 ++++++++++ .../jogamp/opengl/test/junit/util/DumpGLInfo.java | 51 ++ .../opengl/test/junit/util/EventCountAdapter.java | 36 ++ .../test/junit/util/EventCountAdapterUtil.java | 49 ++ .../opengl/test/junit/util/GLSLSimpleProgram.java | 121 ++++ .../jogamp/opengl/test/junit/util/MiscUtils.java | 63 ++ .../opengl/test/junit/util/NEWTFocusAdapter.java | 64 ++ .../opengl/test/junit/util/NEWTKeyAdapter.java | 58 ++ .../opengl/test/junit/util/NEWTMouseAdapter.java | 57 ++ .../jogamp/opengl/test/junit/util/QuitAdapter.java | 52 ++ .../opengl/test/junit/util/SingletonInstance.java | 143 ++++ .../jogamp/opengl/test/junit/util/UITestCase.java | 72 +++ src/test/native/displayMultiple01.c | 18 + src/test/native/displayMultiple02.c | 113 ++++ src/test/native/glExtensionsListGL2.c | 95 +++ src/test/native/glExtensionsListGL3.c | 300 +++++++++ src/test/native/make.sh | 6 + 91 files changed, 13918 insertions(+) create mode 100644 src/test/com/jogamp/opengl/test/bugs/Bug427GLJPanel.java create mode 100644 src/test/com/jogamp/opengl/test/bugs/Issue326Test1.java create mode 100644 src/test/com/jogamp/opengl/test/bugs/Issue326Test2.java create mode 100644 src/test/com/jogamp/opengl/test/bugs/Issue344Base.java create mode 100644 src/test/com/jogamp/opengl/test/bugs/Issue344Test1.java create mode 100644 src/test/com/jogamp/opengl/test/bugs/Issue344Test2.java create mode 100644 src/test/com/jogamp/opengl/test/bugs/Issue344Test3.java create mode 100644 src/test/com/jogamp/opengl/test/bugs/Issue344Test4.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLProfile01NEWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListAWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListNEWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/awt/TestAWT01GLn.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/awt/TestAWT02WindowClosing.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/awt/TestAWT03GLCanvasRecreate01.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/awt/TestSwingAWT01GLn.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/caps/MultisampleChooser01.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/caps/MultisampleDemo01.java create mode 100755 src/test/com/jogamp/opengl/test/junit/jogl/caps/TestMultisampleAWT.java create mode 100755 src/test/com/jogamp/opengl/test/junit/jogl/caps/TestMultisampleNEWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/RedSquare.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquare0.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/RedSquareShader.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/Gears.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/TestGearsAWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/TestGearsGLJPanelAWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/newt/TestGearsNEWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/newt/TestGearsNewtAWTWrapper.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/drawable/TestDrawable01NEWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLSimple01NEWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestTransformFeedbackVaryingsBug407NEWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/newt/TestSwingAWTRobotUsageBeforeJOGLInitBug411.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBuffer2File.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBuffer2Screen.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBufferBase.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBufferUtil.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/offscreen/Surface2File.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/offscreen/TestOffscreen01NEWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/offscreen/WindowUtilNEWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/texture/TestTexture01AWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/util/texture/gl2/TextureGL2ListenerDraw1.java create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/TestCloseNewtAWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle01NEWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle02NEWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/TestEventSourceNotAWTBug.java create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/TestFocus01SwingAWTRobot.java create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/TestFocus02SwingAWTRobot.java create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows00NEWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows01NEWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows02NEWTAnimated.java create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/TestListenerCom01AWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/TestRemoteGLWindows01NEWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/TestRemoteWindow01NEWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00NEWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01NEWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode02NEWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/TestWindows01NEWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/WindowEventCom1.java create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/WindowEventCom2.java create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/WindowEventCom3.java create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/parenting/GLRunnableDummy.java create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/parenting/KeyAction.java create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01NEWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01aAWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01bAWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cAWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cSwingAWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02AWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02NEWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting03AWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting03bAWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/parenting/WindowAction.java create mode 100644 src/test/com/jogamp/opengl/test/junit/util/AWTFocusAdapter.java create mode 100644 src/test/com/jogamp/opengl/test/junit/util/AWTKeyAdapter.java create mode 100644 src/test/com/jogamp/opengl/test/junit/util/AWTMouseAdapter.java create mode 100644 src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java create mode 100644 src/test/com/jogamp/opengl/test/junit/util/DumpGLInfo.java create mode 100644 src/test/com/jogamp/opengl/test/junit/util/EventCountAdapter.java create mode 100644 src/test/com/jogamp/opengl/test/junit/util/EventCountAdapterUtil.java create mode 100644 src/test/com/jogamp/opengl/test/junit/util/GLSLSimpleProgram.java create mode 100644 src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java create mode 100644 src/test/com/jogamp/opengl/test/junit/util/NEWTFocusAdapter.java create mode 100644 src/test/com/jogamp/opengl/test/junit/util/NEWTKeyAdapter.java create mode 100644 src/test/com/jogamp/opengl/test/junit/util/NEWTMouseAdapter.java create mode 100644 src/test/com/jogamp/opengl/test/junit/util/QuitAdapter.java create mode 100644 src/test/com/jogamp/opengl/test/junit/util/SingletonInstance.java create mode 100644 src/test/com/jogamp/opengl/test/junit/util/UITestCase.java create mode 100644 src/test/native/displayMultiple01.c create mode 100644 src/test/native/displayMultiple02.c create mode 100644 src/test/native/glExtensionsListGL2.c create mode 100644 src/test/native/glExtensionsListGL3.c create mode 100755 src/test/native/make.sh (limited to 'src/test') diff --git a/src/test/com/jogamp/opengl/test/bugs/Bug427GLJPanel.java b/src/test/com/jogamp/opengl/test/bugs/Bug427GLJPanel.java new file mode 100644 index 000000000..378952b59 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/bugs/Bug427GLJPanel.java @@ -0,0 +1,72 @@ +package com.jogamp.opengl.test.bugs; + +import javax.swing.*; +import java.awt.*; +import javax.media.opengl.*; +import javax.media.opengl.awt.*; + +public class Bug427GLJPanel extends JFrame implements GLEventListener { + + public Bug427GLJPanel() { + super("JOGL Hello World"); + + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setLayout(new BorderLayout()); + + setSize(600, 600); + setLocation(40, 40); + setVisible(true); + + GLProfile glp = GLProfile.getDefault(); + GLCapabilities caps = new GLCapabilities(glp); + caps.setDoubleBuffered(true); + caps.setHardwareAccelerated(true); + + GLJPanel panel = new GLJPanel(caps); + panel.addGLEventListener(this); + + add(panel, BorderLayout.CENTER); + } + + public static void main(String[] args) { + Bug427GLJPanel demo = new Bug427GLJPanel(); + demo.setVisible(true); + } + + public void display(GLAutoDrawable drawable) { + GL2 gl = drawable.getGL().getGL2(); + + gl.glClear(GL.GL_COLOR_BUFFER_BIT); + gl.glBegin(GL.GL_TRIANGLES); + + gl.glColor3f(1, 0, 0); + gl.glVertex3f(0.25f, 0.25f, 0); + + gl.glColor3f(0, 1, 0); + gl.glVertex3f(0.5f, 0.25f, 0); + + gl.glColor3f(0, 0, 1); + gl.glVertex3f(0.25f, 0.5f, 0); + + gl.glEnd(); + gl.glFlush(); + } + + public void init(GLAutoDrawable drawable) { + GL2 gl = drawable.getGL().getGL2(); + + gl.glClearColor(0, 0, 0, 0); + gl.glMatrixMode(GL2.GL_PROJECTION); + gl.glLoadIdentity(); + gl.glOrtho(0, 1, 0, 1, -1, 1); + } + + public void reshape(GLAutoDrawable glDrawable, int x, int y, int w, int h) { + } + + public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { + } + + public void dispose(GLAutoDrawable drawable) { + } +} diff --git a/src/test/com/jogamp/opengl/test/bugs/Issue326Test1.java b/src/test/com/jogamp/opengl/test/bugs/Issue326Test1.java new file mode 100644 index 000000000..4c2b54755 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/bugs/Issue326Test1.java @@ -0,0 +1,94 @@ +package com.jogamp.opengl.test.bugs; + +import java.awt.Frame; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.util.Random; + +import javax.media.opengl.GL2; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.awt.GLCanvas; +import javax.media.opengl.glu.GLU; + +import com.jogamp.opengl.util.Animator; +import com.jogamp.opengl.util.awt.TextRenderer; + +/** + * Demonstrates corruption with older versions of TextRenderer. Two + * problems: errors when punting from glyph-based renderer to + * string-by-string renderer, and failure of glyph-based renderer when + * backing store was NPOT using GL_ARB_texture_rectangle. + * + * @author emzic + */ + +public class Issue326Test1 extends Frame implements GLEventListener { + + int width, height; + + public static void main(String[] args) { + new Issue326Test1(); + } + + GLCanvas canvas; + TextRenderer tr ; + + public Issue326Test1() { + super("TextTest"); + this.setSize(800, 800); + canvas = new GLCanvas(); + canvas.addGLEventListener(this); + add(canvas); + + setVisible(true); + addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + System.exit(0); + } + }); + } + + public void display(GLAutoDrawable drawable) { + GL2 gl = drawable.getGL().getGL2(); + gl.glClearColor(0, 0, 0, 0); + gl.glClear(GL2.GL_COLOR_BUFFER_BIT|GL2.GL_DEPTH_BUFFER_BIT); + + + gl.glMatrixMode(GL2.GL_PROJECTION); + gl.glLoadIdentity(); + //new GLU().gluPerspective(45f, (float)width/(float)height, 0.1f, 1000f); + gl.glOrtho(0.0, 800, 0.0, 800, -100.0, 100.0); + gl.glMatrixMode(GL2.GL_MODELVIEW); + gl.glLoadIdentity(); + + tr.beginRendering(800,800); + tr.draw( "die Marktwirtschaft. Da regelt sich � angeblich", 16, 32); + tr.draw( "Hello World! This text is scrambled", 16, 16); + tr.endRendering(); + + } + + public void init(GLAutoDrawable arg0) { + tr = new TextRenderer(new java.awt.Font("Verdana", java.awt.Font.PLAIN, 12), true, false, null, false); + tr.setColor(1, 1, 1 ,1); + } + + public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4) { + width = arg3; + height = arg4; + GL2 gl = arg0.getGL().getGL2(); + gl.glViewport(0, 0, width, height); + gl.glMatrixMode(GL2.GL_PROJECTION); + gl.glLoadIdentity(); + gl.glOrtho(0.0, 800, 0.0, 200, -100.0, 100.0); + gl.glMatrixMode(GL2.GL_MODELVIEW); + gl.glLoadIdentity(); + } + + public void dispose(GLAutoDrawable drawable) {} +} diff --git a/src/test/com/jogamp/opengl/test/bugs/Issue326Test2.java b/src/test/com/jogamp/opengl/test/bugs/Issue326Test2.java new file mode 100644 index 000000000..8960c9658 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/bugs/Issue326Test2.java @@ -0,0 +1,73 @@ +package com.jogamp.opengl.test.bugs; + +import java.awt.Font; +import java.awt.Frame; +import java.awt.event.*; +import javax.media.opengl.GL2; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.awt.GLCanvas; + +import com.jogamp.opengl.util.awt.*; + +/** + * Another test case demonstrating corruption with older version of + * TextRenderer when glyphs were too big for backing store. Font and + * text courtesy of Patrick Murris. Adapted from Issue326Test1. + */ + +public class Issue326Test2 extends Frame implements GLEventListener { + + int width, height; + + public static void main(String[] args) { + new Issue326Test2(); + } + + GLCanvas canvas; + TextRenderer tr; + + public Issue326Test2() { + super(""); + this.setSize(800, 800); + canvas = new GLCanvas(); + canvas.addGLEventListener(this); + add(canvas); + + setVisible(true); + addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + System.exit(0); + } + }); + } + + public void display(GLAutoDrawable drawable) { + GL2 gl = drawable.getGL().getGL2(); + gl.glClearColor(0, 0, 0, 0); + gl.glClear(GL2.GL_COLOR_BUFFER_BIT|GL2.GL_DEPTH_BUFFER_BIT); + + tr.beginRendering(drawable.getWidth(), drawable.getHeight()); + tr.draw("LA CLAPI\u00c8RE \nAlt: 1100-1700m \nGlissement de terrain majeur", 16, 80); + tr.draw("dans la haute Tin\u00e9e, sur un flanc du Parc du Mercantour.", 16, 16); + tr.endRendering(); + + } + + public void init(GLAutoDrawable arg0) { + tr = new TextRenderer(Font.decode("Arial-BOLD-64")); + tr.setColor(1, 1, 1 ,1); + } + + public void reshape(GLAutoDrawable arg0, int x, int y, int w, int h) { + GL2 gl = arg0.getGL().getGL2(); + gl.glMatrixMode(GL2.GL_PROJECTION); + gl.glLoadIdentity(); + gl.glOrtho(0.0, w, 0.0, h, -1, 1); + gl.glMatrixMode(GL2.GL_MODELVIEW); + gl.glLoadIdentity(); + } + + public void dispose(GLAutoDrawable drawable) {} +} + diff --git a/src/test/com/jogamp/opengl/test/bugs/Issue344Base.java b/src/test/com/jogamp/opengl/test/bugs/Issue344Base.java new file mode 100644 index 000000000..c3401fec3 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/bugs/Issue344Base.java @@ -0,0 +1,107 @@ +package com.jogamp.opengl.test.bugs; + +import java.awt.BorderLayout; +import java.awt.Font; +import java.awt.Frame; +import java.awt.event.*; +import java.awt.geom.*; + +import javax.media.opengl.GL2; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.awt.GLCanvas; +import javax.media.opengl.glu.*; +import com.jogamp.opengl.util.awt.TextRenderer; + +/** Test Code adapted from TextCube.java (in JOGL demos) + * + * @author spiraljetty + * @author kbr + */ + +public abstract class Issue344Base implements GLEventListener +{ + GLU glu = new GLU(); + TextRenderer renderer; + + float textScaleFactor; + Font font; + boolean useMipMaps; + + protected Issue344Base() { + font = new Font("default", Font.PLAIN, 200); + useMipMaps = true; //false + } + + protected abstract String getText(); + + protected void run(String[] args) { + Frame frame = new Frame(getClass().getName()); + frame.setLayout(new BorderLayout()); + + GLCanvas canvas = new GLCanvas(); + canvas.addGLEventListener(this); + frame.add(canvas, BorderLayout.CENTER); + + frame.setSize(512, 512); + frame.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + new Thread(new Runnable() { + public void run() { + System.exit(0); + } + }).start(); + } + }); + frame.setVisible(true); + } + + public void init(GLAutoDrawable drawable) + { + GL2 gl = drawable.getGL().getGL2(); + + gl.glEnable(GL2.GL_DEPTH_TEST); + + renderer = new TextRenderer(font, useMipMaps); + + Rectangle2D bounds = renderer.getBounds(getText()); + float w = (float) bounds.getWidth(); + float h = (float) bounds.getHeight(); + textScaleFactor = 2.0f / (w * 1.1f); + gl.setSwapInterval(0); + } + + public void display(GLAutoDrawable drawable) + { + GL2 gl = drawable.getGL().getGL2(); + gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT); + + gl.glMatrixMode(GL2.GL_MODELVIEW); + gl.glLoadIdentity(); + glu.gluLookAt(0, 0, 10, + 0, 0, 0, + 0, 1, 0); + + renderer.begin3DRendering(); + Rectangle2D bounds = renderer.getBounds(getText()); + float w = (float) bounds.getWidth(); + float h = (float) bounds.getHeight(); + renderer.draw3D(getText(), + w / -2.0f * textScaleFactor, + h / -2.0f * textScaleFactor, + 3f, + textScaleFactor); + + renderer.end3DRendering(); + } + + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) + { + GL2 gl = drawable.getGL().getGL2(); + gl.glMatrixMode(GL2.GL_PROJECTION); + gl.glLoadIdentity(); + glu.gluPerspective(15, (float) width / (float) height, 5, 15); + } + + public void dispose(GLAutoDrawable drawable) {} +} diff --git a/src/test/com/jogamp/opengl/test/bugs/Issue344Test1.java b/src/test/com/jogamp/opengl/test/bugs/Issue344Test1.java new file mode 100644 index 000000000..f0da7cbf8 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/bugs/Issue344Test1.java @@ -0,0 +1,12 @@ +package com.jogamp.opengl.test.bugs; + +public class Issue344Test1 extends Issue344Base { + protected String getText() { + // test 1 - weird artifacts appear with a large font & long string + return "abcdefghijklmnopqrstuvwxyz1234567890"; + } + + public static void main(String[] args) { + new Issue344Test1().run(args); + } +} diff --git a/src/test/com/jogamp/opengl/test/bugs/Issue344Test2.java b/src/test/com/jogamp/opengl/test/bugs/Issue344Test2.java new file mode 100644 index 000000000..bb1acf2de --- /dev/null +++ b/src/test/com/jogamp/opengl/test/bugs/Issue344Test2.java @@ -0,0 +1,12 @@ +package com.jogamp.opengl.test.bugs; + +public class Issue344Test2 extends Issue344Base { + protected String getText() { + // test 2 - unicode hangs program with a large font & long string + return "\u201Cabcdefghijklmnopqrstuvwxyz\u201D"; + } + + public static void main(String[] args) { + new Issue344Test2().run(args); + } +} diff --git a/src/test/com/jogamp/opengl/test/bugs/Issue344Test3.java b/src/test/com/jogamp/opengl/test/bugs/Issue344Test3.java new file mode 100644 index 000000000..bb73d84ec --- /dev/null +++ b/src/test/com/jogamp/opengl/test/bugs/Issue344Test3.java @@ -0,0 +1,12 @@ +package com.jogamp.opengl.test.bugs; + +public class Issue344Test3 extends Issue344Base { + protected String getText() { + // test 3 - slight rendering artifacts around very large letters + return "abcde"; + } + + public static void main(String[] args) { + new Issue344Test3().run(args); + } +} diff --git a/src/test/com/jogamp/opengl/test/bugs/Issue344Test4.java b/src/test/com/jogamp/opengl/test/bugs/Issue344Test4.java new file mode 100644 index 000000000..de4c37a40 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/bugs/Issue344Test4.java @@ -0,0 +1,12 @@ +package com.jogamp.opengl.test.bugs; + +public class Issue344Test4 extends Issue344Base { + protected String getText() { + // test 4 - unicode letter as second-to-last is rendered incorrectly + return "\u201CGreetings\u201D!"; + } + + public static void main(String[] args) { + new Issue344Test4().run(args); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLProfile01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLProfile01NEWT.java new file mode 100644 index 000000000..88caed357 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLProfile01NEWT.java @@ -0,0 +1,160 @@ +/** + * 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.acore; + +import com.jogamp.common.GlueGenVersion; +import com.jogamp.common.util.VersionUtil; +import com.jogamp.nativewindow.NativeWindowVersion; +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.test.junit.util.DumpGLInfo; + +import org.junit.Assert; +import org.junit.Test; + +import javax.media.opengl.*; +import com.jogamp.newt.opengl.*; + +import com.jogamp.newt.*; +import com.jogamp.opengl.JoglVersion; +import java.io.IOException; + +public class TestGLProfile01NEWT extends UITestCase { + + @Test + public void test00Version() throws InterruptedException { + System.err.println(VersionUtil.getPlatformInfo()); + System.err.println(GlueGenVersion.getInstance()); + System.err.println(NativeWindowVersion.getInstance()); + System.err.println(JoglVersion.getInstance()); + System.err.println(NewtVersion.getInstance()); + } + + @Test + public void test01GLProfileDefault() throws InterruptedException { + System.out.println("GLProfile "+GLProfile.glAvailabilityToString()); + GLProfile glp = GLProfile.getDefault(); + dumpVersion(glp); + } + + @Test + public void test02GLProfileMaxFixedFunc() throws InterruptedException { + // Assuming at least one fixed profile is available + GLProfile glp = GLProfile.getMaxFixedFunc(); + System.out.println("GLProfile getMaxFixedFunc(): "+glp); + if(glp.getName().equals(GLProfile.GL4bc)) { + Assert.assertTrue(GLProfile.isGL4bcAvailable()); + Assert.assertTrue(GLProfile.isGL3bcAvailable()); + Assert.assertTrue(GLProfile.isGL2Available()); + Assert.assertTrue(GLProfile.isGL2ES1Available()); + Assert.assertTrue(GLProfile.isGL2ES2Available()); + } else if(glp.getName().equals(GLProfile.GL3bc)) { + Assert.assertTrue(GLProfile.isGL3bcAvailable()); + Assert.assertTrue(GLProfile.isGL2Available()); + Assert.assertTrue(GLProfile.isGL2ES1Available()); + Assert.assertTrue(GLProfile.isGL2ES2Available()); + } else if(glp.getName().equals(GLProfile.GL2)) { + Assert.assertTrue(GLProfile.isGL2Available()); + Assert.assertTrue(GLProfile.isGL2ES1Available()); + Assert.assertTrue(GLProfile.isGL2ES2Available()); + } else if(glp.getName().equals(GLProfile.GL2ES1)) { + Assert.assertTrue(GLProfile.isGL2ES1Available()); + } + dumpVersion(glp); + } + + @Test + public void test03GLProfileMaxProgrammable() throws InterruptedException { + // Assuming at least one programmable profile is available + GLProfile glp = GLProfile.getMaxProgrammable(); + System.out.println("GLProfile getMaxProgrammable(): "+glp); + if(glp.getName().equals(GLProfile.GL4)) { + Assert.assertTrue(GLProfile.isGL4Available()); + Assert.assertTrue(GLProfile.isGL3Available()); + Assert.assertTrue(GLProfile.isGL2Available()); + Assert.assertTrue(GLProfile.isGL2ES1Available()); + Assert.assertTrue(GLProfile.isGL2ES2Available()); + } else if(glp.getName().equals(GLProfile.GL3)) { + Assert.assertTrue(GLProfile.isGL3Available()); + Assert.assertTrue(GLProfile.isGL2Available()); + Assert.assertTrue(GLProfile.isGL2ES1Available()); + Assert.assertTrue(GLProfile.isGL2ES2Available()); + } else if(glp.getName().equals(GLProfile.GL2)) { + Assert.assertTrue(GLProfile.isGL2Available()); + Assert.assertTrue(GLProfile.isGL2ES1Available()); + Assert.assertTrue(GLProfile.isGL2ES2Available()); + } else if(glp.getName().equals(GLProfile.GL2ES2)) { + Assert.assertTrue(GLProfile.isGL2ES2Available()); + } + dumpVersion(glp); + } + + @Test + public void test04GLProfileGL2ES1() throws InterruptedException { + if(!GLProfile.isGL2ES1Available()) { + System.out.println("GLProfile GL2ES1 n/a"); + return; + } + GLProfile glp = GLProfile.getGL2ES1(); + System.out.println("GLProfile GL2ES1: "+glp); + dumpVersion(glp); + } + + @Test + public void test05GLProfileGL2ES2() throws InterruptedException { + if(!GLProfile.isGL2ES2Available()) { + System.out.println("GLProfile GL2ES2 n/a"); + return; + } + GLProfile glp = GLProfile.getGL2ES2(); + System.out.println("GLProfile GL2ES2: "+glp); + dumpVersion(glp); + } + + protected void dumpVersion(GLProfile glp) throws InterruptedException { + GLCapabilities caps = new GLCapabilities(glp); + GLWindow glWindow = GLWindow.create(caps); + Assert.assertNotNull(glWindow); + glWindow.setTitle("TestGLProfile01NEWT"); + + glWindow.addGLEventListener(new DumpGLInfo()); + + glWindow.setSize(128, 128); + glWindow.setVisible(true); + + glWindow.display(); + Thread.sleep(100); + glWindow.invalidate(); + } + + public static void main(String args[]) throws IOException { + String tstname = TestGLProfile01NEWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListAWT.java new file mode 100644 index 000000000..dd3518fe3 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListAWT.java @@ -0,0 +1,134 @@ +/** + * 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.acore; + +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLDrawableFactory; +import javax.media.opengl.GLPbuffer; +import javax.media.opengl.GLProfile; +import javax.media.opengl.awt.GLCanvas; +import com.jogamp.opengl.util.Animator; + +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears; + +import java.awt.Frame; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +public class TestSharedContextListAWT extends UITestCase { + static GLProfile glp; + static GLCapabilities caps; + static int width, height; + GLPbuffer sharedDrawable; + Gears sharedGears; + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + glp = GLProfile.getDefault(); + Assert.assertNotNull(glp); + caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + width = 512; + height = 512; + } + + private void initShared() { + sharedDrawable = GLDrawableFactory.getFactory(glp).createGLPbuffer(null, caps, null, width, height, null); + Assert.assertNotNull(sharedDrawable); + sharedGears = new Gears(); + Assert.assertNotNull(sharedGears); + sharedDrawable.addGLEventListener(sharedGears); + // init and render one frame, which will setup the Gears display lists + sharedDrawable.display(); + } + + private void releaseShared() { + Assert.assertNotNull(sharedDrawable); + sharedDrawable.destroy(); + } + + protected Frame runTestGL(Animator animator, int x, int y, boolean useShared) { + Frame frame = new Frame("Shared Gears AWT Test: "+x+"/"+y+" shared "+useShared); + Assert.assertNotNull(frame); + + GLCanvas glCanvas = new GLCanvas(caps, useShared ? sharedDrawable.getContext() : null); + Assert.assertNotNull(glCanvas); + frame.add(glCanvas); + frame.setSize(width, height); + frame.setLocation(x, y); + + Gears gears = new Gears(); + if(useShared) { + gears.setGears(sharedGears.getGear1(), sharedGears.getGear2(), sharedGears.getGear3()); + } + glCanvas.addGLEventListener(gears); + + animator.add(glCanvas); + + frame.setVisible(true); + + return frame; + } + + @Test + public void test01() throws InterruptedException { + initShared(); + Animator animator = new Animator(); + Frame f1 = runTestGL(animator, 0, 0, true); + Frame f2 = runTestGL(animator, width, 0, true); + Frame f3 = runTestGL(animator, 0, height, false); + animator.start(); + while(animator.isAnimating() && animator.getDuration()= 0; i--) { + gl.glVertex3d(radius * Math.cos(i * increment), radius * Math.sin(i * increment), 0); + gl.glVertex3d(-1.0 * radius * Math.cos(i * increment), -1.0 * radius * Math.sin(i * increment), 0); + } + gl.glEnd(); + if (multisample) { + gl.glDisable(GL.GL_MULTISAMPLE); + } + } + + // Unused routines + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + } + + public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestMultisampleAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestMultisampleAWT.java new file mode 100755 index 000000000..53047611d --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestMultisampleAWT.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.test.junit.jogl.caps; + +import com.jogamp.opengl.test.junit.util.MiscUtils; +import java.awt.*; +import javax.media.opengl.*; +import javax.media.opengl.awt.GLCanvas; +import com.jogamp.opengl.test.junit.util.UITestCase; +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.AbstractGraphicsScreen; +import javax.media.nativewindow.GraphicsConfigurationFactory; +import javax.media.nativewindow.awt.AWTGraphicsConfiguration; +import javax.media.nativewindow.awt.AWTGraphicsDevice; +import javax.media.nativewindow.awt.AWTGraphicsScreen; +import org.junit.Test; + + +public class TestMultisampleAWT extends UITestCase { + static long durationPerTest = 500; // ms + private GLCanvas canvas; + + public static void main(String[] args) { + for(int i=0; i0) { + caps.setSampleBuffers(true); + caps.setNumSamples(samples); + } + // turns out we need to have alpha, + // otherwise no AA will be visible. + caps.setAlphaBits(1); + + /** + * whatever I tried here (passing and preconfig GraphicsConfiguration) + * either it just didn't picked up .. or the context couldn't be made current. + * + GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); + GraphicsConfiguration gc = AWTGraphicsConfiguration.getAWTGraphicsConfiguration(caps, gd); + + AbstractGraphicsScreen aScreen = AWTGraphicsScreen.createScreenDevice(gd, AbstractGraphicsDevice.DEFAULT_UNIT); + AWTGraphicsConfiguration config = (AWTGraphicsConfiguration) + GraphicsConfigurationFactory.getFactory(AWTGraphicsDevice.class).chooseGraphicsConfiguration(caps, caps, + chooser, aScreen); + canvas = new GLCanvas(caps, chooser, null, gd, config.getGraphicsConfiguration(), config); */ + canvas = new GLCanvas(caps, chooser, null, null); + canvas.addGLEventListener(new MultisampleDemo01(samples>0?true:false)); + + Frame frame = new Frame("Multi Samples "+samples); + frame.setLayout(new BorderLayout()); + canvas.setSize(512, 512); + frame.add(canvas, BorderLayout.CENTER); + frame.pack(); + frame.setVisible(true); + frame.setLocation(0, 0); + canvas.requestFocus(); + + Thread.sleep(durationPerTest); + + frame.dispose(); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestMultisampleNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestMultisampleNEWT.java new file mode 100755 index 000000000..8285a6699 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestMultisampleNEWT.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.test.junit.jogl.caps; + +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.test.junit.util.MiscUtils; +import javax.media.opengl.*; +import org.junit.Test; + +public class TestMultisampleNEWT { + static long durationPerTest = 500; // ms + private GLWindow window; + + public static void main(String[] args) { + for(int i=0; i0) { + caps.setSampleBuffers(true); + caps.setNumSamples(4); + } + // turns out we need to have alpha, + // otherwise no AA will be visible. + caps.setAlphaBits(1); + + window = GLWindow.create(caps); + window.setCapabilitiesChooser(chooser); + window.addGLEventListener(new MultisampleDemo01(samples>0?true:false)); + window.setSize(512, 512); + window.setVisible(true); + window.setPosition(0, 0); + window.requestFocus(); + + GLCapabilitiesImmutable capsChosen0 = window.getChosenGLCapabilities(); + + Thread.sleep(durationPerTest); + + window.destroy(); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/RedSquare.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/RedSquare.java new file mode 100644 index 000000000..eaf697a10 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/RedSquare.java @@ -0,0 +1,169 @@ +package com.jogamp.opengl.test.junit.jogl.demos.es1; + +import com.jogamp.common.nio.Buffers; +import java.nio.*; +import java.util.*; +import javax.media.opengl.*; +import javax.media.opengl.glu.*; +import javax.media.nativewindow.*; + +import com.jogamp.opengl.util.*; +import com.jogamp.opengl.util.glsl.fixedfunc.*; + +public class RedSquare implements GLEventListener { + + public static boolean glDebugEmu = false; + public static boolean glDebug = false ; + public static boolean glTrace = false ; + public static boolean oneThread = false; + public static boolean useAnimator = false; + public static int swapInterval = -1; + + boolean debug = false; + long startTime = 0; + long curTime = 0; + + GLU glu = null; + + public RedSquare() { + this(false); + } + + public RedSquare(boolean debug) { + this.debug = debug; + } + + // FIXME: we must add storage of the pointers in the GL state to + // the GLImpl classes. The need for this can be seen by making + // these variables method local instead of instance members. The + // square will disappear after a second or so due to garbage + // collection. On desktop OpenGL this implies a stack of + // references due to the existence of glPush/PopClientAttrib. On + // OpenGL ES 1/2 it can simply be one set of references. + private FloatBuffer colors; + private FloatBuffer vertices; + + public void init(GLAutoDrawable drawable) { + System.out.println("RedSquare: Init"); + GL _gl = drawable.getGL(); + + if(glDebugEmu) { + try { + // Debug .. + _gl = _gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Debug", GL2ES2.class, _gl, null) ); + + if(glTrace) { + // Trace .. + _gl = _gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Trace", GL2ES2.class, _gl, new Object[] { System.err } ) ); + } + } catch (Exception e) {e.printStackTrace();} + glDebug = false; + glTrace = false; + } + + GL2ES1 gl = FixedFuncUtil.getFixedFuncImpl(_gl); + if(swapInterval>=0) { + gl.setSwapInterval(swapInterval); + } + + if(glDebug) { + try { + // Debug .. + gl = (GL2ES1) gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Debug", GL2ES1.class, gl, null) ); + } catch (Exception e) {e.printStackTrace();} + } + + if(glTrace) { + try { + // Trace .. + gl = (GL2ES1) gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Trace", GL2ES1.class, gl, new Object[] { System.err } ) ); + } catch (Exception e) {e.printStackTrace();} + } + + glu = GLU.createGLU(gl); + + if(debug) { + System.err.println(Thread.currentThread()+" Entering initialization"); + System.err.println(Thread.currentThread()+" GL Profile: "+gl.getGLProfile()); + System.err.println(Thread.currentThread()+" GL:" + gl); + System.err.println(Thread.currentThread()+" GL_VERSION=" + gl.glGetString(gl.GL_VERSION)); + System.err.println(Thread.currentThread()+" GL_EXTENSIONS:"); + System.err.println(Thread.currentThread()+" " + gl.glGetString(gl.GL_EXTENSIONS)); + System.err.println(Thread.currentThread()+" swapInterval: " + swapInterval + " (GL: "+gl.getSwapInterval()+")"); + System.err.println(Thread.currentThread()+" GLU: " + glu); + } + + // Allocate vertex arrays + colors = Buffers.newDirectFloatBuffer(16); + vertices = Buffers.newDirectFloatBuffer(12); + // Fill them up + colors.put( 0, 1); colors.put( 1, 0); colors.put( 2, 0); colors.put( 3, 1); + colors.put( 4, 0); colors.put( 5, 0); colors.put( 6, 1); colors.put( 7, 1); + colors.put( 8, 1); colors.put( 9, 0); colors.put(10, 0); colors.put(11, 1); + colors.put(12, 1); colors.put(13, 0); colors.put(14, 0); colors.put(15, 1); + vertices.put(0, -2); vertices.put( 1, 2); vertices.put( 2, 0); + vertices.put(3, 2); vertices.put( 4, 2); vertices.put( 5, 0); + vertices.put(6, -2); vertices.put( 7, -2); vertices.put( 8, 0); + vertices.put(9, 2); vertices.put(10, -2); vertices.put(11, 0); + + gl.glEnableClientState(gl.GL_VERTEX_ARRAY); + gl.glEnableClientState(gl.GL_COLOR_ARRAY); + gl.glVertexPointer(3, GL.GL_FLOAT, 0, vertices); + gl.glColorPointer(4, GL.GL_FLOAT, 0, colors); + + // OpenGL Render Settings + gl.glClearColor(0, 0, 0, 1); + gl.glEnable(GL.GL_DEPTH_TEST); + + startTime = System.currentTimeMillis(); + curTime = startTime; + } + + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + System.out.println("RedSquare: Reshape"); + GL2ES1 gl = drawable.getGL().getGL2ES1(); + // Set location in front of camera + gl.glMatrixMode(gl.GL_PROJECTION); + gl.glLoadIdentity(); + glu.gluPerspective(45.0f, (float)width / (float)height, 1.0f, 100.0f); + //gl.glOrthof(-4.0f, 4.0f, -4.0f, 4.0f, 1.0f, 100.0f); + //glu.gluLookAt(0, 0, -20, 0, 0, 0, 0, 1, 0); + } + + public void display(GLAutoDrawable drawable) { + curTime = System.currentTimeMillis(); + GL2ES1 gl = drawable.getGL().getGL2ES1(); + gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); + + // One rotation every four seconds + gl.glMatrixMode(gl.GL_MODELVIEW); + gl.glLoadIdentity(); + gl.glTranslatef(0, 0, -10); + float ang = ((float) (curTime - startTime) * 360.0f) / 4000.0f; + gl.glRotatef(ang, 0, 0, 1); + gl.glRotatef(ang, 0, 1, 0); + + + // Draw a square + gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 4); + } + + public void dispose(GLAutoDrawable drawable) { + System.out.println("RedSquare: Dispose"); + GL2ES1 gl = drawable.getGL().getGL2ES1(); + if(debug) { + System.out.println(Thread.currentThread()+" RedSquare.dispose: "+gl.getContext()); + } + gl.glDisableClientState(gl.GL_VERTEX_ARRAY); + gl.glDisableClientState(gl.GL_COLOR_ARRAY); + glu.destroy(); + glu = null; + colors.clear(); + colors = null; + vertices.clear(); + vertices = null; + if(debug) { + System.out.println(Thread.currentThread()+" RedSquare.dispose: FIN"); + } + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquare0.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquare0.java new file mode 100644 index 000000000..f062a7375 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquare0.java @@ -0,0 +1,198 @@ +/** + * 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.demos.es2; + +import com.jogamp.common.nio.Buffers; +import com.jogamp.opengl.util.Animator; +import com.jogamp.opengl.util.GLArrayDataWrapper; +import com.jogamp.opengl.util.PMVMatrix; +import com.jogamp.opengl.test.junit.jogl.demos.es2.shader.RedSquareShader; +import com.jogamp.opengl.test.junit.util.GLSLSimpleProgram; +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.nio.FloatBuffer; +import javax.media.opengl.GL; +import javax.media.opengl.GL2ES2; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLContext; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.GLUniformData; +import org.junit.Assert; + +public class RedSquare0 implements GLEventListener { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + PrintStream pbaos = new PrintStream(baos); + GLSLSimpleProgram myShader; + PMVMatrix pmvMatrix; + int mgl_PMVMatrix; + GLUniformData pmvMatrixUniform; + int mgl_Vertex; + int mgl_Color; + long t0; + + public void init(GLAutoDrawable glad) { + GLContext context = glad.getContext(); + context.makeCurrent(); + GL2ES2 gl = context.getGL().getGL2ES2(); + myShader = GLSLSimpleProgram.create(gl, RedSquareShader.VERTEX_SHADER_TEXT, RedSquareShader.FRAGMENT_SHADER_TEXT, true); + gl.glUseProgram(myShader.getShaderProgram()); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + // setup mgl_PMVMatrix + pmvMatrix = new PMVMatrix(); + pmvMatrix.glMatrixMode(PMVMatrix.GL_PROJECTION); + pmvMatrix.glLoadIdentity(); + pmvMatrix.glMatrixMode(PMVMatrix.GL_MODELVIEW); + pmvMatrix.glLoadIdentity(); + mgl_PMVMatrix = gl.glGetUniformLocation(myShader.getShaderProgram(), "mgl_PMVMatrix"); + Assert.assertTrue(0 <= mgl_PMVMatrix); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + pmvMatrixUniform = new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf()); + pmvMatrixUniform.setLocation(mgl_PMVMatrix); + gl.glUniform(pmvMatrixUniform); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + // Allocate Vertex Array + int components = 3; + int numElements = 4; + mgl_Vertex = gl.glGetAttribLocation(myShader.getShaderProgram(), "mgl_Vertex"); + Assert.assertTrue(0 <= mgl_Vertex); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + FloatBuffer buffer = Buffers.newDirectFloatBuffer(numElements * components); + GLArrayDataWrapper vertices = GLArrayDataWrapper.createGLSL(gl, "mgl_Vertex", 3, gl.GL_FLOAT, false, 0, buffer, -1, 0); + { + // Fill them up + FloatBuffer verticeb = (FloatBuffer) vertices.getBuffer(); + verticeb.put(-2); + verticeb.put(2); + verticeb.put(0); + verticeb.put(2); + verticeb.put(2); + verticeb.put(0); + verticeb.put(-2); + verticeb.put(-2); + verticeb.put(0); + verticeb.put(2); + verticeb.put(-2); + verticeb.put(0); + } + buffer.flip(); + vertices.setLocation(mgl_Vertex); + gl.glEnableVertexAttribArray(mgl_Vertex); + gl.glVertexAttribPointer(vertices); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + // Allocate Color Array + components = 4; + numElements = 4; + mgl_Color = gl.glGetAttribLocation(myShader.getShaderProgram(), "mgl_Color"); + Assert.assertTrue(0 <= mgl_Color); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + buffer = Buffers.newDirectFloatBuffer(numElements * components); + GLArrayDataWrapper colors = GLArrayDataWrapper.createGLSL(gl, "mgl_Color", 4, gl.GL_FLOAT, false, 0, buffer, -1, 0); + { + // Fill them up + FloatBuffer colorb = (FloatBuffer) colors.getBuffer(); + colorb.put(1); + colorb.put(0); + colorb.put(0); + colorb.put(1); + colorb.put(0); + colorb.put(0); + colorb.put(1); + colorb.put(1); + colorb.put(1); + colorb.put(0); + colorb.put(0); + colorb.put(1); + colorb.put(1); + colorb.put(0); + colorb.put(0); + colorb.put(1); + } + buffer.flip(); + colors.setLocation(mgl_Color); + gl.glEnableVertexAttribArray(mgl_Color); + gl.glVertexAttribPointer(colors); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + // OpenGL Render Settings + gl.glClearColor(0, 0, 0, 1); + gl.glEnable(GL2ES2.GL_DEPTH_TEST); + gl.glUseProgram(0); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + + t0 = System.currentTimeMillis(); + } + + public void reshape(GLAutoDrawable glad, int x, int y, int width, int height) { + GL2ES2 gl = glad.getGL().getGL2ES2(); + gl.glUseProgram(myShader.getShaderProgram()); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + // Set location in front of camera + pmvMatrix.glMatrixMode(PMVMatrix.GL_PROJECTION); + pmvMatrix.glLoadIdentity(); + pmvMatrix.gluPerspective(45.0F, (float) width / (float) height, 1.0F, 100.0F); + //pmvMatrix.glOrthof(-4.0f, 4.0f, -4.0f, 4.0f, 1.0f, 100.0f); + gl.glUniform(pmvMatrixUniform); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + gl.glUseProgram(0); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + } + + public void display(GLAutoDrawable glad) { + long t1 = System.currentTimeMillis(); + + GL2ES2 gl = glad.getGL().getGL2ES2(); + gl.glUseProgram(myShader.getShaderProgram()); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + // One rotation every four seconds + pmvMatrix.glMatrixMode(PMVMatrix.GL_MODELVIEW); + pmvMatrix.glLoadIdentity(); + pmvMatrix.glTranslatef(0, 0, -10); + float ang = ((float) (t1 - t0) * 360.0F) / 4000.0F; + pmvMatrix.glRotatef(ang, 0, 0, 1); + pmvMatrix.glRotatef(ang, 0, 1, 0); + gl.glUniform(pmvMatrixUniform); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + // Draw a square + gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + gl.glUseProgram(0); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + } + + public void dispose(GLAutoDrawable glad) { + GL2ES2 gl = glad.getGL().getGL2ES2(); + gl.glDisableVertexAttribArray(mgl_Vertex); + gl.glDisableVertexAttribArray(mgl_Color); + myShader.release(gl); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + pmvMatrix.destroy(); + pmvMatrix = null; + System.err.println("dispose done"); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/RedSquareShader.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/RedSquareShader.java new file mode 100644 index 000000000..3ef62df31 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/RedSquareShader.java @@ -0,0 +1,68 @@ +/** + * 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.demos.es2.shader; + +public class RedSquareShader { + public static String VERTEX_SHADER_TEXT = + " #ifdef GL_ES\n" + + " #define MEDIUMP mediump\n" + + " #define HIGHP highp\n" + + "#else\n" + + " #define MEDIUMP\n" + + " #define HIGHP\n" + + "#endif\n" + + "\n" + + "uniform MEDIUMP mat4 mgl_PMVMatrix[2];\n" + + "attribute HIGHP vec4 mgl_Vertex;\n" + + "attribute HIGHP vec4 mgl_Color;\n" + + "varying HIGHP vec4 frontColor;\n" + + "\n" + + "void main(void)\n" + + "{\n" + + " frontColor=mgl_Color;\n" + + " gl_Position = mgl_PMVMatrix[0] * mgl_PMVMatrix[1] * mgl_Vertex;\n" + + "}\n" ; + + public static String FRAGMENT_SHADER_TEXT = + "#ifdef GL_ES\n" + + " #define MEDIUMP mediump\n" + + " #define HIGHP highp\n" + + "#else\n" + + " #define MEDIUMP\n" + + " #define HIGHP\n" + + "#endif\n" + + "\n" + + "varying HIGHP vec4 frontColor;\n" + + "\n" + + "void main (void)\n" + + "{\n" + + " gl_FragColor = frontColor;\n" + + "}\n" ; + +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/Gears.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/Gears.java new file mode 100644 index 000000000..dd28b4e40 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/Gears.java @@ -0,0 +1,353 @@ + +package com.jogamp.opengl.test.junit.jogl.demos.gl2.gears; + +import javax.media.opengl.*; + +import com.jogamp.newt.event.*; +import com.jogamp.newt.event.awt.*; +import com.jogamp.newt.Window; + +/** + * Gears.java
+ * author: Brian Paul (converted to Java by Ron Cemer and Sven Gothel)

+ * + * This version is equal to Brian Paul's version 1.2 1999/10/21 + */ + +public class Gears implements GLEventListener { + private float view_rotx = 20.0f, view_roty = 30.0f, view_rotz = 0.0f; + private int gear1=0, gear2=0, gear3=0; + private float angle = 0.0f; + private int swapInterval; + + private boolean mouseRButtonDown = false; + private int prevMouseX, prevMouseY; + + public Gears(int swapInterval) { + this.swapInterval = swapInterval; + } + + public Gears() { + this.swapInterval = 1; + } + + public void setGears(int g1, int g2, int g3) { + gear1 = g1; + gear2 = g2; + gear3 = g3; + } + + /** + * @return display list gear1 + */ + public int getGear1() { return gear1; } + + /** + * @return display list gear2 + */ + public int getGear2() { return gear2; } + + /** + * @return display list gear3 + */ + public int getGear3() { return gear3; } + + public void init(GLAutoDrawable drawable) { + System.err.println("Gears: Init"); + // Use debug pipeline + // drawable.setGL(new DebugGL(drawable.getGL())); + + GL2 gl = drawable.getGL().getGL2(); + + float pos[] = { 5.0f, 5.0f, 10.0f, 0.0f }; + float red[] = { 0.8f, 0.1f, 0.0f, 0.7f }; + float green[] = { 0.0f, 0.8f, 0.2f, 0.7f }; + float blue[] = { 0.2f, 0.2f, 1.0f, 0.7f }; + + gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, pos, 0); + gl.glEnable(GL2.GL_CULL_FACE); + gl.glEnable(GL2.GL_LIGHTING); + gl.glEnable(GL2.GL_LIGHT0); + gl.glEnable(GL2.GL_DEPTH_TEST); + + /* make the gears */ + if(0>=gear1) { + gear1 = gl.glGenLists(1); + gl.glNewList(gear1, GL2.GL_COMPILE); + gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, red, 0); + gear(gl, 1.0f, 4.0f, 1.0f, 20, 0.7f); + gl.glEndList(); + System.err.println("gear1 list created: "+gear1); + } else { + System.err.println("gear1 list reused: "+gear1); + } + + if(0>=gear2) { + gear2 = gl.glGenLists(1); + gl.glNewList(gear2, GL2.GL_COMPILE); + gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, green, 0); + gear(gl, 0.5f, 2.0f, 2.0f, 10, 0.7f); + gl.glEndList(); + System.err.println("gear2 list created: "+gear2); + } else { + System.err.println("gear2 list reused: "+gear2); + } + + if(0>=gear3) { + gear3 = gl.glGenLists(1); + gl.glNewList(gear3, GL2.GL_COMPILE); + gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, blue, 0); + gear(gl, 1.3f, 2.0f, 0.5f, 10, 0.7f); + gl.glEndList(); + System.err.println("gear3 list created: "+gear3); + } else { + System.err.println("gear3 list reused: "+gear3); + } + + gl.glEnable(GL2.GL_NORMALIZE); + + // MouseListener gearsMouse = new TraceMouseAdapter(new GearsMouseAdapter()); + MouseListener gearsMouse = new GearsMouseAdapter(); + + if (drawable instanceof Window) { + Window window = (Window) drawable; + window.addMouseListener(gearsMouse); + } else if (GLProfile.isAWTAvailable() && drawable instanceof java.awt.Component) { + java.awt.Component comp = (java.awt.Component) drawable; + new AWTMouseAdapter(gearsMouse).addTo(comp); + } + } + + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + System.err.println("Gears: Reshape "+x+"/"+y+" "+width+"x"+height); + GL2 gl = drawable.getGL().getGL2(); + + gl.setSwapInterval(swapInterval); + + float h = (float)height / (float)width; + + gl.glMatrixMode(GL2.GL_PROJECTION); + + gl.glLoadIdentity(); + gl.glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f); + gl.glMatrixMode(GL2.GL_MODELVIEW); + gl.glLoadIdentity(); + gl.glTranslatef(0.0f, 0.0f, -40.0f); + } + + public void dispose(GLAutoDrawable drawable) { + System.err.println("Gears: Dispose"); + setGears(0, 0, 0); + } + + public void display(GLAutoDrawable drawable) { + // Turn the gears' teeth + angle += 2.0f; + + // Get the GL corresponding to the drawable we are animating + GL2 gl = drawable.getGL().getGL2(); + + gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + + // Special handling for the case where the GLJPanel is translucent + // and wants to be composited with other Java 2D content + if (GLProfile.isAWTAvailable() && + (drawable instanceof javax.media.opengl.awt.GLJPanel) && + !((javax.media.opengl.awt.GLJPanel) drawable).isOpaque() && + ((javax.media.opengl.awt.GLJPanel) drawable).shouldPreserveColorBufferIfTranslucent()) { + gl.glClear(GL2.GL_DEPTH_BUFFER_BIT); + } else { + gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT); + } + + // Rotate the entire assembly of gears based on how the user + // dragged the mouse around + gl.glPushMatrix(); + gl.glRotatef(view_rotx, 1.0f, 0.0f, 0.0f); + gl.glRotatef(view_roty, 0.0f, 1.0f, 0.0f); + gl.glRotatef(view_rotz, 0.0f, 0.0f, 1.0f); + + // Place the first gear and call its display list + gl.glPushMatrix(); + gl.glTranslatef(-3.0f, -2.0f, 0.0f); + gl.glRotatef(angle, 0.0f, 0.0f, 1.0f); + gl.glCallList(gear1); + gl.glPopMatrix(); + + // Place the second gear and call its display list + gl.glPushMatrix(); + gl.glTranslatef(3.1f, -2.0f, 0.0f); + gl.glRotatef(-2.0f * angle - 9.0f, 0.0f, 0.0f, 1.0f); + gl.glCallList(gear2); + gl.glPopMatrix(); + + // Place the third gear and call its display list + gl.glPushMatrix(); + gl.glTranslatef(-3.1f, 4.2f, 0.0f); + gl.glRotatef(-2.0f * angle - 25.0f, 0.0f, 0.0f, 1.0f); + gl.glCallList(gear3); + gl.glPopMatrix(); + + // Remember that every push needs a pop; this one is paired with + // rotating the entire gear assembly + gl.glPopMatrix(); + } + + public static void gear(GL2 gl, + float inner_radius, + float outer_radius, + float width, + int teeth, + float tooth_depth) + { + int i; + float r0, r1, r2; + float angle, da; + float u, v, len; + + r0 = inner_radius; + r1 = outer_radius - tooth_depth / 2.0f; + r2 = outer_radius + tooth_depth / 2.0f; + + da = 2.0f * (float) Math.PI / teeth / 4.0f; + + gl.glShadeModel(GL2.GL_FLAT); + + gl.glNormal3f(0.0f, 0.0f, 1.0f); + + /* draw front face */ + gl.glBegin(GL2.GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) + { + angle = i * 2.0f * (float) Math.PI / teeth; + gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), width * 0.5f); + gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), width * 0.5f); + if(i < teeth) + { + gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), width * 0.5f); + gl.glVertex3f(r1 * (float)Math.cos(angle + 3.0f * da), r1 * (float)Math.sin(angle + 3.0f * da), width * 0.5f); + } + } + gl.glEnd(); + + /* draw front sides of teeth */ + gl.glBegin(GL2.GL_QUADS); + for (i = 0; i < teeth; i++) + { + angle = i * 2.0f * (float) Math.PI / teeth; + gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), width * 0.5f); + gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), width * 0.5f); + gl.glVertex3f(r2 * (float)Math.cos(angle + 2.0f * da), r2 * (float)Math.sin(angle + 2.0f * da), width * 0.5f); + gl.glVertex3f(r1 * (float)Math.cos(angle + 3.0f * da), r1 * (float)Math.sin(angle + 3.0f * da), width * 0.5f); + } + gl.glEnd(); + + /* draw back face */ + gl.glBegin(GL2.GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) + { + angle = i * 2.0f * (float) Math.PI / teeth; + gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), -width * 0.5f); + gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), -width * 0.5f); + gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), -width * 0.5f); + gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), -width * 0.5f); + } + gl.glEnd(); + + /* draw back sides of teeth */ + gl.glBegin(GL2.GL_QUADS); + for (i = 0; i < teeth; i++) + { + angle = i * 2.0f * (float) Math.PI / teeth; + gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), -width * 0.5f); + gl.glVertex3f(r2 * (float)Math.cos(angle + 2 * da), r2 * (float)Math.sin(angle + 2 * da), -width * 0.5f); + gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), -width * 0.5f); + gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), -width * 0.5f); + } + gl.glEnd(); + + /* draw outward faces of teeth */ + gl.glBegin(GL2.GL_QUAD_STRIP); + for (i = 0; i < teeth; i++) + { + angle = i * 2.0f * (float) Math.PI / teeth; + gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), width * 0.5f); + gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), -width * 0.5f); + u = r2 * (float)Math.cos(angle + da) - r1 * (float)Math.cos(angle); + v = r2 * (float)Math.sin(angle + da) - r1 * (float)Math.sin(angle); + len = (float)Math.sqrt(u * u + v * v); + u /= len; + v /= len; + gl.glNormal3f(v, -u, 0.0f); + gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), width * 0.5f); + gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), -width * 0.5f); + gl.glNormal3f((float)Math.cos(angle), (float)Math.sin(angle), 0.0f); + gl.glVertex3f(r2 * (float)Math.cos(angle + 2 * da), r2 * (float)Math.sin(angle + 2 * da), width * 0.5f); + gl.glVertex3f(r2 * (float)Math.cos(angle + 2 * da), r2 * (float)Math.sin(angle + 2 * da), -width * 0.5f); + u = r1 * (float)Math.cos(angle + 3 * da) - r2 * (float)Math.cos(angle + 2 * da); + v = r1 * (float)Math.sin(angle + 3 * da) - r2 * (float)Math.sin(angle + 2 * da); + gl.glNormal3f(v, -u, 0.0f); + gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), width * 0.5f); + gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), -width * 0.5f); + gl.glNormal3f((float)Math.cos(angle), (float)Math.sin(angle), 0.0f); + } + gl.glVertex3f(r1 * (float)Math.cos(0), r1 * (float)Math.sin(0), width * 0.5f); + gl.glVertex3f(r1 * (float)Math.cos(0), r1 * (float)Math.sin(0), -width * 0.5f); + gl.glEnd(); + + gl.glShadeModel(GL2.GL_SMOOTH); + + /* draw inside radius cylinder */ + gl.glBegin(GL2.GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) + { + angle = i * 2.0f * (float) Math.PI / teeth; + gl.glNormal3f(-(float)Math.cos(angle), -(float)Math.sin(angle), 0.0f); + gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), -width * 0.5f); + gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), width * 0.5f); + } + gl.glEnd(); + } + + class GearsMouseAdapter extends MouseAdapter { + public void mousePressed(MouseEvent e) { + prevMouseX = e.getX(); + prevMouseY = e.getY(); + if ((e.getModifiers() & e.BUTTON3_MASK) != 0) { + mouseRButtonDown = true; + } + } + + public void mouseReleased(MouseEvent e) { + if ((e.getModifiers() & e.BUTTON3_MASK) != 0) { + mouseRButtonDown = false; + } + } + + public void mouseDragged(MouseEvent e) { + int x = e.getX(); + int y = e.getY(); + int width=0, height=0; + Object source = e.getSource(); + if(source instanceof Window) { + Window window = (Window) source; + width=window.getWidth(); + height=window.getHeight(); + } else if (GLProfile.isAWTAvailable() && source instanceof java.awt.Component) { + java.awt.Component comp = (java.awt.Component) source; + width=comp.getWidth(); + height=comp.getHeight(); + } else { + throw new RuntimeException("Event source neither Window nor Component: "+source); + } + float thetaY = 360.0f * ( (float)(x-prevMouseX)/(float)width); + float thetaX = 360.0f * ( (float)(prevMouseY-y)/(float)height); + + prevMouseX = x; + prevMouseY = y; + + view_rotx += thetaX; + view_roty += thetaY; + } + } +} 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 new file mode 100644 index 000000000..d04ce3849 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/TestGearsAWT.java @@ -0,0 +1,122 @@ +/** + * 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.demos.gl2.gears; + +import javax.media.opengl.*; +import com.jogamp.opengl.util.Animator; +import javax.media.opengl.awt.GLCanvas; +import com.jogamp.newt.event.awt.AWTKeyAdapter; +import com.jogamp.newt.event.awt.AWTWindowAdapter; +import com.jogamp.newt.event.TraceKeyAdapter; +import com.jogamp.newt.event.TraceWindowAdapter; + +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.test.junit.util.QuitAdapter; +import java.awt.Frame; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.AfterClass; +import org.junit.Test; + +public class TestGearsAWT extends UITestCase { + static GLProfile glp; + static int width, height; + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + glp = GLProfile.getDefault(); + Assert.assertNotNull(glp); + width = 512; + height = 512; + } + + @AfterClass + public static void releaseClass() { + } + + protected void runTestGL(GLCapabilities caps) throws InterruptedException { + Frame frame = new Frame("Gears AWT Test"); + Assert.assertNotNull(frame); + + GLCanvas glCanvas = new GLCanvas(caps); + Assert.assertNotNull(glCanvas); + frame.add(glCanvas); + frame.setSize(512, 512); + + glCanvas.addGLEventListener(new Gears()); + + Animator animator = new Animator(glCanvas); + QuitAdapter quitAdapter = new QuitAdapter(); + + new AWTKeyAdapter(new TraceKeyAdapter(quitAdapter)).addTo(glCanvas); + new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter)).addTo(frame); + + frame.setVisible(true); + animator.start(); + + while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getDuration()5); + Assert.assertTrue(glCaps.getBlueBits()>5); + Assert.assertTrue(glCaps.getRedBits()>5); + Assert.assertEquals(glCaps.isOnscreen(),onscreen); + Assert.assertTrue(onscreen || !pbuffer || glCaps.isPBuffer()); // pass if onscreen, or !pbuffer req. or have pbuffer + Assert.assertEquals(glCaps.getDoubleBuffered(),onscreen); + Assert.assertTrue(glCaps.getDepthBits()>4); + + drawable = factory.createGLDrawable(window); + Assert.assertNotNull(drawable); + // System.out.println("Pre: "+drawable); + // + drawable.setRealized(true); + // Assert.assertEquals(width,drawable.getWidth()); + // Assert.assertEquals(height,drawable.getHeight()); + // Assert.assertEquals(glCaps,drawable.getChosenGLCapabilities()); + Assert.assertEquals(window,drawable.getNativeSurface()); + // System.out.println("Post: "+drawable); + + context = drawable.createContext(null); + Assert.assertNotNull(context); + // System.out.println(context); + + int res = context.makeCurrent(); + Assert.assertTrue(GLContext.CONTEXT_CURRENT_NEW==res || GLContext.CONTEXT_CURRENT==res); + + // draw something .. + + drawable.swapBuffers(); + context.release(); + + // System.out.println("Final: "+window); + } + + void destroyWindow() { + // GLWindow.dispose(..) sequence + Assert.assertNotNull(context); + context.destroy(); + + Assert.assertNotNull(drawable); + drawable.setRealized(false); + + // GLWindow.destroy(..) sequence cont.. + Assert.assertNotNull(window); + window.invalidate(); + + drawable = null; + context = null; + window = null; + } + + @Test + public void testOnScreenDecorated() throws InterruptedException { + createWindow(true, false, false); + Thread.sleep(1000); // 1000 ms + destroyWindow(); + } + + @Test + public void testOnScreenUndecorated() throws InterruptedException { + createWindow(true, false, true); + Thread.sleep(1000); // 1000 ms + destroyWindow(); + } + + public static void main(String args[]) throws IOException { + String tstname = TestDrawable01NEWT.class.getName(); + org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { + tstname, + "filtertrace=true", + "haltOnError=false", + "haltOnFailure=false", + "showoutput=true", + "outputtoformatters=true", + "logfailedtests=true", + "logtestlistenerevents=true", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLSimple01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLSimple01NEWT.java new file mode 100644 index 000000000..ed2f5d3cb --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLSimple01NEWT.java @@ -0,0 +1,143 @@ +/** + * 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.glsl; + +import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquare0; +import com.jogamp.opengl.test.junit.util.GLSLSimpleProgram; +import com.jogamp.opengl.test.junit.util.UITestCase; + + +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLContext; +import javax.media.opengl.GLProfile; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.util.Animator; +import com.jogamp.opengl.test.junit.jogl.demos.es2.shader.RedSquareShader; +import com.jogamp.opengl.test.junit.util.MiscUtils; + +import java.io.IOException; +import javax.media.opengl.GL2ES2; +import org.junit.AfterClass; + +public class TestGLSLSimple01NEWT extends UITestCase { + static long durationPerTest = 100; // ms + + @BeforeClass + public static void initClass() { + System.err.println("class init"); + GLProfile.initSingleton(true); + } + + @AfterClass + public static void tearDownClass() { + System.err.println("class tear down .."); + GLProfile.shutdown(); + System.err.println("class tear down end"); + } + + @Test(timeout=60000) + public void testGLSLCompilation01() { + GLProfile glp = GLProfile.get(GLProfile.GL2ES2); + Assert.assertNotNull(glp); + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + + GLWindow window = GLWindow.create(caps); + Assert.assertNotNull(window); + window.setSize(800, 600); + window.setVisible(true); + Assert.assertTrue(window.isNativeValid()); + + GLContext context = window.getContext(); + context.setSynchronized(true); + + // trigger native creation of drawable/context + window.display(); + Assert.assertTrue(window.isRealized()); + Assert.assertTrue(window.getContext().isCreated()); + + context.makeCurrent(); + + // given + + GL2ES2 gl = context.getGL().getGL2ES2(); + GLSLSimpleProgram myShader = GLSLSimpleProgram.create(gl, + RedSquareShader.VERTEX_SHADER_TEXT, + RedSquareShader.FRAGMENT_SHADER_TEXT, + true); + + myShader.release(gl); + context.release(); + window.destroy(); + } + + @Test(timeout=60000) + public void testGLSLUse01() throws InterruptedException { + GLProfile glp = GLProfile.get(GLProfile.GL2ES2); + Assert.assertNotNull(glp); + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + + GLWindow window = GLWindow.create(caps); + Assert.assertNotNull(window); + window.setSize(800, 600); + window.setVisible(true); + Assert.assertTrue(window.isNativeValid()); + window.addGLEventListener(new RedSquare0()); + + Animator animator = new Animator(window); + animator.start(); + Assert.assertEquals(true, animator.isAnimating()); + while(animator.isAnimating() && animator.getDuration()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(readTextureData); + } else { + readTexture.updateSubImage(readTextureData, 0, + 0, 0, // src offset + 0, 0, // dst offset + drawable.getWidth(), drawable.getHeight()); + } + readPixelBuffer.rewind(); + } + } + + @SuppressWarnings("deprecation") + public void dispose() { + readTexture.dispose(); + 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 new file mode 100644 index 000000000..6be732a63 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/Surface2File.java @@ -0,0 +1,79 @@ +/** + * 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 javax.media.opengl.*; + +import com.jogamp.opengl.util.texture.TextureIO; + +import java.io.File; +import java.io.IOException; + +import javax.media.nativewindow.*; + +public class Surface2File implements SurfaceUpdatedListener { + + ReadBufferUtil readBufferUtil = new ReadBufferUtil(); + int shotNum = 0; + + public void dispose() { + readBufferUtil.dispose(); + } + + public void surfaceUpdated(Object updater, NativeSurface ns, long when) { + if (updater instanceof GLDrawable) { + GLDrawable drawable = (GLDrawable) updater; + GLContext ctx = GLContext.getCurrent(); + if (null != ctx && ctx.getGLDrawable() == drawable) { + GL gl = ctx.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("shot"); + } catch (IOException ex) { + throw new RuntimeException("can not write survace to file", ex); + } + } + } + } + + public void surface2File(String basename) throws IOException { + if (!readBufferUtil.isValid()) { + return; + } + + File file = File.createTempFile(basename + shotNum + "-", ".ppm"); + TextureIO.write(readBufferUtil.getTextureData(), file); + System.out.println("Wrote: " + file.getAbsolutePath() + ", ..."); + shotNum++; + readBufferUtil.rewindPixelBuffer(); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/TestOffscreen01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/TestOffscreen01NEWT.java new file mode 100644 index 000000000..8851e4f7f --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/TestOffscreen01NEWT.java @@ -0,0 +1,489 @@ +/** + * 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.newt.Display; +import com.jogamp.newt.NewtFactory; +import com.jogamp.newt.Screen; +import com.jogamp.newt.Window; +import com.jogamp.newt.event.MouseListener; +import com.jogamp.newt.event.WindowListener; +import com.jogamp.newt.opengl.GLWindow; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Assume; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import javax.media.opengl.*; +import javax.media.nativewindow.*; + +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.test.junit.jogl.demos.es1.RedSquare; +import java.io.IOException; + +public class TestOffscreen01NEWT extends UITestCase { + static GLProfile glpDefault; + static GLDrawableFactory glDrawableFactory; + static int width, height; + GLCapabilities capsDefault; + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + glpDefault = GLProfile.getDefault(); + Assert.assertNotNull(glpDefault); + glDrawableFactory = GLDrawableFactory.getFactory(glpDefault); + System.out.println("INFO: PBuffer supported: "+ glDrawableFactory.canCreateGLPbuffer(null)); + width = 640; + height = 480; + } + + @AfterClass + public static void releaseClass() { + } + + @Before + public void init() { + capsDefault = new GLCapabilities(glpDefault); + Assert.assertNotNull(capsDefault); + } + + private void do01OffscreenWindowPBuffer(GLCapabilities caps) { + 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); + GLWindow glWindow = GLWindow.create(window); + Assert.assertNotNull(glWindow); + try { + glWindow.setVisible(true); + } catch (Throwable t) { + // stop test and ignore if pixmap cannot be used + t.printStackTrace(); + Assume.assumeNoException(t); + } + GLEventListener demo = new RedSquare(); + WindowUtilNEWT.setDemoFields(demo, window, glWindow, false); + glWindow.addGLEventListener(demo); + + while ( glWindow.getTotalFrames() < 2) { + try { + glWindow.display(); + } catch (Throwable t) { + // stop test and ignore if pbuffer cannot be used + t.printStackTrace(); + Assume.assumeNoException(t); + } + } + + if(null!=glWindow) { + glWindow.destroy(); + } + if(null!=window) { + window.destroy(); + } + if(null!=screen) { + screen.destroy(); + } + if(null!=display) { + display.destroy(); + } + } + + @Test + public void test01aOffscreenWindowPBuffer() { + if(!glDrawableFactory.canCreateGLPbuffer(null)) { + System.out.println("WARNING: PBuffer not supported on this platform - cannot test"); + return; + } + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false); + do01OffscreenWindowPBuffer(caps2); + } + + @Test + public void test01bOffscreenWindowPBufferStencil() { + if(!glDrawableFactory.canCreateGLPbuffer(null)) { + System.out.println("WARNING: PBuffer not supported on this platform - cannot test"); + return; + } + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false); + caps2.setStencilBits(8); + do01OffscreenWindowPBuffer(caps2); + } + + @Test + public void test01cOffscreenWindowPBufferStencilAlpha() { + if(!glDrawableFactory.canCreateGLPbuffer(null)) { + System.out.println("WARNING: PBuffer not supported on this platform - cannot test"); + return; + } + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false); + caps2.setStencilBits(8); + caps2.setAlphaBits(8); + do01OffscreenWindowPBuffer(caps2); + } + + @Test + public void test01cOffscreenWindowPBuffer555() { + if(!glDrawableFactory.canCreateGLPbuffer(null)) { + System.out.println("WARNING: PBuffer not supported on this platform - cannot test"); + return; + } + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false); + caps2.setRedBits(5); + caps2.setGreenBits(5); + caps2.setBlueBits(5); + do01OffscreenWindowPBuffer(caps2); + } + + @Test + public void test02Offscreen3Windows1DisplayPBuffer() { + if(!glDrawableFactory.canCreateGLPbuffer(null)) { + System.out.println("WARNING: PBuffer not supported on this platform - cannot test"); + return; + } + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false); + int winnum = 3, i; + Window windows[] = new Window[winnum]; + GLWindow glWindows[] = new GLWindow[winnum]; + GLEventListener demos[] = new GLEventListener[winnum]; + + Display display = NewtFactory.createDisplay(null); // local display + Assert.assertNotNull(display); + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + Assert.assertNotNull(screen); + + for(i=0; i= GL3 (ATI) + GLProfile glp = GLProfile.get(GLProfile.GL2); + Assert.assertNotNull(glp); + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(caps, false, false, false); + + 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, caps2); + Assert.assertNotNull(window); + window.setSize(width, height); + GLWindow glWindow = GLWindow.create(window); + Assert.assertNotNull(glWindow); + try { + glWindow.setVisible(true); + } catch (Throwable t) { + // stop test and ignore if pixmap cannot be used + t.printStackTrace(); + Assume.assumeNoException(t); + } + GLEventListener demo = new RedSquare(); + WindowUtilNEWT.setDemoFields(demo, window, glWindow, false); + glWindow.addGLEventListener(demo); + + while ( glWindow.getTotalFrames() < 2) { + try { + glWindow.display(); + } catch (Throwable t) { + // stop test and ignore if pixmap cannot be used + t.printStackTrace(); + Assume.assumeNoException(t); + } + } + + if(null!=glWindow) { + glWindow.destroy(); + } + if(null!=window) { + window.destroy(); + } + if(null!=screen) { + screen.destroy(); + } + if(null!=display) { + display.destroy(); + } + } + + @Test + public void test14OffscreenSnapshotWithDemoPixmap() { + // Offscreen doesn't work on >= GL3 (ATI) + GLProfile glp = GLProfile.get(GLProfile.GL2); + Assert.assertNotNull(glp); + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(caps, false, false, false); + + System.out.println("Create Window 1"); + 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, caps2); + Assert.assertNotNull(window); + window.setSize(width, height); + GLWindow glWindow = GLWindow.create(window); + Assert.assertNotNull(glWindow); + try { + glWindow.setVisible(true); + } catch (Throwable t) { + // stop test and ignore if pixmap cannot be used + t.printStackTrace(); + Assume.assumeNoException(t); + } + + GLWindow windowOnScreen = null; + WindowListener wl=null; + MouseListener ml=null; + SurfaceUpdatedListener ul=null; + + GLEventListener demo = new RedSquare(); + Assert.assertNotNull(demo); + + try { + WindowUtilNEWT.run(glWindow, demo, windowOnScreen, wl, ml, ul, 2, true /*snapshot*/, false /*debug*/); + } catch (Throwable t) { + // stop test and ignore if pixmap cannot be used + t.printStackTrace(); + Assume.assumeNoException(t); + } + + if(null!=windowOnScreen) { + windowOnScreen.destroy(); + } + if(null!=glWindow) { + glWindow.destroy(); + } + if(null!=window) { + window.destroy(); + } + if(null!=screen) { + screen.destroy(); + } + if(null!=display) { + display.destroy(); + } + } + public static void main(String args[]) throws IOException { + String tstname = TestOffscreen01NEWT.class.getName(); + org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { + tstname, + "filtertrace=true", + "haltOnError=false", + "haltOnFailure=false", + "showoutput=true", + "outputtoformatters=true", + "logfailedtests=true", + "logtestlistenerevents=true", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/WindowUtilNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/WindowUtilNEWT.java new file mode 100644 index 000000000..ba9896d4b --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/WindowUtilNEWT.java @@ -0,0 +1,110 @@ +/** + * 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.test.junit.util.*; + +import org.junit.Assert; + +import javax.media.opengl.*; +import javax.media.nativewindow.*; +import com.jogamp.newt.*; +import com.jogamp.newt.event.*; +import com.jogamp.newt.opengl.*; + +public class WindowUtilNEWT { + + public static GLCapabilities fixCaps(GLCapabilities caps, boolean onscreen, boolean pbuffer, boolean undecorated) { + GLCapabilities caps2 = (GLCapabilities) caps.cloneMutable(); + caps2.setOnscreen(onscreen); + caps2.setPBuffer(!onscreen && pbuffer); + caps2.setDoubleBuffered(!onscreen); + return caps2; + } + + public static void setDemoFields(GLEventListener demo, Window window, GLWindow glWindow, boolean debug) { + Assert.assertNotNull(demo); + Assert.assertNotNull(window); + if(debug) { + MiscUtils.setFieldIfExists(demo, "glDebug", true); + MiscUtils.setFieldIfExists(demo, "glTrace", true); + } + if(!MiscUtils.setFieldIfExists(demo, "window", window)) { + MiscUtils.setFieldIfExists(demo, "glWindow", glWindow); + } + } + + public static void run(GLWindow windowOffScreen, GLEventListener demo, + GLWindow windowOnScreen, WindowListener wl, MouseListener ml, + SurfaceUpdatedListener ul, int frames, boolean snapshot, boolean debug) { + Assert.assertNotNull(windowOffScreen); + Assert.assertNotNull(demo); + + setDemoFields(demo, windowOffScreen, windowOffScreen, debug); + windowOffScreen.addGLEventListener(demo); + + if ( null != windowOnScreen ) { + if(null!=wl) { + windowOnScreen.addWindowListener(wl); + } + if(null!=ml) { + windowOnScreen.addMouseListener(ml); + } + windowOnScreen.setVisible(true); + } + + GLDrawable readDrawable = windowOffScreen.getContext().getGLDrawable() ; + + if ( null == windowOnScreen ) { + if(snapshot) { + Surface2File s2f = new Surface2File(); + windowOffScreen.addSurfaceUpdatedListener(s2f); + } + } else { + ReadBuffer2Screen readDemo = new ReadBuffer2Screen( readDrawable ) ; + windowOnScreen.addGLEventListener(readDemo); + } + if(null!=ul) { + windowOffScreen.addSurfaceUpdatedListener(ul); + } + + if(debug) { + System.out.println("+++++++++++++++++++++++++++"); + System.out.println(windowOffScreen); + System.out.println("+++++++++++++++++++++++++++"); + } + + while ( windowOffScreen.getTotalFrames() < frames) { + windowOffScreen.display(); + } + windowOffScreen.removeAllSurfaceUpdatedListener(); + + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/texture/TestTexture01AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/texture/TestTexture01AWT.java new file mode 100644 index 000000000..bd83799d4 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/texture/TestTexture01AWT.java @@ -0,0 +1,146 @@ +/** + * 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.texture; + +import com.jogamp.opengl.test.junit.jogl.util.texture.gl2.TextureGL2ListenerDraw1; + +import com.jogamp.opengl.test.junit.util.UITestCase; + +import javax.media.opengl.GLProfile; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.awt.GLCanvas; +import com.jogamp.opengl.util.texture.TextureData; +import com.jogamp.opengl.util.texture.awt.AWTTextureIO; +import com.jogamp.opengl.util.Animator; + +import java.awt.AlphaComposite; +import java.awt.Color; +import java.awt.Frame; +import java.awt.GradientPaint; +import java.awt.Graphics2D; +import java.awt.image.BufferedImage; + +import java.io.IOException; +import org.junit.Assert; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +public class TestTexture01AWT extends UITestCase { + static GLProfile glp; + static GLCapabilities caps; + BufferedImage textureImage; + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + glp = GLProfile.get(GLProfile.GL2GL3); + Assert.assertNotNull(glp); + caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + } + + @Before + public void initTest() { + // create base image + BufferedImage baseImage = new BufferedImage(256, 256, BufferedImage.TYPE_3BYTE_BGR); + Assert.assertNotNull(baseImage); + Graphics2D g = baseImage.createGraphics(); + Assert.assertNotNull(g); + g.setPaint(new GradientPaint(0, 0, Color.CYAN, + baseImage.getWidth(), baseImage.getHeight(), Color.BLUE)); + g.fillRect(0, 0, baseImage.getWidth(), baseImage.getHeight()); + g.dispose(); + + // create texture image + int imageType = BufferedImage.TYPE_3BYTE_BGR; + textureImage = new BufferedImage(baseImage.getWidth(), + baseImage.getHeight(), + imageType); + Assert.assertNotNull(textureImage); + g = textureImage.createGraphics(); + g.setComposite(AlphaComposite.Src); + g.drawImage(baseImage, 0, 0, null); + g.dispose(); + + baseImage.flush(); + baseImage=null; + } + + @After + public void cleanupTest() { + Assert.assertNotNull(textureImage); + textureImage.flush(); + textureImage=null; + } + + @Test + public void test1() throws InterruptedException { + GLCanvas glCanvas = new GLCanvas(caps); + + Frame frame = new Frame("Texture Test"); + Assert.assertNotNull(frame); + frame.add(glCanvas); + frame.setSize(512, 512); + + // create texture + TextureData textureData = AWTTextureIO.newTextureData(caps.getGLProfile(), textureImage, false); + glCanvas.addGLEventListener(new TextureGL2ListenerDraw1(textureData)); + + Animator animator = new Animator(glCanvas); + frame.setVisible(true); + animator.start(); + + Thread.sleep(500); // 500 ms + + animator.stop(); + frame.setVisible(false); + frame.remove(glCanvas); + glCanvas=null; + Assert.assertNotNull(frame); + frame.dispose(); + frame=null; + } + + public static void main(String args[]) throws IOException { + String tstname = TestTexture01AWT.class.getName(); + org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { + tstname, + "filtertrace=true", + "haltOnError=false", + "haltOnFailure=false", + "showoutput=true", + "outputtoformatters=true", + "logfailedtests=true", + "logtestlistenerevents=true", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/gl2/TextureGL2ListenerDraw1.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/gl2/TextureGL2ListenerDraw1.java new file mode 100644 index 000000000..b41dde645 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/gl2/TextureGL2ListenerDraw1.java @@ -0,0 +1,109 @@ +/** + * 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.util.texture.gl2; + +import com.jogamp.opengl.util.texture.Texture; +import com.jogamp.opengl.util.texture.TextureCoords; +import com.jogamp.opengl.util.texture.TextureData; +import com.jogamp.opengl.util.texture.TextureIO; +import javax.media.opengl.GL; +import javax.media.opengl.GL2ES1; +import javax.media.opengl.GL2; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.glu.GLU; + +public class TextureGL2ListenerDraw1 implements GLEventListener { + private GLU glu = new GLU(); + private TextureData textureData; + private Texture texture; + + public TextureGL2ListenerDraw1(TextureData td) { + this.textureData = td; + } + + public void init(GLAutoDrawable drawable) { + if(null!=textureData) { + this.texture = TextureIO.newTexture(textureData); + } + } + + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + GL2 gl = drawable.getGL().getGL2(); + gl.glMatrixMode(GL2ES1.GL_PROJECTION); + gl.glLoadIdentity(); + glu.gluOrtho2D(0, 1, 0, 1); + gl.glMatrixMode(GL2ES1.GL_MODELVIEW); + gl.glLoadIdentity(); + } + + public void dispose(GLAutoDrawable drawable) { + GL2 gl = drawable.getGL().getGL2(); + if(null!=texture) { + texture.disable(); + texture.destroy(gl); + } + if(null!=textureData) { + textureData.destroy(); + } + } + + public void display(GLAutoDrawable drawable) { + GL2 gl = drawable.getGL().getGL2(); + + // need a valid GL context for this .. + + /** OpenGL .. + texture.updateSubImage(textureData, 0, + 20, 20, + 20, 20, + 100, 100); */ + + + // Now draw one quad with the texture + if(null!=texture) { + texture.enable(); + texture.bind(); + gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_REPLACE); + TextureCoords coords = texture.getImageTexCoords(); + gl.glBegin(GL2.GL_QUADS); + gl.glTexCoord2f(coords.left(), coords.bottom()); + gl.glVertex3f(0, 0, 0); + gl.glTexCoord2f(coords.right(), coords.bottom()); + gl.glVertex3f(1, 0, 0); + gl.glTexCoord2f(coords.right(), coords.top()); + gl.glVertex3f(1, 1, 0); + gl.glTexCoord2f(coords.left(), coords.top()); + gl.glVertex3f(0, 1, 0); + gl.glEnd(); + texture.disable(); + } + } +} + diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestCloseNewtAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestCloseNewtAWT.java new file mode 100644 index 000000000..8cad4f0ed --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestCloseNewtAWT.java @@ -0,0 +1,141 @@ +/** + * 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.newt; + +import org.junit.Test; + +import java.lang.reflect.InvocationTargetException; +import java.awt.EventQueue; +import java.awt.Toolkit; +import javax.swing.JFrame; +import javax.swing.SwingUtilities; + +import javax.media.nativewindow.NativeWindow; +import javax.media.nativewindow.util.Point; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; +import com.jogamp.newt.Window; +import com.jogamp.newt.awt.NewtCanvasAWT; +import com.jogamp.newt.event.WindowAdapter; +import com.jogamp.newt.event.WindowEvent; +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.test.junit.util.UITestCase; + +public class TestCloseNewtAWT extends UITestCase { + + GLWindow newtWindow = null; + NewtCanvasAWT newtCanvas = null; + JFrame frame = null; + + class MyCanvas extends NewtCanvasAWT { + public MyCanvas(Window window) { + super(window); + } + + public void addNotify() { + System.err.println("MyCanvas START add: "+Thread.currentThread()+", holds AWTTreeLock: "+Thread.holdsLock(this.getTreeLock())); + super.addNotify(); + System.err.println("MyCanvas END add: "+Thread.currentThread()+", holds AWTTreeLock: "+Thread.holdsLock(this.getTreeLock())); + } + + public void removeNotify() { + System.err.println("MyCanvas START remove: "+Thread.currentThread()+", holds AWTTreeLock: "+Thread.holdsLock(this.getTreeLock())); + + // trigger critical situation around the AWT TreeLock + newtWindow.runOnEDTIfAvail(true, new Runnable() { + public void run() { + // NEWT EDT while AWT is locked + System.err.println("MyCanvas On NEWT-EDT From AWT-EDT: "+Thread.currentThread()+ + ", holds AWTTreeLock: "+Thread.holdsLock(MyCanvas.this.getTreeLock())); + + // Critical: Within NEWT EDT, while AWT is locked + NativeWindow nw = MyCanvas.this.getNativeWindow(); + if(null != nw) { + Point p = nw.getLocationOnScreen(null); + System.err.println("MyCanvas On NEWT-EDT: position: "+p); + } else { + System.err.println("MyCanvas On NEWT-EDT: position n/a, null NativeWindow"); + } + } + }); + System.err.println("MyCanvas passed critical: "+Thread.currentThread()+", holds AWTTreeLock: "+Thread.holdsLock(this.getTreeLock())); + + super.removeNotify(); + + System.err.println("MyCanvas END remove: "+Thread.currentThread()+", holds AWTTreeLock: "+Thread.holdsLock(this.getTreeLock())); + } + } + + class NEWTWindowClosingAdapter extends WindowAdapter { + public void windowDestroyNotify(WindowEvent e) { + System.err.println("Destroy NEWT: windowDestroyNotify "+Thread.currentThread() + ", "+ e); + } + } + + class AWTClosingWindowAdapter extends java.awt.event.WindowAdapter { + public void windowClosing(WindowEvent ev) { + System.err.println("Destroy AWT: windowClosing "+Thread.currentThread() + ", "+ ev); + } + } + + + @Test + public void testCloseNewtAWT() throws InterruptedException, InvocationTargetException { + newtWindow = GLWindow.create(new GLCapabilities(GLProfile.getDefault())); + newtWindow.addWindowListener(new NEWTWindowClosingAdapter()); + newtCanvas = new MyCanvas(newtWindow); + + SwingUtilities.invokeLater(new Runnable() { + public void run() { + frame = new JFrame("NEWT Close Test"); + frame.addWindowListener(new AWTClosingWindowAdapter()); + frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + frame.getContentPane().add(newtCanvas); + frame.pack(); + frame.setSize(800, 600); + frame.setVisible(true); + } + }); + Thread.sleep(1000); + + // programatically issue windowClosing + Toolkit tk = Toolkit.getDefaultToolkit(); + EventQueue evtQ = tk.getSystemEventQueue(); + evtQ.postEvent(new java.awt.event.WindowEvent(frame, java.awt.event.WindowEvent.WINDOW_CLOSING)); + Thread.sleep(200); + + GLProfile.shutdown(); + } + + public static void main(String[] args) { + String tstname = TestCloseNewtAWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle01NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle01NEWT.java new file mode 100644 index 000000000..9343e2dd8 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle01NEWT.java @@ -0,0 +1,264 @@ +/** + * 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.newt; + +import java.lang.reflect.*; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Test; + +import javax.media.nativewindow.*; +import javax.media.opengl.*; + +import com.jogamp.newt.*; +import com.jogamp.newt.event.*; +import com.jogamp.newt.opengl.*; +import java.io.IOException; + +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.test.junit.util.MiscUtils; +import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears; + +public class TestDisplayLifecycle01NEWT extends UITestCase { + static GLProfile glp; + static GLCapabilities caps; + static int width, height; + static long durationPerTest = 100; // ms + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + width = 640; + height = 480; + glp = GLProfile.getDefault(); + caps = new GLCapabilities(glp); + } + + static GLWindow createWindow(Screen screen, GLCapabilities caps, int width, int height) + throws InterruptedException + { + Assert.assertNotNull(caps); + + // + // Create native windowing resources .. X11/Win/OSX + // + GLWindow glWindow; + if(null!=screen) { + Window window = NewtFactory.createWindow(screen, caps); + Assert.assertNotNull(window); + glWindow = GLWindow.create(window); + } else { + glWindow = GLWindow.create(caps); + } + + GLEventListener demo = new Gears(); + setDemoFields(demo, glWindow); + glWindow.addGLEventListener(demo); + glWindow.addWindowListener(new TraceWindowAdapter()); + glWindow.setSize(width, height); + return glWindow; + } + + private void testDisplayCreate01(Display display, Screen screen) throws InterruptedException { + // start-state == end-state + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + Assert.assertEquals(0,display.getReferenceCount()); + Assert.assertEquals(false,display.isNativeValid()); + Assert.assertNotNull(display.getEDTUtil()); + Assert.assertEquals(false,display.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen.getReferenceCount()); + Assert.assertEquals(false,screen.isNativeValid()); + + // Create Window, pending lazy native creation + GLWindow window = createWindow(screen, caps, width, height); + Assert.assertEquals(screen,window.getScreen()); + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + Assert.assertEquals(0,display.getReferenceCount()); + Assert.assertEquals(false,display.isNativeValid()); + Assert.assertEquals(true,display.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen.getReferenceCount()); + Assert.assertEquals(false,screen.isNativeValid()); + + Assert.assertNotNull(window.getScreen()); + Assert.assertEquals(true,window.isValid()); + Assert.assertEquals(false,window.isNativeValid()); + Assert.assertEquals(false,window.isVisible()); + + // lazy native creation sequence: Display, Screen and Window + Assert.assertEquals(0, window.getTotalFrames()); + window.setVisible(true); + + Assert.assertEquals(screen,window.getScreen()); + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + Assert.assertEquals(1,display.getReferenceCount()); + Assert.assertEquals(true,display.isNativeValid()); + Assert.assertEquals(true,display.getEDTUtil().isRunning()); + Assert.assertEquals(1,screen.getReferenceCount()); + Assert.assertEquals(true,screen.isNativeValid()); + Assert.assertEquals(true,window.isNativeValid()); + Assert.assertEquals(true,window.isVisible()); + System.err.println("Frames for setVisible(true) 1: "+window.getTotalFrames()); + Assert.assertTrue(0 < window.getTotalFrames()); + + while(window.getDuration()<1*durationPerTest) { + window.display(); + Thread.sleep(100); + } + System.err.println("duration: "+window.getDuration()); + + // just make the Window invisible + window.setVisible(false); + Assert.assertEquals(true,window.isNativeValid()); + Assert.assertEquals(false,window.isVisible()); + + // just make the Window visible again + window.resetCounter(); + Assert.assertEquals(0, window.getTotalFrames()); + window.setVisible(true); + Assert.assertEquals(true,window.isNativeValid()); + Assert.assertEquals(true,window.isVisible()); + System.err.println("Frames for setVisible(true) 1: "+window.getTotalFrames()); + Assert.assertTrue(0 < window.getTotalFrames()); + + while(window.getDuration()<2*durationPerTest) { + window.display(); + Thread.sleep(100); + } + System.err.println("duration: "+window.getDuration()); + + // destruction .. + window.destroy(); + Assert.assertEquals(screen,window.getScreen()); + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + Assert.assertEquals(0,display.getReferenceCount()); + Assert.assertEquals(false,display.isNativeValid()); + Assert.assertNotNull(display.getEDTUtil()); + Assert.assertEquals(false,display.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen.getReferenceCount()); + Assert.assertEquals(false,screen.isNativeValid()); + Assert.assertEquals(true, window.isValid()); + Assert.assertEquals(false,window.isNativeValid()); + Assert.assertEquals(false,window.isVisible()); + window.resetCounter(); + Assert.assertEquals(0, window.getTotalFrames()); + + // a display call shall not change a thing + window.display(); + Assert.assertEquals(0, window.getTotalFrames()); + Assert.assertEquals(false,window.isNativeValid()); + Assert.assertEquals(false,window.isVisible()); + + // recover Window + window.setVisible(true); + + Assert.assertEquals(screen,window.getScreen()); + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + Assert.assertEquals(1,display.getReferenceCount()); + Assert.assertEquals(true,display.isNativeValid()); + Assert.assertEquals(true,display.getEDTUtil().isRunning()); + Assert.assertEquals(1,screen.getReferenceCount()); + Assert.assertEquals(true,screen.isNativeValid()); + Assert.assertEquals(true,window.isNativeValid()); + Assert.assertEquals(true,window.isVisible()); + System.err.println("Frames for setVisible(true) 2: "+window.getTotalFrames()); + Assert.assertTrue(0 < window.getTotalFrames()); + + while(window.getDuration()<1*durationPerTest) { + window.display(); + Thread.sleep(100); + } + System.err.println("duration: "+window.getDuration()); + + // destruction .. + window.destroy(); + display.dumpDisplayList("Post destroy(true)"); + + // end-state == start-state + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + Assert.assertEquals(0,display.getReferenceCount()); + Assert.assertEquals(false,display.isNativeValid()); + Assert.assertNotNull(display.getEDTUtil()); + Assert.assertEquals(false,display.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen.getReferenceCount()); + Assert.assertEquals(false,screen.isNativeValid()); + + Assert.assertNotNull(window.getScreen()); + Assert.assertEquals(true,window.isValid()); + Assert.assertEquals(false,window.isNativeValid()); + Assert.assertEquals(false,window.isVisible()); + } + + @Test + public void testDisplayCreate01_AutoDestroyLifecycle() throws InterruptedException { + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + + // Create Display/Screen, pending lazy native creation + Display display = NewtFactory.createDisplay(null); + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + testDisplayCreate01(display, screen); + testDisplayCreate01(display, screen); + + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + } + + public static void setDemoFields(GLEventListener demo, GLWindow glWindow) { + Assert.assertNotNull(demo); + Assert.assertNotNull(glWindow); + if(!MiscUtils.setFieldIfExists(demo, "window", glWindow)) { + MiscUtils.setFieldIfExists(demo, "glWindow", glWindow); + } + } + + static int atoi(String a) { + int i=0; + try { + i = Integer.parseInt(a); + } catch (Exception ex) { ex.printStackTrace(); } + return i; + } + + public static void main(String args[]) throws IOException { + for(int i=0; i=5); + Assert.assertTrue(caps2.getBlueBits()>=5); + Assert.assertTrue(caps2.getRedBits()>=5); + Assert.assertEquals(caps2.isOnscreen(),onscreen); + + if(addGLEventListenerAfterVisible) { + glWindow.addGLEventListener(demo); + glWindow.display(); + } + + return glWindow; + } + + static void destroyWindow(GLWindow glWindow) { + if(null!=glWindow) { + glWindow.invalidate(); + Assert.assertEquals(false,glWindow.isNativeValid()); + Assert.assertEquals(false,glWindow.isValid()); + } + } + + @Test + public void testWindowNativeRecreate01aSimple() throws InterruptedException { + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + GLWindow window = createWindow(null, caps, width, height, + true /* onscreen */, false /* undecorated */, + false /*addGLEventListenerAfterVisible*/); + + Assert.assertEquals(true,window.isNativeValid()); + Assert.assertEquals(true,window.isVisible()); + window.destroy(); + Assert.assertEquals(false,window.isNativeValid()); + Assert.assertEquals(false,window.isVisible()); + + window.display(); + Assert.assertEquals(false,window.isNativeValid()); + Assert.assertEquals(false,window.isVisible()); + + window.setVisible(true); + Assert.assertEquals(true,window.isNativeValid()); + Assert.assertEquals(true,window.isVisible()); + + window.setVisible(false); + Assert.assertEquals(true,window.isNativeValid()); + Assert.assertEquals(false,window.isVisible()); + + destroyWindow(window); + } + + @Test + public void testWindowNativeRecreate01bSimple() throws InterruptedException { + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + GLWindow window = createWindow(null, caps, width, height, + true /* onscreen */, false /* undecorated */, + true /*addGLEventListenerAfterVisible*/); + + Assert.assertEquals(true,window.isNativeValid()); + Assert.assertEquals(true,window.isVisible()); + window.destroy(); + Assert.assertEquals(false,window.isNativeValid()); + Assert.assertEquals(false,window.isVisible()); + + window.display(); + Assert.assertEquals(false,window.isNativeValid()); + Assert.assertEquals(false,window.isVisible()); + + window.setVisible(true); + Assert.assertEquals(true,window.isNativeValid()); + Assert.assertEquals(true,window.isVisible()); + + window.setVisible(false); + Assert.assertEquals(true,window.isNativeValid()); + Assert.assertEquals(false,window.isVisible()); + + destroyWindow(window); + } + + @Test + public void testWindowDecor01aSimple() throws InterruptedException { + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + GLWindow window = createWindow(null, caps, width, height, + true /* onscreen */, false /* undecorated */, + false /*addGLEventListenerAfterVisible*/); + System.out.println("Created: "+window); + int state; + for(state=0; state*100 X11 Display). + // In such cases, closing displays shall happen in the same order as + // opening them, otherwise some driver related bug appears. + // You may test this, ie just reverse the destroy order below. + // See also native test: jogl/test/native/displayMultiple02.c + destroyWindow(window1); + destroyWindow(window2); + + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + + Assert.assertEquals(0,display1.getReferenceCount()); + Assert.assertEquals(false,display1.isNativeValid()); + Assert.assertNotNull(display1.getEDTUtil()); + Assert.assertEquals(false,display1.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen1.getReferenceCount()); + Assert.assertEquals(false,screen1.isNativeValid()); + + Assert.assertEquals(0,display2.getReferenceCount()); + Assert.assertEquals(false,display2.isNativeValid()); + Assert.assertNotNull(display2.getEDTUtil()); + Assert.assertEquals(false,display2.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen2.getReferenceCount()); + Assert.assertEquals(false,screen2.isNativeValid()); + } + + public static void setDemoFields(GLEventListener demo, GLWindow glWindow) { + Assert.assertNotNull(demo); + Assert.assertNotNull(glWindow); + if(!MiscUtils.setFieldIfExists(demo, "window", glWindow)) { + MiscUtils.setFieldIfExists(demo, "glWindow", glWindow); + } + } + + static int atoi(String a) { + int i=0; + try { + i = Integer.parseInt(a); + } catch (Exception ex) { ex.printStackTrace(); } + return i; + } + + public static void main(String args[]) throws IOException { + for(int i=0; i=5); + Assert.assertTrue(caps2.getBlueBits()>=5); + Assert.assertTrue(caps2.getRedBits()>=5); + Assert.assertEquals(caps2.isOnscreen(),onscreen); + + return glWindow; + } + + static void destroyWindow(GLWindow glWindow) { + if(null!=glWindow) { + glWindow.destroy(); + } + } + + @Test + public void testWindowDecor01Simple() throws InterruptedException { + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + GLWindow window = createWindow(null, caps, width, height, true /* onscreen */, false /* undecorated */); + Animator animator = new Animator(window); + Assert.assertTrue(animator.start()); + while(animator.isAnimating() && animator.getDuration() AbstractGraphicsDevice -> GLProfile (device) + Display display2 = NewtFactory.createDisplay("charelle:0.0"); // remote display + try { + display2.createNative(); + } catch (NativeWindowException nwe) { + System.err.println(nwe); + Assume.assumeNoException(nwe); + destroyWindow(window1); + return; + } + AbstractGraphicsDevice device2 = display2.getGraphicsDevice(); + GLProfile.initProfiles(device2); // just to make sure + System.err.println(""); + System.err.println("GLProfiles window2: "+device2.getConnection()+": "+GLProfile.glAvailabilityToString(device2)); + + Screen screen2 = NewtFactory.createScreen(display2, 0); // screen 0 + GLWindow window2 = createWindow(screen2, caps); // remote + Assert.assertEquals(true,window2.isNativeValid()); + Assert.assertEquals(true,window2.isVisible()); + + Animator animator2 = new Animator(window2); + animator2.start(); + + for(int state=0; state*1005); + Assert.assertTrue(chosenCapabilities.getBlueBits()>5); + Assert.assertTrue(chosenCapabilities.getRedBits()>5); + Assert.assertEquals(chosenCapabilities.isOnscreen(),onscreen); + + return window; + } + + static void destroyWindow(Display display, Screen screen, Window window) { + if(null!=window) { + window.destroy(); + } + if(null!=screen) { + screen.destroy(); + } + if(null!=display) { + display.destroy(); + } + } + + @Test + public void testRemoteWindow01() throws InterruptedException { + Capabilities caps = new Capabilities(); + Display display1 = NewtFactory.createDisplay(null); // local display + Screen screen1 = NewtFactory.createScreen(display1, 0); // screen 0 + Window window1 = createWindow(screen1, caps, width, height, true /* onscreen */, false /* undecorated */); + window1.setVisible(true); + + Assert.assertEquals(true,window1.isNativeValid()); + Assert.assertEquals(true,window1.isVisible()); + + Display display2 = NewtFactory.createDisplay("charelle:0.0"); // remote display + try { + display2.createNative(); + } catch (NativeWindowException nwe) { + System.err.println(nwe); + Assume.assumeNoException(nwe); + destroyWindow(display1, screen1, window1); + return; + } + Screen screen2 = NewtFactory.createScreen(display2, 0); // screen 0 + Window window2 = createWindow(screen2, caps, width, height, true /* onscreen */, false /* undecorated */); + window2.setVisible(true); + + Assert.assertEquals(true,window2.isNativeValid()); + Assert.assertEquals(true,window2.isVisible()); + + Thread.sleep(500); // 500 ms + + destroyWindow(display1, screen1, window1); + destroyWindow(display2, screen2, window2); + } + + public static void main(String args[]) throws IOException { + String tstname = TestRemoteWindow01NEWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00NEWT.java new file mode 100644 index 000000000..846013b1d --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00NEWT.java @@ -0,0 +1,140 @@ +/** + * 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.newt; + +import java.io.IOException; +import javax.media.nativewindow.NativeWindowFactory; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.jogamp.newt.Display; +import com.jogamp.newt.NewtFactory; +import com.jogamp.newt.Screen; +import com.jogamp.newt.Window; +import com.jogamp.newt.ScreenMode; +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.newt.util.MonitorMode; +import com.jogamp.newt.util.ScreenModeUtil; +import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears; +import com.jogamp.opengl.test.junit.util.UITestCase; +import java.util.Iterator; +import java.util.List; +import javax.media.nativewindow.Capabilities; +import javax.media.nativewindow.util.Dimension; +import javax.media.nativewindow.util.DimensionReadOnly; +import javax.media.nativewindow.util.SurfaceSize; + +public class TestScreenMode00NEWT extends UITestCase { + static int width, height; + + static int waitTimeShort = 4; //1 sec + static int waitTimeLong = 6; //6 sec + + + + @BeforeClass + public static void initClass() { + NativeWindowFactory.initSingleton(true); + width = 640; + height = 480; + } + + @Test + public void testScreenModeInfo00() throws InterruptedException { + DimensionReadOnly res = new Dimension(640, 480); + SurfaceSize surfsz = new SurfaceSize(res, 32); + DimensionReadOnly mm = new Dimension(500, 400); + MonitorMode mon = new MonitorMode(surfsz, mm, 60); + ScreenMode sm_out = new ScreenMode(mon, 90); + System.err.println("00 out: "+sm_out); + + int[] props = ScreenModeUtil.streamOut(sm_out); + ScreenMode sm_in = ScreenModeUtil.streamIn(props, 0); + System.err.println("00 in : "+sm_in); + + Assert.assertEquals(sm_in.getMonitorMode().getSurfaceSize().getResolution(), + sm_out.getMonitorMode().getSurfaceSize().getResolution()); + + Assert.assertEquals(sm_in.getMonitorMode().getSurfaceSize(), + sm_out.getMonitorMode().getSurfaceSize()); + + Assert.assertEquals(sm_in.getMonitorMode().getScreenSizeMM(), + sm_out.getMonitorMode().getScreenSizeMM()); + + Assert.assertEquals(sm_in.getMonitorMode(), sm_out.getMonitorMode()); + + Assert.assertEquals(sm_in, sm_out); + + Assert.assertEquals(sm_out.hashCode(), sm_in.hashCode()); + } + + @Test + public void testScreenModeInfo01() throws InterruptedException { + Capabilities caps = new Capabilities(); + Window window = NewtFactory.createWindow(caps); + window.setSize(width, height); + window.setVisible(true); + + Screen screen = window.getScreen(); + + List screenModes = screen.getScreenModes(); + if(null != screenModes) { + Assert.assertTrue(screenModes.size()>0); + int i=0; + for(Iterator iter=screenModes.iterator(); iter.hasNext(); i++) { + System.err.println(i+": "+iter.next()); + } + ScreenMode sm_o = screen.getOriginalScreenMode(); + Assert.assertNotNull(sm_o); + ScreenMode sm_c = screen.getOriginalScreenMode(); + Assert.assertNotNull(sm_c); + System.err.println("orig: "+sm_o); + System.err.println("curr: "+sm_c); + } else { + // no support .. + System.err.println("Your platform has no ScreenMode change support, sorry"); + } + + window.invalidate(); + + Assert.assertEquals(false,window.isVisible()); + Assert.assertEquals(false,window.isNativeValid()); + Assert.assertEquals(false,screen.isNativeValid()); + Assert.assertEquals(false,screen.getDisplay().isNativeValid()); + } + + public static void main(String args[]) throws IOException { + String tstname = TestScreenMode00NEWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01NEWT.java new file mode 100644 index 000000000..ffff682dc --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01NEWT.java @@ -0,0 +1,284 @@ +/** + * 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.newt; + +import java.io.IOException; +import javax.media.nativewindow.NativeWindowFactory; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; + +import com.jogamp.opengl.util.Animator; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.jogamp.newt.Display; +import com.jogamp.newt.NewtFactory; +import com.jogamp.newt.Screen; +import com.jogamp.newt.Window; +import com.jogamp.newt.ScreenMode; +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.newt.util.ScreenModeUtil; +import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears; +import com.jogamp.opengl.test.junit.util.UITestCase; +import java.util.List; +import javax.media.nativewindow.util.Dimension; + +public class TestScreenMode01NEWT extends UITestCase { + static GLProfile glp; + static int width, height; + + static int waitTimeShort = 1000; // 1 sec + static int waitTimeLong = 5000; // 5 sec + + + + @BeforeClass + public static void initClass() { + NativeWindowFactory.initSingleton(true); + width = 640; + height = 480; + glp = GLProfile.getDefault(); + } + + static GLWindow createWindow(Screen screen, GLCapabilities caps, int width, int height, boolean onscreen, boolean undecorated) { + Assert.assertNotNull(caps); + caps.setOnscreen(onscreen); + + GLWindow window = GLWindow.create(screen, caps); + window.setSize(width, height); + window.addGLEventListener(new Gears()); + Assert.assertNotNull(window); + window.setVisible(true); + return window; + } + + static void destroyWindow(Window window) { + if(null!=window) { + window.destroy(); + } + } + + @Test + public void testFullscreenChange01() throws InterruptedException { + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + Display display = NewtFactory.createDisplay(null); // local display + Assert.assertNotNull(display); + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + Assert.assertNotNull(screen); + + GLWindow window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */); + Animator animator = new Animator(window); + animator.start(); + + window.setFullscreen(true); + Assert.assertEquals(true, window.isFullscreen()); + + Thread.sleep(waitTimeShort); + + window.setFullscreen(false); + Assert.assertEquals(false, window.isFullscreen()); + + Thread.sleep(waitTimeShort); + + animator.stop(); + destroyWindow(window); + } + + @Test + public void testScreenModeChange01() throws InterruptedException { + Thread.sleep(waitTimeShort); + + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + Display display = NewtFactory.createDisplay(null); // local display + Assert.assertNotNull(display); + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + Assert.assertNotNull(screen); + GLWindow window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */); + Assert.assertNotNull(window); + + List screenModes = screen.getScreenModes(); + if(null==screenModes) { + // no support .. + System.err.println("Your platform has no ScreenMode change support, sorry"); + destroyWindow(window); + return; + } + Assert.assertTrue(screenModes.size()>0); + + Animator animator = new Animator(window); + animator.start(); + + ScreenMode smCurrent = screen.getCurrentScreenMode(); + Assert.assertNotNull(smCurrent); + ScreenMode smOrig = screen.getOriginalScreenMode(); + Assert.assertNotNull(smOrig); + Assert.assertEquals(smCurrent, smOrig); + System.err.println("[0] current/orig: "+smCurrent); + + screenModes = ScreenModeUtil.filterByRate(screenModes, smOrig.getMonitorMode().getRefreshRate()); + Assert.assertNotNull(screenModes); + Assert.assertTrue(screenModes.size()>0); + screenModes = ScreenModeUtil.filterByRotation(screenModes, 0); + Assert.assertNotNull(screenModes); + Assert.assertTrue(screenModes.size()>0); + screenModes = ScreenModeUtil.filterByResolution(screenModes, new Dimension(801, 601)); + Assert.assertNotNull(screenModes); + Assert.assertTrue(screenModes.size()>0); + screenModes = ScreenModeUtil.getHighestAvailableBpp(screenModes); + Assert.assertNotNull(screenModes); + Assert.assertTrue(screenModes.size()>0); + + ScreenMode sm = (ScreenMode) screenModes.get(0); + System.err.println("[0] set current: "+sm); + screen.setCurrentScreenMode(sm); + Assert.assertEquals(sm, screen.getCurrentScreenMode()); + Assert.assertNotSame(smOrig, screen.getCurrentScreenMode()); + + Thread.sleep(waitTimeLong); + + // check reset .. + + ScreenMode saveOrigMode = (ScreenMode) smOrig.clone(); + + Assert.assertEquals(true,display.isNativeValid()); + Assert.assertEquals(true,screen.isNativeValid()); + Assert.assertEquals(true,window.isNativeValid()); + Assert.assertEquals(true,window.isVisible()); + + animator.stop(); + destroyWindow(window); + + Assert.assertEquals(false,window.isVisible()); + Assert.assertEquals(false,window.isNativeValid()); + Assert.assertEquals(false,screen.isNativeValid()); + Assert.assertEquals(false,display.isNativeValid()); + + screen.createNative(); // trigger native re-creation + + Assert.assertEquals(true,display.isNativeValid()); + Assert.assertEquals(true,screen.isNativeValid()); + + smCurrent = screen.getCurrentScreenMode(); + System.err.println("[1] current/orig: "+smCurrent); + + Assert.assertNotNull(smCurrent); + Assert.assertEquals(saveOrigMode, smOrig); + + screen.destroy(); + + Assert.assertEquals(false,screen.isNativeValid()); + Assert.assertEquals(false,display.isNativeValid()); + + Thread.sleep(waitTimeShort); + } + + @Test + public void testScreenModeChangeWithFS01Pre() throws InterruptedException { + Thread.sleep(waitTimeShort); + testScreenModeChangeWithFS01Impl(true) ; + Thread.sleep(waitTimeShort); + } + + @Test + public void testScreenModeChangeWithFS01Post() throws InterruptedException { + Thread.sleep(waitTimeShort); + testScreenModeChangeWithFS01Impl(false) ; + Thread.sleep(waitTimeShort); + } + + protected void testScreenModeChangeWithFS01Impl(boolean preFS) throws InterruptedException { + GLCapabilities caps = new GLCapabilities(glp); + Display display = NewtFactory.createDisplay(null); // local display + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + GLWindow window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */); + Animator animator = new Animator(window); + animator.start(); + + ScreenMode smOrig = screen.getOriginalScreenMode(); + List screenModes = screen.getScreenModes(); + if(null==screenModes) { + // no support .. + destroyWindow(window); + return; + } + Assert.assertTrue(screenModes.size()>0); + screenModes = ScreenModeUtil.filterByRate(screenModes, smOrig.getMonitorMode().getRefreshRate()); + screenModes = ScreenModeUtil.filterByRotation(screenModes, 0); + screenModes = ScreenModeUtil.filterByResolution(screenModes, new Dimension(801, 601)); + screenModes = ScreenModeUtil.getHighestAvailableBpp(screenModes); + + ScreenMode screenMode = (ScreenMode) screenModes.get(0); + Assert.assertNotNull(screenMode); + + if(preFS) { + System.err.println("[0] set FS pre 0: "+window.isFullscreen()); + window.setFullscreen(true); + Assert.assertEquals(true, window.isFullscreen()); + System.err.println("[0] set FS pre X: "+window.isFullscreen()); + } + + System.err.println("[0] set current: "+screenMode); + screen.setCurrentScreenMode(screenMode); + + if(!preFS) { + System.err.println("[0] set FS post 0: "+window.isFullscreen()); + window.setFullscreen(true); + Assert.assertEquals(true, window.isFullscreen()); + System.err.println("[0] set FS post X: "+window.isFullscreen()); + } + + Thread.sleep(waitTimeLong); + + // check reset .. + + ScreenMode saveOrigMode = (ScreenMode) smOrig.clone(); + + animator.stop(); + destroyWindow(window); + + screen.createNative(); // trigger native re-creation + + ScreenMode smCurrent = screen.getCurrentScreenMode(); + System.err.println("[1] current/orig: "+smCurrent); + + Assert.assertNotNull(smCurrent); + Assert.assertEquals(saveOrigMode, smOrig); + + screen.destroy(); + } + + public static void main(String args[]) throws IOException { + String tstname = TestScreenMode01NEWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode02NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode02NEWT.java new file mode 100644 index 000000000..2ec0490f0 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode02NEWT.java @@ -0,0 +1,187 @@ +/** + * 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.newt; + +import java.io.IOException; +import javax.media.nativewindow.NativeWindowFactory; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; + +import com.jogamp.opengl.util.Animator; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.jogamp.newt.Display; +import com.jogamp.newt.NewtFactory; +import com.jogamp.newt.Screen; +import com.jogamp.newt.Window; +import com.jogamp.newt.ScreenMode; +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.newt.util.ScreenModeUtil; +import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears; +import com.jogamp.opengl.test.junit.util.UITestCase; +import java.util.List; +import javax.media.nativewindow.util.Dimension; + +public class TestScreenMode02NEWT extends UITestCase { + static GLProfile glp; + static int width, height; + + static int waitTimeShort = 1000; // 1 sec + static int waitTimeLong = 5000; // 5 sec + + @BeforeClass + public static void initClass() { + NativeWindowFactory.initSingleton(true); + width = 640; + height = 480; + glp = GLProfile.getDefault(); + } + + static GLWindow createWindow(Screen screen, GLCapabilities caps, int width, int height, boolean onscreen, boolean undecorated) { + Assert.assertNotNull(caps); + caps.setOnscreen(onscreen); + + GLWindow window = GLWindow.create(screen, caps); + window.setSize(width, height); + window.addGLEventListener(new Gears()); + Assert.assertNotNull(window); + window.setVisible(true); + Assert.assertTrue(window.isVisible()); + return window; + } + + static void destroyWindow(Window window) { + if(null!=window) { + window.destroy(); + } + } + + @Test + public void testScreenRotationChange01() throws InterruptedException { + Thread.sleep(waitTimeShort); + + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + Display display = NewtFactory.createDisplay(null); // local display + Assert.assertNotNull(display); + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + Assert.assertNotNull(screen); + GLWindow window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */); + Assert.assertNotNull(window); + + List screenModes = screen.getScreenModes(); + if(null==screenModes) { + // no support .. + System.err.println("Your platform has no ScreenMode change support, sorry"); + destroyWindow(window); + return; + } + Assert.assertTrue(screenModes.size()>0); + + Animator animator = new Animator(window); + animator.start(); + + ScreenMode smCurrent = screen.getCurrentScreenMode(); + Assert.assertNotNull(smCurrent); + ScreenMode smOrig = screen.getOriginalScreenMode(); + Assert.assertNotNull(smOrig); + Assert.assertEquals(smCurrent, smOrig); + System.err.println("[0] current/orig: "+smCurrent); + + screenModes = ScreenModeUtil.filterByRate(screenModes, smOrig.getMonitorMode().getRefreshRate()); + Assert.assertNotNull(screenModes); + Assert.assertTrue(screenModes.size()>0); + screenModes = ScreenModeUtil.filterByRotation(screenModes, 90); + if(null==screenModes) { + // no rotation support .. + System.err.println("Your platform has no rotation support, sorry"); + destroyWindow(window); + return; + } + Assert.assertTrue(screenModes.size()>0); + screenModes = ScreenModeUtil.filterByResolution(screenModes, new Dimension(801, 601)); + Assert.assertNotNull(screenModes); + Assert.assertTrue(screenModes.size()>0); + screenModes = ScreenModeUtil.getHighestAvailableBpp(screenModes); + Assert.assertNotNull(screenModes); + Assert.assertTrue(screenModes.size()>0); + + ScreenMode sm = (ScreenMode) screenModes.get(0); + System.err.println("[0] set current: "+sm); + screen.setCurrentScreenMode(sm); + Assert.assertEquals(sm, screen.getCurrentScreenMode()); + Assert.assertNotSame(smOrig, screen.getCurrentScreenMode()); + + Thread.sleep(waitTimeLong); + + // check reset .. + + ScreenMode saveOrigMode = (ScreenMode) smOrig.clone(); + + Assert.assertEquals(true,display.isNativeValid()); + Assert.assertEquals(true,screen.isNativeValid()); + Assert.assertEquals(true,window.isNativeValid()); + Assert.assertEquals(true,window.isVisible()); + + animator.stop(); + destroyWindow(window); + + Assert.assertEquals(false,window.isVisible()); + Assert.assertEquals(false,window.isNativeValid()); + Assert.assertEquals(false,screen.isNativeValid()); + Assert.assertEquals(false,display.isNativeValid()); + + screen.createNative(); // trigger native re-creation + + Assert.assertEquals(true,display.isNativeValid()); + Assert.assertEquals(true,screen.isNativeValid()); + + smCurrent = screen.getCurrentScreenMode(); + System.err.println("[1] current/orig: "+smCurrent); + + Assert.assertNotNull(smCurrent); + Assert.assertEquals(saveOrigMode, smOrig); + + screen.destroy(); + + Assert.assertEquals(false,screen.isNativeValid()); + Assert.assertEquals(false,display.isNativeValid()); + + Thread.sleep(waitTimeShort); + } + + public static void main(String args[]) throws IOException { + String tstname = TestScreenMode02NEWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestWindows01NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestWindows01NEWT.java new file mode 100644 index 000000000..5ac6041ac --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestWindows01NEWT.java @@ -0,0 +1,179 @@ +/** + * 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.newt; + +import java.lang.reflect.*; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Test; + +import javax.media.nativewindow.*; + +import com.jogamp.newt.*; +import java.io.IOException; + +import com.jogamp.opengl.test.junit.util.UITestCase; + +public class TestWindows01NEWT extends UITestCase { + static int width, height; + + @BeforeClass + public static void initClass() { + NativeWindowFactory.initSingleton(true); + width = 640; + height = 480; + } + + static Window createWindow(Screen screen, Capabilities caps, int width, int height, boolean onscreen, boolean undecorated) { + Assert.assertNotNull(caps); + caps.setOnscreen(onscreen); + // System.out.println("Requested: "+caps); + + // + // Create native windowing resources .. X11/Win/OSX + // + Window window = NewtFactory.createWindow(screen, caps); + Assert.assertNotNull(window); + window.setUndecorated(onscreen && undecorated); + window.setSize(width, height); + Assert.assertEquals(false,window.isNativeValid()); + Assert.assertEquals(false,window.isVisible()); + window.setVisible(true); + Assert.assertEquals(true,window.isVisible()); + Assert.assertEquals(true,window.isNativeValid()); + // Assert.assertEquals(width,window.getWidth()); + // Assert.assertEquals(height,window.getHeight()); + // System.out.println("Created: "+window); + + // + // Create native OpenGL resources .. XGL/WGL/CGL .. + // equivalent to GLAutoDrawable methods: setVisible(true) + // + CapabilitiesImmutable chosenCapabilities = window.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities(); + Assert.assertNotNull(chosenCapabilities); + Assert.assertTrue(chosenCapabilities.getGreenBits()>5); + Assert.assertTrue(chosenCapabilities.getBlueBits()>5); + Assert.assertTrue(chosenCapabilities.getRedBits()>5); + Assert.assertEquals(chosenCapabilities.isOnscreen(),onscreen); + + return window; + } + + static void destroyWindow(Display display, Screen screen, Window window) { + if(null!=window) { + window.destroy(); + } + if(null!=screen) { + screen.destroy(); + } + if(null!=display) { + display.destroy(); + } + } + + @Test + public void testWindowNativeRecreate01Simple() throws InterruptedException { + Capabilities caps = new Capabilities(); + Assert.assertNotNull(caps); + Display display = NewtFactory.createDisplay(null); // local display + Assert.assertNotNull(display); + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + Assert.assertNotNull(screen); + + Window window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */); + window.destroy(); + Assert.assertEquals(false,window.isNativeValid()); + Assert.assertEquals(false,window.isVisible()); + + window.setVisible(true); + Assert.assertEquals(true,window.isNativeValid()); + Assert.assertEquals(true,window.isVisible()); + + Thread.sleep(100); // 100 ms + destroyWindow(display, screen, window); + } + + @Test + public void testWindowDecor01Simple() throws InterruptedException { + Capabilities caps = new Capabilities(); + Assert.assertNotNull(caps); + Display display = NewtFactory.createDisplay(null); // local display + Assert.assertNotNull(display); + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + Assert.assertNotNull(screen); + + Window window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */); + Thread.sleep(100); // 100 ms + destroyWindow(display, screen, window); + } + + @Test + public void testWindowDecor02DestroyWinTwiceA() throws InterruptedException { + Capabilities caps = new Capabilities(); + Assert.assertNotNull(caps); + Display display = NewtFactory.createDisplay(null); // local display + Assert.assertNotNull(display); + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + Assert.assertNotNull(screen); + + Window window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */); + Thread.sleep(100); // 100 ms + destroyWindow(null, null, window); + destroyWindow(display, screen, window); + } + + @Test + public void testWindowDecor03TwoWin() throws InterruptedException { + Capabilities caps = new Capabilities(); + Assert.assertNotNull(caps); + Display display = NewtFactory.createDisplay(null); // local display + Assert.assertNotNull(display); + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + Assert.assertNotNull(screen); + + Window window1 = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */); + Window window2 = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */); + Thread.sleep(100); // 100 ms + destroyWindow(null, null, window2); + destroyWindow(display, screen, window1); + } + + public static void main(String args[]) throws IOException { + String tstname = TestWindows01NEWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/WindowEventCom1.java b/src/test/com/jogamp/opengl/test/junit/newt/WindowEventCom1.java new file mode 100644 index 000000000..609d443aa --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/WindowEventCom1.java @@ -0,0 +1,42 @@ +/** + * 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.newt; + +import com.jogamp.newt.event.*; + +class WindowEventCom1 extends WindowAdapter { + + public void windowResized(WindowEvent e) { + e.setAttachment(new String("WindowEventCom1.windowResized: "+e)); + } + public void windowMoved(WindowEvent e) { + e.setAttachment(new String("WindowEventCom1.windowMoved: "+e)); + } +} + diff --git a/src/test/com/jogamp/opengl/test/junit/newt/WindowEventCom2.java b/src/test/com/jogamp/opengl/test/junit/newt/WindowEventCom2.java new file mode 100644 index 000000000..d15a3ccd8 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/WindowEventCom2.java @@ -0,0 +1,48 @@ +/** + * 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.newt; + +import com.jogamp.newt.event.*; + +class WindowEventCom2 extends WindowAdapter { + + public void windowResized(WindowEvent e) { + String str = (String) e.getAttachment(); + if(null==str) { + e.setAttachment(new String("WindowEventCom2.windowResized: "+e)); + } + } + public void windowMoved(WindowEvent e) { + String str = (String) e.getAttachment(); + if(null==str) { + e.setAttachment(new String("WindowEventCom2.windowMoved: "+e)); + } + } +} + diff --git a/src/test/com/jogamp/opengl/test/junit/newt/WindowEventCom3.java b/src/test/com/jogamp/opengl/test/junit/newt/WindowEventCom3.java new file mode 100644 index 000000000..87e5eccbb --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/WindowEventCom3.java @@ -0,0 +1,44 @@ +/** + * 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.newt; + +import com.jogamp.newt.event.*; + +class WindowEventCom3 extends WindowAdapter { + + public void windowResized(WindowEvent e) { + String str = (String) e.getAttachment(); + System.out.println("WindowEventCom3.windowResized: "+str); + } + public void windowMoved(WindowEvent e) { + String str = (String) e.getAttachment(); + System.out.println("WindowEventCom3.windowMoved: "+str); + } +} + diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/GLRunnableDummy.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/GLRunnableDummy.java new file mode 100644 index 000000000..d518616b1 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/GLRunnableDummy.java @@ -0,0 +1,57 @@ +/** + * 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.newt.parenting; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.AfterClass; +import org.junit.Test; + +import javax.media.opengl.*; + +public class GLRunnableDummy implements GLRunnable { + float r=0.0f; + float g=0.0f; + float b=0.0f; + float d=0.001f; + + public void run(GLAutoDrawable drawable) { + GL2ES1 gl = drawable.getGL().getGL2ES1(); + gl.glClearColor(r, g, b, 1f); + r+=d; + if(r>1f) { + r=1f; + d*=-1f; + } else if(r<0f) { + r=0f; + d*=-1f; + } + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/KeyAction.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/KeyAction.java new file mode 100644 index 000000000..3313ec65c --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/KeyAction.java @@ -0,0 +1,45 @@ +/** + * 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.newt.parenting; + +import com.jogamp.newt.event.*; + +class KeyAction extends KeyAdapter { + NEWTEventFiFo eventFifo; + + public KeyAction(NEWTEventFiFo eventFifo) { + this.eventFifo = eventFifo; + } + + public void keyTyped(KeyEvent e) { + eventFifo.put(e); + } +} + diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01NEWT.java new file mode 100644 index 000000000..5173d0f22 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01NEWT.java @@ -0,0 +1,716 @@ +/** + * 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.newt.parenting; + + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import javax.media.opengl.*; + +import com.jogamp.opengl.util.Animator; +import com.jogamp.newt.*; +import com.jogamp.newt.event.*; +import com.jogamp.newt.opengl.*; + +import java.io.IOException; + +import com.jogamp.opengl.test.junit.util.*; +import com.jogamp.opengl.test.junit.jogl.demos.es1.RedSquare; +import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears; + +public class TestParenting01NEWT extends UITestCase { + static int width, height; + static long durationPerTest = 500; + static long waitAbout10FramesAt30fps = 10*34; // 10 frames @ 30fps + static GLCapabilities glCaps; + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + width = 640; + height = 480; + glCaps = new GLCapabilities(null); + } + + @Test + public void testWindowParenting01CreateVisibleDestroy() throws InterruptedException { + int x = 0; + int y = 0; + + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + Display display = null; + Screen screen = null; + + NEWTEventFiFo eventFifo = new NEWTEventFiFo(); + + GLWindow glWindow1 = GLWindow.create(glCaps); + Assert.assertNotNull(glWindow1); + Assert.assertEquals(false, glWindow1.isVisible()); + Assert.assertEquals(false, glWindow1.isNativeValid()); + Assert.assertNull(glWindow1.getParent()); + screen = glWindow1.getScreen(); + display = screen.getDisplay(); + Assert.assertEquals(0,display.getReferenceCount()); + Assert.assertEquals(false,display.isNativeValid()); + Assert.assertNotNull(display.getEDTUtil()); + Assert.assertEquals(true,display.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen.getReferenceCount()); + Assert.assertEquals(false,screen.isNativeValid()); + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + + glWindow1.setTitle("testWindowParenting01CreateVisibleDestroy"); + glWindow1.setSize(640, 480); + GLEventListener demo1 = new RedSquare(); + setDemoFields(demo1, glWindow1, false); + glWindow1.addGLEventListener(demo1); + + GLWindow glWindow2 = GLWindow.create(glWindow1, glCaps); + Assert.assertNotNull(glWindow2); + Assert.assertEquals(false, glWindow2.isVisible()); + Assert.assertEquals(false, glWindow2.isNativeValid()); + Assert.assertSame(glWindow1,glWindow2.getParent()); + Assert.assertSame(screen,glWindow2.getScreen()); + Assert.assertSame(display,glWindow2.getScreen().getDisplay()); + glWindow2.setSize(320, 240); + GLEventListener demo2 = new Gears(); + setDemoFields(demo2, glWindow2, false); + glWindow2.addGLEventListener(demo2); + + Assert.assertEquals(0,display.getReferenceCount()); + Assert.assertEquals(false,display.isNativeValid()); + Assert.assertNotNull(display.getEDTUtil()); + Assert.assertEquals(true,display.getEDTUtil().isRunning()); // GLWindow -> invoke .. + Assert.assertEquals(0,screen.getReferenceCount()); + Assert.assertEquals(false,screen.isNativeValid()); + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + + // visible test + Assert.assertEquals(0, glWindow1.getTotalFrames()); + Assert.assertEquals(0, glWindow2.getTotalFrames()); + glWindow1.setVisible(true); + System.err.println("Frames for setVisible(true): A1: "+glWindow1.getTotalFrames()+", B1: "+glWindow2.getTotalFrames()); + Assert.assertTrue(0 < glWindow1.getTotalFrames()); + Assert.assertTrue(0 < glWindow2.getTotalFrames()); + + Assert.assertEquals(true, glWindow1.isVisible()); + Assert.assertEquals(true, glWindow1.isNativeValid()); + Assert.assertEquals(true, glWindow2.isVisible()); + Assert.assertEquals(true, glWindow2.isNativeValid()); + Assert.assertEquals(1,display.getReferenceCount()); + Assert.assertEquals(true,display.isNativeValid()); + Assert.assertNotNull(display.getEDTUtil()); + Assert.assertEquals(true,display.getEDTUtil().isRunning()); + Assert.assertEquals(2,screen.getReferenceCount()); + Assert.assertEquals(true,screen.isNativeValid()); + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + + glWindow1.setVisible(false); + Assert.assertEquals(false, glWindow1.isVisible()); + Assert.assertEquals(true, glWindow1.isNativeValid()); + Assert.assertEquals(false, glWindow2.isVisible()); + Assert.assertEquals(true, glWindow2.isNativeValid()); + + glWindow1.resetCounter(); + glWindow2.resetCounter(); + Assert.assertEquals(0, glWindow1.getTotalFrames()); + Assert.assertEquals(0, glWindow2.getTotalFrames()); + glWindow1.setVisible(true); + System.err.println("Frames for setVisible(true): A2: "+glWindow1.getTotalFrames()+", B2: "+glWindow2.getTotalFrames()); + Assert.assertTrue(0 < glWindow1.getTotalFrames()); + Assert.assertTrue(0 < glWindow2.getTotalFrames()); + + Assert.assertEquals(true, glWindow1.isVisible()); + Assert.assertEquals(true, glWindow1.isNativeValid()); + Assert.assertEquals(true, glWindow2.isVisible()); + Assert.assertEquals(true, glWindow2.isNativeValid()); + + glWindow1.resetCounter(); + glWindow2.resetCounter(); + Animator animator1 = new Animator(glWindow1); + animator1.start(); + Assert.assertEquals(true, animator1.isAnimating()); + Assert.assertEquals(false, animator1.isPaused()); + Assert.assertNotNull(animator1.getThread()); + Animator animator2 = new Animator(glWindow2); + animator2.start(); + Assert.assertEquals(true, animator2.isAnimating()); + Assert.assertEquals(false, animator2.isPaused()); + Assert.assertNotNull(animator2.getThread()); + while(animator1.isAnimating() && animator1.getDuration() glwindow2 ; can be recreated .. + glWindow1.destroy(); + Assert.assertEquals(true, glWindow1.isValid()); + Assert.assertEquals(false, glWindow1.isNativeValid()); + Assert.assertEquals(true, glWindow2.isValid()); + Assert.assertEquals(false, glWindow2.isNativeValid()); + Assert.assertEquals(0,display.getReferenceCount()); + Assert.assertEquals(false,display.isNativeValid()); + Assert.assertNotNull(display.getEDTUtil()); + Assert.assertEquals(false,display.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen.getReferenceCount()); + Assert.assertEquals(false,screen.isNativeValid()); + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + + glWindow1.invalidate(); + Assert.assertEquals(false, glWindow1.isValid()); + Assert.assertEquals(false, glWindow2.isValid()); + + // test double destroy/invalidate .. + glWindow2.invalidate(); + Assert.assertEquals(false, glWindow2.isValid()); + + Assert.assertEquals(0,display.getReferenceCount()); + Assert.assertEquals(false,display.isNativeValid()); + Assert.assertNotNull(display.getEDTUtil()); + Assert.assertEquals(false,display.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen.getReferenceCount()); + Assert.assertEquals(false,screen.isNativeValid()); + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + } + + @Test + public void testWindowParenting02ReparentTop2WinReparentRecreate() throws InterruptedException { + testWindowParenting02ReparentTop2WinImpl(true); + } + + @Test + public void testWindowParenting02ReparentTop2WinReparentNative() throws InterruptedException { + testWindowParenting02ReparentTop2WinImpl(false); + } + + /** + * @param reparentRecreate true, if the followup reparent should utilize destroy/create, instead of native reparenting + */ + protected void testWindowParenting02ReparentTop2WinImpl(boolean reparentRecreate) throws InterruptedException { + int x = 0; + int y = 0; + + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + Display display1 = null; + Screen screen1 = null; + + NEWTEventFiFo eventFifo = new NEWTEventFiFo(); + + GLWindow glWindow1 = GLWindow.create(glCaps); + glWindow1.setTitle("testWindowParenting02ReparentTop2Win"); + glWindow1.setSize(640, 480); + GLEventListener demo1 = new RedSquare(); + setDemoFields(demo1, glWindow1, false); + glWindow1.addGLEventListener(demo1); + screen1 = glWindow1.getScreen(); + display1 = screen1.getDisplay(); + + Assert.assertEquals(0,display1.getReferenceCount()); + Assert.assertEquals(false,display1.isNativeValid()); + Assert.assertNotNull(display1.getEDTUtil()); + Assert.assertEquals(true,display1.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen1.getReferenceCount()); + Assert.assertEquals(false,screen1.isNativeValid()); + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + + GLWindow glWindow2 = GLWindow.create(glCaps); + glWindow2.setSize(320, 240); + GLEventListener demo2 = new Gears(); + setDemoFields(demo2, glWindow2, false); + glWindow2.addGLEventListener(demo2); + Assert.assertSame(screen1, glWindow2.getScreen()); + Assert.assertSame(display1, glWindow2.getScreen().getDisplay()); + + Assert.assertEquals(0,display1.getReferenceCount()); + Assert.assertEquals(false,display1.isNativeValid()); + Assert.assertNotNull(display1.getEDTUtil()); + Assert.assertEquals(true,display1.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen1.getReferenceCount()); + Assert.assertEquals(false,screen1.isNativeValid()); + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + + Assert.assertEquals(0, glWindow1.getTotalFrames()); + glWindow1.setVisible(true); + Assert.assertEquals(1,display1.getReferenceCount()); + Assert.assertEquals(true,display1.isNativeValid()); + Assert.assertNotNull(display1.getEDTUtil()); + Assert.assertEquals(true,display1.getEDTUtil().isRunning()); + Assert.assertEquals(1,screen1.getReferenceCount()); + Assert.assertEquals(true,screen1.isNativeValid()); + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + Assert.assertEquals(true, glWindow1.isVisible()); + System.err.println("Frames for setVisible(true) A1: "+glWindow1.getTotalFrames()); + Assert.assertTrue(0 < glWindow1.getTotalFrames()); + + Assert.assertEquals(0, glWindow2.getTotalFrames()); + glWindow2.setVisible(true); + + Assert.assertEquals(1,display1.getReferenceCount()); + Assert.assertEquals(true,display1.isNativeValid()); + Assert.assertNotNull(display1.getEDTUtil()); + Assert.assertEquals(true,display1.getEDTUtil().isRunning()); + Assert.assertEquals(2,screen1.getReferenceCount()); + Assert.assertEquals(true,screen1.isNativeValid()); + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + Assert.assertEquals(true, glWindow2.isVisible()); + System.err.println("Frames for setVisible(true) B1: "+glWindow2.getTotalFrames()); + Assert.assertTrue(0 < glWindow1.getTotalFrames()); + + Animator animator1 = new Animator(glWindow1); + animator1.start(); + Animator animator2 = new Animator(glWindow2); + animator2.start(); + + int state = 0; + int reparentAction; + while(animator1.isAnimating() && animator1.getDuration()<3*durationPerTest) { + Thread.sleep(durationPerTest); + switch(state) { + case 0: + // glWindow2 -- child --> glWindow1: compatible + Assert.assertEquals(true, glWindow2.isVisible()); + System.err.println("Frames(1) "+glWindow2.getTotalFrames()); + reparentAction = glWindow2.reparentWindow(glWindow1, reparentRecreate); + System.err.println("Frames(2) "+glWindow2.getTotalFrames()); + Assert.assertTrue(Window.ReparentAction.ACTION_INVALID < reparentAction); + Assert.assertEquals(true, glWindow2.isVisible()); + Assert.assertEquals(true, glWindow2.isNativeValid()); + Assert.assertSame(glWindow1,glWindow2.getParent()); + System.err.println("Frames for reparentWindow(parent, "+reparentRecreate+"): "+reparentAction+", B2: "+glWindow2.getTotalFrames()); + Assert.assertTrue(0 < glWindow2.getTotalFrames()); + + Assert.assertEquals(1,display1.getReferenceCount()); + Assert.assertEquals(true,display1.isNativeValid()); + Assert.assertNotNull(display1.getEDTUtil()); + Assert.assertEquals(true,display1.getEDTUtil().isRunning()); + Assert.assertEquals(true,screen1.isNativeValid()); + Assert.assertSame(screen1,glWindow2.getScreen()); + Assert.assertSame(display1,glWindow2.getScreen().getDisplay()); + Assert.assertEquals(2,screen1.getReferenceCount()); + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + + break; + + case 1: + // glWindow2 --> top + Assert.assertEquals(true, glWindow2.isVisible()); + + reparentAction = glWindow2.reparentWindow(null, reparentRecreate); + Assert.assertTrue(Window.ReparentAction.ACTION_INVALID < reparentAction); + Assert.assertEquals(true, glWindow2.isVisible()); + Assert.assertEquals(true, glWindow2.isNativeValid()); + Assert.assertNull(glWindow2.getParent()); + System.err.println("Frames for reparentWindow(parent, "+reparentRecreate+"): "+reparentAction+", B3: "+glWindow2.getTotalFrames()); + Assert.assertTrue(0 < glWindow2.getTotalFrames()); + + Assert.assertEquals(1,display1.getReferenceCount()); + Assert.assertEquals(true,display1.isNativeValid()); + Assert.assertNotNull(display1.getEDTUtil()); + Assert.assertEquals(true,display1.getEDTUtil().isRunning()); + Assert.assertEquals(true,screen1.isNativeValid()); + Assert.assertSame(screen1,glWindow2.getScreen()); + Assert.assertSame(display1,glWindow2.getScreen().getDisplay()); + Assert.assertEquals(2,screen1.getReferenceCount()); + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + + break; + } + state++; + } + // + // both windows are now top level + // + + animator1.stop(); + Assert.assertEquals(false, animator1.isAnimating()); + Assert.assertEquals(false, animator1.isPaused()); + Assert.assertEquals(null, animator1.getThread()); + animator2.stop(); + Assert.assertEquals(false, animator2.isAnimating()); + Assert.assertEquals(false, animator2.isPaused()); + Assert.assertEquals(null, animator2.getThread()); + + // pre-destroy check (both valid and running) + Assert.assertEquals(1,display1.getReferenceCount()); + Assert.assertEquals(true,display1.isNativeValid()); + Assert.assertNotNull(display1.getEDTUtil()); + Assert.assertEquals(true,display1.getEDTUtil().isRunning()); + Assert.assertEquals(2,screen1.getReferenceCount()); + Assert.assertEquals(true,screen1.isNativeValid()); + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + + // destroy glWindow2 + glWindow2.destroy(); + Assert.assertEquals(true, glWindow1.isValid()); + Assert.assertEquals(true, glWindow1.isNativeValid()); + Assert.assertEquals(true, glWindow1.isVisible()); + Assert.assertEquals(true, glWindow2.isValid()); + Assert.assertEquals(false, glWindow2.isNativeValid()); + Assert.assertEquals(false, glWindow2.isVisible()); + + Assert.assertEquals(1,display1.getReferenceCount()); + Assert.assertEquals(true,display1.isNativeValid()); + Assert.assertNotNull(display1.getEDTUtil()); + Assert.assertEquals(true,display1.getEDTUtil().isRunning()); + Assert.assertEquals(1,screen1.getReferenceCount()); + Assert.assertEquals(true,screen1.isNativeValid()); + + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + + // destroy glWindow1 + glWindow1.destroy(); + Assert.assertEquals(true, glWindow1.isValid()); + Assert.assertEquals(false, glWindow1.isNativeValid()); + Assert.assertEquals(false, glWindow1.isVisible()); + Assert.assertEquals(true, glWindow2.isValid()); + Assert.assertEquals(false, glWindow2.isNativeValid()); + Assert.assertEquals(false, glWindow2.isVisible()); + + Assert.assertEquals(0,display1.getReferenceCount()); + Assert.assertEquals(false,display1.isNativeValid()); + Assert.assertNotNull(display1.getEDTUtil()); + Assert.assertEquals(false,display1.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen1.getReferenceCount()); + Assert.assertEquals(false,screen1.isNativeValid()); + + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + + glWindow1.invalidate(); + Assert.assertEquals(false, glWindow1.isValid()); + Assert.assertEquals(true, glWindow2.isValid()); + + glWindow2.invalidate(); + Assert.assertEquals(false, glWindow2.isValid()); + } + + @Test + public void testWindowParenting03ReparentWin2TopReparentRecreate() throws InterruptedException { + testWindowParenting03ReparentWin2TopImpl(true); + } + + @Test + public void testWindowParenting03ReparentWin2TopReparentNative() throws InterruptedException { + testWindowParenting03ReparentWin2TopImpl(false); + } + + protected void testWindowParenting03ReparentWin2TopImpl(boolean reparentRecreate) throws InterruptedException { + int x = 0; + int y = 0; + + NEWTEventFiFo eventFifo = new NEWTEventFiFo(); + + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + Display display1 = null; + Screen screen1 = null; + Display display2 = null; + Screen screen2 = null; + + GLWindow glWindow1 = GLWindow.create(glCaps); + screen1 = glWindow1.getScreen(); + display1 = screen1.getDisplay(); + glWindow1.setTitle("testWindowParenting03ReparentWin2Top"); + glWindow1.setSize(640, 480); + GLEventListener demo1 = new RedSquare(); + setDemoFields(demo1, glWindow1, false); + glWindow1.addGLEventListener(demo1); + + Assert.assertEquals(0,display1.getReferenceCount()); + Assert.assertEquals(false,display1.isNativeValid()); + Assert.assertNotNull(display1.getEDTUtil()); + Assert.assertEquals(true,display1.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen1.getReferenceCount()); + Assert.assertEquals(false,screen1.isNativeValid()); + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + + GLWindow glWindow2 = GLWindow.create(glWindow1, glCaps); + screen2 = glWindow2.getScreen(); + display2 = screen2.getDisplay(); + glWindow2.setSize(320, 240); + GLEventListener demo2 = new Gears(); + setDemoFields(demo2, glWindow2, false); + glWindow2.addGLEventListener(demo2); + + Assert.assertEquals(0,display2.getReferenceCount()); + Assert.assertEquals(false,display2.isNativeValid()); + Assert.assertNotNull(display2.getEDTUtil()); + Assert.assertEquals(true,display2.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen2.getReferenceCount()); + Assert.assertEquals(false,screen2.isNativeValid()); + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + + Assert.assertSame(screen1,glWindow2.getScreen()); + Assert.assertSame(display1,glWindow2.getScreen().getDisplay()); + + Assert.assertEquals(0, glWindow1.getTotalFrames()); + Assert.assertEquals(0, glWindow2.getTotalFrames()); + glWindow1.setVisible(true); + System.err.println("Frames for setVisible(): A1: "+glWindow1.getTotalFrames()+", B1: "+glWindow2.getTotalFrames()); + Assert.assertTrue(0 < glWindow2.getTotalFrames()); + Assert.assertTrue(0 < glWindow1.getTotalFrames()); + + Assert.assertEquals(1,display1.getReferenceCount()); + Assert.assertEquals(true,display1.isNativeValid()); + Assert.assertNotNull(display1.getEDTUtil()); + Assert.assertEquals(true,display1.getEDTUtil().isRunning()); + Assert.assertEquals(2,screen1.getReferenceCount()); + Assert.assertEquals(true,screen1.isNativeValid()); + Assert.assertSame(glWindow1,glWindow2.getParent()); + Assert.assertSame(screen1,glWindow2.getScreen()); + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + + Animator animator1 = new Animator(glWindow1); + animator1.start(); + Animator animator2 = new Animator(glWindow2); + animator2.start(); + + int state = 0; + int reparentAction; + while(animator1.isAnimating() && animator1.getDuration()<3*durationPerTest) { + Thread.sleep(durationPerTest); + switch(state) { + case 0: + Assert.assertEquals(true, glWindow2.isVisible()); + reparentAction = glWindow2.reparentWindow(null, reparentRecreate); + Assert.assertTrue(Window.ReparentAction.ACTION_INVALID < reparentAction); + Assert.assertEquals(true, glWindow2.isVisible()); + Assert.assertEquals(true, glWindow2.isNativeValid()); + System.err.println("Frames for reparentWindow(parent, "+reparentRecreate+"): "+reparentAction+", B2: "+glWindow2.getTotalFrames()); + Assert.assertTrue(0 < glWindow2.getTotalFrames()); + Assert.assertNull(glWindow2.getParent()); + Assert.assertSame(screen1,glWindow2.getScreen()); + Assert.assertSame(display1,glWindow2.getScreen().getDisplay()); + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + break; + case 1: + Assert.assertEquals(true, glWindow2.isVisible()); + reparentAction = glWindow2.reparentWindow(glWindow1, reparentRecreate); + Assert.assertTrue(Window.ReparentAction.ACTION_INVALID < reparentAction); + Assert.assertEquals(true, glWindow2.isVisible()); + Assert.assertEquals(true, glWindow2.isNativeValid()); + System.err.println("Frames for reparentWindow(parent, "+reparentRecreate+"): "+reparentAction+", B3 "+glWindow2.getTotalFrames()); + Assert.assertTrue(0 < glWindow2.getTotalFrames()); + Assert.assertSame(glWindow1,glWindow2.getParent()); + Assert.assertSame(screen1,glWindow2.getScreen()); + Assert.assertSame(display1,glWindow2.getScreen().getDisplay()); + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + break; + } + state++; + } + // + // glwindow2 is child of glwindow1 + // + + animator1.stop(); + Assert.assertEquals(false, animator1.isAnimating()); + Assert.assertEquals(false, animator1.isPaused()); + Assert.assertEquals(null, animator1.getThread()); + animator2.stop(); + Assert.assertEquals(false, animator2.isAnimating()); + Assert.assertEquals(false, animator2.isPaused()); + Assert.assertEquals(null, animator2.getThread()); + + Assert.assertEquals(1,display1.getReferenceCount()); + Assert.assertEquals(true,display1.isNativeValid()); + Assert.assertNotNull(display1.getEDTUtil()); + Assert.assertEquals(true,display1.getEDTUtil().isRunning()); + Assert.assertEquals(2,screen1.getReferenceCount()); + Assert.assertEquals(true,screen1.isNativeValid()); + Assert.assertSame(glWindow1,glWindow2.getParent()); + Assert.assertSame(screen1,glWindow2.getScreen()); + + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + + glWindow1.destroy(); // should destroy both windows, actually, since glWindow2 is a child + Assert.assertEquals(true, glWindow1.isValid()); + Assert.assertEquals(false, glWindow1.isNativeValid()); + Assert.assertEquals(false, glWindow1.isVisible()); + Assert.assertEquals(true, glWindow2.isValid()); + Assert.assertEquals(false, glWindow2.isNativeValid()); + Assert.assertEquals(false, glWindow2.isVisible()); + + Assert.assertEquals(0,display1.getReferenceCount()); + Assert.assertEquals(false,display1.isNativeValid()); + Assert.assertNotNull(display1.getEDTUtil()); + Assert.assertEquals(false,display1.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen1.getReferenceCount()); + Assert.assertEquals(false,screen1.isNativeValid()); + + Assert.assertEquals(0,display2.getReferenceCount()); + Assert.assertEquals(false,display2.isNativeValid()); + Assert.assertNotNull(display2.getEDTUtil()); + Assert.assertEquals(false,display2.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen2.getReferenceCount()); + Assert.assertEquals(false,screen2.isNativeValid()); + + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + + glWindow2.destroy(); // dbl destroy check .. + Assert.assertEquals(false, glWindow1.isNativeValid()); + Assert.assertEquals(false, glWindow2.isNativeValid()); + + glWindow1.invalidate(); // parent -> child + Assert.assertEquals(false, glWindow1.isValid()); + Assert.assertEquals(false, glWindow2.isValid()); + + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + } + + public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) { + Assert.assertNotNull(demo); + Assert.assertNotNull(glWindow); + if(debug) { + MiscUtils.setFieldIfExists(demo, "glDebug", true); + MiscUtils.setFieldIfExists(demo, "glTrace", true); + } + if(!MiscUtils.setFieldIfExists(demo, "window", glWindow.getWindow())) { + MiscUtils.setFieldIfExists(demo, "glWindow", glWindow); + } + } + + static int atoi(String a) { + int i=0; + try { + i = Integer.parseInt(a); + } catch (Exception ex) { ex.printStackTrace(); } + return i; + } + + public static void main(String args[]) throws IOException { + for(int i=0; i0) { + animator1 = new FPSAnimator(glWindow1, fps); + } else { + animator1 = new Animator(glWindow1); + } + animator1.start(); + + int state; + for(state=0; state<3; state++) { + Thread.sleep(durationPerTest); + switch(state) { + case 0: + frame1.remove(newtCanvasAWT); + frame2.add(newtCanvasAWT, BorderLayout.CENTER); + break; + case 1: + frame2.remove(newtCanvasAWT); + frame1.add(newtCanvasAWT, BorderLayout.CENTER); + break; + } + } + + Assert.assertEquals(true, animator1.isAnimating()); + Assert.assertEquals(false, animator1.isPaused()); + Assert.assertNotNull(animator1.getThread()); + animator1.stop(); + Assert.assertEquals(false, animator1.isAnimating()); + Assert.assertEquals(false, animator1.isPaused()); + Assert.assertEquals(null, animator1.getThread()); + + frame1.dispose(); + frame2.dispose(); + glWindow1.invalidate(); + } + + public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) { + Assert.assertNotNull(demo); + Assert.assertNotNull(glWindow); + Window window = glWindow.getWindow(); + if(debug) { + MiscUtils.setFieldIfExists(demo, "glDebug", true); + MiscUtils.setFieldIfExists(demo, "glTrace", true); + } + if(!MiscUtils.setFieldIfExists(demo, "window", window)) { + MiscUtils.setFieldIfExists(demo, "glWindow", glWindow); + } + } + + static int atoi(String a) { + int i=0; + try { + i = Integer.parseInt(a); + } catch (Exception ex) { ex.printStackTrace(); } + return i; + } + + public static void main(String args[]) throws IOException { + for(int i=0; i0 && !shouldQuit) { + glWindow.display(); + Thread.sleep(step); + duration -= step; + + while( null != ( event = (NEWTEvent) eventFifo.get() ) ) { + Window source = (Window) event.getSource(); + if(event instanceof KeyEvent) { + KeyEvent keyEvent = (KeyEvent) event; + switch(keyEvent.getKeyChar()) { + case 'q': + shouldQuit = true; + break; + case 'f': + source.setFullscreen(!source.isFullscreen()); + break; + } + } + } + } + if(verbose) { + System.out.println("+++++++++++++++++++ END"); + } + Thread.sleep(waitReparent); + + glWindow.invalidate(); + if(useLayout) { + frame.remove(newtCanvasAWT); + } + frame.dispose(); + } + + public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) { + Assert.assertNotNull(demo); + Assert.assertNotNull(glWindow); + Window window = glWindow.getWindow(); + if(debug) { + MiscUtils.setFieldIfExists(demo, "glDebug", true); + MiscUtils.setFieldIfExists(demo, "glTrace", true); + } + if(!MiscUtils.setFieldIfExists(demo, "window", window)) { + MiscUtils.setFieldIfExists(demo, "glWindow", glWindow); + } + } + + static int atoi(String a) { + int i=0; + try { + i = Integer.parseInt(a); + } catch (Exception ex) { ex.printStackTrace(); } + return i; + } + + public static void main(String args[]) throws IOException { + verbose = true; + for(int i=0; i0 && !shouldQuit) { + glWindow1.display(); + glWindow2.display(); + Thread.sleep(step); + duration -= step; + x += 1; + y += 1; + glWindow1.setPosition(x,y); + glWindow2.setPosition(glWindow1.getWidth()/2,glWindow1.getHeight()/2-y); + + while( null != ( event = (NEWTEvent) eventFifo.get() ) ) { + Window source = (Window) event.getSource(); + if(WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY == event.getEventType()) { + shouldQuit = true; + } else if(event instanceof KeyEvent) { + KeyEvent keyEvent = (KeyEvent) event; + switch(keyEvent.getKeyChar()) { + case 'q': + shouldQuit = true; + break; + case 'f': + source.setFullscreen(!source.isFullscreen()); + break; + } + } + } + } + destroyWindow(null, null, window2, glWindow2); + destroyWindow(display, screen, window1, glWindow1); + } + + public static void setDemoFields(GLEventListener demo, Window window, GLWindow glWindow, boolean debug) { + Assert.assertNotNull(demo); + Assert.assertNotNull(window); + if(debug) { + MiscUtils.setFieldIfExists(demo, "glDebug", true); + MiscUtils.setFieldIfExists(demo, "glTrace", true); + } + if(!MiscUtils.setFieldIfExists(demo, "window", window)) { + MiscUtils.setFieldIfExists(demo, "glWindow", glWindow); + } + } + + static int atoi(String a) { + int i=0; + try { + i = Integer.parseInt(a); + } catch (Exception ex) { ex.printStackTrace(); } + return i; + } + + public static void main(String args[]) throws IOException { + for(int i=0; i*/ adapters) { + for(Iterator i = adapters.iterator(); i.hasNext(); ) { + EventCountAdapter adapter = (EventCountAdapter) i.next(); + adapter.reset(); + } + } +} + diff --git a/src/test/com/jogamp/opengl/test/junit/util/GLSLSimpleProgram.java b/src/test/com/jogamp/opengl/test/junit/util/GLSLSimpleProgram.java new file mode 100644 index 000000000..bcafc02f7 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/util/GLSLSimpleProgram.java @@ -0,0 +1,121 @@ +/** + * 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.opengl.util.glsl.ShaderUtil; +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import javax.media.opengl.GL; +import javax.media.opengl.GL2ES2; +import org.junit.Assert; + +public class GLSLSimpleProgram { + private int shaderProgram; + private int vertShader; + private int fragShader; + + private GLSLSimpleProgram(int shaderProgram, int vertShader, int fragShader) { + this.shaderProgram = shaderProgram; + this.vertShader = vertShader; + this.fragShader = fragShader; + } + + public static GLSLSimpleProgram create(GL2ES2 gl, String vertShaderCode, String fragShaderCode, boolean link) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + PrintStream pbaos = new PrintStream(baos); + + int vertShader = gl.glCreateShader(GL2ES2.GL_VERTEX_SHADER); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + + int fragShader = gl.glCreateShader(GL2ES2.GL_FRAGMENT_SHADER); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + + String[] vlines = new String[] { vertShaderCode }; + int[] vlengths = new int[] { vlines[0].length() }; + gl.glShaderSource(vertShader, vlines.length, vlines, vlengths, 0); + gl.glCompileShader(vertShader); + if(!ShaderUtil.isShaderStatusValid(gl, vertShader, gl.GL_COMPILE_STATUS, pbaos)) { + System.out.println("getShader:postCompile vertShader: "+baos.toString()); + Assert.assertTrue(false); + } + pbaos.flush(); baos.reset(); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + + + String[] flines = new String[] { fragShaderCode }; + int[] flengths = new int[] { flines[0].length() }; + gl.glShaderSource(fragShader, flines.length, flines, flengths, 0); + gl.glCompileShader(fragShader); + if(!ShaderUtil.isShaderStatusValid(gl, fragShader, gl.GL_COMPILE_STATUS, pbaos)) { + System.out.println("getShader:postCompile fragShader: "+baos.toString()); + Assert.assertTrue(false); + } + pbaos.flush(); baos.reset(); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + + int shaderProgram = gl.glCreateProgram(); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + gl.glAttachShader(shaderProgram, vertShader); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + gl.glAttachShader(shaderProgram, fragShader); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + + if(link) { + gl.glLinkProgram(shaderProgram); + if(!ShaderUtil.isProgramValid(gl, shaderProgram, pbaos)) { + System.out.println("Error (GLSL link error): "+baos.toString()); + Assert.assertTrue(false); + } + } + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + GLSLSimpleProgram res = new GLSLSimpleProgram(shaderProgram, vertShader, fragShader); + return res; + } + + public void release(GL2ES2 gl) { + gl.glUseProgram(0); + gl.glDetachShader(shaderProgram, vertShader); + gl.glDeleteShader(vertShader); + gl.glDetachShader(shaderProgram, fragShader); + gl.glDeleteShader(fragShader); + gl.glDeleteProgram(shaderProgram); + } + + public int getFragShader() { + return fragShader; + } + + public int getShaderProgram() { + return shaderProgram; + } + + public int getVertShader() { + return vertShader; + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java b/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java new file mode 100644 index 000000000..506fe2d97 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java @@ -0,0 +1,63 @@ +/** + * 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 java.lang.reflect.*; + +public class MiscUtils { + public static int atoi(String str, int def) { + try { + return Integer.parseInt(str); + } catch (Exception ex) { + ex.printStackTrace(); + } + return def; + } + + public static boolean setFieldIfExists(Object instance, String fieldName, Object value) { + try { + Field f = instance.getClass().getField(fieldName); + if(value instanceof Boolean || f.getType().isInstance(value)) { + f.set(instance, value); + return true; + } else { + System.out.println(instance.getClass()+" '"+fieldName+"' field not assignable with "+value.getClass()+", it's a: "+f.getType()); + } + } catch (IllegalAccessException ex) { + throw new RuntimeException(ex); + } catch (NoSuchFieldException nsfe) { + // OK - throw new RuntimeException(instance.getClass()+" has no '"+fieldName+"' field", nsfe); + } + return false; + } +} + + + diff --git a/src/test/com/jogamp/opengl/test/junit/util/NEWTFocusAdapter.java b/src/test/com/jogamp/opengl/test/junit/util/NEWTFocusAdapter.java new file mode 100644 index 000000000..9ee74aeff --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/util/NEWTFocusAdapter.java @@ -0,0 +1,64 @@ +/** + * 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.event.WindowAdapter; +import com.jogamp.newt.event.WindowEvent; + +public class NEWTFocusAdapter extends WindowAdapter implements EventCountAdapter { + + String prefix; + int focusGained; + + public NEWTFocusAdapter(String prefix) { + this.prefix = prefix; + reset(); + } + + public int getCount() { + return focusGained; + } + + public void reset() { + focusGained = 0; + } + + @Override + public void windowGainedFocus(WindowEvent e) { + ++focusGained; + System.err.println("FOCUS NEWT GAINED ["+focusGained+"]: "+prefix+", "+e); + } + + @Override + public void windowLostFocus(WindowEvent e) { + --focusGained; + System.err.println("FOCUS NEWT LOST ["+focusGained+"]: "+prefix+", "+e); + } +} + diff --git a/src/test/com/jogamp/opengl/test/junit/util/NEWTKeyAdapter.java b/src/test/com/jogamp/opengl/test/junit/util/NEWTKeyAdapter.java new file mode 100644 index 000000000..ba1a2f3f5 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/util/NEWTKeyAdapter.java @@ -0,0 +1,58 @@ +/** + * 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.event.KeyAdapter; +import com.jogamp.newt.event.KeyEvent; + +public class NEWTKeyAdapter extends KeyAdapter implements EventCountAdapter { + + String prefix; + int keyTyped; + + public NEWTKeyAdapter(String prefix) { + this.prefix = prefix; + reset(); + } + + public int getCount() { + return keyTyped; + } + + public void reset() { + keyTyped = 0; + } + + @Override + public void keyTyped(KeyEvent e) { + ++keyTyped; + System.err.println("KEY NEWT TYPED ["+keyTyped+"]: "+prefix+", "+e); + } +} + diff --git a/src/test/com/jogamp/opengl/test/junit/util/NEWTMouseAdapter.java b/src/test/com/jogamp/opengl/test/junit/util/NEWTMouseAdapter.java new file mode 100644 index 000000000..617d951ec --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/util/NEWTMouseAdapter.java @@ -0,0 +1,57 @@ +/** + * 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.event.MouseAdapter; +import com.jogamp.newt.event.MouseEvent; + +public class NEWTMouseAdapter extends MouseAdapter implements EventCountAdapter { + + String prefix; + int mouseClicked; + + public NEWTMouseAdapter(String prefix) { + this.prefix = prefix; + reset(); + } + + public int getCount() { + return mouseClicked; + } + + public void reset() { + mouseClicked = 0; + } + + public void mouseClicked(MouseEvent e) { + mouseClicked+=e.getClickCount(); + System.err.println("MOUSE NEWT CLICKED ["+mouseClicked+"]: "+prefix+", "+e); + } +} + diff --git a/src/test/com/jogamp/opengl/test/junit/util/QuitAdapter.java b/src/test/com/jogamp/opengl/test/junit/util/QuitAdapter.java new file mode 100644 index 000000000..77996bf1e --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/util/QuitAdapter.java @@ -0,0 +1,52 @@ +/** + * 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.event.*; + +public class QuitAdapter extends WindowAdapter implements WindowListener, KeyListener { + boolean shouldQuit = false; + + public boolean shouldQuit() { return shouldQuit; } + + public void windowDestroyNotify(WindowEvent e) { + System.out.println("QUIT Window "+Thread.currentThread()); + shouldQuit = true; + } + + public void keyTyped(KeyEvent e) { + if(e.getKeyChar()=='q') { + System.out.println("QUIT Key "+Thread.currentThread()); + shouldQuit = true; + } + } + public void keyPressed(KeyEvent e) {} + public void keyReleased(KeyEvent e) {} +} + diff --git a/src/test/com/jogamp/opengl/test/junit/util/SingletonInstance.java b/src/test/com/jogamp/opengl/test/junit/util/SingletonInstance.java new file mode 100644 index 000000000..7e3b9ebc0 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/util/SingletonInstance.java @@ -0,0 +1,143 @@ +/** + * 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 java.io.File; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.nio.channels.FileLock; + +public class SingletonInstance { + + static final boolean DEBUG = true; + static final String temp_file_path; + + static { + String s = null; + try { + File tmpFile = File.createTempFile("TEST", "tst"); + String absTmpFile = tmpFile.getCanonicalPath(); + tmpFile.delete(); + s = absTmpFile.substring(0, absTmpFile.lastIndexOf(File.separator)); + } catch (IOException ex) { + ex.printStackTrace(); + } + temp_file_path = s; + } + + public static String getCanonicalTempPath() { + return temp_file_path; + } + + public static String getCanonicalTempLockFilePath(String basename) { + return getCanonicalTempPath() + File.separator + basename; + } + + public SingletonInstance(String lockFileBasename) { + this.file = new File ( getCanonicalTempLockFilePath ( lockFileBasename ) ); + } + + public SingletonInstance(File lockFile) { + this.file = lockFile ; + } + + public synchronized void lock(long timeout_ms, long poll_ms) { + long i=0; + try { + do { + if(tryLock()) { + return; + } + if(DEBUG && 0==i) { + System.err.println("Wait for lock " + file); + } + i++; + Thread.sleep(poll_ms); + } while ( i < timeout_ms / poll_ms ) ; + } catch ( InterruptedException ie ) { + throw new RuntimeException(ie); + } + throw new RuntimeException("SingletonInstance couldn't get lock within "+timeout_ms+"ms"); + } + + public synchronized boolean tryLock() { + try { + randomAccessFile = new RandomAccessFile(file, "rw"); + fileLock = randomAccessFile.getChannel().tryLock(); + + if (fileLock != null) { + //final File f_file = file; + //final RandomAccessFile f_randomAccessFile = randomAccessFile; + //final FileLock f_fileLock = fileLock; + Runtime.getRuntime().addShutdownHook(new Thread() { + public void run() { + unlock(); + } + }); + locked = true; + if(DEBUG) { + System.err.println("Locked " + file); + } + return true; + } + } catch (Exception e) { + System.err.println("Unable to create and/or lock file: " + file); + e.printStackTrace(); + } + return false; + } + + public synchronized boolean unlock() { + if(locked) { + try { + fileLock.release(); + randomAccessFile.close(); + file.delete(); + return true; + } catch (Exception e) { + System.err.println("Unable to remove lock file: " + file); + e.printStackTrace(); + } finally { + fileLock = null; + randomAccessFile = null; + locked = false; + } + } + return false; + } + + public synchronized boolean isLocked() { + return locked; + } + + File file = null; + RandomAccessFile randomAccessFile = null; + FileLock fileLock = null; + boolean locked = false; +} diff --git a/src/test/com/jogamp/opengl/test/junit/util/UITestCase.java b/src/test/com/jogamp/opengl/test/junit/util/UITestCase.java new file mode 100644 index 000000000..b01ba1be9 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/util/UITestCase.java @@ -0,0 +1,72 @@ +/** + * 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 org.junit.Before; +import org.junit.BeforeClass; +import org.junit.After; +import org.junit.AfterClass; + + +public abstract class UITestCase { + + public static final String SINGLE_INSTANCE_LOCK_FILE = "UITestCase.lock"; + + static SingletonInstance singletonInstance; + + protected SingletonInstance getSingletonInstance() { + return singletonInstance; + } + + @BeforeClass + public static void oneTimeSetUp() { + // one-time initialization code + singletonInstance = new SingletonInstance(SINGLE_INSTANCE_LOCK_FILE); + singletonInstance.lock(3*60*1000, 100); // wait up to 3 min, poll every 100ms + } + + @AfterClass + public static void oneTimeTearDown() { + // one-time cleanup code + System.gc(); // force cleanup + singletonInstance.unlock(); + } + + @Before + public void setUp() { + System.err.println("++++ UITestCase.setUp: "+getClass().getName()); + } + + @After + public void tearDown() { + System.err.println("++++ UITestCase.tearDown: "+getClass().getName()); + } + +} + diff --git a/src/test/native/displayMultiple01.c b/src/test/native/displayMultiple01.c new file mode 100644 index 000000000..d51453687 --- /dev/null +++ b/src/test/native/displayMultiple01.c @@ -0,0 +1,18 @@ +#include +#include +#include +#include +#include + +int main(int nargs, char **vargs) { + int major, minor; + Display *disp = XOpenDisplay(NULL); + glXQueryVersion(disp, &major, &minor); + fprintf(stderr, "%p: %d.%d\n", disp, major, minor); + XCloseDisplay(disp); + disp = XOpenDisplay(NULL); + glXQueryVersion(disp, &major, &minor); + fprintf(stderr, "%p: %d.%d\n", disp, major, minor); + XCloseDisplay(disp); + return 0; +} diff --git a/src/test/native/displayMultiple02.c b/src/test/native/displayMultiple02.c new file mode 100644 index 000000000..1bfe95b95 --- /dev/null +++ b/src/test/native/displayMultiple02.c @@ -0,0 +1,113 @@ +/** + * compile with: gcc -o displayMultiple02 displayMultiple02.c -lX11 -lGL + */ + +#include +#include +#include +#include +#include +#include + +static void testOrder(int reverseDestroyOrder, const char * msg); + +int main(int nargs, char **vargs) { + testOrder(0, "Normal order"); + testOrder(1, "Reverse order"); + return 0; +} + +static void createGLWin(Display *dpy, int width, int height, Window *rWin, GLXContext *rCtx); +static void useGL(Display *dpy, Window win, GLXContext ctx, int width, int height); + +void testOrder(int reverseDestroyOrder, const char * msg) { + int major, minor; + Display *disp1; + Window win1; + GLXContext ctx1; + + Display *disp2; + Window win2; + GLXContext ctx2; + + fprintf(stderr, "%s: Create #1\n", msg); + disp1 = XOpenDisplay(NULL); + createGLWin(disp1, 200, 200, &win1, &ctx1); + useGL(disp1, win1, ctx1, 200, 200); + + fprintf(stderr, "%s: Create #2\n", msg); + disp2 = XOpenDisplay(NULL); + createGLWin(disp2, 300, 300, &win2, &ctx2); + useGL(disp2, win2, ctx2, 300, 300); + + if(reverseDestroyOrder) { + fprintf(stderr, "%s: Destroy #2\n", msg); + glXMakeCurrent(disp2, 0, 0); + glXDestroyContext(disp2, ctx2); + XCloseDisplay(disp2); + + fprintf(stderr, "%s: Destroy #1\n", msg); + glXMakeCurrent(disp1, 0, 0); + glXDestroyContext(disp1, ctx1); + XCloseDisplay(disp1); + } else { + fprintf(stderr, "%s: Destroy #1\n", msg); + glXMakeCurrent(disp1, 0, 0); + glXDestroyContext(disp1, ctx1); + XCloseDisplay(disp1); + + fprintf(stderr, "%s: Destroy #2\n", msg); + glXMakeCurrent(disp2, 0, 0); + glXDestroyContext(disp2, ctx2); + XCloseDisplay(disp2); + + } + + fprintf(stderr, "%s: Success - no bug\n", msg); +} + +/* attributes for a double buffered visual in RGBA format with at least + * 4 bits per color and a 16 bit depth buffer */ +static int attrListDbl[] = { GLX_RGBA, GLX_DOUBLEBUFFER, + GLX_RED_SIZE, 4, + GLX_GREEN_SIZE, 4, + GLX_BLUE_SIZE, 4, + GLX_DEPTH_SIZE, 16, + None }; + +void createGLWin(Display *dpy, int width, int height, Window *rWin, GLXContext *rCtx) +{ + int screen = DefaultScreen(dpy); + XVisualInfo *vi = glXChooseVisual(dpy, screen, attrListDbl); + Colormap cmap; + XSetWindowAttributes attr; + + /* create a GLX context */ + *rCtx = glXCreateContext(dpy, vi, 0, GL_TRUE); + /* create a color map */ + cmap = XCreateColormap(dpy, RootWindow(dpy, vi->screen), vi->visual, AllocNone); + attr.colormap = cmap; + attr.border_pixel = 0; + + /* create a window in window mode*/ + attr.event_mask = ExposureMask | KeyPressMask | ButtonPressMask | + StructureNotifyMask; + *rWin = XCreateWindow(dpy, RootWindow(dpy, vi->screen), + 0, 0, width, height, 0, vi->depth, InputOutput, vi->visual, + CWBorderPixel | CWColormap | CWEventMask, &attr); + + XMapRaised(dpy, *rWin); +} + +void useGL(Display *dpy, Window win, GLXContext ctx, int width, int height) +{ + glXMakeCurrent(dpy, win, ctx); + glShadeModel(GL_SMOOTH); + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + glClearDepth(1.0f); + glViewport(0, 0, width, height); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glXSwapBuffers(dpy, win); + glXMakeCurrent(dpy, 0, 0); +} + diff --git a/src/test/native/glExtensionsListGL2.c b/src/test/native/glExtensionsListGL2.c new file mode 100644 index 000000000..89815e9c0 --- /dev/null +++ b/src/test/native/glExtensionsListGL2.c @@ -0,0 +1,95 @@ +/** + * compile with: gcc -o displayMultiple02 displayMultiple02.c -lX11 -lGL + */ + +#include +#include +#include +#include +#include +#include + +static void testExtensions(); + +int main(int nargs, char **vargs) { + testExtensions(); + return 0; +} + +static void createGLWin(Display *dpy, int width, int height, Window *rWin, GLXContext *rCtx); +static void useGL(Display *dpy, Window win, GLXContext ctx, int width, int height); + +void testExtensions() { + int major, minor; + Display *disp1; + Window win1; + GLXContext ctx1; + + disp1 = XOpenDisplay(NULL); + createGLWin(disp1, 200, 200, &win1, &ctx1); + if(0 != win1 && 0 != ctx1) { + useGL(disp1, win1, ctx1, 200, 200); + + glXMakeCurrent(disp1, 0, 0); + glXDestroyContext(disp1, ctx1); + } + XCloseDisplay(disp1); +} + +/* attributes for a double buffered visual in RGBA format with at least + * 4 bits per color and a 16 bit depth buffer */ +static int attrListDbl[] = { GLX_RGBA, GLX_DOUBLEBUFFER, + GLX_RED_SIZE, 4, + GLX_GREEN_SIZE, 4, + GLX_BLUE_SIZE, 4, + GLX_DEPTH_SIZE, 16, + None }; + +void createGLWin(Display *dpy, int width, int height, Window *rWin, GLXContext *rCtx) +{ + int screen = DefaultScreen(dpy); + XVisualInfo *vi = glXChooseVisual(dpy, screen, attrListDbl); + Colormap cmap; + XSetWindowAttributes attr; + + /* create a GLX context */ + *rCtx = glXCreateContext(dpy, vi, 0, GL_TRUE); + /* create a color map */ + cmap = XCreateColormap(dpy, RootWindow(dpy, vi->screen), vi->visual, AllocNone); + attr.colormap = cmap; + attr.border_pixel = 0; + + /* create a window in window mode*/ + attr.event_mask = ExposureMask | KeyPressMask | ButtonPressMask | + StructureNotifyMask; + *rWin = XCreateWindow(dpy, RootWindow(dpy, vi->screen), + 0, 0, width, height, 0, vi->depth, InputOutput, vi->visual, + CWBorderPixel | CWColormap | CWEventMask, &attr); + + XMapRaised(dpy, *rWin); +} + +void useGL(Display *dpy, Window win, GLXContext ctx, int width, int height) +{ + PFNGLGETSTRINGIPROC glGetStringi = 0; + int i, n; + + glXMakeCurrent(dpy, win, ctx); + + fprintf(stderr, "GL_VENDOR: %s\n", glGetString(GL_VENDOR)); + + glGetIntegerv(GL_NUM_EXTENSIONS, &n); + fprintf(stderr, "GL_NUM_EXTENSIONS: %d\n", n); + + glGetStringi = (PFNGLGETSTRINGIPROC)glXGetProcAddressARB("glGetStringi"); + if(NULL==glGetStringi) { + return; + } + + for (i=0; i +#include +#include +#include +#include +#include +#include +#include +#include +#include + +typedef int bool; +#define true 1; +#define false 0; + +// Helper to check for extension string presence. Adapted from: +// http://www.opengl.org/resources/features/OGLextensions/ +static bool isExtensionSupported(const char *extList, const char *extension) +{ + + const char *start; + const char *where, *terminator; + + /* Extension names should not have spaces. */ + where = strchr(extension, ' '); + if ( where || *extension == '\0' ) + return false; + + /* It takes a bit of care to be fool-proof about parsing the + OpenGL extensions string. Don't be fooled by sub-strings, + etc. */ + for ( start = extList; ; ) { + where = strstr( start, extension ); + + if ( !where ) + break; + + terminator = where + strlen( extension ); + + if ( where == start || *(where - 1) == ' ' ) + if ( *terminator == ' ' || *terminator == '\0' ) + return true; + + start = terminator; + } + + return false; +} + +static bool ctxErrorOccurred = false; +static int ctxErrorHandler( Display *dpy, XErrorEvent *ev ) +{ + ctxErrorOccurred = true; + return 0; +} + +void dumpGLExtension() { + PFNGLGETSTRINGIPROC glGetStringi = 0; + int i, n; + + fprintf(stderr, "GL_VENDOR: %s\n", glGetString(GL_VENDOR)); + + glGetIntegerv(GL_NUM_EXTENSIONS, &n); + fprintf(stderr, "GL_NUM_EXTENSIONS: %d\n", n); + + glGetStringi = (PFNGLGETSTRINGIPROC)glXGetProcAddressARB("glGetStringi"); + if(NULL==glGetStringi) { + return; + } + + for (i=0; i visualid), samp_buf, samples ); + + if ( best_fbc < 0 || samp_buf && samples > best_num_samp ) + best_fbc = i, best_num_samp = samples; + if ( worst_fbc < 0 || !samp_buf || samples < worst_num_samp ) + worst_fbc = i, worst_num_samp = samples; + } + XFree( vi ); + } + + GLXFBConfig bestFbc = fbc[ best_fbc ]; + + // Be sure to free the FBConfig list allocated by glXChooseFBConfig() + XFree( fbc ); + + // Get a visual + XVisualInfo *vi = glXGetVisualFromFBConfig( display, bestFbc ); + printf( "Chosen visual ID = 0x%x\n", (int) vi->visualid ); + + printf( "Creating colormap\n" ); + XSetWindowAttributes swa; + Colormap cmap; + swa.colormap = cmap = XCreateColormap( display, + RootWindow( display, vi->screen ), + vi->visual, AllocNone ); + swa.background_pixmap = None ; + swa.border_pixel = 0; + swa.event_mask = StructureNotifyMask; + + printf( "Creating window\n" ); + Window win = XCreateWindow( display, RootWindow( display, vi->screen ), + 0, 0, 100, 100, 0, vi->depth, InputOutput, + vi->visual, + CWBorderPixel|CWColormap|CWEventMask, &swa ); + if ( !win ) + { + printf( "Failed to create window.\n" ); + exit(1); + } + + // Done with the visual info data + XFree( vi ); + + XStoreName( display, win, "GL 3.0 Window" ); + + printf( "Mapping window\n" ); + XMapWindow( display, win ); + + // Get the default screen's GLX extension list + const char *glxExts = glXQueryExtensionsString( display, + DefaultScreen( display ) ); + + // NOTE: It is not necessary to create or make current to a context before + // calling glXGetProcAddressARB + PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = 0; + glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC) + glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" ); + + GLXContext ctx = 0; + + // Install an X error handler so the application won't exit if GL 3.0 + // context allocation fails. + // + // Note this error handler is global. All display connections in all threads + // of a process use the same error handler, so be sure to guard against other + // threads issuing X commands while this code is running. + ctxErrorOccurred = false; + int (*oldHandler)(Display*, XErrorEvent*) = + XSetErrorHandler(&ctxErrorHandler); + + // Check for the GLX_ARB_create_context extension string and the function. + // If either is not present, use GLX 1.3 context creation method. + if ( !isExtensionSupported( glxExts, "GLX_ARB_create_context" ) || + !glXCreateContextAttribsARB ) + { + printf( "glXCreateContextAttribsARB() not found" + " ... using old-style GLX context\n" ); + ctx = glXCreateNewContext( display, bestFbc, GLX_RGBA_TYPE, 0, True ); + } + + // If it does, try to get a GL 3.0 context! + else + { + int context_attribs[] = + { + GLX_CONTEXT_MAJOR_VERSION_ARB, 3, + GLX_CONTEXT_MINOR_VERSION_ARB, 0, + GLX_RENDER_TYPE , GLX_RGBA_TYPE, + GLX_CONTEXT_FLAGS_ARB , GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, + None + }; + + printf( "Creating context\n" ); + ctx = glXCreateContextAttribsARB( display, bestFbc, 0, + True, context_attribs ); + + // Sync to ensure any errors generated are processed. + XSync( display, False ); + if ( !ctxErrorOccurred && ctx ) { + printf( "Created GL 3.0 context\n" ); + } else + { + // Couldn't create GL 3.0 context. Fall back to old-style 2.x context. + // When a context version below 3.0 is requested, implementations will + // return the newest context version compatible with OpenGL versions less + // than version 3.0. + // GLX_CONTEXT_MAJOR_VERSION_ARB = 1 + context_attribs[1] = 1; + // GLX_CONTEXT_MINOR_VERSION_ARB = 0 + context_attribs[3] = 0; + + ctxErrorOccurred = false; + + printf( "Failed to create GL 3.0 context" + " ... using old-style GLX context\n" ); + ctx = glXCreateContextAttribsARB( display, bestFbc, 0, + True, context_attribs ); + } + } + + // Sync to ensure any errors generated are processed. + XSync( display, False ); + + // Restore the original error handler + XSetErrorHandler( oldHandler ); + + if ( ctxErrorOccurred || !ctx ) + { + printf( "Failed to create an OpenGL context\n" ); + exit(1); + } + + // Verifying that context is a direct context + if ( ! glXIsDirect ( display, ctx ) ) + { + printf( "Indirect GLX rendering context obtained\n" ); + } + else + { + printf( "Direct GLX rendering context obtained\n" ); + } + + printf( "Making context current\n" ); + glXMakeCurrent( display, win, ctx ); + + dumpGLExtension(); + + glXMakeCurrent( display, 0, 0 ); + glXDestroyContext( display, ctx ); + + XDestroyWindow( display, win ); + XFreeColormap( display, cmap ); + XCloseDisplay( display ); + + return 0; +} + diff --git a/src/test/native/make.sh b/src/test/native/make.sh new file mode 100755 index 000000000..20bd49e4a --- /dev/null +++ b/src/test/native/make.sh @@ -0,0 +1,6 @@ +#! /bin/bash + +gcc -o displayMultiple01 displayMultiple01.c -lX11 -lGL +gcc -o displayMultiple02 displayMultiple02.c -lX11 -lGL +gcc -o glExtensionsListGL2 glExtensionsListGL2.c -lX11 -lGL +gcc -o glExtensionsListGL3 glExtensionsListGL3.c -lX11 -lGL -- cgit v1.2.3