[Bf-blender-cvs] [7f1fadba677] soc-2019-openxr: Core XR Support [part 4]: Blender-side changes (+ the remaining bits)

Julian Eisel noreply at git.blender.org
Fri Nov 15 11:29:44 CET 2019


Commit: 7f1fadba67718434efecb7aa2c0aaf8dbea6f042
Author: Julian Eisel
Date:   Tue Nov 5 15:33:16 2019 +0100
Branches: soc-2019-openxr
https://developer.blender.org/rB7f1fadba67718434efecb7aa2c0aaf8dbea6f042

Core XR Support [part 4]: Blender-side changes (+ the remaining bits)

Changes for the higher level, more Blender specific side of the implementation.

Main additions:
* WM-XR: Layer tying Ghost-XR to the Blender specific APIs/data
* wmSurface API: drawable, non-window container (manages Ghost-OpenGL and GPU context)
* DNA/RNA for initial management of VR session settings
* Utility batch & config file for using the Oculus runtime (Windows only)

Differential Revision: https://developer.blender.org/D6193

===================================================================

M	intern/ghost/GHOST_C-api.h
M	intern/ghost/GHOST_IContext.h
M	intern/ghost/GHOST_IWindow.h
M	intern/ghost/intern/GHOST_C-api.cpp
M	intern/ghost/intern/GHOST_Context.cpp
M	intern/ghost/intern/GHOST_Context.h
M	intern/ghost/intern/GHOST_ContextNone.h
M	intern/ghost/intern/GHOST_Window.cpp
M	intern/ghost/intern/GHOST_Window.h
M	source/blender/CMakeLists.txt
M	source/blender/blenkernel/BKE_global.h
M	source/blender/blenkernel/CMakeLists.txt
M	source/blender/blenlib/BLI_math_geom.h
M	source/blender/blenlib/intern/math_geom.c
M	source/blender/blenloader/CMakeLists.txt
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/versioning_280.c
M	source/blender/draw/DRW_engine.h
M	source/blender/draw/intern/draw_manager.c
M	source/blender/editors/include/ED_view3d.h
M	source/blender/editors/space_view3d/view3d_draw.c
M	source/blender/gpu/GPU_shader.h
M	source/blender/gpu/GPU_viewport.h
M	source/blender/gpu/intern/gpu_shader.c
M	source/blender/gpu/intern/gpu_viewport.c
M	source/blender/makesdna/DNA_view3d_types.h
M	source/blender/makesdna/DNA_windowmanager_types.h
A	source/blender/makesdna/DNA_xr_types.h
M	source/blender/makesdna/intern/makesdna.c
M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/intern/CMakeLists.txt
M	source/blender/makesrna/intern/makesrna.c
M	source/blender/makesrna/intern/rna_internal.h
M	source/blender/makesrna/intern/rna_wm.c
A	source/blender/makesrna/intern/rna_xr.c
M	source/blender/windowmanager/CMakeLists.txt
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/intern/wm.c
M	source/blender/windowmanager/intern/wm_draw.c
M	source/blender/windowmanager/intern/wm_init_exit.c
M	source/blender/windowmanager/intern/wm_operators.c
A	source/blender/windowmanager/intern/wm_surface.c
M	source/blender/windowmanager/intern/wm_window.c
A	source/blender/windowmanager/intern/wm_xr.c
M	source/blender/windowmanager/wm.h
A	source/blender/windowmanager/wm_surface.h
M	source/creator/CMakeLists.txt
M	source/creator/creator_args.c
M	tests/python/bl_load_addons.py
M	tests/python/bl_load_py_modules.py

===================================================================

diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h
index 5a1e2a60f4b..fb46e0b2031 100644
--- a/intern/ghost/GHOST_C-api.h
+++ b/intern/ghost/GHOST_C-api.h
@@ -244,6 +244,11 @@ extern void GHOST_SetWindowUserData(GHOST_WindowHandle windowhandle, GHOST_TUser
 
 extern int GHOST_IsDialogWindow(GHOST_WindowHandle windowhandle);
 
+/**
+ * Returns whether a window is rendered upside down compared to OpenGL.
+ */
+extern int GHOST_isUpsideDownWindow(GHOST_WindowHandle windowhandle);
+
 /**
  * Dispose a window.
  * \param systemhandle The handle to the system
@@ -751,6 +756,16 @@ extern GHOST_TSuccess GHOST_ActivateOpenGLContext(GHOST_ContextHandle contexthan
  */
 extern GHOST_TSuccess GHOST_ReleaseOpenGLContext(GHOST_ContextHandle contexthandle);
 
+/**
+ * Get the OpenGL framebuffer handle that serves as a default framebuffer.
+ */
+extern unsigned int GHOST_GetContextDefaultOpenGLFramebuffer(GHOST_ContextHandle contexthandle);
+
+/**
+ * Returns whether a context is rendered upside down compared to OpenGL.
+ */
+extern int GHOST_isUpsideDownContext(GHOST_ContextHandle contexthandle);
+
 /**
  * Get the OpenGL framebuffer handle that serves as a default framebuffer.
  */
diff --git a/intern/ghost/GHOST_IContext.h b/intern/ghost/GHOST_IContext.h
index a341e18ca0a..33422b8e351 100644
--- a/intern/ghost/GHOST_IContext.h
+++ b/intern/ghost/GHOST_IContext.h
@@ -56,6 +56,15 @@ class GHOST_IContext {
    */
   virtual GHOST_TSuccess releaseDrawingContext() = 0;
 
+  virtual unsigned int getDefaultFramebuffer() = 0;
+
+  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_IWindow.h b/intern/ghost/GHOST_IWindow.h
index c19d4bdf6bd..c9187fde231 100644
--- a/intern/ghost/GHOST_IWindow.h
+++ b/intern/ghost/GHOST_IWindow.h
@@ -243,6 +243,11 @@ class GHOST_IWindow {
 
   virtual bool isDialog() const = 0;
 
+  /**
+   * Returns if the window is rendered upside down compared to OpenGL.
+   */
+  virtual bool isUpsideDown() const = 0;
+
   /**
    * Returns the tablet data (pressure etc).
    * \return The tablet data (pressure etc).
diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp
index 6b47d57d4ff..dee9daa34c9 100644
--- a/intern/ghost/intern/GHOST_C-api.cpp
+++ b/intern/ghost/intern/GHOST_C-api.cpp
@@ -224,6 +224,13 @@ int GHOST_IsDialogWindow(GHOST_WindowHandle windowhandle)
   return (int)window->isDialog();
 }
 
+int GHOST_isUpsideDownWindow(GHOST_WindowHandle windowhandle)
+{
+  GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
+
+  return window->isUpsideDown();
+}
+
 GHOST_TSuccess GHOST_DisposeWindow(GHOST_SystemHandle systemhandle,
                                    GHOST_WindowHandle windowhandle)
 {
@@ -702,6 +709,20 @@ GHOST_TSuccess GHOST_ReleaseOpenGLContext(GHOST_ContextHandle contexthandle)
   return context->releaseDrawingContext();
 }
 
+unsigned int GHOST_GetContextDefaultOpenGLFramebuffer(GHOST_ContextHandle contexthandle)
+{
+  GHOST_IContext *context = (GHOST_IContext *)contexthandle;
+
+  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;
diff --git a/intern/ghost/intern/GHOST_Context.cpp b/intern/ghost/intern/GHOST_Context.cpp
index 0d167209909..c0f6b39a1d3 100644
--- a/intern/ghost/intern/GHOST_Context.cpp
+++ b/intern/ghost/intern/GHOST_Context.cpp
@@ -149,3 +149,4 @@ void GHOST_Context::initClearGL()
   glClear(GL_COLOR_BUFFER_BIT);
   glClearColor(0.000, 0.000, 0.000, 0.000);
 }
+
diff --git a/intern/ghost/intern/GHOST_Context.h b/intern/ghost/intern/GHOST_Context.h
index bbf6d6a510d..b8372dd7bc3 100644
--- a/intern/ghost/intern/GHOST_Context.h
+++ b/intern/ghost/intern/GHOST_Context.h
@@ -38,7 +38,8 @@ class GHOST_Context : public GHOST_IContext {
    * Constructor.
    * \param stereoVisual      Stereo visual for quad buffered stereo.
    */
-  GHOST_Context(bool stereoVisual) : m_stereoVisual(stereoVisual)
+  GHOST_Context(bool stereoVisual)
+      : m_stereoVisual(stereoVisual)
   {
   }
 
@@ -119,6 +120,14 @@ class GHOST_Context : public GHOST_IContext {
     return m_stereoVisual;
   }
 
+  /**
+   * Returns if the window is rendered upside down compared to OpenGL.
+   */
+  inline bool isUpsideDown() const
+  {
+    return false;
+  }
+
   /**
    * Gets the OpenGL framebuffer associated with the OpenGL context
    * \return The ID of an OpenGL framebuffer object.
diff --git a/intern/ghost/intern/GHOST_ContextNone.h b/intern/ghost/intern/GHOST_ContextNone.h
index 2a3c08701b4..42820f0e243 100644
--- a/intern/ghost/intern/GHOST_ContextNone.h
+++ b/intern/ghost/intern/GHOST_ContextNone.h
@@ -30,7 +30,8 @@
 
 class GHOST_ContextNone : public GHOST_Context {
  public:
-  GHOST_ContextNone(bool stereoVisual) : GHOST_Context(stereoVisual), m_swapInterval(1)
+  GHOST_ContextNone(bool stereoVisual)
+      : GHOST_Context(stereoVisual), m_swapInterval(1)
   {
   }
 
diff --git a/intern/ghost/intern/GHOST_Window.cpp b/intern/ghost/intern/GHOST_Window.cpp
index ca19e251279..cc4f871ea26 100644
--- a/intern/ghost/intern/GHOST_Window.cpp
+++ b/intern/ghost/intern/GHOST_Window.cpp
@@ -114,6 +114,11 @@ unsigned int GHOST_Window::getDefaultFramebuffer()
   return (m_context) ? m_context->getDefaultFramebuffer() : 0;
 }
 
+bool GHOST_Window::isUpsideDown() const
+{
+  return m_context->isUpsideDown();
+}
+
 GHOST_TSuccess GHOST_Window::activateDrawingContext()
 {
   return m_context->activateDrawingContext();
diff --git a/intern/ghost/intern/GHOST_Window.h b/intern/ghost/intern/GHOST_Window.h
index 553a7d89df4..b94b6caed6c 100644
--- a/intern/ghost/intern/GHOST_Window.h
+++ b/intern/ghost/intern/GHOST_Window.h
@@ -284,6 +284,11 @@ class GHOST_Window : public GHOST_IWindow {
     m_userData = userData;
   }
 
+  /**
+   * Returns if the window is rendered upside down compared to OpenGL.
+   */
+  bool isUpsideDown() const;
+
   float getNativePixelSize(void)
   {
     if (m_nativePixelSize > 0.0f)
diff --git a/source/blender/CMakeLists.txt b/source/blender/CMakeLists.txt
index 203543b0ef0..a9d42a1764d 100644
--- a/source/blender/CMakeLists.txt
+++ b/source/blender/CMakeLists.txt
@@ -89,6 +89,7 @@ set(SRC_DNA_INC
   ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_windowmanager_types.h
   ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_workspace_types.h
   ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_world_types.h
+  ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_xr_types.h
 )
 
 add_subdirectory(datatoc)
diff --git a/source/blender/blenkernel/BKE_global.h b/source/blender/blenkernel/BKE_global.h
index bee76c09cbc..de875457b2e 100644
--- a/source/blender/blenkernel/BKE_global.h
+++ b/source/blender/blenkernel/BKE_global.h
@@ -151,6 +151,8 @@ enum {
   G_DEBUG_IO = (1 << 17),                    /* IO Debugging (for Collada, ...)*/
   G_DEBUG_GPU_SHADERS = (1 << 18),           /* GLSL shaders */
   G_DEBUG_GPU_FORCE_WORKAROUNDS = (1 << 19), /* force gpu workarounds bypassing detections. */
+  G_DEBUG_XR = (1 << 20),                    /* XR/OpenXR messages */
+  G_DEBUG_XR_TIME = (1 << 21),               /* XR/OpenXR timing messages */
 };
 
 #define G_DEBUG_ALL \
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 023980292fa..4574b70e4f0 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -646,6 +646,10 @@ if(WITH_TBB)
   )
 endif()
 
+if(WITH_OPENXR)
+  add_definitions(-DWITH_OPENXR)
+endif()
+
 # # Warnings as errors, this is too strict!
 # if(MSVC)
 #    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX")
diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h
index eec5d214473..2128b0a4711 100644
--- a/source/blender/blenlib/BLI_math_geom.h
+++ b/source/blender/blenlib/BLI_math_geom.h
@@ -633,6 +633,13 @@ void perspective_m4(float mat[4][4],
                     const float top,
                     const float nearClip,
                     const float farClip);
+void perspective_m4_fov(float mat[4][4],
+                        const float angle_left,
+                        const float angle_right,
+                        const float angle_up,
+                        const float angle_down,
+                        const float nearClip,
+                        const float farClip);
 void orthographic_m4(float mat[4][4],
                      const float left,
                      const float right,
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index 6d8193e7675..2c72db4ec8d 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -4655,6 +4655,25 @@ void perspective_m4(float mat[4][4],
       mat[3][3] = 0.0f;
 }
 
+void perspective_m4_fov(float mat[4][4],
+                        const float angle_left,
+                        const float angle_right,
+                        const float angle_up,
+                        const float angle_down,
+                        const float nearClip,
+                        const float farClip)
+{
+  const float tan_angle_left = tanf(angle_left);
+  const float tan_angle_right = tanf(angle_right);
+  const float tan_angle_bottom = tanf(angle_up);
+  const float tan_angle_top = tanf(angle_down);
+
+  perspective_m4(
+      mat, tan_angle_left, tan_angle_right, tan_angle_top, tan_angle_bottom, nearClip, farClip);
+  mat[0][0] /= nearClip;
+  mat[1][1] /= nearClip;
+}
+
 /* translate a matrix created by orthographic_m4 or perspective_m4 in XY coords
  * (used to jitter the view) */
 void window_translate_m4(float winmat[4][4], float perspmat[4][4], const float x, const float y)
diff --git a/source/blender/blenloader/CMakeLists.txt b/source/blender/blenloader/CMakeLists.txt
index 1520c7b8

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list