module Graphics.Caramia.Internal.Exception
( NoSupport(..)
, checkExtension
, checkExtensionM
, checkOpenGLOrExtensionM
, checkOpenGLM )
where
import Control.Monad.Catch
import Control.Monad.IO.Class
import Data.Text ( Text )
import Graphics.Caramia.Internal.OpenGLVersion
import Graphics.Caramia.Prelude
data NoSupport = NoSupport { info :: Text }
deriving ( Eq, Ord, Show, Read, Typeable )
instance Exception NoSupport
checkExtension :: MonadIO m => Text -> Bool -> m ()
checkExtension _ True = return ()
checkExtension extname False =
liftIO $ throwM $
NoSupport $ "This operation requires " <> extname <> " extension."
checkExtensionM :: MonadIO m => Text -> Bool -> m a -> m a
checkExtensionM ext test action = checkExtension ext test >> action
checkOpenGLOrExtensionM :: MonadIO m
=> OpenGLVersion -> Text -> Bool -> m a -> m a
checkOpenGLOrExtensionM ver ext test action =
if openGLVersion >= ver
then action
else checkExtensionM ext test action
checkOpenGLM :: MonadIO m
=> OpenGLVersion -> m a -> m a
checkOpenGLM ver action =
if openGLVersion >= ver
then action
else liftIO $ throwM $ NoSupport $ "This operation requires " <> showT openGLVersion