    -----------------------------------------------------------------------------
    -- |
    -- Module      :  Graphics.Rendering.OpenGL.GL.FramebufferObjects.RenderbufferObjects
    -- Copyright   :  (c) Sven Panne 2011-2019, Lars Corbijn 2011-2016
    -- License     :  BSD3
    --
    -- Maintainer  :  Sven Panne <svenpanne@gmail.com>
    -- Stability   :  stable
    -- Portability :  portable
    --
    -----------------------------------------------------------------------------

    module Graphics.Rendering.OpenGL.GL.FramebufferObjects.RenderbufferObjects (
       RenderbufferObject,
       noRenderbufferObject,
       RenderbufferTarget(..),
       RenderbufferSize(..), Samples(..),

       bindRenderbuffer,

       renderbufferStorage, renderbufferStorageMultiSample,
    ) where

    import Data.StateVar
    import Graphics.Rendering.OpenGL.GL.FramebufferObjects.RenderbufferObject
    import Graphics.Rendering.OpenGL.GL.FramebufferObjects.RenderbufferTarget
    import Graphics.Rendering.OpenGL.GL.QueryUtils
    import Graphics.Rendering.OpenGL.GL.Texturing.PixelInternalFormat
    import Graphics.GL

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

    noRenderbufferObject :: RenderbufferObject
    noRenderbufferObject :: RenderbufferObject
    noRenderbufferObject = GLuint -> RenderbufferObject
    RenderbufferObject GLuint
    0

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

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

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

    bindRenderbuffer :: RenderbufferTarget -> StateVar RenderbufferObject
    bindRenderbuffer :: RenderbufferTarget -> StateVar RenderbufferObject
    bindRenderbuffer RenderbufferTarget
    rbt =
        IO RenderbufferObject
    -> (RenderbufferObject -> IO ()) -> StateVar RenderbufferObject
    forall a. IO a -> (a -> IO ()) -> StateVar a
    makeStateVar (RenderbufferTarget -> IO RenderbufferObject
    getBoundRenderbuffer RenderbufferTarget
    rbt) (RenderbufferTarget -> RenderbufferObject -> IO ()
    setRenderbuffer RenderbufferTarget
    rbt)

    marshalRenderbufferTargetBinding :: RenderbufferTarget -> PName1I
    marshalRenderbufferTargetBinding :: RenderbufferTarget -> PName1I
    marshalRenderbufferTargetBinding RenderbufferTarget
    x = case RenderbufferTarget
    x of
        RenderbufferTarget
    Renderbuffer -> PName1I
    GetRenderbufferBinding

    getBoundRenderbuffer :: RenderbufferTarget -> IO RenderbufferObject
    getBoundRenderbuffer :: RenderbufferTarget -> IO RenderbufferObject
    getBoundRenderbuffer =
       (GLint -> RenderbufferObject) -> PName1I -> IO RenderbufferObject
    forall p a. GetPName1I p => (GLint -> a) -> p -> IO a
    forall a. (GLint -> a) -> PName1I -> IO a
    getInteger1 (GLuint -> RenderbufferObject
    RenderbufferObject (GLuint -> RenderbufferObject)
    -> (GLint -> GLuint) -> GLint -> RenderbufferObject
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . GLint -> GLuint
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral) (PName1I -> IO RenderbufferObject)
    -> (RenderbufferTarget -> PName1I)
    -> RenderbufferTarget
    -> IO RenderbufferObject
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . RenderbufferTarget -> PName1I
    marshalRenderbufferTargetBinding

    setRenderbuffer :: RenderbufferTarget -> RenderbufferObject -> IO ()
    setRenderbuffer :: RenderbufferTarget -> RenderbufferObject -> IO ()
    setRenderbuffer RenderbufferTarget
    rbt = GLuint -> GLuint -> IO ()
    forall (m :: * -> *). MonadIO m => GLuint -> GLuint -> m ()
    glBindRenderbuffer (RenderbufferTarget -> GLuint
    marshalRenderbufferTarget RenderbufferTarget
    rbt)
       (GLuint -> IO ())
    -> (RenderbufferObject -> GLuint) -> RenderbufferObject -> IO ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . RenderbufferObject -> GLuint
    renderbufferID

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

    renderbufferStorageMultiSample :: RenderbufferTarget -> Samples
       -> PixelInternalFormat -> RenderbufferSize -> IO ()
    renderbufferStorageMultiSample :: RenderbufferTarget
    -> Samples -> PixelInternalFormat -> RenderbufferSize -> IO ()
    renderbufferStorageMultiSample RenderbufferTarget
    rbt (Samples GLint
    s) PixelInternalFormat
    pif (RenderbufferSize GLint
    w GLint
    h) =
       GLuint -> GLint -> GLuint -> GLint -> GLint -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLuint -> GLint -> GLuint -> GLint -> GLint -> m ()
    glRenderbufferStorageMultisample (RenderbufferTarget -> GLuint
    marshalRenderbufferTarget RenderbufferTarget
    rbt) GLint
    s
           (PixelInternalFormat -> GLuint
    marshalPixelInternalFormat' PixelInternalFormat
    pif) GLint
    w GLint
    h

    renderbufferStorage :: RenderbufferTarget -> PixelInternalFormat
       -> RenderbufferSize -> IO ()
    renderbufferStorage :: RenderbufferTarget
    -> PixelInternalFormat -> RenderbufferSize -> IO ()
    renderbufferStorage RenderbufferTarget
    rbt PixelInternalFormat
    pif (RenderbufferSize GLint
    w GLint
    h) =
        GLuint -> GLuint -> GLint -> GLint -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLuint -> GLuint -> GLint -> GLint -> m ()
    glRenderbufferStorage (RenderbufferTarget -> GLuint
    marshalRenderbufferTarget RenderbufferTarget
    rbt)
           (PixelInternalFormat -> GLuint
    marshalPixelInternalFormat' PixelInternalFormat
    pif) GLint
    w GLint
    h