    {-# OPTIONS_HADDOCK hide #-}
    --------------------------------------------------------------------------------
    -- |
    -- Module      :  Graphics.Rendering.OpenGL.GL.RenderMode
    -- Copyright   :  (c) Sven Panne 2002-2019
    -- License     :  BSD3
    --
    -- Maintainer  :  Sven Panne <svenpanne@gmail.com>
    -- Stability   :  stable
    -- Portability :  portable
    --
    -- This is a purely internal module related to the current render mode.
    --
    --------------------------------------------------------------------------------

    module Graphics.Rendering.OpenGL.GL.RenderMode (
       RenderMode(..), withRenderMode, renderMode
    ) where

    import Data.StateVar
    import Graphics.Rendering.OpenGL.GL.Exception
    import Graphics.Rendering.OpenGL.GL.QueryUtils
    import Graphics.GL

    --------------------------------------------------------------------------------

    data RenderMode =
         Render
       | Feedback
       | Select
       deriving ( RenderMode -> RenderMode -> Bool
    (RenderMode -> RenderMode -> Bool)
    -> (RenderMode -> RenderMode -> Bool) -> Eq RenderMode
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: RenderMode -> RenderMode -> Bool
    == :: RenderMode -> RenderMode -> Bool
    $c/= :: RenderMode -> RenderMode -> Bool
    /= :: RenderMode -> RenderMode -> Bool
    Eq, Eq RenderMode
    Eq RenderMode =>
    (RenderMode -> RenderMode -> Ordering)
    -> (RenderMode -> RenderMode -> Bool)
    -> (RenderMode -> RenderMode -> Bool)
    -> (RenderMode -> RenderMode -> Bool)
    -> (RenderMode -> RenderMode -> Bool)
    -> (RenderMode -> RenderMode -> RenderMode)
    -> (RenderMode -> RenderMode -> RenderMode)
    -> Ord RenderMode
    RenderMode -> RenderMode -> Bool
    RenderMode -> RenderMode -> Ordering
    RenderMode -> RenderMode -> RenderMode
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: RenderMode -> RenderMode -> Ordering
    compare :: RenderMode -> RenderMode -> Ordering
    $c< :: RenderMode -> RenderMode -> Bool
    < :: RenderMode -> RenderMode -> Bool
    $c<= :: RenderMode -> RenderMode -> Bool
    <= :: RenderMode -> RenderMode -> Bool
    $c> :: RenderMode -> RenderMode -> Bool
    > :: RenderMode -> RenderMode -> Bool
    $c>= :: RenderMode -> RenderMode -> Bool
    >= :: RenderMode -> RenderMode -> Bool
    $cmax :: RenderMode -> RenderMode -> RenderMode
    max :: RenderMode -> RenderMode -> RenderMode
    $cmin :: RenderMode -> RenderMode -> RenderMode
    min :: RenderMode -> RenderMode -> RenderMode
    Ord, Int -> RenderMode -> ShowS
    [RenderMode] -> ShowS
    RenderMode -> String
    (Int -> RenderMode -> ShowS)
    -> (RenderMode -> String)
    -> ([RenderMode] -> ShowS)
    -> Show RenderMode
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> RenderMode -> ShowS
    showsPrec :: Int -> RenderMode -> ShowS
    $cshow :: RenderMode -> String
    show :: RenderMode -> String
    $cshowList :: [RenderMode] -> ShowS
    showList :: [RenderMode] -> ShowS
    Show )

    marshalRenderMode :: RenderMode -> GLenum
    marshalRenderMode :: RenderMode -> GLenum
    marshalRenderMode RenderMode
    x = case RenderMode
    x of
       RenderMode
    Render -> GLenum
    GL_RENDER
       RenderMode
    Feedback -> GLenum
    GL_FEEDBACK
       RenderMode
    Select -> GLenum
    GL_SELECT

    unmarshalRenderMode :: GLenum -> RenderMode
    unmarshalRenderMode :: GLenum -> RenderMode
    unmarshalRenderMode GLenum
    x
       | GLenum
    x GLenum -> GLenum -> Bool
    forall a. Eq a => a -> a -> Bool
    == GLenum
    GL_RENDER = RenderMode
    Render
       | GLenum
    x GLenum -> GLenum -> Bool
    forall a. Eq a => a -> a -> Bool
    == GLenum
    GL_FEEDBACK = RenderMode
    Feedback
       | GLenum
    x GLenum -> GLenum -> Bool
    forall a. Eq a => a -> a -> Bool
    == GLenum
    GL_SELECT = RenderMode
    Select
       | Bool
    otherwise = String -> RenderMode
    forall a. HasCallStack => String -> a
    error (String
    "unmarshalRenderMode: illegal value " String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ GLenum -> String
    forall a. Show a => a -> String
    show GLenum
    x)

    --------------------------------------------------------------------------------

    withRenderMode :: RenderMode -> IO a -> IO (a, GLint)
    withRenderMode :: forall a. RenderMode -> IO a -> IO (a, GLint)
    withRenderMode RenderMode
    newMode IO a
    action = do
       oldMode <- GettableStateVar RenderMode -> GettableStateVar RenderMode
    forall t a (m :: * -> *). (HasGetter t a, MonadIO m) => t -> m a
    forall (m :: * -> *).
    MonadIO m =>
    GettableStateVar RenderMode -> m RenderMode
    get GettableStateVar RenderMode
    renderMode
       _ <- setRenderMode newMode
       action `finallyRet` setRenderMode oldMode

    setRenderMode :: RenderMode -> IO GLint
    setRenderMode :: RenderMode -> IO GLint
    setRenderMode = GLenum -> IO GLint
    forall (m :: * -> *). MonadIO m => GLenum -> m GLint
    glRenderMode (GLenum -> IO GLint)
    -> (RenderMode -> GLenum) -> RenderMode -> IO GLint
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . RenderMode -> GLenum
    marshalRenderMode

    --------------------------------------------------------------------------------

    renderMode :: GettableStateVar RenderMode
    renderMode :: GettableStateVar RenderMode
    renderMode = GettableStateVar RenderMode -> GettableStateVar RenderMode
    forall a. IO a -> IO a
    makeGettableStateVar (GettableStateVar RenderMode -> GettableStateVar RenderMode)
    -> GettableStateVar RenderMode -> GettableStateVar RenderMode
    forall a b. (a -> b) -> a -> b
    $ (GLenum -> RenderMode) -> PName1I -> GettableStateVar RenderMode
    forall p a. GetPName1I p => (GLenum -> a) -> p -> IO a
    forall a. (GLenum -> a) -> PName1I -> IO a
    getEnum1 GLenum -> RenderMode
    unmarshalRenderMode PName1I
    GetRenderMode