net.java.games.jogl.impl

Class GLContext

Known Direct Subclasses:
X11GLContext

public abstract class GLContext
extends java.lang.Object

Field Summary

protected static boolean
DEBUG
protected static boolean
NO_FREE
protected static boolean
VERBOSE
protected boolean
autoSwapBuffers
protected GLCapabilities
capabilities
protected GLCapabilitiesChooser
chooser
protected Component
component
protected boolean
deferredDestroy
protected Runnable
deferredReshapeAction
protected boolean
deferredSetRealized
protected FunctionAvailabilityCache
functionAvailability
protected GL
gl
protected GLU
glu
protected static GLUProcAddressTable
gluProcAddressTable
protected static boolean
haveResetGLUProcAddressTable
protected boolean
noAutoRedraw
protected int
pendingOffscreenHeight
protected boolean
pendingOffscreenResize
protected int
pendingOffscreenWidth
protected static ThreadLocal
perThreadContextStack
protected static ThreadLocal
perThreadRenderingContext
protected static ThreadLocal
perThreadSavedCurrentContext
protected boolean
realized
protected Thread
renderingThread
protected boolean
willSetRenderingThread

Constructor Summary

GLContext(Component component, GLCapabilities capabilities, GLCapabilitiesChooser chooser, GLContext shareWith)

Method Summary

abstract void
bindPbufferToTexture()
Pbuffer support; given that this is a GLContext associated with a pbuffer, binds this pbuffer to its texture target.
abstract boolean
canCreatePbufferContext()
Pbuffer support; indicates whether this context is capable of creating a subordinate pbuffer context (distinct from an "offscreen context", which is typically software-rendered on all platforms).
protected abstract GL
createGL()
Create the GL for this context.
abstract GLContext
createPbufferContext(GLCapabilities capabilities, int initialWidth, int initialHeight)
Pbuffer support; creates a subordinate GLContext for a pbuffer associated with this context.
void
destroy()
Destroys the underlying OpenGL context and changes the realized state to false.
protected abstract void
destroyImpl()
Destroys the underlying OpenGL context.
protected abstract long
dynamicLookupFunction(String glFuncName)
Dynamically looks up the given function.
protected abstract void
free()
Frees the OpenGL context.
boolean
getAutoSwapBufferMode()
int
getFloatingPointMode()
Indicates which floating-point pbuffer implementation is in use.
GL
getGL()
GLU
getGLU()
boolean
getNoAutoRedrawMode()
abstract int
getOffscreenContextHeight()
Only called for offscreen contexts; needed by glReadPixels
abstract int
getOffscreenContextPixelDataType()
Only called for offscreen contexts; needed by glReadPixels
abstract int
getOffscreenContextReadBuffer()
Only called for offscreen contexts; returns the buffer from which to read pixels (GL.GL_FRONT or GL.GL_BACK).
abstract int
getOffscreenContextWidth()
Only called for offscreen contexts; needed by glReadPixels
protected static GLContextStack
getPerThreadContextStack()
Support for recursive makeCurrent() calls as well as calling other drawables' display() methods from within another one's
protected static GLContext
getPerThreadSavedCurrentContext()
Support for setRenderingThread()'s optimized context handling
protected static Runnable
getPerThreadSavedInitAction()
Support for setRenderingThread()'s optimized context handling
abstract String
getPlatformExtensionsString()
Returns a non-null (but possibly empty) string containing the space-separated list of available platform-dependent (e.g., WGL, GLX) extensions.
boolean
getRealized()
Indicates whether the component associated with this context has been realized.
Thread
getRenderingThread()
protected static String
getThreadName()
void
invokeGL(Runnable runnable, boolean isReshape, Runnable initAction)
Runs the given runnable with this OpenGL context valid.
abstract boolean
isCreated()
Indicates whether the underlying OpenGL context has been created.
boolean
isExtensionAvailable(String glExtensionName)
Returns true if the specified OpenGL extension can be successfully called using this GL context given the current host (OpenGL client) and display (OpenGL server) configuration.
protected boolean
isFunctionAvailable(String glFunctionName)
Returns true if the specified OpenGL core- or extension-function can be successfully called using this GL context given the current host (OpenGL client) and display (OpenGL server) configuration.
protected abstract boolean
isOffscreen()
Hook indicating whether the concrete GLContext implementation is offscreen and therefore whether we need to process resize requests.
boolean
isRealized()
protected abstract boolean
makeCurrent(Runnable initAction)
Attempts to make the GL context current.
protected abstract String
mapToRealGLExtensionName(String glExtensionName)
Maps the given "platform-independent" extension name to a real function name.
protected abstract String
mapToRealGLFunctionName(String glFunctionName)
Maps the given "platform-independent" function name to a real function name.
abstract boolean
offscreenImageNeedsVerticalFlip()
On some platforms the mismatch between OpenGL's coordinate system (origin at bottom left) and the window system's coordinate system (origin at top left) necessitates a vertical flip of pixels read from offscreen contexts.
abstract void
releasePbufferFromTexture()
Pbuffer support; given that this is a GLContext associated with a pbuffer, releases this pbuffer from its texture target.
protected void
resetGLFunctionAvailability()
Resets the cache of which GL functions are available for calling through this context.
protected void
resetProcAddressTable(Object table)
Helper routine which resets a ProcAddressTable generated by the GLEmitter by looking up anew all of its function pointers.
void
resizeOffscreenContext(int newWidth, int newHeight)
Routine needed only for offscreen contexts in order to resize the underlying bitmap.
void
setAutoSwapBufferMode(boolean autoSwapBuffers)
void
setGL(GL gl)
void
setGLU(GLU glu)
void
setNoAutoRedrawMode(boolean noAutoRedraw)
protected static void
setPerThreadSavedCurrentContext(GLContext context, Runnable initAction)
Support for setRenderingThread()'s optimized context handling
void
setRealized()
Inform the system that the associated heavyweight widget has been realized and that it is safe to create an associated OpenGL context.
protected void
setRealized(boolean realized)
Sets only the "realized" bit.
void
setRenderingThread(Thread currentThreadOrNull, Runnable initAction)
void
setSwapInterval(int interval)
abstract void
swapBuffers()
Swaps the buffers of the OpenGL context if necessary.
void
willSetRenderingThread()
Gives a hint to the context that setRenderingThread will be called in the near future; causes redraws to be halted.

