com.sun.javafx.newt.opengl
Class GLWindow

java.lang.Object
  extended by com.sun.javafx.newt.Window
      extended by com.sun.javafx.newt.opengl.GLWindow
All Implemented Interfaces:
NativeWindow, GLAutoDrawable, GLDrawable

public class GLWindow
extends Window
implements GLAutoDrawable

An implementation of Window which is customized for OpenGL use, and which implements the GLAutoDrawable interface. For convenience, this window class guarantees that its OpenGL context is current inside the various EventListeners' callbacks (MouseListener, KeyListener, etc.).

Best performance is currently achieved with default settings, setEventHandlerMode(int) to EVENT_HANDLER_GL_NONE and one thread per GLWindow. To ensure compatibility with the underlying platform, window shall also be created within your working thread. See comment at setRunPumpMessages(boolean).


Field Summary
static int EVENT_HANDLER_GL_CURRENT
          Event handling mode: EVENT_HANDLER_GL_CURRENT.
static int EVENT_HANDLER_GL_NONE
          Event handling mode: EVENT_HANDLER_GL_NONE.
 
Fields inherited from class com.sun.javafx.newt.Window
ClickTimeout, config, DEBUG_IMPLEMENTATION, DEBUG_KEY_EVENT, DEBUG_MOUSE_EVENT, DEBUG_WINDOW_EVENT, eventMask, fullscreen, height, lockedStack, screen, title, undecorated, visible, width, windowHandle, x, y
 
Fields inherited from interface javax.media.opengl.GLAutoDrawable
SCREEN_CHANGE_ACTION_ENABLED
 
Fields inherited from interface javax.media.nativewindow.NativeWindow
LOCK_SUCCESS, LOCK_SURFACE_CHANGED, LOCK_SURFACE_NOT_READY
 
Constructor Summary
protected GLWindow(Window window, boolean ownerOfDisplayAndScreen)
          Constructor.
 
Method Summary
 void addGLEventListener(GLEventListener listener)
          Adds a GLEventListener to this drawable.
 void addKeyListener(KeyListener l)
           
 void addMouseListener(MouseListener l)
           
 void addWindowListener(WindowListener l)
           
protected  void closeNative()
           
static GLWindow create()
          Creates a new GLWindow on the local display, screen 0, with a dummy visual ID, and with the default GLCapabilities.
static GLWindow create(boolean undecorated)
           
static GLWindow create(GLCapabilities caps)
           
static GLWindow create(GLCapabilities caps, boolean undecorated)
          Creates a new GLWindow on the local display, screen 0, with a dummy visual ID, and with the given GLCapabilities.
static GLWindow create(Window window)
          Creates a new GLWindow referring to the given window.
 GLContext createContext(GLContext shareWith)
          Creates a new context for drawing to this drawable that will optionally share display lists and other server-side OpenGL objects with the specified GLContext.
protected  void createNative(long parentWindowHandle, Capabilities caps)
          Create native windowHandle, ie creates a new native invisible window.
 void destroy()
          destroys the window and releases windowing related resources.
 void display()
          Causes OpenGL rendering to be performed for this GLAutoDrawable by calling display(..) for all registered GLEventListeners.
protected  void dispose(boolean regenerate)
           
 void enablePerfLog(boolean v)
           
 boolean getAutoSwapBufferMode()
          This implementation uses a static value
 GLCapabilities getChosenGLCapabilities()
          Fetches the GLCapabilities corresponding to the chosen OpenGL capabilities (pixel format / visual / GLProfile) for this drawable.
