SDL_openxr.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2026 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /* WIKI CATEGORY: OpenXR */
  19. /**
  20. * # CategoryOpenXR
  21. *
  22. * Functions for creating OpenXR handles for [GPU API](CategoryGPU) contexts.
  23. *
  24. * For the most part, OpenXR operates independent of SDL, but the graphics
  25. * initialization depends on direct support from the GPU API.
  26. */
  27. #ifndef SDL_openxr_h_
  28. #define SDL_openxr_h_
  29. #include <SDL3/SDL_stdinc.h>
  30. #include <SDL3/SDL_gpu.h>
  31. #include <SDL3/SDL_begin_code.h>
  32. /* Set up for C function definitions, even when using C++ */
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. #ifndef SDL_WIKI_DOCUMENTATION_SECTION
  37. #if defined(OPENXR_H_)
  38. #define NO_SDL_OPENXR_TYPEDEFS 1
  39. #endif /* OPENXR_H_ */
  40. #if !defined(NO_SDL_OPENXR_TYPEDEFS)
  41. #define XR_NULL_HANDLE 0
  42. #if !defined(XR_DEFINE_HANDLE)
  43. #define XR_DEFINE_HANDLE(object) typedef Uint64 object;
  44. #endif /* XR_DEFINE_HANDLE */
  45. typedef enum XrStructureType {
  46. XR_TYPE_SESSION_CREATE_INFO = 8,
  47. XR_TYPE_SWAPCHAIN_CREATE_INFO = 9,
  48. } XrStructureType;
  49. XR_DEFINE_HANDLE(XrInstance)
  50. XR_DEFINE_HANDLE(XrSystemId)
  51. XR_DEFINE_HANDLE(XrSession)
  52. XR_DEFINE_HANDLE(XrSwapchain)
  53. typedef struct {
  54. XrStructureType type;
  55. const void* next;
  56. } XrSessionCreateInfo;
  57. typedef struct {
  58. XrStructureType type;
  59. const void* next;
  60. } XrSwapchainCreateInfo;
  61. typedef enum XrResult {
  62. XR_ERROR_FUNCTION_UNSUPPORTED = -7,
  63. XR_ERROR_HANDLE_INVALID = -12,
  64. } XrResult;
  65. #define PFN_xrGetInstanceProcAddr SDL_FunctionPointer
  66. #endif /* NO_SDL_OPENXR_TYPEDEFS */
  67. #endif /* !SDL_WIKI_DOCUMENTATION_SECTION */
  68. /**
  69. * Creates an OpenXR session.
  70. *
  71. * The OpenXR system ID is pulled from the passed GPU context.
  72. *
  73. * \param device a GPU context.
  74. * \param createinfo the create info for the OpenXR session, sans the system
  75. * ID.
  76. * \param session a pointer filled in with an OpenXR session created for the
  77. * given device.
  78. * \returns the result of the call.
  79. *
  80. * \since This function is available since SDL 3.6.0.
  81. *
  82. * \sa SDL_CreateGPUDeviceWithProperties
  83. */
  84. extern SDL_DECLSPEC XrResult SDLCALL SDL_CreateGPUXRSession(SDL_GPUDevice *device, const XrSessionCreateInfo *createinfo, XrSession *session);
  85. /**
  86. * Queries the GPU device for supported XR swapchain image formats.
  87. *
  88. * The returned pointer should be allocated with SDL_malloc() and will be
  89. * passed to SDL_free().
  90. *
  91. * \param device a GPU context.
  92. * \param session an OpenXR session created for the given device.
  93. * \param num_formats a pointer filled with the number of supported XR
  94. * swapchain formats.
  95. * \returns a 0 terminated array of supported formats or NULL on failure; call
  96. * SDL_GetError() for more information. This should be freed with
  97. * SDL_free() when it is no longer needed.
  98. *
  99. * \since This function is available since SDL 3.6.0.
  100. *
  101. * \sa SDL_CreateGPUXRSwapchain
  102. */
  103. extern SDL_DECLSPEC SDL_GPUTextureFormat * SDLCALL SDL_GetGPUXRSwapchainFormats(SDL_GPUDevice *device, XrSession session, int *num_formats);
  104. /**
  105. * Creates an OpenXR swapchain.
  106. *
  107. * The array returned via `textures` is sized according to
  108. * `xrEnumerateSwapchainImages`, and thus should only be accessed via index
  109. * values returned from `xrAcquireSwapchainImage`.
  110. *
  111. * Applications are still allowed to call `xrEnumerateSwapchainImages` on the
  112. * returned XrSwapchain if they need to get the exact size of the array.
  113. *
  114. * \param device a GPU context.
  115. * \param session an OpenXR session created for the given device.
  116. * \param createinfo the create info for the OpenXR swapchain, sans the
  117. * format.
  118. * \param format a supported format for the OpenXR swapchain.
  119. * \param swapchain a pointer filled in with the created OpenXR swapchain.
  120. * \param textures a pointer filled in with the array of created swapchain
  121. * images.
  122. * \returns the result of the call.
  123. *
  124. * \since This function is available since SDL 3.6.0.
  125. *
  126. * \sa SDL_CreateGPUDeviceWithProperties
  127. * \sa SDL_CreateGPUXRSession
  128. * \sa SDL_GetGPUXRSwapchainFormats
  129. * \sa SDL_DestroyGPUXRSwapchain
  130. */
  131. extern SDL_DECLSPEC XrResult SDLCALL SDL_CreateGPUXRSwapchain(
  132. SDL_GPUDevice *device,
  133. XrSession session,
  134. const XrSwapchainCreateInfo *createinfo,
  135. SDL_GPUTextureFormat format,
  136. XrSwapchain *swapchain,
  137. SDL_GPUTexture ***textures);
  138. /**
  139. * Destroys and OpenXR swapchain previously returned by
  140. * SDL_CreateGPUXRSwapchain.
  141. *
  142. * \param device a GPU context.
  143. * \param swapchain a swapchain previously returned by
  144. * SDL_CreateGPUXRSwapchain.
  145. * \param swapchainImages an array of swapchain images returned by the same
  146. * call to SDL_CreateGPUXRSwapchain.
  147. * \returns the result of the call.
  148. *
  149. * \since This function is available since SDL 3.6.0.
  150. *
  151. * \sa SDL_CreateGPUDeviceWithProperties
  152. * \sa SDL_CreateGPUXRSession
  153. * \sa SDL_CreateGPUXRSwapchain
  154. */
  155. extern SDL_DECLSPEC XrResult SDLCALL SDL_DestroyGPUXRSwapchain(SDL_GPUDevice *device, XrSwapchain swapchain, SDL_GPUTexture **swapchainImages);
  156. /**
  157. * Dynamically load the OpenXR loader.
  158. *
  159. * This can be called at any time.
  160. *
  161. * SDL keeps a reference count of the OpenXR loader, calling this function
  162. * multiple times will increment that count, rather than loading the library
  163. * multiple times.
  164. *
  165. * If not called, this will be implicitly called when creating a GPU device
  166. * with OpenXR.
  167. *
  168. * This function will use the platform default OpenXR loader name, unless the
  169. * `SDL_HINT_OPENXR_LIBRARY` hint is set.
  170. *
  171. * \returns true on success or false on failure; call SDL_GetError() for more
  172. * information.
  173. *
  174. * \threadsafety This function is not thread safe.
  175. *
  176. * \since This function is available since SDL 3.6.0.
  177. *
  178. * \sa SDL_HINT_OPENXR_LIBRARY
  179. */
  180. extern SDL_DECLSPEC bool SDLCALL SDL_OpenXR_LoadLibrary(void);
  181. /**
  182. * Unload the OpenXR loader previously loaded by SDL_OpenXR_LoadLibrary.
  183. *
  184. * SDL keeps a reference count of the OpenXR loader, calling this function
  185. * will decrement that count. Once the reference count reaches zero, the
  186. * library is unloaded.
  187. *
  188. * \threadsafety This function is not thread safe.
  189. *
  190. * \since This function is available since SDL 3.6.0.
  191. */
  192. extern SDL_DECLSPEC void SDLCALL SDL_OpenXR_UnloadLibrary(void);
  193. /**
  194. * Get the address of the `xrGetInstanceProcAddr` function.
  195. *
  196. * This should be called after either calling SDL_OpenXR_LoadLibrary() or
  197. * creating an OpenXR SDL_GPUDevice.
  198. *
  199. * The actual type of the returned function pointer is
  200. * PFN_xrGetInstanceProcAddr, but that isn't always available. You should
  201. * include the OpenXR headers before this header, or cast the return value of
  202. * this function to the correct type.
  203. *
  204. * \returns the function pointer for `xrGetInstanceProcAddr` or NULL on
  205. * failure; call SDL_GetError() for more information.
  206. *
  207. * \since This function is available since SDL 3.6.0.
  208. */
  209. extern SDL_DECLSPEC PFN_xrGetInstanceProcAddr SDLCALL SDL_OpenXR_GetXrGetInstanceProcAddr(void);
  210. /* Ends C function definitions when using C++ */
  211. #ifdef __cplusplus
  212. }
  213. #endif
  214. #include <SDL3/SDL_close_code.h>
  215. #endif /* SDL_openxr_h_ */