    --------------------------------------------------------------------------------
    -- |
    -- Module      :  Graphics.Rendering.OpenGL.GL.ConditionalRendering
    -- Copyright   :  (c) Sven Panne 2019
    -- License     :  BSD3
    --
    -- Maintainer  :  Sven Panne <svenpanne@gmail.com>
    -- Stability   :  stable
    -- Portability :  portable
    --
    -- This module corresponds to section 10.10 (Conditional Rendering) of the
    -- OpenGL 4.4 specs.
    --
    --------------------------------------------------------------------------------

    module Graphics.Rendering.OpenGL.GL.ConditionalRendering (
       ConditionalRenderMode(..),
       beginConditionalRender, endConditionalRender, withConditionalRender
    ) where

    import Graphics.Rendering.OpenGL.GL.Exception
    import Graphics.Rendering.OpenGL.GL.QueryObject
    import Graphics.GL

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

    data ConditionalRenderMode =
         QueryWait
       | QueryNoWait
       | QueryByRegionWait
       | QueryByRegionNoWait
       deriving ( ConditionalRenderMode -> ConditionalRenderMode -> Bool
    (ConditionalRenderMode -> ConditionalRenderMode -> Bool)
    -> (ConditionalRenderMode -> ConditionalRenderMode -> Bool)
    -> Eq ConditionalRenderMode
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: ConditionalRenderMode -> ConditionalRenderMode -> Bool
    == :: ConditionalRenderMode -> ConditionalRenderMode -> Bool
    $c/= :: ConditionalRenderMode -> ConditionalRenderMode -> Bool
    /= :: ConditionalRenderMode -> ConditionalRenderMode -> Bool
    Eq, Eq ConditionalRenderMode
    Eq ConditionalRenderMode =>
    (ConditionalRenderMode -> ConditionalRenderMode -> Ordering)
    -> (ConditionalRenderMode -> ConditionalRenderMode -> Bool)
    -> (ConditionalRenderMode -> ConditionalRenderMode -> Bool)
    -> (ConditionalRenderMode -> ConditionalRenderMode -> Bool)
    -> (ConditionalRenderMode -> ConditionalRenderMode -> Bool)
    -> (ConditionalRenderMode
        -> ConditionalRenderMode -> ConditionalRenderMode)
    -> (ConditionalRenderMode
        -> ConditionalRenderMode -> ConditionalRenderMode)
    -> Ord ConditionalRenderMode
    ConditionalRenderMode -> ConditionalRenderMode -> Bool
    ConditionalRenderMode -> ConditionalRenderMode -> Ordering
    ConditionalRenderMode
    -> ConditionalRenderMode -> ConditionalRenderMode
    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 :: ConditionalRenderMode -> ConditionalRenderMode -> Ordering
    compare :: ConditionalRenderMode -> ConditionalRenderMode -> Ordering
    $c< :: ConditionalRenderMode -> ConditionalRenderMode -> Bool
    < :: ConditionalRenderMode -> ConditionalRenderMode -> Bool
    $c<= :: ConditionalRenderMode -> ConditionalRenderMode -> Bool
    <= :: ConditionalRenderMode -> ConditionalRenderMode -> Bool
    $c> :: ConditionalRenderMode -> ConditionalRenderMode -> Bool
    > :: ConditionalRenderMode -> ConditionalRenderMode -> Bool
    $c>= :: ConditionalRenderMode -> ConditionalRenderMode -> Bool
    >= :: ConditionalRenderMode -> ConditionalRenderMode -> Bool
    $cmax :: ConditionalRenderMode
    -> ConditionalRenderMode -> ConditionalRenderMode
    max :: ConditionalRenderMode
    -> ConditionalRenderMode -> ConditionalRenderMode
    $cmin :: ConditionalRenderMode
    -> ConditionalRenderMode -> ConditionalRenderMode
    min :: ConditionalRenderMode
    -> ConditionalRenderMode -> ConditionalRenderMode
    Ord, Int -> ConditionalRenderMode -> ShowS
    [ConditionalRenderMode] -> ShowS
    ConditionalRenderMode -> String
    (Int -> ConditionalRenderMode -> ShowS)
    -> (ConditionalRenderMode -> String)
    -> ([ConditionalRenderMode] -> ShowS)
    -> Show ConditionalRenderMode
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> ConditionalRenderMode -> ShowS
    showsPrec :: Int -> ConditionalRenderMode -> ShowS
    $cshow :: ConditionalRenderMode -> String
    show :: ConditionalRenderMode -> String
    $cshowList :: [ConditionalRenderMode] -> ShowS
    showList :: [ConditionalRenderMode] -> ShowS
    Show )

    marshalConditionalRenderMode :: ConditionalRenderMode -> GLenum
    marshalConditionalRenderMode :: ConditionalRenderMode -> GLenum
    marshalConditionalRenderMode ConditionalRenderMode
    x = case ConditionalRenderMode
    x of
       ConditionalRenderMode
    QueryWait -> GLenum
    GL_QUERY_WAIT
       ConditionalRenderMode
    QueryNoWait -> GLenum
    GL_QUERY_NO_WAIT
       ConditionalRenderMode
    QueryByRegionWait -> GLenum
    GL_QUERY_BY_REGION_WAIT
       ConditionalRenderMode
    QueryByRegionNoWait -> GLenum
    GL_QUERY_BY_REGION_NO_WAIT

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

    beginConditionalRender :: QueryObject -> ConditionalRenderMode -> IO ()
    beginConditionalRender :: QueryObject -> ConditionalRenderMode -> IO ()
    beginConditionalRender QueryObject
    q =
       GLenum -> GLenum -> IO ()
    forall (m :: * -> *). MonadIO m => GLenum -> GLenum -> m ()
    glBeginConditionalRender (QueryObject -> GLenum
    queryID QueryObject
    q) (GLenum -> IO ())
    -> (ConditionalRenderMode -> GLenum)
    -> ConditionalRenderMode
    -> IO ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ConditionalRenderMode -> GLenum
    marshalConditionalRenderMode

    endConditionalRender :: IO ()
    endConditionalRender :: IO ()
    endConditionalRender = IO ()
    forall (m :: * -> *). MonadIO m => m ()
    glEndConditionalRender

    withConditionalRender :: QueryObject -> ConditionalRenderMode -> IO a -> IO a
    withConditionalRender :: forall a. QueryObject -> ConditionalRenderMode -> IO a -> IO a
    withConditionalRender QueryObject
    q ConditionalRenderMode
    m =
       IO () -> IO () -> IO a -> IO a
    forall a b c. IO a -> IO b -> IO c -> IO c
    bracket_ (QueryObject -> ConditionalRenderMode -> IO ()
    beginConditionalRender QueryObject
    q ConditionalRenderMode
    m) IO ()
    endConditionalRender