{-# OPTIONS_HADDOCK hide #-}
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
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: QueryObject -> QueryObject -> Bool
$c/= :: QueryObject -> QueryObject -> Bool
== :: QueryObject -> QueryObject -> Bool
$c== :: QueryObject -> QueryObject -> Bool
Eq, Eq 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
min :: QueryObject -> QueryObject -> QueryObject
$cmin :: QueryObject -> QueryObject -> QueryObject
max :: QueryObject -> QueryObject -> QueryObject
$cmax :: QueryObject -> QueryObject -> QueryObject
>= :: QueryObject -> QueryObject -> Bool
$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
compare :: QueryObject -> QueryObject -> Ordering
$ccompare :: QueryObject -> QueryObject -> Ordering
Ord, Int -> QueryObject -> ShowS
[QueryObject] -> ShowS
QueryObject -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [QueryObject] -> ShowS
$cshowList :: [QueryObject] -> ShowS
show :: QueryObject -> String
$cshow :: QueryObject -> String
showsPrec :: Int -> QueryObject -> ShowS
$cshowsPrec :: Int -> 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 = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. (Eq a, Num a) => a -> Bool
unmarshalGLboolean forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *). MonadIO m => GLuint -> m GLboolean
glIsQuery forall b c a. (b -> c) -> (a -> b) -> a -> c
. QueryObject -> GLuint
queryID
deleteObjectNames :: forall (m :: * -> *). MonadIO m => [QueryObject] -> m ()
deleteObjectNames [QueryObject]
queryObjects =
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. Storable a => [a] -> (Int -> Ptr a -> IO b) -> IO b
withArrayLen (forall a b. (a -> b) -> [a] -> [b]
map QueryObject -> GLuint
queryID [QueryObject]
queryObjects) forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *). MonadIO m => GLsizei -> Ptr GLuint -> m ()
glDeleteQueries forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 =
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. Storable a => Int -> (Ptr a -> IO b) -> IO b
allocaArray Int
n forall a b. (a -> b) -> a -> b
$ \Ptr GLuint
buf -> do
forall (m :: * -> *). MonadIO m => GLsizei -> Ptr GLuint -> m ()
glGenQueries (forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n) Ptr GLuint
buf
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a b. (a -> b) -> [a] -> [b]
map GLuint -> QueryObject
QueryObject) forall a b. (a -> b) -> a -> b
$ 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 forall b c a. (b -> c) -> (a -> b) -> a -> c
. QueryObject -> GLuint
queryID