29package com.jogamp.opengl.test.junit.jogl.acore;
31import java.awt.Dimension;
33import java.io.IOException;
35import com.jogamp.junit.util.JunitTracer;
36import com.jogamp.nativewindow.CapabilitiesImmutable;
37import com.jogamp.opengl.GLAutoDrawable;
38import com.jogamp.opengl.GLCapabilities;
39import com.jogamp.opengl.GLCapabilitiesImmutable;
40import com.jogamp.opengl.GLContext;
41import com.jogamp.opengl.GLDrawable;
42import com.jogamp.opengl.GLDrawableFactory;
43import com.jogamp.opengl.GLEventListener;
44import com.jogamp.opengl.GLProfile;
45import com.jogamp.opengl.awt.GLCanvas;
47import jogamp.nativewindow.jawt.JAWTUtil;
48import jogamp.opengl.GLGraphicsConfigurationUtil;
50import org.junit.Assert;
51import org.junit.Assume;
53import org.junit.FixMethodOrder;
54import org.junit.runners.MethodSorters;
56import com.jogamp.opengl.JoglVersion;
57import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
58import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
59import com.jogamp.opengl.test.junit.util.GLTestUtil;
60import com.jogamp.opengl.test.junit.util.UITestCase;
65@FixMethodOrder(MethodSorters.NAME_ASCENDING)
67 static final int widthStep = 800/4;
68 static final int heightStep = 600/4;
69 static boolean waitForKey =
false;
70 volatile int szStep = 2;
74 System.err.println(
"Profile "+profile+
" n/a");
80 static void setGLCanvasSize(
final Frame frame,
final GLCanvas glc,
final int width,
final int height) {
82 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
85 glc.setMinimumSize(new_sz);
86 glc.setPreferredSize(new_sz);
91 }
catch(
final Throwable throwable ) {
92 throwable.printStackTrace();
93 Assume.assumeNoException( throwable );
98 void setMakeSnapshot();
102 if(reqGLCaps.
isOnscreen() && JAWTUtil.isOffscreenLayerRequired()) {
103 System.err.println(
"onscreen layer n/a");
106 if(!reqGLCaps.
isOnscreen() && !JAWTUtil.isOffscreenLayerSupported()) {
107 System.err.println(
"offscreen layer n/a");
110 System.out.println(
"Requested GL Caps: "+reqGLCaps);
112 final GLCapabilitiesImmutable expGLCaps = GLGraphicsConfigurationUtil.fixGLCapabilities(reqGLCaps, factory,
null);
113 System.out.println(
"Expected GL Caps: "+expGLCaps);
118 Assert.assertNotNull(glad);
120 glad.setMinimumSize(glc_sz);
121 glad.setPreferredSize(glc_sz);
123 final Frame frame =
new Frame(getSimpleTestName(
"."));
124 Assert.assertNotNull(frame);
128 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
131 frame.setVisible(
true);
133 }
catch(
final Throwable throwable ) {
134 throwable.printStackTrace();
135 Assume.assumeNoException( throwable );
140 System.out.println(
"Window: "+glad.getClass().getName());
144 System.out.println(
"Window Caps Pre_GL: "+chosenCaps);
145 Assert.assertNotNull(chosenCaps);
158 Assert.assertNotNull(actualDrawable);
159 System.out.println(
"Drawable Pre-GL(0): "+actualDrawable.getClass().getName()+
", "+actualDrawable.
getNativeSurface().getClass().getName());
163 System.out.println(
"Drawable Post-GL(1): "+glad.getClass().getName()+
", "+glad.
getNativeSurface().getClass().getName());
167 System.out.println(
"Chosen GL Caps(1): "+chosenGLCaps);
168 Assert.assertNotNull(chosenGLCaps);
171 Assert.assertTrue(chosenGLCaps.
getRedBits()>5);
174 Assert.assertEquals(expGLCaps.
isFBO(), chosenGLCaps.
isFBO());
185 System.out.println(
"Chosen GL CTX (2): "+context.
getGLVersion());
186 Assert.assertNotNull(context);
191 System.out.println(
"Drawable Post-GL(2): "+glad.getClass().getName()+
", "+glad.
getNativeSurface().getClass().getName());
202 Assert.assertTrue(
"Surface Size not reached: Expected "+expSurfaceSize[0]+
"x"+expSurfaceSize[1]+
", Is "+glad.
getSurfaceWidth()+
"x"+glad.
getSurfaceHeight(),
209 setGLCanvasSize(frame, glad, widthStep*szStep, heightStep*szStep);
210 expSurfaceSize[0] = widthStep*szStep;
211 expSurfaceSize[1] = heightStep*szStep;
213 Assert.assertTrue(
"Surface Size not reached: Expected "+expSurfaceSize[0]+
"x"+expSurfaceSize[1]+
", Is "+glad.
getSurfaceWidth()+
"x"+glad.
getSurfaceHeight(),
221 setGLCanvasSize(frame, glad, widthStep*szStep, heightStep*szStep);
222 expSurfaceSize[0] = widthStep*szStep;
223 expSurfaceSize[1] = heightStep*szStep;
225 Assert.assertTrue(
"Surface Size not reached: Expected "+expSurfaceSize[0]+
"x"+expSurfaceSize[1]+
", Is "+glad.
getSurfaceWidth()+
"x"+glad.
getSurfaceHeight(),
234 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
236 frame.setVisible(
false);
240 }
catch(
final Throwable throwable ) {
241 throwable.printStackTrace();
242 Assume.assumeNoException( throwable );
244 System.out.println(
"Fin: "+glad);
250 if(
null == reqGLCaps)
return;
257 if(
null == reqGLCaps)
return;
265 if(
null == reqGLCaps)
return;
274 if(
null == reqGLCaps)
return;
284 if(
null == reqGLCaps)
return;
292 if(
null == reqGLCaps)
return;
302 if(
null == reqGLCaps)
return;
313 if(
null == reqGLCaps)
return;
325 if(
null == reqGLCaps)
return;
331 public static void main(
final String args[])
throws IOException {
332 for(
int i=0; i<args.length; i++) {
333 if(args[i].equals(
"-wait")) {
338 JunitTracer.waitForKey(
"Start");
void setOnscreen(final boolean onscreen)
Sets whether the surface shall be on- or offscreen.
Specifies a set of OpenGL capabilities.
void setPBuffer(final boolean enable)
Requesting offscreen pbuffer mode.
void setStencilBits(final int stencilBits)
Sets the number of bits requested for the stencil buffer.
void setFBO(final boolean enable)
Requesting offscreen FBO mode.
void setNumSamples(final int numSamples)
If sample buffers are enabled, indicates the number of buffers to be allocated.
void setSampleBuffers(final boolean enable)
Defaults to false.
Abstraction for an OpenGL rendering context.
final boolean isCreated()
Indicates whether the underlying native OpenGL context has been created.
final String getGLVersion()
Returns a valid OpenGL version string, ie
static GLDrawableFactory getFactory(final GLProfile glProfile)
Returns the sole GLDrawableFactory instance.
Specifies the the OpenGL profile.
static boolean isAvailable(final AbstractGraphicsDevice device, final String profile)
Returns the availability of a profile on a device.
static GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
static final String GL2
The desktop OpenGL profile 1.x up to 3.0.
A heavyweight AWT component which provides OpenGL rendering support.
GLContext getContext()
Returns the context associated with this drawable.
final GLDrawable getDelegatedDrawable()
If the implementation uses delegation, return the delegated GLDrawable instance, otherwise return thi...
int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
NativeSurface getNativeSurface()
Returns the associated NativeSurface of this NativeSurfaceHolder.Returns the underlying NativeSurface...
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
GLCapabilitiesImmutable getChosenGLCapabilities()
Fetches the GLCapabilitiesImmutable corresponding to the chosen OpenGL capabilities (pixel format / v...
Tests using an AWT GLCanvas auto drawable for on- and offscreen cases.
void testGL2OffScreenFBODblBufStencil()
void testGL2OffScreenFBODblBufStencilMSAA()
void testGL2OnScreenDblBufMSAA()
static void main(final String args[])
void testGL2OffScreenPbuffer()
void testGL2OffScreenFBODblBufMSAA()
void testGL2OffScreenAutoDblBuf()
void testGL2OnScreenDblBuf()
void testGL2OnScreenDblBufStencilMSAA()
void testGL2OnScreenDblBufStencil()
static boolean waitForVisible(final java.awt.Component comp, final boolean visible, final Runnable waitAction)
static boolean waitForRealized(final GLAutoDrawable glad, final boolean realized, final Runnable waitAction)
static boolean waitForSize(final GLDrawable drawable, final int width, final int height, final Runnable waitAction)
Specifies an immutable set of capabilities that a window's rendering context must support,...
int getBlueBits()
Returns the number of bits for the color buffer's blue component.
boolean isBitmap()
Returns whether bitmap offscreen mode is requested, available or chosen.
int getRedBits()
Returns the number of bits for the color buffer's red component.
int getGreenBits()
Returns the number of bits for the color buffer's green component.
boolean isOnscreen()
Returns whether an on- or offscreen surface is requested, available or chosen.
int[] convertToPixelUnits(final int[] windowUnitsAndResult)
Converts the given window units into pixel units in place.
Specifies an immutable set of OpenGL capabilities.
int getDepthBits()
Returns the number of depth buffer bits.
boolean isPBuffer()
Returns whether pbuffer offscreen mode is requested, available or chosen.
GLProfile getGLProfile()
Returns the GL profile you desire or used by the drawable.
boolean isFBO()
Returns whether FBO offscreen mode is requested, available or chosen.
An abstraction for an OpenGL rendering target.
NativeSurface getNativeSurface()
Returns the associated NativeSurface of this NativeSurfaceHolder.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.
void setSize(int width, int height)
Requests a new width and height for this AWTGLAutoDrawable.