    {-# OPTIONS_HADDOCK hide #-}
    --------------------------------------------------------------------------------
    -- |
    -- Module      :  Graphics.Rendering.OpenGL.GL.Texturing.TextureUnit
    -- 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 (un-)marshaling TextureUnit.
    --
    --------------------------------------------------------------------------------

    module Graphics.Rendering.OpenGL.GL.Texturing.TextureUnit (
       TextureUnit(..), marshalTextureUnit, unmarshalTextureUnit
    ) where

    import Foreign.Ptr
    import Foreign.Storable
    import Graphics.GL

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

    -- | Identifies a texture unit via its number, which must be in the range of
    -- (0 .. 'maxTextureUnit').

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

    -- Internal note, when setting a sampler (TextureUnit) uniform the GLint
    -- functions should be used.

    instance Storable TextureUnit where
        sizeOf :: TextureUnit -> Int
    sizeOf TextureUnit
    _                 = GLenum -> Int
    forall a. Storable a => a -> Int
    sizeOf    (GLenum
    forall a. HasCallStack => a
    undefined :: GLuint)
        alignment :: TextureUnit -> Int
    alignment TextureUnit
    _              = GLenum -> Int
    forall a. Storable a => a -> Int
    alignment (GLenum
    forall a. HasCallStack => a
    undefined :: GLuint)
        peek :: Ptr TextureUnit -> IO TextureUnit
    peek Ptr TextureUnit
    pt                  = Ptr GLenum -> IO GLenum
    forall a. Storable a => Ptr a -> IO a
    peek (Ptr TextureUnit -> Ptr GLenum
    forall a b. Ptr a -> Ptr b
    castPtr Ptr TextureUnit
    pt) IO GLenum -> (GLenum -> IO TextureUnit) -> IO TextureUnit
    forall a b. IO a -> (a -> IO b) -> IO b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= TextureUnit -> IO TextureUnit
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (TextureUnit -> IO TextureUnit)
    -> (GLenum -> TextureUnit) -> GLenum -> IO TextureUnit
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . GLenum -> TextureUnit
    TextureUnit
        poke :: Ptr TextureUnit -> TextureUnit -> IO ()
    poke Ptr TextureUnit
    pt (TextureUnit GLenum
    tu) = Ptr GLenum -> GLenum -> IO ()
    forall a. Storable a => Ptr a -> a -> IO ()
    poke (Ptr TextureUnit -> Ptr GLenum
    forall a b. Ptr a -> Ptr b
    castPtr Ptr TextureUnit
    pt) GLenum
    tu
        peekByteOff :: forall b. Ptr b -> Int -> IO TextureUnit
    peekByteOff Ptr b
    pt Int
    off       = Ptr b -> Int -> IO GLenum
    forall b. Ptr b -> Int -> IO GLenum
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr b
    pt Int
    off IO GLenum -> (GLenum -> IO TextureUnit) -> IO TextureUnit
    forall a b. IO a -> (a -> IO b) -> IO b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= TextureUnit -> IO TextureUnit
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (TextureUnit -> IO TextureUnit)
    -> (GLenum -> TextureUnit) -> GLenum -> IO TextureUnit
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . GLenum -> TextureUnit
    TextureUnit
        pokeByteOff :: forall b. Ptr b -> Int -> TextureUnit -> IO ()
    pokeByteOff Ptr b
    pt Int
    off (TextureUnit GLenum
    tu)
                                 = Ptr b -> Int -> GLenum -> IO ()
    forall b. Ptr b -> Int -> GLenum -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr b
    pt Int
    off GLenum
    tu

    marshalTextureUnit :: TextureUnit -> GLenum
    marshalTextureUnit :: TextureUnit -> GLenum
    marshalTextureUnit (TextureUnit GLenum
    x) = GLenum
    GL_TEXTURE0 GLenum -> GLenum -> GLenum
    forall a. Num a => a -> a -> a
    + GLenum -> GLenum
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral GLenum
    x

    unmarshalTextureUnit :: GLenum -> TextureUnit
    unmarshalTextureUnit :: GLenum -> TextureUnit
    unmarshalTextureUnit GLenum
    x = GLenum -> TextureUnit
    TextureUnit (GLenum -> GLenum
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral (GLenum
    x GLenum -> GLenum -> GLenum
    forall a. Num a => a -> a -> a
    - GLenum
    GL_TEXTURE0))