[Bf-blender-cvs] [084a33ca94c] soc-2019-openxr: Use base pose from Blender camera

Julian Eisel noreply at git.blender.org
Mon Jul 8 14:13:54 CEST 2019


Commit: 084a33ca94c09f6c5e6650ee4f3c176b324e6607
Author: Julian Eisel
Date:   Sun Jul 7 14:54:18 2019 +0200
Branches: soc-2019-openxr
https://developer.blender.org/rB084a33ca94c09f6c5e6650ee4f3c176b324e6607

Use base pose from Blender camera

I was trying to set the camera pose as OpenXR reference pose. But then I
got really strange poses for drawing back from OpenXR. Couldn't figure
out a way to solve this.
Now we just apply OpenXR's draw pose to the Blender camera pose. If we
later want to support moving around in the scene (e.g. via teleporting),
that has to be changed.

Also uses flipped drawing for DirectX surface to correct DirectX upside
down drawing (compared to OpenGL).

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

M	intern/ghost/GHOST_C-api.h
M	intern/ghost/GHOST_IContext.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_Xr.cpp
M	intern/ghost/intern/GHOST_XrSession.cpp
M	intern/ghost/intern/GHOST_XrSession.h
M	source/blender/windowmanager/intern/wm_draw.c
M	source/blender/windowmanager/intern/wm_operators.c
M	source/blender/windowmanager/intern/wm_xr.c
M	source/blender/windowmanager/wm.h

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

diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h
index e0d951885b5..7d67a7b37a8 100644
--- a/intern/ghost/GHOST_C-api.h
+++ b/intern/ghost/GHOST_C-api.h
@@ -738,6 +738,11 @@ extern GHOST_TSuccess GHOST_ReleaseOpenGLContext(GHOST_ContextHandle contexthand
  */
 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.
  */
@@ -987,7 +992,8 @@ void GHOST_XrDrawViewFunc(struct GHOST_XrContext *xr_context, GHOST_XrDrawViewFn
 
 /* sessions */
 GHOST_TSuccess GHOST_XrSessionIsRunning(const struct GHOST_XrContext *xr_context);
-void GHOST_XrSessionStart(struct GHOST_XrContext *xr_context);
+void GHOST_XrSessionStart(struct GHOST_XrContext *xr_context,
+                          const GHOST_XrSessionBeginInfo *begin_info);
 void GHOST_XrSessionEnd(struct GHOST_XrContext *xr_context);
 void GHOST_XrSessionDrawViews(struct GHOST_XrContext *xr_context, void *customdata);
 
diff --git a/intern/ghost/GHOST_IContext.h b/intern/ghost/GHOST_IContext.h
index cb6eb5fc76b..3bad8db115f 100644
--- a/intern/ghost/GHOST_IContext.h
+++ b/intern/ghost/GHOST_IContext.h
@@ -64,6 +64,8 @@ class GHOST_IContext {
 
   virtual GHOST_TSuccess swapBuffers() = 0;
 
+  virtual bool isUpsideDown() const = 0;
+
 #ifdef WITH_CXX_GUARDEDALLOC
   MEM_CXX_CLASS_ALLOC_FUNCS("GHOST:GHOST_IContext")
 #endif
diff --git a/intern/ghost/GHOST_Types.h b/intern/ghost/GHOST_Types.h
index 89bab0987a7..c22abda60bb 100644
--- a/intern/ghost/GHOST_Types.h
+++ b/intern/ghost/GHOST_Types.h
@@ -582,16 +582,20 @@ typedef enum {
  * available candidate will be chosen, so order defines priority. */
 typedef const GHOST_TXrGraphicsBinding *GHOST_XrGraphicsBindingCandidates;
 
+typedef struct {
+  float position[3];
+  /* Blender convention (w, x, y, z) */
+  float orientation_quat[4];
+} GHOST_XrPose;
+
 typedef struct {
   const GHOST_XrGraphicsBindingCandidates gpu_binding_candidates;
   unsigned int gpu_binding_candidates_count;
 } GHOST_XrContextCreateInfo;
 
 typedef struct {
-  float position[3];
-  /* Blender convention (w, x, y, z) */
-  float orientation_quat[4];
-} GHOST_XrPose;
+  GHOST_XrPose base_pose;
+} GHOST_XrSessionBeginInfo;
 
 typedef struct {
   int ofsx, ofsy;
diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp
index c190b8fc885..16a6d515c1b 100644
--- a/intern/ghost/intern/GHOST_C-api.cpp
+++ b/intern/ghost/intern/GHOST_C-api.cpp
@@ -688,6 +688,13 @@ 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;
diff --git a/intern/ghost/intern/GHOST_Context.h b/intern/ghost/intern/GHOST_Context.h
index d7a720bb545..0bc2aa21119 100644
--- a/intern/ghost/intern/GHOST_Context.h
+++ b/intern/ghost/intern/GHOST_Context.h
@@ -120,7 +120,7 @@ class GHOST_Context : public GHOST_IContext {
     return m_stereoVisual;
   }
 
-  inline virtual bool isUpsideDown() const
+  inline bool isUpsideDown() const
   {
     return false;
   }
diff --git a/intern/ghost/intern/GHOST_Xr.cpp b/intern/ghost/intern/GHOST_Xr.cpp
index 914d8236154..87e59d55393 100644
--- a/intern/ghost/intern/GHOST_Xr.cpp
+++ b/intern/ghost/intern/GHOST_Xr.cpp
@@ -260,13 +260,13 @@ void GHOST_XrContextDestroy(GHOST_XrContext *xr_context)
   delete xr_context;
 }
 
-void GHOST_XrSessionStart(GHOST_XrContext *xr_context)
+void GHOST_XrSessionStart(GHOST_XrContext *xr_context, const GHOST_XrSessionBeginInfo *begin_info)
 {
   if (xr_context->session == nullptr) {
     xr_context->session = std::unique_ptr<GHOST_XrSession>(new GHOST_XrSession(xr_context));
   }
 
-  xr_context->session->start();
+  xr_context->session->start(begin_info);
 }
 
 void GHOST_XrSessionEnd(GHOST_XrContext *xr_context)
diff --git a/intern/ghost/intern/GHOST_XrSession.cpp b/intern/ghost/intern/GHOST_XrSession.cpp
index d61036bc5df..930edb4e190 100644
--- a/intern/ghost/intern/GHOST_XrSession.cpp
+++ b/intern/ghost/intern/GHOST_XrSession.cpp
@@ -201,23 +201,26 @@ void GHOST_XrSession::prepareDrawing()
   m_oxr->views.resize(view_count, {XR_TYPE_VIEW});
 }
 
-static void create_reference_space(OpenXRSessionData *oxr)
+static void create_reference_space(OpenXRSessionData *oxr, const GHOST_XrPose *base_pose)
 {
   XrReferenceSpaceCreateInfo create_info{XR_TYPE_REFERENCE_SPACE_CREATE_INFO};
+  create_info.poseInReferenceSpace.orientation.w = 1.0f;
 
   create_info.referenceSpaceType = XR_REFERENCE_SPACE_TYPE_LOCAL;
-  create_info.poseInReferenceSpace.position.x = 0.0f;
-  create_info.poseInReferenceSpace.position.y = 0.0f;
-  create_info.poseInReferenceSpace.position.z = 0.0f;
-  create_info.poseInReferenceSpace.orientation.x = 0.0f;
-  create_info.poseInReferenceSpace.orientation.y = 0.0f;
-  create_info.poseInReferenceSpace.orientation.z = 0.0f;
-  create_info.poseInReferenceSpace.orientation.w = 1.0f;
+#if 0
+  create_info.poseInReferenceSpace.position.x = base_pose->position[0];
+  create_info.poseInReferenceSpace.position.y = base_pose->position[2];
+  create_info.poseInReferenceSpace.position.z = -base_pose->position[1];
+  create_info.poseInReferenceSpace.orientation.x = base_pose->orientation_quat[1];
+  create_info.poseInReferenceSpace.orientation.y = base_pose->orientation_quat[3];
+  create_info.poseInReferenceSpace.orientation.z = -base_pose->orientation_quat[2];
+  create_info.poseInReferenceSpace.orientation.w = base_pose->orientation_quat[0];
+#endif
 
   xrCreateReferenceSpace(oxr->session, &create_info, &oxr->reference_space);
 }
 
-void GHOST_XrSession::start()
+void GHOST_XrSession::start(const GHOST_XrSessionBeginInfo *begin_info)
 {
   assert(m_context->oxr.instance != XR_NULL_HANDLE);
   assert(m_oxr->session == XR_NULL_HANDLE);
@@ -251,7 +254,7 @@ void GHOST_XrSession::start()
   xrCreateSession(m_context->oxr.instance, &create_info, &m_oxr->session);
 
   prepareDrawing();
-  create_reference_space(m_oxr.get());
+  create_reference_space(m_oxr.get(), &begin_info->base_pose);
 }
 
 void GHOST_XrSession::end()
@@ -339,14 +342,24 @@ void GHOST_XrSession::draw(void *draw_customdata)
 
 static void ghost_xr_draw_view_info_from_view(const XrView &view, GHOST_XrDrawViewInfo &r_info)
 {
+#if 0
   /* Set and convert to Blender coodinate space */
-  r_info.pose.position[0] = -view.pose.position.x;
+  r_info.pose.position[0] = view.pose.position.x;
+  r_info.pose.position[1] = -view.pose.position.z;
+  r_info.pose.position[2] = view.pose.position.y;
+  r_info.pose.orientation_quat[0] = view.pose.orientation.w;
+  r_info.pose.orientation_quat[1] = view.pose.orientation.x;
+  r_info.pose.orientation_quat[2] = -view.pose.orientation.z;
+  r_info.pose.orientation_quat[3] = view.pose.orientation.y;
+#else
+  r_info.pose.position[0] = view.pose.position.x;
   r_info.pose.position[1] = view.pose.position.y;
-  r_info.pose.position[2] = -view.pose.position.z;
+  r_info.pose.position[2] = view.pose.position.z;
   r_info.pose.orientation_quat[0] = view.pose.orientation.w;
   r_info.pose.orientation_quat[1] = view.pose.orientation.x;
-  r_info.pose.orientation_quat[2] = -view.pose.orientation.y;
+  r_info.pose.orientation_quat[2] = view.pose.orientation.y;
   r_info.pose.orientation_quat[3] = view.pose.orientation.z;
+#endif
 
   r_info.fov.angle_left = view.fov.angleLeft;
   r_info.fov.angle_right = view.fov.angleRight;
diff --git a/intern/ghost/intern/GHOST_XrSession.h b/intern/ghost/intern/GHOST_XrSession.h
index 7442a8ad01b..ccf025db264 100644
--- a/intern/ghost/intern/GHOST_XrSession.h
+++ b/intern/ghost/intern/GHOST_XrSession.h
@@ -36,7 +36,7 @@ class GHOST_XrSession {
   GHOST_XrSession(struct GHOST_XrContext *xr_context);
   ~GHOST_XrSession();
 
-  void start();
+  void start(const GHOST_XrSessionBeginInfo *begin_info);
   void end();
 
   eLifeExpectancy handleStateChangeEvent(const struct XrEventDataSessionStateChanged *lifecycle);
diff --git a/source/blender/windowmanager/intern/wm_draw.c b/source/blender/windowmanager/intern/wm_draw.c
index f57b6f6dc6d..0400310db5d 100644
--- a/source/blender/windowmanager/intern/wm_draw.c
+++ b/source/blender/windowmanager/intern/wm_draw.c
@@ -291,7 +291,7 @@ static void wm_draw_region_buffer_free(ARegion *ar)
   }
 }
 
-static void wm_draw_offscreen_texture_parameters(GPUOffScreen *offscreen)
+void wm_draw_offscreen_texture_parameters(GPUOffScreen *offscreen)
 {
   /* Setup offscreen color texture for drawing. */
   GPUTexture *texture = GPU_offscreen_color_texture(offscreen);
@@ -723,7 +723,7 @@ static void wm_draw_window_onscreen(bContext *C, wmWindow *win, int view)
   }
 }
 
-static void wm_draw_upside_down(wmWindow *win)
+void wm_draw_upside_down(int sizex, int sizey)
 {
   GPUVertFormat *format = immVertexFormat();
   uint texcoord = GPU_vertformat_attr_add(format, "texCoord", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
@@ -731,9 +731,6 @@ static void wm_draw_upside_down(wmWindow *win)
 
   immBindBuiltinProgram(GPU_SHADER_2D_IMAGE);
 
-  const int sizex = WM_window_pixels_x(win);
-  const int sizey = WM_window_pixels_y(win);
-
   /* wmOrtho for the screen has this same offset */
   const float halfx = GLA_PIXEL_OFS / sizex;
   const float halfy = GLA_PIXEL_OFS / sizex;
@@ -782,7 +779,7 @@ static void wm_draw_window_upside_down_onscreen(bContext *C, wmWindow *win)
     glActiveTexture(GL_TEXTURE0);
     glBindTexture(GL_TEXTURE_2D, GPU_texture_opengl_bindcode(texture));
 
-    wm_draw_upside_down(win);
+    wm_draw_upside_down(win->sizex, win->sizey);
 
     glBindTexture(GL_TEXTURE_2D, 0);
 
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index d695d03f828..81a7929d91e 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list