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