[Bf-blender-cvs] [34465a7fb09] master: VR: Refactor DirectX context management
Julian Eisel
noreply at git.blender.org
Thu Apr 2 17:44:51 CEST 2020
Commit: 34465a7fb091664b07611353d99dcaa0862d4a4c
Author: Julian Eisel
Date: Thu Apr 2 17:40:29 2020 +0200
Branches: master
https://developer.blender.org/rB34465a7fb091664b07611353d99dcaa0862d4a4c
VR: Refactor DirectX context management
All DirectX management happens on Ghost level now, higher level code can
just assume everything is OpenGL (except of the upside-down drawing that
still needs to be done for DirectX). This is similar to how the
metal-layer is hidden outside of Ghost.
The Ghost-XR graphics binding for DirectX is responsible for managing
the DirectX compatibility now.
===================================================================
M intern/ghost/GHOST_C-api.h
M intern/ghost/GHOST_IContext.h
M intern/ghost/GHOST_ISystem.h
M intern/ghost/GHOST_IXrContext.h
M intern/ghost/GHOST_Types.h
M intern/ghost/intern/GHOST_C-api.cpp
M intern/ghost/intern/GHOST_Context.h
M intern/ghost/intern/GHOST_IXrGraphicsBinding.h
M intern/ghost/intern/GHOST_System.cpp
M intern/ghost/intern/GHOST_System.h
M intern/ghost/intern/GHOST_SystemWin32.cpp
M intern/ghost/intern/GHOST_SystemWin32.h
M intern/ghost/intern/GHOST_XrContext.cpp
M intern/ghost/intern/GHOST_XrContext.h
M intern/ghost/intern/GHOST_XrGraphicsBinding.cpp
M intern/ghost/intern/GHOST_XrSession.cpp
M intern/ghost/intern/GHOST_XrSession.h
M source/blender/windowmanager/WM_api.h
M source/blender/windowmanager/intern/wm_window.c
M source/blender/windowmanager/intern/wm_xr.c
===================================================================
diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h
index aba5b5f733b..4f994f76539 100644
--- a/intern/ghost/GHOST_C-api.h
+++ b/intern/ghost/GHOST_C-api.h
@@ -214,25 +214,6 @@ extern GHOST_ContextHandle GHOST_CreateOpenGLContext(GHOST_SystemHandle systemha
extern GHOST_TSuccess GHOST_DisposeOpenGLContext(GHOST_SystemHandle systemhandle,
GHOST_ContextHandle contexthandle);
-#ifdef WIN32
-/**
- * Create a new offscreen context.
- * Never explicitly delete the context, use disposeContext() instead.
- * \param systemhandle The handle to the system
- * \return A handle to the new context ( == NULL if creation failed).
- */
-GHOST_ContextHandle GHOST_CreateDirectXContext(GHOST_SystemHandle systemhandle);
-
-/**
- * Dispose of a context.
- * \param systemhandle The handle to the system
- * \param contexthandle Handle to the context to be disposed.
- * \return Indication of success.
- */
-GHOST_TSuccess GHOST_DisposeDirectXContext(GHOST_SystemHandle systemhandle,
- GHOST_ContextHandle contexthandle);
-#endif
-
/**
* Returns the window user data.
* \param windowhandle The handle to the window
@@ -1078,6 +1059,13 @@ void GHOST_XrSessionDrawViews(GHOST_XrContextHandle xr_context, void *customdata
*/
int GHOST_XrSessionIsRunning(const GHOST_XrContextHandle xr_context);
+/**
+ * Check if \a xr_context has a session that requrires an upside-down framebuffer (compared to
+ * OpenGL). If true, the render result should be flipped vertically for correct output.
+ * \note: Only to be called after session start, may otherwise result in a false negative.
+ */
+int GHOST_XrSessionNeedsUpsideDownDrawing(const GHOST_XrContextHandle xr_context);
+
/* events */
/**
* Invoke handling of all OpenXR events for \a xr_context. Should be called on every main-loop
diff --git a/intern/ghost/GHOST_IContext.h b/intern/ghost/GHOST_IContext.h
index d404287fe56..1225262a908 100644
--- a/intern/ghost/GHOST_IContext.h
+++ b/intern/ghost/GHOST_IContext.h
@@ -60,11 +60,6 @@ class GHOST_IContext {
virtual GHOST_TSuccess swapBuffers() = 0;
- /**
- * Returns if the window is rendered upside down compared to OpenGL.
- */
- virtual bool isUpsideDown() const = 0;
-
#ifdef WITH_CXX_GUARDEDALLOC
MEM_CXX_CLASS_ALLOC_FUNCS("GHOST:GHOST_IContext")
#endif
diff --git a/intern/ghost/GHOST_ISystem.h b/intern/ghost/GHOST_ISystem.h
index 8adf49fe1f9..58d1a08da74 100644
--- a/intern/ghost/GHOST_ISystem.h
+++ b/intern/ghost/GHOST_ISystem.h
@@ -266,12 +266,6 @@ class GHOST_ISystem {
*/
virtual GHOST_IContext *createOffscreenContext() = 0;
- /**
- * Overload to allow requesting a different context type. By default only OpenGL is supported.
- * However by explicitly overloading this a system may add support for others.
- */
- virtual GHOST_IContext *createOffscreenContext(GHOST_TDrawingContextType type) = 0;
-
/**
* Dispose of a context.
* \param context Pointer to the context to be disposed.
diff --git a/intern/ghost/GHOST_IXrContext.h b/intern/ghost/GHOST_IXrContext.h
index 362bc923ee8..3076de96690 100644
--- a/intern/ghost/GHOST_IXrContext.h
+++ b/intern/ghost/GHOST_IXrContext.h
@@ -37,6 +37,8 @@ class GHOST_IXrContext {
virtual void setGraphicsContextBindFuncs(GHOST_XrGraphicsContextBindFn bind_fn,
GHOST_XrGraphicsContextUnbindFn unbind_fn) = 0;
virtual void setDrawViewFunc(GHOST_XrDrawViewFn draw_view_fn) = 0;
+
+ virtual bool needsUpsideDownDrawing() const = 0;
};
#endif // __GHOST_IXRCONTEXT_H__
diff --git a/intern/ghost/GHOST_Types.h b/intern/ghost/GHOST_Types.h
index 637935d9142..6667d113fe8 100644
--- a/intern/ghost/GHOST_Types.h
+++ b/intern/ghost/GHOST_Types.h
@@ -621,9 +621,8 @@ typedef void (*GHOST_XrErrorHandlerFn)(const struct GHOST_XrError *);
typedef void (*GHOST_XrSessionExitFn)(void *customdata);
-typedef void *(*GHOST_XrGraphicsContextBindFn)(enum GHOST_TXrGraphicsBinding graphics_lib);
-typedef void (*GHOST_XrGraphicsContextUnbindFn)(enum GHOST_TXrGraphicsBinding graphics_lib,
- GHOST_ContextHandle graphics_context);
+typedef void *(*GHOST_XrGraphicsContextBindFn)();
+typedef void (*GHOST_XrGraphicsContextUnbindFn)(GHOST_ContextHandle graphics_context);
typedef void (*GHOST_XrDrawViewFn)(const struct GHOST_XrDrawViewInfo *draw_view, void *customdata);
/* An array of GHOST_TXrGraphicsBinding items defining the candidate bindings to use. The first
diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp
index af2a13945d1..6ee1557122d 100644
--- a/intern/ghost/intern/GHOST_C-api.cpp
+++ b/intern/ghost/intern/GHOST_C-api.cpp
@@ -150,25 +150,6 @@ GHOST_TSuccess GHOST_DisposeOpenGLContext(GHOST_SystemHandle systemhandle,
return system->disposeContext(context);
}
-#ifdef WIN32
-GHOST_ContextHandle GHOST_CreateDirectXContext(GHOST_SystemHandle systemhandle)
-{
- GHOST_ISystem *system = (GHOST_ISystem *)systemhandle;
-
- return (GHOST_ContextHandle)system->createOffscreenContext(GHOST_kDrawingContextTypeD3D);
-}
-
-GHOST_TSuccess GHOST_DisposeDirectXContext(GHOST_SystemHandle systemhandle,
- GHOST_ContextHandle contexthandle)
-{
- GHOST_ISystem *system = (GHOST_ISystem *)systemhandle;
- GHOST_IContext *context = (GHOST_IContext *)contexthandle;
-
- return system->disposeContext(context);
-}
-
-#endif
-
GHOST_WindowHandle GHOST_CreateWindow(GHOST_SystemHandle systemhandle,
const char *title,
GHOST_TInt32 left,
@@ -716,13 +697,6 @@ unsigned int GHOST_GetContextDefaultOpenGLFramebuffer(GHOST_ContextHandle contex
return context->getDefaultFramebuffer();
}
-int GHOST_isUpsideDownContext(GHOST_ContextHandle contexthandle)
-{
- GHOST_IContext *context = (GHOST_IContext *)contexthandle;
-
- return context->isUpsideDown();
-}
-
unsigned int GHOST_GetDefaultOpenGLFramebuffer(GHOST_WindowHandle windowhandle)
{
GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
@@ -991,4 +965,12 @@ void GHOST_XrDrawViewFunc(GHOST_XrContextHandle xr_contexthandle, GHOST_XrDrawVi
GHOST_XR_CAPI_CALL(xr_context->setDrawViewFunc(draw_view_fn), xr_context);
}
+int GHOST_XrSessionNeedsUpsideDownDrawing(const GHOST_XrContextHandle xr_contexthandle)
+{
+ GHOST_IXrContext *xr_context = (GHOST_IXrContext *)xr_contexthandle;
+
+ GHOST_XR_CAPI_CALL_RET(xr_context->needsUpsideDownDrawing(), xr_context);
+ return 0; /* Only reached if exception is thrown. */
+}
+
#endif
diff --git a/intern/ghost/intern/GHOST_Context.h b/intern/ghost/intern/GHOST_Context.h
index 0bd6f63d07e..411a7de5c79 100644
--- a/intern/ghost/intern/GHOST_Context.h
+++ b/intern/ghost/intern/GHOST_Context.h
@@ -120,9 +120,9 @@ class GHOST_Context : public GHOST_IContext {
}
/**
- * Returns if the window is rendered upside down compared to OpenGL.
+ * Returns if the context is rendered upside down compared to OpenGL.
*/
- inline bool isUpsideDown() const
+ virtual inline bool isUpsideDown() const
{
return false;
}
diff --git a/intern/ghost/intern/GHOST_IXrGraphicsBinding.h b/intern/ghost/intern/GHOST_IXrGraphicsBinding.h
index 25281d3d0ba..cddb557d163 100644
--- a/intern/ghost/intern/GHOST_IXrGraphicsBinding.h
+++ b/intern/ghost/intern/GHOST_IXrGraphicsBinding.h
@@ -61,6 +61,7 @@ class GHOST_IXrGraphicsBinding {
uint32_t image_count) = 0;
virtual void submitToSwapchainImage(XrSwapchainImageBaseHeader *swapchain_image,
const GHOST_XrDrawViewInfo *draw_info) = 0;
+ virtual bool needsUpsideDownDrawing(GHOST_Context &ghost_ctx) const = 0;
protected:
/* Use GHOST_XrGraphicsBindingCreateFromType! */
@@ -68,6 +69,6 @@ class GHOST_IXrGraphicsBinding {
};
std::unique_ptr<GHOST_IXrGraphicsBinding> GHOST_XrGraphicsBindingCreateFromType(
- GHOST_TXrGraphicsBinding type);
+ GHOST_TXrGraphicsBinding type, GHOST_Context *ghost_ctx);
#endif /* __GHOST_IXRGRAPHICSBINDING_H__ */
diff --git a/intern/ghost/intern/GHOST_System.cpp b/intern/ghost/intern/GHOST_System.cpp
index 97704435f04..85eb6d58679 100644
--- a/intern/ghost/intern/GHOST_System.cpp
+++ b/intern/ghost/intern/GHOST_System.cpp
@@ -122,16 +122,6 @@ GHOST_TSuccess GHOST_System::disposeWindow(GHOST_IWindow *window)
return success;
}
-GHOST_IContext *GHOST_System::createOffscreenContext(GHOST_TDrawingContextType type)
-{
- switch (type) {
- case GHOST_kDrawingContextTypeOpenGL:
- return createOffscreenContext();
- default:
- return NULL;
- }
-}
-
bool GHOST_System::validWindow(GHOST_IWindow *window)
{
return m_windowManager->getWindowFound(window);
diff --git a/intern/ghost/intern/GHOST_System.h b/intern/ghost/intern/GHOST_System.h
index 2eec6ca43b3..eaaa2ff6ee6 100644
--- a/intern/ghost/intern/GHOST_System.h
+++ b/intern/ghost/intern/GHOST_System.h
@@ -118,12 +118,6 @@ class GHOST_System : public GHOST_ISystem {
*/
virtual GHOST_IContext *createOffscreenContext() = 0;
- /**
- * Overload to allow requesting a different context type. By default only OpenGL is supported.
- * However by explicitly overloading this a system may add support for others.
- */
- GHOST_IContext *createOffscreenContext(GHOST_TDrawingContextType type);
-
/**
* Returns whether a window is valid.
* \param window Pointer to the window to be checked.
diff --git a/intern/ghost/intern/GHOST_SystemWin32.cpp b/intern/ghost/intern/GHOST_SystemWin32.cpp
index e4988d8a0b3..9149d81e32e 100644
--- a/intern/ghost/intern/GHOST_SystemWin32.cpp
+++ b/intern/ghost/intern/GHOST_SystemWin32.cpp
@@ -411,9 +411,9 @@ GHOST_TSuccess GHOST_SystemWin32::disposeContext(GHOST_IContext *context)
* Never explicitly delete the window, use #disposeContext() instead.
* \return The new context (or 0 if creation failed).
*/
-GHOST_IContext *GHOST_SystemWin32::createOffscreenContextD3D()
+GHOST_ContextD3D *GHOST_SystemWin32::createOffscreenContextD3D()
{
- GHOST_Context *context;
+ GHOST_ContextD3D *context;
HWND wnd = CreateWindowA("STATIC",
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list