{-# language CPP #-}
-- | = Name
--
-- XR_MSFT_spatial_anchor - instance extension
--
-- = Specification
--
-- See
-- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XR_MSFT_spatial_anchor  XR_MSFT_spatial_anchor>
-- in the main specification for complete information.
--
-- = Registered Extension Number
--
-- 40
--
-- = Revision
--
-- 1
--
-- = Extension and Version Dependencies
--
-- -   Requires OpenXR 1.0
--
-- = See Also
--
-- 'createSpatialAnchorMSFT', 'createSpatialAnchorSpaceMSFT',
-- 'destroySpatialAnchorMSFT'
--
-- = Document Notes
--
-- For more information, see the
-- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XR_MSFT_spatial_anchor OpenXR Specification>
--
-- This page is a generated document. Fixes and changes should be made to
-- the generator scripts, not directly.
module OpenXR.Extensions.XR_MSFT_spatial_anchor  ( createSpatialAnchorMSFT
                                                 , withSpatialAnchorMSFT
                                                 , createSpatialAnchorSpaceMSFT
                                                 , withSpatialAnchorSpaceMSFT
                                                 , destroySpatialAnchorMSFT
                                                 , SpatialAnchorCreateInfoMSFT(..)
                                                 , SpatialAnchorSpaceCreateInfoMSFT(..)
                                                 , MSFT_spatial_anchor_SPEC_VERSION
                                                 , pattern MSFT_spatial_anchor_SPEC_VERSION
                                                 , MSFT_SPATIAL_ANCHOR_EXTENSION_NAME
                                                 , pattern MSFT_SPATIAL_ANCHOR_EXTENSION_NAME
                                                 , SpatialAnchorMSFT(..)
                                                 ) where

import OpenXR.Internal.Utils (traceAroundEvent)
import Control.Exception.Base (bracket)
import Control.Monad (unless)
import Control.Monad.IO.Class (liftIO)
import Foreign.Marshal.Alloc (allocaBytesAligned)
import Foreign.Marshal.Alloc (callocBytes)
import Foreign.Marshal.Alloc (free)
import GHC.Base (when)
import GHC.IO (throwIO)
import GHC.Ptr (nullFunPtr)
import Foreign.Ptr (nullPtr)
import Foreign.Ptr (plusPtr)
import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.Cont (evalContT)
import OpenXR.CStruct (FromCStruct)
import OpenXR.CStruct (FromCStruct(..))
import OpenXR.CStruct (ToCStruct)
import OpenXR.CStruct (ToCStruct(..))
import OpenXR.Zero (Zero(..))
import Control.Monad.IO.Class (MonadIO)
import Data.String (IsString)
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 GHC.IO.Exception (IOErrorType(..))
import GHC.IO.Exception (IOException(..))
import Foreign.Ptr (FunPtr)
import Foreign.Ptr (Ptr)
import Data.Kind (Type)
import Control.Monad.Trans.Cont (ContT(..))
import OpenXR.Core10.Space (destroySpace)
import OpenXR.Dynamic (InstanceCmds(pXrCreateSpatialAnchorMSFT))
import OpenXR.Dynamic (InstanceCmds(pXrCreateSpatialAnchorSpaceMSFT))
import OpenXR.Dynamic (InstanceCmds(pXrDestroySpatialAnchorMSFT))
import OpenXR.Exception (OpenXrException(..))
import OpenXR.Core10.Space (Posef)
import OpenXR.Core10.Enums.Result (Result)
import OpenXR.Core10.Enums.Result (Result(..))
import OpenXR.Core10.Handles (Session)
import OpenXR.Core10.Handles (Session(..))
import OpenXR.Core10.Handles (Session_T)
import OpenXR.Core10.Handles (Space)
import OpenXR.Core10.Handles (Space(Space))
import OpenXR.Core10.Handles (Space_T)
import OpenXR.Extensions.Handles (SpatialAnchorMSFT)
import OpenXR.Extensions.Handles (SpatialAnchorMSFT(..))
import OpenXR.Extensions.Handles (SpatialAnchorMSFT(SpatialAnchorMSFT))
import OpenXR.Extensions.Handles (SpatialAnchorMSFT_T)
import OpenXR.Core10.Enums.StructureType (StructureType)
import OpenXR.Core10.FundamentalTypes (Time)
import OpenXR.Core10.Enums.Result (Result(SUCCESS))
import OpenXR.Core10.Enums.StructureType (StructureType(TYPE_SPATIAL_ANCHOR_CREATE_INFO_MSFT))
import OpenXR.Core10.Enums.StructureType (StructureType(TYPE_SPATIAL_ANCHOR_SPACE_CREATE_INFO_MSFT))
import OpenXR.Extensions.Handles (SpatialAnchorMSFT(..))
foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "dynamic" mkXrCreateSpatialAnchorMSFT
  :: FunPtr (Ptr Session_T -> Ptr SpatialAnchorCreateInfoMSFT -> Ptr (Ptr SpatialAnchorMSFT_T) -> IO Result) -> Ptr Session_T -> Ptr SpatialAnchorCreateInfoMSFT -> Ptr (Ptr SpatialAnchorMSFT_T) -> IO Result

-- | xrCreateSpatialAnchorMSFT - Creates a spatial anchor
--
-- == Parameter Descriptions
--
-- = Description
--
-- Creates an 'OpenXR.Extensions.Handles.SpatialAnchorMSFT' handle
-- representing a spatial anchor that will track a fixed location in the
-- physical world over time. That real-world location is specified by the
-- position and orientation of the specified @pose@ within @space@ at
-- @time@.
--
-- If @space@ cannot be located relative to the environment at the moment
-- of the call to 'createSpatialAnchorMSFT', the runtime /must/ return
-- 'OpenXR.Core10.Enums.Result.ERROR_CREATE_SPATIAL_ANCHOR_FAILED_MSFT'.
--
-- After the anchor is created, the runtime /should/ then adjust its
-- position and orientation over time relative to other spaces so as to
-- maintain maximum alignment to its original real-world location, even if
-- that changes the anchor’s relationship to the original @space@ used to
-- initialize it.
--
-- == Valid Usage (Implicit)
--
-- -   #VUID-xrCreateSpatialAnchorMSFT-extension-notenabled# The @@
--     extension /must/ be enabled prior to calling
--     'createSpatialAnchorMSFT'
--
-- -   #VUID-xrCreateSpatialAnchorMSFT-session-parameter# @session@ /must/
--     be a valid 'OpenXR.Core10.Handles.Session' handle
--
-- -   #VUID-xrCreateSpatialAnchorMSFT-createInfo-parameter# @createInfo@
--     /must/ be a pointer to a valid 'SpatialAnchorCreateInfoMSFT'
--     structure
--
-- -   #VUID-xrCreateSpatialAnchorMSFT-anchor-parameter# @anchor@ /must/ be
--     a pointer to an 'OpenXR.Extensions.Handles.SpatialAnchorMSFT' handle
--
-- == Return Codes
--
-- [<https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#fundamentals-successcodes Success>]
--
--     -   'OpenXR.Core10.Enums.Result.SUCCESS'
--
-- [<https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#fundamentals-errorcodes Failure>]
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_INSTANCE_LOST'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_OUT_OF_MEMORY'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_FUNCTION_UNSUPPORTED'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_VALIDATION_FAILURE'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_HANDLE_INVALID'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_POSE_INVALID'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_CREATE_SPATIAL_ANCHOR_FAILED_MSFT'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_TIME_INVALID'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_SESSION_LOST'
--
--     -   'OpenXR.Core10.Enums.Result.SESSION_LOSS_PENDING'
--
-- = See Also
--
-- 'OpenXR.Core10.Handles.Session', 'SpatialAnchorCreateInfoMSFT',
-- 'OpenXR.Extensions.Handles.SpatialAnchorMSFT'
createSpatialAnchorMSFT :: forall io
                         . (MonadIO io)
                        => -- | @session@ is a handle to an 'OpenXR.Core10.Handles.Session'.
                           Session
                        -> -- | @createInfo@ is a pointer to an 'SpatialAnchorCreateInfoMSFT' structure
                           -- containing information about how to create the anchor.
                           SpatialAnchorCreateInfoMSFT
                        -> io (SpatialAnchorMSFT)
createSpatialAnchorMSFT :: Session -> SpatialAnchorCreateInfoMSFT -> io SpatialAnchorMSFT
createSpatialAnchorMSFT session :: Session
session createInfo :: SpatialAnchorCreateInfoMSFT
createInfo = IO SpatialAnchorMSFT -> io SpatialAnchorMSFT
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO SpatialAnchorMSFT -> io SpatialAnchorMSFT)
-> (ContT SpatialAnchorMSFT IO SpatialAnchorMSFT
    -> IO SpatialAnchorMSFT)
-> ContT SpatialAnchorMSFT IO SpatialAnchorMSFT
-> io SpatialAnchorMSFT
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT SpatialAnchorMSFT IO SpatialAnchorMSFT
-> IO SpatialAnchorMSFT
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT SpatialAnchorMSFT IO SpatialAnchorMSFT
 -> io SpatialAnchorMSFT)
-> ContT SpatialAnchorMSFT IO SpatialAnchorMSFT
-> io SpatialAnchorMSFT
forall a b. (a -> b) -> a -> b
$ do
  let cmds :: InstanceCmds
cmds = Session -> InstanceCmds
instanceCmds (Session
session :: Session)
  let xrCreateSpatialAnchorMSFTPtr :: FunPtr
  (Ptr Session_T
   -> Ptr SpatialAnchorCreateInfoMSFT
   -> ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
   -> IO Result)
xrCreateSpatialAnchorMSFTPtr = InstanceCmds
-> FunPtr
     (Ptr Session_T
      -> Ptr SpatialAnchorCreateInfoMSFT
      -> ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
      -> IO Result)
pXrCreateSpatialAnchorMSFT InstanceCmds
cmds
  IO () -> ContT SpatialAnchorMSFT IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT SpatialAnchorMSFT IO ())
