OpenSceneGraph  3.0.1
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends
osg::GraphicsContext Class Reference

Base class for providing Windowing API agnostic access to creating and managing graphics context. More...

Inheritance diagram for osg::GraphicsContext:
Inheritance graph
[legend]

List of all members.

Classes

struct  ResizedCallback
struct  ScreenIdentifier
struct  ScreenSettings
 Simple resolution structure used by WindowingSystemInterface to get and set screen resolution. More...
struct  SwapCallback
struct  Traits
 GraphicsContext Traits object provides the specification of what type of graphics context is required. More...
struct  WindowingSystemInterface
 Callback to be implemented to provide access to Windowing API's ability to create Windows/pbuffers. More...

Public Types

typedef std::vector
< ScreenSettings
ScreenSettingsList
typedef std::vector
< GraphicsContext * > 
GraphicsContexts
typedef std::list< ref_ptr
< Operation > > 
GraphicsOperationQueue
typedef std::list< osg::Camera * > Cameras

Public Member Functions

void add (Operation *operation)
 Add operation to end of OperationQueue.
void remove (Operation *operation)
 Remove operation from OperationQueue.
void remove (const std::string &name)
 Remove named operation from OperationQueue.
void removeAllOperations ()
 Remove all operations from OperationQueue.
void runOperations ()
 Run the operations.
GraphicsOperationQueuegetOperationsQueue ()
 Get the operations queue, not you must use the OperationsMutex when accessing the queue.
OpenThreads::Mutex * getOperationsMutex ()
 Get the operations queue mutex.
osg::RefBlockgetOperationsBlock ()
 Get the operations queue block used to mark an empty queue, if you end items into the empty queue you must release this block.
OperationgetCurrentOperation ()
 Get the current operations that is being run.
const TraitsgetTraits () const
 Get the traits of the GraphicsContext.
virtual bool valid () const =0
 Return whether a valid and usable GraphicsContext has been created.
void setState (State *state)
 Set the State object which tracks the current OpenGL state for this graphics context.
StategetState ()
 Get the State object which tracks the current OpenGL state for this graphics context.
const StategetState () const
 Get the const State object which tracks the current OpenGL state for this graphics context.
void setClearColor (const Vec4 &color)
 Sets the clear color.
const Vec4getClearColor () const
 Returns the clear color.
void setClearMask (GLbitfield mask)
 Set the clear mask used in glClear(..).
GLbitfield getClearMask () const
 Get the clear mask.
virtual void clear ()
 Do an OpenGL clear of the full graphics context/window.
double getTimeSinceLastClear () const
bool realize ()
 Realize the GraphicsContext.
void close (bool callCloseImplementation=true)
 close the graphics context.
void swapBuffers ()
 swap the front and back buffers.
bool isRealized () const
 Return true if the graphics context has been realized and is ready to use.
bool makeCurrent ()
 Make this graphics context current.
bool makeContextCurrent (GraphicsContext *readContext)
 Make this graphics context current with specified read context.
bool releaseContext ()
 Release the graphics context.
bool isCurrent () const
 Return true if the current thread has this OpenGL graphics context.
void bindPBufferToTexture (GLenum buffer)
 Bind the graphics context to associated texture.
void createGraphicsThread ()
 Create a graphics thread to the graphics context, so that the thread handles all OpenGL operations.
void setGraphicsThread (GraphicsThread *gt)
 Assign a graphics thread to the graphics context, so that the thread handles all OpenGL operations.
GraphicsThreadgetGraphicsThread ()
 Get the graphics thread assigned the graphics context.
const GraphicsThreadgetGraphicsThread () const
 Get the const graphics thread assigned the graphics context.
virtual bool realizeImplementation ()=0
 Realize the GraphicsContext implementation, Pure virtual - must be implemented by concrete implementations of GraphicsContext.
virtual bool isRealizedImplementation () const =0
 Return true if the graphics context has been realized, and is ready to use, implementation.
virtual void closeImplementation ()=0
 Close the graphics context implementation.
virtual bool makeCurrentImplementation ()=0
 Make this graphics context current implementation.
