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