On some platforms, the pixel format is not directly associated with the drawable; a best attempt is made to return a reasonable value in this case.
 GLContext getContext()
          Returns the context associated with this drawable.
 long getCurrentTime()
           
 long getDuration()
           
 int getEventHandlerMode()
           
 GLDrawableFactory getFactory()
           
 GL getGL()
          Returns the GL pipeline object this GLAutoDrawable uses.
 GLProfile getGLProfile()
          Fetches the GLProfile for this drawable.
 int getHeight()
          Returns the height of the client area of this window
 Insets getInsets()
          Returns the insets for this native window (the difference between the size of the toplevel window with the decorations and the client area).
 KeyListener[] getKeyListeners()
           
 Exception getLockedStack()
          Return the lock-exception, or null if not locked.
 MouseListener[] getMouseListeners()
           
 NativeWindow getNativeWindow()
           
 boolean getPerfLogEnabled()
           
 Screen getScreen()
           
 long getStartTime()
           
 long getSurfaceHandle()
          Returns the handle to the surface for this NativeWindow.
 String getTitle()
           
 int getTotalFrames()
           
 int getWidth()
          Returns the width of the client area of this window
 long getWindowHandle()
          Returns the window handle for this NativeWindow.
 WindowListener[] getWindowListeners()
           
 int getX()
           
 int getY()
           
 boolean isFullscreen()
           
 boolean isSurfaceLocked()
          Return if surface is locked
 boolean isUndecorated()
           
 boolean isVisible()
           
 int lockSurface()
          Lock the surface of this native window
 void removeGLEventListener(GLEventListener listener)
          Removes a GLEventListener from this drawable.
 void removeKeyListener(KeyListener l)
           
 void removeMouseListener(MouseListener l)
           
 void removeWindowListener(WindowListener l)
           
