{-# OPTIONS_HADDOCK hide #-}
module Graphics.Rendering.OpenGL.GL.Texturing.TextureObject (
TextureObject(..)
) where
import Control.Monad.IO.Class
import Data.ObjectName
import Foreign.Marshal.Array ( allocaArray, peekArray, withArrayLen )
import Graphics.Rendering.OpenGL.GL.DebugOutput
import Graphics.Rendering.OpenGL.GL.GLboolean
import Graphics.Rendering.OpenGL.GL.QueryUtils
import Graphics.GL
newtype TextureObject = TextureObject { TextureObject -> GLuint
textureID :: GLuint }
deriving ( TextureObject -> TextureObject -> Bool
(TextureObject -> TextureObject -> Bool)
-> (TextureObject -> TextureObject -> Bool) -> Eq TextureObject
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TextureObject -> TextureObject -> Bool
== :: TextureObject -> TextureObject -> Bool
$c/= :: TextureObject -> TextureObject -> Bool
/= :: TextureObject -> TextureObject -> Bool
Eq, Eq TextureObject
Eq TextureObject =>
(TextureObject -> TextureObject -> Ordering)
-> (TextureObject -> TextureObject -> Bool)
-> (TextureObject -> TextureObject -> Bool)
-> (TextureObject -> TextureObject -> Bool)
-> (TextureObject -> TextureObject -> Bool)
-> (TextureObject -> TextureObject -> TextureObject)
-> (TextureObject -> TextureObject -> TextureObject)
-> Ord TextureObject
TextureObject -> TextureObject -> Bool
TextureObject -> TextureObject -> Ordering
TextureObject -> TextureObject -> TextureObject
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 :: TextureObject -> TextureObject -> Ordering
compare :: TextureObject -> TextureObject -> Ordering
$c< :: TextureObject -> TextureObject -> Bool
< :: TextureObject -> TextureObject -> Bool
$c<= :: TextureObject -> TextureObject -> Bool
<= :: TextureObject -> TextureObject -> Bool
$c> :: TextureObject -> TextureObject -> Bool
> :: TextureObject -> TextureObject -> Bool
$c>= :: TextureObject -> TextureObject -> Bool
>= :: TextureObject -> TextureObject -> Bool
$cmax :: TextureObject -> TextureObject -> TextureObject
max :: TextureObject -> TextureObject -> TextureObject
$cmin :: TextureObject -> TextureObject -> TextureObject
min :: TextureObject -> TextureObject -> TextureObject
Ord, Int -> TextureObject -> ShowS
[TextureObject] -> ShowS
TextureObject -> String
(Int -> TextureObject -> ShowS)
-> (TextureObject -> String)
-> ([TextureObject] -> ShowS)
-> Show TextureObject
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TextureObject -> ShowS
showsPrec :: Int -> TextureObject -> ShowS
$cshow :: TextureObject -> String
show :: TextureObject -> String
$cshowList :: [TextureObject] -> ShowS
showList :: [TextureObject] -> ShowS
Show )
instance ObjectName TextureObject where
isObjectName :: forall (m :: * -> *). MonadIO m => TextureObject -> m Bool
isObjectName = IO Bool -> m Bool
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bool -> m Bool)
-> (TextureObject -> IO Bool) -> TextureObject -> m Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GLboolean -> Bool) -> IO GLboolean -> IO Bool
forall a b. (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap GLboolean -> Bool
forall a. (Eq a, Num a) => a -> Bool
unmarshalGLboolean (IO GLboolean -> IO Bool)
-> (TextureObject -> IO GLboolean) -> TextureObject -> IO Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GLuint -> IO GLboolean
forall (m :: * -> *). MonadIO m => GLuint -> m GLboolean
glIsTexture (GLuint -> IO GLboolean)
-> (TextureObject -> GLuint) -> TextureObject -> IO GLboolean
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TextureObject -> GLuint
textureID
deleteObjectNames :: forall (m :: * -> *). MonadIO m => [TextureObject] -> m ()
deleteObjectNames [TextureObject]
textureObjects =
IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ())
-> ((Int -> Ptr GLuint -> IO ()) -> IO ())
-> (Int -> Ptr GLuint -> IO ())
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [GLuint] -> (Int -> Ptr GLuint -> IO ()) -> IO ()
forall a b. Storable a => [a] -> (Int -> Ptr a -> IO b) -> IO b
withArrayLen ((TextureObject -> GLuint) -> [TextureObject] -> [GLuint]
forall a b. (a -> b) -> [a] -> [b]
map TextureObject -> GLuint
textureID [TextureObject]
textureObjects) ((Int -> Ptr GLuint -> IO ()) -> m ())
-> (Int -> Ptr GLuint -> IO ()) -> m ()
forall a b. (a -> b) -> a -> b
$
GLsizei -> Ptr GLuint -> IO ()
forall (m :: * -> *). MonadIO m => GLsizei -> Ptr GLuint -> m ()
glDeleteTextures (GLsizei -> Ptr GLuint -> IO ())
-> (Int -> GLsizei) -> Int -> Ptr GLuint -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> GLsizei
forall a b. (Integral a, Num b) => a -> b
fromIntegral
instance GeneratableObjectName TextureObject where
genObjectNames :: forall (m :: * -> *). MonadIO m => Int -> m [TextureObject]
genObjectNames Int
n =
IO [TextureObject] -> m [TextureObject]
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO [TextureObject] -> m [TextureObject])
-> ((Ptr GLuint -> IO [TextureObject]) -> IO [TextureObject])
-> (Ptr GLuint -> IO [TextureObject])
-> m [TextureObject]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> (Ptr GLuint -> IO [TextureObject]) -> IO [TextureObject]
forall a b. Storable a => Int -> (Ptr a -> IO b) -> IO b
allocaArray Int
n ((Ptr GLuint -> IO [TextureObject]) -> m [TextureObject])
-> (Ptr GLuint -> IO [TextureObject]) -> m [TextureObject]
forall a b. (a -> b) -> a -> b
$ \Ptr GLuint
buf -> do
GLsizei -> Ptr GLuint -> IO ()
forall (m :: * -> *). MonadIO m => GLsizei -> Ptr GLuint -> m ()
glGenTextures (Int -> GLsizei
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n) Ptr GLuint
buf
([GLuint] -> [TextureObject]) -> IO [GLuint] -> IO [TextureObject]
forall a b. (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((GLuint -> TextureObject) -> [GLuint] -> [TextureObject]
forall a b. (a -> b) -> [a] -> [b]
map GLuint -> TextureObject
TextureObject) (IO [GLuint] -> IO [TextureObject])
-> IO [GLuint] -> IO [TextureObject]
forall a b. (a -> b) -> a -> b
$ Int -> Ptr GLuint -> IO [GLuint]
forall a. Storable a => Int -> Ptr a -> IO [a]
peekArray Int
n Ptr GLuint
buf
instance CanBeLabeled TextureObject where
objectLabel :: TextureObject -> StateVar (Maybe String)
objectLabel = GLuint -> GLuint -> StateVar (Maybe String)
objectNameLabel GLuint
GL_TEXTURE (GLuint -> StateVar (Maybe String))
-> (TextureObject -> GLuint)
-> TextureObject
-> StateVar (Maybe String)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TextureObject -> GLuint
textureID