-> IO () -> ContT SpatialAnchorMSFT IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (FunPtr
  (Ptr Session_T
   -> Ptr SpatialAnchorCreateInfoMSFT
   -> ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
   -> IO Result)
xrCreateSpatialAnchorMSFTPtr FunPtr
  (Ptr Session_T
   -> Ptr SpatialAnchorCreateInfoMSFT
   -> ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
   -> IO Result)
-> FunPtr
     (Ptr Session_T
      -> Ptr SpatialAnchorCreateInfoMSFT
      -> ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
      -> IO Result)
-> Bool
forall a. Eq a => a -> a -> Bool
/= FunPtr
  (Ptr Session_T
   -> Ptr SpatialAnchorCreateInfoMSFT
   -> ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
   -> IO Result)
forall a. FunPtr a
nullFunPtr) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
    IOException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (IOException -> IO ()) -> IOException -> IO ()
forall a b. (a -> b) -> a -> b
$ Maybe Handle
-> IOErrorType
-> String
-> String
-> Maybe CInt
-> Maybe String
-> IOException
IOError Maybe Handle
forall a. Maybe a
Nothing IOErrorType
InvalidArgument "" "The function pointer for xrCreateSpatialAnchorMSFT is null" Maybe CInt
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing
  let xrCreateSpatialAnchorMSFT' :: Ptr Session_T
-> Ptr SpatialAnchorCreateInfoMSFT
-> ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
-> IO Result
xrCreateSpatialAnchorMSFT' = FunPtr
  (Ptr Session_T
   -> Ptr SpatialAnchorCreateInfoMSFT
   -> ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
   -> IO Result)
-> Ptr Session_T
-> Ptr SpatialAnchorCreateInfoMSFT
-> ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
-> IO Result
mkXrCreateSpatialAnchorMSFT FunPtr
  (Ptr Session_T
   -> Ptr SpatialAnchorCreateInfoMSFT
   -> ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
   -> IO Result)
xrCreateSpatialAnchorMSFTPtr
  Ptr SpatialAnchorCreateInfoMSFT
createInfo' <- ((Ptr SpatialAnchorCreateInfoMSFT -> IO SpatialAnchorMSFT)
 -> IO SpatialAnchorMSFT)
-> ContT SpatialAnchorMSFT IO (Ptr SpatialAnchorCreateInfoMSFT)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr SpatialAnchorCreateInfoMSFT -> IO SpatialAnchorMSFT)
  -> IO SpatialAnchorMSFT)
 -> ContT SpatialAnchorMSFT IO (Ptr SpatialAnchorCreateInfoMSFT))
-> ((Ptr SpatialAnchorCreateInfoMSFT -> IO SpatialAnchorMSFT)
    -> IO SpatialAnchorMSFT)
-> ContT SpatialAnchorMSFT IO (Ptr SpatialAnchorCreateInfoMSFT)
forall a b. (a -> b) -> a -> b
$ SpatialAnchorCreateInfoMSFT
-> (Ptr SpatialAnchorCreateInfoMSFT -> IO SpatialAnchorMSFT)
-> IO SpatialAnchorMSFT
forall a b. ToCStruct a => a -> (Ptr a -> IO b) -> IO b
withCStruct (SpatialAnchorCreateInfoMSFT
createInfo)
  "anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T)
pAnchor <- ((("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
  -> IO SpatialAnchorMSFT)
 -> IO SpatialAnchorMSFT)
-> ContT
     SpatialAnchorMSFT IO ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
   -> IO SpatialAnchorMSFT)
  -> IO SpatialAnchorMSFT)
 -> ContT
      SpatialAnchorMSFT IO ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T)))
-> ((("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
     -> IO SpatialAnchorMSFT)
    -> IO SpatialAnchorMSFT)
-> ContT
     SpatialAnchorMSFT IO ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
forall a b. (a -> b) -> a -> b
$ IO ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
-> (("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T)) -> IO ())
-> (("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
    -> IO SpatialAnchorMSFT)
-> IO SpatialAnchorMSFT
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (Int -> IO ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
forall a. Int -> IO (Ptr a)
callocBytes @(Ptr SpatialAnchorMSFT_T) 8) ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T)) -> IO ()
forall a. Ptr a -> IO ()
free
  Result
r <- IO Result -> ContT SpatialAnchorMSFT IO Result
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Result -> ContT SpatialAnchorMSFT IO Result)
-> IO Result -> ContT SpatialAnchorMSFT IO Result
forall a b. (a -> b) -> a -> b
$ String -> IO Result -> IO Result
forall a. String -> IO a -> IO a
traceAroundEvent "xrCreateSpatialAnchorMSFT" (Ptr Session_T
-> Ptr SpatialAnchorCreateInfoMSFT
-> ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
-> IO Result
xrCreateSpatialAnchorMSFT' (Session -> Ptr Session_T
sessionHandle (Session
session)) Ptr SpatialAnchorCreateInfoMSFT
createInfo' ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T)
pAnchor))
  IO () -> ContT SpatialAnchorMSFT IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT SpatialAnchorMSFT IO ())
