Jogamp
JOGL X11/WGL: Proper usage of the shared resources in implementation
[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 */
333 public synchronized void setVisibleAction(boolean visible, boolean nativeWindowCreated) {
334 if(Window.DEBUG_WINDOW_EVENT || Window.DEBUG_IMPLEMENTATION) {
335 String msg = new String("GLWindow.setVisibleAction("+visible+", "+nativeWindowCreated+") "+Thread.currentThread()+", start");
336 System.err.println(msg);
337 // Exception e1 = new Exception(msg);
338 // e1.printStackTrace();
339 }
340
341 /* if (nativeWindowCreated && null != context) {
342 throw new GLException("InternalError: Native Windows has been just created, but context wasn't destroyed (is not null)");
343 } */
344 if (null == context && visible && 0 != window.getWindowHandle() && 0<getWidth()*getHeight()) {
345 NativeWindow nw;
346 if (window.getWrappedWindow() != null) {
347 nw = NativeWindowFactory.getNativeWindow(window.getWrappedWindow(), window.getGraphicsConfiguration());
348 } else {
349 nw = window;
350 }
351 GLCapabilities glCaps = (GLCapabilities) nw.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities();
352 if(null==factory) {
353 factory = GLDrawableFactory.getFactory(glCaps.getGLProfile());
354 }
355 if(null==drawable) {
356 drawable = factory.createGLDrawable(nw);
357 }
358 drawable.setRealized(true);
359 context = drawable.createContext(null);
018c7e86 360 resetCounter();
0feca163 361 } else if(!visible) {
018c7e86 362 resetCounter();
0feca163
SG
363 }
364 if(Window.DEBUG_WINDOW_EVENT || Window.DEBUG_IMPLEMENTATION) {
365 String msg = new String("GLWindow.setVisibleAction("+visible+", "+nativeWindowCreated+") "+Thread.currentThread()+", fin");
366 System.err.println(msg);
367 //Exception e1 = new Exception(msg);
368 //e1.printStackTrace();
369 }
370 }
371
372 boolean animatorPaused = false;
373
a0e9d6c8 374 public synchronized void pauseRenderingAction() {
0feca163
SG
375 GLAnimatorControl ctrl = GLWindow.this.getAnimator();
376 if ( null!=ctrl && ctrl.isAnimating() && ctrl.getThread() != Thread.currentThread() ) {
377 animatorPaused = true;
378 ctrl.pause();
379 }
380 }
381
a0e9d6c8 382 public synchronized void resumeRenderingAction() {
018c7e86 383 resetCounter();
0feca163
SG
384 GLAnimatorControl ctrl = GLWindow.this.getAnimator();
385 if ( null!=ctrl && animatorPaused ) {
386 animatorPaused = false;
387 ctrl.resume();
388 }
389 }
390 }
a0e9d6c8 391
a959c53b
KR
392 //----------------------------------------------------------------------
393 // OpenGL-related methods and state
394 //
395
a959c53b
KR
396 private GLDrawableFactory factory;
397 private GLDrawable drawable;
398 private GLContext context;
399 private GLDrawableHelper helper = new GLDrawableHelper();
400 // To make reshape events be sent immediately before a display event
401 private boolean sendReshape=false;
402 private boolean sendDestroy=false;
403 private boolean perfLog = false;
0feca163
SG
404 private long startTime, curTime, lastCheck;
405 private int totalFrames, lastFrames;
406
a959c53b
KR
407 public GLDrawableFactory getFactory() {
408 return factory;
409 }
410
411 public void setContext(GLContext newCtx) {
412 context = newCtx;
413 }
414
415 public GLContext getContext() {
416 return context;
417 }
418
419 public GL getGL() {
420 if (context == null) {
421 return null;
422 }
423 return context.getGL();
424 }
425
4e0a5af0 426 public GL setGL(GL gl) {
a959c53b
KR
427 if (context != null) {
428 context.setGL(gl);
4e0a5af0 429 return gl;
a959c53b 430 }
4e0a5af0 431 return null;
a959c53b
KR
432 }
433
434 public void addGLEventListener(GLEventListener listener) {
77413854
SG
435 if(null!=helper) {
436 helper.addGLEventListener(listener);
437 }
a959c53b
KR
438 }
439
302f183c 440 public void addGLEventListener(int index, GLEventListener listener) {
77413854
SG
441 if(null!=helper) {
442 helper.addGLEventListener(index, listener);
443 }
302f183c
SG
444 }
445
a959c53b 446 public void removeGLEventListener(GLEventListener listener) {
77413854
SG
447 if(null!=helper) {
448 helper.removeGLEventListener(listener);
449 }
a959c53b
KR
450 }
451
0feca163 452 public void setAnimator(GLAnimatorControl animatorControl) {
77413854
SG
453 if(null!=helper) {
454 helper.setAnimator(animatorControl);
455 }
969e4276
SG
456 }
457
0feca163 458 public GLAnimatorControl getAnimator() {
77413854
SG
459 if(null!=helper) {
460 return helper.getAnimator();
461 }
462 return null;
969e4276
SG
463 }
464
0feca163
SG
465 public boolean getPerfLogEnabled() { return perfLog; }
466
467 public void enablePerfLog(boolean v) {
468 perfLog = v;
469 }
470
0d24458c 471 public void invoke(boolean wait, GLRunnable glRunnable) {
77413854
SG
472 if(null!=helper) {
473 helper.invoke(this, wait, glRunnable);
474 }
0d24458c
SG
475 }
476
a959c53b 477 public void display() {
cf4c4037
SG
478 display(false);
479 }
480
481 public void display(boolean forceReshape) {
6e599a26
SG
482 if( null == window ) { return; }
483
969e4276 484 if(sendDestroy || ( null!=window && window.hasDeviceChanged() && GLAutoDrawable.SCREEN_CHANGE_ACTION_ENABLED ) ) {
63be4a40
SG
485 sendDestroy=false;
486 destroy();
487 return;
488 }
969e4276 489
5e1a67c9 490 if( null == context && isVisible() && 0<getWidth()*getHeight() ) {
6e599a26
SG
491 // retry native window and drawable/context creation
492 setVisible(true);
493 }
494
0feca163 495 if( isVisible() && isNativeValid() && null != context ) {
969e4276
SG
496 if(forceReshape) {
497 sendReshape = true;
a92906bc 498 }
c8a9c59e 499 if( NativeSurface.LOCK_SURFACE_NOT_READY < lockSurface() ) {
1d265b51 500 try {
c8a9c59e
SG
501 helper.invokeGL(drawable, context, displayAction, initAction);
502 } finally {
503 unlockSurface();
504 }
a959c53b
KR
505 }
506 }
507 }
508
a92906bc 509 /** This implementation uses a static value */
a959c53b 510 public void setAutoSwapBufferMode(boolean onOrOff) {
77413854
SG
511 if(null!=helper) {
512 helper.setAutoSwapBufferMode(onOrOff);
513 }
a959c53b
KR
514 }
515
a92906bc 516 /** This implementation uses a static value */
a959c53b 517 public boolean getAutoSwapBufferMode() {
77413854
SG
518 if(null!=helper) {
519 return helper.getAutoSwapBufferMode();
520 }
521 return false;
a959c53b
KR
522 }
523
524 public void swapBuffers() {
2268a6ce 525 if(drawable!=null && context != null) {
1d333a77 526 // Lock: Locked Surface/Window by MakeCurrent/Release
2268a6ce 527 if (context != GLContext.getCurrent()) {
a959c53b
KR
528 // Assume we should try to make the context current before swapping the buffers
529 helper.invokeGL(drawable, context, swapBuffersAction, initAction);
530 } else {
531 drawable.swapBuffers();
532 }
533 }
534 }
535
536 class InitAction implements Runnable {
537 public void run() {
1d333a77 538 // Lock: Locked Surface/Window by MakeCurrent/Release
a959c53b 539 helper.init(GLWindow.this);
018c7e86 540 resetCounter();
a959c53b
KR
541 }
542 }
543 private InitAction initAction = new InitAction();
544
a959c53b
KR
545 class DisplayAction implements Runnable {
546 public void run() {
1d333a77 547 // Lock: Locked Surface/Window by display _and_ MakeCurrent/Release
a959c53b 548 if (sendReshape) {
969e4276 549 helper.reshape(GLWindow.this, 0, 0, getWidth(), getHeight());
a959c53b
KR
550 sendReshape = false;
551 }
552
553 helper.display(GLWindow.this);
554
555 curTime = System.currentTimeMillis();
556 totalFrames++;
557
558 if(perfLog) {
559 long dt0, dt1;
560 lastFrames++;
561 dt0 = curTime-lastCheck;
562 if ( dt0 > 5000 ) {
563 dt1 = curTime-startTime;
0feca163 564 System.err.println(dt0/1000 +"s: "+ lastFrames + "f, " + (lastFrames*1000)/dt0 + " fps, "+dt0/lastFrames+" ms/f; "+
a959c53b
KR
565 "total: "+ dt1/1000+"s, "+(totalFrames*1000)/dt1 + " fps, "+dt1/totalFrames+" ms/f");
566 lastCheck=curTime;
567 lastFrames=0;
568 }
569 }
570 }
571 }
a92906bc 572 private DisplayAction displayAction = new DisplayAction();
a959c53b 573
0feca163
SG
574 /**
575 * @return Time of the first display call in milliseconds.
576 * This value is reset if becoming visible again or reparenting.
0feca163
SG
577 */
578 public final long getStartTime() {
018c7e86 579 return startTime;
0feca163 580 }
a959c53b 581
0feca163
SG
582 /**
583 * @return Time of the last display call in milliseconds.
584 * This value is reset if becoming visible again or reparenting.
0feca163
SG
585 */
586 public final long getCurrentTime() {
018c7e86 587 return curTime;
0feca163
SG
588 }
589
590 /**
591 * @return Duration <code>getCurrentTime() - getStartTime()</code>.
592 *
593 * @see #getStartTime()
594 * @see #getCurrentTime()
595 */
596 public final long getDuration() {
597 return getCurrentTime()-getStartTime();
598 }
599
600 /**
601 * @return Number of frames displayed since the first display call, ie <code>getStartTime()</code>.
602 * This value is reset if becoming visible again or reparenting.
0feca163 603 */
018c7e86
SG
604 public final int getTotalFrames() {
605 return totalFrames;
606 }
607
608 /** Reset all counter (startTime, currentTime, frame number) */
609 public synchronized void resetCounter() {
610 startTime = System.currentTimeMillis(); // overwrite startTime to real init one
611 curTime = startTime;
612 lastCheck = startTime;
613 totalFrames = 0; lastFrames = 0;
0feca163 614 }
a959c53b 615
a959c53b
KR
616 class SwapBuffersAction implements Runnable {
617 public void run() {
618 drawable.swapBuffers();
619 }
620 }
a959c53b
KR
621 private SwapBuffersAction swapBuffersAction = new SwapBuffersAction();
622
623 //----------------------------------------------------------------------
0feca163 624 // GLDrawable methods
a959c53b
KR
625 //
626
018c7e86
SG
627 public final NativeSurface getNativeSurface() {
628 return null!=drawable ? drawable.getNativeSurface() : null;
a959c53b
KR
629 }
630
0feca163
SG
631 public final long getHandle() {
632 return null!=drawable ? drawable.getHandle() : 0;
8883fa88 633 }
634
0feca163
SG
635 public final void destroy() {
636 window.destroy();
a959c53b
KR
637 }
638
0feca163
SG
639 public final int getX() {
640 return window.getX();
6e599a26
SG
641 }
642
0feca163
SG
643 public final int getY() {
644 return window.getY();
6e599a26
SG
645 }
646
0feca163
SG
647 public final int getWidth() {
648 return window.getWidth();
a959c53b
KR
649 }
650
0feca163
SG
651 public final int getHeight() {
652 return window.getHeight();
1d333a77
SG
653 }
654
a959c53b
KR
655 //----------------------------------------------------------------------
656 // GLDrawable methods that are not really needed
657 //
658
0feca163 659 public final GLContext createContext(GLContext shareWith) {
a959c53b
KR
660 return drawable.createContext(shareWith);
661 }
662
0feca163 663 public final void setRealized(boolean realized) {
a959c53b
KR
664 }
665
0feca163 666 public final boolean isRealized() {
811bd23e
SG
667 return ( null != drawable ) ? drawable.isRealized() : false;
668 }
669
0feca163 670 public final GLCapabilities getChosenGLCapabilities() {
a959c53b
KR
671 if (drawable == null) {
672 throw new GLException("No drawable yet");
673 }
674
675 return drawable.getChosenGLCapabilities();
676 }
677
0feca163 678 public final GLProfile getGLProfile() {
a959c53b
KR
679 if (drawable == null) {
680 throw new GLException("No drawable yet");
681 }
682
683 return drawable.getGLProfile();
684 }
0feca163
SG
685
686 //----------------------------------------------------------------------
687 // Window completion
688 //
689 public final void windowRepaint(int x, int y, int width, int height) {
690 window.windowRepaint(x, y, width, height);
691 }
692
693 public final void enqueueEvent(boolean wait, com.jogamp.newt.event.NEWTEvent event) {
694 window.enqueueEvent(wait, event);
695 }
696
697 public final void runOnEDTIfAvail(boolean wait, final Runnable task) {
698 window.runOnEDTIfAvail(wait, task);
699 }
700
701 public final SurfaceUpdatedListener getSurfaceUpdatedListener(int index) {
702 return window.getSurfaceUpdatedListener(index);
703 }
704
705 public final SurfaceUpdatedListener[] getSurfaceUpdatedListeners() {
706 return window.getSurfaceUpdatedListeners();
707 }
708
709 public final void removeAllSurfaceUpdatedListener() {
710 window.removeAllSurfaceUpdatedListener();
711 }
712
713 public final void removeSurfaceUpdatedListener(SurfaceUpdatedListener l) {
714 window.removeSurfaceUpdatedListener(l);
715 }
716
717 public final void addSurfaceUpdatedListener(SurfaceUpdatedListener l) {
718 window.addSurfaceUpdatedListener(l);
719 }
720
721 public final void addSurfaceUpdatedListener(int index, SurfaceUpdatedListener l) throws IndexOutOfBoundsException {
722 window.addSurfaceUpdatedListener(index, l);
723 }
724
725 public void sendWindowEvent(int eventType) {
726 window.sendWindowEvent(eventType);
727 }
728
729 public final WindowListener getWindowListener(int index) {
730 return window.getWindowListener(index);
731 }
732
733 public final WindowListener[] getWindowListeners() {
734 return window.getWindowListeners();
735 }
736
737 public final void removeWindowListener(WindowListener l) {
738 window.removeWindowListener(l);
739 }
740
741 public final void addWindowListener(WindowListener l) {
742 window.addWindowListener(l);
743 }
744
745 public final void addWindowListener(int index, WindowListener l) throws IndexOutOfBoundsException {
746 window.addWindowListener(index, l);
747 }
748
749 public final void addKeyListener(KeyListener l) {
750 window.addKeyListener(l);
751 }
752
753 public final void addKeyListener(int index, KeyListener l) {
754 window.addKeyListener(index, l);
755 }
756
757 public final void removeKeyListener(KeyListener l) {
758 window.removeKeyListener(l);
759 }
760
761 public final KeyListener getKeyListener(int index) {
762 return window.getKeyListener(index);
763 }
764
765 public final KeyListener[] getKeyListeners() {
766 return window.getKeyListeners();
767 }
768
769 public final void addMouseListener(MouseListener l) {
770 window.addMouseListener(l);
771 }
772
773 public final void addMouseListener(int index, MouseListener l) {
774 window.addMouseListener(index, l);
775 }
776
777 public final void removeMouseListener(MouseListener l) {
778 window.removeMouseListener(l);
779 }
780
781 public final MouseListener getMouseListener(int index) {
782 return window.getMouseListener(index);
783 }
784
785 public final MouseListener[] getMouseListeners() {
786 return window.getMouseListeners();
787 }
788
789 //----------------------------------------------------------------------
790 // NativeWindow completion
791 //
792
793 public final int lockSurface() {
794 return window.lockSurface();
795 }
796
797 public final void unlockSurface() throws NativeWindowException {
798 window.unlockSurface();
799 }
800
801 public final boolean isSurfaceLockedByOtherThread() {
802 return window.isSurfaceLockedByOtherThread();
803 }
804
805 public final boolean isSurfaceLocked() {
806 return window.isSurfaceLocked();
807 }
808
809 public final Thread getSurfaceLockOwner() {
810 return window.getSurfaceLockOwner();
811
812 }
813
0feca163
SG
814 public final boolean surfaceSwap() {
815 return window.surfaceSwap();
816 }
817
818 public final void invalidate() {
819 window.invalidate();
820 }
821
822 public final long getWindowHandle() {
823 return window.getWindowHandle();
824
825 }
826
827 public final long getSurfaceHandle() {
828 return window.getSurfaceHandle();
829
830 }
831
832 public final AbstractGraphicsConfiguration getGraphicsConfiguration() {
833 return window.getGraphicsConfiguration();
834 }
835
836 public final long getDisplayHandle() {
837 return window.getDisplayHandle();
838 }
839
840 public final int getScreenIndex() {
841 return window.getScreenIndex();
842 }
843
018c7e86
SG
844 public final void surfaceUpdated(Object updater, NativeSurface ns, long when) {
845 window.surfaceUpdated(updater, ns, when);
0feca163 846 }
597d10f5
SG
847
848 /**
849 * A most simple JOGL AWT test entry
850 */
851 public static void main(String args[]) {
6ea02e25
SG
852 System.err.println(GlueGenVersion.getInstance());
853 System.err.println(NativeWindowVersion.getInstance());
854 System.err.print(JoglVersion.getInstance());
855 System.err.println(NewtVersion.getInstance());
597d10f5
SG
856 GLCapabilities caps = new GLCapabilities( GLProfile.getDefault() );
857
858 GLWindow glWindow = GLWindow.create(caps);
859 glWindow.setSize(128, 128);
860
861 glWindow.addGLEventListener(new GLEventListener() {
862 public void init(GLAutoDrawable drawable) {
863 GL gl = drawable.getGL();
6ea02e25 864 System.err.println(JoglVersion.getInstance().toString(gl));
597d10f5
SG
865 }
866
867 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
868 }
869
870 public void display(GLAutoDrawable drawable) {
871 }
872
873 public void dispose(GLAutoDrawable drawable) {
874 }
875 });
876
877 glWindow.setVisible(true);
878 glWindow.destroy(true);
879 }
880
a959c53b 881}
http://JogAmp.org git info: FAQ, tutorial and man pages.