{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE MonoLocalBinds #-}
{-# OPTIONS_GHC -Wall -fno-warn-tabs #-}

module Gpu.Vulkan.Khr.Surface.Glfw.Middle where

import Foreign.Marshal
import Foreign.Storable
import Data.TypeLevel.ParMaybe qualified as TPMaybe

import Gpu.Vulkan.Exception.Middle

import qualified Graphics.UI.GLFW as GlfwB
import Gpu.Vulkan.AllocationCallbacks.Middle.Internal
	qualified as AllocationCallbacks
import qualified Gpu.Vulkan.Instance.Middle.Internal as Instance
import qualified Gpu.Vulkan.Khr.Surface.Middle.Internal as Surface

createWindowSurface :: Instance.I ->
	GlfwB.Window -> TPMaybe.M AllocationCallbacks.A mn -> IO Surface.S
createWindowSurface :: forall (mn :: Maybe (*)). I -> Window -> M A mn -> IO S
createWindowSurface (Instance.I I
ist) Window
win M A mn
mac = S -> S
Surface.S (S -> S) -> IO S -> IO S
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
	(Ptr S -> IO S) -> IO S
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca \Ptr S
psfc -> do
		M A mn -> (Ptr A -> IO ()) -> IO ()
forall (ma :: Maybe (*)) b. M A ma -> (Ptr A -> IO b) -> IO ()
AllocationCallbacks.mToCore M A mn
mac \Ptr A
pac -> do
			r <- I -> Window -> Ptr A -> Ptr S -> IO Result
forall vkResult vkInstance vkAllocationCallbacks vkSurfaceKHR.
Enum vkResult =>
Ptr vkInstance
-> Window
-> Ptr vkAllocationCallbacks
-> Ptr vkSurfaceKHR
-> IO vkResult
GlfwB.createWindowSurface I
ist Window
win Ptr A
pac Ptr S
psfc
			throwUnlessSuccess r
		Ptr S -> IO S
forall a. Storable a => Ptr a -> IO a
peek Ptr S
psfc