JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestGLContextDrawableSwitch02AWT.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.awt.BorderLayout;
32import java.awt.Component;
33import java.awt.Dimension;
34import java.awt.Frame;
35import java.io.IOException;
36import java.lang.reflect.InvocationTargetException;
37
38import com.jogamp.newt.event.TraceWindowAdapter;
39import com.jogamp.newt.event.awt.AWTWindowAdapter;
40
41import com.jogamp.opengl.GLAutoDrawable;
42import com.jogamp.opengl.GLCapabilitiesImmutable;
43import com.jogamp.opengl.GLDrawableFactory;
44import com.jogamp.opengl.awt.GLCanvas;
45
46import jogamp.nativewindow.awt.AWTMisc;
47
48import com.jogamp.opengl.test.junit.util.QuitAdapter;
49
50import org.junit.Assert;
51import org.junit.FixMethodOrder;
52import org.junit.runners.MethodSorters;
53
54/**
55 * Test re-association (switching) of GLContext/GLDrawables,
56 * from GLCanvas to an GLOffscreenAutoDrawable and back.
57 */
58@FixMethodOrder(MethodSorters.NAME_ASCENDING)
60
61 @Override
62 public GLAutoDrawable createGLAutoDrawable(final QuitAdapter quitAdapter, final GLCapabilitiesImmutable caps, final int width, final int height) throws InterruptedException, InvocationTargetException {
63 final GLAutoDrawable glad;
64 if( caps.isOnscreen() ) {
65 final Frame frame = new Frame("Gears AWT Test");
66 Assert.assertNotNull(frame);
67
68 final GLCanvas glCanvas = new GLCanvas(caps);
69 Assert.assertNotNull(glCanvas);
70 final Dimension glc_sz = new Dimension(width, height);
71 glCanvas.setMinimumSize(glc_sz);
72 glCanvas.setPreferredSize(glc_sz);
73 glCanvas.setSize(glc_sz);
74 glad = glCanvas;
75
76 new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter), glCanvas).addTo(frame);
77
78 frame.setLayout(new BorderLayout());
79 frame.add(glCanvas, BorderLayout.CENTER);
80 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
81 public void run() {
82 frame.pack();
83 frame.setVisible(true);
84 }});
85 } else {
86 final GLDrawableFactory factory = GLDrawableFactory.getFactory(caps.getGLProfile());
87 glad = factory.createOffscreenAutoDrawable(null, caps, null, width, height);
88 Assert.assertNotNull(glad);
89 }
90 return glad;
91 }
92
93 @Override
94 public void destroyGLAutoDrawable(final GLAutoDrawable glad) throws InterruptedException, InvocationTargetException {
95 if( glad.getChosenGLCapabilities().isOnscreen() ) {
96 final Frame frame = AWTMisc.getFrame((Component)glad);
97 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
98 public void run() {
99 final Frame _frame = frame;
100 _frame.dispose();
101 }});
102 } else {
103 glad.destroy();
104 }
105 }
106
107 public static void main(final String args[]) throws IOException {
108 for(int i=0; i<args.length; i++) {
109 if(args[i].equals("-time")) {
110 i++;
111 try {
112 duration = Integer.parseInt(args[i]);
113 } catch (final Exception ex) { ex.printStackTrace(); }
114 } else if(args[i].equals("-period")) {
115 i++;
116 try {
117 period = Integer.parseInt(args[i]);
118 } catch (final Exception ex) { ex.printStackTrace(); }
119 } else if(args[i].equals("-testUnsafe")) {
120 testEvenUnsafeSwapGLContext = true;
121 }
122 }
123 /**
124 BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
125 System.err.println("Press enter to continue");
126 System.err.println(stdin.readLine()); */
127 org.junit.runner.JUnitCore.main(TestGLContextDrawableSwitch02AWT.class.getName());
128 }
129}
synchronized AWTAdapter addTo(final java.awt.Component awtComponent)
Due to the fact that some NEWT com.jogamp.newt.event.NEWTEventListener are mapped to more than one ja...
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.
A heavyweight AWT component which provides OpenGL rendering support.
Definition: GLCanvas.java:170
Test re-association (switching) of GLWindow /GLDrawables, from GLWindow/GLOffscreenAutoDrawable to an...
Test re-association (switching) of GLContext/GLDrawables, from GLCanvas to an GLOffscreenAutoDrawable...
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.
void setSize(int width, int height)
Requests a new width and height for this AWTGLAutoDrawable.