-> IO () -> ContT SpatialAnchorMSFT IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r Result -> Result -> Bool
forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (OpenXrException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (Result -> OpenXrException
OpenXrException Result
r))
  Ptr SpatialAnchorMSFT_T
anchor <- IO (Ptr SpatialAnchorMSFT_T)
-> ContT SpatialAnchorMSFT IO (Ptr SpatialAnchorMSFT_T)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO (Ptr SpatialAnchorMSFT_T)
 -> ContT SpatialAnchorMSFT IO (Ptr SpatialAnchorMSFT_T))
-> IO (Ptr SpatialAnchorMSFT_T)
-> ContT SpatialAnchorMSFT IO (Ptr SpatialAnchorMSFT_T)
forall a b. (a -> b) -> a -> b
$ ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
-> IO (Ptr SpatialAnchorMSFT_T)
forall a. Storable a => Ptr a -> IO a
peek @(Ptr SpatialAnchorMSFT_T) "anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T)
pAnchor
  SpatialAnchorMSFT -> ContT SpatialAnchorMSFT IO SpatialAnchorMSFT
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SpatialAnchorMSFT -> ContT SpatialAnchorMSFT IO SpatialAnchorMSFT)
-> SpatialAnchorMSFT
-> ContT SpatialAnchorMSFT IO SpatialAnchorMSFT
forall a b. (a -> b) -> a -> b
$ (((\h :: Ptr SpatialAnchorMSFT_T
h -> Ptr SpatialAnchorMSFT_T -> InstanceCmds -> SpatialAnchorMSFT
SpatialAnchorMSFT Ptr SpatialAnchorMSFT_T
h InstanceCmds
cmds ) Ptr SpatialAnchorMSFT_T
anchor))

-- | A convenience wrapper to make a compatible pair of calls to
-- 'createSpatialAnchorMSFT' and 'destroySpatialAnchorMSFT'
--
-- To ensure that 'destroySpatialAnchorMSFT' is always called: pass
-- 'Control.Exception.bracket' (or the allocate function from your
-- favourite resource management library) as the last argument.
-- To just extract the pair pass '(,)' as the last argument.
--
withSpatialAnchorMSFT :: forall io r . MonadIO io => Session -> SpatialAnchorCreateInfoMSFT -> (io SpatialAnchorMSFT -> (SpatialAnchorMSFT -> io ()) -> r) -> r
withSpatialAnchorMSFT :: Session
-> SpatialAnchorCreateInfoMSFT
-> (io SpatialAnchorMSFT -> (SpatialAnchorMSFT -> io ()) -> r)
-> r
withSpatialAnchorMSFT session :: Session
session createInfo :: SpatialAnchorCreateInfoMSFT
createInfo b :: io SpatialAnchorMSFT -> (SpatialAnchorMSFT -> io ()) -> r
b =
  io SpatialAnchorMSFT -> (SpatialAnchorMSFT -> io ()) -> r
b (Session -> SpatialAnchorCreateInfoMSFT -> io SpatialAnchorMSFT
forall (io :: * -> *).
MonadIO io =>
Session -> SpatialAnchorCreateInfoMSFT -> io SpatialAnchorMSFT
createSpatialAnchorMSFT Session
session SpatialAnchorCreateInfoMSFT
createInfo)
    (\(SpatialAnchorMSFT
o0) -> SpatialAnchorMSFT -> io ()
forall (io :: * -> *). MonadIO io => SpatialAnchorMSFT -> io ()
destroySpatialAnchorMSFT SpatialAnchorMSFT
o0)


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "dynamic" mkXrCreateSpatialAnchorSpaceMSFT
  :: FunPtr (Ptr Session_T -> Ptr SpatialAnchorSpaceCreateInfoMSFT -> Ptr (Ptr Space_T) -> IO Result) -> Ptr Session_T -> Ptr SpatialAnchorSpaceCreateInfoMSFT -> Ptr (Ptr Space_T) -> IO Result

-- | xrCreateSpatialAnchorSpaceMSFT - Creates a space from a spatial anchor
--
-- == Parameter Descriptions
--
-- = Description
--
-- Creates an 'OpenXR.Core10.Handles.Space' handle based on a spatial
-- anchor. Application /can/ provide an 'OpenXR.Core10.Space.Posef' to
-- define the position and orientation of the new space’s origin relative
-- to the anchor’s natural origin.
--
-- Multiple 'OpenXR.Core10.Handles.Space' handles may exist for a given
-- 'OpenXR.Extensions.Handles.SpatialAnchorMSFT' simultaneously, up to some
-- limit imposed by the runtime. The 'OpenXR.Core10.Handles.Space' handle
-- must be eventually freed via the 'OpenXR.Core10.Space.destroySpace'
-- function or by destroying the parent
-- 'OpenXR.Extensions.Handles.SpatialAnchorMSFT' handle.
--
-- == Valid Usage (Implicit)
--
-- -   #VUID-xrCreateSpatialAnchorSpaceMSFT-extension-notenabled# The @@
--     extension /must/ be enabled prior to calling
--     'createSpatialAnchorSpaceMSFT'
--
-- -   #VUID-xrCreateSpatialAnchorSpaceMSFT-session-parameter# @session@
--     /must/ be a valid 'OpenXR.Core10.Handles.Session' handle
--
-- -   #VUID-xrCreateSpatialAnchorSpaceMSFT-createInfo-parameter#
--     @createInfo@ /must/ be a pointer to a valid
--     'SpatialAnchorSpaceCreateInfoMSFT' structure
--
-- -   #VUID-xrCreateSpatialAnchorSpaceMSFT-space-parameter# @space@ /must/
--     be a pointer to an 'OpenXR.Core10.Handles.Space' handle
--
-- == Return Codes
--
-- [<https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#fundamentals-successcodes Success>]
--
--     -   'OpenXR.Core10.Enums.Result.SUCCESS'
--
-- [<https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#fundamentals-errorcodes Failure>]
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_INSTANCE_LOST'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_OUT_OF_MEMORY'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_FUNCTION_UNSUPPORTED'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_VALIDATION_FAILURE'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_HANDLE_INVALID'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_POSE_INVALID'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_SESSION_LOST'
--
--     -   'OpenXR.Core10.Enums.Result.SESSION_LOSS_PENDING'
--
-- = See Also
--
-- 'OpenXR.Core10.Handles.Session', 'OpenXR.Core10.Handles.Space',
-- 'OpenXR.Extensions.Handles.SpatialAnchorMSFT',
-- 'SpatialAnchorSpaceCreateInfoMSFT'
createSpatialAnchorSpaceMSFT :: forall io
                              . (MonadIO io)
                             => -- | @session@ is a handle to an 'OpenXR.Core10.Handles.Session'.
                                Session
                             -> -- | @createInfo@ is a pointer to an 'SpatialAnchorSpaceCreateInfoMSFT'
                                -- structure containing information about how to create the anchor.
                                SpatialAnchorSpaceCreateInfoMSFT
                             -> io (Space)
createSpatialAnchorSpaceMSFT :: Session -> SpatialAnchorSpaceCreateInfoMSFT -> io Space
createSpatialAnchorSpaceMSFT session :: Session
session createInfo :: SpatialAnchorSpaceCreateInfoMSFT
createInfo = IO Space -> io Space
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Space -> io Space)
-> (ContT Space IO Space -> IO Space)
-> ContT Space IO Space
-> io Space
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT Space IO Space -> IO Space
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT Space IO Space -> io Space)
-> ContT Space IO Space -> io Space
forall a b. (a -> b) -> a -> b
$ do
  let cmds :: InstanceCmds
