28package com.jogamp.opengl.test.junit.jogl.acore;
31import java.util.Locale;
33import com.jogamp.nativewindow.util.Dimension;
34import com.jogamp.nativewindow.util.DimensionImmutable;
35import com.jogamp.opengl.GL;
36import com.jogamp.opengl.GLAutoDrawable;
37import com.jogamp.opengl.GLCapabilitiesImmutable;
38import com.jogamp.opengl.GLEventListener;
39import com.jogamp.opengl.GLProfile;
41import org.junit.Assume;
42import org.junit.BeforeClass;
43import org.junit.FixMethodOrder;
44import org.junit.runners.MethodSorters;
46import com.jogamp.common.util.VersionUtil;
47import com.jogamp.newt.opengl.GLWindow;
48import com.jogamp.opengl.JoglVersion;
49import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
50import com.jogamp.opengl.test.junit.jogl.demos.es2.MultisampleDemoES2;
51import com.jogamp.opengl.test.junit.util.MiscUtils;
52import com.jogamp.opengl.util.Animator;
53import com.jogamp.opengl.util.GLDrawableUtil;
54import com.jogamp.opengl.util.GLReadBufferUtil;
55import com.jogamp.opengl.util.texture.TextureIO;
64@FixMethodOrder(MethodSorters.NAME_ASCENDING)
74 if( skipGLOrientationVerticalFlip || useSwingDoubleBuffer ) {
80 final SnapshotGLEL snapshotGLEL = doSnapshot ?
new SnapshotGLEL(textRendererGLEL, glReadBufferUtil) :
null;
88 System.err.println(VersionUtil.getPlatformInfo());
89 System.err.println(
"GLEventListener init on "+Thread.currentThread());
91 System.err.println(
"INIT GL IS: " + gl.getClass().getName());
99 public void reshape(
final GLAutoDrawable drawable,
final int x,
final int y,
final int width,
final int height) {}
117 }
catch(
final Throwable throwable ) {
118 throwable.printStackTrace();
119 Assume.assumeNoException( throwable );
125 for(
int i=0; i<3; i++) {
126 final String str =
"Frame# "+textRendererGLEL.
frameNo+
", user #"+(i+1);
127 System.err.println(str);
131 textRendererGLEL.userCounter = i + 1;
134 try { Thread.sleep(duration); }
catch (
final InterruptedException e) { }
136 try { Thread.sleep(duration); }
catch (
final InterruptedException e) { }
138 try { Thread.sleep(duration); }
catch (
final InterruptedException e) { }
140 try { Thread.sleep(duration); }
catch (
final InterruptedException e) { }
147 try { Thread.sleep(2*duration); }
catch (
final InterruptedException e) { }
149 }
catch (
final Exception e1) {
150 e1.printStackTrace();
156 final TextRendererGLEL textRendererGLEL;
158 boolean defAutoSwapMode;
159 boolean swapBuffersBeforeRead;
162 SnapshotGLEL(
final TextRendererGLEL textRendererGLEL,
final GLReadBufferUtil glReadBufferUtil) {
163 this.textRendererGLEL = textRendererGLEL;
164 this.glReadBufferUtil = glReadBufferUtil;
165 this.defAutoSwapMode =
true;
166 this.swapBuffersBeforeRead =
false;
181 public void reshape(
final GLAutoDrawable drawable,
final int x,
final int y,
final int width,
final int height) { }
184 snapshot(i++, drawable, TextureIO.PNG,
null);
186 public void snapshot(
final int sn,
final GLAutoDrawable drawable,
final String fileSuffix,
final String destPath) {
187 final GL gl = drawable.getGL();
188 final String postSNDetail = String.format((Locale)
null,
"jgl-usr%03d", textRendererGLEL.userCounter);
189 final String filenameJGL = getSnapshotFilename(sn, postSNDetail,
190 drawable.getChosenGLCapabilities(), drawable.getSurfaceWidth(), drawable.getSurfaceHeight(),
191 glReadBufferUtil.
hasAlpha(), fileSuffix, destPath);
192 if( swapBuffersBeforeRead ) {
193 drawable.swapBuffers();
196 gl.glClear(GL.GL_COLOR_BUFFER_BIT);
200 final boolean mustFlipVertically = !drawable.isGLOriented();
201 System.err.println(Thread.currentThread().getName()+
": ** screenshot: v-flip "+mustFlipVertically+
", swapBuffersBeforeRead "+swapBuffersBeforeRead+
", "+filenameJGL);
203 if(glReadBufferUtil.
readPixels(gl, mustFlipVertically)) {
204 glReadBufferUtil.
write(
new File(filenameJGL));
209 static GLCapabilitiesImmutable caps =
null;
210 static boolean doSnapshot =
true;
211 static boolean keyFrame =
false;
213 public static void main(
final String[] args) {
214 for(
int i=0; i<args.length; i++) {
215 if(args[i].equals(
"-time")) {
218 }
else if(args[i].equals(
"-keyFrame")) {
220 }
else if(args[i].equals(
"-noSnapshot")) {
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 setPosition(final int x, final int y)
Sets the location of the window's client area excluding insets (window decorations) in window units.
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 destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Specifies the the OpenGL profile.
static void initSingleton()
Static initialization of JOGL.
static StringBuilder getGLStrings(final GL gl, final StringBuilder sb)
void setFlipVerticalInGLOrientation(final boolean v)
Test synchronous GLAutoDrawable display, swap-buffer and read-pixels including non-MSAA and MSAA fram...
Test synchronous GLAutoDrawable display, swap-buffer and read-pixels with NEWT including non-MSAA and...
static void main(final String[] args)
void test(final GLCapabilitiesImmutable caps, final boolean useSwingDoubleBuffer, final boolean skipGLOrientationVerticalFlip)
GearsES2 setVerbose(final boolean v)
void setClearBuffers(final boolean v)
static long atol(final String str, final long def)
final synchronized boolean start()
Starts this animator, if not running.
final synchronized boolean stop()
Stops this animator.
Providing utility functions dealing w/ GLDrawables, GLAutoDrawable and their GLEventListener.
static final boolean swapBuffersBeforeRead(final GLCapabilitiesImmutable chosenCaps)
Determines whether the chosen GLCapabilitiesImmutable requires a swap-buffers before reading pixels.
Utility to read out the current FB to TextureData, optionally writing the data back to a texture obje...
void write(final File dest)
Write the TextureData filled by readPixels(GLAutoDrawable, boolean) to file.
boolean readPixels(final GL gl, final boolean mustFlipVertically)
Read the drawable's pixels to TextureData and Texture, if requested at construction.
Immutable Dimension Interface, consisting of it's read only components:
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GLEventListener disposeGLEventListener(GLEventListener listener, boolean remove)
Disposes the given listener via dispose(..) if it has been initialized and added to this queue.
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
boolean getAutoSwapBufferMode()
Indicates whether automatic buffer swapping is enabled for this drawable.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
void setAutoSwapBufferMode(boolean enable)
Enables or disables automatic buffer swapping for this drawable.
Specifies an immutable set of OpenGL capabilities.
boolean getSampleBuffers()
Returns whether sample buffers for full-scene antialiasing (FSAA) should be allocated for this drawab...
GLProfile getGLProfile()
Returns the GL profile you desire or used by the drawable.
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.