Safe Haskell | None |
---|---|
Language | Haskell98 |
A Context in GPipe (just as in OpenGl) consist of two things, a window and an object space. The object space consists of Buffers, Textures and Shaders. You may create a context without a window (for example for rendering to textures that are saved as pngs instead of showed), and you can create a context that shares the object space with another context.
Context creation is abstracted away from GPipe, and you need a package that provides a ContextFactory
, such as GPipe-GLFW
.
- data ContextT w os f m a
- runContextT :: (MonadIO m, MonadAsyncException m) => ContextFactory c ds w -> ContextFormat c ds -> (forall os. ContextT w os (ContextFormat c ds) m a) -> m a
- runSharedContextT :: (MonadIO m, MonadAsyncException m) => ContextFormat c ds -> ContextT w os (ContextFormat c ds) (ContextT w os f m) a -> ContextT w os f m a
- getContextBuffersSize :: MonadIO m => ContextT w os f m (V2 Int)
- swapContextBuffers :: MonadIO m => ContextT w os f m ()
- type ContextFactory c ds w = ContextFormat c ds -> IO (ContextHandle w)
- data ContextHandle w = ContextHandle {
- newSharedContext :: forall c ds. ContextFormat c ds -> IO (ContextHandle w)
- contextDoSync :: forall a. Bool -> IO a -> IO a
- contextDoAsync :: Bool -> IO () -> IO ()
- contextSwap :: IO ()
- contextFrameBufferSize :: IO (Int, Int)
- contextDelete :: IO ()
- contextWindow :: w
- withContextWindow :: MonadIO m => (w -> IO a) -> ContextT w os f m a
- data GPipeException = GPipeException String
The ContextT monad transformer
data ContextT w os f m a Source
The monad transformer that encapsulates a GPipe context (which wraps an OpenGl context).
A value of type ContextT w os f m a
is an action on a context with these parameters:
w
- The type of the window that is bound to this context. It is defined by the window manager package and is probably an opaque type.
os
- An abstract type that is used to denote the object space. This is an forall type defined by the
runContextT
call which will restrict any objects created inside this context to be returned from it or used by another context (the same trick as theST
monad uses). f
- The format of the context's default frame buffer, always an instance of
ContextFormat
. m
- The monad this monad transformer wraps. Need to have
IO
in the bottom for thisContextT
to be runnable. a
- The value returned from this monad action.
MonadTrans (ContextT w os f) | |
Monad m => Monad (ContextT w os f m) | |
Functor m => Functor (ContextT w os f m) | |
Applicative m => Applicative (ContextT w os f m) | |
MonadIO m => MonadIO (ContextT w os f m) | |
MonadException m => MonadException (ContextT w os f m) | |
MonadAsyncException m => MonadAsyncException (ContextT w os f m) |
runContextT :: (MonadIO m, MonadAsyncException m) => ContextFactory c ds w -> ContextFormat c ds -> (forall os. ContextT w os (ContextFormat c ds) m a) -> m a Source
Run a ContextT
monad transformer, creating a window (unless the ContextFormat
is ContextFormatNone
) that is later destroyed when the action returns. This function will
also create a new object space.
You need a ContextFactory
, which is provided by an auxillary package, such as GPipe-GLFW
.
runSharedContextT :: (MonadIO m, MonadAsyncException m) => ContextFormat c ds -> ContextT w os (ContextFormat c ds) (ContextT w os f m) a -> ContextT w os f m a Source
Run a ContextT
monad transformer inside another one, creating a window (unless the ContextFormat
is ContextFormatNone
) that is later destroyed when the action returns. The inner ContextT
monad
transformer will share object space with the outer one. The ContextFactory
of the outer context will be used in the creation of the inner context.
getContextBuffersSize :: MonadIO m => ContextT w os f m (V2 Int) Source
Return the current size of the context frame buffer. This is needed to set viewport size and to get the aspect ratio to calculate projection matrices.
swapContextBuffers :: MonadIO m => ContextT w os f m () Source
Run this action after a render
call to swap out the context windows back buffer with the front buffer, effectively showing the result.
This call may block if vsync is enabled in the system and/or too many frames are outstanding.
After this call, the context window content is undefined and should be cleared at earliest convenience using clearContextColor
and friends.
External interfaces
Users of GPipe shouldn't bother with these functions, instead use a separate window manager package such as GPipe-GLFW that will provide you with
a function of type ContextFactory
.
To create a window manager package, create a ContextFactory
function that provides a ContextHandle
with all functionality needed.
type ContextFactory c ds w = ContextFormat c ds -> IO (ContextHandle w) Source
data ContextHandle w Source
ContextHandle | |
|
withContextWindow :: MonadIO m => (w -> IO a) -> ContextT w os f m a Source
Use the context window handle, which type is specific to the window system used. This handle shouldn't be returned from this function
Hardware exceptions
data GPipeException Source
This kind of exception may be thrown from GPipe when a GPU hardware limit is reached (for instance, too many textures are drawn to from the same FragmentStream
)