OpenGL context management class. More...
#include <Inventor/devices/SoGLContext.h>
Public Types | |
enum | SharedGroupPolicy { DISABLED , CONSERVATIVE , AGGRESSIVE } |
Sharing Policy. More... | |
typedef SbGlContextHelper::Display | SharedGroupDescription |
Returns an SoGLContext that matches the specified SharedGroupDescription. | |
Public Member Functions | |
SoGLContext (bool shared) | |
Constructor which creates an SoGLContext based on the attributes of the current context. | |
SoGLContext (SbGlContextHelper::Display dpy, SbGlContextHelper::VisualInfo vis, SbGlContextHelper::Drawable drawable, SbGlContextHelper::GLContext ctx) | |
Constructor which creates an SoGLContext based on the specifed parameters. | |
SoGLContext (const SoGLFormat &format, SbGlContextHelper::GLContext ctx, SbGlContextHelper::Drawable drawable=0) | |
Constructor which creates a SoGLContext based on the specified parameters. | |
SoGLContext (const SoGLFormat &format, SbGlContextHelper::Drawable drawable=0) | |
Constructor which creates a SoGLContext based on the specifed format. | |
SoGLContext (SbGlContextHelper::Display dpy, SbGlContextHelper::VisualInfo vis, SbGlContextHelper::Drawable drawable, bool shared=true) | |
Constructor which creates a SoGLContext based on the specified parameters. | |
SoGLContext (SoGLContext *context, bool shared) | |
Constructor which creates an SoGLContext based on the attributes of the specified context. | |
SoGLContext (SoGLContext *context, const SoGLFormat &format, SbGlContextHelper::Drawable drawable=0) | |
Constructor which creates a SoGLContext shared with a specific context, but attached to the display specified in the SoGLFormat. | |
virtual void | bind () |
Bind the OpenGL context to the current thread. | |
virtual bool | tryBind () |
Try to bind the OpenGL context to the current thread. | |
virtual void | unbind () |
Unbind the OpenGL context from the current thread. | |
bool | isSharedWith (const SoDeviceContext *context) const |
Returns true if the specified context and this context are shared. | |
virtual bool | isValid () const |
Returns true if this context is valid. | |
void | invalidate () |
Set this context as invalid so it won't be used anymore. | |
int | getId () const |
Returns the internal id for this context. | |
virtual bool | isCompatible (SoDeviceContext *context) const |
Returns true if the specified context and this one are compatible. | |
virtual bool | isCurrent () const |
Returns true if this context is valid and currently active. | |
const SbGlContextHelper::GLContext & | getGLContext () const |
Returns the OpenGL rendering context of this SoGLContext. | |
const SbGlContextHelper::Display & | getDisplay () const |
Returns the Display of this SoGLContext. | |
const SbGlContextHelper::VisualInfo & | getVisualInfo () const |
Returns the VisualInfo of this SoGLContext. | |
const SoGLFormat & | getFormat () const |
Returns the SoGLFormat associated to the SoGLContext. | |
bool | isValidForCurrent () const |
Returns true if the context is the current active context or if it is shared with the current active context. | |
void | assertContext () const |
Assert this context and the current active context are the same. | |
bool | swapBuffers () |
Swaps the buffers with the value stored in the SoGLFormat, which is set to the main plane by default. | |
SbStringList | getSupportedExtensions () |
Returns an SbString containing the supported extensions for this context. | |
void | setNoGLContextDelete () |
Prevent deletion of the native OpenGL context by SoGLContext. | |
const SbGPUCapabilities & | getContextGraphicsCapabilities () |
Retrieve graphics capabilities from this context. | |
Public Member Functions inherited from SoDeviceContext | |
SoDeviceContext () | |
Default constructor. | |
void | setSharable (bool sharable) |
Sets the sharable property. | |
bool | isSharable () const |
Returns the sharable status of this context. | |
virtual int | getSharedId () const |
Returns an id common to all compatible/shared contexts. | |
SoDeviceContextSharedGroup * | getSharedGroup () const |
Returns the current shared group. | |
bool | setSharedGroup (SoDeviceContextSharedGroup *sharedGroup) |
Explicitly change the sharedGroup. | |
Public Member Functions inherited from SoRefCounter | |
void | ref () const |
Adds a reference to an instance. | |
void | unref () const |
Removes a reference from an instance. | |
void | unrefNoDelete () const |
unrefNoDelete() should be called when it is desired to decrement the reference count, but not delete the instance if this brings the reference count to zero. | |
int | getRefCount () const |
Returns current reference count. | |
void | lock () const |
lock this instance. | |
void | unlock () const |
unlock this instance. | |
Static Public Member Functions | |
static SoGLContext * | getCurrent (bool checkGLState=false) |
Returns the current active OpenGL context (if any). | |
static SoGLContext * | findGLContext (SbGlContextHelper::GLContext) |
Returns the first SoGLContext associated with the specified OpenGL context. | |
static SoGLContext * | findSharedContext (SharedGroupDescription) |
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. | |
static SharedGroupPolicy | getSharedGroupPolicy () |
Returns the current sharedGroupPolicy. | |
static const SbGPUCapabilities & | getGraphicsCapabilities () |
Retrieve graphics capabilities from the current bound context, if any. | |
OpenGL context management class.
This class provides functions to manage OpenGL device contexts.
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 SoGpuBufferObject, 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 an 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:
Reference counting:
Definition at line 184 of file SoGLContext.h.
Returns an SoGLContext that matches the specified SharedGroupDescription.
On Windows, SharedGroupDescription is a PixelFormat id.
On Unix, SharedGroupDescription is a display pointer.
Definition at line 404 of file SoGLContext.h.
Sharing Policy.
User can change sharing policy by defining the OIV_SHARE_LISTS environment variable.
Enumerator | |
---|---|
DISABLED | Disables context sharing (same behavior as v2.6 and older) |
CONSERVATIVE | Conservative sharing (not available on Unix) This mode matchs the official behavior of the wglShareLists() function. (Please refer to Microsoft documentation for more details.) |
AGGRESSIVE | Aggressive sharing (default) When sharing succeeds, shared contexts are part of the same sharedGroup, else, a new sharedGroup is created. |
Definition at line 192 of file SoGLContext.h.
SoGLContext::SoGLContext | ( | bool | shared | ) |
Constructor which creates an SoGLContext based on the attributes of the current context.
If the current context is NULL, the function tries to create a context on a temporary window. If this doesn't work, the resulting 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. |
SoGLContext::SoGLContext | ( | SbGlContextHelper::Display | dpy, |
SbGlContextHelper::VisualInfo | vis, | ||
SbGlContextHelper::Drawable | drawable, | ||
SbGlContextHelper::GLContext | ctx | ||
) |
Constructor which creates an SoGLContext based on the specifed parameters.
On Microsoft Windows platforms the Display, VisualInfo and GLContext parameters cannot be NULL.
On Linux platforms the Display, Drawable, VisualInfo and GLContext parameters cannot be NULL.
On Mac platforms the Drawable, VisualInfo and GLContext parameters cannot be NULL.
Display is equal to zero for the first display, 1 for the second, ...
SoGLContext::SoGLContext | ( | const SoGLFormat & | format, |
SbGlContextHelper::GLContext | ctx, | ||
SbGlContextHelper::Drawable | drawable = 0 |
||
) |
Constructor which creates a SoGLContext based on the specified parameters.
The specified format must have been acticated before using it with this contructor. The GLContext paramater cannot be NULL as long as this constructor is not supposed to create an OpenGL context but use an existing one. If the constructor must create a context, you must use the constructor which takes only a SoGLFormat or the one which takes a SoGLContext and a SoGLFormat.
SoGLContext::SoGLContext | ( | const SoGLFormat & | format, |
SbGlContextHelper::Drawable | drawable = 0 |
||
) |
Constructor which creates a SoGLContext based on the specifed format.
Note: Context will be shared with other contexts, depending on the currently defined SharedGroupPolicy
The specified format must have been activated before using it with this contructor.
SoGLContext::SoGLContext | ( | SbGlContextHelper::Display | dpy, |
SbGlContextHelper::VisualInfo | vis, | ||
SbGlContextHelper::Drawable | drawable, | ||
bool | shared = true |
||
) |
Constructor which creates a SoGLContext based on the specified parameters.
Note: Context will be shared with other contexts, depending on the currently defined SharedGroupPolicy.
On Microsoft Windows platforms the Display and VisualInfo parameters cannot be NULL.
On Linux platforms the Display, Drawable and VisualInfo parameters cannot be NULL.
On Mac platforms the Drawable and VisualInfo parameters cannot be NULL.
Display is equal to zero for the first display, 1 for the second, ...
dpy | The display/device context. |
vis | The visual/pixel format descriptor for the rendering context. |
drawable | The drawable (must be null under Windows). |
shared | Indicates if we want to share the context. If TRUE, context is shared with one of the already created contexts, depending on the currently defined SharedGroupPolicy. If FALSE, context is explicitly not shared. |
SoGLContext::SoGLContext | ( | SoGLContext * | context, |
bool | shared | ||
) |
Constructor which creates an 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.
SoGLContext::SoGLContext | ( | SoGLContext * | context, |
const SoGLFormat & | format, | ||
SbGlContextHelper::Drawable | drawable = 0 |
||
) |
Constructor which creates a SoGLContext shared with a specific context, but attached to the display specified in the SoGLFormat.
context | The SoGLContext to be share with. Cannot be NULL. |
format | The format used for the drawable used by the new context. |
drawable | The drawable on which the context is created. Use the one from the context parameter if NULL is provided. |
void SoGLContext::assertContext | ( | ) | const |
Assert this context and the current active context are the same.
|
virtual |
Bind the OpenGL context to the current thread.
This call should be followed by a call to unbind() once the context is no longer used.
Implements SoDeviceContext.
|
static |
Returns the first SoGLContext associated with the specified OpenGL context.
|
static |
|
static |
Returns the context corresponding to an internal id.
id | The internal id used to search for the context. |
|
static |
Returns the first context that belongs to the specified sharedIdGroup.
sharedIdGroup | The internal sharedIdGroup used to search for the context. |
const SbGPUCapabilities & SoGLContext::getContextGraphicsCapabilities | ( | ) |
Retrieve graphics capabilities from this context.
Make sure that this context is valid, otherwise capabilities will be wrong.
|
static |
Returns the current active OpenGL context (if any).
This method returns the current active OpenGL context from the Open Inventor state. However it can also get the actual current context from OpenGL. It may be useful if Open Inventor should render using an OpenGL context created by the application or a third-party library. In that case, Open Inventor will create a new SoGLContext using contextId returned by system getCurrentContext() method.
checkGLState | This param is no longer used. |
const SbGlContextHelper::Display & SoGLContext::getDisplay | ( | ) | const |
Returns the Display of this SoGLContext.
const SoGLFormat & SoGLContext::getFormat | ( | ) | const |
Returns the SoGLFormat associated to the SoGLContext.
const SbGlContextHelper::GLContext & SoGLContext::getGLContext | ( | ) | const |
Returns the OpenGL rendering context of this SoGLContext.
|
static |
Retrieve graphics capabilities from the current bound context, if any.
A tempory context is created with default values if no context is bound.
int SoGLContext::getId | ( | ) | const |
Returns the internal id for this context.
The internal id is unique, it's not possible to get two contexts with the same id.
|
static |
Returns the current sharedGroupPolicy.
SbStringList SoGLContext::getSupportedExtensions | ( | ) |
Returns an SbString containing the supported extensions for this context.
Note: SbStringList is a list of pointers, not a list of objects, so the destructor for this class does not free the memory associated with the SbString objects. The application is responsible for deleting each object in the list.
const SbGlContextHelper::VisualInfo & SoGLContext::getVisualInfo | ( | ) | const |
Returns the VisualInfo of this SoGLContext.
void SoGLContext::invalidate | ( | ) |
Set this context as invalid so it won't be used anymore.
This is mainly useful when the SoGLContext has been created from an OpenGL context managed by the application or a third-party library (e.g.: Qt, JOGL...).
|
virtual |
Returns true if the specified context and this one are compatible.
Compatible means that using a buffer from one of these contexts inside the other will not require copying the data. If two OpenGL contexts are compatible, they either have the same id or they are shared.
context | The context to compare with this one. |
Implements SoDeviceContext.
|
virtual |
Returns true if this context is valid and currently active.
If the current context is shared with this context then it returns true.
Implements SoDeviceContext.
|
virtual |
Returns true if the specified context and this context are shared.
Reimplemented from SoDeviceContext.
|
virtual |
Returns true if this context is valid.
Reimplemented from SoDeviceContext.
bool SoGLContext::isValidForCurrent | ( | ) | const |
Returns true if the context is the current active context or if it is shared with the current active context.
|
inline |
Prevent deletion of the native OpenGL context by SoGLContext.
Note: Can be useful when the OpenGL context is created and managed by the application or a third-party library such as Qt.
Definition at line 481 of file SoGLContext.h.
bool SoGLContext::swapBuffers | ( | ) |
Swaps the buffers with the value stored in the SoGLFormat, which is set to the main plane by default.
|
virtual |
Try to bind the OpenGL context to the current thread.
Returns false if already bound, else calls bind() and returns true.
|
virtual |
Unbind the OpenGL context from the current thread.
Implements SoDeviceContext.