virtual bool makeContextCurrentImplementation (GraphicsContext *readContext)=0
 Make this graphics context current with specified read context implementation.
virtual bool releaseContextImplementation ()=0
 Release the graphics context implementation.
virtual void bindPBufferToTextureImplementation (GLenum buffer)=0
 Pure virtual, Bind the graphics context to associated texture implementation.
void setSwapCallback (SwapCallback *rc)
 Set the swap callback which overrides the GraphicsContext::swapBuffersImplementation(), allowing developers to provide custom behavior for swap.
SwapCallbackgetSwapCallback ()
 Get the swap callback which overrides the GraphicsContext::swapBuffersImplementation().
const SwapCallbackgetSwapCallback () const
 Get the const swap callback which overrides the GraphicsContext::swapBuffersImplementation().
void swapBuffersCallbackOrImplemenation ()
 convinience method for handling whether to call swapbuffers callback or the standard context swapBuffersImplementation.
virtual void swapBuffersImplementation ()=0
 Swap the front and back buffers implementation.
void resized (int x, int y, int width, int height)
 resized method should be called when the underlying window has been resized and the GraphicsWindow and associated Cameras must be updated to keep in sync with the new size.
void setResizedCallback (ResizedCallback *rc)
 Set the resized callback which overrides the GraphicsConext::realizedImplementation(), allow developers to provide custom behavior in response to a window being resized.
ResizedCallbackgetResizedCallback ()
 Get the resized callback which overrides the GraphicsConext::realizedImplementation().
const ResizedCallbackgetResizedCallback () const
 Get the const resized callback which overrides the GraphicsConext::realizedImplementation().
virtual void resizedImplementation (int x, int y, int width, int height)
 resized implementation, by default resizes the viewports and aspect ratios the cameras associated with the graphics Window.
CamerasgetCameras ()
 Get the the list of cameras associated with this graphics context.
const CamerasgetCameras () const
 Get the the const list of cameras associated with this graphics context.
void setDefaultFboId (GLuint i)
 set the default FBO-id, this id will be used when the rendering-backend is finished with RTT FBOs
GLuint getDefaultFboId () const
virtual bool isSameKindAs (const Object *object) const
virtual const char * libraryName () const
 return the name of the object's library.
virtual const char * className () const
 return the name of the object's class type.

Static Public Member Functions

static void setWindowingSystemInterface (WindowingSystemInterface *wsInterface)
 Set the query the windowing system for screens and create graphics context - this functor should be supplied by the windows toolkit.
static WindowingSystemInterfacegetWindowingSystemInterface ()
 Get the WindowingSystemInterface.
static GraphicsContextcreateGraphicsContext (Traits *traits)
 Create a graphics context for a specified set of traits.
static unsigned int createNewContextID ()
 Create a contextID for a new graphics context, this contextID is used to set up the osg::State associate with context.
static unsigned int getMaxContextID ()
 Get the current max ContextID.
static void incrementContextIDUsageCount (unsigned int contextID)
 Increment the usage count associate with a contextID.
static void decrementContextIDUsageCount (unsigned int contextID)
 Decrement the usage count associate with a contextID.
static GraphicsContexts getAllRegisteredGraphicsContexts ()
 Get all the registered graphics contexts.
static GraphicsContexts getRegisteredGraphicsContexts (unsigned int contextID)
 Get all the registered graphics contexts associated with a specific contextID.
static void setCompileContext (unsigned int contextID, GraphicsContext *gc)
 Get the GraphicsContext for doing background compilation for GraphicsContexts associated with specified contextID.
static GraphicsContextgetOrCreateCompileContext (unsigned int contextID)
 Get existing or create a new GraphicsContext to do background compilation for GraphicsContexts associated with specified contextID.
static GraphicsContextgetCompileContext (unsigned int contextID)
 Get the GraphicsContext for doing background compilation for GraphicsContexts associated with specified contextID.

Protected Member Functions

 GraphicsContext ()
 GraphicsContext (const GraphicsContext &, const osg::CopyOp &)
virtual ~GraphicsContext ()
virtual ObjectcloneType () const
 Clone the type of an object, with Object* return type.
virtual Objectclone (const CopyOp &) const
 Clone an object, with Object* return type.
