From 5bcc2049300cafcf23a8fdde26da417019198645 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Fern=C3=A1ndez=20Garc=C3=ADa-Boente?= Date: Thu, 2 May 2024 18:39:33 +0200 Subject: [PATCH] Additional color format checks Implemented a utility function to call the SupportsColorFormat check, with additional logging about the selected color format. Ensure that selected color format is supported by the runtime's swapchain. --- app/src/openxr/cpp/DeviceDelegateOpenXR.cpp | 26 +++++++++++++++++++++ app/src/openxr/cpp/DeviceDelegateOpenXR.h | 4 ++++ app/src/openxr/cpp/OpenXRLayers.h | 2 +- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/app/src/openxr/cpp/DeviceDelegateOpenXR.cpp b/app/src/openxr/cpp/DeviceDelegateOpenXR.cpp index 4c4ea6f1c1..60ced8525d 100644 --- a/app/src/openxr/cpp/DeviceDelegateOpenXR.cpp +++ b/app/src/openxr/cpp/DeviceDelegateOpenXR.cpp @@ -1371,6 +1371,30 @@ DeviceDelegateOpenXR::CreateLayerCylinder(const VRLayerSurfacePtr& aMoveLayer) { return layer; } +void DeviceDelegateOpenXR::checkSupportedColorFormats(GLint aInternalFormat) { + ASSERT(m.session); + std::string format; + switch (aInternalFormat) { + case GL_COMPRESSED_SRGB8_ETC2: + format = "GL_COMPRESSED_SRGB8_ETC2"; + break; + case GL_COMPRESSED_RGB8_ETC2: + format = "GL_COMPRESSED_RGB8_ETC2"; + break; + case GL_RGBA8: + format = "GL_RGBA8"; + break; + case GL_SRGB8_ALPHA8: + format = "GL_SRGB8_ALPHA8"; + break; + default: + format = "UNKNOWN"; + } + + VRB_LOG("Checking the %s color format", format.c_str()); + CHECK_MSG(m.SupportsColorFormat(aInternalFormat), "Runtime doesn't support the selected swapChain color format"); +} + VRLayerCubePtr DeviceDelegateOpenXR::CreateLayerCube(int32_t aWidth, int32_t aHeight, GLint aInternalFormat) { @@ -1383,6 +1407,7 @@ DeviceDelegateOpenXR::CreateLayerCube(int32_t aWidth, int32_t aHeight, GLint aIn VRLayerCubePtr layer = VRLayerCube::Create(aWidth, aHeight, aInternalFormat); m.cubeLayer = OpenXRLayerCube::Create(layer, aInternalFormat); if (m.session != XR_NULL_HANDLE) { + checkSupportedColorFormats(aInternalFormat); vrb::RenderContextPtr context = m.context.lock(); m.cubeLayer->Init(m.javaContext->env, m.session, context); } @@ -1602,6 +1627,7 @@ DeviceDelegateOpenXR::EnterVR(const crow::BrowserEGLContext& aEGLContext) { layer->Init(m.javaContext->env, m.session, context); } if (m.cubeLayer) { + checkSupportedColorFormats(m.cubeLayer->GetColorFormat()); m.cubeLayer->Init(m.javaContext->env, m.session, context); } if (m.equirectLayer) { diff --git a/app/src/openxr/cpp/DeviceDelegateOpenXR.h b/app/src/openxr/cpp/DeviceDelegateOpenXR.h index 84c38f611d..02daec1a3f 100644 --- a/app/src/openxr/cpp/DeviceDelegateOpenXR.h +++ b/app/src/openxr/cpp/DeviceDelegateOpenXR.h @@ -73,6 +73,10 @@ class DeviceDelegateOpenXR : public DeviceDelegate { bool IsInVRMode() const; bool ExitApp(); bool ShouldExitRenderLoop() const; + +private: + void checkSupportedColorFormats(GLint aInternalFormat); + protected: struct State; DeviceDelegateOpenXR(State& aState); diff --git a/app/src/openxr/cpp/OpenXRLayers.h b/app/src/openxr/cpp/OpenXRLayers.h index c9f529ce8a..76b335aef3 100644 --- a/app/src/openxr/cpp/OpenXRLayers.h +++ b/app/src/openxr/cpp/OpenXRLayers.h @@ -393,7 +393,7 @@ class OpenXRLayerCube : public OpenXRLayerBase