SoGLContext Class Reference
[GL device]

VSG extension OpenGL context management class. More...

#include <Inventor/devices/SoGLContext.h>

Inheritance diagram for SoGLContext:
SoDeviceContext SoRefCounter

List of all members.

Classes

struct  MTstruct

Public Types

enum  SharedGroupPolicy {
  DISABLED,
  CONSERVATIVE,
  AGGRESSIVE
}
typedef SbGlContextHelper::Display SharedGroupDescription

Public Member Functions

 SoGLContext (bool shared)
 SoGLContext (SbGlContextHelper::Display dpy, SbGlContextHelper::VisualInfo vis, SbGlContextHelper::Drawable drawable, SbGlContextHelper::GLContext ctx)
 SoGLContext (const SoGLFormat &format, SbGlContextHelper::GLContext ctx, SbGlContextHelper::Drawable drawable=0)
 SoGLContext (const SoGLFormat &format, SbGlContextHelper::Drawable drawable=0)
 SoGLContext (SbGlContextHelper::Display dpy, SbGlContextHelper::VisualInfo vis, SbGlContextHelper::Drawable drawable, bool shared=true)
 SoGLContext (SoGLContext *context, bool shared)
 SoGLContext (SoGLContext *context, const SoGLFormat &format, SbGlContextHelper::Drawable drawable=0)
virtual void bind ()
virtual bool tryBind ()
virtual void unbind ()
bool isSharedWith (const SoDeviceContext *context) const
virtual bool isValid () const
void invalidate ()
int getId () const
virtual bool isCompatible (SoDeviceContext *context) const
virtual bool isCurrent () const
const
SbGlContextHelper::GLContext
getGLContext () const
const SbGlContextHelper::DisplaygetDisplay () const
const
SbGlContextHelper::VisualInfo
getVisualInfo () const
const SoGLFormatgetFormat () const
bool isValidForCurrent () const
void assertContext () const
bool swapBuffers ()
SbStringList getSupportedExtensions ()
void setNoGLContextDelete ()
const SbGPUCapabilitiesgetContextGraphicsCapabilities ()

Static Public Member Functions

static SoGLContextgetCurrent (bool checkGLState=false)
static SoGLContextfindGLContext (SbGlContextHelper::GLContext)
static SoGLContextfindSharedContext (SharedGroupDescription)
static SoGLContextgetContextFromId (int id)
static SoGLContextgetContextFromSharedId (int sharedIdGroup)
static SharedGroupPolicy getSharedGroupPolicy ()
static const SbGPUCapabilitiesgetGraphicsCapabilities ()

Detailed Description

VSG extension 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 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:

    SoRef<SoGLContext> glContext = new SoGLContext(true);
    glContext->bind();
        SoRef<SoGLBufferObject>  gpuBuffer = new SoGLBufferObject( SoGLBufferObject::STATIC_DRAW );
        gpuBuffer->setTarget( SoGLBufferObject::ARRAY_BUFFER );
    glContext->unbind();

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:

   SoGLContext* context = SoGLContext::getCurrent( true );
   if (context != NULL)
       context->setNoGLContextDelete(); // Context is managed by someone else
   else
       context = new SoGLContext( true );
   context->bind();
       . . .
   context->unbind();

Reference counting:


Member Typedef Documentation

Returns an SoGLContext that matches the specified SharedGroupDescription.

On Windows, SharedGroupDescription is a PixelFormat id.
On Unix, SharedGroupDescription is a display pointer.


Member Enumeration Documentation

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)
Only add context to a share group containing contexts with the constraint (ex: same pixel format for SoGLContext objects).

This mode matchs the official behavior of the wglShareLists() function. (Please refer to Microsoft documentation for more details.)

AGGRESSIVE 

Aggressive sharing (default)
Tries to share contexts, independent of their sharing constraint.

When sharing succeeds, shared contexts are part of the same sharedGroup, else, a new sharedGroup is created.


Constructor & Destructor Documentation

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!

Parameters:
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.

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

Parameters:
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.

Parameters:
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.

Member Function Documentation

void SoGLContext::assertContext (  )  const

Assert this context and the current active context are the same.

virtual void SoGLContext::bind (  )  [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 SoGLContext* SoGLContext::findGLContext ( SbGlContextHelper::GLContext   )  [static]

Returns the first SoGLContext associated with the specified OpenGL context.

Returns:
The found SoGLContext or NULL if none found.
static SoGLContext* SoGLContext::findSharedContext ( SharedGroupDescription   )  [static]
static SoGLContext* SoGLContext::getContextFromId ( int  id  )  [static]

Returns the context corresponding to an internal id.

Parameters:
id The internal id used to search for the context.
Returns:
The context which has the specified id.
static SoGLContext* SoGLContext::getContextFromSharedId ( int  sharedIdGroup  )  [static]

Returns the first context that belongs to the specified sharedIdGroup.

Parameters:
sharedIdGroup The internal sharedIdGroup used to search for the context.
Returns:
The first context that belongs to the specified sharedIdGroup.
const SbGPUCapabilities& SoGLContext::getContextGraphicsCapabilities (  ) 

Retrieve graphics capabilities from this context.

Make sure that this context is valid, otherwise capabilities will be wrong.

static SoGLContext* SoGLContext::getCurrent ( bool  checkGLState = false  )  [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.

Parameters:
checkGLState This param is no longer used.
Returns:
The current OpenGL context (or NULL if there isn't one).
const SbGlContextHelper::Display& SoGLContext::getDisplay (  )  const

Returns the Display of this SoGLContext.

Returns:
The Display.
const SoGLFormat& SoGLContext::getFormat (  )  const

Returns the SoGLFormat associated to the SoGLContext.

Returns:
the SoGLFormat.
const SbGlContextHelper::GLContext& SoGLContext::getGLContext (  )  const

Returns the OpenGL rendering context of this SoGLContext.

Returns:
The OpenGL rendering context.
static const SbGPUCapabilities& SoGLContext::getGraphicsCapabilities (  )  [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.

Returns:
The internal id of the context.
static SharedGroupPolicy SoGLContext::getSharedGroupPolicy (  )  [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.

Returns:
The VisualInfo.
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 bool SoGLContext::isCompatible ( SoDeviceContext context  )  const [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.

Parameters:
context The context to compare with this one.
Returns:
True if the specified context is compatible with this one.
virtual bool SoGLContext::isCurrent (  )  const [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.

bool SoGLContext::isSharedWith ( const SoDeviceContext context  )  const

Returns true if the specified context and this context are shared.

Returns:
true if the two contexts are shared.
virtual bool SoGLContext::isValid (  )  const [virtual]

Returns true if this context is valid.

Returns:
true if the 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.

void SoGLContext::setNoGLContextDelete (  )  [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 wxWidgets.

bool SoGLContext::swapBuffers (  ) 

Swaps the buffers with the value stored in the SoGLFormat, which is set to the main plane by default.

virtual bool SoGLContext::tryBind (  )  [virtual]

Try to bind the OpenGL context to the current thread.


Returns false if already bound, else calls bind() and returns true.

virtual void SoGLContext::unbind (  )  [virtual]

Unbind the OpenGL context from the current thread.

Implements SoDeviceContext.


The documentation for this class was generated from the following file:

Open Inventor Toolkit reference manual, generated on 28 Oct 2019
Copyright © Thermo Fisher Scientific All rights reserved.
http://www.openinventor.com/