module Graphics.Rendering.OpenGL.GL.PeekPoke (
poke1, poke2, poke3, poke4,
peek1, peek2, peek3, peek4,
peek1M, peek2M, peek3M, peek4M
) where
import Foreign.Ptr
import Foreign.Storable
poke1 :: Storable a => Ptr a -> a -> IO ()
poke1 ptr x =
pokeElemOff ptr 0 x
poke2 :: Storable a => Ptr a -> a -> a -> IO ()
poke2 ptr x y = do
pokeElemOff ptr 0 x
pokeElemOff ptr 1 y
poke3 :: Storable a => Ptr a -> a -> a -> a -> IO ()
poke3 ptr x y z = do
pokeElemOff ptr 0 x
pokeElemOff ptr 1 y
pokeElemOff ptr 2 z
poke4 :: Storable a => Ptr a -> a -> a -> a -> a -> IO ()
poke4 ptr x y z w = do
pokeElemOff ptr 0 x
pokeElemOff ptr 1 y
pokeElemOff ptr 2 z
pokeElemOff ptr 3 w
peek1 :: Storable a => (a -> b) -> Ptr a -> IO b
peek1 f ptr = do
x <- peekElemOff ptr 0
return $ f x
peek2 :: Storable a => (a -> a -> b) -> Ptr a -> IO b
peek2 f = peek2M $ \x y -> return (f x y)
peek3 :: Storable a => (a -> a -> a -> b) -> Ptr a -> IO b
peek3 f = peek3M $ \x y z -> return (f x y z)
peek4 :: Storable a => (a -> a -> a -> a -> b) -> Ptr a -> IO b
peek4 f = peek4M $ \x y z w -> return (f x y z w)
peek1M :: Storable a => (a -> IO b) -> Ptr a -> IO b
peek1M f ptr = do
x <- peekElemOff ptr 0
f x
peek2M :: Storable a => (a -> a -> IO b) -> Ptr a -> IO b
peek2M f ptr = do
x <- peekElemOff ptr 0
y <- peekElemOff ptr 1
f x y
peek3M :: Storable a => (a -> a -> a -> IO b) -> Ptr a -> IO b
peek3M f ptr = do
x <- peekElemOff ptr 0
y <- peekElemOff ptr 1
z <- peekElemOff ptr 2
f x y z
peek4M :: Storable a => (a -> a -> a -> a -> IO b) -> Ptr a -> IO b
peek4M f ptr = do
x <- peekElemOff ptr 0
y <- peekElemOff ptr 1
z <- peekElemOff ptr 2
w <- peekElemOff ptr 3
f x y z w