summaryrefslogtreecommitdiff
path: root/modules/openxr/extensions/openxr_vulkan_extension.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/openxr/extensions/openxr_vulkan_extension.cpp')
-rw-r--r--modules/openxr/extensions/openxr_vulkan_extension.cpp81
1 files changed, 67 insertions, 14 deletions
diff --git a/modules/openxr/extensions/openxr_vulkan_extension.cpp b/modules/openxr/extensions/openxr_vulkan_extension.cpp
index a481c6f979..2608c4ac17 100644
--- a/modules/openxr/extensions/openxr_vulkan_extension.cpp
+++ b/modules/openxr/extensions/openxr_vulkan_extension.cpp
@@ -30,10 +30,11 @@
#include "core/string/print_string.h"
-#include "modules/openxr/extensions/openxr_vulkan_extension.h"
-#include "modules/openxr/openxr_api.h"
-#include "modules/openxr/openxr_util.h"
-#include "servers/rendering/renderer_rd/renderer_storage_rd.h"
+#include "../extensions/openxr_vulkan_extension.h"
+#include "../openxr_api.h"
+#include "../openxr_util.h"
+#include "servers/rendering/renderer_rd/effects/copy_effects.h"
+#include "servers/rendering/renderer_rd/storage_rd/texture_storage.h"
#include "servers/rendering/rendering_server_globals.h"
#include "servers/rendering_server.h"
@@ -325,10 +326,65 @@ bool OpenXRVulkanExtension::get_swapchain_image_data(XrSwapchain p_swapchain, in
*r_swapchain_graphics_data = data;
data->is_multiview = (p_array_size > 1);
- RenderingDevice::DataFormat format = RenderingDevice::DATA_FORMAT_R8G8B8A8_SRGB; // TODO set this based on p_swapchain_format
- RenderingDevice::TextureSamples samples = RenderingDevice::TEXTURE_SAMPLES_1; // TODO set this based on p_sample_count
+ RenderingDevice::DataFormat format = RenderingDevice::DATA_FORMAT_R8G8B8A8_SRGB;
+ RenderingDevice::TextureSamples samples = RenderingDevice::TEXTURE_SAMPLES_1;
uint64_t usage_flags = RenderingDevice::TEXTURE_USAGE_SAMPLING_BIT | RenderingDevice::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT;
+ switch (p_swapchain_format) {
+ case VK_FORMAT_R8G8B8A8_SRGB:
+ // Even though this is an sRGB framebuffer format we're using UNORM here.
+ // The reason here is because Godot does a linear to sRGB conversion while
+ // with the sRGB format, this conversion would be doubled by the hardware.
+ // This also means we're reading the values as is for our preview on screen.
+ // The OpenXR runtime however is still treating this as an sRGB format and
+ // will thus do an sRGB -> Linear conversion as expected.
+ // format = RenderingDevice::DATA_FORMAT_R8G8B8A8_SRGB;
+ format = RenderingDevice::DATA_FORMAT_R8G8B8A8_UNORM;
+ break;
+ case VK_FORMAT_B8G8R8A8_SRGB:
+ // format = RenderingDevice::DATA_FORMAT_B8G8R8A8_SRGB;
+ format = RenderingDevice::DATA_FORMAT_B8G8R8A8_UNORM;
+ break;
+ case VK_FORMAT_R8G8B8A8_UINT:
+ format = RenderingDevice::DATA_FORMAT_R8G8B8A8_UINT;
+ break;
+ case VK_FORMAT_B8G8R8A8_UINT:
+ format = RenderingDevice::DATA_FORMAT_B8G8R8A8_UINT;
+ break;
+ default:
+ // continue with our default value
+ print_line("Unsupported swapchain format ", p_swapchain_format);
+ break;
+ }
+
+ switch (p_sample_count) {
+ case 1:
+ samples = RenderingDevice::TEXTURE_SAMPLES_1;
+ break;
+ case 2:
+ samples = RenderingDevice::TEXTURE_SAMPLES_2;
+ break;
+ case 4:
+ samples = RenderingDevice::TEXTURE_SAMPLES_4;
+ break;
+ case 8:
+ samples = RenderingDevice::TEXTURE_SAMPLES_8;
+ break;
+ case 16:
+ samples = RenderingDevice::TEXTURE_SAMPLES_16;
+ break;
+ case 32:
+ samples = RenderingDevice::TEXTURE_SAMPLES_32;
+ break;
+ case 64:
+ samples = RenderingDevice::TEXTURE_SAMPLES_64;
+ break;
+ default:
+ // continue with our default value
+ print_line("Unsupported sample count ", p_sample_count);
+ break;
+ }
+
Vector<RID> image_rids;
Vector<RID> framebuffers;
@@ -364,7 +420,7 @@ bool OpenXRVulkanExtension::get_swapchain_image_data(XrSwapchain p_swapchain, in
return true;
}
-bool OpenXRVulkanExtension::create_projection_fov(const XrFovf p_fov, double p_z_near, double p_z_far, CameraMatrix &r_camera_matrix) {
+bool OpenXRVulkanExtension::create_projection_fov(const XrFovf p_fov, double p_z_near, double p_z_far, Projection &r_camera_matrix) {
// Even though this is a Vulkan renderer we're using OpenGL coordinate systems
XrMatrix4x4f matrix;
XrMatrix4x4f_CreateProjectionFov(&matrix, GRAPHICS_OPENGL, p_fov, (float)p_z_near, (float)p_z_far);
@@ -382,9 +438,8 @@ bool OpenXRVulkanExtension::copy_render_target_to_image(RID p_from_render_target
SwapchainGraphicsData *data = (SwapchainGraphicsData *)p_swapchain_graphics_data;
ERR_FAIL_NULL_V(data, false);
ERR_FAIL_COND_V(p_from_render_target.is_null(), false);
- ERR_FAIL_NULL_V(RendererStorageRD::base_singleton, false);
- RID source_image = RendererStorageRD::base_singleton->render_target_get_rd_texture(p_from_render_target);
+ RID source_image = RendererRD::TextureStorage::get_singleton()->render_target_get_rd_texture(p_from_render_target);
ERR_FAIL_COND_V(source_image.is_null(), false);
RID depth_image; // TODO implement
@@ -394,11 +449,9 @@ bool OpenXRVulkanExtension::copy_render_target_to_image(RID p_from_render_target
ERR_FAIL_COND_V(fb.is_null(), false);
// Our vulkan extension can only be used in conjunction with our vulkan renderer.
- // We need access to the effects object in order to have access to our copy logic.
- // Breaking all the rules but there is no nice way to do this.
- EffectsRD *effects = RendererStorageRD::base_singleton->get_effects();
- ERR_FAIL_NULL_V(effects, false);
- effects->copy_to_fb_rect(source_image, fb, Rect2i(), false, false, false, false, depth_image, data->is_multiview);
+ RendererRD::CopyEffects *copy_effects = RendererRD::CopyEffects::get_singleton();
+ ERR_FAIL_NULL_V(copy_effects, false);
+ copy_effects->copy_to_fb_rect(source_image, fb, Rect2i(), false, false, false, false, depth_image, data->is_multiview);
return true;
}