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

    module Graphics.Rendering.OpenGL.GL.FramebufferObjects.RenderbufferObject (
       RenderbufferObject(..)
    ) where

    import Control.Monad.IO.Class
    import Data.ObjectName
    import Foreign.Marshal ( 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 RenderbufferObject = RenderbufferObject { RenderbufferObject -> GLuint
    renderbufferID :: GLuint}
       deriving ( RenderbufferObject -> RenderbufferObject -> Bool
    (RenderbufferObject -> RenderbufferObject -> Bool)
    -> (RenderbufferObject -> RenderbufferObject -> Bool)
    -> Eq RenderbufferObject
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: RenderbufferObject -> RenderbufferObject -> Bool
    == :: RenderbufferObject -> RenderbufferObject -> Bool
    $c/= :: RenderbufferObject -> RenderbufferObject -> Bool
    /= :: RenderbufferObject -> RenderbufferObject -> Bool
    Eq, Eq RenderbufferObject
    Eq RenderbufferObject =>
    (RenderbufferObject -> RenderbufferObject -> Ordering)
    -> (RenderbufferObject -> RenderbufferObject -> Bool)
    -> (RenderbufferObject -> RenderbufferObject -> Bool)
    -> (RenderbufferObject -> RenderbufferObject -> Bool)
    -> (RenderbufferObject -> RenderbufferObject -> Bool)
    -> (RenderbufferObject -> RenderbufferObject -> RenderbufferObject)
    -> (RenderbufferObject -> RenderbufferObject -> RenderbufferObject)
    -> Ord RenderbufferObject
    RenderbufferObject -> RenderbufferObject -> Bool
    RenderbufferObject -> RenderbufferObject -> Ordering
    RenderbufferObject -> RenderbufferObject -> RenderbufferObject
    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 :: RenderbufferObject -> RenderbufferObject -> Ordering
    compare :: RenderbufferObject -> RenderbufferObject -> Ordering
    $c< :: RenderbufferObject -> RenderbufferObject -> Bool
    < :: RenderbufferObject -> RenderbufferObject -> Bool
    $c<= :: RenderbufferObject -> RenderbufferObject -> Bool
    <= :: RenderbufferObject -> RenderbufferObject -> Bool
    $c> :: RenderbufferObject -> RenderbufferObject -> Bool
    > :: RenderbufferObject -> RenderbufferObject -> Bool
    $c>= :: RenderbufferObject -> RenderbufferObject -> Bool
    >= :: RenderbufferObject -> RenderbufferObject -> Bool
    $cmax :: RenderbufferObject -> RenderbufferObject -> RenderbufferObject
    max :: RenderbufferObject -> RenderbufferObject -> RenderbufferObject
    $cmin :: RenderbufferObject -> RenderbufferObject -> RenderbufferObject
    min :: RenderbufferObject -> RenderbufferObject -> RenderbufferObject
    Ord, Int -> RenderbufferObject -> ShowS
    [RenderbufferObject] -> ShowS
    RenderbufferObject -> String
    (Int -> RenderbufferObject -> ShowS)
    -> (RenderbufferObject -> String)
    -> ([RenderbufferObject] -> ShowS)
    -> Show RenderbufferObject
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> RenderbufferObject -> ShowS
    showsPrec :: Int -> RenderbufferObject -> ShowS
    $cshow :: RenderbufferObject -> String
    show :: RenderbufferObject -> String
    $cshowList :: [RenderbufferObject] -> ShowS
    showList :: [RenderbufferObject] -> ShowS
    Show )

    instance ObjectName RenderbufferObject where
       isObjectName :: forall (m :: * -> *). MonadIO m => RenderbufferObject -> 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)
    -> (RenderbufferObject -> IO Bool) -> RenderbufferObject -> 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)
    -> (RenderbufferObject -> IO GLboolean)
    -> RenderbufferObject
    -> IO Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . GLuint -> IO GLboolean
    forall (m :: * -> *). MonadIO m => GLuint -> m GLboolean
    glIsRenderbuffer (GLuint -> IO GLboolean)
    -> (RenderbufferObject -> GLuint)
    -> RenderbufferObject
    -> IO GLboolean
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . RenderbufferObject -> GLuint
    renderbufferID

       deleteObjectNames :: forall (m :: * -> *). MonadIO m => [RenderbufferObject] -> m ()
    deleteObjectNames [RenderbufferObject]
    objs =
          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 ((RenderbufferObject -> GLuint) -> [RenderbufferObject] -> [GLuint]
    forall a b. (a -> b) -> [a] -> [b]
    map RenderbufferObject -> GLuint
    renderbufferID [RenderbufferObject]
    objs) ((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 ()
    glDeleteRenderbuffers (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 RenderbufferObject where
       genObjectNames :: forall (m :: * -> *). MonadIO m => Int -> m [RenderbufferObject]
    genObjectNames Int
    n =
          IO [RenderbufferObject] -> m [RenderbufferObject]
    forall a. IO a -> m a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO [RenderbufferObject] -> m [RenderbufferObject])
    -> ((Ptr GLuint -> IO [RenderbufferObject])
        -> IO [RenderbufferObject])
    -> (Ptr GLuint -> IO [RenderbufferObject])
    -> m [RenderbufferObject]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Int
    -> (Ptr GLuint -> IO [RenderbufferObject])
    -> IO [RenderbufferObject]
    forall a b. Storable a => Int -> (Ptr a -> IO b) -> IO b
    allocaArray Int
    n ((Ptr GLuint -> IO [RenderbufferObject]) -> m [RenderbufferObject])
    -> (Ptr GLuint -> IO [RenderbufferObject])
    -> m [RenderbufferObject]
    forall a b. (a -> b) -> a -> b
    $ \Ptr GLuint
    buf -> do
             GLsizei -> Ptr GLuint -> IO ()
    forall (m :: * -> *). MonadIO m => GLsizei -> Ptr GLuint -> m ()
    glGenRenderbuffers (Int -> GLsizei
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Int
    n) Ptr GLuint
    buf
             ([GLuint] -> [RenderbufferObject])
    -> IO [GLuint] -> IO [RenderbufferObject]
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap ((GLuint -> RenderbufferObject) -> [GLuint] -> [RenderbufferObject]
    forall a b. (a -> b) -> [a] -> [b]
    map GLuint -> RenderbufferObject
    RenderbufferObject) (IO [GLuint] -> IO [RenderbufferObject])
    -> IO [GLuint] -> IO [RenderbufferObject]
    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 RenderbufferObject where
       objectLabel :: RenderbufferObject -> StateVar (Maybe String)
    objectLabel = GLuint -> GLuint -> StateVar (Maybe String)
    objectNameLabel GLuint
    GL_RENDERBUFFER (GLuint -> StateVar (Maybe String))
    -> (RenderbufferObject -> GLuint)
    -> RenderbufferObject
    -> StateVar (Maybe String)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . RenderbufferObject -> GLuint
    renderbufferID