cmds = Session -> InstanceCmds
instanceCmds (Session
session :: Session)
  let xrCreateSpatialAnchorSpaceMSFTPtr :: FunPtr
  (Ptr Session_T
   -> Ptr SpatialAnchorSpaceCreateInfoMSFT
   -> ("space" ::: Ptr (Ptr Space_T))
   -> IO Result)
xrCreateSpatialAnchorSpaceMSFTPtr = InstanceCmds
-> FunPtr
     (Ptr Session_T
      -> Ptr SpatialAnchorSpaceCreateInfoMSFT
      -> ("space" ::: Ptr (Ptr Space_T))
      -> IO Result)
pXrCreateSpatialAnchorSpaceMSFT InstanceCmds
cmds
  IO () -> ContT Space IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT Space IO ()) -> IO () -> ContT Space IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (FunPtr
  (Ptr Session_T
   -> Ptr SpatialAnchorSpaceCreateInfoMSFT
   -> ("space" ::: Ptr (Ptr Space_T))
   -> IO Result)
xrCreateSpatialAnchorSpaceMSFTPtr FunPtr
  (Ptr Session_T
   -> Ptr SpatialAnchorSpaceCreateInfoMSFT
   -> ("space" ::: Ptr (Ptr Space_T))
   -> IO Result)
-> FunPtr
     (Ptr Session_T
      -> Ptr SpatialAnchorSpaceCreateInfoMSFT
      -> ("space" ::: Ptr (Ptr Space_T))
      -> IO Result)
-> Bool
forall a. Eq a => a -> a -> Bool
/= FunPtr
  (Ptr Session_T
   -> Ptr SpatialAnchorSpaceCreateInfoMSFT
   -> ("space" ::: Ptr (Ptr Space_T))
   -> IO Result)
forall a. FunPtr a
nullFunPtr) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
    IOException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (IOException -> IO ()) -> IOException -> IO ()
forall a b. (a -> b) -> a -> b
$ Maybe Handle
-> IOErrorType
-> String
-> String
-> Maybe CInt
-> Maybe String
-> IOException
IOError Maybe Handle
forall a. Maybe a
Nothing IOErrorType
InvalidArgument "" "The function pointer for xrCreateSpatialAnchorSpaceMSFT is null" Maybe CInt
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing
  let xrCreateSpatialAnchorSpaceMSFT' :: Ptr Session_T
-> Ptr SpatialAnchorSpaceCreateInfoMSFT
-> ("space" ::: Ptr (Ptr Space_T))
-> IO Result
xrCreateSpatialAnchorSpaceMSFT' = FunPtr
  (Ptr Session_T
   -> Ptr SpatialAnchorSpaceCreateInfoMSFT
   -> ("space" ::: Ptr (Ptr Space_T))
   -> IO Result)
-> Ptr Session_T
-> Ptr SpatialAnchorSpaceCreateInfoMSFT
-> ("space" ::: Ptr (Ptr Space_T))
-> IO Result
mkXrCreateSpatialAnchorSpaceMSFT FunPtr
  (Ptr Session_T
   -> Ptr SpatialAnchorSpaceCreateInfoMSFT
   -> ("space" ::: Ptr (Ptr Space_T))
   -> IO Result)
xrCreateSpatialAnchorSpaceMSFTPtr
  Ptr SpatialAnchorSpaceCreateInfoMSFT
createInfo' <- ((Ptr SpatialAnchorSpaceCreateInfoMSFT -> IO Space) -> IO Space)
-> ContT Space IO (Ptr SpatialAnchorSpaceCreateInfoMSFT)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr SpatialAnchorSpaceCreateInfoMSFT -> IO Space) -> IO Space)
 -> ContT Space IO (Ptr SpatialAnchorSpaceCreateInfoMSFT))
-> ((Ptr SpatialAnchorSpaceCreateInfoMSFT -> IO Space) -> IO Space)
-> ContT Space IO (Ptr SpatialAnchorSpaceCreateInfoMSFT)
forall a b. (a -> b) -> a -> b
$ SpatialAnchorSpaceCreateInfoMSFT
-> (Ptr SpatialAnchorSpaceCreateInfoMSFT -> IO Space) -> IO Space
forall a b. ToCStruct a => a -> (Ptr a -> IO b) -> IO b
withCStruct (SpatialAnchorSpaceCreateInfoMSFT
createInfo)
  "space" ::: Ptr (Ptr Space_T)
pSpace <- ((("space" ::: Ptr (Ptr Space_T)) -> IO Space) -> IO Space)
-> ContT Space IO ("space" ::: Ptr (Ptr Space_T))
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((("space" ::: Ptr (Ptr Space_T)) -> IO Space) -> IO Space)
 -> ContT Space IO ("space" ::: Ptr (Ptr Space_T)))
-> ((("space" ::: Ptr (Ptr Space_T)) -> IO Space) -> IO Space)
-> ContT Space IO ("space" ::: Ptr (Ptr Space_T))
forall a b. (a -> b) -> a -> b
$ IO ("space" ::: Ptr (Ptr Space_T))
-> (("space" ::: Ptr (Ptr Space_T)) -> IO ())
-> (("space" ::: Ptr (Ptr Space_T)) -> IO Space)
-> IO Space
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (Int -> IO ("space" ::: Ptr (Ptr Space_T))
forall a. Int -> IO (Ptr a)
callocBytes @(Ptr Space_T) 8) ("space" ::: Ptr (Ptr Space_T)) -> IO ()
forall a. Ptr a -> IO ()
free
  Result
r <- IO Result -> ContT Space IO Result
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Result -> ContT Space IO Result)
-> IO Result -> ContT Space IO Result
forall a b. (a -> b) -> a -> b
$ String -> IO Result -> IO Result
forall a. String -> IO a -> IO a
traceAroundEvent "xrCreateSpatialAnchorSpaceMSFT" (Ptr Session_T
-> Ptr SpatialAnchorSpaceCreateInfoMSFT
-> ("space" ::: Ptr (Ptr Space_T))
-> IO Result
xrCreateSpatialAnchorSpaceMSFT' (Session -> Ptr Session_T
sessionHandle (Session
session)) Ptr SpatialAnchorSpaceCreateInfoMSFT
createInfo' ("space" ::: Ptr (Ptr Space_T)
pSpace))
  IO () -> ContT Space IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT Space IO ()) -> IO () -> ContT Space IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r Result -> Result -> Bool
forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (OpenXrException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (Result -> OpenXrException
OpenXrException Result
r))
  Ptr Space_T
space <- IO (Ptr Space_T) -> ContT Space IO (Ptr Space_T)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO (Ptr Space_T) -> ContT Space IO (Ptr Space_T))
-> IO (Ptr Space_T) -> ContT Space IO (Ptr Space_T)
forall a b. (a -> b) -> a -> b
$ ("space" ::: Ptr (Ptr Space_T)) -> IO (Ptr Space_T)
forall a. Storable a => Ptr a -> IO a
peek @(Ptr Space_T) "space" ::: Ptr (Ptr Space_T)
pSpace
  Space -> ContT Space IO Space
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Space -> ContT Space IO Space) -> Space -> ContT Space IO Space
forall a b. (a -> b) -> a -> b
$ (((\h :: Ptr Space_T
h -> Ptr Space_T -> InstanceCmds -> Space
Space Ptr Space_T
h InstanceCmds
cmds ) Ptr Space_T
space))

