Version: 3.1.1
wxGLContext Class Reference

#include <wx/glcanvas.h>

+ Inheritance diagram for wxGLContext:

Detailed Description

An instance of a wxGLContext represents the state of an OpenGL state machine and the connection between OpenGL and the system.

The OpenGL state includes everything that can be set with the OpenGL API: colors, rendering variables, buffer data ids, texture objects, etc. It is possible to have multiple rendering contexts share buffer data and textures. This feature is specially useful when the application use multiple threads for updating data into the memory of the graphics card.

Whether one only rendering context is used with or bound to multiple output windows or if each window has its own bound context is a developer decision. It is important to take into account that GPU makers may set different pointers to the same OGL function for different contexts. The way these pointers are retrieved from the OGL driver should be used again for each new context.

Binding (making current) a rendering context with another instance of a wxGLCanvas however works only if the both wxGLCanvas instances were created with the same attributes.

OpenGL version 3 introduced a new type of specification profile, the modern core profile. The old compatibility profile maintains all legacy features. Since wxWidgets 3.1.0 you can choose the type of context and even ask for a specified OGL version number. However, its advised to use only core profile as the compatibility profile may run a bit slower.

OpenGL core profile specification defines several flags at context creation that determine not only the type of context but also some features. Some of these flags can be set in the list of attributes used at wxGLCanvas ctor. But since wxWidgets 3.1.0 it is strongly encouraged to use the new mechanism: setting the context attributes with a wxGLContextAttrs object and the canvas attributes with a wxGLAttributes object.

The best way of knowing if your OpenGL environment supports a specific type of context is creating a wxGLContext instance and checking wxGLContext::IsOK(). If it returns false, then simply delete that instance and create a new one with other attributes.

wxHAS_OPENGL_ES is defined on platforms that only have this implementation available (e.g. the iPhone) and don't support the full specification.

Library:  wxGL
Category:  OpenGL
See also
wxGLCanvas, wxGLContextAttrs, wxGLAttributes

Public Member Functions

 wxGLContext (wxGLCanvas *win, const wxGLContext *other=NULL, const wxGLContextAttrs *ctxAttrs=NULL)
 Constructor. More...
 
bool IsOK ()
 Checks if the underlying OpenGL rendering context was correctly created by the system with the requested attributes. More...
 
virtual bool SetCurrent (const wxGLCanvas &win) const
 Makes the OpenGL state that is represented by this rendering context current with the wxGLCanvas win. More...
 
- Public Member Functions inherited from wxObject
 wxObject ()
 Default ctor; initializes to NULL the internal reference data. More...
 
 wxObject (const wxObject &other)
 Copy ctor. More...
 
virtual ~wxObject ()
 Destructor. More...
 
virtual wxClassInfoGetClassInfo () const
 This virtual function is redefined for every class that requires run-time type information, when using the wxDECLARE_CLASS macro (or similar). More...
 
wxObjectRefDataGetRefData () const
 Returns the wxObject::m_refData pointer, i.e. the data referenced by this object. More...
 
bool IsKindOf (const wxClassInfo *info) const
 Determines whether this class is a subclass of (or the same class as) the given class. More...
 
bool IsSameAs (const wxObject &obj) const
 Returns true if this object has the same data pointer as obj. More...
 
void Ref (const wxObject &clone)
 Makes this object refer to the data in clone. More...
 
void SetRefData (wxObjectRefData *data)
 Sets the wxObject::m_refData pointer. More...
 
void UnRef ()
 Decrements the reference count in the associated data, and if it is zero, deletes the data. More...
 
void UnShare ()
 This is the same of AllocExclusive() but this method is public. More...
 
void operator delete (void *buf)
 The delete operator is defined for debugging versions of the library only, when the identifier WXDEBUG is defined. More...
 
void * operator new (size_t size, const wxString &filename=NULL, int lineNum=0)
 The new operator is defined for debugging versions of the library only, when the identifier WXDEBUG is defined. More...
 

Additional Inherited Members

- Protected Member Functions inherited from wxObject
void AllocExclusive ()
 Ensure that this object's data is not shared with any other object. More...
 
virtual wxObjectRefDataCreateRefData () const
 Creates a new instance of the wxObjectRefData-derived class specific to this object and returns it. More...
 
virtual wxObjectRefDataCloneRefData (const wxObjectRefData *data) const
 Creates a new instance of the wxObjectRefData-derived class specific to this object and initializes it copying data. More...
 
- Protected Attributes inherited from wxObject
wxObjectRefDatam_refData
 Pointer to an object which is the object's reference-counted data. More...
 

Constructor & Destructor Documentation

wxGLContext::wxGLContext ( wxGLCanvas win,
const wxGLContext other = NULL,
const wxGLContextAttrs ctxAttrs = NULL 
)

Constructor.

Parameters
winThe canvas that is used to initialize this context. This parameter is needed only temporarily, and the caller may do anything with it (e.g. destroy the window) after the constructor returned.
It will be possible to bind (make current) this context to any other wxGLCanvas that has been created with equivalent attributes as win.
otherContext to share some data with or NULL (the default) for no sharing.
ctxAttrsA wxGLContextAttrs pointer to the attributes used for defining the flags when OGL >= 3.2 is requested. This is the preferred method since wxWidgets 3.1.0. The previous method (still available for backwards compatibility) is to define the attributes at wxGLCanvas ctor. If this parameter is NULL (the default) then that previous method is taken. If no attributes are defined at all, then those provided by the GPU driver defaults will be used.

Member Function Documentation

bool wxGLContext::IsOK ( )

Checks if the underlying OpenGL rendering context was correctly created by the system with the requested attributes.

If this function returns false then the wxGLContext object is useless and should be deleted and recreated with different attributes.

Since
3.1.0
virtual bool wxGLContext::SetCurrent ( const wxGLCanvas win) const
virtual

Makes the OpenGL state that is represented by this rendering context current with the wxGLCanvas win.

Note
win can be a different wxGLCanvas window than the one that was passed to the constructor of this rendering context. If RC is an object of type wxGLContext, the statements "RC.SetCurrent(win);" and "win.SetCurrent(RC);" are equivalent, see wxGLCanvas::SetCurrent().