void addCamera (osg::Camera *camera)
void removeCamera (osg::Camera *camera)

Static Protected Member Functions

static void registerGraphicsContext (GraphicsContext *gc)
 Register a GraphicsContext.
static void unregisterGraphicsContext (GraphicsContext *gc)
 Unregister a GraphicsContext.

Protected Attributes

Cameras _cameras
ref_ptr< Traits_traits
ref_ptr< State_state
Vec4 _clearColor
GLbitfield _clearMask
OpenThreads::Thread * _threadOfLastMakeCurrent
OpenThreads::Mutex _operationsMutex
osg::ref_ptr< osg::RefBlock_operationsBlock
GraphicsOperationQueue _operations
osg::ref_ptr< Operation_currentOperation
ref_ptr< GraphicsThread_graphicsThread
ref_ptr< ResizedCallback_resizedCallback
ref_ptr< SwapCallback_swapCallback
Timer_t _lastClearTick
GLuint _defaultFboId

Friends

class osg::Camera

Detailed Description

Base class for providing Windowing API agnostic access to creating and managing graphics context.


Member Typedef Documentation


Constructor & Destructor Documentation

osg::GraphicsContext::GraphicsContext ( ) [protected]
osg::GraphicsContext::GraphicsContext ( const GraphicsContext ,
const osg::CopyOp  
) [protected]
virtual osg::GraphicsContext::~GraphicsContext ( ) [protected, virtual]

Member Function Documentation

void osg::GraphicsContext::add ( Operation operation)

Add operation to end of OperationQueue.

void osg::GraphicsContext::addCamera ( osg::Camera camera) [protected]
void osg::GraphicsContext::bindPBufferToTexture ( GLenum  buffer) [inline]

Bind the graphics context to associated texture.

virtual void osg::GraphicsContext::bindPBufferToTextureImplementation ( GLenum  buffer) [pure virtual]

Pure virtual, Bind the graphics context to associated texture implementation.

Pure virtual - must be implemented by concrete implementations of GraphicsContext.

Implemented in osgViewer::GraphicsWindow, osgViewer::PixelBufferWin32, and osgViewer::PixelBufferX11.

virtual const char* osg::GraphicsContext::className ( ) const [inline, virtual]

return the name of the object's class type.

Must be defined by derived classes.

Implements osg::Object.

Reimplemented in osgViewer::GraphicsWindowEmbedded, osgViewer::GraphicsWindowX11, osgViewer::GraphicsWindow, osgViewer::GraphicsWindowWin32, osgViewer::PixelBufferWin32, and osgViewer::PixelBufferX11.

virtual void osg::GraphicsContext::clear ( ) [virtual]

Do an OpenGL clear of the full graphics context/window.

Note, must only be called from a thread with this context current.

virtual Object* osg::GraphicsContext::clone ( const CopyOp ) const [inline, protected, virtual]

Clone an object, with Object* return type.

Must be defined by derived classes.

Implements osg::Object.

virtual Object* osg::GraphicsContext::cloneType ( ) const [inline, protected, virtual]

Clone the type of an object, with Object* return type.

Must be defined by derived classes.

Implements osg::Object.

void osg::GraphicsContext::close ( bool  callCloseImplementation = true)

close the graphics context.

close(bool) stops any associated graphics threads, releases the contextID for the GraphicsContext then optional calls closeImplementation() to do the actual deletion of the graphics. This call is made optional as there are times when the graphics context has already been deleted externally and only the OSG side of the its data need to be closed down.

virtual void osg::GraphicsContext::closeImplementation ( ) [pure virtual]

Close the graphics context implementation.

Pure virtual - must be implemented by concrete implementations of GraphicsContext.

Implemented in osgViewer::GraphicsWindowEmbedded, osgViewer::GraphicsWindow, osgQt::GraphicsWindowQt, osgViewer::GraphicsWindowX11, osgViewer::GraphicsWindowWin32, osgViewer::PixelBufferWin32, and osgViewer::PixelBufferX11.

static GraphicsContext* osg::GraphicsContext::createGraphicsContext ( Traits traits) [static]