Field Details

DEBUG

protected static final boolean DEBUG

NO_FREE

protected static final boolean NO_FREE

VERBOSE

protected static final boolean VERBOSE

autoSwapBuffers

protected boolean autoSwapBuffers

capabilities

protected GLCapabilities capabilities

chooser

protected GLCapabilitiesChooser chooser

component

protected Component component

deferredDestroy

protected boolean deferredDestroy

deferredReshapeAction

protected Runnable deferredReshapeAction

deferredSetRealized

protected boolean deferredSetRealized

functionAvailability

protected FunctionAvailabilityCache functionAvailability

gl

protected GL gl

glu

protected GLU glu

gluProcAddressTable

protected static final GLUProcAddressTable gluProcAddressTable

haveResetGLUProcAddressTable

protected static boolean haveResetGLUProcAddressTable

noAutoRedraw

protected boolean noAutoRedraw

pendingOffscreenHeight

protected int pendingOffscreenHeight

pendingOffscreenResize

protected boolean pendingOffscreenResize

pendingOffscreenWidth

protected int pendingOffscreenWidth

perThreadContextStack

protected static final ThreadLocal perThreadContextStack

perThreadRenderingContext

protected static final ThreadLocal perThreadRenderingContext

perThreadSavedCurrentContext

protected static final ThreadLocal perThreadSavedCurrentContext

realized

protected boolean realized

renderingThread

protected Thread renderingThread

