29package com.jogamp.opengl.test.junit.jogl.acore;
31import java.io.BufferedReader;
32import java.io.IOException;
33import java.io.InputStreamReader;
35import com.jogamp.newt.event.WindowEvent;
36import com.jogamp.newt.event.WindowAdapter;
37import com.jogamp.newt.opengl.GLWindow;
38import com.jogamp.opengl.test.junit.util.MiscUtils;
39import com.jogamp.opengl.test.junit.util.NewtTestUtil;
40import com.jogamp.opengl.test.junit.util.UITestCase;
41import com.jogamp.opengl.test.junit.util.QuitAdapter;
43import com.jogamp.opengl.util.Animator;
44import com.jogamp.opengl.util.FPSAnimator;
45import com.jogamp.opengl.util.GLReadBufferUtil;
46import com.jogamp.opengl.util.texture.TextureIO;
47import com.jogamp.opengl.test.junit.jogl.demos.GLFinishOnDisplay;
48import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
49import com.jogamp.opengl.test.junit.jogl.demos.es2.Mix2TexturesES2;
50import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2;
51import com.jogamp.common.util.InterruptSource;
52import com.jogamp.nativewindow.NativeSurface;
53import com.jogamp.nativewindow.SurfaceUpdatedListener;
54import com.jogamp.opengl.GL;
55import com.jogamp.opengl.GLAutoDrawable;
56import com.jogamp.opengl.GLCapabilities;
57import com.jogamp.opengl.GLCapabilitiesImmutable;
58import com.jogamp.opengl.GLContext;
59import com.jogamp.opengl.GLDrawableFactory;
60import com.jogamp.opengl.GLEventListener;
61import com.jogamp.opengl.GLOffscreenAutoDrawable;
62import com.jogamp.opengl.GLProfile;
64import org.junit.Assert;
65import org.junit.AfterClass;
67import org.junit.FixMethodOrder;
68import org.junit.runners.MethodSorters;
98@FixMethodOrder(MethodSorters.NAME_ASCENDING)
100 static long duration = 500;
101 static int swapInterval = 1;
102 static boolean showFPS =
false;
103 static boolean forceES2 =
false;
104 static boolean mainRun =
false;
112 System.err.println(
"requested: vsync "+swapInterval+
", "+caps);
115 Assert.assertNotNull(glWindow);
116 glWindow.
setTitle(
"Gears NEWT Test (translucent "+!caps.isBackgroundOpaque()+
"), swapInterval "+swapInterval);
126 final int fbod1_texUnit = 0;
127 final int fbod2_texUnit = 1;
139 fbod1.setUpstreamWidget(glWindow);
140 fbod1.setTextureUnit(fbod1_texUnit);
143 fbod1.addGLEventListener(demo0);
149 public void surfaceUpdated(
final Object updater,
final NativeSurface ns,
final long when) {
153 System.err.println(
"FBOD1 "+fbod1);
154 Assert.assertTrue(fbod1.isInitialized());
160 fbod2.setTextureUnit(fbod2_texUnit);
165 public void surfaceUpdated(
final Object updater,
final NativeSurface ns,
final long when) {
169 System.err.println(
"FBOD2 "+fbod2);
170 Assert.assertTrue(fbod2.isInitialized());
192 System.err.println(
"XXX: "+dw+
"x"+dh+
", c "+c);
194 snapshot(i++,
"msaa"+fbod1.getNumSamples(), drawable.
getGL(), screenshot,
TextureIO.
PNG,
null);
198 new InterruptSource.Thread() {
201 glWindow.
setSize(dw+256, dh+256);
207 public void reshape(
final GLAutoDrawable drawable,
final int x,
final int y,
final int width,
final int height) {
208 fbod1.setSurfaceSize(width, height);
209 fbod2.setSurfaceSize(width, height);
214 animator0.
add(fbod1);
215 animator0.
add(fbod2);
218 animator1.
add(glWindow);
251 while(!quitAdapter.shouldQuit() && animator1.isAnimating() && animator1.
getTotalFPSDuration()<duration) {
256 Assert.assertFalse(animator0.isAnimating());
257 Assert.assertFalse(animator0.
isStarted());
260 Assert.assertFalse(animator1.isAnimating());
261 Assert.assertFalse(animator1.
isStarted());
271 public void test01() throws InterruptedException {
277 public static void main(
final String args[])
throws IOException {
278 boolean waitForKey =
false;
282 for(
int i=0; i<args.length; i++) {
283 if(args[i].equals(
"-time")) {
286 }
else if(args[i].equals(
"-vsync")) {
289 }
else if(args[i].equals(
"-es2")) {
291 }
else if(args[i].equals(
"-showFPS")) {
293 }
else if(args[i].equals(
"-wait")) {
295 }
else if(args[i].equals(
"-nomain")) {
300 System.err.println(
"swapInterval "+swapInterval);
301 System.err.println(
"forceES2 "+forceES2);
304 final BufferedReader stdin =
new BufferedReader(
new InputStreamReader(System.in));
305 System.err.println(
"Press enter to continue");
307 System.err.println(stdin.readLine());
308 }
catch (
final IOException e) { }
void setAlphaBits(final int alphaBits)
Sets the number of bits requested for the color buffer's alpha component.
NEWT Window events are provided for notification purposes ONLY.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
final void setTitle(final String title)
final int getX()
Returns the current x position of this window, relative to it's parent.
final void addKeyListener(final KeyListener l)
Appends the given com.jogamp.newt.event.KeyListener to the end of the list.
final int getY()
Returns the current y position of the top-left corner of the client area relative to it's parent in w...
final int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
final void addWindowListener(final WindowListener l)
Appends the given com.jogamp.newt.event.WindowListener to the end of the list.
final CapabilitiesImmutable getChosenCapabilities()
Gets an immutable set of chosen capabilities.
final InsetsImmutable getInsets()
Returns the insets defined as the width and height of the window decoration on the left,...
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
final Window getDelegatedWindow()
If the implementation uses delegation, return the delegated Window instance, otherwise return this in...
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Specifies a set of OpenGL capabilities.
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.
Specifies the the OpenGL profile.
static final String GLES2
The embedded OpenGL profile ES 2.x, with x >= 0.
static GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
static GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
Toolkit agnostic GLOffscreenAutoDrawable.FBO tests using the factory model.
void runTestGL(final GLCapabilitiesImmutable caps)
static void releaseClass()
static void main(final String args[])
void setIgnoreFocus(final boolean v)
void setTexID1(final int texID)
void setTexID0(final int texID)
static int atoi(final String str, final int def)
static long atol(final String str, final long def)
static boolean waitForRealized(final Screen screen, final boolean realized, final Runnable waitAction)
final long getTotalFPSDuration()
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
final void setUpdateFPSFrames(final int frames, final PrintStream out)
synchronized boolean isStarted()
Indicates whether this animator has been started.
final synchronized boolean start()
Starts this animator, if not running.
final synchronized boolean stop()
Stops this animator.
An Animator subclass which attempts to achieve a target frames-per-second rate to avoid using all CPU...
final synchronized boolean start()
Starts this animator, if not running.
final synchronized boolean stop()
Stops this FPSAnimator.
Utility to read out the current FB to TextureData, optionally writing the data back to a texture obje...
static final String PNG
Constant which can be used as a file suffix to indicate a PNG file, value {@value}.
Provides low-level information required for hardware-accelerated rendering using a surface in a platf...
Clients may add their SurfaceUpdateListener implementation to a com.jogamp.nativewindow....
CapabilitiesImmutable getChosenCapabilities()
Gets an immutable set of chosen capabilities.
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Specifies an immutable set of OpenGL capabilities.
int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.
FBObject based GLOffscreenAutoDrawable specialization
Platform-independent GLAutoDrawable specialization, exposing offscreen functionality.
void setSharedAutoDrawable(GLAutoDrawable sharedAutoDrawable)
Specifies an GLAutoDrawable, which OpenGL context shall be shared by this GLAutoDrawable's GLContext.
static final int GL_FRONT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_FRONT" with expressio...