Jogamp
NewtVersionActivity: Remove 'gears' test; Version Info: Drop NativeWindow/Newt Versio...
[jogl.git] / src / newt / classes / com / jogamp / newt / opengl / GLWindow.java
CommitLineData
a959c53b
KR
1/*
2 * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
0feca163 3 * Copyright (c) 2010 JogAmp Community. All rights reserved.
a959c53b
KR
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * - Redistribution of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * - Redistribution in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * Neither the name of Sun Microsystems, Inc. or the names of
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * This software is provided "AS IS," without a warranty of any kind. ALL
21 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
22 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
23 * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
24 * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
25 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
26 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
27 * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
28 * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
29 * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
30 * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
31 * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
32 *
33 */
34
2d57c252 35package com.jogamp.newt.opengl;
a959c53b 36
ea819ff7 37import java.io.PrintStream;
8adc0478
SG
38import java.util.List;
39
dac35658 40import com.jogamp.common.GlueGenVersion;
8c9f3bb3 41import com.jogamp.common.util.VersionUtil;
dac35658 42import com.jogamp.nativewindow.NativeWindowVersion;
2d57c252 43import com.jogamp.newt.*;
1ad8c39d 44import com.jogamp.newt.event.*;
360b6716 45import jogamp.newt.WindowImpl;
8adc0478 46
a959c53b 47import javax.media.nativewindow.*;
018c7e86 48import javax.media.nativewindow.util.Point;
8adc0478 49import javax.media.nativewindow.util.Insets;
a959c53b 50import javax.media.opengl.*;
8adc0478 51
ea819ff7 52import jogamp.opengl.FPSCounterImpl;
360b6716 53import jogamp.opengl.GLDrawableHelper;
dac35658 54import com.jogamp.opengl.JoglVersion;
a959c53b
KR
55
56/**
0feca163
SG
57 * An implementation of {@link javax.media.opengl.GLAutoDrawable} interface,
58 * using an aggregation of a {@link com.jogamp.newt.Window} implementation.
2268a6ce
SG
59 * <P>
60 * This implementation does not make the OpenGL context current<br>
0feca163
SG
61 * before calling the various input EventListener callbacks, ie {@link com.jogamp.newt.event.MouseListener} etc.<br>
62 * This design decision is made in favor of a more performant and simplified
63 * implementation. Also the event dispatcher shall be implemented OpenGL agnostic.<br>
64 * To be able to use OpenGL commands from within such input {@link com.jogamp.newt.event.NEWTEventListener},<br>
65 * you can inject {@link javax.media.opengl.GLRunnable} objects
66 * via {@link #invoke(boolean, javax.media.opengl.GLRunnable)} to the OpenGL command stream.<br>
2268a6ce 67 * <p>
a959c53b 68 */
ea819ff7 69public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer, FPSCounter {
0feca163 70 private WindowImpl window;
a959c53b 71
476d1d75
MB
72 /**
73 * Constructor. Do not call this directly -- use {@link #create()} instead.
74 */
811bd23e 75 protected GLWindow(Window window) {
ea819ff7 76 resetFPSCounter();
0feca163
SG
77 this.window = (WindowImpl) window;
78 ((WindowImpl)this.window).setHandleDestroyNotify(false);
1ad8c39d 79 window.addWindowListener(new WindowAdapter() {
10c696f7 80 @Override
969e4276 81 public void windowRepaint(WindowUpdateEvent e) {
e587f2a7 82 if( !GLWindow.this.window.isWindowLockedByOtherThread() && !GLWindow.this.helper.isExternalAnimatorAnimating() ) {
969e4276
SG
83 display();
84 }
85 }
86
10c696f7 87 @Override
a959c53b
KR
88 public void windowResized(WindowEvent e) {
89 sendReshape = true;
e587f2a7 90 if( !GLWindow.this.window.isWindowLockedByOtherThread() && !GLWindow.this.helper.isExternalAnimatorAnimating() ) {
969e4276
SG
91 display();
92 }
a959c53b
KR
93 }
94
10c696f7 95 @Override
a959c53b 96 public void windowDestroyNotify(WindowEvent e) {
2cbab63b
SG
97 if( DISPOSE_ON_CLOSE == GLWindow.this.getDefaultCloseOperation() ) {
98 // Is an animator thread perform rendering?
99 if (GLWindow.this.helper.isExternalAnimatorRunning()) {
100 // Pause animations before initiating safe destroy.
101 GLAnimatorControl ctrl = GLWindow.this.helper.getAnimator();
102 boolean isPaused = ctrl.pause();
103 destroy();
104 if(isPaused) {
105 ctrl.resume();
106 }
e587f2a7
SG
107 } else if (GLWindow.this.window.isWindowLockedByOtherThread()) {
108 // Window is locked by another thread
2cbab63b
SG
109 // Flag that destroy should be performed on the next
110 // attempt to display.
111 sendDestroy = true;
112 } else {
113 // Without an external thread animating or locking the
114 // surface, we are safe.
115 destroy ();
4c3e9e25 116 }
5ece52d5 117 }
a959c53b
KR
118 }
119 });
0feca163 120 this.window.setLifecycleHook(new GLLifecycleHook());
a959c53b
KR
121 }
122
0feca163
SG
123 /**
124 * Creates a new GLWindow attaching a new Window referencing a new Screen
125 * with the given GLCapabilities.
126 * <P>
127 * The resulting GLWindow owns the Window, Screen and Device, ie it will be destructed.
128 */
29e3b223 129 public static GLWindow create(GLCapabilitiesImmutable caps) {
0feca163 130 return new GLWindow(NewtFactory.createWindow(caps));
a959c53b
KR
131 }
132
0feca163
SG
133 /**
134 * Creates a new GLWindow attaching a new Window referencing the given Screen
135 * with the given GLCapabilities.
136 * <P>
137 * The resulting GLWindow owns the Window, ie it will be destructed.
138 */
29e3b223 139 public static GLWindow create(Screen screen, GLCapabilitiesImmutable caps) {
0feca163 140 return new GLWindow(NewtFactory.createWindow(screen, caps));
a959c53b
KR
141 }
142
0feca163
SG
143 /**
144 * Creates a new GLWindow attaching the given window.
145 * <P>
146 * The resulting GLWindow does not own the given Window, ie it will not be destructed.
147 */
148 public static GLWindow create(Window window) {
811bd23e 149 return new GLWindow(window);
a959c53b 150 }
6e599a26 151
0feca163
SG
152 /**
153 * Creates a new GLWindow attaching a new child Window
154 * of the given <code>parentNativeWindow</code> with the given GLCapabilities.
155 * <P>
156 * The Display/Screen will be compatible with the <code>parentNativeWindow</code>,
157 * or even identical in case it's a Newt Window.
158 * <P>
159 * The resulting GLWindow owns the Window, ie it will be destructed.
160 */
29e3b223 161 public static GLWindow create(NativeWindow parentNativeWindow, GLCapabilitiesImmutable caps) {
0feca163 162 return new GLWindow(NewtFactory.createWindow(parentNativeWindow, caps));
a959c53b 163 }
a959c53b 164
0feca163 165 //----------------------------------------------------------------------
2cbab63b
SG
166 // WindowClosingProtocol implementation
167 //
168 public int getDefaultCloseOperation() {
169 return window.getDefaultCloseOperation();
170 }
171
172 public int setDefaultCloseOperation(int op) {
173 return window.setDefaultCloseOperation(op);
174 }
175
176 //----------------------------------------------------------------------
0feca163
SG
177 // Window Access
178 //
a959c53b 179
7c159772
SG
180 public CapabilitiesChooser setCapabilitiesChooser(CapabilitiesChooser chooser) {
181 return window.setCapabilitiesChooser(chooser);
182 }
183
e4913066 184 public final CapabilitiesImmutable getChosenCapabilities() {
0feca163
SG
185 if (drawable == null) {
186 return window.getChosenCapabilities();
811bd23e 187 }
811bd23e 188
0feca163 189 return drawable.getChosenGLCapabilities();
a959c53b
KR
190 }
191
e4913066 192 public final CapabilitiesImmutable getRequestedCapabilities() {
0feca163 193 return window.getRequestedCapabilities();
811bd23e
SG
194 }
195
0feca163
SG
196 public final Window getWindow() {
197 return window;
811bd23e
SG
198 }
199
018c7e86
SG
200 public final NativeWindow getParent() {
201 return window.getParent();
811bd23e
SG
202 }
203
0feca163 204 public final Screen getScreen() {
a959c53b
KR
205 return window.getScreen();
206 }
207
0feca163 208 public final void setTitle(String title) {
a959c53b
KR
209 window.setTitle(title);
210 }
211
0feca163 212 public final String getTitle() {
a959c53b
KR
213 return window.getTitle();
214 }
215
0feca163 216 public final void setUndecorated(boolean value) {
a959c53b
KR
217 window.setUndecorated(value);
218 }
219
0feca163 220 public final boolean isUndecorated() {
a959c53b
KR
221 return window.isUndecorated();
222 }
223
0feca163 224 public final void setFocusAction(FocusRunnable focusAction) {
a4b16ad5
SG
225 window.setFocusAction(focusAction);
226 }
0feca163
SG
227
228 public final void requestFocus() {
229 window.requestFocus();
811bd23e
SG
230 }
231
609e3083
SG
232 public boolean hasFocus() {
233 return window.hasFocus();
234 }
235
0feca163
SG
236 public final Insets getInsets() {
237 return window.getInsets();
811bd23e 238 }
a959c53b 239
0feca163 240 public final void setPosition(int x, int y) {
a959c53b
KR
241 window.setPosition(x, y);
242 }
7bed517f 243
0feca163 244 public final boolean setFullscreen(boolean fullscreen) {
a959c53b
KR
245 return window.setFullscreen(fullscreen);
246 }
0feca163
SG
247
248 public final boolean isFullscreen() {
249 return window.isFullscreen();
811bd23e 250 }
a959c53b 251
0feca163 252 public final boolean isVisible() {
a959c53b
KR
253 return window.isVisible();
254 }
255
10c696f7 256 @Override
0feca163
SG
257 public final String toString() {
258 return "NEWT-GLWindow[ \n\tHelper: " + helper + ", \n\tDrawable: " + drawable +
259 ", \n\tContext: " + context + /** ", \n\tWindow: "+window+", \n\tFactory: "+factory+ */ "]";
a959c53b
KR
260 }
261
0feca163
SG
262 public final int reparentWindow(NativeWindow newParent) {
263 return window.reparentWindow(newParent);
a959c53b
KR
264 }
265
0feca163
SG
266 public final int reparentWindow(NativeWindow newParent, boolean forceDestroyCreate) {
267 return window.reparentWindow(newParent, forceDestroyCreate);
a959c53b
KR
268 }
269
0feca163
SG
270 public final void removeChild(NativeWindow win) {
271 window.removeChild(win);
a959c53b
KR
272 }
273
0feca163
SG
274 public final void addChild(NativeWindow win) {
275 window.addChild(win);
a959c53b 276 }
2aa29677 277
0feca163
SG
278 //----------------------------------------------------------------------
279 // Window.LifecycleHook Implementation
280 //
969e4276 281
db4d7d19
SG
282 public final void destroy() {
283 window.destroy();
bf584fba
SG
284 }
285
0feca163
SG
286 public final void setVisible(boolean visible) {
287 window.setVisible(visible);
a959c53b
KR
288 }
289
0feca163
SG
290 public final void setSize(int width, int height) {
291 window.setSize(width, height);
a959c53b
KR
292 }
293
0feca163
SG
294 public final boolean isValid() {
295 return window.isValid();
969e4276 296 }
a959c53b 297
0feca163
SG
298 public final boolean isNativeValid() {
299 return window.isNativeValid();
a959c53b
KR
300 }
301
018c7e86
SG
302 public Point getLocationOnScreen(Point storage) {
303 return window.getLocationOnScreen(storage);
304 }
305
0feca163
SG
306 // Hide methods here ..
307 protected class GLLifecycleHook implements WindowImpl.LifecycleHook {
308
3747f6a6
SG
309 private class DisposeAction implements Runnable {
310 public final void run() {
0feca163
SG
311 // Lock: Covered by DestroyAction ..
312 helper.dispose(GLWindow.this);
313 }
314 }
315 DisposeAction disposeAction = new DisposeAction();
316
db4d7d19
SG
317 public synchronized void destroyActionPreLock() {
318 // nop
e6225fce
SG
319 }
320
db4d7d19 321 public synchronized void destroyActionInLock() {
0feca163 322 if(Window.DEBUG_WINDOW_EVENT || Window.DEBUG_IMPLEMENTATION) {
10c696f7 323 String msg = "GLWindow.destroy() "+Thread.currentThread()+", start";
0feca163
SG
324 System.err.println(msg);
325 //Exception e1 = new Exception(msg);
326 //e1.printStackTrace();
327 }
328
329 if( window.isNativeValid() && null != drawable && drawable.isRealized() ) {
330 if( null != context && context.isCreated() ) {
331 // Catch dispose GLExceptions by GLEventListener, just 'print' them
332 // so we can continue with the destruction.
333 try {
334 helper.invokeGL(drawable, context, disposeAction, null);
335 } catch (GLException gle) {
336 gle.printStackTrace();
337 }
338 context.destroy();
339 }
340 drawable.setRealized(false);
341 }
342 context = null;
343 drawable = null;
f47230cb
SG
344
345 GLAnimatorControl ctrl = GLWindow.this.getAnimator();
346 if ( null!=ctrl ) {
347 ctrl.remove(GLWindow.this);
348 }
349 // helper=null; // pending events ..
350
db4d7d19
SG
351 if(Window.DEBUG_WINDOW_EVENT || Window.DEBUG_IMPLEMENTATION) {
352 System.err.println("GLWindow.destroy() "+Thread.currentThread()+", fin");
0feca163 353 }
db4d7d19 354 }
0feca163 355
2c1a870f 356 public synchronized void resetCounter() {
0feca163 357 if(Window.DEBUG_WINDOW_EVENT || Window.DEBUG_IMPLEMENTATION) {
2c1a870f
SG
358 System.err.println("GLWindow.resetCounter() "+Thread.currentThread());
359 }
ea819ff7 360 GLWindow.this.resetFPSCounter();
2c1a870f
SG
361 }
362
363 public synchronized void setVisibleActionPost(boolean visible, boolean nativeWindowCreated) {
364 if(Window.DEBUG_WINDOW_EVENT || Window.DEBUG_IMPLEMENTATION) {
10c696f7 365 String msg = "GLWindow.setVisibleActionPost("+visible+", "+nativeWindowCreated+") "+Thread.currentThread()+", start";
0feca163
SG
366 System.err.println(msg);
367 // Exception e1 = new Exception(msg);
368 // e1.printStackTrace();
369 }
370
371 /* if (nativeWindowCreated && null != context) {
372 throw new GLException("InternalError: Native Windows has been just created, but context wasn't destroyed (is not null)");
373 } */
374 if (null == context && visible && 0 != window.getWindowHandle() && 0<getWidth()*getHeight()) {
375 NativeWindow nw;
376 if (window.getWrappedWindow() != null) {
377 nw = NativeWindowFactory.getNativeWindow(window.getWrappedWindow(), window.getGraphicsConfiguration());
378 } else {
379 nw = window;
380 }
29e3b223 381 GLCapabilitiesImmutable glCaps = (GLCapabilitiesImmutable) nw.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities();
0feca163
SG
382 if(null==factory) {
383 factory = GLDrawableFactory.getFactory(glCaps.getGLProfile());
384 }
385 if(null==drawable) {
386 drawable = factory.createGLDrawable(nw);
387 }
388 drawable.setRealized(true);
fd0d3f15 389 context = drawable.createContext(sharedContext);
6c0ad949 390 context.setContextCreationFlags(additionalCtxCreationFlags);
0feca163
SG
391 }
392 if(Window.DEBUG_WINDOW_EVENT || Window.DEBUG_IMPLEMENTATION) {
10c696f7 393 String msg = "GLWindow.setVisibleActionPost("+visible+", "+nativeWindowCreated+") "+Thread.currentThread()+", fin";
0feca163
SG
394 System.err.println(msg);
395 //Exception e1 = new Exception(msg);
396 //e1.printStackTrace();
397 }
398 }
2aa29677 399
f47230cb
SG
400 private GLAnimatorControl savedAnimator = null;
401
2aa29677
SG
402 public synchronized boolean pauseRenderingAction() {
403 boolean animatorPaused = false;
f47230cb
SG
404 savedAnimator = GLWindow.this.getAnimator();
405 if ( null != savedAnimator ) {
406 animatorPaused = savedAnimator.pause();
0feca163 407 }
2aa29677 408 return animatorPaused;
0feca163
SG
409 }
410
a0e9d6c8 411 public synchronized void resumeRenderingAction() {
f47230cb
SG
412 if ( null != savedAnimator && savedAnimator.isPaused() ) {
413 savedAnimator.resume();
0feca163
SG
414 }
415 }
416 }
a0e9d6c8 417
a959c53b
KR
418 //----------------------------------------------------------------------
419 // OpenGL-related methods and state
420 //
421
fd0d3f15 422 private GLContext sharedContext = null;
6c0ad949 423 private int additionalCtxCreationFlags = 0;
a959c53b
KR
424 private GLDrawableFactory factory;
425 private GLDrawable drawable;
426 private GLContext context;
427 private GLDrawableHelper helper = new GLDrawableHelper();
428 // To make reshape events be sent immediately before a display event
429 private boolean sendReshape=false;
430 private boolean sendDestroy=false;
ea819ff7 431 private FPSCounterImpl fpsCounter = new FPSCounterImpl();
0feca163 432
a959c53b
KR
433 public GLDrawableFactory getFactory() {
434 return factory;
435 }
436
fd0d3f15
SG
437 /**
438 * Specifies an {@link javax.media.opengl.GLContext OpenGL context} to share with.<br>
439 * At native creation, {@link #setVisible(boolean) setVisible(true)},
440 * a {@link javax.media.opengl.GLDrawable drawable} and {@link javax.media.opengl.GLContext context} is created besides the native Window itself,<br>
441 * hence you shall set the shared context before.
442 *
443 * @param sharedContext The OpenGL context shared by this GLWindow's one
444 */
445 public void setSharedContext(GLContext sharedContext) {
446 this.sharedContext = sharedContext;
447 }
448
a959c53b
KR
449 public void setContext(GLContext newCtx) {
450 context = newCtx;
6c0ad949
SG
451 if(null != context) {
452 context.setContextCreationFlags(additionalCtxCreationFlags);
453 }
a959c53b
KR
454 }
455
456 public GLContext getContext() {
457 return context;
458 }
459
460 public GL getGL() {
461 if (context == null) {
462 return null;
463 }
464 return context.getGL();
465 }
466
4e0a5af0 467 public GL setGL(GL gl) {
a959c53b
KR
468 if (context != null) {
469 context.setGL(gl);
4e0a5af0 470 return gl;
a959c53b 471 }
4e0a5af0 472 return null;
a959c53b
KR
473 }
474
475 public void addGLEventListener(GLEventListener listener) {
77413854
SG
476 if(null!=helper) {
477 helper.addGLEventListener(listener);
478 }
a959c53b
KR
479 }
480
302f183c 481 public void addGLEventListener(int index, GLEventListener listener) {
77413854
SG
482 if(null!=helper) {
483 helper.addGLEventListener(index, listener);
484 }
302f183c
SG
485 }
486
a959c53b 487 public void removeGLEventListener(GLEventListener listener) {
77413854
SG
488 if(null!=helper) {
489 helper.removeGLEventListener(listener);
490 }
a959c53b
KR
491 }
492
0feca163 493 public void setAnimator(GLAnimatorControl animatorControl) {
77413854
SG
494 if(null!=helper) {
495 helper.setAnimator(animatorControl);
496 }
969e4276
SG
497 }
498
0feca163 499 public GLAnimatorControl getAnimator() {
77413854
SG
500 if(null!=helper) {
501 return helper.getAnimator();
502 }
503 return null;
969e4276
SG
504 }
505
0d24458c 506 public void invoke(boolean wait, GLRunnable glRunnable) {
77413854
SG
507 if(null!=helper) {
508 helper.invoke(this, wait, glRunnable);
509 }
0d24458c
SG
510 }
511
a959c53b 512 public void display() {
cf4c4037
SG
513 display(false);
514 }
515
516 public void display(boolean forceReshape) {
6e599a26
SG
517 if( null == window ) { return; }
518
969e4276 519 if(sendDestroy || ( null!=window && window.hasDeviceChanged() && GLAutoDrawable.SCREEN_CHANGE_ACTION_ENABLED ) ) {
63be4a40
SG
520 sendDestroy=false;
521 destroy();
522 return;
523 }
969e4276 524
5e1a67c9 525 if( null == context && isVisible() && 0<getWidth()*getHeight() ) {
6e599a26
SG
526 // retry native window and drawable/context creation
527 setVisible(true);
528 }
529
2aa29677
SG
530 if(forceReshape) {
531 sendReshape = true;
532 }
533
534 if( isVisible() && null != context ) {
c8a9c59e 535 if( NativeSurface.LOCK_SURFACE_NOT_READY < lockSurface() ) {
1d265b51 536 try {
c8a9c59e
SG
537 helper.invokeGL(drawable, context, displayAction, initAction);
538 } finally {
539 unlockSurface();
540 }
a959c53b
KR
541 }
542 }
543 }
6c0ad949 544
a92906bc 545 /** This implementation uses a static value */
a959c53b 546 public void setAutoSwapBufferMode(boolean onOrOff) {
77413854
SG
547 if(null!=helper) {
548 helper.setAutoSwapBufferMode(onOrOff);
549 }
a959c53b
KR
550 }
551
a92906bc 552 /** This implementation uses a static value */
a959c53b 553 public boolean getAutoSwapBufferMode() {
77413854
SG
554 if(null!=helper) {
555 return helper.getAutoSwapBufferMode();
556 }
557 return false;
a959c53b 558 }
6c0ad949 559
a959c53b 560 public void swapBuffers() {
2268a6ce 561 if(drawable!=null && context != null) {
d72745fa 562 drawable.swapBuffers();
a959c53b
KR
563 }
564 }
565
6c0ad949
SG
566 public void setContextCreationFlags(int flags) {
567 additionalCtxCreationFlags = flags;
568 }
569
570 public int getContextCreationFlags() {
571 return additionalCtxCreationFlags;
572 }
573
3747f6a6
SG
574 private class InitAction implements Runnable {
575 public final void run() {
1d333a77 576 // Lock: Locked Surface/Window by MakeCurrent/Release
a959c53b 577 helper.init(GLWindow.this);
ea819ff7 578 resetFPSCounter();
a959c53b
KR
579 }
580 }
581 private InitAction initAction = new InitAction();
582
3747f6a6
SG
583 private class DisplayAction implements Runnable {
584 public final void run() {
1d333a77 585 // Lock: Locked Surface/Window by display _and_ MakeCurrent/Release
a959c53b 586 if (sendReshape) {
969e4276 587 helper.reshape(GLWindow.this, 0, 0, getWidth(), getHeight());
a959c53b
KR
588 sendReshape = false;
589 }
590
591 helper.display(GLWindow.this);
592
ea819ff7 593 fpsCounter.tickFPS();
a959c53b
KR
594 }
595 }
a92906bc 596 private DisplayAction displayAction = new DisplayAction();
a959c53b 597
ea819ff7
SG
598 public final void setUpdateFPSFrames(int frames, PrintStream out) {
599 fpsCounter.setUpdateFPSFrames(frames, out);
600 }
601
602 public final void resetFPSCounter() {
603 fpsCounter.resetFPSCounter();
0feca163 604 }
a959c53b 605
ea819ff7
SG
606 public final int getUpdateFPSFrames() {
607 return fpsCounter.getUpdateFPSFrames();
608 }
609
610 public final long getFPSStartTime() {
611 return fpsCounter.getFPSStartTime();
0feca163
SG
612 }
613
ea819ff7
SG
614 public final long getLastFPSUpdateTime() {
615 return fpsCounter.getLastFPSUpdateTime();
0feca163
SG
616 }
617
ea819ff7
SG
618 public final long getLastFPSPeriod() {
619 return fpsCounter.getLastFPSPeriod();
620 }
621
622 public final float getLastFPS() {
623 return fpsCounter.getLastFPS();
624 }
625
626 public final int getTotalFPSFrames() {
627 return fpsCounter.getTotalFPSFrames();
018c7e86
SG
628 }
629
ea819ff7
SG
630 public final long getTotalFPSDuration() {
631 return fpsCounter.getTotalFPSDuration();
0feca163 632 }
ea819ff7
SG
633
634 public final float getTotalFPS() {
635 return fpsCounter.getTotalFPS();
636 }
a959c53b 637
3747f6a6
SG
638 private class SwapBuffersAction implements Runnable {
639 public final void run() {
a959c53b
KR
640 drawable.swapBuffers();
641 }
642 }
a959c53b
KR
643 private SwapBuffersAction swapBuffersAction = new SwapBuffersAction();
644
645 //----------------------------------------------------------------------
0feca163 646 // GLDrawable methods
a959c53b
KR
647 //
648
018c7e86
SG
649 public final NativeSurface getNativeSurface() {
650 return null!=drawable ? drawable.getNativeSurface() : null;
a959c53b
KR
651 }
652
0feca163
SG
653 public final long getHandle() {
654 return null!=drawable ? drawable.getHandle() : 0;
8883fa88 655 }
656
0feca163
SG
657 public final int getX() {
658 return window.getX();
6e599a26
SG
659 }
660
0feca163
SG
661 public final int getY() {
662 return window.getY();
6e599a26
SG
663 }
664
0feca163
SG
665 public final int getWidth() {
666 return window.getWidth();
a959c53b
KR
667 }
668
0feca163
SG
669 public final int getHeight() {
670 return window.getHeight();
1d333a77
SG
671 }
672
a959c53b
KR
673 //----------------------------------------------------------------------
674 // GLDrawable methods that are not really needed
675 //
676
0feca163 677 public final GLContext createContext(GLContext shareWith) {
a959c53b
KR
678 return drawable.createContext(shareWith);
679 }
680
0feca163 681 public final void setRealized(boolean realized) {
a959c53b
KR
682 }
683
0feca163 684 public final boolean isRealized() {
811bd23e
SG
685 return ( null != drawable ) ? drawable.isRealized() : false;
686 }
687
29e3b223 688 public final GLCapabilitiesImmutable getChosenGLCapabilities() {
a959c53b
KR
689 if (drawable == null) {
690 throw new GLException("No drawable yet");
691 }
692
693 return drawable.getChosenGLCapabilities();
694 }
695
0feca163 696 public final GLProfile getGLProfile() {
a959c53b
KR
697 if (drawable == null) {
698 throw new GLException("No drawable yet");
699 }
700
701 return drawable.getGLProfile();
702 }
0feca163
SG
703
704 //----------------------------------------------------------------------
1b7b5d34
SG
705 // NEWTEventConsumer
706 //
707 public boolean consumeEvent(NEWTEvent event) {
708 return window.consumeEvent(event);
709 }
710
711 //----------------------------------------------------------------------
0feca163
SG
712 // Window completion
713 //
714 public final void windowRepaint(int x, int y, int width, int height) {
715 window.windowRepaint(x, y, width, height);
716 }
717
718 public final void enqueueEvent(boolean wait, com.jogamp.newt.event.NEWTEvent event) {
719 window.enqueueEvent(wait, event);
720 }
721
722 public final void runOnEDTIfAvail(boolean wait, final Runnable task) {
723 window.runOnEDTIfAvail(wait, task);
724 }
725
726 public final SurfaceUpdatedListener getSurfaceUpdatedListener(int index) {
727 return window.getSurfaceUpdatedListener(index);
728 }
729
730 public final SurfaceUpdatedListener[] getSurfaceUpdatedListeners() {
731 return window.getSurfaceUpdatedListeners();
732 }
733
734 public final void removeAllSurfaceUpdatedListener() {
735 window.removeAllSurfaceUpdatedListener();
736 }
737
738 public final void removeSurfaceUpdatedListener(SurfaceUpdatedListener l) {
739 window.removeSurfaceUpdatedListener(l);
740 }
741
742 public final void addSurfaceUpdatedListener(SurfaceUpdatedListener l) {
743 window.addSurfaceUpdatedListener(l);
744 }
745
746 public final void addSurfaceUpdatedListener(int index, SurfaceUpdatedListener l) throws IndexOutOfBoundsException {
747 window.addSurfaceUpdatedListener(index, l);
748 }
749
750 public void sendWindowEvent(int eventType) {
751 window.sendWindowEvent(eventType);
752 }
753
754 public final WindowListener getWindowListener(int index) {
755 return window.getWindowListener(index);
756 }
757
758 public final WindowListener[] getWindowListeners() {
759 return window.getWindowListeners();
760 }
761
762 public final void removeWindowListener(WindowListener l) {
763 window.removeWindowListener(l);
764 }
765
766 public final void addWindowListener(WindowListener l) {
767 window.addWindowListener(l);
768 }
769
770 public final void addWindowListener(int index, WindowListener l) throws IndexOutOfBoundsException {
771 window.addWindowListener(index, l);
772 }
773
774 public final void addKeyListener(KeyListener l) {
775 window.addKeyListener(l);
776 }
777
778 public final void addKeyListener(int index, KeyListener l) {
779 window.addKeyListener(index, l);
780 }
781
782 public final void removeKeyListener(KeyListener l) {
783 window.removeKeyListener(l);
784 }
785
786 public final KeyListener getKeyListener(int index) {
787 return window.getKeyListener(index);
788 }
789
790 public final KeyListener[] getKeyListeners() {
791 return window.getKeyListeners();
792 }
793
794 public final void addMouseListener(MouseListener l) {
795 window.addMouseListener(l);
796 }
797
798 public final void addMouseListener(int index, MouseListener l) {
799 window.addMouseListener(index, l);
800 }
801
802 public final void removeMouseListener(MouseListener l) {
803 window.removeMouseListener(l);
804 }
805
806 public final MouseListener getMouseListener(int index) {
807 return window.getMouseListener(index);
808 }
809
810 public final MouseListener[] getMouseListeners() {
811 return window.getMouseListeners();
812 }
813
814 //----------------------------------------------------------------------
815 // NativeWindow completion
816 //
817
818 public final int lockSurface() {
819 return window.lockSurface();
820 }
821
822 public final void unlockSurface() throws NativeWindowException {
823 window.unlockSurface();
824 }
825
826 public final boolean isSurfaceLockedByOtherThread() {
827 return window.isSurfaceLockedByOtherThread();
828 }
829
830 public final boolean isSurfaceLocked() {
831 return window.isSurfaceLocked();
832 }
833
834 public final Thread getSurfaceLockOwner() {
835 return window.getSurfaceLockOwner();
836
837 }
838
0feca163
SG
839 public final boolean surfaceSwap() {
840 return window.surfaceSwap();
841 }
842
0feca163
SG
843 public final long getWindowHandle() {
844 return window.getWindowHandle();
845
846 }
847
848 public final long getSurfaceHandle() {
849 return window.getSurfaceHandle();
850
851 }
852
853 public final AbstractGraphicsConfiguration getGraphicsConfiguration() {
854 return window.getGraphicsConfiguration();
855 }
856
857 public final long getDisplayHandle() {
858 return window.getDisplayHandle();
859 }
860
861 public final int getScreenIndex() {
862 return window.getScreenIndex();
863 }
864
018c7e86
SG
865 public final void surfaceUpdated(Object updater, NativeSurface ns, long when) {
866 window.surfaceUpdated(updater, ns, when);
0feca163 867 }
597d10f5
SG
868
869 /**
870 * A most simple JOGL AWT test entry
871 */
872 public static void main(String args[]) {
8c9f3bb3 873 System.err.println(VersionUtil.getPlatformInfo());
6ea02e25 874 System.err.println(GlueGenVersion.getInstance());
62df9dd1 875 // System.err.println(NativeWindowVersion.getInstance());
2aa90676 876 System.err.println(JoglVersion.getInstance());
6ea02e25 877 System.err.println(NewtVersion.getInstance());
8adc0478 878
3349511a
SG
879 final GLProfile glp = GLProfile.getDefault();
880 final GLDrawableFactory factory = GLDrawableFactory.getFactory(glp);
881 final List/*<GLCapabilitiesImmutable>*/ availCaps = factory.getAvailableCapabilities(null);
8adc0478
SG
882 for(int i=0; i<availCaps.size(); i++) {
883 System.err.println(availCaps.get(i));
884 }
3349511a 885 final GLCapabilitiesImmutable caps = new GLCapabilities( glp );
597d10f5
SG
886
887 GLWindow glWindow = GLWindow.create(caps);
888 glWindow.setSize(128, 128);
889
890 glWindow.addGLEventListener(new GLEventListener() {
891 public void init(GLAutoDrawable drawable) {
892 GL gl = drawable.getGL();
10c696f7 893 System.err.println(JoglVersion.getGLInfo(gl, null));
3349511a
SG
894 System.err.println("Requested: "+drawable.getNativeSurface().getGraphicsConfiguration().getRequestedCapabilities());
895 System.err.println("Chosen : "+drawable.getChosenGLCapabilities());
597d10f5
SG
896 }
897
898 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
899 }
900
901 public void display(GLAutoDrawable drawable) {
902 }
903
904 public void dispose(GLAutoDrawable drawable) {
905 }
906 });
907
908 glWindow.setVisible(true);
f47230cb 909 glWindow.destroy();
597d10f5
SG
910 }
911
a959c53b 912}
http://JogAmp.org git info: FAQ, tutorial and man pages.