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