Skip to content

Commit 8e23c8a

Browse files
Enabled OpenXR on GLES/Android
1 parent e31d2af commit 8e23c8a

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

Graphics/GraphicsEngineOpenGL/include/GLContextAndroid.hpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,26 @@
2727

2828
#pragma once
2929

30+
#include <memory>
31+
3032
#include <EGL/egl.h>
3133
#include <android/native_window.h>
3234

3335
namespace Diligent
3436
{
3537

38+
struct EngineGLCreateInfo;
39+
struct OpenXRAttribs;
40+
3641
class GLContext
3742
{
3843
public:
3944
using NativeGLContextType = EGLContext;
4045

41-
GLContext(const struct EngineGLCreateInfo& InitAttribs,
42-
RENDER_DEVICE_TYPE& DevType,
43-
struct Version& APIVersion,
44-
const struct SwapChainDesc* pSCDesc);
46+
GLContext(const EngineGLCreateInfo& InitAttribs,
47+
RENDER_DEVICE_TYPE& DevType,
48+
struct Version& APIVersion,
49+
const struct SwapChainDesc* pSCDesc);
4550
~GLContext();
4651

4752
bool Init(ANativeWindow* window);
@@ -68,6 +73,10 @@ class GLContext
6873
EGLContext context_ = EGL_NO_CONTEXT;
6974
EGLConfig config_;
7075

76+
#if DILIGENT_USE_OPENXR
77+
std::unique_ptr<OpenXRAttribs> openxr_attribs_;
78+
#endif
79+
7180
EGLint egl_major_version_ = 0;
7281
EGLint egl_minor_version_ = 0;
7382

Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232

3333
#include "GLContextAndroid.hpp"
3434

35+
#if DILIGENT_USE_OPENXR
36+
# include "OpenXR_GLHelpers.hpp"
37+
#endif
38+
3539
#ifndef EGL_CONTEXT_MINOR_VERSION_KHR
3640
# define EGL_CONTEXT_MINOR_VERSION_KHR 0x30FB
3741
#endif
@@ -150,6 +154,14 @@ bool GLContext::InitEGLSurface()
150154

151155
bool GLContext::InitEGLContext()
152156
{
157+
#if DILIGENT_USE_OPENXR
158+
Version OpenXRRequiredGLESVersion;
159+
if (openxr_attribs_)
160+
{
161+
OpenXRRequiredGLESVersion = GetOpenXRRequiredGLVersion(openxr_attribs_.get());
162+
}
163+
#endif
164+
153165
std::pair<int, int> es_versions[] = {{3, 2}, {3, 1}, {3, 0}};
154166
for (size_t i = 0; i < _countof(es_versions) && context_ == EGL_NO_CONTEXT; ++i)
155167
{
@@ -192,6 +204,14 @@ bool GLContext::InitEGLContext()
192204
LOG_ERROR_AND_THROW("Failed to create EGLContext");
193205
}
194206

207+
#if DILIGENT_USE_OPENXR
208+
if (openxr_attribs_ && OpenXRRequiredGLESVersion > Version{static_cast<Uint32>(major_version_), static_cast<Uint32>(minor_version_)})
209+
{
210+
LOG_ERROR("OpenGLES version ", major_version_, '.', minor_version_, " does not meet minimum required version for OpenXR: ",
211+
OpenXRRequiredGLESVersion.Major, '.', OpenXRRequiredGLESVersion.Minor);
212+
}
213+
#endif
214+
195215
if (eglMakeCurrent(display_, surface_, surface_, context_) == EGL_FALSE)
196216
{
197217
LOG_ERROR_AND_THROW("Unable to eglMakeCurrent");
@@ -288,6 +308,13 @@ GLContext::GLContext(const EngineGLCreateInfo& InitAttribs,
288308
gles_initialized_(false),
289309
egl_context_initialized_(false)
290310
{
311+
#if DILIGENT_USE_OPENXR
312+
if (InitAttribs.pXRAttribs != nullptr && InitAttribs.pXRAttribs->Instance != 0)
313+
{
314+
openxr_attribs_ = std::make_unique<OpenXRAttribs>(*InitAttribs.pXRAttribs);
315+
}
316+
#endif
317+
291318
auto* NativeWindow = reinterpret_cast<ANativeWindow*>(InitAttribs.Window.pAWindow);
292319
Init(NativeWindow);
293320

ThirdParty/OpenXR-SDK/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ set(BUILD_TESTS OFF)
77
set(BUILD_API_LAYERS ON)
88
FetchContent_Declare(
99
OpenXR
10-
URL_HASH MD5=924a94a2da0b5ef8e82154c623d88644
1110
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
1211
URL https://github.com/KhronosGroup/OpenXR-SDK-Source/archive/refs/tags/release-1.0.34.zip
1312
)

0 commit comments

Comments
 (0)