{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RecordWildCards #-}
module WGPU.Internal.CommandEncoder
(
CommandEncoder (..),
createCommandEncoder,
commandEncoderFinish,
)
where
import Control.Monad.IO.Class (liftIO)
import Control.Monad.Trans.Cont (ContT (ContT), evalContT)
import Data.Text (Text)
import Foreign (nullPtr, with)
import WGPU.Internal.CommandBuffer (CommandBuffer (CommandBuffer))
import WGPU.Internal.Device (Device, deviceInst, wgpuDevice)
import WGPU.Internal.Instance (Instance, wgpuHsInstance)
import WGPU.Internal.Memory (ToRaw, raw, rawPtr, showWithPtr)
import qualified WGPU.Raw.Generated.Fun as RawFun
import WGPU.Raw.Generated.Struct.WGPUCommandBufferDescriptor (WGPUCommandBufferDescriptor)
import qualified WGPU.Raw.Generated.Struct.WGPUCommandBufferDescriptor as WGPUCommandBufferDescriptor
import qualified WGPU.Raw.Generated.Struct.WGPUCommandEncoderDescriptor as WGPUCommandEncoderDescriptor
import WGPU.Raw.Types (WGPUCommandEncoder (WGPUCommandEncoder))
data CommandEncoder = CommandEncoder
{ CommandEncoder -> Instance
commandEncoderInst :: !Instance,
CommandEncoder -> WGPUCommandEncoder
wgpuCommandEncoder :: !WGPUCommandEncoder
}
instance Show CommandEncoder where
show :: CommandEncoder -> String
show CommandEncoder
e =
let CommandEncoder Instance
_ (WGPUCommandEncoder Ptr ()
ptr) = CommandEncoder
e
in String -> Ptr () -> String
forall a. String -> Ptr a -> String
showWithPtr String
"CommandEncoder" Ptr ()
ptr
instance Eq CommandEncoder where
== :: CommandEncoder -> CommandEncoder -> Bool
(==) CommandEncoder
e1 CommandEncoder
e2 =
let CommandEncoder Instance
_ (WGPUCommandEncoder Ptr ()
e1_ptr) = CommandEncoder
e1
CommandEncoder Instance
_ (WGPUCommandEncoder Ptr ()
e2_ptr) = CommandEncoder
e2
in Ptr ()
e1_ptr Ptr () -> Ptr () -> Bool
forall a. Eq a => a -> a -> Bool
== Ptr ()
e2_ptr
instance ToRaw CommandEncoder WGPUCommandEncoder where
raw :: CommandEncoder -> ContT c IO WGPUCommandEncoder
raw = WGPUCommandEncoder -> ContT c IO WGPUCommandEncoder
forall (f :: * -> *) a. Applicative f => a -> f a
pure (WGPUCommandEncoder -> ContT c IO WGPUCommandEncoder)
-> (CommandEncoder -> WGPUCommandEncoder)
-> CommandEncoder
-> ContT c IO WGPUCommandEncoder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CommandEncoder -> WGPUCommandEncoder
wgpuCommandEncoder
createCommandEncoder ::
Device ->
Text ->
IO CommandEncoder
createCommandEncoder :: Device -> Text -> IO CommandEncoder
createCommandEncoder Device
device Text
label = ContT CommandEncoder IO CommandEncoder -> IO CommandEncoder
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT CommandEncoder IO CommandEncoder -> IO CommandEncoder)
-> ContT CommandEncoder IO CommandEncoder -> IO CommandEncoder
forall a b. (a -> b) -> a -> b
$ do
let inst :: Instance
inst = Device -> Instance
deviceInst Device
device
Ptr CChar
label_ptr <- Text -> ContT CommandEncoder IO (Ptr CChar)
forall a b c. ToRawPtr a b => a -> ContT c IO (Ptr b)
rawPtr Text
label
Ptr WGPUCommandEncoderDescriptor
commandEncoderDescriptor_ptr <-
((Ptr WGPUCommandEncoderDescriptor -> IO CommandEncoder)
-> IO CommandEncoder)
-> ContT CommandEncoder IO (Ptr WGPUCommandEncoderDescriptor)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr WGPUCommandEncoderDescriptor -> IO CommandEncoder)
-> IO CommandEncoder)
-> ContT CommandEncoder IO (Ptr WGPUCommandEncoderDescriptor))
-> (WGPUCommandEncoderDescriptor
-> (Ptr WGPUCommandEncoderDescriptor -> IO CommandEncoder)
-> IO CommandEncoder)
-> WGPUCommandEncoderDescriptor
-> ContT CommandEncoder IO (Ptr WGPUCommandEncoderDescriptor)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WGPUCommandEncoderDescriptor
-> (Ptr WGPUCommandEncoderDescriptor -> IO CommandEncoder)
-> IO CommandEncoder
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with (WGPUCommandEncoderDescriptor
-> ContT CommandEncoder IO (Ptr WGPUCommandEncoderDescriptor))
-> WGPUCommandEncoderDescriptor
-> ContT CommandEncoder IO (Ptr WGPUCommandEncoderDescriptor)
forall a b. (a -> b) -> a -> b
$
WGPUCommandEncoderDescriptor :: Ptr WGPUChainedStruct -> Ptr CChar -> WGPUCommandEncoderDescriptor
WGPUCommandEncoderDescriptor.WGPUCommandEncoderDescriptor
{ nextInChain :: Ptr WGPUChainedStruct
nextInChain = Ptr WGPUChainedStruct
forall a. Ptr a
nullPtr,
label :: Ptr CChar
label = Ptr CChar
label_ptr
}
WGPUCommandEncoder
commandEncoderRaw <-
IO WGPUCommandEncoder -> ContT CommandEncoder IO WGPUCommandEncoder
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO WGPUCommandEncoder
-> ContT CommandEncoder IO WGPUCommandEncoder)
-> IO WGPUCommandEncoder
-> ContT CommandEncoder IO WGPUCommandEncoder
forall a b. (a -> b) -> a -> b
$
WGPUHsInstance
-> WGPUDevice
-> Ptr WGPUCommandEncoderDescriptor
-> IO WGPUCommandEncoder
RawFun.wgpuDeviceCreateCommandEncoder
(Instance -> WGPUHsInstance
wgpuHsInstance Instance
inst)
(Device -> WGPUDevice
wgpuDevice Device
device)
Ptr WGPUCommandEncoderDescriptor
commandEncoderDescriptor_ptr
CommandEncoder -> ContT CommandEncoder IO CommandEncoder
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Instance -> WGPUCommandEncoder -> CommandEncoder
CommandEncoder Instance
inst WGPUCommandEncoder
commandEncoderRaw)
commandEncoderFinish ::
CommandEncoder ->
Text ->
IO CommandBuffer
commandEncoderFinish :: CommandEncoder -> Text -> IO CommandBuffer
commandEncoderFinish CommandEncoder
commandEncoder Text
label = ContT CommandBuffer IO CommandBuffer -> IO CommandBuffer
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT CommandBuffer IO CommandBuffer -> IO CommandBuffer)
-> ContT CommandBuffer IO CommandBuffer -> IO CommandBuffer
forall a b. (a -> b) -> a -> b
$ do
let inst :: Instance
inst = CommandEncoder -> Instance
commandEncoderInst CommandEncoder
commandEncoder
Ptr WGPUCommandBufferDescriptor
commandBufferDescriptor_ptr <- CommandBufferDescriptor
-> ContT CommandBuffer IO (Ptr WGPUCommandBufferDescriptor)
forall a b c. ToRawPtr a b => a -> ContT c IO (Ptr b)
rawPtr (CommandBufferDescriptor
-> ContT CommandBuffer IO (Ptr WGPUCommandBufferDescriptor))
-> CommandBufferDescriptor
-> ContT CommandBuffer IO (Ptr WGPUCommandBufferDescriptor)
forall a b. (a -> b) -> a -> b
$ Text -> CommandBufferDescriptor
CommandBufferDescriptor Text
label
WGPUCommandBuffer
commandBufferRaw <-
IO WGPUCommandBuffer -> ContT CommandBuffer IO WGPUCommandBuffer
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO WGPUCommandBuffer -> ContT CommandBuffer IO WGPUCommandBuffer)
-> IO WGPUCommandBuffer -> ContT CommandBuffer IO WGPUCommandBuffer
forall a b. (a -> b) -> a -> b
$
WGPUHsInstance
-> WGPUCommandEncoder
-> Ptr WGPUCommandBufferDescriptor
-> IO WGPUCommandBuffer
RawFun.wgpuCommandEncoderFinish
(Instance -> WGPUHsInstance
wgpuHsInstance Instance
inst)
(CommandEncoder -> WGPUCommandEncoder
wgpuCommandEncoder CommandEncoder
commandEncoder)
Ptr WGPUCommandBufferDescriptor
commandBufferDescriptor_ptr
CommandBuffer -> ContT CommandBuffer IO CommandBuffer
forall (f :: * -> *) a. Applicative f => a -> f a
pure (WGPUCommandBuffer -> CommandBuffer
CommandBuffer WGPUCommandBuffer
commandBufferRaw)
newtype CommandBufferDescriptor = CommandBufferDescriptor
{CommandBufferDescriptor -> Text
commandBufferLabel :: Text}
deriving (CommandBufferDescriptor -> CommandBufferDescriptor -> Bool
(CommandBufferDescriptor -> CommandBufferDescriptor -> Bool)
-> (CommandBufferDescriptor -> CommandBufferDescriptor -> Bool)
-> Eq CommandBufferDescriptor
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CommandBufferDescriptor -> CommandBufferDescriptor -> Bool
$c/= :: CommandBufferDescriptor -> CommandBufferDescriptor -> Bool
== :: CommandBufferDescriptor -> CommandBufferDescriptor -> Bool
$c== :: CommandBufferDescriptor -> CommandBufferDescriptor -> Bool
Eq, Int -> CommandBufferDescriptor -> ShowS
[CommandBufferDescriptor] -> ShowS
CommandBufferDescriptor -> String
(Int -> CommandBufferDescriptor -> ShowS)
-> (CommandBufferDescriptor -> String)
-> ([CommandBufferDescriptor] -> ShowS)
-> Show CommandBufferDescriptor
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CommandBufferDescriptor] -> ShowS
$cshowList :: [CommandBufferDescriptor] -> ShowS
show :: CommandBufferDescriptor -> String
$cshow :: CommandBufferDescriptor -> String
showsPrec :: Int -> CommandBufferDescriptor -> ShowS
$cshowsPrec :: Int -> CommandBufferDescriptor -> ShowS
Show)
instance ToRaw CommandBufferDescriptor WGPUCommandBufferDescriptor where
raw :: CommandBufferDescriptor -> ContT c IO WGPUCommandBufferDescriptor
raw CommandBufferDescriptor {Text
commandBufferLabel :: Text
commandBufferLabel :: CommandBufferDescriptor -> Text
..} = do
Ptr CChar
label_ptr <- Text -> ContT c IO (Ptr CChar)
forall a b c. ToRawPtr a b => a -> ContT c IO (Ptr b)
rawPtr Text
commandBufferLabel
WGPUCommandBufferDescriptor
-> ContT c IO WGPUCommandBufferDescriptor
forall (f :: * -> *) a. Applicative f => a -> f a
pure
WGPUCommandBufferDescriptor :: Ptr WGPUChainedStruct -> Ptr CChar -> WGPUCommandBufferDescriptor
WGPUCommandBufferDescriptor.WGPUCommandBufferDescriptor
{ nextInChain :: Ptr WGPUChainedStruct
nextInChain = Ptr WGPUChainedStruct
forall a. Ptr a
nullPtr,
label :: Ptr CChar
label = Ptr CChar
label_ptr
}