Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module manages OpenGL contexts in Caramia.
Caramia does not actually have any functionality about creating OpenGL contexts. You need to tell it about them with this module.
giveContext
is the most important function in this module. You also want
to runPendingFinalizers
regularly to make sure OpenGL resources are
garbage collected.
- giveContext :: IO a -> IO a
- currentContextID :: IO (Maybe ContextID)
- type ContextID = Int
- runPendingFinalizers :: IO ()
- scheduleFinalizer :: ContextID -> IO () -> IO ()
- storeContextLocalData :: Typeable a => a -> IO ()
- retrieveContextLocalData :: forall a. Typeable a => IO a -> IO a
- data TooOldOpenGL = TooOldOpenGL {
- wantedVersion :: (Int, Int)
- reportedVersion :: (Int, Int)
Running with an OpenGL context
giveContext :: IO a -> IO a Source
Tell Caramia the current thread has an OpenGL context active.
When the given IO action returns, Caramia will think that the OpenGL context is now gone. It is probably best to actually close the context because this also means OpenGL finalizers will not be run (Caramia thinks they were all released when the OpenGL context went away).
The context in the IO action is referred to as 'Caramia context' in this documentation to distinguish it from OpenGL context.
If the environment variable 'CARAMIA_OPENGL_DEBUG' is set, then, if 'GL_KHR_debug' extension is supported, OpenGL debug output is written. Note that you might need a debug OpenGL context for there to be any messages.
Throws TooOldOpenGL
if the code detects a context that does not provide
OpenGL 3.3.
Context IDs
currentContextID :: IO (Maybe ContextID) Source
Returns the current Caramia context ID.
The context ID is unique between different calls to giveContext
.
Returns Nothing
if there is no context active.
Finalization
runPendingFinalizers :: IO () Source
Run any pending finalizers in the current Caramia context.
Does nothing if current thread does not have a Caramia context or there are no pending finalizers.
If any finalizer throws an exception (asynchronous or synchronous), the
Caramia context dies and that exception is propagated upwards.
runPendingFinalizers
itself runs mask_
to run the finalizers with
exceptions masked but you might still receive asynchronous exceptions with,
for example, the MVar
functions.
A good place to call this is right after or before swapping buffers.
scheduleFinalizer :: ContextID -> IO () -> IO () Source
Schedules a finalizer to be run in a Caramia context.
Does nothing if given context is not alive anymore.
This is typically called from Haskell garbage collector finalizers because they cannot do finalization there (Haskell finalizers are running in the wrong operating system thread).
Context local data
storeContextLocalData :: Typeable a => a -> IO () Source
Stores a context local value.
The type of the given value is used as a key. This means that if a value of the same type was stored before, that value is thrown away and replaced with this new value you just gave.
The value is evaluated to WHNF.
You don't need this function to work with context local data.
retrieveContextLocalData
is sufficient as it also lets you set a default
value in case a value was not already set.
Context local data is wiped to oblivion once giveContext
ends.
retrieveContextLocalData Source
:: forall a . Typeable a | |
=> IO a | Default value generating action; not evaluated if there was already a value stored. |
-> IO a |
Retrieves a context local value.
Exceptions
data TooOldOpenGL Source
An exception that is thrown when the OpenGL version is too old for this library.
TooOldOpenGL | |
|