ARB_create_context
related: created via ARB_create_context */
protected static final int CTX_IS_ARB_CREATED = 1 << 0;
/** ARB_create_context
related: compatibility profile */
protected static final int CTX_PROFILE_COMPAT = 1 << 1;
/** ARB_create_context
related: core profile */
protected static final int CTX_PROFILE_CORE = 1 << 2;
/** ARB_create_context
related: ES profile */
protected static final int CTX_PROFILE_ES = 1 << 3;
/** ARB_create_context
related: flag forward compatible */
protected static final int CTX_OPTION_FORWARD = 1 << 4;
/** ARB_create_context
related: flag not forward compatible */
protected static final int CTX_OPTION_ANY = 1 << 5;
/** ARB_create_context
related: flag debug */
public static final int CTX_OPTION_DEBUG = 1 << 6;
/** GL_ARB_ES2_compatibility
related: Context is compatible w/ ES2 */
protected static final int CTX_PROFILE_ES2_COMPAT = 1 << 8;
/** GLContext {@link com.jogamp.gluegen.runtime.ProcAddressTable} caching related: GL software implementation */
protected static final int CTX_IMPL_ACCEL_SOFT = 1 << 0;
/** GLContext {@link com.jogamp.gluegen.runtime.ProcAddressTable} caching related: GL hardware implementation */
protected static final int CTX_IMPL_ACCEL_HARD = 1 << 1;
private static ThreadLocalmask
* 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 {@link
* GL#glPushAttrib glPushAttrib}. The single symbolic constant
* {@link GL2#GL_ALL_ATTRIB_BITS 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 {@link * GL2#glPushAttrib 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.
*
* @param source the source OpenGL context from which to copy state
* @param mask a mask of symbolic names indicating which groups of state to copy
* @throws GLException if an OpenGL-related error occurred
*/
public abstract void copy(GLContext source, int mask) throws GLException;
/**
* Returns the GL object bound to this thread current context.
* If no context is current, throw an GLException
*
* @return the current context's GL object on this thread
* @throws GLException if no context is current
*/
public static GL getCurrentGL() throws GLException {
GLContext glc = getCurrent();
if(null==glc) {
throw new GLException("No OpenGL context current on this thread");
}
return glc.getGL();
}
/**
* Returns this thread current context.
* If no context is current, returns null.
*
* @return the context current on this thread, or null if no context
* is current.
*/
public static GLContext getCurrent() {
return currentContext.get();
}
/**
* @return true if this GLContext is current on this thread
*/
public final boolean isCurrent() {
return getCurrent() == this ;
}
/**
* @throws GLException if this GLContext is not current on this thread
*/
public final void validateCurrent() throws GLException {
if(getCurrent() != this) {
throw new GLException("Given GL context not current");
}
}
/**
* Sets the thread-local variable returned by {@link #getCurrent}
* and has no other side-effects. For use by third parties adding
* new GLContext implementations; not for use by end users.
*/
protected static void setCurrent(GLContext cur) {
currentContext.set(cur);
}
/**
* Destroys this OpenGL context and frees its associated
* resources. The context should have been released before this
* method is called.
*/
public abstract void destroy();
/**
* Returns true if 'makeCurrent' will exhibit synchronized behavior.
*/
public abstract boolean isSynchronized();
/**
* Determines whether 'makeCurrent' will exhibit synchronized behavior.
*/
public abstract void setSynchronized(boolean isSynchronized);
/**
* Returns the GL pipeline object for this GLContext.
*
* @return the aggregated GL instance, or null if this context was not yet made current.
*/
public abstract GL getGL();
/**
* Sets the GL pipeline object for this GLContext.
*
* @return the set GL pipeline or null if not successful
*/
public abstract GL setGL(GL gl);
/**
* Returns the native GL context handle
*/
public final long getHandle() { return contextHandle; }
/**
* Indicates whether the underlying OpenGL context has been created.
*/
public final boolean isCreated() {
return 0 != contextHandle;
}
/**
* Returns the attached user object for the given name to this GLContext.
*/
public final Object getAttachedObject(int name) {
return attachedObjectsByInt.get(name);
}
/**
* Returns the attached user object for the given name to this GLContext.
*/
public final Object getAttachedObject(String name) {
return attachedObjectsByString.get(name);
}
/**
* Sets the attached user object for the given name to this GLContext.
* Returns the previously set object or null.
*/
public final Object attachObject(int name, Object obj) {
return attachedObjectsByInt.put(name, obj);
}
public final Object detachObject(int name) {
return attachedObjectsByInt.remove(name);
}
/**
* Sets the attached user object for the given name to this GLContext.
* Returns the previously set object or null.
*/
public final Object attachObject(String name, Object obj) {
return attachedObjectsByString.put(name, obj);
}
public final Object detachObject(String name) {
return attachedObjectsByString.remove(name);
}
/**
* Classname, GL, GLDrawable
*/
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append(getClass().getSimpleName());
sb.append(" [");
this.append(sb);
sb.append("] ");
return sb.toString();
}
public final StringBuffer append(StringBuffer sb) {
sb.append("OpenGL ");
sb.append(getGLVersionMajor());
sb.append(".");
sb.append(getGLVersionMinor());
sb.append(", options 0x");
sb.append(Integer.toHexString(ctxOptions));
sb.append(", ");
sb.append(getGLVersion());
sb.append(", handle ");
sb.append(toHexString(contextHandle));
sb.append(", ");
sb.append(getGL());
if(getGLDrawable()!=getGLReadDrawable()) {
sb.append(",\n\tRead Drawable : ");
sb.append(getGLReadDrawable());
sb.append(",\n\tWrite Drawable: ");
sb.append(getGLDrawable());
} else {
sb.append(",\n\tDrawable: ");
sb.append(getGLDrawable());
}
return sb;
}
/** 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. */
public abstract String getPlatformExtensionsString();
/** 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
{@link javax.media.opengl.GL#glGetString(int) glGetString}({@link javax.media.opengl.GL#GL_EXTENSIONS GL_EXTENSIONS})
*/
public abstract String getGLExtensionsString();
public final int getGLVersionMajor() { return ctxMajorVersion; }
public final int getGLVersionMinor() { return ctxMinorVersion; }
public final boolean isGLCompatibilityProfile() { return ( 0 != ( CTX_PROFILE_COMPAT & ctxOptions ) ); }
public final boolean isGLCoreProfile() { return ( 0 != ( CTX_PROFILE_CORE & ctxOptions ) ); }
public final boolean isGLForwardCompatible() { return ( 0 != ( CTX_OPTION_FORWARD & ctxOptions ) ); }
public final boolean isGLDebugEnabled() { return ( 0 != ( CTX_OPTION_DEBUG & ctxOptions ) ); }
public final boolean isCreatedWithARBMethod() { return ( 0 != ( CTX_IS_ARB_CREATED & ctxOptions ) ); }
/**
* @return Additional context creation flags, supported: {@link GLContext#CTX_OPTION_DEBUG}.
*/
public abstract int getContextCreationFlags();
/**
* @param flags Additional context creation flags, supported: {@link GLContext#CTX_OPTION_DEBUG}.
* Unsupported flags are masked out.
* Only affects this context state if not created yet via {@link #makeCurrent()}.
* @see #enableGLDebugMessage(boolean)
* @see GLAutoDrawable#setContextCreationFlags(int)
*/
public abstract void setContextCreationFlags(int flags);
/**
* Returns a valid OpenGL version string, ie
*
* major.minor ([option]?[options,]*) - gl-version *
old
refers to the non ARB_create_context created contextnew
refers to the ARB_create_context created contextcompatible profile
core profile
forward compatible
any
refers to the non forward compatible contextES
refers to the GLES context variantrow 2, cell 1 | *row 2, cell 2 | *
ES2 | 2.0 (ES, any, new) - 2.0 ES Profile | |
ATI | GL2 | 3.0 (compatibility profile, any, new) - 3.2.9704 Compatibility Profile Context |
ATI | GL3 | 3.3 (core profile, any, new) - 1.4 (3.2.9704 Compatibility Profile Context) |
ATI | GL3bc | 3.3 (compatibility profile, any, new) - 1.4 (3.2.9704 Compatibility Profile Context) |
NV | GL2 | 3.0 (compatibility profile, any, new) - 3.0.0 NVIDIA 195.36.07.03 |
NV | GL3 | 3.3 (core profile, any, new) - 3.3.0 NVIDIA 195.36.07.03 |
NV | GL3bc | 3.3 (compatibility profile, any, new) - 3.3.0 NVIDIA 195.36.07.03 |
GL_ARB_ES2_compatibility
, otherwise false
*/
public final boolean isGLES2Compatible() {
return 0 != ( ctxOptions & CTX_PROFILE_ES2_COMPAT ) ;
}
public final boolean hasGLSL() {
return isGL2ES2() ;
}
public final void setSwapInterval(int interval) {
if (!isCurrent()) {
throw new GLException("This context is not current. Current context: "+getCurrent()+", this context "+this);
}
setSwapIntervalImpl(interval);
}
protected void setSwapIntervalImpl(int interval) { /** nop per default .. **/ }
protected int currentSwapInterval = -1; // default: not set yet ..
public int getSwapInterval() {
return currentSwapInterval;
}
public final boolean queryMaxSwapGroups(int[] maxGroups, int maxGroups_offset,
int[] maxBarriers, int maxBarriers_offset) {
if (!isCurrent()) {
throw new GLException("This context is not current. Current context: "+getCurrent()+", this context "+this);
}
return queryMaxSwapGroupsImpl(maxGroups, maxGroups_offset, maxBarriers, maxBarriers_offset);
}
protected boolean queryMaxSwapGroupsImpl(int[] maxGroups, int maxGroups_offset,
int[] maxBarriers, int maxBarriers_offset) { return false; }
public final boolean joinSwapGroup(int group) {
if (!isCurrent()) {
throw new GLException("This context is not current. Current context: "+getCurrent()+", this context "+this);
}
return joinSwapGroupImpl(group);
}
protected boolean joinSwapGroupImpl(int group) { /** nop per default .. **/ return false; }
protected int currentSwapGroup = -1; // default: not set yet ..
public int getSwapGroup() {
return currentSwapGroup;
}
public final boolean bindSwapBarrier(int group, int barrier) {
if (!isCurrent()) {
throw new GLException("This context is not current. Current context: "+getCurrent()+", this context "+this);
}
return bindSwapBarrierImpl(group, barrier);
}
protected boolean bindSwapBarrierImpl(int group, int barrier) { /** nop per default .. **/ return false; }
/**
* @return The extension implementing the GLDebugOutput feature,
* either GL_ARB_debug_output or GL_AMD_debug_output.
* If unavailable or called before initialized via {@link #makeCurrent()}, null is returned.
*/
public abstract String getGLDebugMessageExtension();
/**
* @return the current synchronous debug behavior via
* @see #setSynchronous(boolean)
*/
public abstract boolean isGLDebugSynchronous();
/**
* Enables or disables the synchronous debug behavior via
* {@link GL2GL3#GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB glEnable/glDisable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB)},
* if extension is {@link #GL_ARB_debug_output}.
* There is no equivalent for {@link #GL_AMD_debug_output}.
* The default is true
, ie {@link GL2GL3#GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB}.
To enable the GLDebugOutput feature {@link #enableGLDebugMessage(boolean) enableGLDebugMessage(true)} * or {@link #setContextCreationFlags(int) setContextCreationFlags}({@link GLContext#CTX_OPTION_DEBUG}) * shall be called before context creation via {@link #makeCurrent()}!
* *In case {@link GLAutoDrawable} are being used, * {@link GLAutoDrawable#setContextCreationFlags(int) glAutoDrawable.setContextCreationFlags}({@link GLContext#CTX_OPTION_DEBUG}) * shall be issued before context creation via {@link #makeCurrent()}!
* *After context creation, the GLDebugOutput feature may be enabled or disabled at any time using this method.
* * @param enable If true enables, otherwise disables the GLDebugOutput feature. * * @throws GLException if this context is not current or GLDebugOutput registration failed (enable) * * @see #setContextCreationFlags(int) * @see #addGLDebugListener(GLDebugListener) * @see GLAutoDrawable#setContextCreationFlags(int) */ public abstract void enableGLDebugMessage(boolean enable) throws GLException; /** * Add {@link GLDebugListener}.