public class SoGLContext extends SoDeviceContext
Starting with Open Inventor 8.5, the application can control sharing of OpenGL contexts (previously this was done internally for rendering contexts). When OpenGL contexts are shared it means that display lists, texture objects, buffer objects, etc created in any context in that share group can be used by any other context in that group. This saves time and memory when rendering into multiple windows, buffers, etc.
In a typical Open Inventor application an OpenGL device context is created automatically by the viewer class and is managed automatically by the viewer for rendering and other operations involving the GPU. However this context is only made current when the viewer is actively using it, for example to render the scene graph. (Prior to Open Inventor 8.5, the viewer made its OpenGL context "current" and this context remained current even when the viewer was not actively rendering the scene graph. This was convenient in some cases, but could conflict with application strategies for managing OpenGL contexts.)
Do not assume that any OpenGL context is current. If you need a current OpenGL context, for example to create an SoGLBufferObject
, bind() and unbind() an SoGLContext
object.
If your application uses an Open Inventor viewer, the viewer's rendering context can be made current using the viewer's bindNormalContext() method and released using the viewer's unbindNormalContext() method. This context can also be queried using the viewer's getNormalSoContext() method.
If you do not have (or do not have access to) a viewer, you can create a context by creating an SoGLContext
object. In almost all cases, calling the constructor with a true value will create a context that is in a share group with the rendering context. In other words, resources such as textures and buffer objects are shared between these contexts and can be used in any of the contexts in the share group. For example:
If the OpenGL context is created and managed by the application or a third- party library, the application should create anSoGLContext glContext = new SoGLContext( true ); glContext.bind(); SoGLBufferObject gpuBuffer = new SoGLBufferObject( SoGLBufferObject.Usages.STATIC_DRAW ); gpuBuffer.setTarget( SoGLBufferObject.BufferObjectTargets.ARRAY_BUFFER ); glContext.unbind();
SoGLContext
object to wrap the actual current context, then bind() and unbind() this object around the Open Inventor render call. Note that this method will return null if there is no current OpenGL context. Also note that the SoGLContext
object should be told not to manage (specifically not to delete) the OpenGL context since its lifespan is managed by other software. For example:
if (context != null) context.setNoGLContextDelete(); // Context is managed by someone else else context = new SoGLContext( true ); context.bind(); . . . context.unbind();
Modifier and Type | Class and Description |
---|---|
static class |
SoGLContext.SharedGroupPolicies
Sharing Policy.
|
Inventor.ConstructorCommand
VERBOSE_LEVEL, ZeroHandle
Constructor and Description |
---|
SoGLContext(boolean shared)
Constructor which creates an
SoGLContext based on the attributes of the current context. |
SoGLContext(SoGLContext context,
boolean shared)
Constructor which creates an
SoGLContext based on the attributes of the specified context. |
Modifier and Type | Method and Description |
---|---|
void |
assertContext()
Assert this context and the current active context are the same.
|
static SoGLContext |
getContextFromId(int id)
Returns the context corresponding to an internal id.
|
static SoGLContext |
getContextFromSharedId(int sharedIdGroup)
Returns the first context that belongs to the specified sharedIdGroup.
|
SbGPUCapabilities |
getContextGraphicsCapabilities()
Retrieve graphics capabilities from this context.
|
static SoGLContext |
getCurrent()
Calls getCurrent((boolean)false).
|
static SoGLContext |
getCurrent(boolean checkGLState)
Returns the current active OpenGL context (if any).
|
SoGLFormat |
getFormat()
Returns the
SoGLFormat associated to the SoGLContext . |
static SbGPUCapabilities |
getGraphicsCapabilities()
Retrieve graphics capabilities from the current bound context, if any.
|
int |
getId()
Returns the internal id for this context.
|
static SoGLContext.SharedGroupPolicies |
getSharedGroupPolicy()
Returns the current sharedGroupPolicy.
|
void |
invalidate()
Set this context as invalid so it won't be used anymore.
|
boolean |
isValidForCurrent()
Returns true if the context is the current active context or if it is shared with the current active context.
|
void |
setNoGLContextDelete()
Prevent deletion of the native OpenGL context by
SoGLContext . |
boolean |
swapBuffers()
Swaps the buffers with the value stored in the
SoGLFormat , which is set to the main plane by default. |
boolean |
tryBind()
Try to bind the OpenGL context to the current thread.
|
bind, dispose, getSharedGroup, getSharedId, isCompatible, isCurrent, isDisposable, isSharable, isSharedWith, isValid, setSharable, setSharedGroup, setSharedWith, unbind
getNativeResourceHandle
public SoGLContext(SoGLContext context, boolean shared)
SoGLContext
based on the attributes of the specified context.
If
shared is true then the created OpenGL context will be shared with the given context, depending on the current SharedGroupPolicy.public SoGLContext(boolean shared)
SoGLContext
based on the attributes of the current context.
SoGLContext
will not be valid!
shared
- Indicates if we want to share the context. If true, context is shared with current context, depending on the currently defined SharedGroupPolicy. If false, context is explicitly not shared.public static SoGLContext getCurrent()
public boolean tryBind()
public static SoGLContext getCurrent(boolean checkGLState)
SoGLContext
using contextId returned by system getCurrentContext() method.
checkGLState
- This param is no longer used.
public SbGPUCapabilities getContextGraphicsCapabilities()
public void setNoGLContextDelete()
SoGLContext
.
Note: Can be useful when the OpenGL context is created and managed by the application or a third-party library such as wxWidgets.public static SoGLContext getContextFromSharedId(int sharedIdGroup)
sharedIdGroup
- The internal sharedIdGroup used to search for the context.
public void assertContext()
public boolean isValidForCurrent()
public SoGLFormat getFormat()
SoGLFormat
associated to the SoGLContext
.
SoGLFormat
.
public static SoGLContext.SharedGroupPolicies getSharedGroupPolicy()
public static SbGPUCapabilities getGraphicsCapabilities()
public boolean swapBuffers()
SoGLFormat
, which is set to the main plane by default.public void invalidate()
SoGLContext
has been created from an OpenGL context managed by the application or a third-party library (e.g.: Qt, JOGL...).public static SoGLContext getContextFromId(int id)
id
- The internal id used to search for the context.
public int getId()
Generated on July 31, 2019, Copyright © Thermo Fisher Scientific. All rights reserved. http://www.openinventor.com