Create a graphics context for a specified set of traits.

void osg::GraphicsContext::createGraphicsThread ( )

Create a graphics thread to the graphics context, so that the thread handles all OpenGL operations.

static unsigned int osg::GraphicsContext::createNewContextID ( ) [static]

Create a contextID for a new graphics context, this contextID is used to set up the osg::State associate with context.

Automatically increments the usage count of the contextID to 1.

Referenced by osgViewer::GraphicsWindowX11::GraphicsWindowX11(), and osgViewer::GraphicsWindowEmbedded::init().

static void osg::GraphicsContext::decrementContextIDUsageCount ( unsigned int  contextID) [static]

Decrement the usage count associate with a contextID.

Once the contextID goes to 0 the contextID is then free to be reused.

static GraphicsContexts osg::GraphicsContext::getAllRegisteredGraphicsContexts ( ) [static]

Get all the registered graphics contexts.

Cameras& osg::GraphicsContext::getCameras ( ) [inline]

Get the the list of cameras associated with this graphics context.

const Cameras& osg::GraphicsContext::getCameras ( ) const [inline]

Get the the const list of cameras associated with this graphics context.

const Vec4& osg::GraphicsContext::getClearColor ( ) const [inline]

Returns the clear color.

GLbitfield osg::GraphicsContext::getClearMask ( ) const [inline]

Get the clear mask.

static GraphicsContext* osg::GraphicsContext::getCompileContext ( unsigned int  contextID) [static]

Get the GraphicsContext for doing background compilation for GraphicsContexts associated with specified contextID.

Operation* osg::GraphicsContext::getCurrentOperation ( ) [inline]

Get the current operations that is being run.

GLuint osg::GraphicsContext::getDefaultFboId ( ) const [inline]
GraphicsThread* osg::GraphicsContext::getGraphicsThread ( ) [inline]

Get the graphics thread assigned the graphics context.

const GraphicsThread* osg::GraphicsContext::getGraphicsThread ( ) const [inline]

Get the const graphics thread assigned the graphics context.

static unsigned int osg::GraphicsContext::getMaxContextID ( ) [static]

Get the current max ContextID.

osg::RefBlock* osg::GraphicsContext::getOperationsBlock ( ) [inline]

Get the operations queue block used to mark an empty queue, if you end items into the empty queue you must release this block.

OpenThreads::Mutex* osg::GraphicsContext::getOperationsMutex ( ) [inline]

Get the operations queue mutex.

GraphicsOperationQueue& osg::GraphicsContext::getOperationsQueue ( ) [inline]

Get the operations queue, not you must use the OperationsMutex when accessing the queue.

static GraphicsContext* osg::GraphicsContext::getOrCreateCompileContext ( unsigned int  contextID) [static]

Get existing or create a new GraphicsContext to do background compilation for GraphicsContexts associated with specified contextID.

static GraphicsContexts osg::GraphicsContext::getRegisteredGraphicsContexts ( unsigned int  contextID) [static]

Get all the registered graphics contexts associated with a specific contextID.

ResizedCallback* osg::GraphicsContext::getResizedCallback ( ) [inline]

Get the resized callback which overrides the GraphicsConext::realizedImplementation().

const ResizedCallback* osg::GraphicsContext::getResizedCallback ( ) const [inline]

Get the const resized callback which overrides the GraphicsConext::realizedImplementation().

State* osg::GraphicsContext::getState ( ) [inline]

Get the State object which tracks the current OpenGL state for this graphics context.

Referenced by osgViewer::GraphicsWindowEmbedded::init().

const State* osg::GraphicsContext::getState ( ) const [inline]

Get the const State object which tracks the current OpenGL state for this graphics context.

SwapCallback* osg::GraphicsContext::getSwapCallback ( ) [inline]

Get the swap callback which overrides the GraphicsContext::swapBuffersImplementation().

const SwapCallback* osg::GraphicsContext::getSwapCallback ( ) const [inline]

Get the const swap callback which overrides the GraphicsContext::swapBuffersImplementation().

double osg::GraphicsContext::getTimeSinceLastClear ( ) const [inline]
const Traits* osg::GraphicsContext::getTraits ( ) const [inline]

