    {-# OPTIONS_HADDOCK hide #-}
    --------------------------------------------------------------------------------
    -- |
    -- Module      :  Graphics.Rendering.OpenGL.GL.QueryObject
    -- Copyright   :  (c) Sven Panne 2002-2019
    -- License     :  BSD3
    --
    -- Maintainer  :  Sven Panne <svenpanne@gmail.com>
    -- Stability   :  stable
    -- Portability :  portable
    --
    -- This is a purely internal module for handling QueryObjects.
    --
    --------------------------------------------------------------------------------

    module Graphics.Rendering.OpenGL.GL.QueryObject (
       QueryObject(..), noQueryObject
    ) where

    import Control.Monad.IO.Class
    import Data.ObjectName
    import Foreign.Marshal.Array ( allocaArray, peekArray, withArrayLen )
    import Graphics.Rendering.OpenGL.GL.DebugOutput
    import Graphics.Rendering.OpenGL.GL.GLboolean
    import Graphics.Rendering.OpenGL.GL.QueryUtils
    import Graphics.GL

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

    newtype QueryObject = QueryObject { QueryObject -> GLuint
    queryID :: GLuint }
       deriving ( QueryObject -> QueryObject -> Bool
    (QueryObject -> QueryObject -> Bool)
    -> (QueryObject -> QueryObject -> Bool) -> Eq QueryObject
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: QueryObject -> QueryObject -> Bool
    == :: QueryObject -> QueryObject -> Bool
    $c/= :: QueryObject -> QueryObject -> Bool
    /= :: QueryObject -> QueryObject -> Bool
    Eq, Eq QueryObject
    Eq QueryObject =>
    (QueryObject -> QueryObject -> Ordering)
    -> (QueryObject -> QueryObject -> Bool)
    -> (QueryObject -> QueryObject -> Bool)
    -> (QueryObject -> QueryObject -> Bool)
    -> (QueryObject -> QueryObject -> Bool)
    -> (QueryObject -> QueryObject -> QueryObject)
    -> (QueryObject -> QueryObject -> QueryObject)
    -> Ord QueryObject
    QueryObject -> QueryObject -> Bool
    QueryObject -> QueryObject -> Ordering
    QueryObject -> QueryObject -> QueryObject
    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 :: QueryObject -> QueryObject -> Ordering
    compare :: QueryObject -> QueryObject -> Ordering
    $c< :: QueryObject -> QueryObject -> Bool
    < :: QueryObject -> QueryObject -> Bool
    $c<= :: QueryObject -> QueryObject -> Bool
    <= :: QueryObject -> QueryObject -> Bool
    $c> :: QueryObject -> QueryObject -> Bool
    > :: QueryObject -> QueryObject -> Bool
    $c>= :: QueryObject -> QueryObject -> Bool
    >= :: QueryObject -> QueryObject -> Bool
    $cmax :: QueryObject -> QueryObject -> QueryObject
    max :: QueryObject -> QueryObject -> QueryObject
    $cmin :: QueryObject -> QueryObject -> QueryObject
    min :: QueryObject -> QueryObject -> QueryObject
    Ord, Int -> QueryObject -> ShowS
    [QueryObject] -> ShowS
    QueryObject -> String
    (Int -> QueryObject -> ShowS)
    -> (QueryObject -> String)
    -> ([QueryObject] -> ShowS)
    -> Show QueryObject
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> QueryObject -> ShowS
    showsPrec :: Int -> QueryObject -> ShowS
    $cshow :: QueryObject -> String
    show :: QueryObject -> String
    $cshowList :: [QueryObject] -> ShowS
    showList :: [QueryObject] -> ShowS
    Show )

    noQueryObject :: QueryObject
    noQueryObject :: QueryObject
    noQueryObject = GLuint -> QueryObject
    QueryObject GLuint
    0

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

    instance ObjectName QueryObject where
       isObjectName :: forall (m :: * -> *). MonadIO m => QueryObject -> m Bool
    isObjectName = IO Bool -> m Bool
    forall a. IO a -> m a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO Bool -> m Bool)
    -> (QueryObject -> IO Bool) -> QueryObject -> m Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (GLboolean -> Bool) -> IO GLboolean -> IO Bool
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap GLboolean -> Bool
    forall a. (Eq a, Num a) => a -> Bool
    unmarshalGLboolean (IO GLboolean -> IO Bool)
    -> (QueryObject -> IO GLboolean) -> QueryObject -> IO Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . GLuint -> IO GLboolean
    forall (m :: * -> *). MonadIO m => GLuint -> m GLboolean
    glIsQuery (GLuint -> IO GLboolean)
    -> (QueryObject -> GLuint) -> QueryObject -> IO GLboolean
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . QueryObject -> GLuint
    queryID

       deleteObjectNames :: forall (m :: * -> *). MonadIO m => [QueryObject] -> m ()
    deleteObjectNames [QueryObject]
    queryObjects =
          IO () -> m ()
    forall a. IO a -> m a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO () -> m ())
    -> ((Int -> Ptr GLuint -> IO ()) -> IO ())
    -> (Int -> Ptr GLuint -> IO ())
    -> m ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [GLuint] -> (Int -> Ptr GLuint -> IO ()) -> IO ()
    forall a b. Storable a => [a] -> (Int -> Ptr a -> IO b) -> IO b
    withArrayLen ((QueryObject -> GLuint) -> [QueryObject] -> [GLuint]
    forall a b. (a -> b) -> [a] -> [b]
    map QueryObject -> GLuint
    queryID [QueryObject]
    queryObjects) ((Int -> Ptr GLuint -> IO ()) -> m ())
    -> (Int -> Ptr GLuint -> IO ()) -> m ()
    forall a b. (a -> b) -> a -> b
    $
             GLsizei -> Ptr GLuint -> IO ()
    forall (m :: * -> *). MonadIO m => GLsizei -> Ptr GLuint -> m ()
    glDeleteQueries (GLsizei -> Ptr GLuint -> IO ())
    -> (Int -> GLsizei) -> Int -> Ptr GLuint -> IO ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Int -> GLsizei
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral

    instance GeneratableObjectName QueryObject where
       genObjectNames :: forall (m :: * -> *). MonadIO m => Int -> m [QueryObject]
    genObjectNames Int
    n =
          IO [QueryObject] -> m [QueryObject]
    forall a. IO a -> m a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO [QueryObject] -> m [QueryObject])
    -> ((Ptr GLuint -> IO [QueryObject]) -> IO [QueryObject])
    -> (Ptr GLuint -> IO [QueryObject])
    -> m [QueryObject]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Int -> (Ptr GLuint -> IO [QueryObject]) -> IO [QueryObject]
    forall a b. Storable a => Int -> (Ptr a -> IO b) -> IO b
    allocaArray Int
    n ((Ptr GLuint -> IO [QueryObject]) -> m [QueryObject])
    -> (Ptr GLuint -> IO [QueryObject]) -> m [QueryObject]
    forall a b. (a -> b) -> a -> b
    $ \Ptr GLuint
    buf -> do
            GLsizei -> Ptr GLuint -> IO ()
    forall (m :: * -> *). MonadIO m => GLsizei -> Ptr GLuint -> m ()
    glGenQueries (Int -> GLsizei
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Int
    n) Ptr GLuint
    buf
            ([GLuint] -> [QueryObject]) -> IO [GLuint] -> IO [QueryObject]
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap ((GLuint -> QueryObject) -> [GLuint] -> [QueryObject]
    forall a b. (a -> b) -> [a] -> [b]
    map GLuint -> QueryObject
    QueryObject) (IO [GLuint] -> IO [QueryObject])
    -> IO [GLuint] -> IO [QueryObject]
    forall a b. (a -> b) -> a -> b
    $ Int -> Ptr GLuint -> IO [GLuint]
    forall a. Storable a => Int -> Ptr a -> IO [a]
    peekArray Int
    n Ptr GLuint
    buf

    instance CanBeLabeled QueryObject where
       objectLabel :: QueryObject -> StateVar (Maybe String)
    objectLabel = GLuint -> GLuint -> StateVar (Maybe String)
    objectNameLabel GLuint
    GL_QUERY (GLuint -> StateVar (Maybe String))
    -> (QueryObject -> GLuint)
    -> QueryObject
    -> StateVar (Maybe String)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . QueryObject -> GLuint
    queryID