Copyright | Will Thompson Iñaki García Etxebarria and Jonas Platte |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria (inaki@blueleaf.cc) |
Safe Haskell | None |
Language | Haskell2010 |
GLContext
is an object representing the platform-specific
OpenGL drawing context.
GdkGLContexts
are created for a Window
using
windowCreateGlContext
, and the context will match
the Visual
of the window.
A GLContext
is not tied to any particular normal framebuffer.
For instance, it cannot draw to the Window
back buffer. The GDK
repaint system is in full control of the painting to that. Instead,
you can create render buffers or textures and use cairoDrawFromGl
in the draw function of your widget to draw them. Then GDK will handle
the integration of your rendering with that of other widgets.
Support for GLContext
is platform-specific, context creation
can fail, returning Nothing
context.
A GLContext
has to be made "current" in order to start using
it, otherwise any OpenGL call will be ignored.
Creating a new OpenGL context
In order to create a new GLContext
instance you need a
Window
, which you typically get during the realize call
of a widget.
A GLContext
is not realized until either gLContextMakeCurrent
,
or until it is realized using gLContextRealize
. It is possible to
specify details of the GL context like the OpenGL version to be used, or
whether the GL context should have extra state validation enabled after
calling windowCreateGlContext
by calling gLContextRealize
.
If the realization fails you have the option to change the settings of the
GLContext
and try again.
Using a GdkGLContext
You will need to make the GLContext
the current context
before issuing OpenGL calls; the system sends OpenGL commands to
whichever context is current. It is possible to have multiple
contexts, so you always need to ensure that the one which you
want to draw with is the current one before issuing commands:
C code
gdk_gl_context_make_current (context);
You can now perform your drawing using OpenGL commands.
You can check which GLContext
is the current one by using
gLContextGetCurrent
; you can also unset any GLContext
that is currently set by calling gLContextClearCurrent
.
Synopsis
- newtype GLContext = GLContext (ManagedPtr GLContext)
- class (GObject o, IsDescendantOf GLContext o) => IsGLContext o
- toGLContext :: (MonadIO m, IsGLContext o) => o -> m GLContext
- noGLContext :: Maybe GLContext
- gLContextClearCurrent :: (HasCallStack, MonadIO m) => m ()
- gLContextGetCurrent :: (HasCallStack, MonadIO m) => m (Maybe GLContext)
- gLContextGetDebugEnabled :: (HasCallStack, MonadIO m, IsGLContext a) => a -> m Bool
- gLContextGetDisplay :: (HasCallStack, MonadIO m, IsGLContext a) => a -> m (Maybe Display)
- gLContextGetForwardCompatible :: (HasCallStack, MonadIO m, IsGLContext a) => a -> m Bool
- gLContextGetRequiredVersion :: (HasCallStack, MonadIO m, IsGLContext a) => a -> m (Int32, Int32)
- gLContextGetSharedContext :: (HasCallStack, MonadIO m, IsGLContext a) => a -> m (Maybe GLContext)
- gLContextGetUseEs :: (HasCallStack, MonadIO m, IsGLContext a) => a -> m Bool
- gLContextGetVersion :: (HasCallStack, MonadIO m, IsGLContext a) => a -> m (Int32, Int32)
- gLContextGetWindow :: (HasCallStack, MonadIO m, IsGLContext a) => a -> m (Maybe Window)
- gLContextIsLegacy :: (HasCallStack, MonadIO m, IsGLContext a) => a -> m Bool
- gLContextMakeCurrent :: (HasCallStack, MonadIO m, IsGLContext a) => a -> m ()
- gLContextRealize :: (HasCallStack, MonadIO m, IsGLContext a) => a -> m ()
- gLContextSetDebugEnabled :: (HasCallStack, MonadIO m, IsGLContext a) => a -> Bool -> m ()
- gLContextSetForwardCompatible :: (HasCallStack, MonadIO m, IsGLContext a) => a -> Bool -> m ()
- gLContextSetRequiredVersion :: (HasCallStack, MonadIO m, IsGLContext a) => a -> Int32 -> Int32 -> m ()
- gLContextSetUseEs :: (HasCallStack, MonadIO m, IsGLContext a) => a -> Int32 -> m ()
- constructGLContextDisplay :: (IsGLContext o, IsDisplay a) => a -> IO (GValueConstruct o)
- getGLContextDisplay :: (MonadIO m, IsGLContext o) => o -> m (Maybe Display)
- constructGLContextSharedContext :: (IsGLContext o, IsGLContext a) => a -> IO (GValueConstruct o)
- getGLContextSharedContext :: (MonadIO m, IsGLContext o) => o -> m (Maybe GLContext)
- constructGLContextWindow :: (IsGLContext o, IsWindow a) => a -> IO (GValueConstruct o)
- getGLContextWindow :: (MonadIO m, IsGLContext o) => o -> m (Maybe Window)
Exported types
Memory-managed wrapper type.
Instances
GObject GLContext Source # | |
Defined in GI.Gdk.Objects.GLContext gobjectType :: IO GType # | |
HasParentTypes GLContext Source # | |
Defined in GI.Gdk.Objects.GLContext | |
type ParentTypes GLContext Source # | |
Defined in GI.Gdk.Objects.GLContext |
class (GObject o, IsDescendantOf GLContext o) => IsGLContext o Source #
Type class for types which can be safely cast to GLContext
, for instance with toGLContext
.
Instances
(GObject o, IsDescendantOf GLContext o) => IsGLContext o Source # | |
Defined in GI.Gdk.Objects.GLContext |
toGLContext :: (MonadIO m, IsGLContext o) => o -> m GLContext Source #
Methods
clearCurrent
gLContextClearCurrent :: (HasCallStack, MonadIO m) => m () Source #
Clears the current GLContext
.
Any OpenGL call after this function returns will be ignored
until gLContextMakeCurrent
is called.
Since: 3.16
getCurrent
Retrieves the current GLContext
.
Since: 3.16
getDebugEnabled
gLContextGetDebugEnabled Source #
:: (HasCallStack, MonadIO m, IsGLContext a) | |
=> a |
|
-> m Bool | Returns: |
Retrieves the value set using gLContextSetDebugEnabled
.
Since: 3.16
getDisplay
:: (HasCallStack, MonadIO m, IsGLContext a) | |
=> a |
|
-> m (Maybe Display) |
Retrieves the Display
the context
is created for
Since: 3.16
getForwardCompatible
gLContextGetForwardCompatible Source #
:: (HasCallStack, MonadIO m, IsGLContext a) | |
=> a |
|
-> m Bool | Returns: |
Retrieves the value set using gLContextSetForwardCompatible
.
Since: 3.16
getRequiredVersion
gLContextGetRequiredVersion Source #
:: (HasCallStack, MonadIO m, IsGLContext a) | |
=> a |
|
-> m (Int32, Int32) |
Retrieves the major and minor version requested by calling
gLContextSetRequiredVersion
.
Since: 3.16
getSharedContext
gLContextGetSharedContext Source #
:: (HasCallStack, MonadIO m, IsGLContext a) | |
=> a |
|
-> m (Maybe GLContext) |
Retrieves the GLContext
that this context
share data with.
Since: 3.16
getUseEs
:: (HasCallStack, MonadIO m, IsGLContext a) | |
=> a |
|
-> m Bool | Returns: |
Checks whether the context
is using an OpenGL or OpenGL ES profile.
Since: 3.22
getVersion
:: (HasCallStack, MonadIO m, IsGLContext a) | |
=> a |
|
-> m (Int32, Int32) |
Retrieves the OpenGL version of the context
.
The context
must be realized prior to calling this function.
Since: 3.16
getWindow
:: (HasCallStack, MonadIO m, IsGLContext a) | |
=> a |
|
-> m (Maybe Window) |
Retrieves the Window
used by the context
.
Since: 3.16
isLegacy
:: (HasCallStack, MonadIO m, IsGLContext a) | |
=> a |
|
-> m Bool | Returns: |
Whether the GLContext
is in legacy mode or not.
The GLContext
must be realized before calling this function.
When realizing a GL context, GDK will try to use the OpenGL 3.2 core
profile; this profile removes all the OpenGL API that was deprecated
prior to the 3.2 version of the specification. If the realization is
successful, this function will return False
.
If the underlying OpenGL implementation does not support core profiles,
GDK will fall back to a pre-3.2 compatibility profile, and this function
will return True
.
You can use the value returned by this function to decide which kind of OpenGL API to use, or whether to do extension discovery, or what kind of shader programs to load.
Since: 3.20
makeCurrent
:: (HasCallStack, MonadIO m, IsGLContext a) | |
=> a |
|
-> m () |
Makes the context
the current one.
Since: 3.16
realize
:: (HasCallStack, MonadIO m, IsGLContext a) | |
=> a |
|
-> m () | (Can throw |
setDebugEnabled
gLContextSetDebugEnabled Source #
:: (HasCallStack, MonadIO m, IsGLContext a) | |
=> a |
|
-> Bool |
|
-> m () |
setForwardCompatible
gLContextSetForwardCompatible Source #
:: (HasCallStack, MonadIO m, IsGLContext a) | |
=> a |
|
-> Bool |
|
-> m () |
Sets whether the GLContext
should be forward compatible.
Forward compatibile contexts must not support OpenGL functionality that has been marked as deprecated in the requested version; non-forward compatible contexts, on the other hand, must support both deprecated and non deprecated functionality.
The GLContext
must not be realized or made current prior to calling
this function.
Since: 3.16
setRequiredVersion
gLContextSetRequiredVersion Source #
:: (HasCallStack, MonadIO m, IsGLContext a) | |
=> a |
|
-> Int32 |
|
-> Int32 |
|
-> m () |
Sets the major and minor version of OpenGL to request.
Setting major
and minor
to zero will use the default values.
The GLContext
must not be realized or made current prior to calling
this function.
Since: 3.16
setUseEs
:: (HasCallStack, MonadIO m, IsGLContext a) | |
=> a |
|
-> Int32 |
|
-> m () |
Requests that GDK create a OpenGL ES context instead of an OpenGL one, if the platform and windowing system allows it.
The context
must not have been realized.
By default, GDK will attempt to automatically detect whether the
underlying GL implementation is OpenGL or OpenGL ES once the context
is realized.
You should check the return value of gLContextGetUseEs
after
calling gLContextRealize
to decide whether to use the OpenGL or
OpenGL ES API, extensions, or shaders.
Since: 3.22
Properties
display
constructGLContextDisplay :: (IsGLContext o, IsDisplay a) => a -> IO (GValueConstruct o) Source #
Construct a GValueConstruct
with valid value for the “display
” property. This is rarely needed directly, but it is used by new
.
getGLContextDisplay :: (MonadIO m, IsGLContext o) => o -> m (Maybe Display) Source #
Get the value of the “display
” property.
When overloading is enabled, this is equivalent to
get
gLContext #display
sharedContext
constructGLContextSharedContext :: (IsGLContext o, IsGLContext a) => a -> IO (GValueConstruct o) Source #
Construct a GValueConstruct
with valid value for the “shared-context
” property. This is rarely needed directly, but it is used by new
.
getGLContextSharedContext :: (MonadIO m, IsGLContext o) => o -> m (Maybe GLContext) Source #
Get the value of the “shared-context
” property.
When overloading is enabled, this is equivalent to
get
gLContext #sharedContext
window
The Window
the gl context is bound to.
Since: 3.16
constructGLContextWindow :: (IsGLContext o, IsWindow a) => a -> IO (GValueConstruct o) Source #
Construct a GValueConstruct
with valid value for the “window
” property. This is rarely needed directly, but it is used by new
.
getGLContextWindow :: (MonadIO m, IsGLContext o) => o -> m (Maybe Window) Source #
Get the value of the “window
” property.
When overloading is enabled, this is equivalent to
get
gLContext #window