caramia-0.2.0.1: Less painful OpenGL 3.3 rendering

Safe HaskellNone
LanguageHaskell2010

Graphics.Caramia.Resource

Description

Caramia resources.

Resources in Caramia encapsulate OpenGL resources which have some constraints on their use:

  • They are, in the general case, only valid in a specific operating system thread.
  • They need an implicit OpenGL context active to be used.

This module helps with the correct finalization of OpenGL resources as according to those constraints.

Most of the time, Caramia keeps Resource objects hidden so you, the user, is unlikely to see these directly.

Synopsis

Documentation

data Resource a Source

The data type of a Caramia resource.

Instances

Eq (Resource a) 

newResource Source

Arguments

:: IO a

Action that returns the raw, unmanaged resource. Good place to create it.

-> (a -> IO ())

OpenGL finalizer. Will only be called in the same thread as this newResource is called, but only if the same OpenGL context is still alive.

-> IO ()

'Ordinary' finalizer. This will be called immediately when garbage collector collects the resource which means before the OpenGL finalizer and in a separate thread. If this finalizer throws an exception then the OpenGL finalizer is cancelled and the resource is marked as finalized. This will be run even if the OpenGL context is gone.

-> IO (Resource a) 

Creates a new resource.

Must be called in a thread that has an OpenGL context active. Otherwise, an error will be thrown.

If you throw an exception in the OpenGL finalizer, then this will disrupt Caramia context and make it invalid. So try not to throw those exceptions?

withResource Source

Arguments

:: Resource a 
-> (a -> IO b)

Use the resource inside this action. Don't return the unmanaged resource from this because behaviour is then undefined.

-> IO b 

Uses a resource.

Throws an user error if the resource is used in a wrong or dead context.