Skip to content

Commit

Permalink
OpenXRUtils: implemented GetOpenXRGraphicsBindingGL on Win32
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Dec 9, 2024
1 parent 192ad3e commit 6c08410
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 8 deletions.
5 changes: 4 additions & 1 deletion Graphics/GraphicsEngineOpenGL/include/GLContextWindows.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Diligent Graphics LLC
* Copyright 2019-2024 Diligent Graphics LLC
* Copyright 2015-2019 Egor Yusov
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -44,6 +44,9 @@ class GLContext

NativeGLContextType GetCurrentNativeGLContext();

HGLRC GetHandle() const { return m_Context; }
HDC GetWindowHandleToDeviceContext() const { return m_WindowHandleToDeviceContext; }

private:
HGLRC m_Context = NULL;
HDC m_WindowHandleToDeviceContext = NULL;
Expand Down
2 changes: 1 addition & 1 deletion Graphics/GraphicsEngineOpenGL/include/GLProgramCache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
#include <vector>

#include "GraphicsTypesX.hpp"
#include "GLProgram.hpp"

namespace Diligent
{

class ShaderGLImpl;
class GLProgram;

/// Program cached contains linked programs for the given combination of shaders and resource layouts.
class GLProgramCache
Expand Down
11 changes: 9 additions & 2 deletions Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,26 @@
#include "EngineGLImplTraits.hpp"
#include "RenderDeviceBase.hpp"
#include "GLContext.hpp"
#include "VAOCache.hpp"
#include "BaseInterfacesGL.h"
#include "FBOCache.hpp"
#include "GLProgramCache.hpp"

namespace Diligent
{

class VAOCache;
class FBOCache;

/// Render device implementation in OpenGL backend.
// RenderDeviceGLESImpl is inherited from RenderDeviceGLImpl
class RenderDeviceGLImpl : public RenderDeviceBase<EngineGLImplTraits>
{
public:
using TRenderDeviceBase = RenderDeviceBase<EngineGLImplTraits>;

// {5CC1BE12-9E35-46AB-8B6C-D8544D1DD5E0}
static DILIGENT_CONSTEXPR INTERFACE_ID IID_RenderDeviceGLImpl =
{0x5cc1be12, 0x9e35, 0x46ab, {0x8b, 0x6c, 0xd8, 0x54, 0x4d, 0x1d, 0xd5, 0xe0}};

RenderDeviceGLImpl(IReferenceCounters* pRefCounters,
IMemoryAllocator& RawMemAllocator,
IEngineFactory* pEngineFactory,
Expand Down Expand Up @@ -190,6 +195,8 @@ class RenderDeviceGLImpl : public RenderDeviceBase<EngineGLImplTraits>
RESOURCE_DIMENSION Dimension,
Uint32 SampleCount) const override final;

const GLContext& GetContext() const { return m_GLContext; }

FBOCache& GetFBOCache(GLContext::NativeGLContextType Context);
void OnReleaseTexture(ITexture* pTexture);

Expand Down
1 change: 1 addition & 0 deletions Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@

#include "GLTypeConversions.hpp"
#include "VAOCache.hpp"
#include "FBOCache.hpp"
#include "GraphicsAccessories.hpp"


Expand Down
2 changes: 2 additions & 0 deletions Graphics/GraphicsEngineOpenGL/src/GLProgramCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include "RenderDeviceGLImpl.hpp"
#include "PipelineResourceSignatureGLImpl.hpp"
#include "HashUtils.hpp"
#include "GLProgram.hpp"


namespace Diligent
{
Expand Down
3 changes: 2 additions & 1 deletion Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@

#include "GLTypeConversions.hpp"
#include "VAOCache.hpp"
#include "FBOCache.hpp"
#include "EngineMemory.h"
#include "StringTools.hpp"

Expand Down Expand Up @@ -354,7 +355,7 @@ RenderDeviceGLImpl::~RenderDeviceGLImpl()
{
}

IMPLEMENT_QUERY_INTERFACE(RenderDeviceGLImpl, IID_RenderDeviceGL, TRenderDeviceBase)
IMPLEMENT_QUERY_INTERFACE2(RenderDeviceGLImpl, IID_RenderDeviceGL, IID_RenderDeviceGLImpl, TRenderDeviceBase)

void RenderDeviceGLImpl::CreateBuffer(const BufferDesc& BuffDesc, const BufferData* pBuffData, IBuffer** ppBuffer, bool bIsDeviceInternal)
{
Expand Down
1 change: 1 addition & 0 deletions Graphics/GraphicsEngineOpenGL/src/TextureBaseGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "TextureViewGLImpl.hpp"

#include "GLTypeConversions.hpp"
#include "FBOCache.hpp"
#include "EngineMemory.h"
#include "GraphicsAccessories.hpp"
#include "Align.hpp"
Expand Down
36 changes: 33 additions & 3 deletions Graphics/GraphicsTools/src/OpenXRUtilitiesGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,25 @@
#include "DebugUtilities.hpp"
#include "DataBlobImpl.hpp"

typedef unsigned int GLuint;
typedef int GLint;
typedef unsigned int GLenum;

#if GL_SUPPORTED

# if PLATFORM_WIN32

# include "WinHPreface.h"
# include <Windows.h>
# include <Unknwn.h>
# include "WinHPostface.h"

# include "../../GraphicsEngineOpenGL/include/RenderDeviceGLImpl.hpp"
# include "../../GraphicsEngineOpenGL/include/GLContextWindows.hpp"

# define XR_USE_PLATFORM_WIN32
# endif

# define XR_USE_GRAPHICS_API_OPENGL
# include <openxr/openxr_platform.h>

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

#elif GLES_SUPPORTED

typedef unsigned int EGLenum;

# define XR_USE_GRAPHICS_API_OPENGL_ES
# include <openxr/openxr_platform.h>

Expand All @@ -60,7 +75,22 @@ void GetOpenXRGraphicsBindingGL(IRenderDevice* pDevice,
IDeviceContext* pContext,
IDataBlob** ppGraphicsBinding)
{
UNSUPPORTED("Not yet implemented");
#if GL_SUPPORTED && PLATFORM_WIN32
RefCntAutoPtr<DataBlobImpl> pDataBlob{DataBlobImpl::Create(sizeof(XrGraphicsBindingOpenGLWin32KHR))};

RefCntAutoPtr<RenderDeviceGLImpl> pDeviceGL{pDevice, RenderDeviceGLImpl::IID_RenderDeviceGLImpl};
VERIFY_EXPR(pDeviceGL != nullptr);

XrGraphicsBindingOpenGLWin32KHR& Binding = *reinterpret_cast<XrGraphicsBindingOpenGLWin32KHR*>(pDataBlob->GetDataPtr());
Binding.type = XR_TYPE_GRAPHICS_BINDING_D3D11_KHR;
Binding.next = nullptr;
Binding.hDC = pDeviceGL->GetContext().GetWindowHandleToDeviceContext();
Binding.hGLRC = pDeviceGL->GetContext().GetHandle();

*ppGraphicsBinding = pDataBlob.Detach();
#else
UNEXPECTED("OpenXR GL bindings are not supported on this platform. The application should initialize the bindings manually.");
#endif
}

void AllocateOpenXRSwapchainImageDataGL(Uint32 ImageCount,
Expand Down

0 comments on commit 6c08410

Please sign in to comment.