[Bf-blender-cvs] [80f0d9e29dc] temp-xr-virtual-camera-experiment: Add support for XrSession (untested).

Jeroen Bakker noreply at git.blender.org
Fri Nov 11 16:06:16 CET 2022


Commit: 80f0d9e29dcb282935995ef1c87c9c7097f851ff
Author: Jeroen Bakker
Date:   Fri Nov 11 16:06:09 2022 +0100
Branches: temp-xr-virtual-camera-experiment
https://developer.blender.org/rB80f0d9e29dcb282935995ef1c87c9c7097f851ff

Add support for XrSession (untested).

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

M	source/blender/draw/DRW_engine.h
M	source/blender/draw/engines/eevee/eevee_materials.c
M	source/blender/draw/intern/DRW_render.h
M	source/blender/draw/intern/draw_manager.c
M	source/blender/draw/intern/draw_manager.h
M	source/blender/editors/include/ED_view3d_offscreen.h
M	source/blender/editors/space_view3d/view3d_draw.cc
M	source/blender/gpu/GPU_material.h
M	source/blender/gpu/intern/gpu_node_graph.c
M	source/blender/python/gpu/gpu_py_offscreen.c

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

diff --git a/source/blender/draw/DRW_engine.h b/source/blender/draw/DRW_engine.h
index 8c5f1b70cc0..d7b43b85199 100644
--- a/source/blender/draw/DRW_engine.h
+++ b/source/blender/draw/DRW_engine.h
@@ -99,6 +99,7 @@ void DRW_draw_render_loop_offscreen(struct Depsgraph *depsgraph,
                                     bool is_image_render,
                                     bool draw_background,
                                     bool do_color_management,
+                                    bool is_virtual_camera,
                                     struct GPUOffScreen *ofs,
                                     struct GPUViewport *viewport);
 void DRW_draw_render_loop_2d_ex(struct Depsgraph *depsgraph,
diff --git a/source/blender/draw/engines/eevee/eevee_materials.c b/source/blender/draw/engines/eevee/eevee_materials.c
index b4874514bd9..e6de676bc29 100644
--- a/source/blender/draw/engines/eevee/eevee_materials.c
+++ b/source/blender/draw/engines/eevee/eevee_materials.c
@@ -861,10 +861,9 @@ void EEVEE_materials_cache_populate(EEVEE_Data *vedata,
               continue;
             }
 
-            /* Virtual cameras can only be used in the main scene. TODO: needs to be a different
-             * DRW_state.*/
-            if (DRW_state_is_opengl_render() &&
-                GPU_material_flag_get(gpumat_array[i], GPU_MATFLAG_VIRTUAL_CAMERA)) {
+            /* Virtual cameras can only be used in the main scene. */
+            if (DRW_state_is_virtual_camera() &&
+                GPU_material_flag_get(gpumat_array[i], GPU_MATFLAG_VIRTUAL_MONITOR)) {
               continue;
             }
 
diff --git a/source/blender/draw/intern/DRW_render.h b/source/blender/draw/intern/DRW_render.h
index b9444c58191..a4aed0f7e77 100644
--- a/source/blender/draw/intern/DRW_render.h
+++ b/source/blender/draw/intern/DRW_render.h
@@ -885,6 +885,10 @@ bool DRW_state_is_scene_render(void);
  */
 bool DRW_state_is_opengl_render(void);
 bool DRW_state_is_playback(void);
+/**
+ * Whether we are rendering a virtual camera, false when rendering the main camera/viewport.
+ */
+bool DRW_state_is_virtual_camera(void);
 /**
  * Is the user navigating the region.
  */
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index 4fcfec833eb..5e7be9c7fb7 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -1807,6 +1807,7 @@ void DRW_draw_render_loop_offscreen(struct Depsgraph *depsgraph,
                                     const bool is_image_render,
                                     const bool draw_background,
                                     const bool do_color_management,
+                                    const bool is_virtual_camera,
                                     GPUOffScreen *ofs,
                                     GPUViewport *viewport)
 {
@@ -1830,6 +1831,7 @@ void DRW_draw_render_loop_offscreen(struct Depsgraph *depsgraph,
   drw_state_prepare_clean_for_draw(&DST);
   DST.options.is_image_render = is_image_render;
   DST.options.draw_background = draw_background;
+  DST.options.is_virtual_camera = is_virtual_camera;
   DRW_draw_render_loop_ex(depsgraph, engine_type, region, v3d, render_viewport, NULL);
 
   if (draw_background) {
@@ -2920,6 +2922,11 @@ bool DRW_state_is_opengl_render(void)
   return DST.options.is_image_render && !DST.options.is_scene_render;
 }
 
+bool DRW_state_is_virtual_camera(void)
+{
+  return DST.options.is_virtual_camera;
+}
+
 bool DRW_state_is_playback(void)
 {
   if (DST.draw_ctx.evil_C != NULL) {
diff --git a/source/blender/draw/intern/draw_manager.h b/source/blender/draw/intern/draw_manager.h
index 52129049269..b1d097145c8 100644
--- a/source/blender/draw/intern/draw_manager.h
+++ b/source/blender/draw/intern/draw_manager.h
@@ -612,6 +612,7 @@ typedef struct DRWManager {
     uint is_depth : 1;
     uint is_image_render : 1;
     uint is_scene_render : 1;
+    uint is_virtual_camera : 1;
     uint draw_background : 1;
     uint draw_text : 1;
   } options;
diff --git a/source/blender/editors/include/ED_view3d_offscreen.h b/source/blender/editors/include/ED_view3d_offscreen.h
index 2217ace2e62..94d2352018d 100644
--- a/source/blender/editors/include/ED_view3d_offscreen.h
+++ b/source/blender/editors/include/ED_view3d_offscreen.h
@@ -39,6 +39,7 @@ void ED_view3d_draw_offscreen(struct Depsgraph *depsgraph,
                               const char *viewname,
                               bool do_color_management,
                               bool restore_rv3d_mats,
+                              bool is_virtual_camera,
                               struct GPUOffScreen *ofs,
                               struct GPUViewport *viewport);
 /**
diff --git a/source/blender/editors/space_view3d/view3d_draw.cc b/source/blender/editors/space_view3d/view3d_draw.cc
index 57bf8e557c2..59a9185f22a 100644
--- a/source/blender/editors/space_view3d/view3d_draw.cc
+++ b/source/blender/editors/space_view3d/view3d_draw.cc
@@ -1543,12 +1543,10 @@ void view3d_draw_region_info(const bContext *C, ARegion *region)
 /** \name Draw Viewport Contents
  * \{ */
 
-static void view3d_virtual_camera_update(const bContext *C, ARegion *region, Object *object)
+static void view3d_virtual_camera_update(
+    Scene *scene, Depsgraph *depsgraph, View3D *v3d, ARegion *region, Object *object)
 {
   BLI_assert(object->type == OB_CAMERA);
-  Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
-  Scene *scene = CTX_data_scene(C);
-  View3D *v3d = CTX_wm_view3d(C);
   int2 resolution(1920 / 2, 1080 / 2);
 
   RegionView3D *old_rv3d = static_cast<RegionView3D *>(region->regiondata);
@@ -1595,6 +1593,7 @@ static void view3d_virtual_camera_update(const bContext *C, ARegion *region, Obj
                            nullptr,
                            false,
                            true,
+                           true,
                            offscreen,
                            nullptr);
   GPU_offscreen_unbind(offscreen, true);
@@ -1605,13 +1604,18 @@ static void view3d_virtual_camera_update(const bContext *C, ARegion *region, Obj
   region->regiondata = old_rv3d;
 }
 
-static void view3d_draw_virtual_camera(const bContext *C, ARegion *region)
+static void view3d_draw_virtual_camera(Scene *scene,
+                                       Depsgraph *depsgraph,
+                                       View3D *v3d,
+                                       ARegion *region)
 {
-  Main *bmain = CTX_data_main(C);
+  /* TODO: Bad call! */
+  Main *bmain = DEG_get_bmain(depsgraph);
 
-  // create a custom view3d offscreen rendering.
+  /* Collect all cameras in the scene that is used inside a virtual monitor. This should be
+   * optimized by a tagging system. There are far more materials then cameras in a typical scene.
+   */
   Vector<Object *> virtual_cameras;
-
   LISTBASE_FOREACH (Material *, material, &bmain->materials) {
     if (!material->nodetree) {
       continue;
@@ -1630,26 +1634,29 @@ static void view3d_draw_virtual_camera(const bContext *C, ARegion *region)
   }
 
   if (virtual_cameras.is_empty()) {
-    /* No virtual cameras, so skip updating. */
+    /* No cameras used as virtual monitor, so skip updating. */
     return;
   }
 
   GPU_debug_group_begin("VirtualCameras");
   for (Object *object : virtual_cameras) {
-    view3d_virtual_camera_update(C, region, object);
+    view3d_virtual_camera_update(scene, depsgraph, v3d, region, object);
   }
   GPU_debug_group_end();
 }
 
 static void view3d_draw_view(const bContext *C, ARegion *region)
 {
-  view3d_draw_virtual_camera(C, region);
+  Scene *scene = CTX_data_scene(C);
+  Depsgraph *depsgraph = CTX_data_expect_evaluated_depsgraph(C);
+  View3D *v3d = CTX_wm_view3d(C);
+  view3d_draw_virtual_camera(scene, depsgraph, v3d, region);
   ED_view3d_draw_setup_view(CTX_wm_manager(C),
                             CTX_wm_window(C),
-                            CTX_data_expect_evaluated_depsgraph(C),
-                            CTX_data_scene(C),
+                            depsgraph,
+                            scene,
                             region,
-                            CTX_wm_view3d(C),
+                            v3d,
                             nullptr,
                             nullptr,
                             nullptr);
@@ -1747,6 +1754,7 @@ void ED_view3d_draw_offscreen(Depsgraph *depsgraph,
                               const char *viewname,
                               const bool do_color_management,
                               const bool restore_rv3d_mats,
+                              const bool is_virtual_camera,
                               GPUOffScreen *ofs,
                               GPUViewport *viewport)
 {
@@ -1822,6 +1830,7 @@ void ED_view3d_draw_offscreen(Depsgraph *depsgraph,
                                  is_image_render,
                                  draw_background,
                                  do_color_management,
+                                 is_virtual_camera,
                                  ofs,
                                  viewport);
   GPU_matrix_pop_projection();
@@ -1936,6 +1945,8 @@ void ED_view3d_draw_offscreen_simple(Depsgraph *depsgraph,
   /* Actually not used since we pass in the projection matrix. */
   v3d.lens = 0;
 
+  view3d_draw_virtual_camera(scene, depsgraph, &v3d, &ar);
+
   ED_view3d_draw_offscreen(depsgraph,
                            scene,
                            drawtype,
@@ -1950,6 +1961,7 @@ void ED_view3d_draw_offscreen_simple(Depsgraph *depsgraph,
                            viewname,
                            do_color_management,
                            true,
+                           false,
                            ofs,
                            viewport);
 }
@@ -2073,6 +2085,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(Depsgraph *depsgraph,
                            viewname,
                            do_color_management,
                            restore_rv3d_mats,
+                           false,
                            ofs,
                            nullptr);
 
diff --git a/source/blender/gpu/GPU_material.h b/source/blender/gpu/GPU_material.h
index 045

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list