From 1a543cb0c031b93a5ac50519338093ed29d77129 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Mon, 11 Sep 2023 19:05:51 +0100 Subject: [PATCH] a/ogl: Add Vulkan to OpenGL conversion function --- src/xrt/auxiliary/ogl/CMakeLists.txt | 4 ++-- src/xrt/auxiliary/ogl/ogl_helpers.c | 33 ++++++++++++++++++++++++++++ src/xrt/auxiliary/ogl/ogl_helpers.h | 11 ++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/xrt/auxiliary/ogl/CMakeLists.txt b/src/xrt/auxiliary/ogl/CMakeLists.txt index bc78e518e..59730061e 100644 --- a/src/xrt/auxiliary/ogl/CMakeLists.txt +++ b/src/xrt/auxiliary/ogl/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright 2019-2022, Collabora, Ltd. +# Copyright 2019-2023, Collabora, Ltd. # SPDX-License-Identifier: BSL-1.0 add_library( @@ -9,7 +9,7 @@ add_library( ogl_helpers.c ogl_helpers.h ) -target_link_libraries(aux_ogl PUBLIC aux-includes xrt-external-glad) +target_link_libraries(aux_ogl PUBLIC aux-includes xrt-external-glad aux_util) if(XRT_HAVE_OPENGL_GLX AND XRT_HAVE_XLIB) target_sources(aux_ogl PRIVATE glx_api.c glx_api.h) diff --git a/src/xrt/auxiliary/ogl/ogl_helpers.c b/src/xrt/auxiliary/ogl/ogl_helpers.c index 7529a63e6..dd4c205f2 100644 --- a/src/xrt/auxiliary/ogl/ogl_helpers.c +++ b/src/xrt/auxiliary/ogl/ogl_helpers.c @@ -7,9 +7,14 @@ * @ingroup aux_ogl */ +#include "util/u_logging.h" + #include "ogl_helpers.h" #include "ogl_api.h" +#include + + void ogl_texture_target_for_swapchain_info(const struct xrt_swapchain_create_info *info, uint32_t *out_tex_target, @@ -39,3 +44,31 @@ ogl_texture_target_for_swapchain_info(const struct xrt_swapchain_create_info *in *out_tex_target = GL_TEXTURE_2D; *out_tex_param_name = GL_TEXTURE_BINDING_2D; } + +XRT_CHECK_RESULT uint32_t +ogl_vk_format_to_gl(int64_t vk_format) +{ + switch (vk_format) { + case 4 /* VK_FORMAT_R5G6B5_UNORM_PACK16 */: return 0; // GL_RGB565? + case 23 /* VK_FORMAT_R8G8B8_UNORM */: return GL_RGB8; // Should not be used, colour precision. + case 29 /* VK_FORMAT_R8G8B8_SRGB */: return GL_SRGB8; + case 30 /* VK_FORMAT_B8G8R8_UNORM */: return 0; + case 37 /* VK_FORMAT_R8G8B8A8_UNORM */: return GL_RGBA8; // Should not be used, colour precision. + case 43 /* VK_FORMAT_R8G8B8A8_SRGB */: return GL_SRGB8_ALPHA8; + case 44 /* VK_FORMAT_B8G8R8A8_UNORM */: return 0; + case 50 /* VK_FORMAT_B8G8R8A8_SRGB */: return 0; + case 64 /* VK_FORMAT_A2B10G10R10_UNORM_PACK32 */: return GL_RGB10_A2; + case 84 /* VK_FORMAT_R16G16B16_UNORM */: return GL_RGB16; + case 90 /* VK_FORMAT_R16G16B16_SFLOAT */: return GL_RGB16F; + case 91 /* VK_FORMAT_R16G16B16A16_UNORM */: return GL_RGBA16; + case 97 /* VK_FORMAT_R16G16B16A16_SFLOAT */: return GL_RGBA16F; + case 100 /* VK_FORMAT_R32_SFLOAT */: return 0; + case 124 /* VK_FORMAT_D16_UNORM */: return GL_DEPTH_COMPONENT16; + case 125 /* VK_FORMAT_X8_D24_UNORM_PACK32 */: return 0; // GL_DEPTH_COMPONENT24? + case 126 /* VK_FORMAT_D32_SFLOAT */: return GL_DEPTH_COMPONENT32F; + case 127 /* VK_FORMAT_S8_UINT */: return 0; // GL_STENCIL_INDEX8? + case 129 /* VK_FORMAT_D24_UNORM_S8_UINT */: return GL_DEPTH24_STENCIL8; + case 130 /* VK_FORMAT_D32_SFLOAT_S8_UINT */: return GL_DEPTH32F_STENCIL8; + default: U_LOG_W("Cannot convert VK format %" PRIu64 " to GL format!", vk_format); return 0; + } +} diff --git a/src/xrt/auxiliary/ogl/ogl_helpers.h b/src/xrt/auxiliary/ogl/ogl_helpers.h index 753081383..b6bf6b4af 100644 --- a/src/xrt/auxiliary/ogl/ogl_helpers.h +++ b/src/xrt/auxiliary/ogl/ogl_helpers.h @@ -4,6 +4,7 @@ * @file * @brief Common OpenGL code header. * @author Ryan Pavlik + * @author Jakob Bornecrantz * @ingroup aux_ogl */ @@ -26,6 +27,16 @@ ogl_texture_target_for_swapchain_info(const struct xrt_swapchain_create_info *in uint32_t *out_tex_target, uint32_t *out_tex_param_name); +/*! + * Converts a Vulkan format to corresponding OpenGL format, + * will return 0 if no mapping exist for the given format. + * + * @ingroup aux_ogl + */ +XRT_CHECK_RESULT uint32_t +ogl_vk_format_to_gl(int64_t vk_format); + + #ifdef __cplusplus } #endif