JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
WindowUtilNEWT.java
Go to the documentation of this file.
1/**
2 * Copyright 2010 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.offscreen;
30
31import com.jogamp.opengl.test.junit.util.*;
32
33import org.junit.Assert;
34
35import com.jogamp.opengl.*;
36import com.jogamp.nativewindow.*;
37import com.jogamp.newt.*;
38import com.jogamp.newt.event.*;
39import com.jogamp.newt.opengl.*;
40
41public class WindowUtilNEWT {
42
43 public static GLCapabilities fixCaps(final GLCapabilities caps, final boolean onscreen, final boolean pbuffer, final boolean undecorated) {
44 final GLCapabilities caps2 = (GLCapabilities) caps.cloneMutable();
45 caps2.setOnscreen(onscreen);
46 caps2.setPBuffer(!onscreen && pbuffer);
47 caps2.setDoubleBuffered(!onscreen);
48 return caps2;
49 }
50
51 public static void setDemoFields(final GLEventListener demo, final Window window, final GLWindow glWindow, final boolean debug) {
52 Assert.assertNotNull(demo);
53 Assert.assertNotNull(window);
54 if(debug) {
55 MiscUtils.setFieldIfExists(demo, "glDebug", true);
56 MiscUtils.setFieldIfExists(demo, "glTrace", true);
57 }
58 if(!MiscUtils.setFieldIfExists(demo, "window", window)) {
59 MiscUtils.setFieldIfExists(demo, "glWindow", glWindow);
60 }
61 }
62
63 public static void run(final String testName, final GLWindow windowOffScreen, final GLEventListener demo,
64 final GLWindow windowOnScreenBlit, final WindowListener wl, final MouseListener ml,
65 final SurfaceUpdatedListener ul, final int frames, final boolean snapshot, final boolean debug) {
66 Assert.assertNotNull(windowOffScreen);
67 Assert.assertNotNull(demo);
68
69 setDemoFields(demo, windowOffScreen, windowOffScreen, debug);
70 windowOffScreen.addGLEventListener(demo);
71
72 if ( null != windowOnScreenBlit ) {
73 if(null!=wl) {
74 windowOnScreenBlit.addWindowListener(wl);
75 }
76 if(null!=ml) {
77 windowOnScreenBlit.addMouseListener(ml);
78 }
79 windowOnScreenBlit.setVisible(true);
80 }
81
82 final GLDrawable readDrawable = windowOffScreen.getContext().getGLDrawable() ;
83 if ( null != windowOnScreenBlit ) {
84 final ReadBuffer2Screen readDemo = new ReadBuffer2Screen( readDrawable ) ;
85 windowOnScreenBlit.addGLEventListener(readDemo);
86 }
87 if(snapshot) {
88 final boolean alpha = windowOffScreen.getChosenGLCapabilities().getAlphaBits()>0;
89 final Surface2File s2f = new Surface2File(testName, alpha);
90 windowOffScreen.addSurfaceUpdatedListener(s2f);
91 }
92 if(null!=ul) {
93 windowOffScreen.addSurfaceUpdatedListener(ul);
94 }
95
96 if(debug) {
97 System.err.println("+++++++++++++++++++++++++++ "+testName);
98 System.err.println(windowOffScreen);
99 System.err.println("+++++++++++++++++++++++++++ "+testName);
100 }
101
102 while ( windowOffScreen.getTotalFPSFrames() < frames) {
103 windowOffScreen.display();
104 }
105 windowOffScreen.removeSurfaceUpdatedListener(ul);
106
107 }
108
109}
void setOnscreen(final boolean onscreen)
Sets whether the surface shall be on- or offscreen.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
final void addMouseListener(final MouseListener l)
Appends the given MouseListener to the end of the list.
Definition: GLWindow.java:927
final void removeSurfaceUpdatedListener(final SurfaceUpdatedListener l)
Remove the specified SurfaceUpdatedListener from the list.
Definition: GLWindow.java:1020
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
final void addSurfaceUpdatedListener(final SurfaceUpdatedListener l)
Appends the given SurfaceUpdatedListener to the end of the list.
Definition: GLWindow.java:1025
Specifies a set of OpenGL capabilities.
void setPBuffer(final boolean enable)
Requesting offscreen pbuffer mode.
void setDoubleBuffered(final boolean enable)
Enables or disables double buffering.
abstract GLDrawable getGLDrawable()
Returns the write-drawable this context uses for framebuffer operations.
static void setDemoFields(final GLEventListener demo, final Window window, final GLWindow glWindow, final boolean debug)
static void run(final String testName, final GLWindow windowOffScreen, final GLEventListener demo, final GLWindow windowOnScreenBlit, final WindowListener wl, final MouseListener ml, final SurfaceUpdatedListener ul, final int frames, final boolean snapshot, final boolean debug)
static GLCapabilities fixCaps(final GLCapabilities caps, final boolean onscreen, final boolean pbuffer, final boolean undecorated)
static boolean setFieldIfExists(final Object instance, final String fieldName, final Object value)
Definition: MiscUtils.java:193
int getAlphaBits()
Returns the number of bits for the color buffer's alpha component.
Clients may add their SurfaceUpdateListener implementation to a com.jogamp.nativewindow....
Specifying NEWT's Window functionality:
Definition: Window.java:115
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
GLContext getContext()
Returns the context associated with this drawable.
An abstraction for an OpenGL rendering target.
Definition: GLDrawable.java:51
GLCapabilitiesImmutable getChosenGLCapabilities()
Fetches the GLCapabilitiesImmutable corresponding to the chosen OpenGL capabilities (pixel format / v...
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.