[Bf-blender-cvs] [5d30598e3b0] vr_scene_inspection: Make it obvious that the DRW context getters are not for general use

Julian Eisel noreply at git.blender.org
Tue Mar 17 16:56:36 CET 2020


Commit: 5d30598e3b05f89068fdd4469fe0d84bd017c290
Author: Julian Eisel
Date:   Tue Mar 17 16:28:29 2020 +0100
Branches: vr_scene_inspection
https://developer.blender.org/rB5d30598e3b05f89068fdd4469fe0d84bd017c290

Make it obvious that the DRW context getters are not for general use

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

M	source/blender/draw/CMakeLists.txt
M	source/blender/draw/DRW_engine.h
M	source/blender/draw/intern/draw_manager.c
M	source/blender/windowmanager/intern/wm_xr.c

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

diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index a1213be4be0..81f2214b402 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -390,4 +390,8 @@ if(WITH_FREESTYLE)
   add_definitions(-DWITH_FREESTYLE)
 endif()
 
+if(WITH_XR_OPENXR)
+  add_definitions(-DWITH_XR_OPENXR)
+endif()
+
 blender_add_lib(bf_draw "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
diff --git a/source/blender/draw/DRW_engine.h b/source/blender/draw/DRW_engine.h
index 07d6219b85e..d4d015e53ac 100644
--- a/source/blender/draw/DRW_engine.h
+++ b/source/blender/draw/DRW_engine.h
@@ -141,8 +141,8 @@ void DRW_opengl_context_disable(void);
 
 /* Not nice to expose these. Code to render offscreen viewports can save expensive context switches
  * by using this directly however. */
-void *DRW_opengl_context_get(void);
-void *DRW_gpu_context_get(void);
+void *DRW_xr_opengl_context_get(void);
+void *DRW_xr_gpu_context_get(void);
 
 /* For garbage collection */
 void DRW_cache_free_old_batches(struct Main *bmain);
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index d718522bdb4..8aeb90f5f36 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -2794,16 +2794,30 @@ void DRW_opengl_context_disable(void)
   DRW_opengl_context_disable_ex(true);
 }
 
-void *DRW_opengl_context_get(void)
+#ifdef WITH_XR_OPENXR
+
+/* XXX
+ * There should really be no such getter, but for VR we currently can't easily avoid it. OpenXR
+ * needs some low level info for the OpenGL context that will be used for submitting the
+ * final framebuffer. VR could in theory create its own context, but that would mean we have to
+ * switch to it just to submit the final frame, which has notable performance impact.
+ *
+ * We could "inject" a context through DRW_opengl_render_context_enable(), but that would have to
+ * work from the main thread, which is tricky to get working too. The preferable solution would be
+ * using a separate thread for VR drawing where a single context can stay active. */
+void *DRW_xr_opengl_context_get(void)
 {
   return DST.gl_context;
 }
 
-void *DRW_gpu_context_get(void)
+/* XXX See comment on DRW_xr_opengl_context_get(). */
+void *DRW_xr_gpu_context_get(void)
 {
   return DST.gpu_context;
 }
 
+#endif
+
 void DRW_opengl_render_context_enable(void *re_gl_context)
 {
   /* If thread is main you should use DRW_opengl_context_enable(). */
diff --git a/source/blender/windowmanager/intern/wm_xr.c b/source/blender/windowmanager/intern/wm_xr.c
index be6af48f5de..7600c0b350e 100644
--- a/source/blender/windowmanager/intern/wm_xr.c
+++ b/source/blender/windowmanager/intern/wm_xr.c
@@ -335,7 +335,7 @@ wmSurface *wm_xr_session_surface_create(wmWindowManager *UNUSED(wm), unsigned in
   data->gpu_binding_type = gpu_binding_type;
   surface->customdata = data;
 
-  surface->ghost_ctx = DRW_opengl_context_get();
+  surface->ghost_ctx = DRW_xr_opengl_context_get();
 
   switch (gpu_binding_type) {
     case GHOST_kXrGraphicsOpenGL:
@@ -347,7 +347,7 @@ wmSurface *wm_xr_session_surface_create(wmWindowManager *UNUSED(wm), unsigned in
 #endif
   }
 
-  surface->gpu_ctx = DRW_gpu_context_get();
+  surface->gpu_ctx = DRW_xr_gpu_context_get();
 
   g_xr_surface = surface;



More information about the Bf-blender-cvs mailing list