-- | A convenience wrapper to make a compatible pair of calls to
-- 'createSpatialAnchorSpaceMSFT' and 'destroySpace'
--
-- To ensure that 'destroySpace' is always called: pass
-- 'Control.Exception.bracket' (or the allocate function from your
-- favourite resource management library) as the last argument.
-- To just extract the pair pass '(,)' as the last argument.
--
withSpatialAnchorSpaceMSFT :: forall io r . MonadIO io => Session -> SpatialAnchorSpaceCreateInfoMSFT -> (io Space -> (Space -> io ()) -> r) -> r
withSpatialAnchorSpaceMSFT :: Session
-> SpatialAnchorSpaceCreateInfoMSFT
-> (io Space -> (Space -> io ()) -> r)
-> r
withSpatialAnchorSpaceMSFT session :: Session
session createInfo :: SpatialAnchorSpaceCreateInfoMSFT
createInfo b :: io Space -> (Space -> io ()) -> r
b =
  io Space -> (Space -> io ()) -> r
b (Session -> SpatialAnchorSpaceCreateInfoMSFT -> io Space
forall (io :: * -> *).
MonadIO io =>
Session -> SpatialAnchorSpaceCreateInfoMSFT -> io Space
createSpatialAnchorSpaceMSFT Session
session SpatialAnchorSpaceCreateInfoMSFT
createInfo)
    (\(Space
o0) -> Space -> io ()
forall (io :: * -> *). MonadIO io => Space -> io ()
destroySpace Space
o0)


foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
  unsafe
#endif
  "dynamic" mkXrDestroySpatialAnchorMSFT
  :: FunPtr (Ptr SpatialAnchorMSFT_T -> IO Result) -> Ptr SpatialAnchorMSFT_T -> IO Result

-- | xrDestroySpatialAnchorMSFT - Destroys a spatial anchor
--
-- == Parameter Descriptions
--
-- = Description
--
-- 'OpenXR.Extensions.Handles.SpatialAnchorMSFT' handles are destroyed
-- using 'destroySpatialAnchorMSFT'. By destroying an anchor, the runtime
-- /can/ stop spending resources used to maintain tracking for that
-- anchor’s origin.
--
-- == Valid Usage (Implicit)
--
-- -   #VUID-xrDestroySpatialAnchorMSFT-extension-notenabled# The @@
--     extension /must/ be enabled prior to calling
--     'destroySpatialAnchorMSFT'
--
-- -   #VUID-xrDestroySpatialAnchorMSFT-anchor-parameter# @anchor@ /must/
--     be a valid 'OpenXR.Extensions.Handles.SpatialAnchorMSFT' handle
--
-- == Return Codes
--
-- [<https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#fundamentals-successcodes Success>]
--
--     -   'OpenXR.Core10.Enums.Result.SUCCESS'
--
-- [<https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#fundamentals-errorcodes Failure>]
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_HANDLE_INVALID'
--
--     -   'OpenXR.Core10.Enums.Result.ERROR_FUNCTION_UNSUPPORTED'
--
-- = See Also
--
-- 'OpenXR.Extensions.Handles.SpatialAnchorMSFT', 'createSpatialAnchorMSFT'
destroySpatialAnchorMSFT :: forall io
                          . (MonadIO io)
                         => -- | @anchor@ is a handle to an 'OpenXR.Extensions.Handles.SpatialAnchorMSFT'
                            -- previously created by 'createSpatialAnchorMSFT'.
                            SpatialAnchorMSFT
                         -> io ()
destroySpatialAnchorMSFT :: SpatialAnchorMSFT -> io ()
destroySpatialAnchorMSFT anchor :: SpatialAnchorMSFT
anchor = IO () -> io ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> io ()) -> IO () -> io ()
forall a b. (a -> b) -> a -> b
$ do
  let xrDestroySpatialAnchorMSFTPtr :: FunPtr (Ptr SpatialAnchorMSFT_T -> IO Result)
xrDestroySpatialAnchorMSFTPtr = InstanceCmds -> FunPtr (Ptr SpatialAnchorMSFT_T -> IO Result)
pXrDestroySpatialAnchorMSFT (SpatialAnchorMSFT -> InstanceCmds
instanceCmds (SpatialAnchorMSFT
anchor :: SpatialAnchorMSFT))
  Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (FunPtr (Ptr SpatialAnchorMSFT_T -> IO Result)
xrDestroySpatialAnchorMSFTPtr FunPtr (Ptr SpatialAnchorMSFT_T -> IO Result)
-> FunPtr (Ptr SpatialAnchorMSFT_T -> IO Result) -> Bool
forall a. Eq a => a -> a -> Bool
/= FunPtr (Ptr SpatialAnchorMSFT_T -> IO Result)
forall a. FunPtr a
nullFunPtr) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
    IOException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (IOException -> IO ()) -> IOException -> IO ()
forall a b. (a -> b) -> a -> b
$ Maybe Handle
-> IOErrorType
-> String
-> String
-> Maybe CInt
-> Maybe String
-> IOException
IOError Maybe Handle
forall a. Maybe a
Nothing IOErrorType
InvalidArgument "" "The function pointer for xrDestroySpatialAnchorMSFT is null" Maybe CInt
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing
  let xrDestroySpatialAnchorMSFT' :: Ptr SpatialAnchorMSFT_T -> IO Result
xrDestroySpatialAnchorMSFT' = FunPtr (Ptr SpatialAnchorMSFT_T -> IO Result)
-> Ptr SpatialAnchorMSFT_T -> IO Result
mkXrDestroySpatialAnchorMSFT FunPtr (Ptr SpatialAnchorMSFT_T -> IO Result)
xrDestroySpatialAnchorMSFTPtr
  Result
r <- String -> IO Result -> IO Result
forall a. String -> IO a -> IO a
traceAroundEvent "xrDestroySpatialAnchorMSFT" (Ptr SpatialAnchorMSFT_T -> IO Result
xrDestroySpatialAnchorMSFT' (SpatialAnchorMSFT -> Ptr SpatialAnchorMSFT_T
spatialAnchorMSFTHandle (SpatialAnchorMSFT
anchor)))
  Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r Result -> Result -> Bool
forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (OpenXrException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (Result -> OpenXrException
OpenXrException Result
r))


-- | XrSpatialAnchorCreateInfoMSFT - Information to create a spatial anchor
--
-- == Valid Usage (Implicit)
--
-- -   #VUID-XrSpatialAnchorCreateInfoMSFT-extension-notenabled# The @@
--     extension /must/ be enabled prior to using
--     'SpatialAnchorCreateInfoMSFT'
--
-- -   #VUID-XrSpatialAnchorCreateInfoMSFT-type-type# @type@ /must/ be
--     'OpenXR.Core10.Enums.StructureType.TYPE_SPATIAL_ANCHOR_CREATE_INFO_MSFT'
--
-- -   #VUID-XrSpatialAnchorCreateInfoMSFT-next-next# @next@ /must/ be
--     @NULL@ or a valid pointer to the
--     <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#valid-usage-for-structure-pointer-chains next structure in a structure chain>
--
-- -   #VUID-XrSpatialAnchorCreateInfoMSFT-space-parameter# @space@ /must/
--     be a valid 'OpenXR.Core10.Handles.Space' handle
--
-- = See Also
--
-- 'OpenXR.Core10.Space.Posef', 'OpenXR.Core10.Handles.Space',
-- 'OpenXR.Extensions.Handles.SpatialAnchorMSFT',
-- 'OpenXR.Core10.Enums.StructureType.StructureType',
-- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XrTime >,
-- 'createSpatialAnchorMSFT'
data SpatialAnchorCreateInfoMSFT = SpatialAnchorCreateInfoMSFT
  { -- | @space@ is a handle to the 'OpenXR.Core10.Handles.Space' in which @pose@
    -- is specified.
    SpatialAnchorCreateInfoMSFT -> Ptr Space_T
space :: Ptr Space_T
  , -- | @pose@ is the 'OpenXR.Core10.Space.Posef' within @space@ at @time@ that
    -- specifies the point in the real world used to initialize the new anchor.
    SpatialAnchorCreateInfoMSFT -> Posef
pose :: Posef
  , -- | @time@ is the
    -- <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XrTime >
    -- at which @pose@ will be evaluated within @space@.
    SpatialAnchorCreateInfoMSFT -> Time
time :: Time
  }
  deriving (Typeable)
