Cleanup: OpenXR: Introduce a Direct3D base class.
For the Vulkan/OpenXR code will be shared with the OpenGL-Direct3D bridge. This cleanup separates the OpenGL specifics in its own class. Pull Request: https://projects.blender.org/blender/blender/pulls/137252
This commit is contained in:
@@ -897,7 +897,7 @@ typedef enum GHOST_TXrGraphicsBinding {
|
||||
GHOST_kXrGraphicsOpenGL,
|
||||
GHOST_kXrGraphicsVulkan,
|
||||
# ifdef WIN32
|
||||
GHOST_kXrGraphicsD3D11,
|
||||
GHOST_kXrGraphicsOpenGLD3D11,
|
||||
# endif
|
||||
/* For later */
|
||||
// GHOST_kXrGraphicsVulkan,
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
class GHOST_ContextD3D : public GHOST_Context {
|
||||
/* XR code needs low level graphics data to send to OpenXR. */
|
||||
friend class GHOST_XrGraphicsBindingD3D;
|
||||
friend class GHOST_XrGraphicsBindingOpenGLD3D;
|
||||
|
||||
public:
|
||||
GHOST_ContextD3D(bool stereoVisual, HWND hWnd);
|
||||
|
||||
@@ -394,7 +394,7 @@ static const char *openxr_ext_name_from_wm_gpu_binding(GHOST_TXrGraphicsBinding
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
case GHOST_kXrGraphicsD3D11:
|
||||
case GHOST_kXrGraphicsOpenGLD3D11:
|
||||
return XR_KHR_D3D11_ENABLE_EXTENSION_NAME;
|
||||
#endif
|
||||
case GHOST_kXrGraphicsUnknown:
|
||||
|
||||
@@ -333,16 +333,12 @@ static void ghost_format_to_dx_format(GHOST_TXrSwapchainFormat ghost_format,
|
||||
|
||||
class GHOST_XrGraphicsBindingD3D : public GHOST_IXrGraphicsBinding {
|
||||
public:
|
||||
GHOST_XrGraphicsBindingD3D(GHOST_Context &ghost_ctx)
|
||||
: GHOST_IXrGraphicsBinding(), m_ghost_wgl_ctx(static_cast<GHOST_ContextWGL &>(ghost_ctx))
|
||||
GHOST_XrGraphicsBindingD3D() : GHOST_IXrGraphicsBinding()
|
||||
{
|
||||
m_ghost_d3d_ctx = GHOST_SystemWin32::createOffscreenContextD3D();
|
||||
}
|
||||
~GHOST_XrGraphicsBindingD3D()
|
||||
virtual ~GHOST_XrGraphicsBindingD3D()
|
||||
{
|
||||
if (m_shared_resource) {
|
||||
m_ghost_d3d_ctx->disposeSharedOpenGLResource(m_shared_resource);
|
||||
}
|
||||
if (m_ghost_d3d_ctx) {
|
||||
GHOST_SystemWin32::disposeContextD3D(m_ghost_d3d_ctx);
|
||||
}
|
||||
@@ -464,6 +460,32 @@ class GHOST_XrGraphicsBindingD3D : public GHOST_IXrGraphicsBinding {
|
||||
return base_images;
|
||||
}
|
||||
|
||||
bool needsUpsideDownDrawing(GHOST_Context &) const
|
||||
{
|
||||
return m_ghost_d3d_ctx->isUpsideDown();
|
||||
}
|
||||
|
||||
protected:
|
||||
/** Secondary DirectX 11 context used by OpenXR. */
|
||||
GHOST_ContextD3D *m_ghost_d3d_ctx = nullptr;
|
||||
|
||||
std::list<std::vector<XrSwapchainImageD3D11KHR>> m_image_cache;
|
||||
};
|
||||
|
||||
class GHOST_XrGraphicsBindingOpenGLD3D : public GHOST_XrGraphicsBindingD3D {
|
||||
public:
|
||||
GHOST_XrGraphicsBindingOpenGLD3D(GHOST_Context &ghost_ctx)
|
||||
: GHOST_XrGraphicsBindingD3D(), m_ghost_wgl_ctx(static_cast<GHOST_ContextWGL &>(ghost_ctx))
|
||||
{
|
||||
}
|
||||
~GHOST_XrGraphicsBindingOpenGLD3D()
|
||||
{
|
||||
if (m_shared_resource) {
|
||||
m_ghost_d3d_ctx->disposeSharedOpenGLResource(m_shared_resource);
|
||||
m_shared_resource = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void submitToSwapchainImage(XrSwapchainImageBaseHeader &swapchain_image,
|
||||
const GHOST_XrDrawViewInfo &draw_info) override
|
||||
{
|
||||
@@ -504,20 +526,11 @@ class GHOST_XrGraphicsBindingD3D : public GHOST_IXrGraphicsBinding {
|
||||
# endif
|
||||
}
|
||||
|
||||
bool needsUpsideDownDrawing(GHOST_Context &) const
|
||||
{
|
||||
return m_ghost_d3d_ctx->isUpsideDown();
|
||||
}
|
||||
|
||||
private:
|
||||
/** Primary OpenGL context for Blender to use for drawing. */
|
||||
GHOST_ContextWGL &m_ghost_wgl_ctx;
|
||||
/** Secondary DirectX 11 context to share with OpenGL context. */
|
||||
GHOST_ContextD3D *m_ghost_d3d_ctx = nullptr;
|
||||
/** Handle to shared resource object. */
|
||||
GHOST_SharedOpenGLResource *m_shared_resource = nullptr;
|
||||
|
||||
std::list<std::vector<XrSwapchainImageD3D11KHR>> m_image_cache;
|
||||
};
|
||||
#endif // WIN32
|
||||
|
||||
@@ -532,8 +545,8 @@ std::unique_ptr<GHOST_IXrGraphicsBinding> GHOST_XrGraphicsBindingCreateFromType(
|
||||
return std::make_unique<GHOST_XrGraphicsBindingVulkan>();
|
||||
#endif
|
||||
#ifdef WIN32
|
||||
case GHOST_kXrGraphicsD3D11:
|
||||
return std::make_unique<GHOST_XrGraphicsBindingD3D>(context);
|
||||
case GHOST_kXrGraphicsOpenGLD3D11:
|
||||
return std::make_unique<GHOST_XrGraphicsBindingOpenGLD3D>(context);
|
||||
#endif
|
||||
default:
|
||||
return nullptr;
|
||||
|
||||
@@ -71,7 +71,7 @@ bool wm_xr_init(wmWindowManager *wm)
|
||||
case GPU_BACKEND_OPENGL:
|
||||
gpu_bindings_candidates.append(GHOST_kXrGraphicsOpenGL);
|
||||
# ifdef WIN32
|
||||
gpu_bindings_candidates.append(GHOST_kXrGraphicsD3D11);
|
||||
gpu_bindings_candidates.append(GHOST_kXrGraphicsOpenGLD3D11);
|
||||
# endif
|
||||
break;
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user