Get the traits of the GraphicsContext.

static WindowingSystemInterface* osg::GraphicsContext::getWindowingSystemInterface ( ) [static]
static void osg::GraphicsContext::incrementContextIDUsageCount ( unsigned int  contextID) [static]

Increment the usage count associate with a contextID.

The usage count specifies how many graphics contexts a specific contextID is shared between.

Referenced by osgViewer::GraphicsWindowEmbedded::init().

bool osg::GraphicsContext::isCurrent ( ) const [inline]

Return true if the current thread has this OpenGL graphics context.

bool osg::GraphicsContext::isRealized ( ) const [inline]

Return true if the graphics context has been realized and is ready to use.

virtual bool osg::GraphicsContext::isRealizedImplementation ( ) const [pure virtual]

Return true if the graphics context has been realized, and is ready to use, implementation.

Pure virtual - must be implemented by concrete implementations of GraphicsContext.

Implemented in osgViewer::GraphicsWindowEmbedded, osgViewer::GraphicsWindow, osgQt::GraphicsWindowQt, osgViewer::GraphicsWindowX11, osgViewer::GraphicsWindowWin32, osgViewer::PixelBufferWin32, and osgViewer::PixelBufferX11.

virtual bool osg::GraphicsContext::isSameKindAs ( const Object object) const [inline, virtual]

Reimplemented from osg::Object.

virtual const char* osg::GraphicsContext::libraryName ( ) const [inline, virtual]

return the name of the object's library.

Must be defined by derived classes. The OpenSceneGraph convention is that the namespace of a library is the same as the library name.

Implements osg::Object.

Reimplemented in osgViewer::GraphicsWindowEmbedded, osgViewer::GraphicsWindowX11, osgViewer::GraphicsWindow, osgViewer::GraphicsWindowWin32, osgViewer::PixelBufferWin32, and osgViewer::PixelBufferX11.

bool osg::GraphicsContext::makeContextCurrent ( GraphicsContext readContext)

Make this graphics context current with specified read context.

Implemented by calling makeContextCurrentImplementation(). Returns true on success.

virtual bool osg::GraphicsContext::makeContextCurrentImplementation ( GraphicsContext readContext) [pure virtual]

Make this graphics context current with specified read context implementation.

Pure virtual - must be implemented by concrete implementations of GraphicsContext.

Implemented in osgViewer::PixelBufferX11.

bool osg::GraphicsContext::makeCurrent ( )

Make this graphics context current.

Implemented by calling makeCurrentImplementation(). Returns true on success.

Referenced by osgViewer::ViewerBase::makeCurrent().

virtual bool osg::GraphicsContext::makeCurrentImplementation ( ) [pure virtual]

Make this graphics context current implementation.

Pure virtual - must be implemented by concrete implementations of GraphicsContext.

Implemented in osgViewer::GraphicsWindowEmbedded, osgViewer::GraphicsWindow, osgQt::GraphicsWindowQt, osgViewer::GraphicsWindowX11, osgViewer::GraphicsWindowWin32, osgViewer::PixelBufferWin32, and osgViewer::PixelBufferX11.

bool osg::GraphicsContext::realize ( )

Realize the GraphicsContext.

virtual bool osg::GraphicsContext::realizeImplementation ( ) [pure virtual]
static void osg::GraphicsContext::registerGraphicsContext ( GraphicsContext gc) [static, protected]

Register a GraphicsContext.

bool osg::GraphicsContext::releaseContext ( )

Release the graphics context.

Returns true on success.

Referenced by osgViewer::ViewerBase::releaseContext().

virtual bool osg::GraphicsContext::releaseContextImplementation ( ) [pure virtual]
void osg::GraphicsContext::remove ( Operation operation)

Remove operation from OperationQueue.

void osg::GraphicsContext::remove ( const std::string &  name)

Remove named operation from OperationQueue.

void osg::GraphicsContext::removeAllOperations ( )

Remove all operations from OperationQueue.

void osg::GraphicsContext::removeCamera ( osg::Camera camera) [protected]
void osg::GraphicsContext::resized ( int  x,
int  y,
int  width,
int  height 
) [inline]