#if defined(GENERIC_INSTANCES)
deriving instance Generic (SpatialAnchorCreateInfoMSFT)
#endif
deriving instance Show SpatialAnchorCreateInfoMSFT

instance ToCStruct SpatialAnchorCreateInfoMSFT where
  withCStruct :: SpatialAnchorCreateInfoMSFT
-> (Ptr SpatialAnchorCreateInfoMSFT -> IO b) -> IO b
withCStruct x :: SpatialAnchorCreateInfoMSFT
x f :: Ptr SpatialAnchorCreateInfoMSFT -> IO b
f = Int -> Int -> (Ptr SpatialAnchorCreateInfoMSFT -> IO b) -> IO b
forall a b. Int -> Int -> (Ptr a -> IO b) -> IO b
allocaBytesAligned 64 8 ((Ptr SpatialAnchorCreateInfoMSFT -> IO b) -> IO b)
-> (Ptr SpatialAnchorCreateInfoMSFT -> IO b) -> IO b
forall a b. (a -> b) -> a -> b
$ \p :: Ptr SpatialAnchorCreateInfoMSFT
p -> Ptr SpatialAnchorCreateInfoMSFT
-> SpatialAnchorCreateInfoMSFT -> IO b -> IO b
forall a b. ToCStruct a => Ptr a -> a -> IO b -> IO b
pokeCStruct Ptr SpatialAnchorCreateInfoMSFT
p SpatialAnchorCreateInfoMSFT
x (Ptr SpatialAnchorCreateInfoMSFT -> IO b
f Ptr SpatialAnchorCreateInfoMSFT
p)
  pokeCStruct :: Ptr SpatialAnchorCreateInfoMSFT
-> SpatialAnchorCreateInfoMSFT -> IO b -> IO b
pokeCStruct p :: Ptr SpatialAnchorCreateInfoMSFT
p SpatialAnchorCreateInfoMSFT{..} f :: IO b
f = do
    Ptr StructureType -> StructureType -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr SpatialAnchorCreateInfoMSFT
p Ptr SpatialAnchorCreateInfoMSFT -> Int -> Ptr StructureType
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 0 :: Ptr StructureType)) (StructureType
TYPE_SPATIAL_ANCHOR_CREATE_INFO_MSFT)
    Ptr (Ptr ()) -> Ptr () -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr SpatialAnchorCreateInfoMSFT
p Ptr SpatialAnchorCreateInfoMSFT -> Int -> Ptr (Ptr ())
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 8 :: Ptr (Ptr ()))) (Ptr ()
forall a. Ptr a
nullPtr)
    ("space" ::: Ptr (Ptr Space_T)) -> Ptr Space_T -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr SpatialAnchorCreateInfoMSFT
p Ptr SpatialAnchorCreateInfoMSFT
-> Int -> "space" ::: Ptr (Ptr Space_T)
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 16 :: Ptr (Ptr Space_T))) (Ptr Space_T
space)
    Ptr Posef -> Posef -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr SpatialAnchorCreateInfoMSFT
p Ptr SpatialAnchorCreateInfoMSFT -> Int -> Ptr Posef
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 24 :: Ptr Posef)) (Posef
pose)
    Ptr Time -> Time -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr SpatialAnchorCreateInfoMSFT
p Ptr SpatialAnchorCreateInfoMSFT -> Int -> Ptr Time
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 56 :: Ptr Time)) (Time
time)
    IO b
f
  cStructSize :: Int
cStructSize = 64
  cStructAlignment :: Int
cStructAlignment = 8
  pokeZeroCStruct :: Ptr SpatialAnchorCreateInfoMSFT -> IO b -> IO b
pokeZeroCStruct p :: Ptr SpatialAnchorCreateInfoMSFT
p f :: IO b
f = do
    Ptr StructureType -> StructureType -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr SpatialAnchorCreateInfoMSFT
p Ptr SpatialAnchorCreateInfoMSFT -> Int -> Ptr StructureType
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 0 :: Ptr StructureType)) (StructureType
TYPE_SPATIAL_ANCHOR_CREATE_INFO_MSFT)
    Ptr (Ptr ()) -> Ptr () -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr SpatialAnchorCreateInfoMSFT
p Ptr SpatialAnchorCreateInfoMSFT -> Int -> Ptr (Ptr ())
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 8 :: Ptr (Ptr ()))) (Ptr ()
forall a. Ptr a
nullPtr)
    ("space" ::: Ptr (Ptr Space_T)) -> Ptr Space_T -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr SpatialAnchorCreateInfoMSFT
p Ptr SpatialAnchorCreateInfoMSFT
-> Int -> "space" ::: Ptr (Ptr Space_T)
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 16 :: Ptr (Ptr Space_T))) (Ptr Space_T
forall a. Zero a => a
zero)
    Ptr Posef -> Posef -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr SpatialAnchorCreateInfoMSFT
p Ptr SpatialAnchorCreateInfoMSFT -> Int -> Ptr Posef
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 24 :: Ptr Posef)) (Posef
forall a. Zero a => a
zero)
    Ptr Time -> Time -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr SpatialAnchorCreateInfoMSFT
p Ptr SpatialAnchorCreateInfoMSFT -> Int -> Ptr Time
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 56 :: Ptr Time)) (Time
forall a. Zero a => a
zero)
    IO b
f

instance FromCStruct SpatialAnchorCreateInfoMSFT where
  peekCStruct :: Ptr SpatialAnchorCreateInfoMSFT -> IO SpatialAnchorCreateInfoMSFT
peekCStruct p :: Ptr SpatialAnchorCreateInfoMSFT
p = do
    Ptr Space_T
space <- ("space" ::: Ptr (Ptr Space_T)) -> IO (Ptr Space_T)
forall a. Storable a => Ptr a -> IO a
peek @(Ptr Space_T) ((Ptr SpatialAnchorCreateInfoMSFT
p Ptr SpatialAnchorCreateInfoMSFT
-> Int -> "space" ::: Ptr (Ptr Space_T)
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 16 :: Ptr (Ptr Space_T)))
    Posef
pose <- Ptr Posef -> IO Posef
forall a. FromCStruct a => Ptr a -> IO a
peekCStruct @Posef ((Ptr SpatialAnchorCreateInfoMSFT
p Ptr SpatialAnchorCreateInfoMSFT -> Int -> Ptr Posef
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 24 :: Ptr Posef))
    Time
