From 3d3f51fa4b3aff660ea4e8d3d01c243a3745706a Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 2 Mar 2023 15:01:38 +0300 Subject: [PATCH 1/5] BLEN-343: Create PreviewEngine --- release/scripts/modules/hydra.py | 2 +- source/blender/render/hydra/CMakeLists.txt | 2 + source/blender/render/hydra/engine.h | 1 + source/blender/render/hydra/finalEngine.cc | 2 +- source/blender/render/hydra/finalEngine.h | 2 +- source/blender/render/hydra/previewEngine.cc | 81 +++++++++++++++++++ source/blender/render/hydra/previewEngine.h | 28 +++++++ source/blender/render/hydra/python.cc | 18 ++++- .../sceneDelegate/blenderSceneDelegate.cc | 4 + source/blender/render/hydra/viewportEngine.cc | 4 + source/blender/render/hydra/viewportEngine.h | 1 + 11 files changed, 140 insertions(+), 5 deletions(-) create mode 100644 source/blender/render/hydra/previewEngine.cc create mode 100644 source/blender/render/hydra/previewEngine.h diff --git a/release/scripts/modules/hydra.py b/release/scripts/modules/hydra.py index a44c2d68954f..cc4839710644 100644 --- a/release/scripts/modules/hydra.py +++ b/release/scripts/modules/hydra.py @@ -46,7 +46,7 @@ class HydraRenderEngine(bpy.types.RenderEngine): delegate_settings = self.get_delegate_settings(engine_type) _hydra.engine_sync(self.engine_ptr, depsgraph.as_pointer(), bpy.context.as_pointer(), delegate_settings) - _hydra.engine_render(self.engine_ptr, depsgraph.as_pointer()) + _hydra.engine_render(self.engine_ptr, depsgraph.as_pointer(), engine_type) # viewport render def view_update(self, context, depsgraph): diff --git a/source/blender/render/hydra/CMakeLists.txt b/source/blender/render/hydra/CMakeLists.txt index 883177b61977..c5f0016a8f56 100644 --- a/source/blender/render/hydra/CMakeLists.txt +++ b/source/blender/render/hydra/CMakeLists.txt @@ -50,6 +50,8 @@ set(SRC engine.cc finalEngine.h finalEngine.cc + previewEngine.h + previewEngine.cc viewportEngine.h viewportEngine.cc camera.h diff --git a/source/blender/render/hydra/engine.h b/source/blender/render/hydra/engine.h index ec5ec72e9eb6..8b861c9e86fd 100644 --- a/source/blender/render/hydra/engine.h +++ b/source/blender/render/hydra/engine.h @@ -27,6 +27,7 @@ public: virtual ~Engine(); virtual void sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, pxr::HdRenderSettingsMap &renderSettings) = 0; + virtual void render(BL::Depsgraph &b_depsgraph) = 0; protected: float getRendererPercentDone(); diff --git a/source/blender/render/hydra/finalEngine.cc b/source/blender/render/hydra/finalEngine.cc index f0dce20218ce..bceb6a32d74b 100644 --- a/source/blender/render/hydra/finalEngine.cc +++ b/source/blender/render/hydra/finalEngine.cc @@ -19,7 +19,7 @@ using namespace pxr; namespace blender::render::hydra { -void FinalEngine::sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, pxr::HdRenderSettingsMap &renderSettings) +void FinalEngine::sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, HdRenderSettingsMap &renderSettings) { sceneDelegate = std::make_unique(renderIndex.get(), SdfPath::AbsoluteRootPath().AppendElementString("scene")); diff --git a/source/blender/render/hydra/finalEngine.h b/source/blender/render/hydra/finalEngine.h index 77127b8cb51d..d126f2deb3ea 100644 --- a/source/blender/render/hydra/finalEngine.h +++ b/source/blender/render/hydra/finalEngine.h @@ -13,7 +13,7 @@ class FinalEngine : public Engine { public: using Engine::Engine; void sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, pxr::HdRenderSettingsMap &renderSettings) override; - virtual void render(BL::Depsgraph &b_depsgraph); + virtual void render(BL::Depsgraph &b_depsgraph) override; protected: pxr::GfVec2i get_resolution(BL::RenderSettings b_render); diff --git a/source/blender/render/hydra/previewEngine.cc b/source/blender/render/hydra/previewEngine.cc new file mode 100644 index 000000000000..d9b47b82db95 --- /dev/null +++ b/source/blender/render/hydra/previewEngine.cc @@ -0,0 +1,81 @@ +/* SPDX-License-Identifier: Apache-2.0 +* Copyright 2011-2022 Blender Foundation */ + +#include + +#include "previewEngine.h" +#include "camera.h" + +using namespace pxr; +using namespace std; + +namespace blender::render::hydra { + +void PreviewEngine::sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, HdRenderSettingsMap &renderSettings) +{ + is_synced = false; + + sceneDelegate = std::make_unique(renderIndex.get(), + SdfPath::AbsoluteRootPath().AppendElementString("scene")); + sceneDelegate->populate((Depsgraph *)b_depsgraph.ptr.data, (bContext *)b_context.ptr.data); + + for (auto const& setting : renderSettings) { + renderDelegate->SetRenderSetting(setting.first, setting.second); + } + + is_synced = true; +} + +void PreviewEngine::render(BL::Depsgraph &b_depsgraph) +{ + if (!is_synced) { + return; + } + + BL::Scene b_scene = b_depsgraph.scene(); + string layerName = b_depsgraph.view_layer().name(); + GfVec2i buffer_res {b_scene.render().resolution_x(), + b_scene.render().resolution_y()}; + + GfCamera gfCamera = CameraData((Object *)b_scene.camera().ptr.data, buffer_res, GfVec4f(0, 0, 1, 1)).gf_camera(GfVec4f(0, 0, 1, 1)); + + freeCameraDelegate->SetCamera(gfCamera); + renderTaskDelegate->SetCameraAndViewport(freeCameraDelegate->GetCameraId(), GfVec4d(0, 0, buffer_res[0], buffer_res[1])); + renderTaskDelegate->SetRendererAov(HdAovTokens->color); + + HdTaskSharedPtrVector tasks = renderTaskDelegate->GetTasks(); + + vector pixels = vector(buffer_res[0] * buffer_res[1] * 4); // 4 - number of channels + + { + // Release the GIL before calling into hydra, in case any hydra plugins call into python. + TF_PY_ALLOW_THREADS_IN_SCOPE(); + engine->Execute(renderIndex.get(), &tasks); + } + + while (true) { + if (b_engine.test_break()) { + break; + } + + if (renderTaskDelegate->IsConverged()) { + break; + } + + renderTaskDelegate->GetRendererAovData(HdAovTokens->color, pixels.data()); + updateRenderResult(layerName, buffer_res[0], buffer_res[1], pixels); + } + + renderTaskDelegate->GetRendererAovData(HdAovTokens->color, pixels.data()); + updateRenderResult(layerName, buffer_res[0], buffer_res[1], pixels); +} + +void PreviewEngine::updateRenderResult(const string &layerName, int width, int height, vector &pixels) +{ + BL::RenderResult b_result = b_engine.begin_result(0, 0, width, height, layerName.c_str(), NULL); + BL::CollectionRef b_passes = b_result.layers[0].passes; + b_passes[0].rect(pixels.data()); + b_engine.end_result(b_result, false, false, false); +} + +} // namespace blender::render::hydra diff --git a/source/blender/render/hydra/previewEngine.h b/source/blender/render/hydra/previewEngine.h new file mode 100644 index 000000000000..657e61438832 --- /dev/null +++ b/source/blender/render/hydra/previewEngine.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: Apache-2.0 +* Copyright 2011-2022 Blender Foundation */ + +#pragma once + +#include "engine.h" + +namespace blender::render::hydra { + + class PreviewEngine : public Engine { + public: + using Engine::Engine; + void sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, pxr::HdRenderSettingsMap &renderSettings) override; + void render(BL::Depsgraph &b_depsgraph) override; + + protected: + pxr::GfVec2i get_resolution(BL::RenderSettings b_render); + void updateRenderResult(const std::string &layerName, int width, int height, std::vector &pixels); + void notifyStatus(float progress, const std::string &title, const std::string &info); + + protected: + HdRenderSettingsMap renderSettings; + + private: + bool is_synced; + }; + +} // namespace blender::render::hydra diff --git a/source/blender/render/hydra/python.cc b/source/blender/render/hydra/python.cc index 45c055373dd7..b2ebf4cc1682 100644 --- a/source/blender/render/hydra/python.cc +++ b/source/blender/render/hydra/python.cc @@ -16,6 +16,7 @@ #include "finalEngine.h" #include "viewportEngine.h" +#include "previewEngine.h" using namespace std; @@ -130,9 +131,13 @@ static PyObject *engine_create_func(PyObject * /*self*/, PyObject *args) BL::RenderEngine b_engine(engineptr); Engine *engine; + if (string(engineType) == "VIEWPORT") { engine = new ViewportEngine(b_engine, delegateId); } + else if (string(engineType) == "PREVIEW") { + engine = new PreviewEngine(b_engine, delegateId); + } else { if (b_engine.bl_use_gpu_context()) { engine = new FinalEngineGL(b_engine, delegateId); @@ -204,11 +209,20 @@ static PyObject *engine_sync_func(PyObject * /*self*/, PyObject *args) static PyObject *engine_render_func(PyObject * /*self*/, PyObject *args) { PyObject *pyengine, *pydepsgraph; - if (!PyArg_ParseTuple(args, "OO", &pyengine, &pydepsgraph)) { + char *engineType; + + if (!PyArg_ParseTuple(args, "OOs", &pyengine, &pydepsgraph, &engineType)) { Py_RETURN_NONE; } - FinalEngine *engine = (FinalEngine *)PyLong_AsVoidPtr(pyengine); + Engine *engine; + + if (string(engineType) == "PREVIEW") { + engine = (PreviewEngine *)PyLong_AsVoidPtr(pyengine); + } + else { + engine = (FinalEngine *)PyLong_AsVoidPtr(pyengine); + } PointerRNA depsgraphptr; RNA_pointer_create(NULL, &RNA_Depsgraph, (ID *)PyLong_AsVoidPtr(pydepsgraph), &depsgraphptr); diff --git a/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.cc b/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.cc index 22a244d512dd..480f5b3fca16 100644 --- a/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.cc +++ b/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.cc @@ -27,6 +27,10 @@ void BlenderSceneDelegate::set_material(MeshData &mesh_data) mesh_data.material_id = SdfPath::EmptyPath(); return; } + if (!material->flag) { + mesh_data.material_id = SdfPath::EmptyPath(); + return; + } SdfPath id = MaterialData::prim_id(this, material); MaterialData *mat_data = material_data(id); if (!mat_data) { diff --git a/source/blender/render/hydra/viewportEngine.cc b/source/blender/render/hydra/viewportEngine.cc index fc299983e9e4..f0a080dbf7d4 100644 --- a/source/blender/render/hydra/viewportEngine.cc +++ b/source/blender/render/hydra/viewportEngine.cc @@ -307,6 +307,10 @@ void ViewportEngine::viewDraw(BL::Depsgraph &b_depsgraph, BL::Context &b_context } } +void ViewportEngine::render(BL::Depsgraph& b_depsgraph) +{ +} + void ViewportEngine::notifyStatus(const string &info, const string &status) { b_engine.update_stats(status.c_str(), info.c_str()); diff --git a/source/blender/render/hydra/viewportEngine.h b/source/blender/render/hydra/viewportEngine.h index 4d62528be589..7e3c8cf53012 100644 --- a/source/blender/render/hydra/viewportEngine.h +++ b/source/blender/render/hydra/viewportEngine.h @@ -34,6 +34,7 @@ public: using Engine::Engine; void sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, pxr::HdRenderSettingsMap &renderSettings) override; void viewDraw(BL::Depsgraph &b_depsgraph, BL::Context &b_context); + void render(BL::Depsgraph &b_depsgraph) override; private: void notifyStatus(const std::string &title, const std::string &info); -- 2.30.2 From 1f072919b52b0051af04e54797e219eeb66b5e50 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 2 Mar 2023 15:10:48 +0300 Subject: [PATCH 2/5] added comment --- .../render/hydra/sceneDelegate/blenderSceneDelegate.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.cc b/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.cc index 480f5b3fca16..a05c656ab1d5 100644 --- a/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.cc +++ b/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.cc @@ -27,6 +27,10 @@ void BlenderSceneDelegate::set_material(MeshData &mesh_data) mesh_data.material_id = SdfPath::EmptyPath(); return; } + /** + * Haven't found any description about this flag. It disables some materials + * that don't exist for preview render + */ if (!material->flag) { mesh_data.material_id = SdfPath::EmptyPath(); return; -- 2.30.2 From 2fcd7a47139363cac3fd245c9686d4f72f7c39a4 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 2 Mar 2023 17:46:31 +0300 Subject: [PATCH 3/5] refactoring --- release/scripts/modules/hydra.py | 2 +- source/blender/render/hydra/finalEngine.h | 2 +- source/blender/render/hydra/previewEngine.h | 8 +++----- source/blender/render/hydra/python.cc | 14 +++----------- .../hydra/sceneDelegate/blenderSceneDelegate.cc | 8 -------- source/blender/render/hydra/viewportEngine.cc | 4 ++-- source/blender/render/hydra/viewportEngine.h | 2 +- 7 files changed, 11 insertions(+), 29 deletions(-) diff --git a/release/scripts/modules/hydra.py b/release/scripts/modules/hydra.py index cc4839710644..a44c2d68954f 100644 --- a/release/scripts/modules/hydra.py +++ b/release/scripts/modules/hydra.py @@ -46,7 +46,7 @@ class HydraRenderEngine(bpy.types.RenderEngine): delegate_settings = self.get_delegate_settings(engine_type) _hydra.engine_sync(self.engine_ptr, depsgraph.as_pointer(), bpy.context.as_pointer(), delegate_settings) - _hydra.engine_render(self.engine_ptr, depsgraph.as_pointer(), engine_type) + _hydra.engine_render(self.engine_ptr, depsgraph.as_pointer()) # viewport render def view_update(self, context, depsgraph): diff --git a/source/blender/render/hydra/finalEngine.h b/source/blender/render/hydra/finalEngine.h index d126f2deb3ea..2f0e6d3664b6 100644 --- a/source/blender/render/hydra/finalEngine.h +++ b/source/blender/render/hydra/finalEngine.h @@ -12,7 +12,7 @@ namespace blender::render::hydra { class FinalEngine : public Engine { public: using Engine::Engine; - void sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, pxr::HdRenderSettingsMap &renderSettings) override; + virtual void sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, pxr::HdRenderSettingsMap &renderSettings) override; virtual void render(BL::Depsgraph &b_depsgraph) override; protected: diff --git a/source/blender/render/hydra/previewEngine.h b/source/blender/render/hydra/previewEngine.h index 657e61438832..63bb7c802d80 100644 --- a/source/blender/render/hydra/previewEngine.h +++ b/source/blender/render/hydra/previewEngine.h @@ -3,20 +3,18 @@ #pragma once -#include "engine.h" +#include "finalEngine.h" namespace blender::render::hydra { - class PreviewEngine : public Engine { + class PreviewEngine : public FinalEngine { public: - using Engine::Engine; + using FinalEngine::FinalEngine; void sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, pxr::HdRenderSettingsMap &renderSettings) override; void render(BL::Depsgraph &b_depsgraph) override; protected: - pxr::GfVec2i get_resolution(BL::RenderSettings b_render); void updateRenderResult(const std::string &layerName, int width, int height, std::vector &pixels); - void notifyStatus(float progress, const std::string &title, const std::string &info); protected: HdRenderSettingsMap renderSettings; diff --git a/source/blender/render/hydra/python.cc b/source/blender/render/hydra/python.cc index b2ebf4cc1682..55763de05125 100644 --- a/source/blender/render/hydra/python.cc +++ b/source/blender/render/hydra/python.cc @@ -209,20 +209,12 @@ static PyObject *engine_sync_func(PyObject * /*self*/, PyObject *args) static PyObject *engine_render_func(PyObject * /*self*/, PyObject *args) { PyObject *pyengine, *pydepsgraph; - char *engineType; - if (!PyArg_ParseTuple(args, "OOs", &pyengine, &pydepsgraph, &engineType)) { + if (!PyArg_ParseTuple(args, "OO", &pyengine, &pydepsgraph)) { Py_RETURN_NONE; } - Engine *engine; - - if (string(engineType) == "PREVIEW") { - engine = (PreviewEngine *)PyLong_AsVoidPtr(pyengine); - } - else { - engine = (FinalEngine *)PyLong_AsVoidPtr(pyengine); - } + Engine *engine = (Engine *)PyLong_AsVoidPtr(pyengine); PointerRNA depsgraphptr; RNA_pointer_create(NULL, &RNA_Depsgraph, (ID *)PyLong_AsVoidPtr(pydepsgraph), &depsgraphptr); @@ -255,7 +247,7 @@ static PyObject *engine_view_draw_func(PyObject * /*self*/, PyObject *args) /* Allow Blender to execute other Python scripts. */ Py_BEGIN_ALLOW_THREADS - engine->viewDraw(b_depsgraph, b_context); + engine->render(b_depsgraph, b_context); Py_END_ALLOW_THREADS Py_RETURN_NONE; diff --git a/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.cc b/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.cc index a05c656ab1d5..22a244d512dd 100644 --- a/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.cc +++ b/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.cc @@ -27,14 +27,6 @@ void BlenderSceneDelegate::set_material(MeshData &mesh_data) mesh_data.material_id = SdfPath::EmptyPath(); return; } - /** - * Haven't found any description about this flag. It disables some materials - * that don't exist for preview render - */ - if (!material->flag) { - mesh_data.material_id = SdfPath::EmptyPath(); - return; - } SdfPath id = MaterialData::prim_id(this, material); MaterialData *mat_data = material_data(id); if (!mat_data) { diff --git a/source/blender/render/hydra/viewportEngine.cc b/source/blender/render/hydra/viewportEngine.cc index f0a080dbf7d4..09f43af10f61 100644 --- a/source/blender/render/hydra/viewportEngine.cc +++ b/source/blender/render/hydra/viewportEngine.cc @@ -253,7 +253,7 @@ void ViewportEngine::sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, Hd } } -void ViewportEngine::viewDraw(BL::Depsgraph &b_depsgraph, BL::Context &b_context) +void ViewportEngine::render(BL::Depsgraph &b_depsgraph, BL::Context &b_context) { ViewSettings viewSettings(b_context); if (viewSettings.width() * viewSettings.height() == 0) { @@ -307,7 +307,7 @@ void ViewportEngine::viewDraw(BL::Depsgraph &b_depsgraph, BL::Context &b_context } } -void ViewportEngine::render(BL::Depsgraph& b_depsgraph) +void ViewportEngine::render(BL::Depsgraph &b_depsgraph) { } diff --git a/source/blender/render/hydra/viewportEngine.h b/source/blender/render/hydra/viewportEngine.h index 7e3c8cf53012..9dc141705244 100644 --- a/source/blender/render/hydra/viewportEngine.h +++ b/source/blender/render/hydra/viewportEngine.h @@ -33,8 +33,8 @@ class ViewportEngine : public Engine { public: using Engine::Engine; void sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, pxr::HdRenderSettingsMap &renderSettings) override; - void viewDraw(BL::Depsgraph &b_depsgraph, BL::Context &b_context); void render(BL::Depsgraph &b_depsgraph) override; + void render(BL::Depsgraph &b_depsgraph, BL::Context &b_context); private: void notifyStatus(const std::string &title, const std::string &info); -- 2.30.2 From 33bb1cd155560318473245bd278c3724a99cb18f Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 2 Mar 2023 18:49:33 +0300 Subject: [PATCH 4/5] changed pxr::HdSceneDelegate to BlenderSceneDelegate added enum Engine::EngineType added Engine::EngineType to BlenderSceneDelegate --- source/blender/render/hydra/engine.cc | 1 + source/blender/render/hydra/engine.h | 9 ++++++++- source/blender/render/hydra/finalEngine.cc | 3 ++- source/blender/render/hydra/previewEngine.cc | 3 ++- .../render/hydra/sceneDelegate/blenderSceneDelegate.cc | 8 +++++++- .../render/hydra/sceneDelegate/blenderSceneDelegate.h | 6 +++++- source/blender/render/hydra/sceneDelegate/id.cc | 3 ++- source/blender/render/hydra/sceneDelegate/id.h | 6 ++++-- source/blender/render/hydra/sceneDelegate/instance.cc | 3 ++- source/blender/render/hydra/sceneDelegate/instance.h | 2 +- source/blender/render/hydra/sceneDelegate/light.cc | 8 ++++++-- source/blender/render/hydra/sceneDelegate/light.h | 2 +- source/blender/render/hydra/sceneDelegate/material.cc | 7 ++++--- source/blender/render/hydra/sceneDelegate/material.h | 6 +++--- source/blender/render/hydra/sceneDelegate/mesh.cc | 4 ++-- source/blender/render/hydra/sceneDelegate/mesh.h | 2 +- source/blender/render/hydra/sceneDelegate/object.cc | 7 ++++--- source/blender/render/hydra/sceneDelegate/object.h | 6 +++--- source/blender/render/hydra/sceneDelegate/world.cc | 7 ++++--- source/blender/render/hydra/sceneDelegate/world.h | 6 +++--- source/blender/render/hydra/viewportEngine.cc | 3 ++- 21 files changed, 67 insertions(+), 35 deletions(-) diff --git a/source/blender/render/hydra/engine.cc b/source/blender/render/hydra/engine.cc index 5716901e8879..80e8871c9d83 100644 --- a/source/blender/render/hydra/engine.cc +++ b/source/blender/render/hydra/engine.cc @@ -9,6 +9,7 @@ #include "glog/logging.h" +#include "sceneDelegate/blenderSceneDelegate.h" #include "engine.h" using namespace pxr; diff --git a/source/blender/render/hydra/engine.h b/source/blender/render/hydra/engine.h index 8b861c9e86fd..b2388b816669 100644 --- a/source/blender/render/hydra/engine.h +++ b/source/blender/render/hydra/engine.h @@ -16,13 +16,20 @@ #include "MEM_guardedalloc.h" #include "RNA_blender_cpp.h" -#include "sceneDelegate/blenderSceneDelegate.h" #include "renderTaskDelegate.h" namespace blender::render::hydra { +class BlenderSceneDelegate; + class Engine { public: + enum class EngineType { + Viewport = 1, + Final, + Preview + }; + Engine(BL::RenderEngine &b_engine, const std::string &delegateId); virtual ~Engine(); diff --git a/source/blender/render/hydra/finalEngine.cc b/source/blender/render/hydra/finalEngine.cc index bceb6a32d74b..e0b4b7e2e087 100644 --- a/source/blender/render/hydra/finalEngine.cc +++ b/source/blender/render/hydra/finalEngine.cc @@ -10,6 +10,7 @@ #include "glog/logging.h" +#include "sceneDelegate/blenderSceneDelegate.h" #include "finalEngine.h" #include "camera.h" #include "utils.h" @@ -22,7 +23,7 @@ namespace blender::render::hydra { void FinalEngine::sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, HdRenderSettingsMap &renderSettings) { sceneDelegate = std::make_unique(renderIndex.get(), - SdfPath::AbsoluteRootPath().AppendElementString("scene")); + SdfPath::AbsoluteRootPath().AppendElementString("scene"), EngineType::Final); sceneDelegate->populate((Depsgraph *)b_depsgraph.ptr.data, (bContext *)b_context.ptr.data); for (auto const& setting : renderSettings) { diff --git a/source/blender/render/hydra/previewEngine.cc b/source/blender/render/hydra/previewEngine.cc index d9b47b82db95..79f045aed964 100644 --- a/source/blender/render/hydra/previewEngine.cc +++ b/source/blender/render/hydra/previewEngine.cc @@ -3,6 +3,7 @@ #include +#include "sceneDelegate/blenderSceneDelegate.h" #include "previewEngine.h" #include "camera.h" @@ -16,7 +17,7 @@ void PreviewEngine::sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, HdR is_synced = false; sceneDelegate = std::make_unique(renderIndex.get(), - SdfPath::AbsoluteRootPath().AppendElementString("scene")); + SdfPath::AbsoluteRootPath().AppendElementString("scene"), EngineType::Preview); sceneDelegate->populate((Depsgraph *)b_depsgraph.ptr.data, (bContext *)b_context.ptr.data); for (auto const& setting : renderSettings) { diff --git a/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.cc b/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.cc index 22a244d512dd..6887eda8a624 100644 --- a/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.cc +++ b/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.cc @@ -12,11 +12,12 @@ using namespace pxr; namespace blender::render::hydra { -BlenderSceneDelegate::BlenderSceneDelegate(HdRenderIndex* parentIndex, SdfPath const& delegateID) +BlenderSceneDelegate::BlenderSceneDelegate(HdRenderIndex* parentIndex, SdfPath const& delegateID, Engine::EngineType engine_type) : HdSceneDelegate(parentIndex, delegateID) , depsgraph(nullptr) , context(nullptr) , view3d(nullptr) + , engine_type(engine_type) { } @@ -309,6 +310,11 @@ void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont) } } +Engine::EngineType BlenderSceneDelegate::get_engine_type() +{ + return engine_type; +} + HdMeshTopology BlenderSceneDelegate::GetMeshTopology(SdfPath const& id) { MeshData *m_data = mesh_data(id); diff --git a/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.h b/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.h index bace71c8370d..b50957c88086 100644 --- a/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.h +++ b/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.h @@ -13,15 +13,17 @@ #include "light.h" #include "world.h" #include "instance.h" +#include "../engine.h" namespace blender::render::hydra { class BlenderSceneDelegate : public pxr::HdSceneDelegate { public: - BlenderSceneDelegate(pxr::HdRenderIndex *renderIndex, pxr::SdfPath const &delegateId); + BlenderSceneDelegate(pxr::HdRenderIndex *renderIndex, pxr::SdfPath const &delegateId, Engine::EngineType engine_type); ~BlenderSceneDelegate() override = default; void populate(Depsgraph *depsgraph, bContext *context); + Engine::EngineType get_engine_type(); // delegate methods pxr::HdMeshTopology GetMeshTopology(pxr::SdfPath const &id) override; @@ -54,6 +56,8 @@ private: MaterialDataMap materials; std::unique_ptr world_data; InstanceDataMap instances; + + Engine::EngineType engine_type; }; } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/sceneDelegate/id.cc b/source/blender/render/hydra/sceneDelegate/id.cc index 54852c34617e..da56e418540d 100644 --- a/source/blender/render/hydra/sceneDelegate/id.cc +++ b/source/blender/render/hydra/sceneDelegate/id.cc @@ -3,13 +3,14 @@ #include "BKE_lib_id.h" +#include "blenderSceneDelegate.h" #include "id.h" using namespace pxr; namespace blender::render::hydra { -IdData::IdData(pxr::HdSceneDelegate *scene_delegate, ID *id) +IdData::IdData(BlenderSceneDelegate *scene_delegate, ID *id) : scene_delegate(scene_delegate) , id(id) { diff --git a/source/blender/render/hydra/sceneDelegate/id.h b/source/blender/render/hydra/sceneDelegate/id.h index ecd8fe14bcf7..99228418feca 100644 --- a/source/blender/render/hydra/sceneDelegate/id.h +++ b/source/blender/render/hydra/sceneDelegate/id.h @@ -11,9 +11,11 @@ namespace blender::render::hydra { +class BlenderSceneDelegate; + class IdData { public: - IdData(pxr::HdSceneDelegate *scene_delegate, ID *id); + IdData(BlenderSceneDelegate *scene_delegate, ID *id); virtual ~IdData() = default; std::string name(); @@ -32,7 +34,7 @@ class IdData { virtual void mark_prim_dirty(DirtyBits dirty_bits) = 0; protected: - pxr::HdSceneDelegate *scene_delegate; + BlenderSceneDelegate *scene_delegate; ID *id; }; diff --git a/source/blender/render/hydra/sceneDelegate/instance.cc b/source/blender/render/hydra/sceneDelegate/instance.cc index 84feceddb5b4..a6e7a1d7bec8 100644 --- a/source/blender/render/hydra/sceneDelegate/instance.cc +++ b/source/blender/render/hydra/sceneDelegate/instance.cc @@ -1,13 +1,14 @@ /* SPDX-License-Identifier: Apache-2.0 * Copyright 2011-2022 Blender Foundation */ +#include "blenderSceneDelegate.h" #include "instance.h" using namespace pxr; namespace blender::render::hydra { -InstanceData::InstanceData(pxr::HdSceneDelegate *scene_delegate, DupliObject *dupli) +InstanceData::InstanceData(BlenderSceneDelegate *scene_delegate, DupliObject *dupli) : IdData(scene_delegate, (ID *)dupli->ob_data) , dupli(dupli) { diff --git a/source/blender/render/hydra/sceneDelegate/instance.h b/source/blender/render/hydra/sceneDelegate/instance.h index f9dd6e0c15af..f3a9cceaf764 100644 --- a/source/blender/render/hydra/sceneDelegate/instance.h +++ b/source/blender/render/hydra/sceneDelegate/instance.h @@ -11,7 +11,7 @@ namespace blender::render::hydra { class InstanceData: public IdData { public: - InstanceData(pxr::HdSceneDelegate *scene_delegate, DupliObject *dupli); + InstanceData(BlenderSceneDelegate *scene_delegate, DupliObject *dupli); int random_id(); diff --git a/source/blender/render/hydra/sceneDelegate/light.cc b/source/blender/render/hydra/sceneDelegate/light.cc index 3a49dd93e84f..b0b67df1975a 100644 --- a/source/blender/render/hydra/sceneDelegate/light.cc +++ b/source/blender/render/hydra/sceneDelegate/light.cc @@ -12,6 +12,7 @@ #include "BKE_light.h" #include "DNA_light_types.h" +#include "blenderSceneDelegate.h" #include "light.h" using namespace pxr; @@ -19,12 +20,15 @@ using namespace boost::algorithm; namespace blender::render::hydra { -LightData::LightData(pxr::HdSceneDelegate *scene_delegate, Object *object) +LightData::LightData(BlenderSceneDelegate *scene_delegate, Object *object) : ObjectData(scene_delegate, object) { Light *light = (Light *)((Object *)id)->data; - data[HdLightTokens->intensity] = light->energy; + data[HdLightTokens->intensity] = scene_delegate->get_engine_type() == Engine::EngineType::Preview + ? light->energy / 1000 + : light->energy; + data[HdLightTokens->color] = GfVec3f(light->r, light->g, light->b); switch (light->type) { diff --git a/source/blender/render/hydra/sceneDelegate/light.h b/source/blender/render/hydra/sceneDelegate/light.h index 794a0deee730..c961dff9c1bc 100644 --- a/source/blender/render/hydra/sceneDelegate/light.h +++ b/source/blender/render/hydra/sceneDelegate/light.h @@ -13,7 +13,7 @@ namespace blender::render::hydra { class LightData: public ObjectData { public: - LightData(pxr::HdSceneDelegate *scene_delegate, Object *object); + LightData(BlenderSceneDelegate *scene_delegate, Object *object); pxr::VtValue get_data(pxr::TfToken const &key) override; void insert_prim() override; diff --git a/source/blender/render/hydra/sceneDelegate/material.cc b/source/blender/render/hydra/sceneDelegate/material.cc index 492157bfa5cd..b4aaa276beac 100644 --- a/source/blender/render/hydra/sceneDelegate/material.cc +++ b/source/blender/render/hydra/sceneDelegate/material.cc @@ -11,18 +11,19 @@ #include "BKE_material.h" #include "BKE_lib_id.h" +#include "blenderSceneDelegate.h" #include "material.h" using namespace pxr; namespace blender::render::hydra { -std::unique_ptr MaterialData::init(pxr::HdSceneDelegate *scene_delegate, Material *material) +std::unique_ptr MaterialData::init(BlenderSceneDelegate *scene_delegate, Material *material) { return std::make_unique(scene_delegate, material); } -pxr::SdfPath MaterialData::prim_id(pxr::HdSceneDelegate *scene_delegate, Material *material) +pxr::SdfPath MaterialData::prim_id(BlenderSceneDelegate *scene_delegate, Material *material) { /* Making id of material in form like M_. * Example: M_000002074e812088 */ @@ -31,7 +32,7 @@ pxr::SdfPath MaterialData::prim_id(pxr::HdSceneDelegate *scene_delegate, Materia return scene_delegate->GetDelegateID().AppendElementString(str); } -MaterialData::MaterialData(pxr::HdSceneDelegate *scene_delegate, Material *material) +MaterialData::MaterialData(BlenderSceneDelegate *scene_delegate, Material *material) : IdData(scene_delegate, (ID *)material) { } diff --git a/source/blender/render/hydra/sceneDelegate/material.h b/source/blender/render/hydra/sceneDelegate/material.h index 17a21382a270..edab709b01a1 100644 --- a/source/blender/render/hydra/sceneDelegate/material.h +++ b/source/blender/render/hydra/sceneDelegate/material.h @@ -15,10 +15,10 @@ namespace blender::render::hydra { class MaterialData: IdData { public: - static std::unique_ptr init(pxr::HdSceneDelegate *scene_delegate, Material *material); - static pxr::SdfPath prim_id(pxr::HdSceneDelegate *scene_delegate, Material *material); + static std::unique_ptr init(BlenderSceneDelegate *scene_delegate, Material *material); + static pxr::SdfPath prim_id(BlenderSceneDelegate *scene_delegate, Material *material); - MaterialData(pxr::HdSceneDelegate *scene_delegate, Material *material); + MaterialData(BlenderSceneDelegate *scene_delegate, Material *material); pxr::VtValue get_data(pxr::TfToken const &key) override; void insert_prim() override; diff --git a/source/blender/render/hydra/sceneDelegate/mesh.cc b/source/blender/render/hydra/sceneDelegate/mesh.cc index 51d190992ecc..735f4da19ff0 100644 --- a/source/blender/render/hydra/sceneDelegate/mesh.cc +++ b/source/blender/render/hydra/sceneDelegate/mesh.cc @@ -11,14 +11,14 @@ #include "BKE_object.h" #include "BKE_material.h" - +#include "blenderSceneDelegate.h" #include "mesh.h" using namespace pxr; namespace blender::render::hydra { -MeshData::MeshData(pxr::HdSceneDelegate *scene_delegate, Object *object) +MeshData::MeshData(BlenderSceneDelegate *scene_delegate, Object *object) : ObjectData(scene_delegate, object) { if (object->type == OB_MESH && object->mode == OB_MODE_OBJECT && diff --git a/source/blender/render/hydra/sceneDelegate/mesh.h b/source/blender/render/hydra/sceneDelegate/mesh.h index 194ed2879cd6..d67ffa2afc87 100644 --- a/source/blender/render/hydra/sceneDelegate/mesh.h +++ b/source/blender/render/hydra/sceneDelegate/mesh.h @@ -12,7 +12,7 @@ namespace blender::render::hydra { class MeshData: public ObjectData { public: - MeshData(pxr::HdSceneDelegate *scene_delegate, Object *object); + MeshData(BlenderSceneDelegate *scene_delegate, Object *object); pxr::VtValue get_data(pxr::TfToken const &key) override; diff --git a/source/blender/render/hydra/sceneDelegate/object.cc b/source/blender/render/hydra/sceneDelegate/object.cc index 96552c12743b..bc6012f6f51b 100644 --- a/source/blender/render/hydra/sceneDelegate/object.cc +++ b/source/blender/render/hydra/sceneDelegate/object.cc @@ -3,6 +3,7 @@ #include "BKE_object.h" +#include "blenderSceneDelegate.h" #include "object.h" #include "mesh.h" #include "light.h" @@ -30,7 +31,7 @@ bool ObjectData::supported(Object *object) return false; } -std::unique_ptr ObjectData::init(pxr::HdSceneDelegate *scene_delegate, Object *object) +std::unique_ptr ObjectData::init(BlenderSceneDelegate *scene_delegate, Object *object) { switch (object->type) { case OB_MESH: @@ -50,7 +51,7 @@ std::unique_ptr ObjectData::init(pxr::HdSceneDelegate *scene_delegat return nullptr; } -pxr::SdfPath ObjectData::prim_id(pxr::HdSceneDelegate *scene_delegate, Object *object) +pxr::SdfPath ObjectData::prim_id(BlenderSceneDelegate *scene_delegate, Object *object) { /* Making id of object in form like O_. Example: * O_000002073e369608 */ @@ -59,7 +60,7 @@ pxr::SdfPath ObjectData::prim_id(pxr::HdSceneDelegate *scene_delegate, Object *o return scene_delegate->GetDelegateID().AppendElementString(str); } -ObjectData::ObjectData(pxr::HdSceneDelegate *scene_delegate, Object *object) +ObjectData::ObjectData(BlenderSceneDelegate *scene_delegate, Object *object) : IdData(scene_delegate, (ID *)object) , visible(true) { diff --git a/source/blender/render/hydra/sceneDelegate/object.h b/source/blender/render/hydra/sceneDelegate/object.h index f787733355b4..3b55ede62bfa 100644 --- a/source/blender/render/hydra/sceneDelegate/object.h +++ b/source/blender/render/hydra/sceneDelegate/object.h @@ -17,10 +17,10 @@ namespace blender::render::hydra { class ObjectData: public IdData { public: static bool supported(Object *object); - static std::unique_ptr init(pxr::HdSceneDelegate *scene_delegate, Object *object); - static pxr::SdfPath prim_id(pxr::HdSceneDelegate *scene_delegate, Object *object); + static std::unique_ptr init(BlenderSceneDelegate *scene_delegate, Object *object); + static pxr::SdfPath prim_id(BlenderSceneDelegate *scene_delegate, Object *object); - ObjectData(pxr::HdSceneDelegate *scene_delegate, Object *object); + ObjectData(BlenderSceneDelegate *scene_delegate, Object *object); int type(); pxr::GfMatrix4d transform(); diff --git a/source/blender/render/hydra/sceneDelegate/world.cc b/source/blender/render/hydra/sceneDelegate/world.cc index 290eca4f5568..43bdbafaa129 100644 --- a/source/blender/render/hydra/sceneDelegate/world.cc +++ b/source/blender/render/hydra/sceneDelegate/world.cc @@ -22,6 +22,7 @@ #include "glog/logging.h" +#include "blenderSceneDelegate.h" #include "world.h" #include "../utils.h" @@ -31,18 +32,18 @@ using namespace pxr; namespace blender::render::hydra { -std::unique_ptr WorldData::init(pxr::HdSceneDelegate *scene_delegate, +std::unique_ptr WorldData::init(BlenderSceneDelegate *scene_delegate, World *world, bContext *context) { return std::make_unique(scene_delegate, world, context); } -SdfPath WorldData::prim_id(HdSceneDelegate *scene_delegate) +SdfPath WorldData::prim_id(BlenderSceneDelegate *scene_delegate) { return scene_delegate->GetDelegateID().AppendElementString("World"); } -WorldData::WorldData(pxr::HdSceneDelegate *scene_delegate, World *world, bContext *context) +WorldData::WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContext *context) : IdData(scene_delegate, (ID *)world) { data[UsdLuxTokens->orientToStageUpAxis] = true; diff --git a/source/blender/render/hydra/sceneDelegate/world.h b/source/blender/render/hydra/sceneDelegate/world.h index 04a08b29ed09..3a4561716c4b 100644 --- a/source/blender/render/hydra/sceneDelegate/world.h +++ b/source/blender/render/hydra/sceneDelegate/world.h @@ -20,10 +20,10 @@ namespace blender::render::hydra { class WorldData: public IdData { public: - static std::unique_ptr init(pxr::HdSceneDelegate *scene_delegate, World *world, bContext *context); - static pxr::SdfPath prim_id(pxr::HdSceneDelegate *scene_delegate); + static std::unique_ptr init(BlenderSceneDelegate *scene_delegate, World *world, bContext *context); + static pxr::SdfPath prim_id(BlenderSceneDelegate *scene_delegate); - WorldData(pxr::HdSceneDelegate *scene_delegate, World *world, bContext *context); + WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContext *context); pxr::GfMatrix4d transform(); diff --git a/source/blender/render/hydra/viewportEngine.cc b/source/blender/render/hydra/viewportEngine.cc index 09f43af10f61..50874baf82ff 100644 --- a/source/blender/render/hydra/viewportEngine.cc +++ b/source/blender/render/hydra/viewportEngine.cc @@ -12,6 +12,7 @@ #include "glog/logging.h" +#include "sceneDelegate/blenderSceneDelegate.h" #include "viewportEngine.h" #include "camera.h" #include "utils.h" @@ -244,7 +245,7 @@ void ViewportEngine::sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, Hd { if (!sceneDelegate) { sceneDelegate = std::make_unique(renderIndex.get(), - SdfPath::AbsoluteRootPath().AppendElementString("scene")); + SdfPath::AbsoluteRootPath().AppendElementString("scene"), EngineType::Viewport); } sceneDelegate->populate((Depsgraph *)b_depsgraph.ptr.data, (bContext *)b_context.ptr.data); -- 2.30.2 From f2a3093d8e5c2d1b41d90a31fcfd1cdf77b59e29 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Fri, 3 Mar 2023 12:47:37 +0300 Subject: [PATCH 5/5] fix review comments --- source/blender/render/hydra/engine.cc | 1 - source/blender/render/hydra/engine.h | 9 +-------- source/blender/render/hydra/finalEngine.cc | 3 +-- source/blender/render/hydra/previewEngine.cc | 11 +---------- source/blender/render/hydra/previewEngine.h | 3 --- .../hydra/sceneDelegate/blenderSceneDelegate.cc | 7 +------ .../hydra/sceneDelegate/blenderSceneDelegate.h | 14 +++++++++----- source/blender/render/hydra/sceneDelegate/light.cc | 2 +- source/blender/render/hydra/viewportEngine.cc | 3 +-- 9 files changed, 15 insertions(+), 38 deletions(-) diff --git a/source/blender/render/hydra/engine.cc b/source/blender/render/hydra/engine.cc index 80e8871c9d83..5716901e8879 100644 --- a/source/blender/render/hydra/engine.cc +++ b/source/blender/render/hydra/engine.cc @@ -9,7 +9,6 @@ #include "glog/logging.h" -#include "sceneDelegate/blenderSceneDelegate.h" #include "engine.h" using namespace pxr; diff --git a/source/blender/render/hydra/engine.h b/source/blender/render/hydra/engine.h index b2388b816669..8b861c9e86fd 100644 --- a/source/blender/render/hydra/engine.h +++ b/source/blender/render/hydra/engine.h @@ -16,20 +16,13 @@ #include "MEM_guardedalloc.h" #include "RNA_blender_cpp.h" +#include "sceneDelegate/blenderSceneDelegate.h" #include "renderTaskDelegate.h" namespace blender::render::hydra { -class BlenderSceneDelegate; - class Engine { public: - enum class EngineType { - Viewport = 1, - Final, - Preview - }; - Engine(BL::RenderEngine &b_engine, const std::string &delegateId); virtual ~Engine(); diff --git a/source/blender/render/hydra/finalEngine.cc b/source/blender/render/hydra/finalEngine.cc index e0b4b7e2e087..4e01048eae8d 100644 --- a/source/blender/render/hydra/finalEngine.cc +++ b/source/blender/render/hydra/finalEngine.cc @@ -10,7 +10,6 @@ #include "glog/logging.h" -#include "sceneDelegate/blenderSceneDelegate.h" #include "finalEngine.h" #include "camera.h" #include "utils.h" @@ -23,7 +22,7 @@ namespace blender::render::hydra { void FinalEngine::sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, HdRenderSettingsMap &renderSettings) { sceneDelegate = std::make_unique(renderIndex.get(), - SdfPath::AbsoluteRootPath().AppendElementString("scene"), EngineType::Final); + SdfPath::AbsoluteRootPath().AppendElementString("scene"), BlenderSceneDelegate::EngineType::Final); sceneDelegate->populate((Depsgraph *)b_depsgraph.ptr.data, (bContext *)b_context.ptr.data); for (auto const& setting : renderSettings) { diff --git a/source/blender/render/hydra/previewEngine.cc b/source/blender/render/hydra/previewEngine.cc index 79f045aed964..838eb07f1598 100644 --- a/source/blender/render/hydra/previewEngine.cc +++ b/source/blender/render/hydra/previewEngine.cc @@ -3,7 +3,6 @@ #include -#include "sceneDelegate/blenderSceneDelegate.h" #include "previewEngine.h" #include "camera.h" @@ -14,25 +13,17 @@ namespace blender::render::hydra { void PreviewEngine::sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, HdRenderSettingsMap &renderSettings) { - is_synced = false; - sceneDelegate = std::make_unique(renderIndex.get(), - SdfPath::AbsoluteRootPath().AppendElementString("scene"), EngineType::Preview); + SdfPath::AbsoluteRootPath().AppendElementString("scene"), BlenderSceneDelegate::EngineType::Preview); sceneDelegate->populate((Depsgraph *)b_depsgraph.ptr.data, (bContext *)b_context.ptr.data); for (auto const& setting : renderSettings) { renderDelegate->SetRenderSetting(setting.first, setting.second); } - - is_synced = true; } void PreviewEngine::render(BL::Depsgraph &b_depsgraph) { - if (!is_synced) { - return; - } - BL::Scene b_scene = b_depsgraph.scene(); string layerName = b_depsgraph.view_layer().name(); GfVec2i buffer_res {b_scene.render().resolution_x(), diff --git a/source/blender/render/hydra/previewEngine.h b/source/blender/render/hydra/previewEngine.h index 63bb7c802d80..13722e46737e 100644 --- a/source/blender/render/hydra/previewEngine.h +++ b/source/blender/render/hydra/previewEngine.h @@ -18,9 +18,6 @@ namespace blender::render::hydra { protected: HdRenderSettingsMap renderSettings; - - private: - bool is_synced; }; } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.cc b/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.cc index 6887eda8a624..f245f34be6d8 100644 --- a/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.cc +++ b/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.cc @@ -12,7 +12,7 @@ using namespace pxr; namespace blender::render::hydra { -BlenderSceneDelegate::BlenderSceneDelegate(HdRenderIndex* parentIndex, SdfPath const& delegateID, Engine::EngineType engine_type) +BlenderSceneDelegate::BlenderSceneDelegate(HdRenderIndex* parentIndex, SdfPath const& delegateID, BlenderSceneDelegate::EngineType engine_type) : HdSceneDelegate(parentIndex, delegateID) , depsgraph(nullptr) , context(nullptr) @@ -310,11 +310,6 @@ void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont) } } -Engine::EngineType BlenderSceneDelegate::get_engine_type() -{ - return engine_type; -} - HdMeshTopology BlenderSceneDelegate::GetMeshTopology(SdfPath const& id) { MeshData *m_data = mesh_data(id); diff --git a/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.h b/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.h index b50957c88086..132619b944f1 100644 --- a/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.h +++ b/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.h @@ -13,17 +13,21 @@ #include "light.h" #include "world.h" #include "instance.h" -#include "../engine.h" namespace blender::render::hydra { class BlenderSceneDelegate : public pxr::HdSceneDelegate { public: - BlenderSceneDelegate(pxr::HdRenderIndex *renderIndex, pxr::SdfPath const &delegateId, Engine::EngineType engine_type); + enum class EngineType { + Viewport = 1, + Final, + Preview + }; + + BlenderSceneDelegate(pxr::HdRenderIndex *renderIndex, pxr::SdfPath const &delegateId, BlenderSceneDelegate::EngineType engine_type); ~BlenderSceneDelegate() override = default; void populate(Depsgraph *depsgraph, bContext *context); - Engine::EngineType get_engine_type(); // delegate methods pxr::HdMeshTopology GetMeshTopology(pxr::SdfPath const &id) override; @@ -35,6 +39,8 @@ public: pxr::VtValue GetMaterialResource(pxr::SdfPath const &materialId) override; bool GetVisible(pxr::SdfPath const &id) override; + EngineType engine_type; + private: ObjectData *object_data(pxr::SdfPath const &id); MeshData *mesh_data(pxr::SdfPath const &id); @@ -56,8 +62,6 @@ private: MaterialDataMap materials; std::unique_ptr world_data; InstanceDataMap instances; - - Engine::EngineType engine_type; }; } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/sceneDelegate/light.cc b/source/blender/render/hydra/sceneDelegate/light.cc index b0b67df1975a..0c1ddd549ae1 100644 --- a/source/blender/render/hydra/sceneDelegate/light.cc +++ b/source/blender/render/hydra/sceneDelegate/light.cc @@ -25,7 +25,7 @@ LightData::LightData(BlenderSceneDelegate *scene_delegate, Object *object) { Light *light = (Light *)((Object *)id)->data; - data[HdLightTokens->intensity] = scene_delegate->get_engine_type() == Engine::EngineType::Preview + data[HdLightTokens->intensity] = scene_delegate->engine_type == BlenderSceneDelegate::EngineType::Preview ? light->energy / 1000 : light->energy; diff --git a/source/blender/render/hydra/viewportEngine.cc b/source/blender/render/hydra/viewportEngine.cc index 50874baf82ff..849fc3c089e3 100644 --- a/source/blender/render/hydra/viewportEngine.cc +++ b/source/blender/render/hydra/viewportEngine.cc @@ -12,7 +12,6 @@ #include "glog/logging.h" -#include "sceneDelegate/blenderSceneDelegate.h" #include "viewportEngine.h" #include "camera.h" #include "utils.h" @@ -245,7 +244,7 @@ void ViewportEngine::sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, Hd { if (!sceneDelegate) { sceneDelegate = std::make_unique(renderIndex.get(), - SdfPath::AbsoluteRootPath().AppendElementString("scene"), EngineType::Viewport); + SdfPath::AbsoluteRootPath().AppendElementString("scene"), BlenderSceneDelegate::EngineType::Viewport); } sceneDelegate->populate((Depsgraph *)b_depsgraph.ptr.data, (bContext *)b_context.ptr.data); -- 2.30.2