29package com.jogamp.opengl.test.junit.jogl.demos.es2.awt;
31import java.awt.AWTException;
32import java.awt.BorderLayout;
33import java.awt.Component;
34import java.awt.Container;
35import java.awt.event.ComponentAdapter;
36import java.awt.event.ComponentEvent;
37import java.lang.reflect.InvocationTargetException;
38import java.nio.FloatBuffer;
40import com.jogamp.opengl.GLAnimatorControl;
41import com.jogamp.opengl.GLCapabilities;
42import com.jogamp.opengl.GLCapabilitiesImmutable;
43import com.jogamp.opengl.GLEventListener;
44import com.jogamp.opengl.GLProfile;
45import com.jogamp.opengl.awt.GLJPanel;
46import javax.swing.JComponent;
47import javax.swing.JFrame;
48import javax.swing.JPanel;
49import javax.swing.JTextField;
50import javax.swing.SwingUtilities;
52import org.junit.AfterClass;
53import org.junit.Assert;
54import org.junit.BeforeClass;
56import org.junit.FixMethodOrder;
57import org.junit.runners.MethodSorters;
59import com.jogamp.common.nio.Buffers;
60import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
61import com.jogamp.opengl.test.junit.jogl.demos.gl2.Gears;
62import com.jogamp.opengl.test.junit.util.MiscUtils;
63import com.jogamp.opengl.test.junit.util.QuitAdapter;
64import com.jogamp.opengl.test.junit.util.UITestCase;
65import com.jogamp.opengl.util.FPSAnimator;
66import com.jogamp.opengl.util.awt.AWTGLPixelBuffer.SingleAWTGLPixelBufferProvider;
68@FixMethodOrder(MethodSorters.NAME_ASCENDING)
70 static int demoCount = 4;
71 static boolean jOpaque =
false;
72 static boolean glOpaque =
true;
73 static float glAlpha = 0.3f;
74 static boolean jZOrder =
false;
76 static boolean shallUsePBuffer =
false;
77 static boolean shallUseBitmap =
false;
78 static boolean useMSAA =
false;
79 static int swapInterval = 0;
80 static boolean useAnimator =
true;
81 static boolean manualTest =
false;
82 static boolean initSingleBuffer =
false;
95 Assert.assertNotNull(glp);
97 setTestSupported(
false);
100 if( initSingleBuffer ) {
102 singleAWTGLPixelBufferProvider.
initSingleton(
null, 4,
true, 600, 600, 1);
104 singleAWTGLPixelBufferProvider =
null;
112 final static boolean useInterPanel =
true;
115 private JComponent addPanel(
final GLCapabilitiesImmutable caps,
final GLAnimatorControl anim,
final JFrame frame,
final boolean opaque,
final int x,
final int y,
final int w,
final int h,
final FloatBuffer color,
final float[] clearColor)
116 throws InterruptedException, InvocationTargetException
119 if( initSingleBuffer ) {
123 if ( !useInterPanel ) {
124 canvas.setBounds(x, y, w, h);
127 if( caps.isBitmap() ) {
128 demo =
new Gears(swapInterval);
130 final GearsES2 gdemo =
new GearsES2(swapInterval);
131 gdemo.setIgnoreFocus(
true);
132 gdemo.setGearsColors(color, color, color);
133 gdemo.setClearColor(clearColor);
142 final JTextField text;
143 if ( useInterPanel ) {
144 panel =
new JPanel(
new BorderLayout());
145 panel.setBounds(x, y, w, h);
146 panel.setOpaque(opaque);
147 text =
new JTextField(x+
"/"+y+
" "+w+
"x"+h);
148 text.setOpaque(
true);
154 SwingUtilities.invokeAndWait(
new Runnable() {
156 if ( useInterPanel ) {
157 panel.add(text, BorderLayout.NORTH);
158 panel.add(canvas, BorderLayout.CENTER);
159 frame.getContentPane().add(panel, 0);
161 frame.getContentPane().add(canvas, 0);
164 return useInterPanel ? panel : canvas;
167 public static final FloatBuffer red = Buffers.newDirectFloatBuffer(
new float[] { 1.0f, 0.0f, 0.0f, 1.0f } );
168 public static final FloatBuffer green = Buffers.newDirectFloatBuffer(
new float[] { 0.0f, 1.0f, 0.0f, 1.0f } );
169 public static final FloatBuffer blue = Buffers.newDirectFloatBuffer(
new float[] { 0.0f, 0.0f, 1.0f, 1.0f } );
170 public static final FloatBuffer yellow = Buffers.newDirectFloatBuffer(
new float[] { 1.0f, 1.0f, 0.0f, 1.0f } );
171 public static final FloatBuffer grey = Buffers.newDirectFloatBuffer(
new float[] { 0.5f, 0.5f, 0.5f, 1.0f } );
172 public static final float grayf = 0.3f;
173 public static final float[] redish =
new float[] { grayf, 0.0f, 0.0f, glAlpha };
174 public static final float[] greenish =
new float[] { 0.0f, grayf, 0.0f, glAlpha };
175 public static final float[] blueish =
new float[] { 0.0f, 0.0f, grayf, glAlpha };
176 public static final float[] yellowish =
new float[] { grayf, grayf, 0.0f, glAlpha };
177 public static final float[] greyish =
new float[] { grayf, grayf, grayf, glAlpha };
179 protected void relayout(
final Container cont,
final float oW,
final float oH) {
180 final int count = cont.getComponentCount();
181 final int nW = cont.getWidth();
182 final int nH = cont.getHeight();
183 for(
int i = 0 ; i < count; i++ ) {
184 final Component comp = cont.getComponent(i);
185 final float fx = comp.getX() / oW;
186 final float fy = comp.getY() / oH;
187 final float fw = comp.getWidth() / oW;
188 final float fh = comp.getHeight() / oH;
189 comp.setBounds( (
int)(fx * nW), (
int)(fy * nH), (
int)(fw * nW), (
int)(fh * nH) );
194 throws AWTException, InterruptedException, InvocationTargetException
197 caps.setAlphaBits(caps.getRedBits());
200 final JFrame frame =
new JFrame(
"Swing GLJPanel");
201 Assert.assertNotNull(frame);
205 SwingUtilities.invokeAndWait(
new Runnable() {
207 frame.getContentPane().setLayout(
null);
210 final float[] oldSize =
new float[] { 600f, 600f };
212 frame.addComponentListener(
new ComponentAdapter() {
214 public void componentResized(
final ComponentEvent e) {
215 final int count = frame.getComponentCount();
216 for(
int i = 0 ; i < count; i++ ) {
217 relayout(frame.getContentPane(), oldSize[0], oldSize[1]);
219 frame.getContentPane().invalidate();
220 frame.getContentPane().validate();
222 oldSize[0] = frame.getContentPane().getWidth();
223 oldSize[1] = frame.getContentPane().getHeight();
227 if( demoCount > 0 ) {
228 addPanel(caps, animator, frame, jOpaque, 50, 50, 300, 300, red, redish);
230 if( demoCount > 1 ) {
231 addPanel(caps, animator, frame, jOpaque, 0, 250, 300, 300, blue, blueish);
233 if( demoCount > 2 ) {
234 addPanel(caps, animator, frame, jOpaque, 300, 0, 150, 150, green, greenish);
236 if( demoCount > 3 ) {
237 addPanel(caps, animator, frame, jOpaque, 300, 300, 100, 100, yellow, yellowish);
240 final Container cont = frame.getContentPane();
241 final int count = cont.getComponentCount();
242 for(
int i = 0 ; i < count; i++ ) {
243 cont.setComponentZOrder(cont.getComponent(i), count - 1 - i);
247 SwingUtilities.invokeAndWait(
new Runnable() {
249 frame.setSize((
int)oldSize[0], (
int)oldSize[1]);
250 frame.getContentPane().validate();
252 frame.setVisible(
true);
258 Assert.assertEquals(
true, animator.isAnimating());
263 final long t0 = System.currentTimeMillis();
265 while(!quitAdapter.shouldQuit() && t1 - t0 < duration) {
267 t1 = System.currentTimeMillis();
270 Assert.assertNotNull(frame);
271 Assert.assertNotNull(animator);
275 Assert.assertEquals(
false, animator.isAnimating());
277 SwingUtilities.invokeAndWait(
new Runnable() {
279 frame.setVisible(
false);
288 throws AWTException, InterruptedException, InvocationTargetException
295 if(shallUsePBuffer) {
306 throws AWTException, InterruptedException, InvocationTargetException
319 throws AWTException, InterruptedException, InvocationTargetException
331 throws AWTException, InterruptedException, InvocationTargetException
345 throws AWTException, InterruptedException, InvocationTargetException
357 throws AWTException, InterruptedException, InvocationTargetException
369 static long duration = 500;
371 public static void main(
final String args[]) {
372 for(
int i=0; i<args.length; i++) {
373 if(args[i].equals(
"-time")) {
376 }
else if(args[i].equals(
"-vsync")) {
379 }
else if(args[i].equals(
"-msaa")) {
381 }
else if(args[i].equals(
"-jOpaque")) {
384 }
else if(args[i].equals(
"-glOpaque")) {
387 }
else if(args[i].equals(
"-alpha")) {
390 }
else if(args[i].equals(
"-initSingleBuffer")) {
392 initSingleBuffer =
MiscUtils.
atob(args[i], initSingleBuffer);
393 }
else if(args[i].equals(
"-jZOrder")) {
395 }
else if(args[i].equals(
"-noanim")) {
397 }
else if(args[i].equals(
"-pbuffer")) {
398 shallUsePBuffer =
true;
399 }
else if(args[i].equals(
"-bitmap")) {
400 shallUseBitmap =
true;
401 }
else if(args[i].equals(
"-manual")) {
403 }
else if(args[i].equals(
"-demos")) {
408 System.err.println(
"swapInterval "+swapInterval);
409 System.err.println(
"opaque gl "+glOpaque+
", java/gljpanel "+jOpaque);
410 System.err.println(
"alpha "+glAlpha);
411 System.err.println(
"jZOrder "+jZOrder);
412 System.err.println(
"demos "+demoCount);
413 System.err.println(
"useMSAA "+useMSAA);
414 System.err.println(
"useAnimator "+useAnimator);
415 System.err.println(
"shallUsePBuffer "+shallUsePBuffer);
416 System.err.println(
"shallUseBitmap "+shallUseBitmap);
417 System.err.println(
"manualTest "+manualTest);
418 System.err.println(
"useSingleBuffer "+initSingleBuffer);
void setBitmap(final boolean enable)
Requesting offscreen bitmap mode.
Specifies a set of OpenGL capabilities.
void setPBuffer(final boolean enable)
Requesting offscreen pbuffer 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.
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 getDefault(final AbstractGraphicsDevice device)
Returns a default GLProfile object, reflecting the best for the running platform.
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.
final boolean isGL2ES3()
Indicates whether this profile is capable of GL2ES3.
A lightweight Swing component which provides OpenGL rendering support.
void setPixelBufferProvider(final AWTGLPixelBufferProvider custom)
void setOpaque(final boolean opaque)
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
static void releaseClass()
static void main(final String args[])
void test03_PbufferNorm()
void test02_DefaultMsaa()
void runTestGL(final GLCapabilities caps)
void test01_DefaultNorm()
void relayout(final Container cont, final float oW, final float oH)
void test04_PbufferMsaa()
static float atof(final String str, final float def)
static int atoi(final String str, final int def)
static long atol(final String str, final long def)
static boolean atob(final String str, final boolean def)
final void setUpdateFPSFrames(final int frames, final PrintStream out)
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.
Provider for singleton AWTGLPixelBuffer instances.
AWTGLPixelBuffer initSingleton(final GLProfile glp, final int componentCount, final boolean pack, final int width, final int height, final int depth)
Initializes the single AWTGLPixelBuffer w/ a given size, if not yet allocated.
An animator control interface, which implementation may drive a com.jogamp.opengl....
Specifies an immutable set of OpenGL capabilities.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.