Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen Bakker <jeroen@blender.org>2022-11-11 18:06:09 +0300
committerJeroen Bakker <jeroen@blender.org>2022-11-11 18:06:09 +0300
commit80f0d9e29dcb282935995ef1c87c9c7097f851ff (patch)
treec365a2038e3c50969f971d98fdcf518385a44c0c
parent3a3947bcf83228e1e7977556baff3de02b16ea07 (diff)
Add support for XrSession (untested).temp-xr-virtual-camera-experiment
-rw-r--r--source/blender/draw/DRW_engine.h1
-rw-r--r--source/blender/draw/engines/eevee/eevee_materials.c7
-rw-r--r--source/blender/draw/intern/DRW_render.h4
-rw-r--r--source/blender/draw/intern/draw_manager.c7
-rw-r--r--source/blender/draw/intern/draw_manager.h1
-rw-r--r--source/blender/editors/include/ED_view3d_offscreen.h1
-rw-r--r--source/blender/editors/space_view3d/view3d_draw.cc41
-rw-r--r--source/blender/gpu/GPU_material.h2
-rw-r--r--source/blender/gpu/intern/gpu_node_graph.c2
-rw-r--r--source/blender/python/gpu/gpu_py_offscreen.c1
10 files changed, 47 insertions, 20 deletions
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
@@ -886,6 +886,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.
*/
bool DRW_state_is_navigating(void);
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 0457b6bb9f2..4e28d3f2efe 100644
--- a/source/blender/gpu/GPU_material.h
+++ b/source/blender/gpu/GPU_material.h
@@ -83,7 +83,7 @@ typedef enum eGPUMaterialFlag {
GPU_MATFLAG_OBJECT_INFO = (1 << 10),
GPU_MATFLAG_AOV = (1 << 11),
- GPU_MATFLAG_VIRTUAL_CAMERA = (1 << 12),
+ GPU_MATFLAG_VIRTUAL_MONITOR = (1 << 12),
GPU_MATFLAG_BARYCENTRIC = (1 << 20),
diff --git a/source/blender/gpu/intern/gpu_node_graph.c b/source/blender/gpu/intern/gpu_node_graph.c
index 837cb114ac3..5c60d956abf 100644
--- a/source/blender/gpu/intern/gpu_node_graph.c
+++ b/source/blender/gpu/intern/gpu_node_graph.c
@@ -647,7 +647,7 @@ GPUNodeLink *GPU_image_camera(GPUMaterial *mat, Camera *camera, eGPUSamplerState
&camera->runtime.offscreen_color_texture,
link->link_type,
sampler_state);
- GPU_material_flag_set(mat, GPU_MATFLAG_VIRTUAL_CAMERA);
+ GPU_material_flag_set(mat, GPU_MATFLAG_VIRTUAL_MONITOR);
return link;
}
diff --git a/source/blender/python/gpu/gpu_py_offscreen.c b/source/blender/python/gpu/gpu_py_offscreen.c
index 621c6647cb9..1a03e773b19 100644
--- a/source/blender/python/gpu/gpu_py_offscreen.c
+++ b/source/blender/python/gpu/gpu_py_offscreen.c
@@ -398,6 +398,7 @@ static PyObject *pygpu_offscreen_draw_view3d(BPyGPUOffScreen *self, PyObject *ar
"",
do_color_management,
true,
+ false,
self->ofs,
self->viewport);