willSetRenderingThread

protected boolean willSetRenderingThread

Constructor Details

GLContext

public GLContext(Component component,
                 GLCapabilities capabilities,
                 GLCapabilitiesChooser chooser,
                 GLContext shareWith)

Method Details

bindPbufferToTexture

public abstract void bindPbufferToTexture()
Pbuffer support; given that this is a GLContext associated with a pbuffer, binds this pbuffer to its texture target.

canCreatePbufferContext

public abstract boolean canCreatePbufferContext()
Pbuffer support; indicates whether this context is capable of creating a subordinate pbuffer context (distinct from an "offscreen context", which is typically software-rendered on all platforms).

createGL

protected abstract GL createGL()
Create the GL for this context.

createPbufferContext

public abstract GLContext createPbufferContext(GLCapabilities capabilities,
                                               int initialWidth,
                                               int initialHeight)
Pbuffer support; creates a subordinate GLContext for a pbuffer associated with this context.

destroy

public void destroy()
            throws GLException
Destroys the underlying OpenGL context and changes the realized state to false. This should be called when the widget is being destroyed.

destroyImpl

protected abstract void destroyImpl()
            throws GLException
Destroys the underlying OpenGL context.

dynamicLookupFunction

protected abstract long dynamicLookupFunction(String glFuncName)
Dynamically looks up the given function.

free

protected abstract void free()
            throws GLException
Frees the OpenGL context. All error conditions cause a GLException to be thrown.

getAutoSwapBufferMode

public boolean getAutoSwapBufferMode()

getFloatingPointMode

public int getFloatingPointMode()
            throws GLException
Indicates which floating-point pbuffer implementation is in use. Returns one of GLPbuffer.APPLE_FLOAT, GLPbuffer.ATI_FLOAT, or GLPbuffer.NV_FLOAT.

getGL

public GL getGL()

getGLU

public GLU getGLU()

getNoAutoRedrawMode

public boolean getNoAutoRedrawMode()

getOffscreenContextHeight

public abstract int getOffscreenContextHeight()
Only called for offscreen contexts; needed by glReadPixels

getOffscreenContextPixelDataType

public abstract int getOffscreenContextPixelDataType()
Only called for offscreen contexts; needed by glReadPixels

getOffscreenContextReadBuffer

public abstract int getOffscreenContextReadBuffer()
Only called for offscreen contexts; returns the buffer from which to read pixels (GL.GL_FRONT or GL.GL_BACK).

getOffscreenContextWidth

public abstract int getOffscreenContextWidth()
Only called for offscreen contexts; needed by glReadPixels

getPerThreadContextStack

protected static GLContextStack getPerThreadContextStack()
Support for recursive makeCurrent() calls as well as calling other drawables' display() methods from within another one's

getPerThreadSavedCurrentContext

protected static GLContext getPerThreadSavedCurrentContext()
Support for setRenderingThread()'s optimized context handling

getPerThreadSavedInitAction

protected static Runnable getPerThreadSavedInitAction()
Support for setRenderingThread()'s optimized context handling

getPlatformExtensionsString

public abstract String getPlatformExtensionsString()
Returns a non-null (but possibly empty) string containing the space-separated list of available platform-dependent (e.g., WGL, GLX) extensions. Can only be called while this context is current.

getRealized

public boolean getRealized()
Indicates whether the component associated with this context has been realized.

getRenderingThread

public Thread getRenderingThread()

getThreadName

protected static String getThreadName()

invokeGL

public void invokeGL(Runnable runnable,
                     boolean isReshape,
                     Runnable initAction)
            throws GLException
Runs the given runnable with this OpenGL context valid.

isCreated

public abstract boolean isCreated()
Indicates whether the underlying OpenGL context has been created. This is used to manage sharing of display lists and textures between contexts.

isExtensionAvailable

public boolean isExtensionAvailable(String glExtensionName)
Parameters:
glExtensionName - the name of the OpenGL extension (e.g., "GL_VERTEX_PROGRAM_ARB").

