A component that contains an OpenGL canvas. More...
Inherits Component.
Public Types | |
| enum | OpenGLType { openGLDefault = 0 } |
Used to select the type of openGL API to use, if more than one choice is available on a particular platform. More... | |
Public Member Functions | |
| OpenGLComponent (OpenGLType type=openGLDefault) | |
| Creates an OpenGLComponent. | |
| ~OpenGLComponent () | |
| Destructor. | |
| void | setPixelFormat (const OpenGLPixelFormat &formatToUse) |
| Changes the pixel format used by this component. | |
| const OpenGLPixelFormat | getPixelFormat () const |
| Returns the pixel format that this component is currently using. | |
| void | shareWith (OpenGLContext *contextToShareListsWith) |
| Specifies an OpenGL context which should be shared with the one that this component is using. | |
| OpenGLContext * | getShareContext () const throw () |
| Returns the context that this component is sharing with. | |
| void | swapBuffers () |
| Flips the openGL buffers over. | |
| virtual void | renderOpenGL ()=0 |
| This replaces the normal paint() callback - use it to draw your openGL stuff. | |
| virtual void | newOpenGLContextCreated ()=0 |
| This method is called when the component creates a new OpenGL context. | |
| OpenGLContext * | getCurrentContext () const throw () |
| Returns the context that will draw into this component. | |
| bool | makeCurrentContextActive () |
| Makes this component the current openGL context. | |
| void | makeCurrentContextInactive () |
| Stops the current component being the active OpenGL context. | |
| bool | isActiveContext () const throw () |
| Returns true if this component is the active openGL context for the current thread. | |
| virtual bool | renderAndSwapBuffers () |
| Calls the rendering callback, and swaps the buffers afterwards. | |
| CriticalSection & | getContextLock () throw () |
| This returns a critical section that can be used to lock the current context. | |
| void | paint (Graphics &g) |
| void * | getNativeWindowHandle () const |
| Returns the native handle of an embedded heavyweight window, if there is one. | |
A component that contains an OpenGL canvas.
Override this, add it to whatever component you want to, and use the renderOpenGL() method to draw its contents.
| OpenGLComponent::OpenGLComponent | ( | OpenGLType | type = openGLDefault |
) |
Creates an OpenGLComponent.
| OpenGLComponent::~OpenGLComponent | ( | ) |
Destructor.
| void OpenGLComponent::setPixelFormat | ( | const OpenGLPixelFormat & | formatToUse | ) |
Changes the pixel format used by this component.
| const OpenGLPixelFormat OpenGLComponent::getPixelFormat | ( | ) | const |
Returns the pixel format that this component is currently using.
| void OpenGLComponent::shareWith | ( | OpenGLContext * | contextToShareListsWith | ) |
Specifies an OpenGL context which should be shared with the one that this component is using.
This is an OpenGL feature that lets two contexts share their texture data.
Note that this pointer is stored by the component, and when the component needs to recreate its internal context for some reason, the same context will be used again to share lists. So if you pass a context in here, don't delete the context while this component is still using it! You can call shareWith (0) to stop this component from sharing with it.
| OpenGLContext* OpenGLComponent::getShareContext | ( | ) | const throw () |
Returns the context that this component is sharing with.
| void OpenGLComponent::swapBuffers | ( | ) |
Flips the openGL buffers over.
| virtual void OpenGLComponent::renderOpenGL | ( | ) | [pure virtual] |
This replaces the normal paint() callback - use it to draw your openGL stuff.
When this is called, makeCurrentContextActive() will already have been called for you, so you just need to draw.
| virtual void OpenGLComponent::newOpenGLContextCreated | ( | ) | [pure virtual] |
This method is called when the component creates a new OpenGL context.
A new context may be created when the component is first used, or when it is moved to a different window, or when the window is hidden and re-shown, etc.
You can use this callback as an opportunity to set up things like textures that your context needs.
New contexts are created on-demand by the makeCurrentContextActive() method - so if the context is deleted, e.g. by changing the pixel format or window, no context will be created until the next call to makeCurrentContextActive(), which will synchronously create one and call this method. This means that if you're using a non-GUI thread for rendering, you can make sure this method is be called by your renderer thread.
When this callback happens, the context will already have been made current using the makeCurrentContextActive() method, so there's no need to call it again in your code.
| OpenGLContext* OpenGLComponent::getCurrentContext | ( | ) | const throw () |
Returns the context that will draw into this component.
This may return 0 if the component is currently invisible or hasn't currently got a context. The context object can be deleted and a new one created during the lifetime of this component, and there may be times when it doesn't have one.
| bool OpenGLComponent::makeCurrentContextActive | ( | ) |
Makes this component the current openGL context.
You might want to use this in things like your resize() method, before calling GL commands.
If this returns false, then the context isn't active, so you should avoid making any calls.
This call may actually create a context if one isn't currently initialised. If it does this, it will also synchronously call the newOpenGLContextCreated() method to let you initialise it as necessary.
| void OpenGLComponent::makeCurrentContextInactive | ( | ) |
Stops the current component being the active OpenGL context.
This is the opposite of makeCurrentContextActive()
| bool OpenGLComponent::isActiveContext | ( | ) | const throw () |
Returns true if this component is the active openGL context for the current thread.
| virtual bool OpenGLComponent::renderAndSwapBuffers | ( | ) | [virtual] |
Calls the rendering callback, and swaps the buffers afterwards.
This is called automatically by paint() when the component needs to be rendered.
It can be overridden if you need to decouple the rendering from the paint callback and render with a custom thread.
Returns true if the operation succeeded.
| CriticalSection& OpenGLComponent::getContextLock | ( | ) | throw () |
This returns a critical section that can be used to lock the current context.
Because the context that is used by this component can change, e.g. when the component is shown or hidden, then if you're rendering to it on a background thread, this allows you to lock the context for the duration of your rendering routine.
| void OpenGLComponent::paint | ( | Graphics & | g | ) | [virtual] |
For internal use only.
Reimplemented from Component.
| void* OpenGLComponent::getNativeWindowHandle | ( | ) | const |
Returns the native handle of an embedded heavyweight window, if there is one.
E.g. On windows, this will return the HWND of the sub-window containing the opengl context, on the mac it'll be the NSOpenGLView.
1.6.3