{-# language CPP #-}
module Vulkan.Core10.AllocationCallbacks (AllocationCallbacks(..)) where
import Foreign.Marshal.Alloc (allocaBytesAligned)
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 :: AllocationCallbacks -> (Ptr AllocationCallbacks -> IO b) -> IO b
withCStruct x :: AllocationCallbacks
x f :: Ptr AllocationCallbacks -> IO b
f = Int -> Int -> (Ptr AllocationCallbacks -> IO b) -> IO b
forall a b. Int -> Int -> (Ptr a -> IO b) -> IO b
allocaBytesAligned 48 8 ((Ptr AllocationCallbacks -> IO b) -> IO b)
-> (Ptr AllocationCallbacks -> IO b) -> IO b
forall a b. (a -> b) -> a -> b
$ \p :: 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 :: Ptr AllocationCallbacks -> AllocationCallbacks -> IO b -> IO b
pokeCStruct p :: Ptr AllocationCallbacks
p AllocationCallbacks{..} f :: 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` 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` 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` 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` 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` 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` 40 :: Ptr PFN_vkInternalFreeNotification)) (PFN_vkInternalAllocationNotification
pfnInternalFree)
IO b
f
cStructSize :: Int
cStructSize = 48
cStructAlignment :: Int
cStructAlignment = 8
pokeZeroCStruct :: Ptr AllocationCallbacks -> IO b -> IO b
pokeZeroCStruct p :: Ptr AllocationCallbacks
p f :: 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` 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` 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` 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 p :: Ptr AllocationCallbacks
p = do
Ptr ()
pUserData <- Ptr (Ptr ()) -> IO (Ptr ())
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` 0 :: Ptr (Ptr ())))
PFN_vkAllocationFunction
pfnAllocation <- Ptr PFN_vkAllocationFunction -> IO PFN_vkAllocationFunction
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` 8 :: Ptr PFN_vkAllocationFunction))
PFN_vkReallocationFunction
pfnReallocation <- Ptr PFN_vkReallocationFunction -> IO PFN_vkReallocationFunction
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` 16 :: Ptr PFN_vkReallocationFunction))
PFN_vkFreeFunction
pfnFree <- Ptr PFN_vkFreeFunction -> IO PFN_vkFreeFunction
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` 24 :: Ptr PFN_vkFreeFunction))
PFN_vkInternalAllocationNotification
pfnInternalAllocation <- Ptr PFN_vkInternalAllocationNotification
-> IO PFN_vkInternalAllocationNotification
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` 32 :: Ptr PFN_vkInternalAllocationNotification))
PFN_vkInternalAllocationNotification
pfnInternalFree <- Ptr PFN_vkInternalAllocationNotification
-> IO PFN_vkInternalAllocationNotification
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` 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
_ = 48
alignment :: AllocationCallbacks -> Int
alignment ~AllocationCallbacks
_ = 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 :: Ptr AllocationCallbacks
ptr poked :: 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