JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestGLContextDrawableSwitch02NEWT.java
Go to the documentation of this file.
1/**
2 * Copyright 2013 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29package com.jogamp.opengl.test.junit.jogl.acore.glels;
30
31import java.io.IOException;
32import java.lang.reflect.InvocationTargetException;
33
34import com.jogamp.newt.opengl.GLWindow;
35
36import com.jogamp.opengl.GLAutoDrawable;
37import com.jogamp.opengl.GLCapabilitiesImmutable;
38import com.jogamp.opengl.GLDrawableFactory;
39
40import com.jogamp.opengl.test.junit.util.QuitAdapter;
41
42import org.junit.Assert;
43import org.junit.FixMethodOrder;
44import org.junit.runners.MethodSorters;
45
46/**
47 * Test re-association (switching) of GLWindow /GLDrawables,
48 * from GLWindow/GLOffscreenAutoDrawable to an GLOffscreenAutoDrawable and back.
49 */
50@FixMethodOrder(MethodSorters.NAME_ASCENDING)
52 @Override
53 public GLAutoDrawable createGLAutoDrawable(final QuitAdapter quitAdapter, final GLCapabilitiesImmutable caps, final int width, final int height) throws InterruptedException, InvocationTargetException {
54 final GLAutoDrawable glad;
55 if( caps.isOnscreen() ) {
56 final GLWindow glWindow = GLWindow.create(caps);
57 Assert.assertNotNull(glWindow);
58 glad = glWindow;
59
60 if( null != quitAdapter ) {
61 glWindow.addWindowListener(quitAdapter);
62 }
63
64 glWindow.setVisible(true);
65 } else {
66 final GLDrawableFactory factory = GLDrawableFactory.getFactory(caps.getGLProfile());
67 glad = factory.createOffscreenAutoDrawable(null, caps, null, width, height);
68 Assert.assertNotNull(glad);
69 }
70 return glad;
71 }
72
73 @Override
74 public void destroyGLAutoDrawable(final GLAutoDrawable glad) throws InterruptedException, InvocationTargetException {
75 glad.destroy();
76 }
77
78 public static void main(final String args[]) throws IOException {
79 for(int i=0; i<args.length; i++) {
80 if(args[i].equals("-time")) {
81 i++;
82 try {
83 duration = Integer.parseInt(args[i]);
84 } catch (final Exception ex) { ex.printStackTrace(); }
85 } else if(args[i].equals("-period")) {
86 i++;
87 try {
88 period = Integer.parseInt(args[i]);
89 } catch (final Exception ex) { ex.printStackTrace(); }
90 } else if(args[i].equals("-testUnsafe")) {
91 testEvenUnsafeSwapGLContext = true;
92 }
93 }
94 /**
95 BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
96 System.err.println("Press enter to continue");
97 System.err.println(stdin.readLine()); */
98 org.junit.runner.JUnitCore.main(TestGLContextDrawableSwitch02NEWT.class.getName());
99 }
100}
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
Definition: GLWindow.java:615
final void addWindowListener(final WindowListener l)
Appends the given com.jogamp.newt.event.WindowListener to the end of the list.
Definition: GLWindow.java:882
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Definition: GLWindow.java:169
abstract GLOffscreenAutoDrawable createOffscreenAutoDrawable(AbstractGraphicsDevice device, GLCapabilitiesImmutable caps, GLCapabilitiesChooser chooser, int width, int height)
Creates a realized GLOffscreenAutoDrawable incl it's offscreen NativeSurface with the given capabilit...
static GLDrawableFactory getFactory(final GLProfile glProfile)
Returns the sole GLDrawableFactory instance.
Test re-association (switching) of GLWindow /GLDrawables, from GLWindow/GLOffscreenAutoDrawable to an...
Test re-association (switching) of GLWindow /GLDrawables, from GLWindow/GLOffscreenAutoDrawable to an...
GLAutoDrawable createGLAutoDrawable(final QuitAdapter quitAdapter, final GLCapabilitiesImmutable caps, final int width, final int height)
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
Specifies an immutable set of OpenGL capabilities.