{-# 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
/= :: TextureUnit -> TextureUnit -> Bool
$c/= :: TextureUnit -> TextureUnit -> Bool
== :: TextureUnit -> TextureUnit -> Bool
$c== :: 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
min :: TextureUnit -> TextureUnit -> TextureUnit
$cmin :: TextureUnit -> TextureUnit -> TextureUnit
max :: TextureUnit -> TextureUnit -> TextureUnit
$cmax :: TextureUnit -> TextureUnit -> TextureUnit
>= :: TextureUnit -> TextureUnit -> Bool
$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
compare :: TextureUnit -> TextureUnit -> Ordering
$ccompare :: TextureUnit -> TextureUnit -> Ordering
$cp1Ord :: Eq 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
showList :: [TextureUnit] -> ShowS
$cshowList :: [TextureUnit] -> ShowS
show :: TextureUnit -> String
$cshow :: TextureUnit -> String
showsPrec :: Int -> TextureUnit -> ShowS
$cshowsPrec :: Int -> 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
_                 = GLuint -> Int
forall a. Storable a => a -> Int
sizeOf    (GLuint
forall a. HasCallStack => a
undefined :: GLuint)
    alignment :: TextureUnit -> Int
alignment TextureUnit
_              = GLuint -> Int
forall a. Storable a => a -> Int
alignment (GLuint
forall a. HasCallStack => a
undefined :: GLuint)
    peek :: Ptr TextureUnit -> IO TextureUnit
peek Ptr TextureUnit
pt                  = Ptr GLuint -> IO GLuint
forall a. Storable a => Ptr a -> IO a
peek (Ptr TextureUnit -> Ptr GLuint
forall a b. Ptr a -> Ptr b
castPtr Ptr TextureUnit
pt) IO GLuint -> (GLuint -> IO TextureUnit) -> IO TextureUnit
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= TextureUnit -> IO TextureUnit
forall (m :: * -> *) a. Monad m => a -> m a
return (TextureUnit -> IO TextureUnit)
-> (GLuint -> TextureUnit) -> GLuint -> IO TextureUnit
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GLuint -> TextureUnit
TextureUnit
    poke :: Ptr TextureUnit -> TextureUnit -> IO ()
poke Ptr TextureUnit
pt (TextureUnit GLuint
tu) = Ptr GLuint -> GLuint -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr TextureUnit -> Ptr GLuint
forall a b. Ptr a -> Ptr b
castPtr Ptr TextureUnit
pt) GLuint
tu
    peekByteOff :: Ptr b -> Int -> IO TextureUnit
peekByteOff Ptr b
pt Int
off       = Ptr b -> Int -> IO GLuint
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr b
pt Int
off IO GLuint -> (GLuint -> IO TextureUnit) -> IO TextureUnit
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= TextureUnit -> IO TextureUnit
forall (m :: * -> *) a. Monad m => a -> m a
return (TextureUnit -> IO TextureUnit)
-> (GLuint -> TextureUnit) -> GLuint -> IO TextureUnit
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GLuint -> TextureUnit
TextureUnit
    pokeByteOff :: Ptr b -> Int -> TextureUnit -> IO ()
pokeByteOff Ptr b
pt Int
off (TextureUnit GLuint
tu)
                             = Ptr b -> Int -> GLuint -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr b
pt Int
off GLuint
tu



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

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