static void runCurrentThreadPumpMessage()
          Deprecated. EXPERIMENTAL, semantic is about to be removed after further verification.
 void setAutoSwapBufferMode(boolean onOrOff)
          This implementation uses a static value
 void setContext(GLContext newCtx)
          Associate a new context to this drawable.
 void setEventHandlerMode(int mode)
          Sets the event handling mode.
 boolean setFullscreen(boolean fullscreen)
           
 GL setGL(GL gl)
          Sets the GL pipeline object this GLAutoDrawable uses.
 void setPosition(int x, int y)
          Sets the location of the top left corner of the window, including decorations (so the client area will be placed at x+insets.left,y+insets.top.
 void setRealized(boolean realized)
          Indicates to on-screen GLDrawable implementations whether the underlying window has been created and can be drawn into.
 void setRunPumpMessages(boolean onoff)
          Deprecated. EXPERIMENTAL, semantic is about to be removed after further verification.
 void setSize(int width, int height)
          Sets the size of the client area of the window, excluding decorations Total size of the window will be width+insets.left+insets.right, height+insets.top+insets.bottom
 void setTitle(String title)
           
 void setUndecorated(boolean value)
           
 void setVisible(boolean visible)
           
 boolean surfaceSwap()
          Provide a mechanism to utilize custom (pre-) swap surface code.
 void surfaceUpdated()
          Method invoked after the render toolkit (e.g.
 void swapBuffers()
          Swaps the front and back buffers of this drawable.
 String toString()
           
 void unlockSurface()
          Unlock the surface of this native window Shall not modify the window handle, see NativeWindow.getWindowHandle(), or the surface handle, see NativeWindow.lockSurface()
 
Methods inherited from class com.sun.javafx.newt.Window
addPaintListener, clearEventMask, create, create, disposeSurfaceHandle, getDisplayHandle, getGraphicsConfiguration, getScreenIndex, getWrappedWindow, hasDeviceChanged, invalidate, removePaintListener, requestFocus, sendKeyEvent, sendMouseEvent, sendPaintEvent, sendWindowEvent, setAutoDrawableClient, windowDestroyed, windowDestroyNotify, wrapHandle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EVENT_HANDLER_GL_NONE

public static final int EVENT_HANDLER_GL_NONE
Event handling mode: EVENT_HANDLER_GL_NONE. No GL context is current, while calling the EventListener. This might be inconvenient, but don't impact the performance. Also

See Also:
com.sun.javafx.newt.GLWindow#setEventHandlerMode(int), Constant Field Values

EVENT_HANDLER_GL_CURRENT

public static final int EVENT_HANDLER_GL_CURRENT
Event handling mode: EVENT_HANDLER_GL_CURRENT. The GL context is made current, while calling the EventListener. This might be convenient, but impacts the performance due to context switches. This is the default setting!

See Also:
com.sun.javafx.newt.GLWindow#setEventHandlerMode(int), Constant Field Values
Constructor Detail

GLWindow

protected GLWindow(Window window,
                   boolean ownerOfDisplayAndScreen)
Constructor. Do not call this directly -- use create() instead.

Method Detail

create

public static GLWindow create()
Creates a new GLWindow on the local display, screen 0, with a dummy visual ID, and with the default GLCapabilities.


create

public static GLWindow create(boolean undecorated)

create

public static GLWindow create(Window window)
Creates a new GLWindow referring to the given window.


create

public static GLWindow create(GLCapabilities caps)

create

public static GLWindow create(GLCapabilities caps,
                              boolean undecorated)
Creates a new GLWindow on the local display, screen 0, with a dummy visual ID, and with the given GLCapabilities.


setRunPumpMessages

public void setRunPumpMessages(boolean onoff)
Deprecated. EXPERIMENTAL, semantic is about to be removed after further verification.

EXPERIMENTAL
Enable or disables running the Display.pumpMessages() in the display() call.
The default behavior is to run Display.pumpMessages().

The idea was that in a single threaded environment with one Display and many Window's, a performance benefit was expected while disabling the implicit Display.pumpMessages() and do it once via runCurrentThreadPumpMessage()
This could not have been verified. No measurable difference could have been recognized.

Best performance has been achieved with one GLWindow per thread.


createNative

protected void createNative(long parentWindowHandle,
                            Capabilities caps)
Description copied from class: Window
Create native windowHandle, ie creates a new native invisible window. The parentWindowHandle may be null, in which case no window parenting is requested. Shall use the capabilities to determine the graphics configuration and shall set the chosen capabilities.

Specified by:
createNative in class Window

closeNative

protected void closeNative()
Specified by:
closeNative in class Window

dispose

protected void dispose(boolean regenerate)

destroy

public void destroy()
Description copied from interface: NativeWindow
destroys the window and releases windowing related resources.

Specified by:
destroy in interface NativeWindow
Specified by:
destroy in interface GLAutoDrawable
Overrides:
destroy in class Window

getPerfLogEnabled

public boolean getPerfLogEnabled()

enablePerfLog

public void enablePerfLog(boolean v)

setEventHandlerMode

public void setEventHandlerMode(int mode)
Sets the event handling mode.

See Also:
com.sun.javafx.newt.GLWindow#EVENT_HANDLER_GL_NONE, com.sun.javafx.newt.GLWindow#EVENT_HANDLER_GL_CURRENT

getEventHandlerMode

public int getEventHandlerMode()

setVisible

public void setVisible(boolean visible)
Specified by:
setVisible in class Window

getScreen

public Screen getScreen()
Overrides:
getScreen in class Window

setTitle

public void setTitle(String title)
Overrides:
setTitle in class Window

getTitle

public String getTitle()
Overrides:
getTitle in class Window

setUndecorated

public void setUndecorated(boolean value)
Overrides:
setUndecorated in class Window

isUndecorated

public boolean isUndecorated()
Overrides:
isUndecorated in class Window

setSize

public void setSize(int width,
                    int height)
Description copied from class: Window
Sets the size of the client area of the window, excluding decorations Total size of the window will be width+insets.left+insets.right, height+insets.top+insets.bottom

Specified by:
setSize in class Window
Parameters:
width - of the client area of the window
height - of the client area of the window

setPosition

public void setPosition(int x,
                        int y)
Description copied from class: Window
Sets the location of the top left corner of the window, including decorations (so the client area will be placed at x+insets.left,y+insets.top.

Specified by:
setPosition in class Window
Parameters:
x - coord of the top left corner
y - coord of the top left corner

getInsets

public Insets getInsets()
Description copied from class: Window
Returns the insets for this native window (the difference between the size of the toplevel window with the decorations and the client area).

Overrides:
getInsets in class Window
Returns:
insets for this platform window

setFullscreen

public boolean setFullscreen(boolean fullscreen)
Specified by:
setFullscreen in class Window

isVisible

public boolean isVisible()
Overrides:
isVisible in class Window

getX

public int getX()
Overrides:
getX in class Window

getY

public int getY()
Overrides:
getY in class Window

getWidth

public int getWidth()
Description copied from class: Window
Returns the width of the client area of this window

Specified by:
getWidth in interface NativeWindow
Specified by:
getWidth in interface GLDrawable
Overrides:
getWidth in class Window
Returns:
width of the client area

getHeight

public int getHeight()
Description copied from class: Window
Returns the height of the client area of this window

Specified by:
getHeight in interface NativeWindow
Specified by:
getHeight in interface GLDrawable
Overrides:
getHeight in class Window
Returns:
height of the client area

isFullscreen

public boolean isFullscreen()
Overrides:
isFullscreen in class Window

addMouseListener

public void addMouseListener(MouseListener l)
Overrides:
addMouseListener in class Window

removeMouseListener

public void removeMouseListener(MouseListener l)
Overrides:
removeMouseListener in class Window

getMouseListeners

public MouseListener[] getMouseListeners()
Overrides:
getMouseListeners in class Window

addKeyListener

public void addKeyListener(KeyListener l)
Overrides:
addKeyListener in class Window

removeKeyListener

public void removeKeyListener(KeyListener l)
Overrides:
removeKeyListener in class Window

getKeyListeners

public KeyListener[] getKeyListeners()
Overrides:
getKeyListeners in class Window

addWindowListener

public void addWindowListener(WindowListener l)
Overrides:
addWindowListener in class Window

removeWindowListener

public void removeWindowListener(WindowListener l)
Overrides:
removeWindowListener in class Window

getWindowListeners

public WindowListener[] getWindowListeners()
Overrides:
getWindowListeners in class Window

toString

public String toString()
Specified by:
toString in interface GLDrawable
Overrides:
toString in class Window

getFactory

public GLDrawableFactory getFactory()
Specified by:
getFactory in interface GLDrawable

setContext

public void setContext(GLContext newCtx)
Description copied from interface: GLAutoDrawable
Associate a new context to this drawable.

Specified by:
setContext in interface GLAutoDrawable

getContext

public GLContext getContext()
Description copied from interface: GLAutoDrawable
Returns the context associated with this drawable. The returned context will be synchronized. Don't rely on it's identity, the context may change.

Specified by:
getContext in interface GLAutoDrawable

getGL

public GL getGL()
Description copied from interface: GLAutoDrawable
Returns the GL pipeline object this GLAutoDrawable uses. If this method is called outside of the GLEventListener's callback methods (init, display, etc.) it may return null. Users should not rely on the identity of the returned GL object; for example, users should not maintain a hash table with the GL object as the key. Additionally, the GL object should not be cached in client code, but should be re-fetched from the GLAutoDrawable at the beginning of each call to init, display, etc.

Specified by:
getGL in interface GLAutoDrawable

setGL

public GL setGL(GL gl)
Description copied from interface: GLAutoDrawable
Sets the GL pipeline object this GLAutoDrawable uses. This should only be called from within the GLEventListener's callback methods, and usually only from within the init() method, in order to install a composable pipeline. See the JOGL demos for examples.

Specified by:
setGL in interface GLAutoDrawable
Returns:
the set GL pipeline or null if not successful

addGLEventListener

public void addGLEventListener(GLEventListener listener)
Description copied from interface: GLAutoDrawable
Adds a GLEventListener to this drawable. If multiple listeners are added to a given drawable, they are notified of events in an arbitrary order.

Specified by:
addGLEventListener in interface GLAutoDrawable

removeGLEventListener

public void removeGLEventListener(GLEventListener listener)
Description copied from interface: GLAutoDrawable
Removes a GLEventListener from this drawable. Note that if this is done from within a particular drawable's GLEventListener handler (reshape, display, etc.) that it is not guaranteed that all other listeners will be evaluated properly during this update cycle.

Specified by:
removeGLEventListener in interface GLAutoDrawable

runCurrentThreadPumpMessage

public static void runCurrentThreadPumpMessage()
Deprecated. EXPERIMENTAL, semantic is about to be removed after further verification.

See Also:
setRunPumpMessages(boolean)

display

public void display()
Description copied from interface: GLAutoDrawable
Causes OpenGL rendering to be performed for this GLAutoDrawable by calling display(..) for all registered GLEventListeners. Called automatically by the window system toolkit upon receiving a repaint() request. this routine may be called manually for better control over the rendering process. It is legal to call another GLAutoDrawable's display method from within the display(..) callback.

In case of a new generated OpenGL context, the implementation shall call init(..) for all registered GLEventListeners before making the actual display(..) calls, in case this has not been done yet.

Specified by:
display in interface GLAutoDrawable

setAutoSwapBufferMode

public void setAutoSwapBufferMode(boolean onOrOff)
This implementation uses a static value

Specified by:
setAutoSwapBufferMode in interface GLAutoDrawable

getAutoSwapBufferMode

public boolean getAutoSwapBufferMode()
This implementation uses a static value

Specified by:
getAutoSwapBufferMode in interface GLAutoDrawable

swapBuffers

public void swapBuffers()
Description copied from interface: GLDrawable
Swaps the front and back buffers of this drawable. For GLAutoDrawable implementations, when automatic buffer swapping is enabled (as is the default), this method is called automatically and should not be called by the end user.

Specified by:
swapBuffers in interface GLDrawable

getStartTime

public long getStartTime()

getCurrentTime

public long getCurrentTime()

getDuration

public long getDuration()

getTotalFrames

public int getTotalFrames()

getNativeWindow

public NativeWindow getNativeWindow()
Specified by:
getNativeWindow in interface GLDrawable

lockSurface

public int lockSurface()
                throws NativeWindowException
Description copied from interface: NativeWindow
Lock the surface of this native window

The window handle, see NativeWindow.getWindowHandle(), and the surface handle, see NativeWindow.lockSurface(),
shall be set and be valid after a successfull call, ie a return value other than NativeWindow.LOCK_SURFACE_NOT_READY.

The semantics of the underlying native locked resource may be related to the ToolkitLock one. Hence it is important that implementation of both harmonize well.
The implementation may want to aquire the ToolkitLock first to become it's owner before proceeding with it's actual surface lock.

Specified by:
lockSurface in interface NativeWindow
Overrides:
lockSurface in class Window
Returns:
NativeWindow.LOCK_SUCCESS, NativeWindow.LOCK_SURFACE_CHANGED or NativeWindow.LOCK_SURFACE_NOT_READY.
Throws:
NativeWindowException - if surface is already locked
See Also:
ToolkitLock

unlockSurface

public void unlockSurface()
Description copied from interface: NativeWindow
Unlock the surface of this native window Shall not modify the window handle, see NativeWindow.getWindowHandle(), or the surface handle, see NativeWindow.lockSurface()

Specified by:
unlockSurface in interface NativeWindow
Overrides:
unlockSurface in class Window
See Also:
NativeWindow.lockSurface(), ToolkitLock

isSurfaceLocked

public boolean isSurfaceLocked()
Description copied from interface: NativeWindow
Return if surface is locked

Specified by:
isSurfaceLocked in interface NativeWindow
Overrides:
isSurfaceLocked in class Window

getLockedStack

public Exception getLockedStack()
Description copied from interface: NativeWindow
Return the lock-exception, or null if not locked. The lock-exception is created at NativeWindow.lockSurface() and hence holds the locker's call stack.

Specified by:
getLockedStack in interface NativeWindow
Overrides:
getLockedStack in class Window

surfaceSwap

public boolean surfaceSwap()
Description copied from interface: NativeWindow
Provide a mechanism to utilize custom (pre-) swap surface code. This method is called before the render toolkit (e.g. JOGL) swaps the buffer/surface. The implementation may itself apply the swapping, in which case true shall be returned.

Specified by:
surfaceSwap in interface NativeWindow
Overrides:
surfaceSwap in class Window
Returns:
true if this method completed swapping the surface, otherwise false, in which case eg the GLDrawable implementation has to swap the code.

surfaceUpdated

public void surfaceUpdated()
Description copied from interface: NativeWindow
Method invoked after the render toolkit (e.g. JOGL) swapped/changed the buffer/surface.

Specified by:
surfaceUpdated in interface NativeWindow
Overrides:
surfaceUpdated in class Window

getWindowHandle

public long getWindowHandle()
Description copied from interface: NativeWindow
Returns the window handle for this NativeWindow.

The window handle should be set/update by NativeWindow.lockSurface(), where NativeWindow.unlockSurface() is not allowed to modify it.
After NativeWindow.unlockSurface() it is no more guaranteed that the window handle is still valid.

The window handle shall reflect the platform one for all window related operations, e.g. open, close, resize.

On X11 this returns an entity of type Window.
On Microsoft Windows this returns an entity of type HWND.

Specified by:
getWindowHandle in interface NativeWindow
Overrides:
getWindowHandle in class Window

getSurfaceHandle

public long getSurfaceHandle()
Description copied from interface: NativeWindow
Returns the handle to the surface for this NativeWindow.

The surface handle should be set/update by NativeWindow.lockSurface(), where NativeWindow.unlockSurface() is not allowed to modify it. After NativeWindow.unlockSurface() it is no more guaranteed that the surface handle is still valid. The surface handle shall reflect the platform one for all drawable surface operations, e.g. opengl, swap-buffer.

On X11 this returns an entity of type Window, since there is no differentiation of surface and window there.
On Microsoft Windows this returns an entity of type HDC.

Specified by:
getSurfaceHandle in interface NativeWindow
Overrides:
getSurfaceHandle in class Window

createContext

public GLContext createContext(GLContext shareWith)
Description copied from interface: GLDrawable
Creates a new context for drawing to this drawable that will optionally share display lists and other server-side OpenGL objects with the specified GLContext.

The GLContext share need not be associated with this GLDrawable and may be null if sharing of display lists and other objects is not desired. See the note in the overview documentation on context sharing.

Specified by:
createContext in interface GLDrawable

setRealized

public void setRealized(boolean realized)
Description copied from interface: GLDrawable
Indicates to on-screen GLDrawable implementations whether the underlying window has been created and can be drawn into. End users do not need to call this method; it is not necessary to call setRealized on a GLCanvas, a GLJPanel, or a GLPbuffer, as these perform the appropriate calls on their underlying GLDrawables internally.

Developers implementing new OpenGL components for various window toolkits need to call this method against GLDrawables obtained from the GLDrawableFactory via the GLDrawableFactory.getGLDrawable() method. It must typically be called with an argument of true when the component associated with the GLDrawable is realized and with an argument of false just before the component is unrealized. For the AWT, this means calling setRealized(true) in the addNotify method and with an argument of false in the removeNotify method.

GLDrawable implementations should handle multiple cycles of setRealized(true) / setRealized(false) calls. Most, if not all, Java window toolkits have a persistent object associated with a given component, regardless of whether that component is currently realized. The GLDrawable object associated with a particular component is intended to be similarly persistent. A GLDrawable is intended to be created for a given component when it is constructed and live as long as that component. setRealized allows the GLDrawable to re-initialize and destroy any associated resources as the component becomes realized and unrealized, respectively.

With an argument of true, the minimum implementation shall call NativeWindow's lockSurface() and if successfull:


This is important since NativeWindow's lockSurface() ensures resolving the window/surface handles, and the drawable's GLCapabilities might have changed.

Calling this method has no other effects. For example, if removeNotify is called on a Canvas implementation for which a GLDrawable has been created, it is also necessary to destroy all OpenGL contexts associated with that GLDrawable. This is not done automatically by the implementation.

Specified by:
setRealized in interface GLDrawable

getChosenGLCapabilities

public GLCapabilities getChosenGLCapabilities()
Description copied from interface: GLDrawable
Fetches the GLCapabilities corresponding to the chosen OpenGL capabilities (pixel format / visual / GLProfile) for this drawable.
On some platforms, the pixel format is not directly associated with the drawable; a best attempt is made to return a reasonable value in this case.
This object shall be directly associated to the attached NativeWindow's AbstractGraphicsConfiguration, and if changes are necessary, they should reflect those as well.

Specified by:
getChosenGLCapabilities in interface GLDrawable
Returns:
A copy of the queried object.

getGLProfile

public GLProfile getGLProfile()
Description copied from interface: GLDrawable
Fetches the GLProfile for this drawable. Returns the GLProfile object, no copy.

Specified by:
getGLProfile in interface GLDrawable


Copyright 2005 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.