Guest User

Untitled

a guest
Aug 6th, 2025
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haskell 1.17 KB | Source Code | 0 0
  1. module Main where
  2. import Vulkan
  3. import Control.Exception
  4. import Foreign hiding (newForeignPtr)
  5.  
  6. data VulkanException = VulkanException VkResult
  7.     deriving Show
  8. instance Exception VulkanException
  9.  
  10. checkResult :: VkResult -> IO ()
  11. checkResult (VkResult 0) = return ()
  12. checkResult result = throwIO (VulkanException result)
  13.  
  14. createInstance :: VkInstanceCreateInfo -> IO VkInstance
  15. createInstance instance_create_info =
  16.     alloca $ \p_instance_create_info -> do
  17.         poke p_instance_create_info instance_create_info
  18.         alloca $ \p_instance -> do
  19.             vkCreateInstance p_instance_create_info nullPtr p_instance >>= checkResult
  20.             peek p_instance
  21.  
  22. destroyInstance :: VkInstance -> IO ()
  23. destroyInstance instanze =
  24.     vkDestroyInstance instanze nullPtr
  25.  
  26. withInstance :: VkInstanceCreateInfo -> (VkInstance -> IO ()) -> IO ()
  27. withInstance createInfo = bracket (createInstance createInfo) destroyInstance
  28.  
  29. main :: IO ()
  30. main = do
  31.     let instance_create_info = VkInstanceCreateInfo vkStructureTypeInstanceCreateInfo nullPtr (VkInstanceCreateFlags 0) nullPtr 0 nullPtr 0 nullPtr
  32.     withInstance instance_create_info $ \instanze ->
  33.         return ()
  34.  
  35.  
Advertisement
Add Comment
Please, Sign In to add comment