module Graphics.DynamicGraph.Util (
setupGLFW,
replaceMVar,
checkVertexTextureUnits
) where
import Control.Monad
import Control.Monad.Trans.Class
import Control.Monad.Trans.Either
import Control.Concurrent.MVar
import Control.DeepSeq
import Graphics.Rendering.OpenGL
import Graphics.UI.GLFW as G
setupGLFW :: EitherT String IO ()
setupGLFW = do
lift $ setErrorCallback $ Just $ \error msg -> do
print error
putStrLn msg
res <- lift $ G.init
unless res (left "error initializing glfw")
replaceMVar :: MVar a -> a -> IO ()
replaceMVar mv val = do
tryTakeMVar mv
putMVar mv val
checkVertexTextureUnits :: EitherT String IO ()
checkVertexTextureUnits = do
mtu <- lift $ get maxVertexTextureImageUnits
when (mtu <= 0) $ left "No texture units accessible from vertex shader"