{-# language CPP #-}
module Vulkan.Core10.AllocationCallbacks (AllocationCallbacks(..)) where
import Foreign.Marshal.Alloc (allocaBytes)
import Foreign.Ptr (plusPtr)
import Vulkan.CStruct (FromCStruct)
import Vulkan.CStruct (FromCStruct(..))
import Vulkan.CStruct (ToCStruct)
import Vulkan.CStruct (ToCStruct(..))
import Vulkan.Zero (Zero(..))
import Data.Typeable (Typeable)
import Foreign.Storable (Storable)
import Foreign.Storable (Storable(peek))
import Foreign.Storable (Storable(poke))
import qualified Foreign.Storable (Storable(..))
import GHC.Generics (Generic)
import Foreign.Ptr (Ptr)
import Data.Kind (Type)
import Vulkan.Core10.FuncPointers (PFN_vkAllocationFunction)
import Vulkan.Core10.FuncPointers (PFN_vkFreeFunction)
import Vulkan.Core10.FuncPointers (PFN_vkInternalAllocationNotification)
import Vulkan.Core10.FuncPointers (PFN_vkInternalFreeNotification)
import Vulkan.Core10.FuncPointers (PFN_vkReallocationFunction)
data AllocationCallbacks = AllocationCallbacks
{
AllocationCallbacks -> Ptr ()
userData :: Ptr ()
,
AllocationCallbacks -> PFN_vkAllocationFunction
pfnAllocation :: PFN_vkAllocationFunction
,
AllocationCallbacks -> PFN_vkReallocationFunction
pfnReallocation :: PFN_vkReallocationFunction
,
AllocationCallbacks -> PFN_vkFreeFunction
pfnFree :: PFN_vkFreeFunction
,
AllocationCallbacks -> PFN_vkInternalAllocationNotification
pfnInternalAllocation :: PFN_vkInternalAllocationNotification
,
AllocationCallbacks -> PFN_vkInternalAllocationNotification
pfnInternalFree :: PFN_vkInternalFreeNotification
}
deriving (Typeable)
#if defined(GENERIC_INSTANCES)
deriving instance Generic (AllocationCallbacks)
#endif
deriving instance Show AllocationCallbacks
instance ToCStruct AllocationCallbacks where
withCStruct :: forall b.
AllocationCallbacks -> (Ptr AllocationCallbacks -> IO b) -> IO b
withCStruct AllocationCallbacks
x Ptr AllocationCallbacks -> IO b
f = Int -> (Ptr AllocationCallbacks -> IO b) -> IO b
forall a b. Int -> (Ptr a -> IO b) -> IO b
allocaBytes Int
48 ((Ptr AllocationCallbacks -> IO b) -> IO b)
-> (Ptr AllocationCallbacks -> IO b) -> IO b
forall a b. (a -> b) -> a -> b
$ \Ptr AllocationCallbacks
p -> Ptr AllocationCallbacks -> AllocationCallbacks -> IO b -> IO b
forall a b. ToCStruct a => Ptr a -> a -> IO b -> IO b
pokeCStruct Ptr AllocationCallbacks
p AllocationCallbacks
x (Ptr AllocationCallbacks -> IO b
f Ptr AllocationCallbacks
p)
pokeCStruct :: forall b.
Ptr AllocationCallbacks -> AllocationCallbacks -> IO b -> IO b
pokeCStruct Ptr AllocationCallbacks
p AllocationCallbacks{Ptr ()
PFN_vkFreeFunction
PFN_vkReallocationFunction
PFN_vkAllocationFunction
PFN_vkInternalAllocationNotification
pfnInternalFree :: PFN_vkInternalAllocationNotification
pfnInternalAllocation :: PFN_vkInternalAllocationNotification
pfnFree :: PFN_vkFreeFunction
pfnReallocation :: PFN_vkReallocationFunction
pfnAllocation :: PFN_vkAllocationFunction
userData :: Ptr ()
$sel:pfnInternalFree:AllocationCallbacks :: AllocationCallbacks -> PFN_vkInternalAllocationNotification
$sel:pfnInternalAllocation:AllocationCallbacks :: AllocationCallbacks -> PFN_vkInternalAllocationNotification
$sel:pfnFree:AllocationCallbacks :: AllocationCallbacks -> PFN_vkFreeFunction
$sel:pfnReallocation:AllocationCallbacks :: AllocationCallbacks -> PFN_vkReallocationFunction
$sel:pfnAllocation:AllocationCallbacks :: AllocationCallbacks -> PFN_vkAllocationFunction
$sel:userData:AllocationCallbacks :: AllocationCallbacks -> Ptr ()
..} IO b
f = do
Ptr (Ptr ()) -> Ptr () -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr AllocationCallbacks
p Ptr AllocationCallbacks -> Int -> Ptr (Ptr ())
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
0 :: Ptr (Ptr ()))) (Ptr ()
userData)
Ptr PFN_vkAllocationFunction -> PFN_vkAllocationFunction -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr AllocationCallbacks
p Ptr AllocationCallbacks -> Int -> Ptr PFN_vkAllocationFunction
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
8 :: Ptr PFN_vkAllocationFunction)) (PFN_vkAllocationFunction
pfnAllocation)
Ptr PFN_vkReallocationFunction
-> PFN_vkReallocationFunction -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr AllocationCallbacks
p Ptr AllocationCallbacks -> Int -> Ptr PFN_vkReallocationFunction
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
16 :: Ptr PFN_vkReallocationFunction)) (PFN_vkReallocationFunction
pfnReallocation)
Ptr PFN_vkFreeFunction -> PFN_vkFreeFunction -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr AllocationCallbacks
p Ptr AllocationCallbacks -> Int -> Ptr PFN_vkFreeFunction
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
24 :: Ptr PFN_vkFreeFunction)) (PFN_vkFreeFunction
pfnFree)
Ptr PFN_vkInternalAllocationNotification
-> PFN_vkInternalAllocationNotification -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr AllocationCallbacks
p Ptr AllocationCallbacks
-> Int -> Ptr PFN_vkInternalAllocationNotification
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
32 :: Ptr PFN_vkInternalAllocationNotification)) (PFN_vkInternalAllocationNotification
pfnInternalAllocation)
Ptr PFN_vkInternalAllocationNotification
-> PFN_vkInternalAllocationNotification -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr AllocationCallbacks
p Ptr AllocationCallbacks
-> Int -> Ptr PFN_vkInternalAllocationNotification
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
40 :: Ptr PFN_vkInternalFreeNotification)) (PFN_vkInternalAllocationNotification
pfnInternalFree)
IO b
f
cStructSize :: Int
cStructSize = Int
48
cStructAlignment :: Int
cStructAlignment = Int
8
pokeZeroCStruct :: forall b. Ptr AllocationCallbacks -> IO b -> IO b
pokeZeroCStruct Ptr AllocationCallbacks
p IO b
f = do
Ptr PFN_vkAllocationFunction -> PFN_vkAllocationFunction -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr AllocationCallbacks
p Ptr AllocationCallbacks -> Int -> Ptr PFN_vkAllocationFunction
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
8 :: Ptr PFN_vkAllocationFunction)) (PFN_vkAllocationFunction
forall a. Zero a => a
zero)
Ptr PFN_vkReallocationFunction
-> PFN_vkReallocationFunction -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr AllocationCallbacks
p Ptr AllocationCallbacks -> Int -> Ptr PFN_vkReallocationFunction
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
16 :: Ptr PFN_vkReallocationFunction)) (PFN_vkReallocationFunction
forall a. Zero a => a
zero)
Ptr PFN_vkFreeFunction -> PFN_vkFreeFunction -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr AllocationCallbacks
p Ptr AllocationCallbacks -> Int -> Ptr PFN_vkFreeFunction
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
24 :: Ptr PFN_vkFreeFunction)) (PFN_vkFreeFunction
forall a. Zero a => a
zero)
IO b
f
instance FromCStruct AllocationCallbacks where
peekCStruct :: Ptr AllocationCallbacks -> IO AllocationCallbacks
peekCStruct Ptr AllocationCallbacks
p = do
Ptr ()
pUserData <- forall a. Storable a => Ptr a -> IO a
peek @(Ptr ()) ((Ptr AllocationCallbacks
p Ptr AllocationCallbacks -> Int -> Ptr (Ptr ())
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
0 :: Ptr (Ptr ())))
PFN_vkAllocationFunction
pfnAllocation <- forall a. Storable a => Ptr a -> IO a
peek @PFN_vkAllocationFunction ((Ptr AllocationCallbacks
p Ptr AllocationCallbacks -> Int -> Ptr PFN_vkAllocationFunction
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
8 :: Ptr PFN_vkAllocationFunction))
PFN_vkReallocationFunction
pfnReallocation <- forall a. Storable a => Ptr a -> IO a
peek @PFN_vkReallocationFunction ((Ptr AllocationCallbacks
p Ptr AllocationCallbacks -> Int -> Ptr PFN_vkReallocationFunction
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
16 :: Ptr PFN_vkReallocationFunction))
PFN_vkFreeFunction
pfnFree <- forall a. Storable a => Ptr a -> IO a
peek @PFN_vkFreeFunction ((Ptr AllocationCallbacks
p Ptr AllocationCallbacks -> Int -> Ptr PFN_vkFreeFunction
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
24 :: Ptr PFN_vkFreeFunction))
PFN_vkInternalAllocationNotification
pfnInternalAllocation <- forall a. Storable a => Ptr a -> IO a
peek @PFN_vkInternalAllocationNotification ((Ptr AllocationCallbacks
p Ptr AllocationCallbacks
-> Int -> Ptr PFN_vkInternalAllocationNotification
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
32 :: Ptr PFN_vkInternalAllocationNotification))
PFN_vkInternalAllocationNotification
pfnInternalFree <- forall a. Storable a => Ptr a -> IO a
peek @PFN_vkInternalFreeNotification ((Ptr AllocationCallbacks
p Ptr AllocationCallbacks
-> Int -> Ptr PFN_vkInternalAllocationNotification
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
40 :: Ptr PFN_vkInternalFreeNotification))
AllocationCallbacks -> IO AllocationCallbacks
forall (f :: * -> *) a. Applicative f => a -> f a
pure (AllocationCallbacks -> IO AllocationCallbacks)
-> AllocationCallbacks -> IO AllocationCallbacks
forall a b. (a -> b) -> a -> b
$ Ptr ()
-> PFN_vkAllocationFunction
-> PFN_vkReallocationFunction
-> PFN_vkFreeFunction
-> PFN_vkInternalAllocationNotification
-> PFN_vkInternalAllocationNotification
-> AllocationCallbacks
AllocationCallbacks
Ptr ()
pUserData
PFN_vkAllocationFunction
pfnAllocation
PFN_vkReallocationFunction
pfnReallocation
PFN_vkFreeFunction
pfnFree
PFN_vkInternalAllocationNotification
pfnInternalAllocation
PFN_vkInternalAllocationNotification
pfnInternalFree
instance Storable AllocationCallbacks where
sizeOf :: AllocationCallbacks -> Int
sizeOf ~AllocationCallbacks
_ = Int
48
alignment :: AllocationCallbacks -> Int
alignment ~AllocationCallbacks
_ = Int
8
peek :: Ptr AllocationCallbacks -> IO AllocationCallbacks
peek = Ptr AllocationCallbacks -> IO AllocationCallbacks
forall a. FromCStruct a => Ptr a -> IO a
peekCStruct
poke :: Ptr AllocationCallbacks -> AllocationCallbacks -> IO ()
poke Ptr AllocationCallbacks
ptr AllocationCallbacks
poked = Ptr AllocationCallbacks -> AllocationCallbacks -> IO () -> IO ()
forall a b. ToCStruct a => Ptr a -> a -> IO b -> IO b
pokeCStruct Ptr AllocationCallbacks
ptr AllocationCallbacks
poked (() -> IO ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())
instance Zero AllocationCallbacks where
zero :: AllocationCallbacks
zero = Ptr ()
-> PFN_vkAllocationFunction
-> PFN_vkReallocationFunction
-> PFN_vkFreeFunction
-> PFN_vkInternalAllocationNotification
-> PFN_vkInternalAllocationNotification
-> AllocationCallbacks
AllocationCallbacks
Ptr ()
forall a. Zero a => a
zero
PFN_vkAllocationFunction
forall a. Zero a => a
zero
PFN_vkReallocationFunction
forall a. Zero a => a
zero
PFN_vkFreeFunction
forall a. Zero a => a
zero
PFN_vkInternalAllocationNotification
forall a. Zero a => a
zero
PFN_vkInternalAllocationNotification
forall a. Zero a => a
zero