time <- Ptr Time -> IO Time
forall a. Storable a => Ptr a -> IO a
peek @Time ((Ptr SpatialAnchorCreateInfoMSFT
p Ptr SpatialAnchorCreateInfoMSFT -> Int -> Ptr Time
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 56 :: Ptr Time))
    SpatialAnchorCreateInfoMSFT -> IO SpatialAnchorCreateInfoMSFT
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SpatialAnchorCreateInfoMSFT -> IO SpatialAnchorCreateInfoMSFT)
-> SpatialAnchorCreateInfoMSFT -> IO SpatialAnchorCreateInfoMSFT
forall a b. (a -> b) -> a -> b
$ Ptr Space_T -> Posef -> Time -> SpatialAnchorCreateInfoMSFT
SpatialAnchorCreateInfoMSFT
             Ptr Space_T
space Posef
pose Time
time

instance Storable SpatialAnchorCreateInfoMSFT where
  sizeOf :: SpatialAnchorCreateInfoMSFT -> Int
sizeOf ~SpatialAnchorCreateInfoMSFT
_ = 64
  alignment :: SpatialAnchorCreateInfoMSFT -> Int
alignment ~SpatialAnchorCreateInfoMSFT
_ = 8
  peek :: Ptr SpatialAnchorCreateInfoMSFT -> IO SpatialAnchorCreateInfoMSFT
peek = Ptr SpatialAnchorCreateInfoMSFT -> IO SpatialAnchorCreateInfoMSFT
forall a. FromCStruct a => Ptr a -> IO a
peekCStruct
  poke :: Ptr SpatialAnchorCreateInfoMSFT
-> SpatialAnchorCreateInfoMSFT -> IO ()
poke ptr :: Ptr SpatialAnchorCreateInfoMSFT
ptr poked :: SpatialAnchorCreateInfoMSFT
poked = Ptr SpatialAnchorCreateInfoMSFT
-> SpatialAnchorCreateInfoMSFT -> IO () -> IO ()
forall a b. ToCStruct a => Ptr a -> a -> IO b -> IO b
pokeCStruct Ptr SpatialAnchorCreateInfoMSFT
ptr SpatialAnchorCreateInfoMSFT
poked (() -> IO ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())

instance Zero SpatialAnchorCreateInfoMSFT where
  zero :: SpatialAnchorCreateInfoMSFT
zero = Ptr Space_T -> Posef -> Time -> SpatialAnchorCreateInfoMSFT
SpatialAnchorCreateInfoMSFT
           Ptr Space_T
forall a. Zero a => a
zero
           Posef
forall a. Zero a => a
zero
           Time
forall a. Zero a => a
zero


-- | XrSpatialAnchorSpaceCreateInfoMSFT - Information to create a space from
-- a spatial anchor
--
-- == Valid Usage (Implicit)
--
-- -   #VUID-XrSpatialAnchorSpaceCreateInfoMSFT-extension-notenabled# The
--     @@ extension /must/ be enabled prior to using
--     'SpatialAnchorSpaceCreateInfoMSFT'
--
-- -   #VUID-XrSpatialAnchorSpaceCreateInfoMSFT-type-type# @type@ /must/ be
--     'OpenXR.Core10.Enums.StructureType.TYPE_SPATIAL_ANCHOR_SPACE_CREATE_INFO_MSFT'
--
-- -   #VUID-XrSpatialAnchorSpaceCreateInfoMSFT-next-next# @next@ /must/ be
--     @NULL@ or a valid pointer to the
--     <https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#valid-usage-for-structure-pointer-chains next structure in a structure chain>
--
-- -   #VUID-XrSpatialAnchorSpaceCreateInfoMSFT-anchor-parameter# @anchor@
--     /must/ be a valid 'OpenXR.Extensions.Handles.SpatialAnchorMSFT'
--     handle
--
-- = See Also
--
-- 'OpenXR.Core10.Space.Posef', 'OpenXR.Core10.Handles.Space',
-- 'OpenXR.Extensions.Handles.SpatialAnchorMSFT',
-- 'OpenXR.Core10.Enums.StructureType.StructureType',
-- 'createSpatialAnchorSpaceMSFT'
data SpatialAnchorSpaceCreateInfoMSFT = SpatialAnchorSpaceCreateInfoMSFT
  { -- | @anchor@ is a handle to an 'OpenXR.Extensions.Handles.SpatialAnchorMSFT'
    -- previously created with 'createSpatialAnchorMSFT'.
    SpatialAnchorSpaceCreateInfoMSFT -> Ptr SpatialAnchorMSFT_T
anchor :: Ptr SpatialAnchorMSFT_T
  , -- | @poseInAnchorSpace@ is an 'OpenXR.Core10.Space.Posef' defining the
    -- position and orientation of the new space’s origin relative to the
    -- anchor’s natural origin.
    SpatialAnchorSpaceCreateInfoMSFT -> Posef
poseInAnchorSpace :: Posef
  }
  deriving (Typeable)
#if defined(GENERIC_INSTANCES)
deriving instance Generic (SpatialAnchorSpaceCreateInfoMSFT)
#endif
deriving instance Show SpatialAnchorSpaceCreateInfoMSFT

instance ToCStruct SpatialAnchorSpaceCreateInfoMSFT where
  withCStruct :: SpatialAnchorSpaceCreateInfoMSFT
-> (Ptr SpatialAnchorSpaceCreateInfoMSFT -> IO b) -> IO b
withCStruct x :: SpatialAnchorSpaceCreateInfoMSFT
x f :: Ptr SpatialAnchorSpaceCreateInfoMSFT -> IO b
f = Int
-> Int -> (Ptr SpatialAnchorSpaceCreateInfoMSFT -> IO b) -> IO b
forall a b. Int -> Int -> (Ptr a -> IO b) -> IO b
allocaBytesAligned 56 8 ((Ptr SpatialAnchorSpaceCreateInfoMSFT -> IO b) -> IO b)
-> (Ptr SpatialAnchorSpaceCreateInfoMSFT -> IO b) -> IO b
forall a b. (a -> b) -> a -> b
$ \p :: Ptr SpatialAnchorSpaceCreateInfoMSFT
p -> Ptr SpatialAnchorSpaceCreateInfoMSFT
-> SpatialAnchorSpaceCreateInfoMSFT -> IO b -> IO b
forall a b. ToCStruct a => Ptr a -> a -> IO b -> IO b
pokeCStruct Ptr SpatialAnchorSpaceCreateInfoMSFT
p SpatialAnchorSpaceCreateInfoMSFT
x (Ptr SpatialAnchorSpaceCreateInfoMSFT -> IO b
f Ptr SpatialAnchorSpaceCreateInfoMSFT
p)
  pokeCStruct :: Ptr SpatialAnchorSpaceCreateInfoMSFT
-> SpatialAnchorSpaceCreateInfoMSFT -> IO b -> IO b
pokeCStruct p :: Ptr SpatialAnchorSpaceCreateInfoMSFT
p SpatialAnchorSpaceCreateInfoMSFT{..} f :: IO b
f = do
    Ptr StructureType -> StructureType -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr SpatialAnchorSpaceCreateInfoMSFT
p Ptr SpatialAnchorSpaceCreateInfoMSFT -> Int -> Ptr StructureType
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 0 :: Ptr StructureType)) (StructureType
TYPE_SPATIAL_ANCHOR_SPACE_CREATE_INFO_MSFT)
    Ptr (Ptr ()) -> Ptr () -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr SpatialAnchorSpaceCreateInfoMSFT
p Ptr SpatialAnchorSpaceCreateInfoMSFT -> Int -> Ptr (Ptr ())
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 8 :: Ptr (Ptr ()))) (Ptr ()
forall a. Ptr a
nullPtr)
    ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
