Skip to content

Commit 6c08410

Browse files
OpenXRUtils: implemented GetOpenXRGraphicsBindingGL on Win32
1 parent 192ad3e commit 6c08410

File tree

8 files changed

+53
-8
lines changed

8 files changed

+53
-8
lines changed

Graphics/GraphicsEngineOpenGL/include/GLContextWindows.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2022 Diligent Graphics LLC
2+
* Copyright 2019-2024 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -44,6 +44,9 @@ class GLContext
4444

4545
NativeGLContextType GetCurrentNativeGLContext();
4646

47+
HGLRC GetHandle() const { return m_Context; }
48+
HDC GetWindowHandleToDeviceContext() const { return m_WindowHandleToDeviceContext; }
49+
4750
private:
4851
HGLRC m_Context = NULL;
4952
HDC m_WindowHandleToDeviceContext = NULL;

Graphics/GraphicsEngineOpenGL/include/GLProgramCache.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@
3232
#include <vector>
3333

3434
#include "GraphicsTypesX.hpp"
35-
#include "GLProgram.hpp"
3635

3736
namespace Diligent
3837
{
3938

4039
class ShaderGLImpl;
40+
class GLProgram;
4141

4242
/// Program cached contains linked programs for the given combination of shaders and resource layouts.
4343
class GLProgramCache

Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLImpl.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,26 @@
3232
#include "EngineGLImplTraits.hpp"
3333
#include "RenderDeviceBase.hpp"
3434
#include "GLContext.hpp"
35-
#include "VAOCache.hpp"
3635
#include "BaseInterfacesGL.h"
37-
#include "FBOCache.hpp"
3836
#include "GLProgramCache.hpp"
3937

4038
namespace Diligent
4139
{
4240

41+
class VAOCache;
42+
class FBOCache;
43+
4344
/// Render device implementation in OpenGL backend.
4445
// RenderDeviceGLESImpl is inherited from RenderDeviceGLImpl
4546
class RenderDeviceGLImpl : public RenderDeviceBase<EngineGLImplTraits>
4647
{
4748
public:
4849
using TRenderDeviceBase = RenderDeviceBase<EngineGLImplTraits>;
4950

51+
// {5CC1BE12-9E35-46AB-8B6C-D8544D1DD5E0}
52+
static DILIGENT_CONSTEXPR INTERFACE_ID IID_RenderDeviceGLImpl =
53+
{0x5cc1be12, 0x9e35, 0x46ab, {0x8b, 0x6c, 0xd8, 0x54, 0x4d, 0x1d, 0xd5, 0xe0}};
54+
5055
RenderDeviceGLImpl(IReferenceCounters* pRefCounters,
5156
IMemoryAllocator& RawMemAllocator,
5257
IEngineFactory* pEngineFactory,
@@ -190,6 +195,8 @@ class RenderDeviceGLImpl : public RenderDeviceBase<EngineGLImplTraits>
190195
RESOURCE_DIMENSION Dimension,
191196
Uint32 SampleCount) const override final;
192197

198+
const GLContext& GetContext() const { return m_GLContext; }
199+
193200
FBOCache& GetFBOCache(GLContext::NativeGLContextType Context);
194201
void OnReleaseTexture(ITexture* pTexture);
195202

Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252

5353
#include "GLTypeConversions.hpp"
5454
#include "VAOCache.hpp"
55+
#include "FBOCache.hpp"
5556
#include "GraphicsAccessories.hpp"
5657

5758

Graphics/GraphicsEngineOpenGL/src/GLProgramCache.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include "RenderDeviceGLImpl.hpp"
3232
#include "PipelineResourceSignatureGLImpl.hpp"
3333
#include "HashUtils.hpp"
34+
#include "GLProgram.hpp"
35+
3436

3537
namespace Diligent
3638
{

Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050

5151
#include "GLTypeConversions.hpp"
5252
#include "VAOCache.hpp"
53+
#include "FBOCache.hpp"
5354
#include "EngineMemory.h"
5455
#include "StringTools.hpp"
5556

@@ -354,7 +355,7 @@ RenderDeviceGLImpl::~RenderDeviceGLImpl()
354355
{
355356
}
356357

357-
IMPLEMENT_QUERY_INTERFACE(RenderDeviceGLImpl, IID_RenderDeviceGL, TRenderDeviceBase)
358+
IMPLEMENT_QUERY_INTERFACE2(RenderDeviceGLImpl, IID_RenderDeviceGL, IID_RenderDeviceGLImpl, TRenderDeviceBase)
358359

359360
void RenderDeviceGLImpl::CreateBuffer(const BufferDesc& BuffDesc, const BufferData* pBuffData, IBuffer** ppBuffer, bool bIsDeviceInternal)
360361
{

Graphics/GraphicsEngineOpenGL/src/TextureBaseGL.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "TextureViewGLImpl.hpp"
3535

3636
#include "GLTypeConversions.hpp"
37+
#include "FBOCache.hpp"
3738
#include "EngineMemory.h"
3839
#include "GraphicsAccessories.hpp"
3940
#include "Align.hpp"

Graphics/GraphicsTools/src/OpenXRUtilitiesGL.cpp

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,25 @@
2929
#include "DebugUtilities.hpp"
3030
#include "DataBlobImpl.hpp"
3131

32+
typedef unsigned int GLuint;
33+
typedef int GLint;
34+
typedef unsigned int GLenum;
35+
3236
#if GL_SUPPORTED
3337

38+
# if PLATFORM_WIN32
39+
40+
# include "WinHPreface.h"
41+
# include <Windows.h>
42+
# include <Unknwn.h>
43+
# include "WinHPostface.h"
44+
45+
# include "../../GraphicsEngineOpenGL/include/RenderDeviceGLImpl.hpp"
46+
# include "../../GraphicsEngineOpenGL/include/GLContextWindows.hpp"
47+
48+
# define XR_USE_PLATFORM_WIN32
49+
# endif
50+
3451
# define XR_USE_GRAPHICS_API_OPENGL
3552
# include <openxr/openxr_platform.h>
3653

@@ -39,8 +56,6 @@ constexpr XrStructureType XR_TYPE_SWAPCHAIN_IMAGE_GL = XR_TYPE_SWAPCHAIN_IMAGE_O
3956

4057
#elif GLES_SUPPORTED
4158

42-
typedef unsigned int EGLenum;
43-
4459
# define XR_USE_GRAPHICS_API_OPENGL_ES
4560
# include <openxr/openxr_platform.h>
4661

@@ -60,7 +75,22 @@ void GetOpenXRGraphicsBindingGL(IRenderDevice* pDevice,
6075
IDeviceContext* pContext,
6176
IDataBlob** ppGraphicsBinding)
6277
{
63-
UNSUPPORTED("Not yet implemented");
78+
#if GL_SUPPORTED && PLATFORM_WIN32
79+
RefCntAutoPtr<DataBlobImpl> pDataBlob{DataBlobImpl::Create(sizeof(XrGraphicsBindingOpenGLWin32KHR))};
80+
81+
RefCntAutoPtr<RenderDeviceGLImpl> pDeviceGL{pDevice, RenderDeviceGLImpl::IID_RenderDeviceGLImpl};
82+
VERIFY_EXPR(pDeviceGL != nullptr);
83+
84+
XrGraphicsBindingOpenGLWin32KHR& Binding = *reinterpret_cast<XrGraphicsBindingOpenGLWin32KHR*>(pDataBlob->GetDataPtr());
85+
Binding.type = XR_TYPE_GRAPHICS_BINDING_D3D11_KHR;
86+
Binding.next = nullptr;
87+
Binding.hDC = pDeviceGL->GetContext().GetWindowHandleToDeviceContext();
88+
Binding.hGLRC = pDeviceGL->GetContext().GetHandle();
89+
90+
*ppGraphicsBinding = pDataBlob.Detach();
91+
#else
92+
UNEXPECTED("OpenXR GL bindings are not supported on this platform. The application should initialize the bindings manually.");
93+
#endif
6494
}
6595

6696
void AllocateOpenXRSwapchainImageDataGL(Uint32 ImageCount,

0 commit comments

Comments
 (0)