{-# 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
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
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
Ord, Int -> TextureUnit -> ShowS
[TextureUnit] -> ShowS
TextureUnit -> String
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
_                 = forall a. Storable a => a -> Int
sizeOf    (forall a. HasCallStack => a
undefined :: GLuint)
    alignment :: TextureUnit -> Int
alignment TextureUnit
_              = forall a. Storable a => a -> Int
alignment (forall a. HasCallStack => a
undefined :: GLuint)
    peek :: Ptr TextureUnit -> IO TextureUnit
peek Ptr TextureUnit
pt                  = forall a. Storable a => Ptr a -> IO a
peek (forall a b. Ptr a -> Ptr b
castPtr Ptr TextureUnit
pt) forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a. Monad m => a -> m a
return 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) = forall a. Storable a => Ptr a -> a -> IO ()
poke (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       = forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr b
pt Int
off forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a. Monad m => a -> m a
return 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)
                             = 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 forall a. Num a => a -> a -> a
+ forall a b. (Integral a, Num b) => a -> b
fromIntegral GLenum
x

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