resized method should be called when the underlying window has been resized and the GraphicsWindow and associated Cameras must be updated to keep in sync with the new size.

virtual void osg::GraphicsContext::resizedImplementation ( int  x,
int  y,
int  width,
int  height 
) [virtual]

resized implementation, by default resizes the viewports and aspect ratios the cameras associated with the graphics Window.

void osg::GraphicsContext::runOperations ( )

Run the operations.

void osg::GraphicsContext::setClearColor ( const Vec4 color) [inline]

Sets the clear color.

void osg::GraphicsContext::setClearMask ( GLbitfield  mask) [inline]

Set the clear mask used in glClear(..).

Defaults to 0 - so no clear is done by default by the GraphicsContext, instead the Camera's attached the GraphicsContext will do the clear. GraphicsContext::setClearMask() is useful for when the Camera's Viewports don't conver the whole context, so the context will fill in the gaps.

static void osg::GraphicsContext::setCompileContext ( unsigned int  contextID,
GraphicsContext gc 
) [static]

Get the GraphicsContext for doing background compilation for GraphicsContexts associated with specified contextID.

void osg::GraphicsContext::setDefaultFboId ( GLuint  i) [inline]

set the default FBO-id, this id will be used when the rendering-backend is finished with RTT FBOs

void osg::GraphicsContext::setGraphicsThread ( GraphicsThread gt)

Assign a graphics thread to the graphics context, so that the thread handles all OpenGL operations.

void osg::GraphicsContext::setResizedCallback ( ResizedCallback rc) [inline]

Set the resized callback which overrides the GraphicsConext::realizedImplementation(), allow developers to provide custom behavior in response to a window being resized.

void osg::GraphicsContext::setState ( State state) [inline]

Set the State object which tracks the current OpenGL state for this graphics context.

Referenced by osgViewer::GraphicsWindowEmbedded::init().

void osg::GraphicsContext::setSwapCallback ( SwapCallback rc) [inline]

Set the swap callback which overrides the GraphicsContext::swapBuffersImplementation(), allowing developers to provide custom behavior for swap.

The callback must call GraphicsContext::swapBuffersImplementation()

static void osg::GraphicsContext::setWindowingSystemInterface ( WindowingSystemInterface wsInterface) [static]

Set the query the windowing system for screens and create graphics context - this functor should be supplied by the windows toolkit.

void osg::GraphicsContext::swapBuffers ( )

swap the front and back buffers.

void osg::GraphicsContext::swapBuffersCallbackOrImplemenation ( ) [inline]

convinience method for handling whether to call swapbuffers callback or the standard context swapBuffersImplementation.

swapBuffersCallbackOrImplemenation() is called by swapBuffers() and osg::SwapBuffersOperation, end users should normally call swapBuffers() rather than swapBuffersCallbackOrImplemenation().

References osg::GraphicsContext::SwapCallback::swapBuffersImplementation().

virtual void osg::GraphicsContext::swapBuffersImplementation ( ) [pure virtual]

Swap the front and back buffers implementation.

Pure virtual - must be implemented by concrete implementations of GraphicsContext.

Implemented in osgViewer::GraphicsWindowEmbedded, osgViewer::GraphicsWindow, osgQt::GraphicsWindowQt, osgViewer::GraphicsWindowX11, osgViewer::PixelBufferX11, osgViewer::PixelBufferWin32, and osgViewer::GraphicsWindowWin32.

static void osg::GraphicsContext::unregisterGraphicsContext ( GraphicsContext gc) [static, protected]

Unregister a GraphicsContext.

virtual bool osg::GraphicsContext::valid ( ) const [pure virtual]

Friends And Related Function Documentation

friend class osg::Camera [friend]

Member Data Documentation

GLbitfield osg::GraphicsContext::_clearMask [protected]
OpenThreads::Mutex osg::GraphicsContext::_operationsMutex [protected]
OpenThreads::Thread* osg::GraphicsContext::_threadOfLastMakeCurrent [protected]

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

osg logo
Generated at Mon Oct 3 2011 12:39:42 for the OpenSceneGraph by doxygen 1.7.5.