-> Ptr SpatialAnchorMSFT_T -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr SpatialAnchorSpaceCreateInfoMSFT
p Ptr SpatialAnchorSpaceCreateInfoMSFT
-> Int -> "anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T)
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 16 :: Ptr (Ptr SpatialAnchorMSFT_T))) (Ptr SpatialAnchorMSFT_T
anchor)
    Ptr Posef -> Posef -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr SpatialAnchorSpaceCreateInfoMSFT
p Ptr SpatialAnchorSpaceCreateInfoMSFT -> Int -> Ptr Posef
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 24 :: Ptr Posef)) (Posef
poseInAnchorSpace)
    IO b
f
  cStructSize :: Int
cStructSize = 56
  cStructAlignment :: Int
cStructAlignment = 8
  pokeZeroCStruct :: Ptr SpatialAnchorSpaceCreateInfoMSFT -> IO b -> IO b
pokeZeroCStruct p :: Ptr SpatialAnchorSpaceCreateInfoMSFT
p f :: IO b
f = do
    Ptr StructureType -> StructureType -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr SpatialAnchorSpaceCreateInfoMSFT
p Ptr SpatialAnchorSpaceCreateInfoMSFT -> Int -> Ptr StructureType
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 0 :: Ptr StructureType)) (StructureType
TYPE_SPATIAL_ANCHOR_SPACE_CREATE_INFO_MSFT)
    Ptr (Ptr ()) -> Ptr () -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr SpatialAnchorSpaceCreateInfoMSFT
p Ptr SpatialAnchorSpaceCreateInfoMSFT -> Int -> Ptr (Ptr ())
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 8 :: Ptr (Ptr ()))) (Ptr ()
forall a. Ptr a
nullPtr)
    ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
-> Ptr SpatialAnchorMSFT_T -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr SpatialAnchorSpaceCreateInfoMSFT
p Ptr SpatialAnchorSpaceCreateInfoMSFT
-> Int -> "anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T)
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 16 :: Ptr (Ptr SpatialAnchorMSFT_T))) (Ptr SpatialAnchorMSFT_T
forall a. Zero a => a
zero)
    Ptr Posef -> Posef -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((Ptr SpatialAnchorSpaceCreateInfoMSFT
p Ptr SpatialAnchorSpaceCreateInfoMSFT -> Int -> Ptr Posef
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 24 :: Ptr Posef)) (Posef
forall a. Zero a => a
zero)
    IO b
f

instance FromCStruct SpatialAnchorSpaceCreateInfoMSFT where
  peekCStruct :: Ptr SpatialAnchorSpaceCreateInfoMSFT
-> IO SpatialAnchorSpaceCreateInfoMSFT
peekCStruct p :: Ptr SpatialAnchorSpaceCreateInfoMSFT
p = do
    Ptr SpatialAnchorMSFT_T
anchor <- ("anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T))
-> IO (Ptr SpatialAnchorMSFT_T)
forall a. Storable a => Ptr a -> IO a
peek @(Ptr SpatialAnchorMSFT_T) ((Ptr SpatialAnchorSpaceCreateInfoMSFT
p Ptr SpatialAnchorSpaceCreateInfoMSFT
-> Int -> "anchor" ::: Ptr (Ptr SpatialAnchorMSFT_T)
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 16 :: Ptr (Ptr SpatialAnchorMSFT_T)))
    Posef
poseInAnchorSpace <- Ptr Posef -> IO Posef
forall a. FromCStruct a => Ptr a -> IO a
peekCStruct @Posef ((Ptr SpatialAnchorSpaceCreateInfoMSFT
p Ptr SpatialAnchorSpaceCreateInfoMSFT -> Int -> Ptr Posef
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` 24 :: Ptr Posef))
    SpatialAnchorSpaceCreateInfoMSFT
-> IO SpatialAnchorSpaceCreateInfoMSFT
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SpatialAnchorSpaceCreateInfoMSFT
 -> IO SpatialAnchorSpaceCreateInfoMSFT)
-> SpatialAnchorSpaceCreateInfoMSFT
-> IO SpatialAnchorSpaceCreateInfoMSFT
forall a b. (a -> b) -> a -> b
$ Ptr SpatialAnchorMSFT_T
-> Posef -> SpatialAnchorSpaceCreateInfoMSFT
SpatialAnchorSpaceCreateInfoMSFT
             Ptr SpatialAnchorMSFT_T
anchor Posef
poseInAnchorSpace

instance Storable SpatialAnchorSpaceCreateInfoMSFT where
  sizeOf :: SpatialAnchorSpaceCreateInfoMSFT -> Int
sizeOf ~SpatialAnchorSpaceCreateInfoMSFT
_ = 56
  alignment :: SpatialAnchorSpaceCreateInfoMSFT -> Int
alignment ~SpatialAnchorSpaceCreateInfoMSFT
_ = 8
  peek :: Ptr SpatialAnchorSpaceCreateInfoMSFT
-> IO SpatialAnchorSpaceCreateInfoMSFT
peek = Ptr SpatialAnchorSpaceCreateInfoMSFT
-> IO SpatialAnchorSpaceCreateInfoMSFT
forall a. FromCStruct a => Ptr a -> IO a
peekCStruct
  poke :: Ptr SpatialAnchorSpaceCreateInfoMSFT
-> SpatialAnchorSpaceCreateInfoMSFT -> IO ()
poke ptr :: Ptr SpatialAnchorSpaceCreateInfoMSFT
ptr poked :: SpatialAnchorSpaceCreateInfoMSFT
poked = Ptr SpatialAnchorSpaceCreateInfoMSFT
-> SpatialAnchorSpaceCreateInfoMSFT -> IO () -> IO ()
forall a b. ToCStruct a => Ptr a -> a -> IO b -> IO b
pokeCStruct Ptr SpatialAnchorSpaceCreateInfoMSFT
ptr SpatialAnchorSpaceCreateInfoMSFT
poked (() -> IO ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())

instance Zero SpatialAnchorSpaceCreateInfoMSFT where
  zero :: SpatialAnchorSpaceCreateInfoMSFT
zero = Ptr SpatialAnchorMSFT_T
-> Posef -> SpatialAnchorSpaceCreateInfoMSFT
SpatialAnchorSpaceCreateInfoMSFT
           Ptr SpatialAnchorMSFT_T
forall a. Zero a => a
zero
           Posef
forall a. Zero a => a
zero


type MSFT_spatial_anchor_SPEC_VERSION = 1

-- No documentation found for TopLevel "XR_MSFT_spatial_anchor_SPEC_VERSION"
pattern MSFT_spatial_anchor_SPEC_VERSION :: forall a . Integral a => a
pattern $bMSFT_spatial_anchor_SPEC_VERSION :: a
$mMSFT_spatial_anchor_SPEC_VERSION :: forall r a. Integral a => a -> (Void# -> r) -> (Void# -> r) -> r
MSFT_spatial_anchor_SPEC_VERSION = 1


type MSFT_SPATIAL_ANCHOR_EXTENSION_NAME = "XR_MSFT_spatial_anchor"

-- No documentation found for TopLevel "XR_MSFT_SPATIAL_ANCHOR_EXTENSION_NAME"
pattern MSFT_SPATIAL_ANCHOR_EXTENSION_NAME :: forall a . (Eq a, IsString a) => a
pattern $bMSFT_SPATIAL_ANCHOR_EXTENSION_NAME :: a
$mMSFT_SPATIAL_ANCHOR_EXTENSION_NAME :: forall r a.
(Eq a, IsString a) =>
a -> (Void# -> r) -> (Void# -> r) -> r
MSFT_SPATIAL_ANCHOR_EXTENSION_NAME = "XR_MSFT_spatial_anchor"