com.jogamp.newt.opengl
Class GLWindow

java.lang.Object
  extended by com.jogamp.newt.Window
      extended by com.jogamp.newt.opengl.GLWindow
All Implemented Interfaces:
NativeWindow, SurfaceUpdatedListener, 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.

This implementation does not make the OpenGL context current
before calling the various input EventListener callbacks (MouseListener, KeyListener, etc.).
This design decision is made to favor a more performant and simplified implementation, as well as the event dispatcher shall be allowed not having a notion about OpenGL.


Field Summary
 
Fields inherited from class com.jogamp.newt.Window
ClickTimeout, config, DEBUG_IMPLEMENTATION, DEBUG_KEY_EVENT, DEBUG_MOUSE_EVENT, DEBUG_WINDOW_EVENT, eventMask, fullscreen, height, 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 ownerOfWinScrDpy)
          Constructor.
 
Method Summary
 void addGLEventListener(GLEventListener listener)
          Adds a GLEventListener to this drawable.
 void addKeyListener(KeyListener l)
           
 void addMouseListener(MouseListener l)
           
 void addSurfaceUpdatedListener(SurfaceUpdatedListener 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 destroy(boolean sendDisposeEvent)
           
 void display()
          Causes OpenGL rendering to be performed for this GLAutoDrawable by calling display(..) for all registered GLEventListeners.
 void display(boolean forceReshape)
           
protected  void dispose(boolean regenerate, boolean sendEvent)
           
 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()
           
 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.
 SurfaceUpdatedListener[] getSurfaceUpdatedListener()
           
 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()
          Recursive and blocking lockSurface() implementation
 void removeAllSurfaceUpdatedListener()
           
 void removeGLEventListener(GLEventListener listener)
          Removes a GLEventListener from this drawable.
 void removeKeyListener(KeyListener l)
           
 void removeMouseListener(MouseListener l)
           
 void removeSurfaceUpdatedListener(SurfaceUpdatedListener l)
           
 void removeWindowListener(WindowListener l)
           
 void requestFocus()
           
 void sendEvent(NEWTEvent e)
           
 void setAutoSwapBufferMode(boolean onOrOff)
          This implementation uses a static value
 void setContext(GLContext newCtx)
          Associate a new context to this drawable.
 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.
This call is ignored if in fullscreen mode.
 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
This call is ignored if in fullscreen mode.
 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(Object updater, NativeWindow window0, long when)
          Notification of a surface update event.
 void swapBuffers()
          Swaps the front and back buffers of this drawable.
 String toString()
           
 void unlockSurface()
          Recursive and unblocking unlockSurface() implementation
 
Methods inherited from class com.jogamp.newt.Window
addPaintListener, clearEventMask, create, create, getDisplayHandle, getGraphicsConfiguration, getScreenIndex, getSurfaceLockOwner, getWrappedWindow, hasDeviceChanged, invalidate, removePaintListener, sendKeyEvent, sendKeyEvent, sendMouseEvent, sendMouseEvent, sendPaintEvent, sendPaintEvent, sendWindowEvent, sendWindowEvent, setAutoDrawableClient, toHexString, toHexString, windowDestroyed, windowDestroyNotify, wrapHandle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GLWindow

protected GLWindow(Window window,
                   boolean ownerOfWinScrDpy)
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 GLWindow#runCurrentThreadPumpMessage()
This could not have been verified. No measurable difference could have been recognized.

Best performance has been achieved with one GLWindow per thread.
Enabling local pump messages while using the EDT, NewtFactory.setUseEDT(boolean), will result in an exception.


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,
                       boolean sendEvent)

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

destroy

public void destroy(boolean sendDisposeEvent)
Overrides:
destroy in class Window
Parameters:
sendDisposeEvent - should be false in a [time,reliable] critical shutdown

getPerfLogEnabled

public boolean getPerfLogEnabled()

enablePerfLog

public void enablePerfLog(boolean v)

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

requestFocus

public void requestFocus()
Overrides:
requestFocus 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
This call is ignored if in fullscreen mode.

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.
This call is ignored if in fullscreen mode.

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

addSurfaceUpdatedListener

public void addSurfaceUpdatedListener(SurfaceUpdatedListener l)
Overrides:
addSurfaceUpdatedListener in class Window

removeSurfaceUpdatedListener

public void removeSurfaceUpdatedListener(SurfaceUpdatedListener l)
Overrides:
removeSurfaceUpdatedListener in class Window

removeAllSurfaceUpdatedListener

public void removeAllSurfaceUpdatedListener()
Overrides:
removeAllSurfaceUpdatedListener in class Window

getSurfaceUpdatedListener

public SurfaceUpdatedListener[] getSurfaceUpdatedListener()
Overrides:
getSurfaceUpdatedListener in class Window

surfaceUpdated

public void surfaceUpdated(Object updater,
                           NativeWindow window0,
                           long when)
Description copied from interface: SurfaceUpdatedListener
Notification of a surface update event.

Specified by:
surfaceUpdated in interface SurfaceUpdatedListener
Overrides:
surfaceUpdated in class Window
Parameters:
updater - is the caller object who updated the surface, e.g. a JOGL GLDrawable.
window0 - the NativeWindow, which surface is updated
when - the time in ms, when the surface was updated

sendEvent

public void sendEvent(NEWTEvent e)
Overrides:
sendEvent 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

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

display

public void display(boolean forceReshape)

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 class: Window
Recursive and blocking lockSurface() implementation

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 class: Window
Recursive and unblocking unlockSurface() implementation

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.

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 2010 JogAmp Community.