com.jogamp.opengl.impl
Class GLContextImpl

java.lang.Object
  extended by javax.media.opengl.GLContext
      extended by com.jogamp.opengl.impl.GLContextImpl
Direct Known Subclasses:
EGLContext, MacOSXCGLContext, WindowsWGLContext, X11GLXContext

public abstract class GLContextImpl
extends GLContext


Field Summary
protected  int currentSwapInterval
           
protected static boolean DEBUG
           
protected  GLDrawableImpl drawable
           
protected  GLDrawableImpl drawableRead
           
protected  com.jogamp.opengl.impl.ExtensionAvailabilityCache extensionAvailability
           
protected  GL gl
           
protected  boolean hasNativeES2Methods
           
protected  GLContextLock lock
           
protected static Object mappedContextTypeObjectLock
           
protected static HashMap mappedExtensionAvailabilityCache
           
protected static HashMap mappedGLProcAddress
           
protected static HashMap mappedGLXProcAddress
           
 
Fields inherited from class javax.media.opengl.GLContext
CONTEXT_CURRENT, CONTEXT_CURRENT_NEW, CONTEXT_NOT_CURRENT, contextHandle, CTX_IS_ARB_CREATED, CTX_OPTION_ANY, CTX_OPTION_DEBUG, CTX_OPTION_FORWARD, CTX_PROFILE_COMPAT, CTX_PROFILE_CORE, CTX_PROFILE_ES, ctxMajorVersion, ctxMinorVersion, ctxOptions, ctxVersionString, DEBUG0, deviceVersionAvailable, GL_VERSIONS
 
