[Bf-blender-cvs] [0a01bec4006] temp-xr-virtual-camera-experiment: Fixed using correct texture.

Jeroen Bakker noreply at git.blender.org
Wed Nov 9 13:18:15 CET 2022


Commit: 0a01bec40061cea4070c9d21b93f6123c7c1a356
Author: Jeroen Bakker
Date:   Wed Nov 9 13:18:12 2022 +0100
Branches: temp-xr-virtual-camera-experiment
https://developer.blender.org/rB0a01bec40061cea4070c9d21b93f6123c7c1a356

Fixed using correct texture.

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

M	source/blender/blenkernel/intern/camera.c
M	source/blender/draw/engines/eevee/eevee_materials.c
M	source/blender/draw/intern/draw_manager_data.cc
M	source/blender/editors/space_view3d/view3d_draw.cc
M	source/blender/gpu/intern/gpu_codegen.cc
M	source/blender/gpu/intern/gpu_node_graph.c
M	source/blender/makesdna/DNA_camera_types.h

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

diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c
index 71ef05e9a4f..93be310b3b3 100644
--- a/source/blender/blenkernel/intern/camera.c
+++ b/source/blender/blenkernel/intern/camera.c
@@ -137,8 +137,8 @@ static void camera_blend_read_data(BlendDataReader *reader, ID *id)
       bgpic->flag &= ~CAM_BGIMG_FLAG_OVERRIDE_LIBRARY_LOCAL;
     }
   }
-  ca->runtime.virtual_camera_stage = false;
   ca->runtime.virtual_display_texture = NULL;
+  ca->runtime.gpu_texture = NULL;
 }
 
 static void camera_blend_read_lib(BlendLibReader *reader, ID *id)
diff --git a/source/blender/draw/engines/eevee/eevee_materials.c b/source/blender/draw/engines/eevee/eevee_materials.c
index afb84f48bee..b4874514bd9 100644
--- a/source/blender/draw/engines/eevee/eevee_materials.c
+++ b/source/blender/draw/engines/eevee/eevee_materials.c
@@ -861,12 +861,8 @@ void EEVEE_materials_cache_populate(EEVEE_Data *vedata,
               continue;
             }
 
-            /* Virtual cameras can only be used in the main scene. This needs to be a different
+            /* Virtual cameras can only be used in the main scene. TODO: needs to be a different
              * DRW_state.*/
