Copyright | Will Thompson, Iñaki García Etxebarria and Jonas Platte |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria (garetxe@gmail.com) |
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
.
- newtype GLContext = GLContext (ManagedPtr GLContext)
- class GObject o => IsGLContext o
- toGLContext :: IsGLContext o => o -> IO GLContext
- noGLContext :: Maybe GLContext
- gLContextClearCurrent :: (HasCallStack, MonadIO m) => m ()
- gLContextGetCurrent :: (HasCallStack, MonadIO m) => m (Maybe GLContext)
- data GLContextGetDebugEnabledMethodInfo
- gLContextGetDebugEnabled :: (HasCallStack, MonadIO m, IsGLContext a) => a -> m Bool
- data GLContextGetDisplayMethodInfo
- gLContextGetDisplay :: (HasCallStack, MonadIO m, IsGLContext a) => a -> m (Maybe Display)
- data GLContextGetForwardCompatibleMethodInfo
- gLContextGetForwardCompatible :: (HasCallStack, MonadIO m, IsGLContext a) => a -> m Bool
- data GLContextGetRequiredVersionMethodInfo
- gLContextGetRequiredVersion :: (HasCallStack, MonadIO m, IsGLContext a) => a -> m (Int32, Int32)
- data GLContextGetSharedContextMethodInfo
- gLContextGetSharedContext :: (HasCallStack, MonadIO m, IsGLContext a) => a -> m (Maybe GLContext)
- data GLContextGetUseEsMethodInfo
- gLContextGetUseEs :: (HasCallStack, MonadIO m, IsGLContext a) => a -> m Bool
- data GLContextGetVersionMethodInfo
- gLContextGetVersion :: (HasCallStack, MonadIO m, IsGLContext a) => a -> m (Int32, Int32)
- data GLContextGetWindowMethodInfo
- gLContextGetWindow :: (HasCallStack, MonadIO m, IsGLContext a) => a -> m (Maybe Window)
- data GLContextIsLegacyMethodInfo
- gLContextIsLegacy :: (HasCallStack, MonadIO m, IsGLContext a) => a -> m Bool
- data GLContextMakeCurrentMethodInfo
- gLContextMakeCurrent :: (HasCallStack, MonadIO m, IsGLContext a) => a -> m ()
- data GLContextRealizeMethodInfo
- gLContextRealize :: (HasCallStack, MonadIO m, IsGLContext a) => a -> m ()
- data GLContextSetDebugEnabledMethodInfo
- gLContextSetDebugEnabled :: (HasCallStack, MonadIO m, IsGLContext a) => a -> Bool -> m ()
- data GLContextSetForwardCompatibleMethodInfo
- gLContextSetForwardCompatible :: (HasCallStack, MonadIO m, IsGLContext a) => a -> Bool -> m ()
- data GLContextSetRequiredVersionMethodInfo
- gLContextSetRequiredVersion :: (HasCallStack, MonadIO m, IsGLContext a) => a -> Int32 -> Int32 -> m ()
- data GLContextSetUseEsMethodInfo
- gLContextSetUseEs :: (HasCallStack, MonadIO m, IsGLContext a) => a -> Int32 -> m ()
- data GLContextDisplayPropertyInfo
- constructGLContextDisplay :: (IsGLContext o, IsDisplay a) => a -> IO (GValueConstruct o)
- gLContextDisplay :: AttrLabelProxy "display"
- getGLContextDisplay :: (MonadIO m, IsGLContext o) => o -> m (Maybe Display)
- data GLContextSharedContextPropertyInfo
- constructGLContextSharedContext :: (IsGLContext o, IsGLContext a) => a -> IO (GValueConstruct o)
- gLContextSharedContext :: AttrLabelProxy "sharedContext"
- getGLContextSharedContext :: (MonadIO m, IsGLContext o) => o -> m (Maybe GLContext)
- data GLContextWindowPropertyInfo
- constructGLContextWindow :: (IsGLContext o, IsWindow a) => a -> IO (GValueConstruct o)
- gLContextWindow :: AttrLabelProxy "window"
- getGLContextWindow :: (MonadIO m, IsGLContext o) => o -> m (Maybe Window)
Exported types
GObject GLContext Source # | |
IsObject GLContext Source # | |
IsGLContext GLContext Source # | |
((~) * info (ResolveGLContextMethod t GLContext), MethodInfo * info GLContext p) => IsLabel t (GLContext -> p) Source # | |
((~) * info (ResolveGLContextMethod t GLContext), MethodInfo * info GLContext p) => IsLabelProxy t (GLContext -> p) Source # | |
HasAttributeList * GLContext Source # | |
type AttributeList GLContext Source # | |
type SignalList GLContext Source # | |
class GObject o => IsGLContext o Source #
toGLContext :: IsGLContext o => o -> IO 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
data GLContextGetDebugEnabledMethodInfo Source #
((~) * signature (m Bool), MonadIO m, IsGLContext a) => MethodInfo * GLContextGetDebugEnabledMethodInfo a signature Source # | |
gLContextGetDebugEnabled Source #
:: (HasCallStack, MonadIO m, IsGLContext a) | |
=> a |
|
-> m Bool | Returns: |
Retrieves the value set using gLContextSetDebugEnabled
.
Since: 3.16
getDisplay
data GLContextGetDisplayMethodInfo Source #
((~) * signature (m (Maybe Display)), MonadIO m, IsGLContext a) => MethodInfo * GLContextGetDisplayMethodInfo a signature Source # | |
:: (HasCallStack, MonadIO m, IsGLContext a) | |
=> a |
|
-> m (Maybe Display) |
Retrieves the Display
the context
is created for
Since: 3.16
getForwardCompatible
data GLContextGetForwardCompatibleMethodInfo Source #
((~) * signature (m Bool), MonadIO m, IsGLContext a) => MethodInfo * GLContextGetForwardCompatibleMethodInfo a signature Source # | |
gLContextGetForwardCompatible Source #
:: (HasCallStack, MonadIO m, IsGLContext a) | |
=> a |
|
-> m Bool | Returns: |
Retrieves the value set using gLContextSetForwardCompatible
.
Since: 3.16
getRequiredVersion
data GLContextGetRequiredVersionMethodInfo Source #
((~) * signature (m (Int32, Int32)), MonadIO m, IsGLContext a) => MethodInfo * GLContextGetRequiredVersionMethodInfo a signature Source # | |
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
data GLContextGetUseEsMethodInfo Source #
((~) * signature (m Bool), MonadIO m, IsGLContext a) => MethodInfo * GLContextGetUseEsMethodInfo a signature Source # | |
:: (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
data GLContextGetVersionMethodInfo Source #
((~) * signature (m (Int32, Int32)), MonadIO m, IsGLContext a) => MethodInfo * GLContextGetVersionMethodInfo a signature Source # | |
:: (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
data GLContextGetWindowMethodInfo Source #
((~) * signature (m (Maybe Window)), MonadIO m, IsGLContext a) => MethodInfo * GLContextGetWindowMethodInfo a signature Source # | |
:: (HasCallStack, MonadIO m, IsGLContext a) | |
=> a |
|
-> m (Maybe Window) |
Retrieves the Window
used by the context
.
Since: 3.16
isLegacy
data GLContextIsLegacyMethodInfo Source #
((~) * signature (m Bool), MonadIO m, IsGLContext a) => MethodInfo * GLContextIsLegacyMethodInfo a signature Source # | |
:: (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
data GLContextMakeCurrentMethodInfo Source #
((~) * signature (m ()), MonadIO m, IsGLContext a) => MethodInfo * GLContextMakeCurrentMethodInfo a signature Source # | |
:: (HasCallStack, MonadIO m, IsGLContext a) | |
=> a |
|
-> m () |
Makes the context
the current one.
Since: 3.16
realize
data GLContextRealizeMethodInfo Source #
((~) * signature (m ()), MonadIO m, IsGLContext a) => MethodInfo * GLContextRealizeMethodInfo a signature Source # | |
:: (HasCallStack, MonadIO m, IsGLContext a) | |
=> a |
|
-> m () | (Can throw |
setDebugEnabled
data GLContextSetDebugEnabledMethodInfo Source #
((~) * signature (Bool -> m ()), MonadIO m, IsGLContext a) => MethodInfo * GLContextSetDebugEnabledMethodInfo a signature Source # | |
gLContextSetDebugEnabled Source #
:: (HasCallStack, MonadIO m, IsGLContext a) | |
=> a |
|
-> Bool |
|
-> m () |
setForwardCompatible
data GLContextSetForwardCompatibleMethodInfo Source #
((~) * signature (Bool -> m ()), MonadIO m, IsGLContext a) => MethodInfo * GLContextSetForwardCompatibleMethodInfo a signature Source # | |
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
data GLContextSetRequiredVersionMethodInfo Source #
((~) * signature (Int32 -> Int32 -> m ()), MonadIO m, IsGLContext a) => MethodInfo * GLContextSetRequiredVersionMethodInfo a signature Source # | |
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
data GLContextSetUseEsMethodInfo Source #
((~) * signature (Int32 -> m ()), MonadIO m, IsGLContext a) => MethodInfo * GLContextSetUseEsMethodInfo a signature Source # | |
:: (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
data GLContextDisplayPropertyInfo Source #
constructGLContextDisplay :: (IsGLContext o, IsDisplay a) => a -> IO (GValueConstruct o) Source #
gLContextDisplay :: AttrLabelProxy "display" Source #
getGLContextDisplay :: (MonadIO m, IsGLContext o) => o -> m (Maybe Display) Source #
sharedContext
constructGLContextSharedContext :: (IsGLContext o, IsGLContext a) => a -> IO (GValueConstruct o) Source #
gLContextSharedContext :: AttrLabelProxy "sharedContext" Source #
getGLContextSharedContext :: (MonadIO m, IsGLContext o) => o -> m (Maybe GLContext) Source #
window
data GLContextWindowPropertyInfo Source #
constructGLContextWindow :: (IsGLContext o, IsWindow a) => a -> IO (GValueConstruct o) Source #
gLContextWindow :: AttrLabelProxy "window" Source #
getGLContextWindow :: (MonadIO m, IsGLContext o) => o -> m (Maybe Window) Source #