Constructor Summary
GLContextImpl(GLDrawableImpl drawable, 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.
 void copy(GLContext source, int mask)
          Copies selected groups of OpenGL state variables from the supplied source context into this one.
protected abstract  void copyImpl(GLContext source, int mask)
           
protected  long createContextARB(long share, boolean direct, int[] major, int[] minor, int[] ctp)
          Platform independent part of using the ARB_create_context mechanism to create a context.
The implementation of #create shall use this protocol in case the platform supports ARB_create_context.
This method may call createContextARBImpl(long, boolean, int, int, int) and destroyContextARBImpl(long).
protected abstract  long createContextARBImpl(long share, boolean direct, int ctxOptionFlags, int major, int minor)
          Platform dependent but harmonized implementation of the ARB_create_context mechanism to create a context.
This method is called from createContextARB(long, boolean, int[], int[], int[]).
The implementation shall verify this context with a MakeContextCurrent call.
The implementation shall leave the context current.
protected  GL createGL(GLProfile glp)
          Create the GL for this context.
protected abstract  boolean createImpl()
           
 void destroy()
          Destroys this OpenGL context and frees its associated resources.
protected abstract  void destroyContextARBImpl(long context)
          Destroy the context created by createContextARBImpl(long, boolean, int, int, int).
protected abstract  void destroyImpl()
           
 GLBufferSizeTracker getBufferSizeTracker()
           
 GLBufferStateTracker getBufferStateTracker()
           
protected  String getContextFQN()
           
protected static String getContextFQN(AbstractGraphicsDevice device, int major, int minor, int ctp)
           
 GLDrawableImpl getDrawableImpl()
           
protected abstract  Map getExtensionNameMap()
           
 int getFloatingPointMode()
          Indicates which floating-point pbuffer implementation is in use.
protected abstract  Map getFunctionNameMap()
           
 GL getGL()
          Returns the GL pipeline object for this GLContext.
 GLDrawable getGLDrawable()
          Returns the GLDrawable to which this context may be used to draw.
 String getGLExtensionsString()
          Returns a non-null (but possibly empty) string containing the space-separated list of available extensions.
 ProcAddressTable getGLProcAddressTable()
           
 GLDrawable getGLReadDrawable()
          Returns the read GLDrawable this context uses for read framebuffer operations.
 GLStateTracker getGLStateTracker()
           
abstract  int getOffscreenContextPixelDataType()
          Only called for offscreen contexts; needed by glReadPixels
 String getPlatformExtensionsString()
          Returns a non-null (but possibly empty) string containing the space-separated list of available platform-dependent (e.g., WGL, GLX) extensions.
abstract  ProcAddressTable getPlatformExtProcAddressTable()
          Shall return the platform extension ProcAddressTable, ie for GLXExt, EGLExt, ..
abstract  Object getPlatformGLExtensions()
           
 int getSwapInterval()
           
abstract  ByteBuffer glAllocateMemoryNV(int arg0, float arg1, float arg2, float arg3)
           
 boolean hasNativeES2Methods()
           
 boolean hasWaiters()
           
 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.
 boolean isExtensionCacheInitialized()
           
 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.
 boolean isSynchronized()
          Returns true if 'makeCurrent' will exhibit synchronized behavior.
 int makeCurrent()
          MakeCurrent functionality, which also issues the creation of the actual OpenGL context.
The complete callgraph for general OpenGL context creation is:
makeCurrent() GLContextImpl makeCurrentImpl(boolean) Platform Implementation #create Platform Implementation If ARB_create_context is supported: createContextARB(long, boolean, int[], int[], int[]) GLContextImpl createContextARBImpl(long, boolean, int, int, int) Platform Implementation
Once at startup, ie triggered by the singleton constructor of a GLDrawableFactoryImpl specialization, calling createContextARB(long, boolean, int[], int[], int[]) will query all available OpenGL versions:
FOR ALL GL* DO: createContextARBMapVersionsAvailable(int, boolean) createContextARBVersions(long, boolean, int, int, int, int, int, int[], int[]) #mapVersionAvailable
protected abstract  void makeCurrentImpl(boolean newCreatedContext)
           
protected  int makeCurrentLocking()
           
protected  String mapToRealGLExtensionName(String glExtensionName)
          Maps the given "platform-independent" extension name to a real function name.
protected  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.
 void release()
          Releases control of this GLContext from the current thread.
protected abstract  void releaseImpl()
           
abstract  void releasePbufferFromTexture()
          Pbuffer support; given that this is a GLContext associated with a pbuffer, releases this pbuffer from its texture target.
protected  void resetProcAddressTable(ProcAddressTable table)
          Helper routine which resets a ProcAddressTable generated by the GLEmitter by looking up anew all of its function pointers.
protected  void resetStates()
           
 void setBufferSizeTracker(GLBufferSizeTracker bufferSizeTracker)
           
 GL setGL(GL gl)
          Sets the GL pipeline object for this GLContext.
protected  void setGLFunctionAvailability(boolean force, int major, int minor, int ctp)
          Sets the OpenGL implementation class and the cache of which GL functions are available for calling through this context.
 void setGLReadDrawable(GLDrawable read)
          Set the read GLDrawable for read framebuffer operations.
The caller should query if this feature is supported via GLContext.isGLReadDrawableAvailable().
 void setSwapInterval(int interval)
           
protected  void setSwapIntervalImpl(int interval)
           
 void setSynchronized(boolean isSynchronized)
          Determines whether 'makeCurrent' will exhibit synchronized behavior.
protected  void update()
           
protected abstract  void updateGLXProcAddressTable()
          Updates the platform's 'GLX' function cache
 
Methods inherited from class javax.media.opengl.GLContext
append, compose8bit, composed8BitToString, decrementGLVersion, getAttachedObject, getAttachedObject, getAvailableGLVersion, getAvailableGLVersion, getAvailableGLVersionAsString, getAvailableGLVersionsSet, getComposed8bit, getCurrent, getCurrentGL, getDeviceVersionAvailableKey, getGLVersion, getGLVersion, getGLVersionMajor, getGLVersionMinor, getHandle, getMaxMajor, getMaxMinor, getThreadName, hasGLSL, isCreated, isCreatedWithARBMethod, isCurrent, isGL2, isGL2Available, isGL2ES1, isGL2ES2, isGL2GL3, isGL3, isGL3Available, isGL3bc, isGL3bcAvailable, isGL4, isGL4Available, isGL4bc, isGL4bcAvailable, isGLCompatibilityProfile, isGLCoreProfile, isGLEmbeddedProfile, isGLES, isGLES1, isGLES1Available, isGLES2, isGLES2Available, isGLForwardCompatible, isGLReadDrawableAvailable, isGLVersionAvailable, isValidGLVersion, mapAvailableGLVersion, putAttachedObject, putAttachedObject, setAvailableGLVersionsSet, setCurrent, toHexString, toHexString, toString, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEBUG

protected static final boolean DEBUG

lock

protected GLContextLock lock

extensionAvailability

protected com.jogamp.opengl.impl.ExtensionAvailabilityCache extensionAvailability

drawable

protected GLDrawableImpl drawable

drawableRead

protected GLDrawableImpl drawableRead

gl

protected GL gl

mappedContextTypeObjectLock

protected static final Object mappedContextTypeObjectLock

mappedExtensionAvailabilityCache

protected static final HashMap mappedExtensionAvailabilityCache

mappedGLProcAddress

protected static final HashMap mappedGLProcAddress

mappedGLXProcAddress

protected static final HashMap mappedGLXProcAddress

currentSwapInterval

protected int currentSwapInterval

hasNativeES2Methods

protected boolean hasNativeES2Methods
Constructor Detail

GLContextImpl

public GLContextImpl(GLDrawableImpl drawable,
                     GLContext shareWith)
Method Detail

resetStates

protected void resetStates()
Overrides:
resetStates in class GLContext

setGLReadDrawable

public final void setGLReadDrawable(GLDrawable read)
Description copied from class: GLContext
Set the read GLDrawable for read framebuffer operations.
The caller should query if this feature is supported via GLContext.isGLReadDrawableAvailable().

Specified by:
setGLReadDrawable in class GLContext
Parameters:
read - the read GLDrawable for read framebuffer operations. If null is passed, the default write drawable will be set.
See Also:
GLContext.isGLReadDrawableAvailable(), GLContext.getGLReadDrawable()

getGLReadDrawable

public final GLDrawable getGLReadDrawable()
Description copied from class: GLContext
Returns the read GLDrawable this context uses for read framebuffer operations.

Specified by:
getGLReadDrawable in class GLContext
See Also:
GLContext.isGLReadDrawableAvailable(), GLContext.setGLReadDrawable(javax.media.opengl.GLDrawable)

getGLDrawable

public final GLDrawable getGLDrawable()
Description copied from class: GLContext
Returns the GLDrawable to which this context may be used to draw.

Specified by:
getGLDrawable in class GLContext

getDrawableImpl

public final GLDrawableImpl getDrawableImpl()

getGL

public final GL getGL()
Description copied from class: GLContext
Returns the GL pipeline object for this GLContext.

Specified by:
getGL in class GLContext
Returns:
the aggregated GL instance, or null if this context was not yet made current.

setGL

public GL setGL(GL gl)
Description copied from class: GLContext
Sets the GL pipeline object for this GLContext.

Specified by:
setGL in class GLContext
Returns:
the set GL pipeline or null if not successful

update

protected void update()
               throws GLException
Throws:
GLException

isSynchronized

public boolean isSynchronized()
Description copied from class: GLContext
Returns true if 'makeCurrent' will exhibit synchronized behavior.

Specified by:
isSynchronized in class GLContext

setSynchronized

public void setSynchronized(boolean isSynchronized)
Description copied from class: GLContext
Determines whether 'makeCurrent' will exhibit synchronized behavior.

Specified by:
setSynchronized in class GLContext

getPlatformGLExtensions

public abstract Object getPlatformGLExtensions()

release

public void release()
             throws GLException
Description copied from class: GLContext
Releases control of this GLContext from the current thread.

Specified by:
release in class GLContext
Throws:
GLException - if the context had not previously been made current on the current thread

releaseImpl

protected abstract void releaseImpl()
                             throws GLException
Throws:
GLException

destroy

public final void destroy()
Description copied from class: GLContext
Destroys this OpenGL context and frees its associated resources. The context should have been released before this method is called.

Specified by:
destroy in class GLContext

destroyImpl

protected abstract void destroyImpl()
                             throws GLException
Throws:
GLException

copy

public final void copy(GLContext source,
                       int mask)
                throws GLException
Description copied from class: GLContext
Copies selected groups of OpenGL state variables from the supplied source context into this one. The mask parameter indicates which groups of state variables are to be copied. mask contains the bitwise OR of the same symbolic names that are passed to the GL command glPushAttrib. The single symbolic constant GL_ALL_ATTRIB_BITS can be used to copy the maximum possible portion of rendering state.

Not all values for GL state can be copied. For example, pixel pack and unpack state, render mode state, and select and feedback state are not copied. The state that can be copied is exactly the state that is manipulated by the GL command glPushAttrib.

On most platforms, this context may not be current to any thread, including the calling thread, when this method is called. Some platforms have additional requirements such as whether this context or the source context must occasionally be made current in order for the results of the copy to be seen; these requirements are beyond the scope of this specification.

Specified by:
copy in class GLContext
Parameters:
source - the source OpenGL context from which to copy state
mask - a mask of symbolic names indicating which groups of state to copy
Throws:
GLException - if an OpenGL-related error occurred

copyImpl

protected abstract void copyImpl(GLContext source,
                                 int mask)
                          throws GLException
Throws:
GLException

makeCurrent

public int makeCurrent()
                throws GLException
MakeCurrent functionality, which also issues the creation of the actual OpenGL context.
The complete callgraph for general OpenGL context creation is:

Once at startup, ie triggered by the singleton constructor of a GLDrawableFactoryImpl specialization, calling createContextARB(long, boolean, int[], int[], int[]) will query all available OpenGL versions:

Specified by:
makeCurrent in class GLContext
Returns:
CONTEXT_CURRENT if the context was successfully made current
Throws:
GLException - if synchronization is disabled and the context is current on another thread, or because the context could not be created or made current due to non-recoverable, window system-specific errors.
See Also:
makeCurrentImpl(boolean), #create, createContextARB(long, boolean, int[], int[], int[]), createContextARBImpl(long, boolean, int, int, int), #mapVersionAvailable, destroyContextARBImpl(long)

makeCurrentLocking

protected final int makeCurrentLocking()
                                throws GLException
Throws:
GLException

makeCurrentImpl

protected abstract void makeCurrentImpl(boolean newCreatedContext)
                                 throws GLException
Throws:
GLException

createImpl

protected abstract boolean createImpl()
                               throws GLException
Throws:
GLException

createContextARBImpl

protected abstract long createContextARBImpl(long share,
                                             boolean direct,
                                             int ctxOptionFlags,
                                             int major,
                                             int minor)
Platform dependent but harmonized implementation of the ARB_create_context mechanism to create a context.
This method is called from createContextARB(long, boolean, int[], int[], int[]).
The implementation shall verify this context with a MakeContextCurrent call.
The implementation shall leave the context current.

Parameters:
share - the shared context or null
direct - flag if direct is requested
ctxOptionFlags - ARB_create_context related, see references below
major - major number
minor - minor number
Returns:
the valid context if successfull, or null
See Also:
makeCurrent(), GLContext.CTX_PROFILE_COMPAT, GLContext.CTX_OPTION_FORWARD, GLContext.CTX_OPTION_DEBUG, makeCurrentImpl(boolean), #create, createContextARB(long, boolean, int[], int[], int[]), createContextARBImpl(long, boolean, int, int, int), destroyContextARBImpl(long)

destroyContextARBImpl

protected abstract void destroyContextARBImpl(long context)
Destroy the context created by createContextARBImpl(long, boolean, int, int, int).

See Also:
makeCurrent(), makeCurrentImpl(boolean), #create, createContextARB(long, boolean, int[], int[], int[]), createContextARBImpl(long, boolean, int, int, int), destroyContextARBImpl(long)

createContextARB

protected final long createContextARB(long share,
                                      boolean direct,
                                      int[] major,
                                      int[] minor,
                                      int[] ctp)
Platform independent part of using the ARB_create_context mechanism to create a context.
The implementation of #create shall use this protocol in case the platform supports ARB_create_context.
This method may call createContextARBImpl(long, boolean, int, int, int) and destroyContextARBImpl(long).
This method will also query all available native OpenGL context when first called,
usually the first call should happen with the shared GLContext of the DrawableFactory.
The implementation makes the context current, if successful

See Also:
makeCurrentImpl(boolean), #create, createContextARB(long, boolean, int[], int[], int[]), createContextARBImpl(long, boolean, int, int, int), destroyContextARBImpl(long)

createGL

protected GL createGL(GLProfile glp)
Create the GL for this context.


getGLProcAddressTable

public final ProcAddressTable getGLProcAddressTable()

getPlatformExtProcAddressTable

public abstract ProcAddressTable getPlatformExtProcAddressTable()
Shall return the platform extension ProcAddressTable, ie for GLXExt, EGLExt, ..


bindPbufferToTexture

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


releasePbufferFromTexture

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


glAllocateMemoryNV

public abstract ByteBuffer glAllocateMemoryNV(int arg0,
                                              float arg1,
                                              float arg2,
                                              float arg3)

setSwapInterval

public final void setSwapInterval(int interval)

setSwapIntervalImpl

protected void setSwapIntervalImpl(int interval)

getSwapInterval

public int getSwapInterval()

mapToRealGLFunctionName

protected 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.


getFunctionNameMap

protected abstract Map getFunctionNameMap()

mapToRealGLExtensionName

protected 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" to "WGL_ARB_pbuffer/GLX_SGIX_pbuffer" and "GL_ARB_pixel_format" to "WGL_ARB_pixel_format/n.a."


getExtensionNameMap

protected abstract Map getExtensionNameMap()

resetProcAddressTable

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


setGLFunctionAvailability

protected final void setGLFunctionAvailability(boolean force,
                                               int major,
                                               int minor,
                                               int ctp)
Sets the OpenGL implementation class and the cache of which GL functions are available for calling through this context. See isFunctionAvailable(String) for more information on the definition of "available".
All ProcaddressTables are being determined, the GL version is being set and the extension cache is determined as well.

Parameters:
force - force the setting, even if is already being set. This might be useful if you change the OpenGL implementation.
See Also:
setContextVersion(int, int, int)

updateGLXProcAddressTable

protected abstract void updateGLXProcAddressTable()
Updates the platform's 'GLX' function cache


hasNativeES2Methods

public final boolean hasNativeES2Methods()

isFunctionAvailable

public 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. See GLBase.isFunctionAvailable(String) for more details.

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

isExtensionAvailable

public 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. See GLBase.isExtensionAvailable(String) for more details.

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

getPlatformExtensionsString

public String getPlatformExtensionsString()
Description copied from class: GLContext
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.

Specified by:
getPlatformExtensionsString in class GLContext

getGLExtensionsString

public String getGLExtensionsString()
Description copied from class: GLContext
Returns a non-null (but possibly empty) string containing the space-separated list of available extensions. Can only be called while this context is current. This is equivalent to glGetString(GL_EXTENSIONS)

Specified by:
getGLExtensionsString in class GLContext

isExtensionCacheInitialized

public final boolean isExtensionCacheInitialized()

getContextFQN

protected static String getContextFQN(AbstractGraphicsDevice device,
                                      int major,
                                      int minor,
                                      int ctp)

getContextFQN

protected String getContextFQN()

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.

Throws:
GLException

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.


getOffscreenContextPixelDataType

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


setBufferSizeTracker

public void setBufferSizeTracker(GLBufferSizeTracker bufferSizeTracker)

getBufferSizeTracker

public GLBufferSizeTracker getBufferSizeTracker()

getBufferStateTracker

public GLBufferStateTracker getBufferStateTracker()

getGLStateTracker

public GLStateTracker getGLStateTracker()

hasWaiters

public boolean hasWaiters()


Copyright 2010 JogAmp Community.