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

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

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

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