-            printf("%s: %d %d\n",
-                   __func__,
-                   DRW_state_is_opengl_render(),
-                   GPU_material_flag_get(gpumat_array[i], GPU_MATFLAG_VIRTUAL_CAMERA));
             if (DRW_state_is_opengl_render() &&
                 GPU_material_flag_get(gpumat_array[i], GPU_MATFLAG_VIRTUAL_CAMERA)) {
               continue;
diff --git a/source/blender/draw/intern/draw_manager_data.cc b/source/blender/draw/intern/draw_manager_data.cc
index 6183cf41a41..fc0bf64eeaa 100644
--- a/source/blender/draw/intern/draw_manager_data.cc
+++ b/source/blender/draw/intern/draw_manager_data.cc
@@ -1835,7 +1835,7 @@ void DRW_shgroup_add_material_resources(DRWShadingGroup *grp, GPUMaterial *mater
       DRW_shgroup_uniform_texture_ex(
           grp, tex->sampler_name, *tex->sky, eGPUSamplerState(tex->sampler_state));
     }
-    else if (tex->camera) {
+    else if (tex->camera && tex->camera[0]) {
       /* VirtualCamera */
       DRW_shgroup_uniform_texture_ex(
           grp, tex->sampler_name, *tex->camera, eGPUSamplerState(tex->sampler_state));
diff --git a/source/blender/editors/space_view3d/view3d_draw.cc b/source/blender/editors/space_view3d/view3d_draw.cc
index 2b66dbe840d..9ca181e2683 100644
--- a/source/blender/editors/space_view3d/view3d_draw.cc
+++ b/source/blender/editors/space_view3d/view3d_draw.cc
@@ -1543,13 +1543,6 @@ void view3d_draw_region_info(const bContext *C, ARegion *region)
 /** \name Draw Viewport Contents
  * \{ */
 
-static void view3d_virtual_camera_stage_set(Main *bmain, const bool virtual_stage)
-{
-  LISTBASE_FOREACH (Camera *, camera, &bmain->cameras) {
-    camera->runtime.virtual_camera_stage = virtual_stage;
-  }
-}
-
 static void view3d_virtual_camera_update(const bContext *C, ARegion *region, Object *object)
 {
   BLI_assert(object->type == OB_CAMERA);
@@ -1569,6 +1562,8 @@ static void view3d_virtual_camera_update(const bContext *C, ARegion *region, Obj
   DRW_draw_render_loop_offscreen(
       depsgraph, engine_type, region, v3d, true, false, false, offscreen, nullptr);
   GPU_offscreen_unbind(offscreen, true);
+  camera->runtime.gpu_texture = GPU_offscreen_color_texture(
+      camera->runtime.virtual_display_texture);
 }
 
 static void view3d_draw_virtual_camera(const bContext *C, ARegion *region)
@@ -1600,18 +1595,11 @@ static void view3d_draw_virtual_camera(const bContext *C, ARegion *region)
     return;
   }
 
-  // go over each camera and set the flag to virtual camera.
-  view3d_virtual_camera_stage_set(bmain, true);
-
   GPU_debug_group_begin("VirtualCameras");
   for (Object *object : virtual_cameras) {
     view3d_virtual_camera_update(C, region, object);
   }
   GPU_debug_group_end();
-
-  // get reference of the gpu texture and change its ownership
-  // go over eah camera and set the flag back to main camera.
-  view3d_virtual_camera_stage_set(bmain, false);
 }
 
 static void view3d_draw_view(const bContext *C, ARegion *region)
diff --git a/source/blender/gpu/intern/gpu_codegen.cc b/source/blender/gpu/intern/gpu_codegen.cc
index aa0f86d46e4..da00f9850c8 100644
--- a/source/blender/gpu/intern/gpu_codegen.cc
+++ b/source/blender/gpu/intern/gpu_codegen.cc
@@ -392,9 +392,9 @@ void GPUCodegen::generate_resources()
       const char *name = info.name_buffer.append_sampler_name(tex->sampler_name);
       info.sampler(0, ImageType::FLOAT_2D_ARRAY, name, Frequency::BATCH);
     }
-    else if (tex->camera) {
+    else if (tex->camera && tex->camera[0]) {
       const char *name = info.name_buffer.append_sampler_name(tex->sampler_name);
-      info.sampler(0, ImageType::FLOAT_2D, name, Frequency::BATCH);
+      info.sampler(slot++, ImageType::FLOAT_2D, name, Frequency::BATCH);
     }
     else if (tex->tiled_mapping_name[0] != '\0') {
       const char *name = info.name_buffer.append_sampler_name(tex->sampler_name);
diff --git a/source/blender/gpu/intern/gpu_node_graph.c b/source/blender/gpu/intern/gpu_node_graph.c
index 81b9d373951..153906675b0 100644
--- a/source/blender/gpu/intern/gpu_node_graph.c
+++ b/source/blender/gpu/intern/gpu_node_graph.c
@@ -638,10 +638,9 @@ GPUNodeLink *GPU_image_camera(GPUMaterial *mat, Camera *camera, eGPUSamplerState
 {
   GPUNodeGraph *graph = gpu_material_node_graph(mat);
   GPUNodeLink *link = gpu_node_link_create();
-  GPUTexture *texture = GPU_offscreen_color_texture(camera->runtime.virtual_display_texture);
   link->link_type = GPU_NODE_LINK_IMAGE_CAMERA;
   link->texture = gpu_node_graph_add_texture(
-      graph, NULL, NULL, NULL, NULL, &texture, link->link_type, sampler_state);
+      graph, NULL, NULL, NULL, NULL, &camera->runtime.gpu_texture, link->link_type, sampler_state);
   GPU_material_flag_set(mat, GPU_MATFLAG_VIRTUAL_CAMERA);
   return link;
 }
diff --git a/source/blender/makesdna/DNA_camera_types.h b/source/blender/makesdna/DNA_camera_types.h
index a257f3b876b..86a9e344b59 100644
--- a/source/blender/makesdna/DNA_camera_types.h
+++ b/source/blender/makesdna/DNA_camera_types.h
@@ -72,11 +72,9 @@ typedef struct Camera_Runtime {
   float drw_focusmat[4][4];
   float drw_normalmat[4][4];
 
-  /* XXX(jbakker): Yuck but we are experimenting... true when virtual camera is evaluated, false
-   * when scene camera/main camera is evaluated. */
-  int virtual_camera_stage;
-  int _pad[1];
   struct GPUOffScreen *virtual_display_texture;
+  /* Local reference to not owning gpu texture. Used to have a reliable pointer to the texture. */
+  struct GPUTexture *gpu_texture;
 } Camera_Runtime;
 
 typedef struct Camera {



More information about the Bf-blender-cvs mailing list