isFunctionAvailable

protected boolean isFunctionAvailable(String glFunctionName)
Parameters:
glFunctionName - the name of the OpenGL function (e.g., use "glPolygonOffsetEXT" to check if the GL.glPolygonOffsetEXT(float,float) is available).

isOffscreen

protected abstract boolean isOffscreen()
Hook indicating whether the concrete GLContext implementation is offscreen and therefore whether we need to process resize requests.

isRealized

public boolean isRealized()

makeCurrent

protected abstract boolean makeCurrent(Runnable initAction)
            throws GLException
Attempts to make the GL context current. If necessary, creates a context and calls the initAction once the context is current. Most error conditions cause an exception to be thrown, except for the case where the context can not be created because the component has not yet been visualized. In this case makeCurrent returns false and the caller should abort any OpenGL event processing and instead return immediately.

mapToRealGLExtensionName

protected abstract String mapToRealGLExtensionName(String glExtensionName)
Maps the given "platform-independent" extension name to a real function name. Currently this is only used to map "GL_ARB_pbuffer" and "GL_ARB_pixel_format" to "WGL_ARB_pbuffer" and "WGL_ARB_pixel_format" (not yet mapped to X11).

mapToRealGLFunctionName

protected abstract String mapToRealGLFunctionName(String glFunctionName)
Maps the given "platform-independent" function name to a real function name. Currently this is only used to map "glAllocateMemoryNV" and associated routines to wglAllocateMemoryNV / glXAllocateMemoryNV.

offscreenImageNeedsVerticalFlip

public abstract boolean offscreenImageNeedsVerticalFlip()
On some platforms the mismatch between OpenGL's coordinate system (origin at bottom left) and the window system's coordinate system (origin at top left) necessitates a vertical flip of pixels read from offscreen contexts.

releasePbufferFromTexture

public abstract void releasePbufferFromTexture()
Pbuffer support; given that this is a GLContext associated with a pbuffer, releases this pbuffer from its texture target.

resetGLFunctionAvailability

protected void resetGLFunctionAvailability()

resetProcAddressTable

protected void resetProcAddressTable(Object table)
Helper routine which resets a ProcAddressTable generated by the GLEmitter by looking up anew all of its function pointers.

resizeOffscreenContext

public void resizeOffscreenContext(int newWidth,
                                   int newHeight)
Routine needed only for offscreen contexts in order to resize the underlying bitmap. Called by GLJPanel.

setAutoSwapBufferMode

public void setAutoSwapBufferMode(boolean autoSwapBuffers)

setGL

public void setGL(GL gl)

setGLU

public void setGLU(GLU glu)

setNoAutoRedrawMode

public void setNoAutoRedrawMode(boolean noAutoRedraw)

setPerThreadSavedCurrentContext

protected static void setPerThreadSavedCurrentContext(GLContext context,
                                                      Runnable initAction)
Support for setRenderingThread()'s optimized context handling

setRealized

public void setRealized()
Inform the system that the associated heavyweight widget has been realized and that it is safe to create an associated OpenGL context. If the widget is later destroyed then destroy() should be called, which will cause the underlying OpenGL context to be destroyed as well as the realized bit to be set to false.

setRealized

protected void setRealized(boolean realized)
Sets only the "realized" bit. Should be called by subclasses from within the destroy() implementation.

setRenderingThread

public void setRenderingThread(Thread currentThreadOrNull,
                               Runnable initAction)

setSwapInterval

public void setSwapInterval(int interval)

swapBuffers

public abstract void swapBuffers()
            throws GLException
Swaps the buffers of the OpenGL context if necessary. All error conditions cause a GLException to be thrown.

willSetRenderingThread

public void willSetRenderingThread()
Gives a hint to the context that setRenderingThread will be called in the near future; causes redraws to be halted. This is a workaround for bugs in NVidia's drivers and is used only by the Animator class.