openxr_opengl_extension.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /**************************************************************************/
  2. /* openxr_opengl_extension.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef OPENXR_OPENGL_EXTENSION_H
  31. #define OPENXR_OPENGL_EXTENSION_H
  32. #ifdef GLES3_ENABLED
  33. #include "../openxr_api.h"
  34. #include "../util.h"
  35. #include "openxr_extension_wrapper.h"
  36. #include "core/templates/vector.h"
  37. #ifdef ANDROID_ENABLED
  38. #define XR_USE_GRAPHICS_API_OPENGL_ES
  39. #include <EGL/egl.h>
  40. #include <EGL/eglext.h>
  41. #include <GLES3/gl3.h>
  42. #include <GLES3/gl3ext.h>
  43. #else
  44. #define XR_USE_GRAPHICS_API_OPENGL
  45. #endif
  46. #ifdef WINDOWS_ENABLED
  47. // Including windows.h here is absolutely evil, we shouldn't be doing this outside of platform
  48. // however due to the way the openxr headers are put together, we have no choice.
  49. #include <windows.h>
  50. #endif
  51. #ifdef X11_ENABLED
  52. #include OPENGL_INCLUDE_H
  53. #define GL_GLEXT_PROTOTYPES 1
  54. #define GL3_PROTOTYPES 1
  55. #include "thirdparty/glad/glad/gl.h"
  56. #include "thirdparty/glad/glad/glx.h"
  57. #include <X11/Xlib.h>
  58. #endif
  59. #ifdef ANDROID_ENABLED
  60. // The jobject type from jni.h is used by openxr_platform.h on Android.
  61. #include <jni.h>
  62. #endif
  63. // Include platform dependent structs.
  64. #include <openxr/openxr_platform.h>
  65. class OpenXROpenGLExtension : public OpenXRGraphicsExtensionWrapper {
  66. public:
  67. virtual HashMap<String, bool *> get_requested_extensions() override;
  68. virtual void on_instance_created(const XrInstance p_instance) override;
  69. virtual void *set_session_create_and_get_next_pointer(void *p_next_pointer) override;
  70. virtual void on_pre_draw_viewport(RID p_render_target) override;
  71. virtual void on_post_draw_viewport(RID p_render_target) override;
  72. virtual void get_usable_swapchain_formats(Vector<int64_t> &p_usable_swap_chains) override;
  73. virtual void get_usable_depth_formats(Vector<int64_t> &p_usable_swap_chains) override;
  74. virtual String get_swapchain_format_name(int64_t p_swapchain_format) const override;
  75. virtual bool get_swapchain_image_data(XrSwapchain p_swapchain, int64_t p_swapchain_format, uint32_t p_width, uint32_t p_height, uint32_t p_sample_count, uint32_t p_array_size, void **r_swapchain_graphics_data) override;
  76. virtual void cleanup_swapchain_graphics_data(void **p_swapchain_graphics_data) override;
  77. virtual bool create_projection_fov(const XrFovf p_fov, double p_z_near, double p_z_far, Projection &r_camera_matrix) override;
  78. virtual RID get_texture(void *p_swapchain_graphics_data, int p_image_index) override;
  79. private:
  80. static OpenXROpenGLExtension *singleton;
  81. #ifdef WIN32
  82. static XrGraphicsBindingOpenGLWin32KHR graphics_binding_gl;
  83. #elif ANDROID_ENABLED
  84. static XrGraphicsBindingOpenGLESAndroidKHR graphics_binding_gl;
  85. #else
  86. static XrGraphicsBindingOpenGLXlibKHR graphics_binding_gl;
  87. #endif
  88. struct SwapchainGraphicsData {
  89. bool is_multiview;
  90. Vector<RID> texture_rids;
  91. };
  92. bool srgb_ext_is_available = true;
  93. bool hw_linear_to_srgb_is_enabled = false;
  94. bool check_graphics_api_support(XrVersion p_desired_version);
  95. #ifdef ANDROID_ENABLED
  96. EXT_PROTO_XRRESULT_FUNC3(xrGetOpenGLESGraphicsRequirementsKHR, (XrInstance), p_instance, (XrSystemId), p_system_id, (XrGraphicsRequirementsOpenGLESKHR *), p_graphics_requirements)
  97. #else
  98. EXT_PROTO_XRRESULT_FUNC3(xrGetOpenGLGraphicsRequirementsKHR, (XrInstance), p_instance, (XrSystemId), p_system_id, (XrGraphicsRequirementsOpenGLKHR *), p_graphics_requirements)
  99. #endif
  100. EXT_PROTO_XRRESULT_FUNC4(xrEnumerateSwapchainImages, (XrSwapchain), p_swapchain, (uint32_t), p_image_capacity_input, (uint32_t *), p_image_count_output, (XrSwapchainImageBaseHeader *), p_images)
  101. };
  102. #endif // GLES3_ENABLED
  103. #endif // OPENXR_OPENGL_EXTENSION_H