From ad5d8da198f06eb5596ed193d699a101b0b91bdb Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Mon, 13 Mar 2023 17:31:29 +0300 Subject: [PATCH 01/11] run make format --- source/blender/render/hydra/camera.cc | 9 +- source/blender/render/hydra/camera.h | 6 +- source/blender/render/hydra/engine.cc | 17 ++-- source/blender/render/hydra/engine.h | 16 ++-- source/blender/render/hydra/finalEngine.cc | 70 ++++++++++------ source/blender/render/hydra/finalEngine.h | 17 ++-- source/blender/render/hydra/previewEngine.cc | 32 ++++--- source/blender/render/hydra/previewEngine.h | 29 ++++--- source/blender/render/hydra/python.cc | 59 ++++++------- .../render/hydra/renderTaskDelegate.cc | 28 ++++--- .../blender/render/hydra/renderTaskDelegate.h | 13 ++- .../sceneDelegate/blenderSceneDelegate.cc | 72 +++++++++------- .../sceneDelegate/blenderSceneDelegate.h | 41 +++++---- .../blender/render/hydra/sceneDelegate/id.cc | 5 +- .../blender/render/hydra/sceneDelegate/id.h | 11 +-- .../render/hydra/sceneDelegate/light.cc | 11 +-- .../render/hydra/sceneDelegate/light.h | 6 +- .../render/hydra/sceneDelegate/material.cc | 11 +-- .../render/hydra/sceneDelegate/material.h | 14 ++-- .../render/hydra/sceneDelegate/mesh.cc | 31 ++++--- .../blender/render/hydra/sceneDelegate/mesh.h | 17 ++-- .../hydra/sceneDelegate/mtlxHydraAdapter.cc | 2 +- .../render/hydra/sceneDelegate/object.cc | 11 ++- .../render/hydra/sceneDelegate/object.h | 13 +-- .../render/hydra/sceneDelegate/world.cc | 17 ++-- .../render/hydra/sceneDelegate/world.h | 14 ++-- source/blender/render/hydra/utils.cc | 34 +++++--- source/blender/render/hydra/utils.h | 2 +- source/blender/render/hydra/viewportEngine.cc | 83 +++++++++++-------- source/blender/render/hydra/viewportEngine.h | 19 +++-- 30 files changed, 403 insertions(+), 307 deletions(-) diff --git a/source/blender/render/hydra/camera.cc b/source/blender/render/hydra/camera.cc index d7df196cbbb7..48473f700287 100644 --- a/source/blender/render/hydra/camera.cc +++ b/source/blender/render/hydra/camera.cc @@ -1,9 +1,9 @@ /* SPDX-License-Identifier: Apache-2.0 * Copyright 2011-2022 Blender Foundation */ +#include "BKE_context.h" #include "DNA_camera_types.h" #include "DNA_screen_types.h" -#include "BKE_context.h" #include "camera.h" #include "utils.h" @@ -35,9 +35,8 @@ CameraData::CameraData(Object *camera_obj, GfVec2i res, GfVec4f tile) focus_distance = (obj_pos - cam_pos).GetLength(); } - dof_data = std::tuple(std::max(focus_distance, 0.001f), - camera->dof.aperture_fstop, - camera->dof.aperture_blades); + dof_data = std::tuple( + std::max(focus_distance, 0.001f), camera->dof.aperture_fstop, camera->dof.aperture_blades); } float ratio = (float)res[0] / res[1]; @@ -277,4 +276,4 @@ GfCamera CameraData::gf_camera() return gf_camera(GfVec4f(0, 0, 1, 1)); } -} // namespace blender::render::hydra +} // namespace blender::render::hydra diff --git a/source/blender/render/hydra/camera.h b/source/blender/render/hydra/camera.h index 8378574d92df..3310f2403f44 100644 --- a/source/blender/render/hydra/camera.h +++ b/source/blender/render/hydra/camera.h @@ -13,14 +13,14 @@ namespace blender::render::hydra { class CameraData { -public: + public: CameraData(bContext *context); CameraData(Object *camera_obj, pxr::GfVec2i res, pxr::GfVec4f tile); pxr::GfCamera gf_camera(); pxr::GfCamera gf_camera(pxr::GfVec4f tile); -private: + private: int mode; pxr::GfRange1f clip_range; float focal_length; @@ -31,4 +31,4 @@ private: std::tuple dof_data; }; -} // namespace blender::render::hydra +} // namespace blender::render::hydra diff --git a/source/blender/render/hydra/engine.cc b/source/blender/render/hydra/engine.cc index 98836094ba9e..19cac0fabc85 100644 --- a/source/blender/render/hydra/engine.cc +++ b/source/blender/render/hydra/engine.cc @@ -1,11 +1,11 @@ /* SPDX-License-Identifier: Apache-2.0 * Copyright 2011-2022 Blender Foundation */ +#include +#include #include #include #include -#include -#include #include #include "glog/logging.h" @@ -16,10 +16,9 @@ using namespace pxr; namespace blender::render::hydra { -Engine::Engine(RenderEngine *bl_engine, const std::string &delegateId) - : bl_engine(bl_engine) +Engine::Engine(RenderEngine *bl_engine, const std::string &delegateId) : bl_engine(bl_engine) { - HdRendererPluginRegistry& registry = HdRendererPluginRegistry::GetInstance(); + HdRendererPluginRegistry ®istry = HdRendererPluginRegistry::GetInstance(); TF_PY_ALLOW_THREADS_IN_SCOPE(); render_delegate = registry.CreateRenderDelegate(TfToken(delegateId)); @@ -27,7 +26,7 @@ Engine::Engine(RenderEngine *bl_engine, const std::string &delegateId) HdDriverVector hd_drivers; if (bl_engine->type->flag & RE_USE_GPU_CONTEXT) { hgi = Hgi::CreatePlatformDefaultHgi(); - hgi_driver.name = HgiTokens->renderDriver; + hgi_driver.name = HgiTokens->renderDriver; hgi_driver.driver = VtValue(hgi.get()); hd_drivers.push_back(&hgi_driver); @@ -35,9 +34,9 @@ Engine::Engine(RenderEngine *bl_engine, const std::string &delegateId) render_index.reset(HdRenderIndex::New(render_delegate.Get(), hd_drivers)); free_camera_delegate = std::make_unique( - render_index.get(), SdfPath::AbsoluteRootPath().AppendElementString("freeCamera")); + render_index.get(), SdfPath::AbsoluteRootPath().AppendElementString("freeCamera")); render_task_delegate = std::make_unique( - render_index.get(), SdfPath::AbsoluteRootPath().AppendElementString("renderTask")); + render_index.get(), SdfPath::AbsoluteRootPath().AppendElementString("renderTask")); if (render_delegate->GetRendererDisplayName() == "GL") { simple_light_task_delegate = std::make_unique( render_index.get(), SdfPath::AbsoluteRootPath().AppendElementString("simpleLightTask")); @@ -68,4 +67,4 @@ float Engine::renderer_percent_done() return (float)it->second.UncheckedGet(); } -} // namespace blender::render::hydra +} // namespace blender::render::hydra diff --git a/source/blender/render/hydra/engine.h b/source/blender/render/hydra/engine.h index f04af09bc90f..0b38b6a0e515 100644 --- a/source/blender/render/hydra/engine.h +++ b/source/blender/render/hydra/engine.h @@ -7,32 +7,34 @@ #include +#include #include #include -#include #include #include #include "RE_engine.h" -#include "sceneDelegate/blenderSceneDelegate.h" #include "renderTaskDelegate.h" +#include "sceneDelegate/blenderSceneDelegate.h" #include "simpleLightTaskDelegate.h" namespace blender::render::hydra { class Engine { -public: + public: Engine(RenderEngine *bl_engine, const std::string &render_delegate_id); virtual ~Engine(); - virtual void sync(Depsgraph *depsgraph, bContext *context, pxr::HdRenderSettingsMap &renderSettings) = 0; + virtual void sync(Depsgraph *depsgraph, + bContext *context, + pxr::HdRenderSettingsMap &renderSettings) = 0; virtual void render(Depsgraph *depsgraph) = 0; -protected: + protected: float renderer_percent_done(); -protected: + protected: RenderEngine *bl_engine; HdPluginRenderDelegateUniqueHandle render_delegate; @@ -47,4 +49,4 @@ protected: HdDriver hgi_driver; }; -} // namespace blender::render::hydra +} // namespace blender::render::hydra diff --git a/source/blender/render/hydra/finalEngine.cc b/source/blender/render/hydra/finalEngine.cc index 216689d1a473..e8917f199b64 100644 --- a/source/blender/render/hydra/finalEngine.cc +++ b/source/blender/render/hydra/finalEngine.cc @@ -3,13 +3,13 @@ #include -#include "DEG_depsgraph_query.h" #include "BKE_lib_id.h" +#include "DEG_depsgraph_query.h" #include "glog/logging.h" -#include "finalEngine.h" #include "camera.h" +#include "finalEngine.h" #include "utils.h" using namespace std; @@ -17,13 +17,17 @@ using namespace pxr; namespace blender::render::hydra { -void FinalEngine::sync(Depsgraph *depsgraph, bContext *context, HdRenderSettingsMap &renderSettings) +void FinalEngine::sync(Depsgraph *depsgraph, + bContext *context, + HdRenderSettingsMap &renderSettings) { - scene_delegate = std::make_unique(render_index.get(), - SdfPath::AbsoluteRootPath().AppendElementString("scene"), BlenderSceneDelegate::EngineType::Final); + scene_delegate = std::make_unique( + render_index.get(), + SdfPath::AbsoluteRootPath().AppendElementString("scene"), + BlenderSceneDelegate::EngineType::Final); scene_delegate->populate(depsgraph, context); - for (auto const& setting : renderSettings) { + for (auto const &setting : renderSettings) { render_delegate->SetRenderSetting(setting.first, setting.second); } } @@ -40,15 +44,18 @@ void FinalEngine::render(Depsgraph *depsgraph) RenderData &r = scene->r; GfVec4f border(0, 0, 1, 1); if (r.mode & R_BORDER) { - border = GfVec4f(r.border.xmin, r.border.ymin, - r.border.xmax - r.border.xmin, r.border.ymax - r.border.ymin); + border = GfVec4f(r.border.xmin, + r.border.ymin, + r.border.xmax - r.border.xmin, + r.border.ymax - r.border.ymin); } GfVec2i image_res(r.xsch * r.size / 100, r.ysch * r.size / 100); GfVec2i res(int(image_res[0] * border[2]), int(image_res[1] * border[3])); - GfCamera camera = CameraData(scene->camera, image_res, GfVec4f(0, 0, 1, 1)).gf_camera(border); + GfCamera camera = CameraData(scene->camera, image_res, GfVec4f(0, 0, 1, 1)).gf_camera(border); free_camera_delegate->SetCamera(camera); - render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(), GfVec4d(0, 0, res[0], res[1])); + render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(), + GfVec4d(0, 0, res[0], res[1])); render_task_delegate->SetRendererAov(HdAovTokens->color); if (simple_light_task_delegate) { simple_light_task_delegate->SetCameraPath(free_camera_delegate->GetCameraId()); @@ -66,7 +73,7 @@ void FinalEngine::render(Depsgraph *depsgraph) float percentDone = 0.0; map> renderImages{ - {"Combined", vector(res[0] * res[1] * 4)}}; // 4 - number of channels + {"Combined", vector(res[0] * res[1] * 4)}}; // 4 - number of channels vector &pixels = renderImages["Combined"]; { @@ -84,8 +91,10 @@ void FinalEngine::render(Depsgraph *depsgraph) timeCurrent = chrono::steady_clock::now(); elapsedTime = chrono::duration_cast(timeCurrent - timeBegin); - notify_status(percentDone / 100.0, scene_name + ": " + layer_name, - "Render Time: " + format_duration(elapsedTime) + " | Done: " + to_string(int(percentDone)) + "%"); + notify_status(percentDone / 100.0, + scene_name + ": " + layer_name, + "Render Time: " + format_duration(elapsedTime) + + " | Done: " + to_string(int(percentDone)) + "%"); if (render_task_delegate->IsConverged()) { break; @@ -110,9 +119,13 @@ GfVec2i FinalEngine::get_resolution(Scene *scene) return GfVec2i(int(r.xsch * border_w * r.size / 100), int(r.ysch * border_h * r.size / 100)); } -void FinalEngine::updateRenderResult(map>& renderImages, const string &layerName, int width, int height) +void FinalEngine::updateRenderResult(map> &renderImages, + const string &layerName, + int width, + int height) { - RenderResult *result = RE_engine_begin_result(bl_engine, 0, 0, width, height, layerName.c_str(), nullptr); + RenderResult *result = RE_engine_begin_result( + bl_engine, 0, 0, width, height, layerName.c_str(), nullptr); /* TODO: only for the first render layer */ RenderLayer *layer = (RenderLayer *)result->layers.first; @@ -121,7 +134,8 @@ void FinalEngine::updateRenderResult(map>& renderImages, c if (it_image == renderImages.end()) { continue; } - memcpy(pass->rect, it_image->second.data(), + memcpy(pass->rect, + it_image->second.data(), sizeof(float) * pass->rectx * pass->recty * pass->channels); } @@ -138,7 +152,7 @@ void FinalEngineGL::render(Depsgraph *depsgraph) { Scene *scene = DEG_get_input_scene(depsgraph); ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph); - + string scene_name(MAX_ID_FULL_NAME, 0); BKE_id_full_name_get(scene_name.data(), (ID *)scene, 0); string layer_name = view_layer->name; @@ -146,17 +160,18 @@ void FinalEngineGL::render(Depsgraph *depsgraph) RenderData &r = scene->r; GfVec4f border(0, 0, 1, 1); if (r.mode & R_BORDER) { - border = GfVec4f(r.border.xmin, r.border.ymin, - r.border.xmax - r.border.xmin, r.border.ymax - r.border.ymin); + border = GfVec4f(r.border.xmin, + r.border.ymin, + r.border.xmax - r.border.xmin, + r.border.ymax - r.border.ymin); } GfVec2i image_res = {r.xsch * r.size / 100, r.ysch * r.size / 100}; GfVec2i res = {int(image_res[0] * border[2]), int(image_res[1] * border[3])}; - GfCamera camera = CameraData(scene->camera, image_res, GfVec4f(0, 0, 1, 1)).gf_camera(border); - + GfCamera camera = CameraData(scene->camera, image_res, GfVec4f(0, 0, 1, 1)).gf_camera(border); free_camera_delegate->SetCamera(camera); render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(), - GfVec4d(0, 0, res[0], res[1])); + GfVec4d(0, 0, res[0], res[1])); if (simple_light_task_delegate) { simple_light_task_delegate->SetCameraPath(free_camera_delegate->GetCameraId()); } @@ -164,7 +179,8 @@ void FinalEngineGL::render(Depsgraph *depsgraph) HdTaskSharedPtrVector tasks; if (simple_light_task_delegate) { /* TODO: Uncomment this and fix GL error: - invalid operation, reported from void __cdecl pxrInternal_v0_22__pxrReserved__::HgiGLResourceBindings::BindResources(void) */ + invalid operation, reported from void __cdecl + pxrInternal_v0_22__pxrReserved__::HgiGLResourceBindings::BindResources(void) */ // tasks.push_back(simple_light_task_delegate->GetTask()); } tasks.push_back(render_task_delegate->GetTask()); @@ -220,9 +236,9 @@ void FinalEngineGL::render(Depsgraph *depsgraph) elapsedTime = chrono::duration_cast(timeCurrent - timeBegin); notify_status(percentDone / 100.0, - scene_name + ": " + layer_name, - "Render Time: " + format_duration(elapsedTime) + - " | Done: " + to_string(int(percentDone)) + "%"); + scene_name + ": " + layer_name, + "Render Time: " + format_duration(elapsedTime) + + " | Done: " + to_string(int(percentDone)) + "%"); if (render_task_delegate->IsConverged()) { break; @@ -236,4 +252,4 @@ void FinalEngineGL::render(Depsgraph *depsgraph) updateRenderResult(renderImages, layer_name, res[0], res[1]); } -} // namespace blender::render::hydra +} // namespace blender::render::hydra diff --git a/source/blender/render/hydra/finalEngine.h b/source/blender/render/hydra/finalEngine.h index edf3dde45b67..591fa7326953 100644 --- a/source/blender/render/hydra/finalEngine.h +++ b/source/blender/render/hydra/finalEngine.h @@ -10,17 +10,22 @@ namespace blender::render::hydra { class FinalEngine : public Engine { -public: + public: using Engine::Engine; - virtual void sync(Depsgraph *depsgraph, bContext *context, pxr::HdRenderSettingsMap &renderSettings) override; + virtual void sync(Depsgraph *depsgraph, + bContext *context, + pxr::HdRenderSettingsMap &renderSettings) override; virtual void render(Depsgraph *b_depsgraph) override; -protected: + protected: pxr::GfVec2i get_resolution(Scene *scene); - void updateRenderResult(std::map> &render_images, const std::string &layerName, int width, int height); + void updateRenderResult(std::map> &render_images, + const std::string &layerName, + int width, + int height); void notify_status(float progress, const std::string &title, const std::string &info); -protected: + protected: HdRenderSettingsMap renderSettings; }; @@ -30,4 +35,4 @@ class FinalEngineGL : public FinalEngine { void render(Depsgraph *depsgraph) override; }; -} // namespace blender::render::hydra +} // namespace blender::render::hydra diff --git a/source/blender/render/hydra/previewEngine.cc b/source/blender/render/hydra/previewEngine.cc index 6f3e907b44ba..1f98b61bc5a3 100644 --- a/source/blender/render/hydra/previewEngine.cc +++ b/source/blender/render/hydra/previewEngine.cc @@ -1,23 +1,27 @@ /* SPDX-License-Identifier: Apache-2.0 -* Copyright 2011-2022 Blender Foundation */ + * Copyright 2011-2022 Blender Foundation */ #include "DEG_depsgraph_query.h" -#include "previewEngine.h" #include "camera.h" +#include "previewEngine.h" using namespace pxr; using namespace std; namespace blender::render::hydra { -void PreviewEngine::sync(Depsgraph *depsgraph, bContext *context, HdRenderSettingsMap &renderSettings) +void PreviewEngine::sync(Depsgraph *depsgraph, + bContext *context, + HdRenderSettingsMap &renderSettings) { - scene_delegate = make_unique(render_index.get(), - SdfPath::AbsoluteRootPath().AppendElementString("scene"), BlenderSceneDelegate::EngineType::Preview); + scene_delegate = make_unique( + render_index.get(), + SdfPath::AbsoluteRootPath().AppendElementString("scene"), + BlenderSceneDelegate::EngineType::Preview); scene_delegate->populate(depsgraph, context); - for (auto const& setting : renderSettings) { + for (auto const &setting : renderSettings) { render_delegate->SetRenderSetting(setting.first, setting.second); } } @@ -30,10 +34,12 @@ void PreviewEngine::render(Depsgraph *depsgraph) string layerName = view_layer->name; GfVec2i res(scene->r.xsch, scene->r.ysch); - GfCamera camera = CameraData(scene->camera, res, GfVec4f(0, 0, 1, 1)).gf_camera(GfVec4f(0, 0, 1, 1)); + GfCamera camera = + CameraData(scene->camera, res, GfVec4f(0, 0, 1, 1)).gf_camera(GfVec4f(0, 0, 1, 1)); free_camera_delegate->SetCamera(camera); - render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(), GfVec4d(0, 0, res[0], res[1])); + render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(), + GfVec4d(0, 0, res[0], res[1])); render_task_delegate->SetRendererAov(HdAovTokens->color); HdTaskSharedPtrVector tasks; @@ -67,9 +73,13 @@ void PreviewEngine::render(Depsgraph *depsgraph) updateRenderResult(layerName, res[0], res[1], pixels); } -void PreviewEngine::updateRenderResult(const string &layerName, int width, int height, vector &pixels) +void PreviewEngine::updateRenderResult(const string &layerName, + int width, + int height, + vector &pixels) { - RenderResult *result = RE_engine_begin_result(bl_engine, 0, 0, width, height, layerName.c_str(), nullptr); + RenderResult *result = RE_engine_begin_result( + bl_engine, 0, 0, width, height, layerName.c_str(), nullptr); RenderLayer *layer = (RenderLayer *)result->layers.first; RenderPass *pass = (RenderPass *)layer->passes.first; @@ -78,4 +88,4 @@ void PreviewEngine::updateRenderResult(const string &layerName, int width, int h RE_engine_end_result(bl_engine, result, false, false, false); } -} // namespace blender::render::hydra +} // namespace blender::render::hydra diff --git a/source/blender/render/hydra/previewEngine.h b/source/blender/render/hydra/previewEngine.h index f39c2e0c0ff7..5f1d3292567b 100644 --- a/source/blender/render/hydra/previewEngine.h +++ b/source/blender/render/hydra/previewEngine.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: Apache-2.0 -* Copyright 2011-2022 Blender Foundation */ + * Copyright 2011-2022 Blender Foundation */ #pragma once @@ -7,17 +7,22 @@ namespace blender::render::hydra { - class PreviewEngine : public FinalEngine { - public: - using FinalEngine::FinalEngine; - void sync(Depsgraph *depsgraph, bContext *context, pxr::HdRenderSettingsMap &renderSettings) override; - void render(Depsgraph *depsgraph) override; +class PreviewEngine : public FinalEngine { + public: + using FinalEngine::FinalEngine; + void sync(Depsgraph *depsgraph, + bContext *context, + pxr::HdRenderSettingsMap &renderSettings) override; + void render(Depsgraph *depsgraph) override; - protected: - void updateRenderResult(const std::string &layerName, int width, int height, std::vector &pixels); + protected: + void updateRenderResult(const std::string &layerName, + int width, + int height, + std::vector &pixels); - protected: - HdRenderSettingsMap renderSettings; - }; + protected: + HdRenderSettingsMap renderSettings; +}; -} // namespace blender::render::hydra +} // namespace blender::render::hydra diff --git a/source/blender/render/hydra/python.cc b/source/blender/render/hydra/python.cc index 5dfcc2beeb4f..8861680e5a0a 100644 --- a/source/blender/render/hydra/python.cc +++ b/source/blender/render/hydra/python.cc @@ -14,9 +14,9 @@ #include "glog/logging.h" #include "finalEngine.h" -#include "viewportEngine.h" #include "previewEngine.h" #include "utils.h" +#include "viewportEngine.h" using namespace std; @@ -47,7 +47,8 @@ static PyObject *init_func(PyObject * /*self*/, PyObject *args) { LOG(INFO) << "init_func"; - pxr::PlugRegistry::GetInstance().RegisterPlugins(string(BKE_appdir_program_dir()) + "/blender.shared/usd"); + pxr::PlugRegistry::GetInstance().RegisterPlugins(string(BKE_appdir_program_dir()) + + "/blender.shared/usd"); setup_usd_mtlx_environment(); @@ -108,8 +109,10 @@ static PyObject *get_render_plugins_func(PyObject * /*self*/, PyObject *args) PyDict_SetItemString(descr, "id", val = PyUnicode_FromString(plugin_ids[i].GetText())); Py_DECREF(val); - PyDict_SetItemString(descr, "name", - val = PyUnicode_FromString(UsdImagingGLEngine::GetRendererDisplayName(plugin_ids[i]).c_str())); + PyDict_SetItemString(descr, + "name", + val = PyUnicode_FromString( + UsdImagingGLEngine::GetRendererDisplayName(plugin_ids[i]).c_str())); Py_DECREF(val); string plugin_name = plugin_ids[i]; @@ -222,11 +225,10 @@ static PyObject *engine_render_func(PyObject * /*self*/, PyObject *args) Depsgraph *depsgraph = (Depsgraph *)PyLong_AsVoidPtr(pydepsgraph); /* Allow Blender to execute other Python scripts. */ - Py_BEGIN_ALLOW_THREADS - engine->render(depsgraph); + Py_BEGIN_ALLOW_THREADS engine->render(depsgraph); Py_END_ALLOW_THREADS - Py_RETURN_NONE; + Py_RETURN_NONE; } static PyObject *engine_view_draw_func(PyObject * /*self*/, PyObject *args) @@ -241,40 +243,39 @@ static PyObject *engine_view_draw_func(PyObject * /*self*/, PyObject *args) bContext *context = (bContext *)PyLong_AsVoidPtr(pycontext); /* Allow Blender to execute other Python scripts. */ - Py_BEGIN_ALLOW_THREADS - engine->render(depsgraph, context); + Py_BEGIN_ALLOW_THREADS engine->render(depsgraph, context); Py_END_ALLOW_THREADS - Py_RETURN_NONE; + Py_RETURN_NONE; } static PyMethodDef methods[] = { - {"init", init_func, METH_VARARGS, ""}, - {"register_plugins", register_plugins_func, METH_VARARGS, ""}, - {"get_render_plugins", get_render_plugins_func, METH_VARARGS, ""}, + {"init", init_func, METH_VARARGS, ""}, + {"register_plugins", register_plugins_func, METH_VARARGS, ""}, + {"get_render_plugins", get_render_plugins_func, METH_VARARGS, ""}, - {"engine_create", engine_create_func, METH_VARARGS, ""}, - {"engine_free", engine_free_func, METH_VARARGS, ""}, - {"engine_render", engine_render_func, METH_VARARGS, ""}, - {"engine_sync", engine_sync_func, METH_VARARGS, ""}, - {"engine_view_draw", engine_view_draw_func, METH_VARARGS, ""}, + {"engine_create", engine_create_func, METH_VARARGS, ""}, + {"engine_free", engine_free_func, METH_VARARGS, ""}, + {"engine_render", engine_render_func, METH_VARARGS, ""}, + {"engine_sync", engine_sync_func, METH_VARARGS, ""}, + {"engine_view_draw", engine_view_draw_func, METH_VARARGS, ""}, - {NULL, NULL, 0, NULL}, + {NULL, NULL, 0, NULL}, }; static struct PyModuleDef module = { - PyModuleDef_HEAD_INIT, - "_hydra", - "Hydra render API", - -1, - methods, - NULL, - NULL, - NULL, - NULL, + PyModuleDef_HEAD_INIT, + "_hydra", + "Hydra render API", + -1, + methods, + NULL, + NULL, + NULL, + NULL, }; -} // namespace blender::render::hydra +} // namespace blender::render::hydra #ifdef __cplusplus extern "C" { diff --git a/source/blender/render/hydra/renderTaskDelegate.cc b/source/blender/render/hydra/renderTaskDelegate.cc index 97fa139c1505..cdf9ca962768 100644 --- a/source/blender/render/hydra/renderTaskDelegate.cc +++ b/source/blender/render/hydra/renderTaskDelegate.cc @@ -13,13 +13,15 @@ namespace blender::render::hydra { -RenderTaskDelegate::RenderTaskDelegate(HdRenderIndex* parentIndex, SdfPath const& delegateID) +RenderTaskDelegate::RenderTaskDelegate(HdRenderIndex *parentIndex, SdfPath const &delegateID) : HdSceneDelegate(parentIndex, delegateID) { SdfPath renderTaskId = GetTaskID(); GetRenderIndex().InsertTask(this, renderTaskId); - GetRenderIndex().GetChangeTracker().MarkTaskDirty(renderTaskId, HdChangeTracker::DirtyCollection); - GetRenderIndex().GetChangeTracker().MarkTaskDirty(renderTaskId, HdChangeTracker::DirtyRenderTags); + GetRenderIndex().GetChangeTracker().MarkTaskDirty(renderTaskId, + HdChangeTracker::DirtyCollection); + GetRenderIndex().GetChangeTracker().MarkTaskDirty(renderTaskId, + HdChangeTracker::DirtyRenderTags); taskParams.enableLighting = true; taskParams.alphaThreshold = 0.1f; @@ -35,14 +37,15 @@ SdfPath RenderTaskDelegate::GetAovID(TfToken const &aov) const return GetDelegateID().AppendElementString("aov_" + aov.GetString()); } -VtValue RenderTaskDelegate::Get(SdfPath const& id, TfToken const& key) +VtValue RenderTaskDelegate::Get(SdfPath const &id, TfToken const &key) { LOG(INFO) << "RenderTaskDelegate::Get - " << id.GetAsString() << " " << key.GetString() << "\n"; if (key == HdTokens->params) { return VtValue(taskParams); } if (key == HdTokens->collection) { - HdRprimCollection rprimCollection(HdTokens->geometry, HdReprSelector(HdReprTokens->smoothHull), false, TfToken()); + HdRprimCollection rprimCollection( + HdTokens->geometry, HdReprSelector(HdReprTokens->smoothHull), false, TfToken()); rprimCollection.SetRootPath(SdfPath::AbsoluteRootPath()); return VtValue(rprimCollection); } @@ -58,7 +61,7 @@ HdRenderBufferDescriptor RenderTaskDelegate::GetRenderBufferDescriptor(SdfPath c TfTokenVector RenderTaskDelegate::GetTaskRenderTags(SdfPath const &taskId) { LOG(INFO) << "RenderTaskDelegate::GetTaskRenderTags - " << taskId.GetAsString() << "\n"; - return { HdRenderTagTokens->geometry }; + return {HdRenderTagTokens->geometry}; } bool RenderTaskDelegate::IsConverged() @@ -71,7 +74,8 @@ void RenderTaskDelegate::SetRendererAov(TfToken const &aov) { HdAovDescriptor aovDesc = GetRenderIndex().GetRenderDelegate()->GetDefaultAovDescriptor(aov); HdRenderBufferDescriptor desc(GfVec3i(taskParams.viewport[2], taskParams.viewport[3], 1), - aovDesc.format, aovDesc.multiSampled); + aovDesc.format, + aovDesc.multiSampled); SdfPath bufferId = GetAovID(aov); if (bufferDescriptors.find(bufferId) == bufferDescriptors.end()) { @@ -95,14 +99,17 @@ void RenderTaskDelegate::SetRendererAov(TfToken const &aov) HdRenderBuffer *RenderTaskDelegate::GetRendererAov(TfToken const &aov) { - return (HdRenderBuffer *)(GetRenderIndex().GetBprim(HdPrimTypeTokens->renderBuffer, GetAovID(aov))); + return ( + HdRenderBuffer *)(GetRenderIndex().GetBprim(HdPrimTypeTokens->renderBuffer, GetAovID(aov))); } void RenderTaskDelegate::GetRendererAovData(TfToken const &aov, void *data) { HdRenderBuffer *buffer = GetRendererAov(aov); void *bufData = buffer->Map(); - memcpy(data, bufData, buffer->GetWidth() * buffer->GetHeight() * HdDataSizeOfFormat(buffer->GetFormat())); + memcpy(data, + bufData, + buffer->GetWidth() * buffer->GetHeight() * HdDataSizeOfFormat(buffer->GetFormat())); buffer->Unmap(); } @@ -120,5 +127,4 @@ void RenderTaskDelegate::SetCameraAndViewport(SdfPath const &cameraId, GfVec4d c } } - -} // namespace blender::render::hydra +} // namespace blender::render::hydra diff --git a/source/blender/render/hydra/renderTaskDelegate.h b/source/blender/render/hydra/renderTaskDelegate.h index 02fc83c6a53a..d2411450c95d 100644 --- a/source/blender/render/hydra/renderTaskDelegate.h +++ b/source/blender/render/hydra/renderTaskDelegate.h @@ -3,17 +3,16 @@ #pragma once -#include #include +#include using namespace pxr; namespace blender::render::hydra { -class RenderTaskDelegate : public HdSceneDelegate -{ -public: - RenderTaskDelegate(HdRenderIndex* parentIndex, SdfPath const &delegateID); +class RenderTaskDelegate : public HdSceneDelegate { + public: + RenderTaskDelegate(HdRenderIndex *parentIndex, SdfPath const &delegateID); ~RenderTaskDelegate() override = default; SdfPath GetTaskID() const; @@ -31,9 +30,9 @@ public: HdTaskSharedPtr GetTask(); void SetCameraAndViewport(SdfPath const &cameraId, GfVec4d const &viewport); -private: + private: HdxRenderTaskParams taskParams; TfHashMap bufferDescriptors; }; -} // namespace blender::render::hydra +} // namespace blender::render::hydra diff --git a/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.cc b/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.cc index c2140bd389fb..8bac1d74455f 100644 --- a/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.cc +++ b/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.cc @@ -13,12 +13,14 @@ using namespace std; namespace blender::render::hydra { -BlenderSceneDelegate::BlenderSceneDelegate(HdRenderIndex* parentIndex, SdfPath const& delegateID, BlenderSceneDelegate::EngineType engine_type) - : HdSceneDelegate(parentIndex, delegateID) - , engine_type(engine_type) - , depsgraph(nullptr) - , context(nullptr) - , view3d(nullptr) +BlenderSceneDelegate::BlenderSceneDelegate(HdRenderIndex *parentIndex, + SdfPath const &delegateID, + BlenderSceneDelegate::EngineType engine_type) + : HdSceneDelegate(parentIndex, delegateID), + engine_type(engine_type), + depsgraph(nullptr), + context(nullptr), + view3d(nullptr) { } @@ -115,8 +117,10 @@ GfMatrix4d BlenderSceneDelegate::GetInstancerTransform(SdfPath const &instancerI return GfMatrix4d(1.0); } -size_t BlenderSceneDelegate::SampleInstancerTransform(SdfPath const &instancerId, size_t maxSampleCount, - float *sampleTimes, GfMatrix4d *sampleValues) +size_t BlenderSceneDelegate::SampleInstancerTransform(SdfPath const &instancerId, + size_t maxSampleCount, + float *sampleTimes, + GfMatrix4d *sampleValues) { LOG(INFO) << "SampleInstancerTransform: " << instancerId.GetString(); size_t ret = 0; @@ -125,8 +129,11 @@ size_t BlenderSceneDelegate::SampleInstancerTransform(SdfPath const &instancerId return ret; } -size_t BlenderSceneDelegate::SamplePrimvar(SdfPath const &id, TfToken const &key, size_t maxSampleCount, - float *sampleTimes, VtValue *sampleValues) +size_t BlenderSceneDelegate::SamplePrimvar(SdfPath const &id, + TfToken const &key, + size_t maxSampleCount, + float *sampleTimes, + VtValue *sampleValues) { // TODO: add a separate object for instancer for cleaner handling code if (id.GetName() == "Instancer") { @@ -164,7 +171,9 @@ void BlenderSceneDelegate::update_collection(bool remove, bool visibility) ITER_BEGIN (DEG_iterator_objects_begin, DEG_iterator_objects_next, DEG_iterator_objects_end, - &data, Object *, object) { + &data, + Object *, + object) { if (!ObjectData::supported(object)) { continue; @@ -216,7 +225,10 @@ void BlenderSceneDelegate::update_collection(bool remove, bool visibility) } } -void BlenderSceneDelegate::add_update_object(Object *object, bool geometry, bool transform, bool shading) +void BlenderSceneDelegate::add_update_object(Object *object, + bool geometry, + bool transform, + bool shading) { SdfPath id = ObjectData::prim_id(this, object); ObjectData *obj_data = object_data(id); @@ -317,10 +329,8 @@ void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont) DEGIDIterData data = {0}; data.graph = depsgraph; data.only_updated = true; - ITER_BEGIN (DEG_iterator_ids_begin, - DEG_iterator_ids_next, - DEG_iterator_ids_end, - &data, ID *, id) { + ITER_BEGIN ( + DEG_iterator_ids_begin, DEG_iterator_ids_next, DEG_iterator_ids_end, &data, ID *, id) { transform = (id->recalc & ID_RECALC_TRANSFORM) != 0; shading = (id->recalc & (ID_RECALC_SHADING | ID_RECALC_ANIMATION)) != 0; @@ -330,14 +340,13 @@ void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont) switch (GS(id->name)) { case ID_OB: { - Object *object = (Object *)id; - if (!ObjectData::supported(object)) { - break; - } - geometry |= (((ID *)object->data)->recalc & ID_RECALC_GEOMETRY) != 0; - add_update_object(object, geometry, transform, shading); + Object *object = (Object *)id; + if (!ObjectData::supported(object)) { + break; } - break; + geometry |= (((ID *)object->data)->recalc & ID_RECALC_GEOMETRY) != 0; + add_update_object(object, geometry, transform, shading); + } break; case ID_MA: if (shading) { @@ -383,14 +392,14 @@ void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont) } } -HdMeshTopology BlenderSceneDelegate::GetMeshTopology(SdfPath const& id) +HdMeshTopology BlenderSceneDelegate::GetMeshTopology(SdfPath const &id) { LOG(INFO) << "GetMeshTopology: " << id.GetString(); MeshData *m_data = mesh_data(id); return m_data->mesh_topology(); } -VtValue BlenderSceneDelegate::Get(SdfPath const& id, TfToken const& key) +VtValue BlenderSceneDelegate::Get(SdfPath const &id, TfToken const &key) { LOG(INFO) << "Get: " << id.GetString() << " " << key.GetString(); ObjectData *obj_data = object_data(id); @@ -409,7 +418,8 @@ VtValue BlenderSceneDelegate::Get(SdfPath const& id, TfToken const& key) return VtValue(); } -HdPrimvarDescriptorVector BlenderSceneDelegate::GetPrimvarDescriptors(SdfPath const& id, HdInterpolation interpolation) +HdPrimvarDescriptorVector BlenderSceneDelegate::GetPrimvarDescriptors( + SdfPath const &id, HdInterpolation interpolation) { LOG(INFO) << "GetPrimvarDescriptors: " << id.GetString() << " " << interpolation; if (mesh_data(id)) { @@ -425,12 +435,12 @@ HdPrimvarDescriptorVector BlenderSceneDelegate::GetPrimvarDescriptors(SdfPath co return primvars; } -SdfPath BlenderSceneDelegate::GetMaterialId(SdfPath const & rprimId) +SdfPath BlenderSceneDelegate::GetMaterialId(SdfPath const &rprimId) { return mesh_data(rprimId)->material_id; } -VtValue BlenderSceneDelegate::GetMaterialResource(SdfPath const& id) +VtValue BlenderSceneDelegate::GetMaterialResource(SdfPath const &id) { MaterialData *mat_data = material_data(id); if (mat_data) { @@ -439,7 +449,7 @@ VtValue BlenderSceneDelegate::GetMaterialResource(SdfPath const& id) return VtValue(); } -GfMatrix4d BlenderSceneDelegate::GetTransform(SdfPath const& id) +GfMatrix4d BlenderSceneDelegate::GetTransform(SdfPath const &id) { LOG(INFO) << "GetTransform: " << id.GetString(); ObjectData *obj_data = object_data(id); @@ -458,7 +468,7 @@ GfMatrix4d BlenderSceneDelegate::GetTransform(SdfPath const& id) return GfMatrix4d(); } -VtValue BlenderSceneDelegate::GetLightParamValue(SdfPath const& id, TfToken const& key) +VtValue BlenderSceneDelegate::GetLightParamValue(SdfPath const &id, TfToken const &key) { LightData *l_data = light_data(id); if (l_data) { @@ -470,4 +480,4 @@ VtValue BlenderSceneDelegate::GetLightParamValue(SdfPath const& id, TfToken cons return VtValue(); } -} // namespace blender::render::hydra +} // namespace blender::render::hydra diff --git a/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.h b/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.h index 900f89e044f7..67b3e024296c 100644 --- a/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.h +++ b/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.h @@ -8,22 +8,20 @@ #include "BKE_context.h" #include "DEG_depsgraph.h" -#include "object.h" -#include "mesh.h" #include "light.h" +#include "mesh.h" +#include "object.h" #include "world.h" namespace blender::render::hydra { class BlenderSceneDelegate : public pxr::HdSceneDelegate { -public: - enum class EngineType { - Viewport = 1, - Final, - Preview - }; + public: + enum class EngineType { Viewport = 1, Final, Preview }; - BlenderSceneDelegate(pxr::HdRenderIndex *render_index, pxr::SdfPath const &delegateId, BlenderSceneDelegate::EngineType engine_type); + BlenderSceneDelegate(pxr::HdRenderIndex *render_index, + pxr::SdfPath const &delegateId, + BlenderSceneDelegate::EngineType engine_type); ~BlenderSceneDelegate() override = default; void populate(Depsgraph *depsgraph, bContext *context); @@ -33,22 +31,29 @@ public: pxr::GfMatrix4d GetTransform(pxr::SdfPath const &id) override; pxr::VtValue Get(pxr::SdfPath const &id, pxr::TfToken const &key) override; pxr::VtValue GetLightParamValue(pxr::SdfPath const &id, pxr::TfToken const &key) override; - pxr::HdPrimvarDescriptorVector GetPrimvarDescriptors(pxr::SdfPath const &id, pxr::HdInterpolation interpolation) override; + pxr::HdPrimvarDescriptorVector GetPrimvarDescriptors( + pxr::SdfPath const &id, pxr::HdInterpolation interpolation) override; pxr::SdfPath GetMaterialId(pxr::SdfPath const &rprimId) override; pxr::VtValue GetMaterialResource(pxr::SdfPath const &materialId) override; bool GetVisible(pxr::SdfPath const &id) override; pxr::SdfPath GetInstancerId(pxr::SdfPath const &primId) override; pxr::SdfPathVector GetInstancerPrototypes(pxr::SdfPath const &instancerId) override; - pxr::VtIntArray GetInstanceIndices(pxr::SdfPath const &instancerId, pxr::SdfPath const &prototypeId) override; + pxr::VtIntArray GetInstanceIndices(pxr::SdfPath const &instancerId, + pxr::SdfPath const &prototypeId) override; pxr::GfMatrix4d GetInstancerTransform(pxr::SdfPath const &instancerId); - size_t SampleInstancerTransform(pxr::SdfPath const &instancerId, size_t maxSampleCount, - float *sampleTimes, pxr::GfMatrix4d *sampleValues) override; - size_t SamplePrimvar(pxr::SdfPath const &id, pxr::TfToken const &key, size_t maxSampleCount, - float *sampleTimes, pxr::VtValue *sampleValues) override; + size_t SampleInstancerTransform(pxr::SdfPath const &instancerId, + size_t maxSampleCount, + float *sampleTimes, + pxr::GfMatrix4d *sampleValues) override; + size_t SamplePrimvar(pxr::SdfPath const &id, + pxr::TfToken const &key, + size_t maxSampleCount, + float *sampleTimes, + pxr::VtValue *sampleValues) override; EngineType engine_type; -private: + private: ObjectData *object_data(pxr::SdfPath const &id); MeshData *mesh_data(pxr::SdfPath const &id); LightData *light_data(pxr::SdfPath const &id); @@ -61,7 +66,7 @@ private: void update_world(); void update_collection(bool remove, bool visibility); -private: + private: Depsgraph *depsgraph; bContext *context; View3D *view3d; @@ -71,4 +76,4 @@ private: std::unique_ptr world_data; }; -} // namespace blender::render::hydra +} // namespace blender::render::hydra diff --git a/source/blender/render/hydra/sceneDelegate/id.cc b/source/blender/render/hydra/sceneDelegate/id.cc index da56e418540d..b6f5f40db27b 100644 --- a/source/blender/render/hydra/sceneDelegate/id.cc +++ b/source/blender/render/hydra/sceneDelegate/id.cc @@ -11,8 +11,7 @@ using namespace pxr; namespace blender::render::hydra { IdData::IdData(BlenderSceneDelegate *scene_delegate, ID *id) - : scene_delegate(scene_delegate) - , id(id) + : scene_delegate(scene_delegate), id(id) { } @@ -28,4 +27,4 @@ VtValue IdData::get_data(TfToken const &key) return VtValue(); } -} // namespace blender::render::hydra +} // namespace blender::render::hydra diff --git a/source/blender/render/hydra/sceneDelegate/id.h b/source/blender/render/hydra/sceneDelegate/id.h index 99228418feca..b31187f1266b 100644 --- a/source/blender/render/hydra/sceneDelegate/id.h +++ b/source/blender/render/hydra/sceneDelegate/id.h @@ -3,8 +3,8 @@ #pragma once -#include #include +#include #include #include "DNA_ID.h" @@ -22,12 +22,7 @@ class IdData { virtual pxr::VtValue get_data(pxr::TfToken const &key); template const T get_data(pxr::TfToken const &key); - enum class DirtyBits { - DirtyTransform = 1, - DirtyVisibility, - DirtyMaterial, - AllDirty - }; + enum class DirtyBits { DirtyTransform = 1, DirtyVisibility, DirtyMaterial, AllDirty }; virtual void insert_prim() = 0; virtual void remove_prim() = 0; @@ -43,4 +38,4 @@ template const T IdData::get_data(pxr::TfToken const &key) return get_data(key).Get(); } -} // namespace blender::render::hydra +} // namespace blender::render::hydra diff --git a/source/blender/render/hydra/sceneDelegate/light.cc b/source/blender/render/hydra/sceneDelegate/light.cc index 0c1ddd549ae1..5b07b47a245d 100644 --- a/source/blender/render/hydra/sceneDelegate/light.cc +++ b/source/blender/render/hydra/sceneDelegate/light.cc @@ -21,13 +21,14 @@ using namespace boost::algorithm; namespace blender::render::hydra { LightData::LightData(BlenderSceneDelegate *scene_delegate, Object *object) - : ObjectData(scene_delegate, object) + : ObjectData(scene_delegate, object) { Light *light = (Light *)((Object *)id)->data; - data[HdLightTokens->intensity] = scene_delegate->engine_type == BlenderSceneDelegate::EngineType::Preview - ? light->energy / 1000 - : light->energy; + data[HdLightTokens->intensity] = scene_delegate->engine_type == + BlenderSceneDelegate::EngineType::Preview ? + light->energy / 1000 : + light->energy; data[HdLightTokens->color] = GfVec3f(light->r, light->g, light->b); @@ -176,4 +177,4 @@ void LightData::mark_prim_dirty(DirtyBits dirty_bits) LOG(INFO) << "Update light: " << name() << " [" << (int)dirty_bits << "]"; } -} // namespace blender::render::hydra +} // namespace blender::render::hydra diff --git a/source/blender/render/hydra/sceneDelegate/light.h b/source/blender/render/hydra/sceneDelegate/light.h index c961dff9c1bc..ad3223b22769 100644 --- a/source/blender/render/hydra/sceneDelegate/light.h +++ b/source/blender/render/hydra/sceneDelegate/light.h @@ -3,15 +3,15 @@ #pragma once +#include "pxr/base/tf/hashmap.h" #include #include -#include "pxr/base/tf/hashmap.h" #include "object.h" namespace blender::render::hydra { -class LightData: public ObjectData { +class LightData : public ObjectData { public: LightData(BlenderSceneDelegate *scene_delegate, Object *object); @@ -25,4 +25,4 @@ class LightData: public ObjectData { pxr::TfToken prim_type(); }; -} // namespace blender::render::hydra +} // namespace blender::render::hydra diff --git a/source/blender/render/hydra/sceneDelegate/material.cc b/source/blender/render/hydra/sceneDelegate/material.cc index 0dd6f1f557ee..615f1cbc3236 100644 --- a/source/blender/render/hydra/sceneDelegate/material.cc +++ b/source/blender/render/hydra/sceneDelegate/material.cc @@ -3,14 +3,14 @@ #include -#include #include #include +#include #include "glog/logging.h" -#include "BKE_material.h" #include "BKE_lib_id.h" +#include "BKE_material.h" #include "blenderSceneDelegate.h" #include "material.h" @@ -20,7 +20,8 @@ using namespace pxr; namespace blender::render::hydra { -std::unique_ptr MaterialData::init(BlenderSceneDelegate *scene_delegate, Material *material) +std::unique_ptr MaterialData::init(BlenderSceneDelegate *scene_delegate, + Material *material) { return std::make_unique(scene_delegate, material); } @@ -35,7 +36,7 @@ pxr::SdfPath MaterialData::prim_id(BlenderSceneDelegate *scene_delegate, Materia } MaterialData::MaterialData(BlenderSceneDelegate *scene_delegate, Material *material) - : IdData(scene_delegate, (ID *)material) + : IdData(scene_delegate, (ID *)material) { } @@ -120,4 +121,4 @@ void MaterialData::mark_prim_dirty(DirtyBits dirty_bits) LOG(INFO) << "Update material: " << name() << ", mtlx=" << mtlx_path.GetResolvedPath(); } -} // namespace blender::render::hydra +} // namespace blender::render::hydra diff --git a/source/blender/render/hydra/sceneDelegate/material.h b/source/blender/render/hydra/sceneDelegate/material.h index edab709b01a1..5e14f00c9b24 100644 --- a/source/blender/render/hydra/sceneDelegate/material.h +++ b/source/blender/render/hydra/sceneDelegate/material.h @@ -3,9 +3,9 @@ #pragma once +#include "pxr/base/tf/hashmap.h" #include #include -#include "pxr/base/tf/hashmap.h" #include "DNA_material_types.h" @@ -13,9 +13,10 @@ namespace blender::render::hydra { -class MaterialData: IdData { +class MaterialData : IdData { public: - static std::unique_ptr init(BlenderSceneDelegate *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(BlenderSceneDelegate *scene_delegate, Material *material); @@ -28,10 +29,11 @@ class MaterialData: IdData { pxr::VtValue material_resource(); void export_mtlx(); -private: + private: pxr::SdfAssetPath mtlx_path; }; -using MaterialDataMap = pxr::TfHashMap, pxr::SdfPath::Hash>; +using MaterialDataMap = + pxr::TfHashMap, pxr::SdfPath::Hash>; -} // namespace blender::render::hydra +} // namespace blender::render::hydra diff --git a/source/blender/render/hydra/sceneDelegate/mesh.cc b/source/blender/render/hydra/sceneDelegate/mesh.cc index 6d2c5ec754f4..07126f8ddb96 100644 --- a/source/blender/render/hydra/sceneDelegate/mesh.cc +++ b/source/blender/render/hydra/sceneDelegate/mesh.cc @@ -6,21 +6,21 @@ #include "glog/logging.h" +#include "BKE_material.h" #include "BKE_mesh.h" #include "BKE_mesh_runtime.h" #include "BKE_object.h" -#include "BKE_material.h" +#include "../utils.h" #include "blenderSceneDelegate.h" #include "mesh.h" -#include "../utils.h" using namespace pxr; namespace blender::render::hydra { MeshData::MeshData(BlenderSceneDelegate *scene_delegate, Object *object) - : ObjectData(scene_delegate, object) + : ObjectData(scene_delegate, object) { if (object->type == OB_MESH && object->mode == OB_MODE_OBJECT && BLI_listbase_is_empty(&object->modifiers)) { @@ -64,8 +64,10 @@ Material *MeshData::material() HdMeshTopology MeshData::mesh_topology() { - return HdMeshTopology(PxOsdOpenSubdivTokens->catmullClark, HdTokens->rightHanded, - face_vertex_counts, face_vertex_indices); + return HdMeshTopology(PxOsdOpenSubdivTokens->catmullClark, + HdTokens->rightHanded, + face_vertex_counts, + face_vertex_indices); } HdPrimvarDescriptorVector MeshData::primvar_descriptors(HdInterpolation interpolation) @@ -81,7 +83,8 @@ HdPrimvarDescriptorVector MeshData::primvar_descriptors(HdInterpolation interpol primvars.emplace_back(HdTokens->normals, interpolation, HdPrimvarRoleTokens->normal); } if (!uvs.empty()) { - primvars.emplace_back(HdPrimvarRoleTokens->textureCoordinate, interpolation, + primvars.emplace_back(HdPrimvarRoleTokens->textureCoordinate, + interpolation, HdPrimvarRoleTokens->textureCoordinate); } } @@ -92,8 +95,8 @@ HdPrimvarDescriptorVector MeshData::instancer_primvar_descriptors(HdInterpolatio { HdPrimvarDescriptorVector primvars; if (interpolation == HdInterpolationInstance) { - primvars.emplace_back(HdInstancerTokens->instanceTransform, interpolation, - HdPrimvarRoleTokens->none); + primvars.emplace_back( + HdInstancerTokens->instanceTransform, interpolation, HdPrimvarRoleTokens->none); } return primvars; } @@ -107,14 +110,19 @@ VtIntArray MeshData::instance_indices() return ret; } -size_t MeshData::sample_instancer_transform(size_t maxSampleCount, float *sampleTimes, GfMatrix4d *sampleValues) +size_t MeshData::sample_instancer_transform(size_t maxSampleCount, + float *sampleTimes, + GfMatrix4d *sampleValues) { *sampleTimes = 0.0f; *sampleValues = GfMatrix4d(1.0); return 1; } -size_t MeshData::sample_instancer_primvar(TfToken const &key, size_t maxSampleCount, float *sampleTimes, VtValue *sampleValues) +size_t MeshData::sample_instancer_primvar(TfToken const &key, + size_t maxSampleCount, + float *sampleTimes, + VtValue *sampleValues) { if (key == HdInstancerTokens->instanceTransform) { if (maxSampleCount > 0) { @@ -134,7 +142,8 @@ void MeshData::add_instance(DupliObject *dupli) LOG(INFO) << "Add instancer: " << name() << " id=" << instancer_id.GetAsString(); } if (instances.empty()) { - // USD hides the prototype mesh when instancing in contrary to the Blender, so we must add it back implicitly + // USD hides the prototype mesh when instancing in contrary to the Blender, so we must add it + // back implicitly instances.push_back(GfMatrix4d(1.0)); } instances.push_back(transform().GetInverse() * gf_matrix_from_transform(dupli->mat)); diff --git a/source/blender/render/hydra/sceneDelegate/mesh.h b/source/blender/render/hydra/sceneDelegate/mesh.h index 3a0e65eb3b58..9836207f1ec1 100644 --- a/source/blender/render/hydra/sceneDelegate/mesh.h +++ b/source/blender/render/hydra/sceneDelegate/mesh.h @@ -12,8 +12,8 @@ namespace blender::render::hydra { -class MeshData: public ObjectData { -public: +class MeshData : public ObjectData { + public: MeshData(BlenderSceneDelegate *scene_delegate, Object *object); pxr::VtValue get_data(pxr::TfToken const &key) override; @@ -27,8 +27,13 @@ public: pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation); pxr::HdPrimvarDescriptorVector instancer_primvar_descriptors(pxr::HdInterpolation interpolation); pxr::VtIntArray instance_indices(); - size_t sample_instancer_transform(size_t maxSampleCount, float *sampleTimes, pxr::GfMatrix4d *sampleValues); - size_t sample_instancer_primvar(pxr::TfToken const &key, size_t maxSampleCount, float *sampleTimes, pxr::VtValue *sampleValues); + size_t sample_instancer_transform(size_t maxSampleCount, + float *sampleTimes, + pxr::GfMatrix4d *sampleValues); + size_t sample_instancer_primvar(pxr::TfToken const &key, + size_t maxSampleCount, + float *sampleTimes, + pxr::VtValue *sampleValues); void add_instance(DupliObject *dupli); @@ -47,6 +52,4 @@ public: pxr::VtMatrix4dArray instances; }; - - -} // namespace blender::render::hydra +} // namespace blender::render::hydra diff --git a/source/blender/render/hydra/sceneDelegate/mtlxHydraAdapter.cc b/source/blender/render/hydra/sceneDelegate/mtlxHydraAdapter.cc index 4888af16945e..3f04c6815f08 100644 --- a/source/blender/render/hydra/sceneDelegate/mtlxHydraAdapter.cc +++ b/source/blender/render/hydra/sceneDelegate/mtlxHydraAdapter.cc @@ -57,7 +57,7 @@ void HdMtlxConvertToMaterialNetworkMap(std::string const &mtlxPath, TF_RUNTIME_ERROR("MaterialX error: %s\n", x.what()); return; } - + if (UsdPrim materials = stage->GetPrimAtPath(SdfPath("/MaterialX/Materials"))) { if (UsdPrimSiblingRange children = materials.GetChildren()) { if (auto material = UsdShadeMaterial(*children.begin())) { diff --git a/source/blender/render/hydra/sceneDelegate/object.cc b/source/blender/render/hydra/sceneDelegate/object.cc index 65067e983492..f1d9bf1910dd 100644 --- a/source/blender/render/hydra/sceneDelegate/object.cc +++ b/source/blender/render/hydra/sceneDelegate/object.cc @@ -3,11 +3,11 @@ #include "BKE_object.h" -#include "blenderSceneDelegate.h" -#include "object.h" -#include "mesh.h" -#include "light.h" #include "../utils.h" +#include "blenderSceneDelegate.h" +#include "light.h" +#include "mesh.h" +#include "object.h" using namespace pxr; @@ -60,8 +60,7 @@ pxr::SdfPath ObjectData::prim_id(BlenderSceneDelegate *scene_delegate, Object *o } ObjectData::ObjectData(BlenderSceneDelegate *scene_delegate, Object *object) - : IdData(scene_delegate, (ID *)object) - , visible(true) + : 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 3b55ede62bfa..c498f73a2100 100644 --- a/source/blender/render/hydra/sceneDelegate/object.h +++ b/source/blender/render/hydra/sceneDelegate/object.h @@ -3,19 +3,19 @@ #pragma once -#include #include "pxr/base/tf/hashmap.h" +#include -#include "DNA_object_types.h" #include "BKE_layer.h" +#include "DNA_object_types.h" #include "id.h" #include "material.h" namespace blender::render::hydra { -class ObjectData: public IdData { -public: +class ObjectData : public IdData { + public: static bool supported(Object *object); static std::unique_ptr init(BlenderSceneDelegate *scene_delegate, Object *object); static pxr::SdfPath prim_id(BlenderSceneDelegate *scene_delegate, Object *object); @@ -29,6 +29,7 @@ public: bool visible; }; -using ObjectDataMap = pxr::TfHashMap, pxr::SdfPath::Hash>; +using ObjectDataMap = + pxr::TfHashMap, pxr::SdfPath::Hash>; -} // namespace blender::render::hydra +} // namespace blender::render::hydra diff --git a/source/blender/render/hydra/sceneDelegate/world.cc b/source/blender/render/hydra/sceneDelegate/world.cc index 26d1b3e82d13..b8959df34adf 100644 --- a/source/blender/render/hydra/sceneDelegate/world.cc +++ b/source/blender/render/hydra/sceneDelegate/world.cc @@ -3,28 +3,28 @@ #include -#include -#include #include +#include +#include #include -#include #include +#include #include #include "BKE_context.h" #include "DNA_node_types.h" #include "DNA_windowmanager_types.h" +#include "BKE_image.h" #include "BKE_node.h" #include "BKE_node_runtime.hh" -#include "BKE_image.h" #include "NOD_shader.h" #include "glog/logging.h" +#include "../utils.h" #include "blenderSceneDelegate.h" #include "world.h" -#include "../utils.h" /* TODO : add custom tftoken "transparency"? */ @@ -33,7 +33,8 @@ using namespace pxr; namespace blender::render::hydra { std::unique_ptr WorldData::init(BlenderSceneDelegate *scene_delegate, - World *world, bContext *context) + World *world, + bContext *context) { return std::make_unique(scene_delegate, world, context); } @@ -44,7 +45,7 @@ SdfPath WorldData::prim_id(BlenderSceneDelegate *scene_delegate) } WorldData::WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContext *context) - : IdData(scene_delegate, (ID *)world) + : IdData(scene_delegate, (ID *)world) { data[UsdLuxTokens->orientToStageUpAxis] = true; @@ -105,7 +106,7 @@ GfMatrix4d WorldData::transform() { GfMatrix4d transform = GfMatrix4d(GfRotation(GfVec3d(1.0, 0.0, 0.0), -90), GfVec3d()); - /* TODO : do this check via RenderSettings*/ + /* TODO : do this check via RenderSettings*/ if (scene_delegate->GetRenderIndex().GetRenderDelegate()->GetRendererDisplayName() == "RPR") { transform *= GfMatrix4d(GfRotation(GfVec3d(1.0, 0.0, 0.0), -180), GfVec3d()); transform *= GfMatrix4d(GfRotation(GfVec3d(0.0, 0.0, 1.0), 90.0), GfVec3d()); diff --git a/source/blender/render/hydra/sceneDelegate/world.h b/source/blender/render/hydra/sceneDelegate/world.h index 3a4561716c4b..5aa170444f80 100644 --- a/source/blender/render/hydra/sceneDelegate/world.h +++ b/source/blender/render/hydra/sceneDelegate/world.h @@ -5,11 +5,11 @@ #include +#include "pxr/base/tf/staticTokens.h" #include +#include #include #include -#include -#include "pxr/base/tf/staticTokens.h" #include "DNA_view3d_types.h" #include "DNA_world_types.h" @@ -18,9 +18,11 @@ namespace blender::render::hydra { -class WorldData: public IdData { -public: - static std::unique_ptr init(BlenderSceneDelegate *scene_delegate, World *world, bContext *context); +class WorldData : public IdData { + public: + static std::unique_ptr init(BlenderSceneDelegate *scene_delegate, + World *world, + bContext *context); static pxr::SdfPath prim_id(BlenderSceneDelegate *scene_delegate); WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContext *context); @@ -36,4 +38,4 @@ public: std::map data; }; -} // namespace blender::render::hydra +} // namespace blender::render::hydra diff --git a/source/blender/render/hydra/utils.cc b/source/blender/render/hydra/utils.cc index aca17262699a..2dff5f6ecf94 100644 --- a/source/blender/render/hydra/utils.cc +++ b/source/blender/render/hydra/utils.cc @@ -1,15 +1,15 @@ /* SPDX-License-Identifier: Apache-2.0 * Copyright 2011-2022 Blender Foundation */ -#include #include +#include #include #include "BKE_appdir.h" #include "BKE_image_save.h" -#include "BLI_string.h" #include "BLI_path_util.h" +#include "BLI_string.h" #include "DNA_camera_types.h" @@ -22,11 +22,22 @@ namespace blender::render::hydra { GfMatrix4d gf_matrix_from_transform(float m[4][4]) { - return GfMatrix4d( - m[0][0], m[0][1], m[0][2], m[0][3], - m[1][0], m[1][1], m[1][2], m[1][3], - m[2][0], m[2][1], m[2][2], m[2][3], - m[3][0], m[3][1], m[3][2], m[3][3]); + return GfMatrix4d(m[0][0], + m[0][1], + m[0][2], + m[0][3], + m[1][0], + m[1][1], + m[1][2], + m[1][3], + m[2][0], + m[2][1], + m[2][2], + m[2][3], + m[3][0], + m[3][1], + m[3][2], + m[3][3]); } string format_duration(chrono::milliseconds millisecs) @@ -101,18 +112,19 @@ string cache_image(Main *bmain, void set_env_paths(string const &name, vector path_dirs) { - const char *env = BLI_getenv(name.c_str());; + const char *env = BLI_getenv(name.c_str()); + ; stringstream ss; int i = 0; for (string &s : path_dirs) { ++i; ss << s; if (i < path_dirs.size() || env) { - #ifdef _WIN32 +#ifdef _WIN32 ss << ";"; - #else +#else ss << ":"; - #endif +#endif } } if (env) { diff --git a/source/blender/render/hydra/utils.h b/source/blender/render/hydra/utils.h index 978eeb54ff21..7bf8f3be0c97 100644 --- a/source/blender/render/hydra/utils.h +++ b/source/blender/render/hydra/utils.h @@ -23,4 +23,4 @@ std::string cache_image(Main *bmain, ReportList *reports); void set_env_paths(std::string const &name, std::vector path_dirs); -} // namespace blender::render::hydra +} // namespace blender::render::hydra diff --git a/source/blender/render/hydra/viewportEngine.cc b/source/blender/render/hydra/viewportEngine.cc index ce419a47be53..cfaba729682f 100644 --- a/source/blender/render/hydra/viewportEngine.cc +++ b/source/blender/render/hydra/viewportEngine.cc @@ -7,18 +7,18 @@ #include #include -#include "DEG_depsgraph_query.h" +#include "BKE_camera.h" #include "BLI_math_matrix.h" +#include "DEG_depsgraph_query.h" #include "DNA_camera_types.h" #include "DNA_screen_types.h" -#include "BKE_camera.h" #include "GPU_shader.h" #include "glog/logging.h" -#include "viewportEngine.h" #include "camera.h" #include "utils.h" +#include "viewportEngine.h" using namespace std; using namespace pxr; @@ -40,8 +40,7 @@ struct ViewSettings { GfVec4i border; }; -ViewSettings::ViewSettings(bContext *context) - : camera_data(context) +ViewSettings::ViewSettings(bContext *context) : camera_data(context) { View3D *view3d = CTX_wm_view3d(context); RegionView3D *region_data = (RegionView3D *)CTX_wm_region_data(context); @@ -52,7 +51,7 @@ ViewSettings::ViewSettings(bContext *context) Scene *scene = CTX_data_scene(context); - //getting render border + // getting render border int x1 = 0, y1 = 0; int x2 = screen_width, y2 = screen_height; @@ -64,22 +63,29 @@ ViewSettings::ViewSettings(bContext *context) BKE_camera_view_frame(scene, (Camera *)camera_obj->data, camera_points); float screen_points[4][2]; - for (int i = 0 ; i < 4; i++) { - float world_location[] = {camera_points[i][0], camera_points[i][1], camera_points[i][2], 1.0f}; + for (int i = 0; i < 4; i++) { + float world_location[] = { + camera_points[i][0], camera_points[i][1], camera_points[i][2], 1.0f}; mul_m4_v4(camera_obj->object_to_world, world_location); mul_m4_v4(region_data->persmat, world_location); if (world_location[3] > 0.0) { - screen_points[i][0] = screen_width * 0.5f + screen_width * 0.5f * (world_location[0] / world_location[3]); - screen_points[i][1] = screen_height * 0.5f + screen_height * 0.5f * (world_location[1] / world_location[3]); + screen_points[i][0] = screen_width * 0.5f + + screen_width * 0.5f * (world_location[0] / world_location[3]); + screen_points[i][1] = screen_height * 0.5f + + screen_height * 0.5f * (world_location[1] / world_location[3]); } } // getting camera view region - float x1_f = min({screen_points[0][0], screen_points[1][0], screen_points[2][0], screen_points[3][0]}); - float x2_f = max({screen_points[0][0], screen_points[1][0], screen_points[2][0], screen_points[3][0]}); - float y1_f = min({screen_points[0][1], screen_points[1][1], screen_points[2][1], screen_points[3][1]}); - float y2_f = max({screen_points[0][1], screen_points[1][1], screen_points[2][1], screen_points[3][1]}); + float x1_f = min( + {screen_points[0][0], screen_points[1][0], screen_points[2][0], screen_points[3][0]}); + float x2_f = max( + {screen_points[0][0], screen_points[1][0], screen_points[2][0], screen_points[3][0]}); + float y1_f = min( + {screen_points[0][1], screen_points[1][1], screen_points[2][1], screen_points[3][1]}); + float y2_f = max( + {screen_points[0][1], screen_points[1][1], screen_points[2][1], screen_points[3][1]}); // adjusting region to border float x = x1_f, y = y1_f; @@ -101,7 +107,7 @@ ViewSettings::ViewSettings(bContext *context) if (view3d->flag2 & V3D_RENDER_BORDER) { int x = x1, y = y1; int dx = x2 - x1, dy = y2 - y1; - + x1 = int(x + view3d->render_border.xmin * dx); x2 = int(x + view3d->render_border.xmax * dx); y1 = int(y + view3d->render_border.ymin * dy); @@ -124,16 +130,13 @@ int ViewSettings::height() GfCamera ViewSettings::gf_camera() { - return camera_data.gf_camera(GfVec4f( - (float)border[0] / screen_width, (float)border[1] / screen_height, - (float)border[2] / screen_width, (float)border[3] / screen_height)); + return camera_data.gf_camera(GfVec4f((float)border[0] / screen_width, + (float)border[1] / screen_height, + (float)border[2] / screen_width, + (float)border[3] / screen_height)); } -GLTexture::GLTexture() - : textureId(0) - , width(0) - , height(0) - , channels(4) +GLTexture::GLTexture() : textureId(0), width(0), height(0), channels(4) { } @@ -158,7 +161,7 @@ void GLTexture::setBuffer(HdRenderBuffer *buffer) } glBindTexture(GL_TEXTURE_2D, textureId); - + void *data = buffer->Map(); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_FLOAT, data); buffer->Unmap(); @@ -176,7 +179,7 @@ void GLTexture::create(HdRenderBuffer *buffer) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - + void *data = buffer->Map(); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0, GL_RGBA, GL_FLOAT, data); buffer->Unmap(); @@ -204,7 +207,7 @@ void GLTexture::draw(GLfloat x, GLfloat y) GLint position_location = glGetAttribLocation(shader_program, "pos"); // Generate geometry buffers for drawing textured quad - GLfloat position[8] = { x, y, x + width, y, x + width, y + height, x, y + height }; + GLfloat position[8] = {x, y, x + width, y, x + width, y + height, x, y + height}; GLfloat texcoord[8] = {0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0}; GLuint vertex_buffer[2]; @@ -239,15 +242,19 @@ void GLTexture::draw(GLfloat x, GLfloat y) glDeleteVertexArrays(1, &vertex_array); } -void ViewportEngine::sync(Depsgraph *depsgraph, bContext *context, HdRenderSettingsMap &renderSettings) +void ViewportEngine::sync(Depsgraph *depsgraph, + bContext *context, + HdRenderSettingsMap &renderSettings) { if (!scene_delegate) { - scene_delegate = std::make_unique(render_index.get(), - SdfPath::AbsoluteRootPath().AppendElementString("scene"), BlenderSceneDelegate::EngineType::Viewport); + scene_delegate = std::make_unique( + render_index.get(), + SdfPath::AbsoluteRootPath().AppendElementString("scene"), + BlenderSceneDelegate::EngineType::Viewport); } scene_delegate->populate(depsgraph, context); - for (auto const& setting : renderSettings) { + for (auto const &setting : renderSettings) { render_delegate->SetRenderSetting(setting.first, setting.second); } } @@ -261,8 +268,11 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context) GfCamera gfCamera = viewSettings.gf_camera(); free_camera_delegate->SetCamera(gfCamera); - render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(), - GfVec4d(viewSettings.border[0], viewSettings.border[1], viewSettings.border[2], viewSettings.border[3])); + render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(), + GfVec4d(viewSettings.border[0], + viewSettings.border[1], + viewSettings.border[2], + viewSettings.border[3])); if (simple_light_task_delegate) { simple_light_task_delegate->SetCameraPath(free_camera_delegate->GetCameraId()); } @@ -298,12 +308,15 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context) GPU_shader_unbind(); chrono::time_point timeCurrent = chrono::steady_clock::now(); - chrono::milliseconds elapsedTime = chrono::duration_cast(timeCurrent - timeBegin); + chrono::milliseconds elapsedTime = chrono::duration_cast(timeCurrent - + timeBegin); string formattedTime = format_duration(elapsedTime); if (!render_task_delegate->IsConverged()) { - notify_status("Time: " + formattedTime + " | Done: " + to_string(int(renderer_percent_done())) + "%", "Render"); + notify_status("Time: " + formattedTime + + " | Done: " + to_string(int(renderer_percent_done())) + "%", + "Render"); bl_engine->flag |= RE_ENGINE_DO_DRAW; } else { @@ -321,4 +334,4 @@ void ViewportEngine::notify_status(const string &info, const string &status) RE_engine_update_stats(bl_engine, status.c_str(), info.c_str()); } -} // namespace blender::render::hydra +} // namespace blender::render::hydra diff --git a/source/blender/render/hydra/viewportEngine.h b/source/blender/render/hydra/viewportEngine.h index e9866d519fbc..b842f54c59a5 100644 --- a/source/blender/render/hydra/viewportEngine.h +++ b/source/blender/render/hydra/viewportEngine.h @@ -13,15 +13,14 @@ namespace blender::render::hydra { -class GLTexture -{ -public: +class GLTexture { + public: GLTexture(); ~GLTexture(); void setBuffer(pxr::HdRenderBuffer *buffer); void draw(GLfloat x, GLfloat y); -private: + private: void create(pxr::HdRenderBuffer *buffer); void free(); @@ -30,19 +29,21 @@ private: }; class ViewportEngine : public Engine { -public: + public: using Engine::Engine; - void sync(Depsgraph *depsgraph, bContext *context, pxr::HdRenderSettingsMap &renderSettings) override; + void sync(Depsgraph *depsgraph, + bContext *context, + pxr::HdRenderSettingsMap &renderSettings) override; void render(Depsgraph *depsgraph) override; void render(Depsgraph *depsgraph, bContext *context); -private: + private: void notify_status(const std::string &title, const std::string &info); -private: + private: std::chrono::time_point timeBegin; GLTexture texture; }; -} // namespace blender::render::hydra +} // namespace blender::render::hydra -- 2.30.2 From a385bb2b1ee76dfd345c944b3a9488e351c97eda Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Mon, 13 Mar 2023 19:40:04 +0300 Subject: [PATCH 02/11] rename files --- source/blender/render/hydra/CMakeLists.txt | 52 +++++++++---------- source/blender/render/hydra/camera.cc | 1 - source/blender/render/hydra/camera.h | 2 + source/blender/render/hydra/engine.h | 6 +-- .../hydra/{finalEngine.cc => final_engine.cc} | 2 +- .../hydra/{finalEngine.h => final_engine.h} | 0 .../{previewEngine.cc => preview_engine.cc} | 2 +- .../{previewEngine.h => preview_engine.h} | 2 +- source/blender/render/hydra/python.cc | 6 +-- ...askDelegate.cc => render_task_delegate.cc} | 2 +- ...rTaskDelegate.h => render_task_delegate.h} | 0 .../blender_scene_delegate.cc} | 2 +- .../blender_scene_delegate.h} | 0 .../{sceneDelegate => scene_delegate}/id.cc | 2 +- .../{sceneDelegate => scene_delegate}/id.h | 0 .../light.cc | 2 +- .../{sceneDelegate => scene_delegate}/light.h | 0 .../material.cc | 4 +- .../material.h | 0 .../{sceneDelegate => scene_delegate}/mesh.cc | 2 +- .../{sceneDelegate => scene_delegate}/mesh.h | 0 .../mtlx_hydra_adapter.cc} | 4 +- .../mtlx_hydra_adapter.h} | 0 .../object.cc | 2 +- .../object.h | 0 .../world.cc | 2 +- .../{sceneDelegate => scene_delegate}/world.h | 0 ...egate.cc => simple_light_task_delegate.cc} | 2 +- ...elegate.h => simple_light_task_delegate.h} | 0 .../{viewportEngine.cc => viewport_engine.cc} | 4 +- .../{viewportEngine.h => viewport_engine.h} | 0 31 files changed, 52 insertions(+), 49 deletions(-) rename source/blender/render/hydra/{finalEngine.cc => final_engine.cc} (99%) rename source/blender/render/hydra/{finalEngine.h => final_engine.h} (100%) rename source/blender/render/hydra/{previewEngine.cc => preview_engine.cc} (99%) rename source/blender/render/hydra/{previewEngine.h => preview_engine.h} (96%) rename source/blender/render/hydra/{renderTaskDelegate.cc => render_task_delegate.cc} (99%) rename source/blender/render/hydra/{renderTaskDelegate.h => render_task_delegate.h} (100%) rename source/blender/render/hydra/{sceneDelegate/blenderSceneDelegate.cc => scene_delegate/blender_scene_delegate.cc} (99%) rename source/blender/render/hydra/{sceneDelegate/blenderSceneDelegate.h => scene_delegate/blender_scene_delegate.h} (100%) rename source/blender/render/hydra/{sceneDelegate => scene_delegate}/id.cc (93%) rename source/blender/render/hydra/{sceneDelegate => scene_delegate}/id.h (100%) rename source/blender/render/hydra/{sceneDelegate => scene_delegate}/light.cc (99%) rename source/blender/render/hydra/{sceneDelegate => scene_delegate}/light.h (100%) rename source/blender/render/hydra/{sceneDelegate => scene_delegate}/material.cc (98%) rename source/blender/render/hydra/{sceneDelegate => scene_delegate}/material.h (100%) rename source/blender/render/hydra/{sceneDelegate => scene_delegate}/mesh.cc (99%) rename source/blender/render/hydra/{sceneDelegate => scene_delegate}/mesh.h (100%) rename source/blender/render/hydra/{sceneDelegate/mtlxHydraAdapter.cc => scene_delegate/mtlx_hydra_adapter.cc} (98%) rename source/blender/render/hydra/{sceneDelegate/mtlxHydraAdapter.h => scene_delegate/mtlx_hydra_adapter.h} (100%) rename source/blender/render/hydra/{sceneDelegate => scene_delegate}/object.cc (98%) rename source/blender/render/hydra/{sceneDelegate => scene_delegate}/object.h (100%) rename source/blender/render/hydra/{sceneDelegate => scene_delegate}/world.cc (99%) rename source/blender/render/hydra/{sceneDelegate => scene_delegate}/world.h (100%) rename source/blender/render/hydra/{simpleLightTaskDelegate.cc => simple_light_task_delegate.cc} (96%) rename source/blender/render/hydra/{simpleLightTaskDelegate.h => simple_light_task_delegate.h} (100%) rename source/blender/render/hydra/{viewportEngine.cc => viewport_engine.cc} (99%) rename source/blender/render/hydra/{viewportEngine.h => viewport_engine.h} (100%) diff --git a/source/blender/render/hydra/CMakeLists.txt b/source/blender/render/hydra/CMakeLists.txt index 13e47c11cd2d..91f300f78ac3 100644 --- a/source/blender/render/hydra/CMakeLists.txt +++ b/source/blender/render/hydra/CMakeLists.txt @@ -52,38 +52,38 @@ set(SRC engine.h engine.cc - finalEngine.h - finalEngine.cc - previewEngine.h - previewEngine.cc - viewportEngine.h - viewportEngine.cc + final_engine.h + final_engine.cc + preview_engine.h + preview_engine.cc + viewport_engine.h + viewport_engine.cc camera.h camera.cc utils.h utils.cc - renderTaskDelegate.cc - renderTaskDelegate.h - simpleLightTaskDelegate.cc - simpleLightTaskDelegate.h + render_task_delegate.cc + render_task_delegate.h + simple_light_task_delegate.cc + simple_light_task_delegate.h - sceneDelegate/blenderSceneDelegate.h - sceneDelegate/blenderSceneDelegate.cc - sceneDelegate/id.h - sceneDelegate/id.cc - sceneDelegate/object.h - sceneDelegate/object.cc - sceneDelegate/material.h - sceneDelegate/material.cc - sceneDelegate/mesh.h - sceneDelegate/mesh.cc - sceneDelegate/mtlxHydraAdapter.h - sceneDelegate/mtlxHydraAdapter.cc - sceneDelegate/light.h - sceneDelegate/light.cc - sceneDelegate/world.h - sceneDelegate/world.cc + scene_delegate/blender_scene_delegate.h + scene_delegate/blender_scene_delegate.cc + scene_delegate/id.h + scene_delegate/id.cc + scene_delegate/object.h + scene_delegate/object.cc + scene_delegate/material.h + scene_delegate/material.cc + scene_delegate/mesh.h + scene_delegate/mesh.cc + scene_delegate/mtlx_hydra_adapter.h + scene_delegate/mtlx_hydra_adapter.cc + scene_delegate/light.h + scene_delegate/light.cc + scene_delegate/world.h + scene_delegate/world.cc ) set(LIB diff --git a/source/blender/render/hydra/camera.cc b/source/blender/render/hydra/camera.cc index 48473f700287..f11972796b90 100644 --- a/source/blender/render/hydra/camera.cc +++ b/source/blender/render/hydra/camera.cc @@ -1,7 +1,6 @@ /* SPDX-License-Identifier: Apache-2.0 * Copyright 2011-2022 Blender Foundation */ -#include "BKE_context.h" #include "DNA_camera_types.h" #include "DNA_screen_types.h" diff --git a/source/blender/render/hydra/camera.h b/source/blender/render/hydra/camera.h index 3310f2403f44..9e23146b5a60 100644 --- a/source/blender/render/hydra/camera.h +++ b/source/blender/render/hydra/camera.h @@ -8,6 +8,8 @@ #include #include +#include "BKE_context.h" + #include "DNA_object_types.h" namespace blender::render::hydra { diff --git a/source/blender/render/hydra/engine.h b/source/blender/render/hydra/engine.h index 0b38b6a0e515..5f3f6e123e36 100644 --- a/source/blender/render/hydra/engine.h +++ b/source/blender/render/hydra/engine.h @@ -15,9 +15,9 @@ #include "RE_engine.h" -#include "renderTaskDelegate.h" -#include "sceneDelegate/blenderSceneDelegate.h" -#include "simpleLightTaskDelegate.h" +#include "render_task_delegate.h" +#include "scene_delegate/blender_scene_delegate.h" +#include "simple_light_task_delegate.h" namespace blender::render::hydra { diff --git a/source/blender/render/hydra/finalEngine.cc b/source/blender/render/hydra/final_engine.cc similarity index 99% rename from source/blender/render/hydra/finalEngine.cc rename to source/blender/render/hydra/final_engine.cc index e8917f199b64..b0f791c22e51 100644 --- a/source/blender/render/hydra/finalEngine.cc +++ b/source/blender/render/hydra/final_engine.cc @@ -9,7 +9,7 @@ #include "glog/logging.h" #include "camera.h" -#include "finalEngine.h" +#include "final_engine.h" #include "utils.h" using namespace std; diff --git a/source/blender/render/hydra/finalEngine.h b/source/blender/render/hydra/final_engine.h similarity index 100% rename from source/blender/render/hydra/finalEngine.h rename to source/blender/render/hydra/final_engine.h diff --git a/source/blender/render/hydra/previewEngine.cc b/source/blender/render/hydra/preview_engine.cc similarity index 99% rename from source/blender/render/hydra/previewEngine.cc rename to source/blender/render/hydra/preview_engine.cc index 1f98b61bc5a3..745ea7e605b6 100644 --- a/source/blender/render/hydra/previewEngine.cc +++ b/source/blender/render/hydra/preview_engine.cc @@ -4,7 +4,7 @@ #include "DEG_depsgraph_query.h" #include "camera.h" -#include "previewEngine.h" +#include "preview_engine.h" using namespace pxr; using namespace std; diff --git a/source/blender/render/hydra/previewEngine.h b/source/blender/render/hydra/preview_engine.h similarity index 96% rename from source/blender/render/hydra/previewEngine.h rename to source/blender/render/hydra/preview_engine.h index 5f1d3292567b..2f0a9fc29807 100644 --- a/source/blender/render/hydra/previewEngine.h +++ b/source/blender/render/hydra/preview_engine.h @@ -3,7 +3,7 @@ #pragma once -#include "finalEngine.h" +#include "final_engine.h" namespace blender::render::hydra { diff --git a/source/blender/render/hydra/python.cc b/source/blender/render/hydra/python.cc index 8861680e5a0a..c7f3fa1b4487 100644 --- a/source/blender/render/hydra/python.cc +++ b/source/blender/render/hydra/python.cc @@ -13,10 +13,10 @@ #include "glog/logging.h" -#include "finalEngine.h" -#include "previewEngine.h" +#include "final_engine.h" +#include "preview_engine.h" #include "utils.h" -#include "viewportEngine.h" +#include "viewport_engine.h" using namespace std; diff --git a/source/blender/render/hydra/renderTaskDelegate.cc b/source/blender/render/hydra/render_task_delegate.cc similarity index 99% rename from source/blender/render/hydra/renderTaskDelegate.cc rename to source/blender/render/hydra/render_task_delegate.cc index cdf9ca962768..f6cef248374b 100644 --- a/source/blender/render/hydra/renderTaskDelegate.cc +++ b/source/blender/render/hydra/render_task_delegate.cc @@ -9,7 +9,7 @@ #include "glog/logging.h" -#include "renderTaskDelegate.h" +#include "render_task_delegate.h" namespace blender::render::hydra { diff --git a/source/blender/render/hydra/renderTaskDelegate.h b/source/blender/render/hydra/render_task_delegate.h similarity index 100% rename from source/blender/render/hydra/renderTaskDelegate.h rename to source/blender/render/hydra/render_task_delegate.h diff --git a/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.cc b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc similarity index 99% rename from source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.cc rename to source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc index 8bac1d74455f..65daabb3a7b8 100644 --- a/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -6,7 +6,7 @@ #include "glog/logging.h" -#include "blenderSceneDelegate.h" +#include "blender_scene_delegate.h" using namespace pxr; using namespace std; diff --git a/source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.h b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h similarity index 100% rename from source/blender/render/hydra/sceneDelegate/blenderSceneDelegate.h rename to source/blender/render/hydra/scene_delegate/blender_scene_delegate.h diff --git a/source/blender/render/hydra/sceneDelegate/id.cc b/source/blender/render/hydra/scene_delegate/id.cc similarity index 93% rename from source/blender/render/hydra/sceneDelegate/id.cc rename to source/blender/render/hydra/scene_delegate/id.cc index b6f5f40db27b..84c5c506419e 100644 --- a/source/blender/render/hydra/sceneDelegate/id.cc +++ b/source/blender/render/hydra/scene_delegate/id.cc @@ -3,7 +3,7 @@ #include "BKE_lib_id.h" -#include "blenderSceneDelegate.h" +#include "blender_scene_delegate.h" #include "id.h" using namespace pxr; diff --git a/source/blender/render/hydra/sceneDelegate/id.h b/source/blender/render/hydra/scene_delegate/id.h similarity index 100% rename from source/blender/render/hydra/sceneDelegate/id.h rename to source/blender/render/hydra/scene_delegate/id.h diff --git a/source/blender/render/hydra/sceneDelegate/light.cc b/source/blender/render/hydra/scene_delegate/light.cc similarity index 99% rename from source/blender/render/hydra/sceneDelegate/light.cc rename to source/blender/render/hydra/scene_delegate/light.cc index 5b07b47a245d..796ac6e6f398 100644 --- a/source/blender/render/hydra/sceneDelegate/light.cc +++ b/source/blender/render/hydra/scene_delegate/light.cc @@ -12,7 +12,7 @@ #include "BKE_light.h" #include "DNA_light_types.h" -#include "blenderSceneDelegate.h" +#include "blender_scene_delegate.h" #include "light.h" using namespace pxr; diff --git a/source/blender/render/hydra/sceneDelegate/light.h b/source/blender/render/hydra/scene_delegate/light.h similarity index 100% rename from source/blender/render/hydra/sceneDelegate/light.h rename to source/blender/render/hydra/scene_delegate/light.h diff --git a/source/blender/render/hydra/sceneDelegate/material.cc b/source/blender/render/hydra/scene_delegate/material.cc similarity index 98% rename from source/blender/render/hydra/sceneDelegate/material.cc rename to source/blender/render/hydra/scene_delegate/material.cc index 615f1cbc3236..9b4dfc0a8091 100644 --- a/source/blender/render/hydra/sceneDelegate/material.cc +++ b/source/blender/render/hydra/scene_delegate/material.cc @@ -12,9 +12,9 @@ #include "BKE_lib_id.h" #include "BKE_material.h" -#include "blenderSceneDelegate.h" +#include "blender_scene_delegate.h" #include "material.h" -#include "mtlxHydraAdapter.h" +#include "mtlx_hydra_adapter.h" using namespace pxr; diff --git a/source/blender/render/hydra/sceneDelegate/material.h b/source/blender/render/hydra/scene_delegate/material.h similarity index 100% rename from source/blender/render/hydra/sceneDelegate/material.h rename to source/blender/render/hydra/scene_delegate/material.h diff --git a/source/blender/render/hydra/sceneDelegate/mesh.cc b/source/blender/render/hydra/scene_delegate/mesh.cc similarity index 99% rename from source/blender/render/hydra/sceneDelegate/mesh.cc rename to source/blender/render/hydra/scene_delegate/mesh.cc index 07126f8ddb96..9a642fcada52 100644 --- a/source/blender/render/hydra/sceneDelegate/mesh.cc +++ b/source/blender/render/hydra/scene_delegate/mesh.cc @@ -12,7 +12,7 @@ #include "BKE_object.h" #include "../utils.h" -#include "blenderSceneDelegate.h" +#include "blender_scene_delegate.h" #include "mesh.h" using namespace pxr; diff --git a/source/blender/render/hydra/sceneDelegate/mesh.h b/source/blender/render/hydra/scene_delegate/mesh.h similarity index 100% rename from source/blender/render/hydra/sceneDelegate/mesh.h rename to source/blender/render/hydra/scene_delegate/mesh.h diff --git a/source/blender/render/hydra/sceneDelegate/mtlxHydraAdapter.cc b/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.cc similarity index 98% rename from source/blender/render/hydra/sceneDelegate/mtlxHydraAdapter.cc rename to source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.cc index 3f04c6815f08..9cb6c26a4826 100644 --- a/source/blender/render/hydra/sceneDelegate/mtlxHydraAdapter.cc +++ b/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.cc @@ -1,8 +1,6 @@ /* SPDX-License-Identifier: Apache-2.0 * Copyright 2011-2022 Blender Foundation */ -#include "mtlxHydraAdapter.h" - #include #include @@ -20,6 +18,8 @@ #include #include +#include "mtlx_hydra_adapter.h" + namespace mx = MaterialX; PXR_NAMESPACE_OPEN_SCOPE diff --git a/source/blender/render/hydra/sceneDelegate/mtlxHydraAdapter.h b/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.h similarity index 100% rename from source/blender/render/hydra/sceneDelegate/mtlxHydraAdapter.h rename to source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.h diff --git a/source/blender/render/hydra/sceneDelegate/object.cc b/source/blender/render/hydra/scene_delegate/object.cc similarity index 98% rename from source/blender/render/hydra/sceneDelegate/object.cc rename to source/blender/render/hydra/scene_delegate/object.cc index f1d9bf1910dd..ef48433aea9f 100644 --- a/source/blender/render/hydra/sceneDelegate/object.cc +++ b/source/blender/render/hydra/scene_delegate/object.cc @@ -4,7 +4,7 @@ #include "BKE_object.h" #include "../utils.h" -#include "blenderSceneDelegate.h" +#include "blender_scene_delegate.h" #include "light.h" #include "mesh.h" #include "object.h" diff --git a/source/blender/render/hydra/sceneDelegate/object.h b/source/blender/render/hydra/scene_delegate/object.h similarity index 100% rename from source/blender/render/hydra/sceneDelegate/object.h rename to source/blender/render/hydra/scene_delegate/object.h diff --git a/source/blender/render/hydra/sceneDelegate/world.cc b/source/blender/render/hydra/scene_delegate/world.cc similarity index 99% rename from source/blender/render/hydra/sceneDelegate/world.cc rename to source/blender/render/hydra/scene_delegate/world.cc index b8959df34adf..091a57fa1c68 100644 --- a/source/blender/render/hydra/sceneDelegate/world.cc +++ b/source/blender/render/hydra/scene_delegate/world.cc @@ -23,7 +23,7 @@ #include "glog/logging.h" #include "../utils.h" -#include "blenderSceneDelegate.h" +#include "blender_scene_delegate.h" #include "world.h" /* TODO : add custom tftoken "transparency"? */ diff --git a/source/blender/render/hydra/sceneDelegate/world.h b/source/blender/render/hydra/scene_delegate/world.h similarity index 100% rename from source/blender/render/hydra/sceneDelegate/world.h rename to source/blender/render/hydra/scene_delegate/world.h diff --git a/source/blender/render/hydra/simpleLightTaskDelegate.cc b/source/blender/render/hydra/simple_light_task_delegate.cc similarity index 96% rename from source/blender/render/hydra/simpleLightTaskDelegate.cc rename to source/blender/render/hydra/simple_light_task_delegate.cc index ccc8c2294537..ec483b74bce6 100644 --- a/source/blender/render/hydra/simpleLightTaskDelegate.cc +++ b/source/blender/render/hydra/simple_light_task_delegate.cc @@ -3,7 +3,7 @@ #include -#include "simpleLightTaskDelegate.h" +#include "simple_light_task_delegate.h" namespace blender::render::hydra { diff --git a/source/blender/render/hydra/simpleLightTaskDelegate.h b/source/blender/render/hydra/simple_light_task_delegate.h similarity index 100% rename from source/blender/render/hydra/simpleLightTaskDelegate.h rename to source/blender/render/hydra/simple_light_task_delegate.h diff --git a/source/blender/render/hydra/viewportEngine.cc b/source/blender/render/hydra/viewport_engine.cc similarity index 99% rename from source/blender/render/hydra/viewportEngine.cc rename to source/blender/render/hydra/viewport_engine.cc index cfaba729682f..47cbc2b25ec0 100644 --- a/source/blender/render/hydra/viewportEngine.cc +++ b/source/blender/render/hydra/viewport_engine.cc @@ -7,6 +7,7 @@ #include #include +#include "DNA_vec_types.h" #include "BKE_camera.h" #include "BLI_math_matrix.h" #include "DEG_depsgraph_query.h" @@ -16,9 +17,10 @@ #include "glog/logging.h" +#include "viewport_engine.h" #include "camera.h" #include "utils.h" -#include "viewportEngine.h" + using namespace std; using namespace pxr; diff --git a/source/blender/render/hydra/viewportEngine.h b/source/blender/render/hydra/viewport_engine.h similarity index 100% rename from source/blender/render/hydra/viewportEngine.h rename to source/blender/render/hydra/viewport_engine.h -- 2.30.2 From 55786efc3a7582fadc2517a185d09994aa0e8d72 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Tue, 14 Mar 2023 14:37:33 +0300 Subject: [PATCH 03/11] remove `using namespace` --- source/blender/render/hydra/camera.cc | 96 +++++++++---------- source/blender/render/hydra/engine.cc | 32 +++---- source/blender/render/hydra/engine.h | 12 +-- source/blender/render/hydra/final_engine.cc | 95 +++++++++--------- source/blender/render/hydra/final_engine.h | 2 +- source/blender/render/hydra/preview_engine.cc | 35 ++++--- source/blender/render/hydra/preview_engine.h | 2 +- source/blender/render/hydra/python.cc | 26 +++-- .../render/hydra/render_task_delegate.cc | 78 +++++++-------- .../render/hydra/render_task_delegate.h | 30 +++--- .../scene_delegate/blender_scene_delegate.cc | 85 ++++++++-------- .../blender/render/hydra/scene_delegate/id.cc | 6 +- .../render/hydra/scene_delegate/light.cc | 69 +++++++------ .../render/hydra/scene_delegate/material.cc | 32 +++---- .../render/hydra/scene_delegate/mesh.cc | 94 +++++++++--------- .../scene_delegate/mtlx_hydra_adapter.cc | 46 ++++----- .../hydra/scene_delegate/mtlx_hydra_adapter.h | 12 +-- .../render/hydra/scene_delegate/object.cc | 4 +- .../render/hydra/scene_delegate/world.cc | 46 +++++---- .../hydra/simple_light_task_delegate.cc | 24 ++--- .../render/hydra/simple_light_task_delegate.h | 16 ++-- source/blender/render/hydra/utils.cc | 46 +++++---- .../blender/render/hydra/viewport_engine.cc | 64 ++++++------- 23 files changed, 453 insertions(+), 499 deletions(-) diff --git a/source/blender/render/hydra/camera.cc b/source/blender/render/hydra/camera.cc index f11972796b90..b6c74ccda302 100644 --- a/source/blender/render/hydra/camera.cc +++ b/source/blender/render/hydra/camera.cc @@ -7,18 +7,16 @@ #include "camera.h" #include "utils.h" -using namespace pxr; - namespace blender::render::hydra { -CameraData::CameraData(Object *camera_obj, GfVec2i res, GfVec4f tile) +CameraData::CameraData(Object *camera_obj, pxr::GfVec2i res, pxr::GfVec4f tile) { Camera *camera = (Camera *)camera_obj->data; float t_pos[2] = {tile[0], tile[1]}; float t_size[2] = {tile[2], tile[3]}; transform = gf_matrix_from_transform(camera_obj->object_to_world); - clip_range = GfRange1f(camera->clip_start, camera->clip_end); + clip_range = pxr::GfRange1f(camera->clip_start, camera->clip_end); mode = camera->type; if (camera->dof.flag & CAM_DOF_ENABLED) { @@ -27,10 +25,10 @@ CameraData::CameraData(Object *camera_obj, GfVec2i res, GfVec4f tile) focus_distance = camera->dof.focus_distance; } else { - GfVec3f obj_pos(camera->dof.focus_object->object_to_world[0][3], + pxr::GfVec3f obj_pos(camera->dof.focus_object->object_to_world[0][3], camera->dof.focus_object->object_to_world[1][3], camera->dof.focus_object->object_to_world[2][3]); - GfVec3f cam_pos(transform[0][3], transform[1][3], transform[2][3]); + pxr::GfVec3f cam_pos(transform[0][3], transform[1][3], transform[2][3]); focus_distance = (obj_pos - cam_pos).GetLength(); } @@ -42,25 +40,25 @@ CameraData::CameraData(Object *camera_obj, GfVec2i res, GfVec4f tile) switch (camera->sensor_fit) { case CAMERA_SENSOR_FIT_VERT: - lens_shift = GfVec2f(camera->shiftx / ratio, camera->shifty); + lens_shift = pxr::GfVec2f(camera->shiftx / ratio, camera->shifty); break; case CAMERA_SENSOR_FIT_HOR: - lens_shift = GfVec2f(camera->shiftx, camera->shifty * ratio); + lens_shift = pxr::GfVec2f(camera->shiftx, camera->shifty * ratio); break; case CAMERA_SENSOR_FIT_AUTO: if (ratio > 1.0f) { - lens_shift = GfVec2f(camera->shiftx, camera->shifty * ratio); + lens_shift = pxr::GfVec2f(camera->shiftx, camera->shifty * ratio); } else { - lens_shift = GfVec2f(camera->shiftx / ratio, camera->shifty); + lens_shift = pxr::GfVec2f(camera->shiftx / ratio, camera->shifty); } break; default: - lens_shift = GfVec2f(camera->shiftx, camera->shifty); + lens_shift = pxr::GfVec2f(camera->shiftx, camera->shifty); break; } - lens_shift = GfVec2f(lens_shift[0] / t_size[0] + (t_pos[0] + t_size[0] * 0.5 - 0.5) / t_size[0], + lens_shift = pxr::GfVec2f(lens_shift[0] / t_size[0] + (t_pos[0] + t_size[0] * 0.5 - 0.5) / t_size[0], lens_shift[1] / t_size[1] + (t_pos[1] + t_size[1] * 0.5 - 0.5) / t_size[1]); switch (camera->type) { @@ -69,48 +67,48 @@ CameraData::CameraData(Object *camera_obj, GfVec2i res, GfVec4f tile) switch (camera->sensor_fit) { case CAMERA_SENSOR_FIT_VERT: - sensor_size = GfVec2f(camera->sensor_y * ratio, camera->sensor_y); + sensor_size = pxr::GfVec2f(camera->sensor_y * ratio, camera->sensor_y); break; case CAMERA_SENSOR_FIT_HOR: - sensor_size = GfVec2f(camera->sensor_x, camera->sensor_x / ratio); + sensor_size = pxr::GfVec2f(camera->sensor_x, camera->sensor_x / ratio); break; case CAMERA_SENSOR_FIT_AUTO: if (ratio > 1.0f) { - sensor_size = GfVec2f(camera->sensor_x, camera->sensor_x / ratio); + sensor_size = pxr::GfVec2f(camera->sensor_x, camera->sensor_x / ratio); } else { - sensor_size = GfVec2f(camera->sensor_x * ratio, camera->sensor_x); + sensor_size = pxr::GfVec2f(camera->sensor_x * ratio, camera->sensor_x); } break; default: - sensor_size = GfVec2f(camera->sensor_x, camera->sensor_y); + sensor_size = pxr::GfVec2f(camera->sensor_x, camera->sensor_y); break; } - sensor_size = GfVec2f(sensor_size[0] * t_size[0], sensor_size[1] * t_size[1]); + sensor_size = pxr::GfVec2f(sensor_size[0] * t_size[0], sensor_size[1] * t_size[1]); break; case CAM_ORTHO: focal_length = 0.0f; switch (camera->sensor_fit) { case CAMERA_SENSOR_FIT_VERT: - ortho_size = GfVec2f(camera->ortho_scale * ratio, camera->ortho_scale); + ortho_size = pxr::GfVec2f(camera->ortho_scale * ratio, camera->ortho_scale); break; case CAMERA_SENSOR_FIT_HOR: - ortho_size = GfVec2f(camera->ortho_scale, camera->ortho_scale / ratio); + ortho_size = pxr::GfVec2f(camera->ortho_scale, camera->ortho_scale / ratio); break; case CAMERA_SENSOR_FIT_AUTO: if (ratio > 1.0f) { - ortho_size = GfVec2f(camera->ortho_scale, camera->ortho_scale / ratio); + ortho_size = pxr::GfVec2f(camera->ortho_scale, camera->ortho_scale / ratio); } else { - ortho_size = GfVec2f(camera->ortho_scale * ratio, camera->ortho_scale); + ortho_size = pxr::GfVec2f(camera->ortho_scale * ratio, camera->ortho_scale); } break; default: - ortho_size = GfVec2f(camera->ortho_scale, camera->ortho_scale); + ortho_size = pxr::GfVec2f(camera->ortho_scale, camera->ortho_scale); break; } - ortho_size = GfVec2f(ortho_size[0] * t_size[0], ortho_size[1] * t_size[1]); + ortho_size = pxr::GfVec2f(ortho_size[0] * t_size[0], ortho_size[1] * t_size[1]); break; case CAM_PANO: @@ -119,28 +117,28 @@ CameraData::CameraData(Object *camera_obj, GfVec2i res, GfVec4f tile) switch (camera->sensor_fit) { case CAMERA_SENSOR_FIT_VERT: - sensor_size = GfVec2f(camera->sensor_y * ratio, camera->sensor_y); + sensor_size = pxr::GfVec2f(camera->sensor_y * ratio, camera->sensor_y); break; case CAMERA_SENSOR_FIT_HOR: - sensor_size = GfVec2f(camera->sensor_x, camera->sensor_x / ratio); + sensor_size = pxr::GfVec2f(camera->sensor_x, camera->sensor_x / ratio); break; case CAMERA_SENSOR_FIT_AUTO: if (ratio > 1.0f) { - sensor_size = GfVec2f(camera->sensor_x, camera->sensor_x / ratio); + sensor_size = pxr::GfVec2f(camera->sensor_x, camera->sensor_x / ratio); } else { - sensor_size = GfVec2f(camera->sensor_x * ratio, camera->sensor_x); + sensor_size = pxr::GfVec2f(camera->sensor_x * ratio, camera->sensor_x); } break; default: - sensor_size = GfVec2f(camera->sensor_x, camera->sensor_y); + sensor_size = pxr::GfVec2f(camera->sensor_x, camera->sensor_y); break; } - sensor_size = GfVec2f(sensor_size[0] * t_size[0], sensor_size[1] * t_size[1]); + sensor_size = pxr::GfVec2f(sensor_size[0] * t_size[0], sensor_size[1] * t_size[1]); default: focal_length = camera->lens; - sensor_size = GfVec2f(camera->sensor_y * ratio, camera->sensor_y); + sensor_size = pxr::GfVec2f(camera->sensor_y * ratio, camera->sensor_y); } } @@ -154,47 +152,47 @@ CameraData::CameraData(bContext *context) // context.view3d or context.region_data float VIEWPORT_SENSOR_SIZE = 72.0; - GfVec2i res(region->winx, region->winy); + pxr::GfVec2i res(region->winx, region->winy); float ratio = (float)res[0] / res[1]; transform = gf_matrix_from_transform(region_data->viewmat).GetInverse(); switch (region_data->persp) { case RV3D_PERSP: { mode = CAM_PERSP; - clip_range = GfRange1f(view3d->clip_start, view3d->clip_end); - lens_shift = GfVec2f(0.0, 0.0); + clip_range = pxr::GfRange1f(view3d->clip_start, view3d->clip_end); + lens_shift = pxr::GfVec2f(0.0, 0.0); focal_length = view3d->lens; if (ratio > 1.0) { - sensor_size = GfVec2f(VIEWPORT_SENSOR_SIZE, VIEWPORT_SENSOR_SIZE / ratio); + sensor_size = pxr::GfVec2f(VIEWPORT_SENSOR_SIZE, VIEWPORT_SENSOR_SIZE / ratio); } else { - sensor_size = GfVec2f(VIEWPORT_SENSOR_SIZE * ratio, VIEWPORT_SENSOR_SIZE); + sensor_size = pxr::GfVec2f(VIEWPORT_SENSOR_SIZE * ratio, VIEWPORT_SENSOR_SIZE); } break; } case RV3D_ORTHO: { mode = CAM_ORTHO; - lens_shift = GfVec2f(0.0f, 0.0f); + lens_shift = pxr::GfVec2f(0.0f, 0.0f); float o_size = region_data->dist * VIEWPORT_SENSOR_SIZE / view3d->lens; float o_depth = view3d->clip_end; - clip_range = GfRange1f(-o_depth * 0.5, o_depth * 0.5); + clip_range = pxr::GfRange1f(-o_depth * 0.5, o_depth * 0.5); if (ratio > 1.0f) { - ortho_size = GfVec2f(o_size, o_size / ratio); + ortho_size = pxr::GfVec2f(o_size, o_size / ratio); } else { - ortho_size = GfVec2f(o_size * ratio, o_size); + ortho_size = pxr::GfVec2f(o_size * ratio, o_size); } break; } case RV3D_CAMOB: { - GfMatrix4d mat = transform; - *this = CameraData(view3d->camera, res, GfVec4f(0, 0, 1, 1)); + pxr::GfMatrix4d mat = transform; + *this = CameraData(view3d->camera, res, pxr::GfVec4f(0, 0, 1, 1)); transform = mat; // This formula was taken from previous plugin with corresponded comment @@ -204,7 +202,7 @@ CameraData::CameraData(bContext *context) // Updating l_shift due to viewport zoom and view_camera_offset // view_camera_offset should be multiplied by 2 - lens_shift = GfVec2f((lens_shift[0] + region_data->camdx * 2) / zoom, + lens_shift = pxr::GfVec2f((lens_shift[0] + region_data->camdx * 2) / zoom, (lens_shift[1] + region_data->camdy * 2) / zoom); if (mode == CAM_ORTHO) { @@ -221,11 +219,11 @@ CameraData::CameraData(bContext *context) } } -GfCamera CameraData::gf_camera(GfVec4f tile) +pxr::GfCamera CameraData::gf_camera(pxr::GfVec4f tile) { float t_pos[2] = {tile[0], tile[1]}, t_size[2] = {tile[2], tile[3]}; - GfCamera gf_camera = GfCamera(); + pxr::GfCamera gf_camera = pxr::GfCamera(); gf_camera.SetClippingRange(clip_range); @@ -236,7 +234,7 @@ GfCamera CameraData::gf_camera(GfVec4f tile) case CAM_PERSP: case CAM_PANO: { /* TODO: store panoramic camera settings */ - gf_camera.SetProjection(GfCamera::Projection::Perspective); + gf_camera.SetProjection(pxr::GfCamera::Projection::Perspective); gf_camera.SetFocalLength(focal_length); float s_size[2] = {sensor_size[0] * t_size[0], sensor_size[1] * t_size[1]}; @@ -249,7 +247,7 @@ GfCamera CameraData::gf_camera(GfVec4f tile) break; } case CAM_ORTHO: { - gf_camera.SetProjection(GfCamera::Projection::Orthographic); + gf_camera.SetProjection(pxr::GfCamera::Projection::Orthographic); // Use tenths of a world unit accorging to USD docs // https://graphics.pixar.com/usd/docs/api/class_gf_camera.html @@ -270,9 +268,9 @@ GfCamera CameraData::gf_camera(GfVec4f tile) return gf_camera; } -GfCamera CameraData::gf_camera() +pxr::GfCamera CameraData::gf_camera() { - return gf_camera(GfVec4f(0, 0, 1, 1)); + return gf_camera(pxr::GfVec4f(0, 0, 1, 1)); } } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/engine.cc b/source/blender/render/hydra/engine.cc index 19cac0fabc85..84d2719d2720 100644 --- a/source/blender/render/hydra/engine.cc +++ b/source/blender/render/hydra/engine.cc @@ -12,37 +12,35 @@ #include "engine.h" -using namespace pxr; - namespace blender::render::hydra { Engine::Engine(RenderEngine *bl_engine, const std::string &delegateId) : bl_engine(bl_engine) { - HdRendererPluginRegistry ®istry = HdRendererPluginRegistry::GetInstance(); + pxr::HdRendererPluginRegistry ®istry = pxr::HdRendererPluginRegistry::GetInstance(); - TF_PY_ALLOW_THREADS_IN_SCOPE(); - render_delegate = registry.CreateRenderDelegate(TfToken(delegateId)); - - HdDriverVector hd_drivers; + //TF_PY_ALLOW_THREADS_IN_SCOPE(); + render_delegate = registry.CreateRenderDelegate(pxr::TfToken(delegateId)); + + pxr::HdDriverVector hd_drivers; if (bl_engine->type->flag & RE_USE_GPU_CONTEXT) { - hgi = Hgi::CreatePlatformDefaultHgi(); - hgi_driver.name = HgiTokens->renderDriver; - hgi_driver.driver = VtValue(hgi.get()); + hgi = pxr::Hgi::CreatePlatformDefaultHgi(); + hgi_driver.name = pxr::HgiTokens->renderDriver; + hgi_driver.driver = pxr::VtValue(hgi.get()); hd_drivers.push_back(&hgi_driver); } - render_index.reset(HdRenderIndex::New(render_delegate.Get(), hd_drivers)); - free_camera_delegate = std::make_unique( - render_index.get(), SdfPath::AbsoluteRootPath().AppendElementString("freeCamera")); + render_index.reset(pxr::HdRenderIndex::New(render_delegate.Get(), hd_drivers)); + free_camera_delegate = std::make_unique( + render_index.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("freeCamera")); render_task_delegate = std::make_unique( - render_index.get(), SdfPath::AbsoluteRootPath().AppendElementString("renderTask")); + render_index.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("renderTask")); if (render_delegate->GetRendererDisplayName() == "GL") { simple_light_task_delegate = std::make_unique( - render_index.get(), SdfPath::AbsoluteRootPath().AppendElementString("simpleLightTask")); + render_index.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("simpleLightTask")); } - engine = std::make_unique(); + engine = std::make_unique(); } Engine::~Engine() @@ -59,7 +57,7 @@ Engine::~Engine() float Engine::renderer_percent_done() { - VtDictionary render_stats = render_delegate->GetRenderStats(); + pxr::VtDictionary render_stats = render_delegate->GetRenderStats(); auto it = render_stats.find("percentDone"); if (it == render_stats.end()) { return 0.0; diff --git a/source/blender/render/hydra/engine.h b/source/blender/render/hydra/engine.h index 5f3f6e123e36..879fdc097d02 100644 --- a/source/blender/render/hydra/engine.h +++ b/source/blender/render/hydra/engine.h @@ -37,16 +37,16 @@ class Engine { protected: RenderEngine *bl_engine; - HdPluginRenderDelegateUniqueHandle render_delegate; - std::unique_ptr render_index; + pxr::HdPluginRenderDelegateUniqueHandle render_delegate; + std::unique_ptr render_index; std::unique_ptr scene_delegate; std::unique_ptr render_task_delegate; - std::unique_ptr free_camera_delegate; + std::unique_ptr free_camera_delegate; std::unique_ptr simple_light_task_delegate; - std::unique_ptr engine; + std::unique_ptr engine; - HgiUniquePtr hgi; - HdDriver hgi_driver; + pxr::HgiUniquePtr hgi; + pxr::HdDriver hgi_driver; }; } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/final_engine.cc b/source/blender/render/hydra/final_engine.cc index b0f791c22e51..4a1ffc59e6b7 100644 --- a/source/blender/render/hydra/final_engine.cc +++ b/source/blender/render/hydra/final_engine.cc @@ -12,18 +12,15 @@ #include "final_engine.h" #include "utils.h" -using namespace std; -using namespace pxr; - namespace blender::render::hydra { void FinalEngine::sync(Depsgraph *depsgraph, bContext *context, - HdRenderSettingsMap &renderSettings) + pxr::HdRenderSettingsMap &renderSettings) { scene_delegate = std::make_unique( render_index.get(), - SdfPath::AbsoluteRootPath().AppendElementString("scene"), + pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"), BlenderSceneDelegate::EngineType::Final); scene_delegate->populate(depsgraph, context); @@ -37,48 +34,48 @@ void FinalEngine::render(Depsgraph *depsgraph) Scene *scene = DEG_get_input_scene(depsgraph); ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph); - string scene_name(MAX_ID_FULL_NAME, 0); + std::string scene_name(MAX_ID_FULL_NAME, 0); BKE_id_full_name_get(scene_name.data(), (ID *)scene, 0); - string layer_name = view_layer->name; + std::string layer_name = view_layer->name; RenderData &r = scene->r; - GfVec4f border(0, 0, 1, 1); + pxr::GfVec4f border(0, 0, 1, 1); if (r.mode & R_BORDER) { - border = GfVec4f(r.border.xmin, + border = pxr::GfVec4f(r.border.xmin, r.border.ymin, r.border.xmax - r.border.xmin, r.border.ymax - r.border.ymin); } - GfVec2i image_res(r.xsch * r.size / 100, r.ysch * r.size / 100); - GfVec2i res(int(image_res[0] * border[2]), int(image_res[1] * border[3])); - GfCamera camera = CameraData(scene->camera, image_res, GfVec4f(0, 0, 1, 1)).gf_camera(border); + pxr::GfVec2i image_res(r.xsch * r.size / 100, r.ysch * r.size / 100); + pxr::GfVec2i res(int(image_res[0] * border[2]), int(image_res[1] * border[3])); + pxr::GfCamera camera = CameraData(scene->camera, image_res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(border); free_camera_delegate->SetCamera(camera); render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(), - GfVec4d(0, 0, res[0], res[1])); - render_task_delegate->SetRendererAov(HdAovTokens->color); + pxr::GfVec4d(0, 0, res[0], res[1])); + render_task_delegate->SetRendererAov(pxr::HdAovTokens->color); if (simple_light_task_delegate) { simple_light_task_delegate->SetCameraPath(free_camera_delegate->GetCameraId()); } - HdTaskSharedPtrVector tasks; + pxr::HdTaskSharedPtrVector tasks; if (simple_light_task_delegate) { tasks.push_back(simple_light_task_delegate->GetTask()); } tasks.push_back(render_task_delegate->GetTask()); - chrono::time_point timeBegin = chrono::steady_clock::now(), timeCurrent; - chrono::milliseconds elapsedTime; + std::chrono::time_point timeBegin = std::chrono::steady_clock::now(), timeCurrent; + std::chrono::milliseconds elapsedTime; float percentDone = 0.0; - map> renderImages{ - {"Combined", vector(res[0] * res[1] * 4)}}; // 4 - number of channels - vector &pixels = renderImages["Combined"]; + std::map> renderImages{ + {"Combined", std::vector(res[0] * res[1] * 4)}}; // 4 - number of channels + std::vector &pixels = renderImages["Combined"]; { // Release the GIL before calling into hydra, in case any hydra plugins call into python. - TF_PY_ALLOW_THREADS_IN_SCOPE(); + pxr::TF_PY_ALLOW_THREADS_IN_SCOPE(); engine->Execute(render_index.get(), &tasks); } @@ -88,27 +85,27 @@ void FinalEngine::render(Depsgraph *depsgraph) } percentDone = renderer_percent_done(); - timeCurrent = chrono::steady_clock::now(); - elapsedTime = chrono::duration_cast(timeCurrent - timeBegin); + timeCurrent = std::chrono::steady_clock::now(); + elapsedTime = std::chrono::duration_cast(timeCurrent - timeBegin); notify_status(percentDone / 100.0, scene_name + ": " + layer_name, "Render Time: " + format_duration(elapsedTime) + - " | Done: " + to_string(int(percentDone)) + "%"); + " | Done: " + std::to_string(int(percentDone)) + "%"); if (render_task_delegate->IsConverged()) { break; } - render_task_delegate->GetRendererAovData(HdAovTokens->color, pixels.data()); + render_task_delegate->GetRendererAovData(pxr::HdAovTokens->color, pixels.data()); updateRenderResult(renderImages, layer_name, res[0], res[1]); } - render_task_delegate->GetRendererAovData(HdAovTokens->color, pixels.data()); + render_task_delegate->GetRendererAovData(pxr::HdAovTokens->color, pixels.data()); updateRenderResult(renderImages, layer_name, res[0], res[1]); } -GfVec2i FinalEngine::get_resolution(Scene *scene) +pxr::GfVec2i FinalEngine::get_resolution(Scene *scene) { RenderData &r = scene->r; float border_w = 1.0, border_h = 1.0; @@ -116,11 +113,11 @@ GfVec2i FinalEngine::get_resolution(Scene *scene) border_w = r.border.xmax - r.border.xmin; border_h = r.border.ymax - r.border.ymin; } - return GfVec2i(int(r.xsch * border_w * r.size / 100), int(r.ysch * border_h * r.size / 100)); + return pxr::GfVec2i(int(r.xsch * border_w * r.size / 100), int(r.ysch * border_h * r.size / 100)); } -void FinalEngine::updateRenderResult(map> &renderImages, - const string &layerName, +void FinalEngine::updateRenderResult(std::map> &renderImages, + const std::string &layerName, int width, int height) { @@ -142,7 +139,7 @@ void FinalEngine::updateRenderResult(map> &renderImages, RE_engine_end_result(bl_engine, result, false, false, false); } -void FinalEngine::notify_status(float progress, const string &title, const string &info) +void FinalEngine::notify_status(float progress, const std::string &title, const std::string &info) { RE_engine_update_progress(bl_engine, progress); RE_engine_update_stats(bl_engine, title.c_str(), info.c_str()); @@ -153,30 +150,30 @@ void FinalEngineGL::render(Depsgraph *depsgraph) Scene *scene = DEG_get_input_scene(depsgraph); ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph); - string scene_name(MAX_ID_FULL_NAME, 0); + std::string scene_name(MAX_ID_FULL_NAME, 0); BKE_id_full_name_get(scene_name.data(), (ID *)scene, 0); - string layer_name = view_layer->name; + std::string layer_name = view_layer->name; RenderData &r = scene->r; - GfVec4f border(0, 0, 1, 1); + pxr::GfVec4f border(0, 0, 1, 1); if (r.mode & R_BORDER) { - border = GfVec4f(r.border.xmin, + border = pxr::GfVec4f(r.border.xmin, r.border.ymin, r.border.xmax - r.border.xmin, r.border.ymax - r.border.ymin); } - GfVec2i image_res = {r.xsch * r.size / 100, r.ysch * r.size / 100}; - GfVec2i res = {int(image_res[0] * border[2]), int(image_res[1] * border[3])}; - GfCamera camera = CameraData(scene->camera, image_res, GfVec4f(0, 0, 1, 1)).gf_camera(border); + pxr::GfVec2i image_res = {r.xsch * r.size / 100, r.ysch * r.size / 100}; + pxr::GfVec2i res = {int(image_res[0] * border[2]), int(image_res[1] * border[3])}; + pxr::GfCamera camera = CameraData(scene->camera, image_res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(border); free_camera_delegate->SetCamera(camera); render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(), - GfVec4d(0, 0, res[0], res[1])); + pxr::GfVec4d(0, 0, res[0], res[1])); if (simple_light_task_delegate) { simple_light_task_delegate->SetCameraPath(free_camera_delegate->GetCameraId()); } - HdTaskSharedPtrVector tasks; + pxr::HdTaskSharedPtrVector tasks; if (simple_light_task_delegate) { /* TODO: Uncomment this and fix GL error: invalid operation, reported from void __cdecl @@ -185,14 +182,14 @@ void FinalEngineGL::render(Depsgraph *depsgraph) } tasks.push_back(render_task_delegate->GetTask()); - chrono::time_point timeBegin = chrono::steady_clock::now(), timeCurrent; - chrono::milliseconds elapsedTime; + std::chrono::time_point timeBegin = std::chrono::steady_clock::now(), timeCurrent; + std::chrono::milliseconds elapsedTime; float percentDone = 0.0; - map> renderImages{ - {"Combined", vector(res[0] * res[1] * 4)}}; // 4 - number of channels - vector &pixels = renderImages["Combined"]; + std::map> renderImages{ + {"Combined", std::vector(res[0] * res[1] * 4)}}; // 4 - number of channels + std::vector &pixels = renderImages["Combined"]; GLuint FramebufferName = 0; glGenFramebuffers(1, &FramebufferName); @@ -222,7 +219,7 @@ void FinalEngineGL::render(Depsgraph *depsgraph) { // Release the GIL before calling into hydra, in case any hydra plugins call into python. - TF_PY_ALLOW_THREADS_IN_SCOPE(); + pxr::TF_PY_ALLOW_THREADS_IN_SCOPE(); engine->Execute(render_index.get(), &tasks); } @@ -232,13 +229,13 @@ void FinalEngineGL::render(Depsgraph *depsgraph) } percentDone = renderer_percent_done(); - timeCurrent = chrono::steady_clock::now(); - elapsedTime = chrono::duration_cast(timeCurrent - timeBegin); + timeCurrent = std::chrono::steady_clock::now(); + elapsedTime = std::chrono::duration_cast(timeCurrent - timeBegin); notify_status(percentDone / 100.0, scene_name + ": " + layer_name, "Render Time: " + format_duration(elapsedTime) + - " | Done: " + to_string(int(percentDone)) + "%"); + " | Done: " + std::to_string(int(percentDone)) + "%"); if (render_task_delegate->IsConverged()) { break; diff --git a/source/blender/render/hydra/final_engine.h b/source/blender/render/hydra/final_engine.h index 591fa7326953..a4345d0f9148 100644 --- a/source/blender/render/hydra/final_engine.h +++ b/source/blender/render/hydra/final_engine.h @@ -26,7 +26,7 @@ class FinalEngine : public Engine { void notify_status(float progress, const std::string &title, const std::string &info); protected: - HdRenderSettingsMap renderSettings; + pxr::HdRenderSettingsMap renderSettings; }; class FinalEngineGL : public FinalEngine { diff --git a/source/blender/render/hydra/preview_engine.cc b/source/blender/render/hydra/preview_engine.cc index 745ea7e605b6..bdaf6f878695 100644 --- a/source/blender/render/hydra/preview_engine.cc +++ b/source/blender/render/hydra/preview_engine.cc @@ -6,18 +6,15 @@ #include "camera.h" #include "preview_engine.h" -using namespace pxr; -using namespace std; - namespace blender::render::hydra { void PreviewEngine::sync(Depsgraph *depsgraph, bContext *context, - HdRenderSettingsMap &renderSettings) + pxr::HdRenderSettingsMap &renderSettings) { - scene_delegate = make_unique( + scene_delegate = std::make_unique( render_index.get(), - SdfPath::AbsoluteRootPath().AppendElementString("scene"), + pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"), BlenderSceneDelegate::EngineType::Preview); scene_delegate->populate(depsgraph, context); @@ -31,28 +28,28 @@ void PreviewEngine::render(Depsgraph *depsgraph) Scene *scene = DEG_get_input_scene(depsgraph); ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph); - string layerName = view_layer->name; - GfVec2i res(scene->r.xsch, scene->r.ysch); + std::string layerName = view_layer->name; + pxr::GfVec2i res(scene->r.xsch, scene->r.ysch); - GfCamera camera = - CameraData(scene->camera, res, GfVec4f(0, 0, 1, 1)).gf_camera(GfVec4f(0, 0, 1, 1)); + pxr::GfCamera camera = + CameraData(scene->camera, res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(pxr::GfVec4f(0, 0, 1, 1)); free_camera_delegate->SetCamera(camera); render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(), - GfVec4d(0, 0, res[0], res[1])); - render_task_delegate->SetRendererAov(HdAovTokens->color); + pxr::GfVec4d(0, 0, res[0], res[1])); + render_task_delegate->SetRendererAov(pxr::HdAovTokens->color); - HdTaskSharedPtrVector tasks; + pxr::HdTaskSharedPtrVector tasks; if (simple_light_task_delegate) { tasks.push_back(simple_light_task_delegate->GetTask()); } tasks.push_back(render_task_delegate->GetTask()); - vector pixels = vector(res[0] * res[1] * 4); // 4 - number of channels + std::vector pixels = std::vector(res[0] * 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(); + pxr::TF_PY_ALLOW_THREADS_IN_SCOPE(); engine->Execute(render_index.get(), &tasks); } @@ -65,18 +62,18 @@ void PreviewEngine::render(Depsgraph *depsgraph) break; } - render_task_delegate->GetRendererAovData(HdAovTokens->color, pixels.data()); + render_task_delegate->GetRendererAovData(pxr::HdAovTokens->color, pixels.data()); updateRenderResult(layerName, res[0], res[1], pixels); } - render_task_delegate->GetRendererAovData(HdAovTokens->color, pixels.data()); + render_task_delegate->GetRendererAovData(pxr::HdAovTokens->color, pixels.data()); updateRenderResult(layerName, res[0], res[1], pixels); } -void PreviewEngine::updateRenderResult(const string &layerName, +void PreviewEngine::updateRenderResult(const std::string &layerName, int width, int height, - vector &pixels) + std::vector &pixels) { RenderResult *result = RE_engine_begin_result( bl_engine, 0, 0, width, height, layerName.c_str(), nullptr); diff --git a/source/blender/render/hydra/preview_engine.h b/source/blender/render/hydra/preview_engine.h index 2f0a9fc29807..3a8444bbaa91 100644 --- a/source/blender/render/hydra/preview_engine.h +++ b/source/blender/render/hydra/preview_engine.h @@ -22,7 +22,7 @@ class PreviewEngine : public FinalEngine { std::vector &pixels); protected: - HdRenderSettingsMap renderSettings; + pxr::HdRenderSettingsMap renderSettings; }; } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/python.cc b/source/blender/render/hydra/python.cc index c7f3fa1b4487..5860a7a4cbca 100644 --- a/source/blender/render/hydra/python.cc +++ b/source/blender/render/hydra/python.cc @@ -18,8 +18,6 @@ #include "utils.h" #include "viewport_engine.h" -using namespace std; - namespace blender::render::hydra { void setup_usd_mtlx_environment() @@ -47,7 +45,7 @@ static PyObject *init_func(PyObject * /*self*/, PyObject *args) { LOG(INFO) << "init_func"; - pxr::PlugRegistry::GetInstance().RegisterPlugins(string(BKE_appdir_program_dir()) + + pxr::PlugRegistry::GetInstance().RegisterPlugins(std::string(BKE_appdir_program_dir()) + "/blender.shared/usd"); setup_usd_mtlx_environment(); @@ -64,7 +62,7 @@ static PyObject *register_plugins_func(PyObject * /*self*/, PyObject *args) LOG(INFO) << "register_plugins_func"; - vector plugin_dirs, path_dirs; + std::vector plugin_dirs, path_dirs; PyObject *pyiter, *pyitem; pyiter = PyObject_GetIter(pyplugin_dirs); @@ -99,8 +97,8 @@ static PyObject *get_render_plugins_func(PyObject * /*self*/, PyObject *args) { LOG(INFO) << "get_render_plugins_func"; - PlugRegistry ®istry = PlugRegistry::GetInstance(); - TfTokenVector plugin_ids = UsdImagingGLEngine::GetRendererPlugins(); + pxr::PlugRegistry ®istry = pxr::PlugRegistry::GetInstance(); + pxr::TfTokenVector plugin_ids = pxr::UsdImagingGLEngine::GetRendererPlugins(); PyObject *ret = PyTuple_New(plugin_ids.size()); PyObject *val; for (int i = 0; i < plugin_ids.size(); ++i) { @@ -112,14 +110,14 @@ static PyObject *get_render_plugins_func(PyObject * /*self*/, PyObject *args) PyDict_SetItemString(descr, "name", val = PyUnicode_FromString( - UsdImagingGLEngine::GetRendererDisplayName(plugin_ids[i]).c_str())); + pxr::UsdImagingGLEngine::GetRendererDisplayName(plugin_ids[i]).c_str())); Py_DECREF(val); - string plugin_name = plugin_ids[i]; + std::string plugin_name = plugin_ids[i]; plugin_name = plugin_name.substr(0, plugin_name.size() - 6); plugin_name[0] = tolower(plugin_name[0]); - string path = ""; - PlugPluginPtr plugin = registry.GetPluginWithName(plugin_name); + std::string path = ""; + pxr::PlugPluginPtr plugin = registry.GetPluginWithName(plugin_name); if (plugin) { path = plugin->GetPath(); } @@ -145,10 +143,10 @@ static PyObject *engine_create_func(PyObject * /*self*/, PyObject *args) Engine *engine; - if (string(engineType) == "VIEWPORT") { + if (std::string(engineType) == "VIEWPORT") { engine = new ViewportEngine(bl_engine, render_delegate_id); } - else if (string(engineType) == "PREVIEW") { + else if (std::string(engineType) == "PREVIEW") { engine = new PreviewEngine(bl_engine, render_delegate_id); } else { @@ -187,12 +185,12 @@ static PyObject *engine_sync_func(PyObject * /*self*/, PyObject *args) Depsgraph *depsgraph = (Depsgraph *)PyLong_AsVoidPtr(pydepsgraph); bContext *context = (bContext *)PyLong_AsVoidPtr(pycontext); - HdRenderSettingsMap settings; + pxr::HdRenderSettingsMap settings; PyObject *pyiter = PyObject_GetIter(pysettings); if (pyiter) { PyObject *pykey, *pyval; while (pykey = PyIter_Next(pyiter)) { - TfToken key(PyUnicode_AsUTF8(pykey)); + pxr::TfToken key(PyUnicode_AsUTF8(pykey)); pyval = PyDict_GetItem(pysettings, pykey); if (PyLong_Check(pyval)) { diff --git a/source/blender/render/hydra/render_task_delegate.cc b/source/blender/render/hydra/render_task_delegate.cc index f6cef248374b..6bc92a0c994f 100644 --- a/source/blender/render/hydra/render_task_delegate.cc +++ b/source/blender/render/hydra/render_task_delegate.cc @@ -13,117 +13,117 @@ namespace blender::render::hydra { -RenderTaskDelegate::RenderTaskDelegate(HdRenderIndex *parentIndex, SdfPath const &delegateID) - : HdSceneDelegate(parentIndex, delegateID) +RenderTaskDelegate::RenderTaskDelegate(pxr::HdRenderIndex *parentIndex, pxr::SdfPath const &delegateID) + : pxr::HdSceneDelegate(parentIndex, delegateID) { - SdfPath renderTaskId = GetTaskID(); - GetRenderIndex().InsertTask(this, renderTaskId); + pxr::SdfPath renderTaskId = GetTaskID(); + GetRenderIndex().InsertTask(this, renderTaskId); GetRenderIndex().GetChangeTracker().MarkTaskDirty(renderTaskId, - HdChangeTracker::DirtyCollection); + pxr::HdChangeTracker::DirtyCollection); GetRenderIndex().GetChangeTracker().MarkTaskDirty(renderTaskId, - HdChangeTracker::DirtyRenderTags); + pxr::HdChangeTracker::DirtyRenderTags); taskParams.enableLighting = true; taskParams.alphaThreshold = 0.1f; } -SdfPath RenderTaskDelegate::GetTaskID() const +pxr::SdfPath RenderTaskDelegate::GetTaskID() const { return GetDelegateID().AppendElementString("task"); } -SdfPath RenderTaskDelegate::GetAovID(TfToken const &aov) const +pxr::SdfPath RenderTaskDelegate::GetAovID(pxr::TfToken const &aov) const { return GetDelegateID().AppendElementString("aov_" + aov.GetString()); } -VtValue RenderTaskDelegate::Get(SdfPath const &id, TfToken const &key) +pxr::VtValue RenderTaskDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const &key) { LOG(INFO) << "RenderTaskDelegate::Get - " << id.GetAsString() << " " << key.GetString() << "\n"; - if (key == HdTokens->params) { - return VtValue(taskParams); + if (key == pxr::HdTokens->params) { + return pxr::VtValue(taskParams); } - if (key == HdTokens->collection) { - HdRprimCollection rprimCollection( - HdTokens->geometry, HdReprSelector(HdReprTokens->smoothHull), false, TfToken()); - rprimCollection.SetRootPath(SdfPath::AbsoluteRootPath()); - return VtValue(rprimCollection); + if (key == pxr::HdTokens->collection) { + pxr::HdRprimCollection rprimCollection( + pxr::HdTokens->geometry, pxr::HdReprSelector(pxr::HdReprTokens->smoothHull), false, pxr::TfToken()); + rprimCollection.SetRootPath(pxr::SdfPath::AbsoluteRootPath()); + return pxr::VtValue(rprimCollection); } - return VtValue(); + return pxr::VtValue(); } -HdRenderBufferDescriptor RenderTaskDelegate::GetRenderBufferDescriptor(SdfPath const &id) +pxr::HdRenderBufferDescriptor RenderTaskDelegate::GetRenderBufferDescriptor(pxr::SdfPath const &id) { LOG(INFO) << "RenderTaskDelegate::GetRenderBufferDescriptor - " << id.GetAsString() << "\n"; return bufferDescriptors[id]; } -TfTokenVector RenderTaskDelegate::GetTaskRenderTags(SdfPath const &taskId) +pxr::TfTokenVector RenderTaskDelegate::GetTaskRenderTags(pxr::SdfPath const &taskId) { LOG(INFO) << "RenderTaskDelegate::GetTaskRenderTags - " << taskId.GetAsString() << "\n"; - return {HdRenderTagTokens->geometry}; + return {pxr::HdRenderTagTokens->geometry}; } bool RenderTaskDelegate::IsConverged() { - HdTaskSharedPtr renderTask = GetRenderIndex().GetTask(GetTaskID()); - return ((HdxRenderTask &)*renderTask).IsConverged(); + pxr::HdTaskSharedPtr renderTask = GetRenderIndex().GetTask(GetTaskID()); + return ((pxr::HdxRenderTask &)*renderTask).IsConverged(); } -void RenderTaskDelegate::SetRendererAov(TfToken const &aov) +void RenderTaskDelegate::SetRendererAov(pxr::TfToken const &aov) { - HdAovDescriptor aovDesc = GetRenderIndex().GetRenderDelegate()->GetDefaultAovDescriptor(aov); - HdRenderBufferDescriptor desc(GfVec3i(taskParams.viewport[2], taskParams.viewport[3], 1), + pxr::HdAovDescriptor aovDesc = GetRenderIndex().GetRenderDelegate()->GetDefaultAovDescriptor(aov); + pxr::HdRenderBufferDescriptor desc(pxr::GfVec3i(taskParams.viewport[2], taskParams.viewport[3], 1), aovDesc.format, aovDesc.multiSampled); - SdfPath bufferId = GetAovID(aov); + pxr::SdfPath bufferId = GetAovID(aov); if (bufferDescriptors.find(bufferId) == bufferDescriptors.end()) { - GetRenderIndex().InsertBprim(HdPrimTypeTokens->renderBuffer, this, bufferId); + GetRenderIndex().InsertBprim(pxr::HdPrimTypeTokens->renderBuffer, this, bufferId); bufferDescriptors[bufferId] = desc; - GetRenderIndex().GetChangeTracker().MarkBprimDirty(bufferId, HdRenderBuffer::DirtyDescription); + GetRenderIndex().GetChangeTracker().MarkBprimDirty(bufferId, pxr::HdRenderBuffer::DirtyDescription); - HdRenderPassAovBinding binding; + pxr::HdRenderPassAovBinding binding; binding.aovName = aov; binding.renderBufferId = bufferId; binding.aovSettings = aovDesc.aovSettings; taskParams.aovBindings.push_back(binding); - GetRenderIndex().GetChangeTracker().MarkTaskDirty(GetTaskID(), HdChangeTracker::DirtyParams); + GetRenderIndex().GetChangeTracker().MarkTaskDirty(GetTaskID(), pxr::HdChangeTracker::DirtyParams); } else if (bufferDescriptors[bufferId] != desc) { bufferDescriptors[bufferId] = desc; - GetRenderIndex().GetChangeTracker().MarkBprimDirty(bufferId, HdRenderBuffer::DirtyDescription); + GetRenderIndex().GetChangeTracker().MarkBprimDirty(bufferId, pxr::HdRenderBuffer::DirtyDescription); } } -HdRenderBuffer *RenderTaskDelegate::GetRendererAov(TfToken const &aov) +pxr::HdRenderBuffer *RenderTaskDelegate::GetRendererAov(pxr::TfToken const &aov) { return ( - HdRenderBuffer *)(GetRenderIndex().GetBprim(HdPrimTypeTokens->renderBuffer, GetAovID(aov))); + pxr::HdRenderBuffer *)(GetRenderIndex().GetBprim(pxr::HdPrimTypeTokens->renderBuffer, GetAovID(aov))); } -void RenderTaskDelegate::GetRendererAovData(TfToken const &aov, void *data) +void RenderTaskDelegate::GetRendererAovData(pxr::TfToken const &aov, void *data) { - HdRenderBuffer *buffer = GetRendererAov(aov); + pxr::HdRenderBuffer *buffer = GetRendererAov(aov); void *bufData = buffer->Map(); memcpy(data, bufData, - buffer->GetWidth() * buffer->GetHeight() * HdDataSizeOfFormat(buffer->GetFormat())); + buffer->GetWidth() * buffer->GetHeight() * pxr::HdDataSizeOfFormat(buffer->GetFormat())); buffer->Unmap(); } -HdTaskSharedPtr RenderTaskDelegate::GetTask() +pxr::HdTaskSharedPtr RenderTaskDelegate::GetTask() { return GetRenderIndex().GetTask(GetTaskID()); } -void RenderTaskDelegate::SetCameraAndViewport(SdfPath const &cameraId, GfVec4d const &viewport) +void RenderTaskDelegate::SetCameraAndViewport(pxr::SdfPath const &cameraId, pxr::GfVec4d const &viewport) { if (taskParams.viewport != viewport || taskParams.camera != cameraId) { taskParams.viewport = viewport; taskParams.camera = cameraId; - GetRenderIndex().GetChangeTracker().MarkTaskDirty(GetTaskID(), HdChangeTracker::DirtyParams); + GetRenderIndex().GetChangeTracker().MarkTaskDirty(GetTaskID(), pxr::HdChangeTracker::DirtyParams); } } diff --git a/source/blender/render/hydra/render_task_delegate.h b/source/blender/render/hydra/render_task_delegate.h index d2411450c95d..aaa36a2a9b5a 100644 --- a/source/blender/render/hydra/render_task_delegate.h +++ b/source/blender/render/hydra/render_task_delegate.h @@ -6,33 +6,31 @@ #include #include -using namespace pxr; - namespace blender::render::hydra { -class RenderTaskDelegate : public HdSceneDelegate { +class RenderTaskDelegate : public pxr::HdSceneDelegate { public: - RenderTaskDelegate(HdRenderIndex *parentIndex, SdfPath const &delegateID); + RenderTaskDelegate(pxr::HdRenderIndex *parentIndex, pxr::SdfPath const &delegateID); ~RenderTaskDelegate() override = default; - SdfPath GetTaskID() const; - SdfPath GetAovID(TfToken const &aov) const; + pxr::SdfPath GetTaskID() const; + pxr::SdfPath GetAovID(pxr::TfToken const &aov) const; - VtValue Get(SdfPath const &id, TfToken const &key) override; - HdRenderBufferDescriptor GetRenderBufferDescriptor(SdfPath const &id) override; - TfTokenVector GetTaskRenderTags(SdfPath const &taskId) override; + pxr::VtValue Get(pxr::SdfPath const &id, pxr::TfToken const &key) override; + pxr::HdRenderBufferDescriptor GetRenderBufferDescriptor(pxr::SdfPath const &id) override; + pxr::TfTokenVector GetTaskRenderTags(pxr::SdfPath const &taskId) override; bool IsConverged(); - void SetRendererAov(TfToken const &aovId); - HdRenderBuffer *GetRendererAov(TfToken const &id); - void GetRendererAovData(TfToken const &id, void *buf); + void SetRendererAov(pxr::TfToken const &aovId); + pxr::HdRenderBuffer *GetRendererAov(pxr::TfToken const &id); + void GetRendererAovData(pxr::TfToken const &id, void *buf); - HdTaskSharedPtr GetTask(); - void SetCameraAndViewport(SdfPath const &cameraId, GfVec4d const &viewport); + pxr::HdTaskSharedPtr GetTask(); + void SetCameraAndViewport(pxr::SdfPath const &cameraId, pxr::GfVec4d const &viewport); private: - HdxRenderTaskParams taskParams; - TfHashMap bufferDescriptors; + pxr::HdxRenderTaskParams taskParams; + pxr::TfHashMap bufferDescriptors; }; } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc index 65daabb3a7b8..2010bbf9294e 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -8,13 +8,10 @@ #include "blender_scene_delegate.h" -using namespace pxr; -using namespace std; - namespace blender::render::hydra { -BlenderSceneDelegate::BlenderSceneDelegate(HdRenderIndex *parentIndex, - SdfPath const &delegateID, +BlenderSceneDelegate::BlenderSceneDelegate(pxr::HdRenderIndex *parentIndex, + pxr::SdfPath const &delegateID, BlenderSceneDelegate::EngineType engine_type) : HdSceneDelegate(parentIndex, delegateID), engine_type(engine_type), @@ -28,10 +25,10 @@ void BlenderSceneDelegate::set_material(MeshData &mesh_data) { Material *material = mesh_data.material(); if (!material) { - mesh_data.material_id = SdfPath::EmptyPath(); + mesh_data.material_id = pxr::SdfPath::EmptyPath(); return; } - SdfPath id = MaterialData::prim_id(this, material); + pxr::SdfPath id = MaterialData::prim_id(this, material); MaterialData *mat_data = material_data(id); if (!mat_data) { materials[id] = MaterialData::init(this, material); @@ -73,7 +70,7 @@ void BlenderSceneDelegate::update_world() } } -bool BlenderSceneDelegate::GetVisible(SdfPath const &id) +bool BlenderSceneDelegate::GetVisible(pxr::SdfPath const &id) { if (id == WorldData::prim_id(this)) { return true; @@ -82,45 +79,45 @@ bool BlenderSceneDelegate::GetVisible(SdfPath const &id) return object_data(id)->visible; } -SdfPath BlenderSceneDelegate::GetInstancerId(SdfPath const &primId) +pxr::SdfPath BlenderSceneDelegate::GetInstancerId(pxr::SdfPath const &primId) { LOG(INFO) << "GetInstancerId: " << primId.GetAsString(); MeshData *m_data = mesh_data(primId); if (m_data) { return m_data->instancer_id; } - return SdfPath(); + return pxr::SdfPath(); } -SdfPathVector BlenderSceneDelegate::GetInstancerPrototypes(SdfPath const &instancerId) +pxr::SdfPathVector BlenderSceneDelegate::GetInstancerPrototypes(pxr::SdfPath const &instancerId) { LOG(INFO) << "GetInstancerPrototypes: " << instancerId.GetString(); - SdfPathVector paths; + pxr::SdfPathVector paths; paths.push_back(instancerId.GetParentPath()); return paths; } -VtIntArray BlenderSceneDelegate::GetInstanceIndices(SdfPath const &instancerId, - SdfPath const &prototypeId) +pxr::VtIntArray BlenderSceneDelegate::GetInstanceIndices(pxr::SdfPath const &instancerId, + pxr::SdfPath const &prototypeId) { LOG(INFO) << "GetInstanceIndices: " << instancerId.GetString() << " " << prototypeId.GetString(); MeshData *m_data = mesh_data(prototypeId); - VtIntArray ret = m_data->instance_indices(); + pxr::VtIntArray ret = m_data->instance_indices(); return ret; } -GfMatrix4d BlenderSceneDelegate::GetInstancerTransform(SdfPath const &instancerId) +pxr::GfMatrix4d BlenderSceneDelegate::GetInstancerTransform(pxr::SdfPath const &instancerId) { LOG(INFO) << "GetInstancerTransform: " << instancerId.GetString(); // TODO: add a separate object for instancer for cleaner handling code // Actual instancer transform is get here - return GfMatrix4d(1.0); + return pxr::GfMatrix4d(1.0); } -size_t BlenderSceneDelegate::SampleInstancerTransform(SdfPath const &instancerId, +size_t BlenderSceneDelegate::SampleInstancerTransform(pxr::SdfPath const &instancerId, size_t maxSampleCount, float *sampleTimes, - GfMatrix4d *sampleValues) + pxr::GfMatrix4d *sampleValues) { LOG(INFO) << "SampleInstancerTransform: " << instancerId.GetString(); size_t ret = 0; @@ -129,11 +126,11 @@ size_t BlenderSceneDelegate::SampleInstancerTransform(SdfPath const &instancerId return ret; } -size_t BlenderSceneDelegate::SamplePrimvar(SdfPath const &id, - TfToken const &key, +size_t BlenderSceneDelegate::SamplePrimvar(pxr::SdfPath const &id, + pxr::TfToken const &key, size_t maxSampleCount, float *sampleTimes, - VtValue *sampleValues) + pxr::VtValue *sampleValues) { // TODO: add a separate object for instancer for cleaner handling code if (id.GetName() == "Instancer") { @@ -157,8 +154,8 @@ void BlenderSceneDelegate::update_collection(bool remove, bool visibility) } /* Export of new visible objects which were not exported before */ - set available_objects; - SdfPath id; + std::set available_objects; + pxr::SdfPath id; DEGObjectIterSettings settings = {0}; settings.depsgraph = depsgraph; @@ -207,7 +204,7 @@ void BlenderSceneDelegate::update_collection(bool remove, bool visibility) } /* remove unused materials */ - set available_materials; + std::set available_materials; for (auto &obj : objects) { MeshData *m_data = dynamic_cast(obj.second.get()); if (m_data && !m_data->material_id.IsEmpty()) { @@ -230,7 +227,7 @@ void BlenderSceneDelegate::add_update_object(Object *object, bool transform, bool shading) { - SdfPath id = ObjectData::prim_id(this, object); + pxr::SdfPath id = ObjectData::prim_id(this, object); ObjectData *obj_data = object_data(id); if (!obj_data) { objects[id] = ObjectData::init(this, object); @@ -267,7 +264,7 @@ void BlenderSceneDelegate::add_update_object(Object *object, void BlenderSceneDelegate::add_update_instance(DupliObject *dupli) { - SdfPath id = ObjectData::prim_id(this, dupli->ob); + pxr::SdfPath id = ObjectData::prim_id(this, dupli->ob); if (!object_data(id)) { add_update_object(dupli->ob, true, true, true); } @@ -276,7 +273,7 @@ void BlenderSceneDelegate::add_update_instance(DupliObject *dupli) m_data->add_instance(dupli); } -ObjectData *BlenderSceneDelegate::object_data(SdfPath const &id) +ObjectData *BlenderSceneDelegate::object_data(pxr::SdfPath const &id) { auto it = objects.find(id); if (it == objects.end()) { @@ -285,17 +282,17 @@ ObjectData *BlenderSceneDelegate::object_data(SdfPath const &id) return it->second.get(); } -MeshData *BlenderSceneDelegate::mesh_data(SdfPath const &id) +MeshData *BlenderSceneDelegate::mesh_data(pxr::SdfPath const &id) { return static_cast(object_data(id)); } -LightData *BlenderSceneDelegate::light_data(SdfPath const &id) +LightData *BlenderSceneDelegate::light_data(pxr::SdfPath const &id) { return static_cast(object_data(id)); } -MaterialData *BlenderSceneDelegate::material_data(SdfPath const &id) +MaterialData *BlenderSceneDelegate::material_data(pxr::SdfPath const &id) { auto it = materials.find(id); if (it == materials.end()) { @@ -392,14 +389,14 @@ void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont) } } -HdMeshTopology BlenderSceneDelegate::GetMeshTopology(SdfPath const &id) +pxr::HdMeshTopology BlenderSceneDelegate::GetMeshTopology(pxr::SdfPath const &id) { LOG(INFO) << "GetMeshTopology: " << id.GetString(); MeshData *m_data = mesh_data(id); return m_data->mesh_topology(); } -VtValue BlenderSceneDelegate::Get(SdfPath const &id, TfToken const &key) +pxr::VtValue BlenderSceneDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const &key) { LOG(INFO) << "Get: " << id.GetString() << " " << key.GetString(); ObjectData *obj_data = object_data(id); @@ -415,11 +412,11 @@ VtValue BlenderSceneDelegate::Get(SdfPath const &id, TfToken const &key) if (mat_data) { return mat_data->get_data(key); } - return VtValue(); + return pxr::VtValue(); } -HdPrimvarDescriptorVector BlenderSceneDelegate::GetPrimvarDescriptors( - SdfPath const &id, HdInterpolation interpolation) +pxr::HdPrimvarDescriptorVector BlenderSceneDelegate::GetPrimvarDescriptors( + pxr::SdfPath const &id, pxr::HdInterpolation interpolation) { LOG(INFO) << "GetPrimvarDescriptors: " << id.GetString() << " " << interpolation; if (mesh_data(id)) { @@ -431,25 +428,25 @@ HdPrimvarDescriptorVector BlenderSceneDelegate::GetPrimvarDescriptors( return data->instancer_primvar_descriptors(interpolation); } } - HdPrimvarDescriptorVector primvars; + pxr::HdPrimvarDescriptorVector primvars; return primvars; } -SdfPath BlenderSceneDelegate::GetMaterialId(SdfPath const &rprimId) +pxr::SdfPath BlenderSceneDelegate::GetMaterialId(pxr::SdfPath const &rprimId) { return mesh_data(rprimId)->material_id; } -VtValue BlenderSceneDelegate::GetMaterialResource(SdfPath const &id) +pxr::VtValue BlenderSceneDelegate::GetMaterialResource(pxr::SdfPath const &id) { MaterialData *mat_data = material_data(id); if (mat_data) { return mat_data->material_resource(); } - return VtValue(); + return pxr::VtValue(); } -GfMatrix4d BlenderSceneDelegate::GetTransform(SdfPath const &id) +pxr::GfMatrix4d BlenderSceneDelegate::GetTransform(pxr::SdfPath const &id) { LOG(INFO) << "GetTransform: " << id.GetString(); ObjectData *obj_data = object_data(id); @@ -465,10 +462,10 @@ GfMatrix4d BlenderSceneDelegate::GetTransform(SdfPath const &id) if (id == WorldData::prim_id(this)) { return world_data->transform(); } - return GfMatrix4d(); + return pxr::GfMatrix4d(); } -VtValue BlenderSceneDelegate::GetLightParamValue(SdfPath const &id, TfToken const &key) +pxr::VtValue BlenderSceneDelegate::GetLightParamValue(pxr::SdfPath const &id, pxr::TfToken const &key) { LightData *l_data = light_data(id); if (l_data) { @@ -477,7 +474,7 @@ VtValue BlenderSceneDelegate::GetLightParamValue(SdfPath const &id, TfToken cons if (id == WorldData::prim_id(this)) { return world_data->get_data(key); } - return VtValue(); + return pxr::VtValue(); } } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/scene_delegate/id.cc b/source/blender/render/hydra/scene_delegate/id.cc index 84c5c506419e..c630b2f20f4f 100644 --- a/source/blender/render/hydra/scene_delegate/id.cc +++ b/source/blender/render/hydra/scene_delegate/id.cc @@ -6,8 +6,6 @@ #include "blender_scene_delegate.h" #include "id.h" -using namespace pxr; - namespace blender::render::hydra { IdData::IdData(BlenderSceneDelegate *scene_delegate, ID *id) @@ -22,9 +20,9 @@ std::string IdData::name() return str; } -VtValue IdData::get_data(TfToken const &key) +pxr::VtValue IdData::get_data(pxr::TfToken const &key) { - return VtValue(); + return pxr::VtValue(); } } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/scene_delegate/light.cc b/source/blender/render/hydra/scene_delegate/light.cc index 796ac6e6f398..949db040c208 100644 --- a/source/blender/render/hydra/scene_delegate/light.cc +++ b/source/blender/render/hydra/scene_delegate/light.cc @@ -15,9 +15,6 @@ #include "blender_scene_delegate.h" #include "light.h" -using namespace pxr; -using namespace boost::algorithm; - namespace blender::render::hydra { LightData::LightData(BlenderSceneDelegate *scene_delegate, Object *object) @@ -25,51 +22,51 @@ LightData::LightData(BlenderSceneDelegate *scene_delegate, Object *object) { Light *light = (Light *)((Object *)id)->data; - data[HdLightTokens->intensity] = scene_delegate->engine_type == + data[pxr::HdLightTokens->intensity] = scene_delegate->engine_type == BlenderSceneDelegate::EngineType::Preview ? light->energy / 1000 : light->energy; - data[HdLightTokens->color] = GfVec3f(light->r, light->g, light->b); + data[pxr::HdLightTokens->color] = pxr::GfVec3f(light->r, light->g, light->b); switch (light->type) { case LA_LOCAL: - data[HdLightTokens->radius] = light->area_size / 2; + data[pxr::HdLightTokens->radius] = light->area_size / 2; break; case LA_SUN: - data[HdLightTokens->angle] = light->sun_angle * 180.0 / M_PI; + data[pxr::HdLightTokens->angle] = light->sun_angle * 180.0 / M_PI; break; case LA_SPOT: - data[HdLightTokens->shapingConeAngle] = light->spotsize / 2; - data[HdLightTokens->shapingConeSoftness] = light->spotblend; - data[UsdLuxTokens->treatAsPoint] = true; + data[pxr::HdLightTokens->shapingConeAngle] = light->spotsize / 2; + data[pxr::HdLightTokens->shapingConeSoftness] = light->spotblend; + data[pxr::UsdLuxTokens->treatAsPoint] = true; break; case LA_AREA: switch (light->area_shape) { case LA_AREA_SQUARE: - data[HdLightTokens->width] = light->area_size; - data[HdLightTokens->height] = light->area_size; + data[pxr::HdLightTokens->width] = light->area_size; + data[pxr::HdLightTokens->height] = light->area_size; break; case LA_AREA_RECT: - data[HdLightTokens->width] = light->area_size; - data[HdLightTokens->height] = light->area_sizey; + data[pxr::HdLightTokens->width] = light->area_size; + data[pxr::HdLightTokens->height] = light->area_sizey; break; case LA_AREA_DISK: - data[HdLightTokens->radius] = light->area_size / 2; + data[pxr::HdLightTokens->radius] = light->area_size / 2; break; case LA_AREA_ELLIPSE: - data[HdLightTokens->radius] = (light->area_size + light->area_sizey) / 4; + data[pxr::HdLightTokens->radius] = (light->area_size + light->area_sizey) / 4; break; default: break; } - data[HdLightTokens->normalize] = true; + data[pxr::HdLightTokens->normalize] = true; break; default: @@ -77,59 +74,59 @@ LightData::LightData(BlenderSceneDelegate *scene_delegate, Object *object) } /* TODO: temporary value, it should be delivered through Python UI */ - data[HdLightTokens->exposure] = 1.0f; + data[pxr::HdLightTokens->exposure] = 1.0f; } pxr::TfToken LightData::prim_type() { Light *light = (Light *)((Object *)id)->data; - TfToken ret; + pxr::TfToken ret; switch (light->type) { case LA_LOCAL: case LA_SPOT: - ret = HdPrimTypeTokens->sphereLight; + ret = pxr::HdPrimTypeTokens->sphereLight; break; case LA_SUN: - ret = HdPrimTypeTokens->distantLight; + ret = pxr::HdPrimTypeTokens->distantLight; break; case LA_AREA: switch (light->area_shape) { case LA_AREA_SQUARE: case LA_AREA_RECT: - ret = HdPrimTypeTokens->rectLight; + ret = pxr::HdPrimTypeTokens->rectLight; break; case LA_AREA_DISK: case LA_AREA_ELLIPSE: - ret = HdPrimTypeTokens->diskLight; + ret = pxr::HdPrimTypeTokens->diskLight; break; default: - ret = HdPrimTypeTokens->rectLight; + ret = pxr::HdPrimTypeTokens->rectLight; } break; default: - ret = HdPrimTypeTokens->sphereLight; + ret = pxr::HdPrimTypeTokens->sphereLight; } return ret; } -VtValue LightData::get_data(TfToken const &key) +pxr::VtValue LightData::get_data(pxr::TfToken const &key) { LOG(INFO) << "Get data light: " << name() << " [" << key.GetString() << "]"; - VtValue ret; + pxr::VtValue ret; auto it = data.find(key); if (it != data.end()) { ret = it->second; } else { std::string n = key.GetString(); - if (contains(n, "object:visibility:")) { - if (ends_with(n, "camera") || ends_with(n, "shadow")) { + if (boost::algorithm::contains(n, "object:visibility:")) { + if (boost::algorithm::ends_with(n, "camera") || boost::algorithm::ends_with(n, "shadow")) { ret = false; } else { @@ -142,14 +139,14 @@ VtValue LightData::get_data(TfToken const &key) void LightData::insert_prim() { - SdfPath p_id = prim_id(scene_delegate, (Object *)id); + pxr::SdfPath p_id = prim_id(scene_delegate, (Object *)id); scene_delegate->GetRenderIndex().InsertSprim(prim_type(), scene_delegate, p_id); LOG(INFO) << "Add light: " << name() << " id=" << p_id.GetAsString(); } void LightData::remove_prim() { - SdfPath p_id = prim_id(scene_delegate, (Object *)id); + pxr::SdfPath p_id = prim_id(scene_delegate, (Object *)id); scene_delegate->GetRenderIndex().RemoveSprim(prim_type(), p_id); LOG(INFO) << "Remove light: " << name(); } @@ -158,21 +155,21 @@ void LightData::mark_prim_dirty(DirtyBits dirty_bits) { /* TODO: prim_type was changed we have to do remove..add light */ - HdDirtyBits bits = HdLight::Clean; + pxr::HdDirtyBits bits = pxr::HdLight::Clean; switch (dirty_bits) { case DirtyBits::DirtyTransform: - bits = HdLight::DirtyTransform; + bits = pxr::HdLight::DirtyTransform; break; case DirtyBits::DirtyVisibility: - bits = HdLight::DirtyParams; + bits = pxr::HdLight::DirtyParams; break; case DirtyBits::AllDirty: - bits = HdLight::AllDirty; + bits = pxr::HdLight::AllDirty; break; default: break; } - SdfPath p_id = prim_id(scene_delegate, (Object *)id); + pxr::SdfPath p_id = prim_id(scene_delegate, (Object *)id); scene_delegate->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id, bits); LOG(INFO) << "Update light: " << name() << " [" << (int)dirty_bits << "]"; } diff --git a/source/blender/render/hydra/scene_delegate/material.cc b/source/blender/render/hydra/scene_delegate/material.cc index 9b4dfc0a8091..501477f45d04 100644 --- a/source/blender/render/hydra/scene_delegate/material.cc +++ b/source/blender/render/hydra/scene_delegate/material.cc @@ -16,8 +16,6 @@ #include "material.h" #include "mtlx_hydra_adapter.h" -using namespace pxr; - namespace blender::render::hydra { std::unique_ptr MaterialData::init(BlenderSceneDelegate *scene_delegate, @@ -40,9 +38,9 @@ MaterialData::MaterialData(BlenderSceneDelegate *scene_delegate, Material *mater { } -VtValue MaterialData::get_data(TfToken const &key) +pxr::VtValue MaterialData::get_data(pxr::TfToken const &key) { - VtValue ret; + pxr::VtValue ret; if (key.GetString() == "MaterialXFilename") { if (!mtlx_path.GetResolvedPath().empty()) { ret = mtlx_path; @@ -55,14 +53,14 @@ pxr::VtValue MaterialData::material_resource() { std::string const &path = mtlx_path.GetResolvedPath(); if (!path.empty()) { - HdRenderDelegate *render_delegate = scene_delegate->GetRenderIndex().GetRenderDelegate(); - TfTokenVector shader_source_types = render_delegate->GetShaderSourceTypes(); - TfTokenVector render_contexts = render_delegate->GetMaterialRenderContexts(); + pxr::HdRenderDelegate *render_delegate = scene_delegate->GetRenderIndex().GetRenderDelegate(); + pxr::TfTokenVector shader_source_types = render_delegate->GetShaderSourceTypes(); + pxr::TfTokenVector render_contexts = render_delegate->GetMaterialRenderContexts(); - HdMaterialNetworkMap material_network_map; + pxr::HdMaterialNetworkMap material_network_map; HdMtlxConvertToMaterialNetworkMap( path, shader_source_types, render_contexts, &material_network_map); - return VtValue(material_network_map); + return pxr::VtValue(material_network_map); } return pxr::VtValue(); @@ -88,35 +86,35 @@ void MaterialData::export_mtlx() PyGILState_Release(gstate); - mtlx_path = SdfAssetPath(path, path); + mtlx_path = pxr::SdfAssetPath(path, path); LOG(INFO) << "Material export: " << name() << " mtlx=" << mtlx_path.GetResolvedPath(); } void MaterialData::insert_prim() { - SdfPath p_id = prim_id(scene_delegate, (Material *)id); - scene_delegate->GetRenderIndex().InsertSprim(HdPrimTypeTokens->material, scene_delegate, p_id); + pxr::SdfPath p_id = prim_id(scene_delegate, (Material *)id); + scene_delegate->GetRenderIndex().InsertSprim(pxr::HdPrimTypeTokens->material, scene_delegate, p_id); LOG(INFO) << "Add material: " << name() << " id=" << p_id.GetAsString(); } void MaterialData::remove_prim() { - SdfPath p_id = prim_id(scene_delegate, (Material *)id); - scene_delegate->GetRenderIndex().RemoveSprim(HdPrimTypeTokens->material, p_id); + pxr::SdfPath p_id = prim_id(scene_delegate, (Material *)id); + scene_delegate->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->material, p_id); LOG(INFO) << "Remove material: " << name(); } void MaterialData::mark_prim_dirty(DirtyBits dirty_bits) { - HdDirtyBits bits = HdMaterial::Clean; + pxr::HdDirtyBits bits = pxr::HdMaterial::Clean; switch (dirty_bits) { case DirtyBits::AllDirty: - bits = HdMaterial::AllDirty; + bits = pxr::HdMaterial::AllDirty; break; default: break; } - SdfPath p_id = prim_id(scene_delegate, (Material *)id); + pxr::SdfPath p_id = prim_id(scene_delegate, (Material *)id); scene_delegate->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id, bits); LOG(INFO) << "Update material: " << name() << ", mtlx=" << mtlx_path.GetResolvedPath(); } diff --git a/source/blender/render/hydra/scene_delegate/mesh.cc b/source/blender/render/hydra/scene_delegate/mesh.cc index 9a642fcada52..f80040f33813 100644 --- a/source/blender/render/hydra/scene_delegate/mesh.cc +++ b/source/blender/render/hydra/scene_delegate/mesh.cc @@ -15,8 +15,6 @@ #include "blender_scene_delegate.h" #include "mesh.h" -using namespace pxr; - namespace blender::render::hydra { MeshData::MeshData(BlenderSceneDelegate *scene_delegate, Object *object) @@ -35,19 +33,19 @@ MeshData::MeshData(BlenderSceneDelegate *scene_delegate, Object *object) } } -VtValue MeshData::get_data(TfToken const &key) +pxr::VtValue MeshData::get_data(pxr::TfToken const &key) { - VtValue ret; - if (key == HdTokens->points) { + pxr::VtValue ret; + if (key == pxr::HdTokens->points) { ret = vertices; } - else if (key == HdTokens->normals) { + else if (key == pxr::HdTokens->normals) { ret = normals; } - else if (key == HdPrimvarRoleTokens->textureCoordinate) { + else if (key == pxr::HdPrimvarRoleTokens->textureCoordinate) { ret = uvs; } - else if (key == HdInstancerTokens->instanceTransform) { + else if (key == pxr::HdInstancerTokens->instanceTransform) { ret = instances; } return ret; @@ -62,48 +60,48 @@ Material *MeshData::material() return BKE_object_material_get_eval(object, object->actcol); } -HdMeshTopology MeshData::mesh_topology() +pxr::HdMeshTopology MeshData::mesh_topology() { - return HdMeshTopology(PxOsdOpenSubdivTokens->catmullClark, - HdTokens->rightHanded, + return pxr::HdMeshTopology(pxr::PxOsdOpenSubdivTokens->catmullClark, + pxr::HdTokens->rightHanded, face_vertex_counts, face_vertex_indices); } -HdPrimvarDescriptorVector MeshData::primvar_descriptors(HdInterpolation interpolation) +pxr::HdPrimvarDescriptorVector MeshData::primvar_descriptors(pxr::HdInterpolation interpolation) { - HdPrimvarDescriptorVector primvars; - if (interpolation == HdInterpolationVertex) { + pxr::HdPrimvarDescriptorVector primvars; + if (interpolation == pxr::HdInterpolationVertex) { if (!vertices.empty()) { - primvars.emplace_back(HdTokens->points, interpolation, HdPrimvarRoleTokens->point); + primvars.emplace_back(pxr::HdTokens->points, interpolation, pxr::HdPrimvarRoleTokens->point); } } - else if (interpolation == HdInterpolationFaceVarying) { + else if (interpolation == pxr::HdInterpolationFaceVarying) { if (!normals.empty()) { - primvars.emplace_back(HdTokens->normals, interpolation, HdPrimvarRoleTokens->normal); + primvars.emplace_back(pxr::HdTokens->normals, interpolation, pxr::HdPrimvarRoleTokens->normal); } if (!uvs.empty()) { - primvars.emplace_back(HdPrimvarRoleTokens->textureCoordinate, + primvars.emplace_back(pxr::HdPrimvarRoleTokens->textureCoordinate, interpolation, - HdPrimvarRoleTokens->textureCoordinate); + pxr::HdPrimvarRoleTokens->textureCoordinate); } } return primvars; } -HdPrimvarDescriptorVector MeshData::instancer_primvar_descriptors(HdInterpolation interpolation) +pxr::HdPrimvarDescriptorVector MeshData::instancer_primvar_descriptors(pxr::HdInterpolation interpolation) { - HdPrimvarDescriptorVector primvars; - if (interpolation == HdInterpolationInstance) { + pxr::HdPrimvarDescriptorVector primvars; + if (interpolation == pxr::HdInterpolationInstance) { primvars.emplace_back( - HdInstancerTokens->instanceTransform, interpolation, HdPrimvarRoleTokens->none); + pxr::HdInstancerTokens->instanceTransform, interpolation, pxr::HdPrimvarRoleTokens->none); } return primvars; } -VtIntArray MeshData::instance_indices() +pxr::VtIntArray MeshData::instance_indices() { - VtIntArray ret(instances.size()); + pxr::VtIntArray ret(instances.size()); for (size_t i = 0; i < ret.size(); ++i) { ret[i] = i; } @@ -112,19 +110,19 @@ VtIntArray MeshData::instance_indices() size_t MeshData::sample_instancer_transform(size_t maxSampleCount, float *sampleTimes, - GfMatrix4d *sampleValues) + pxr::GfMatrix4d *sampleValues) { *sampleTimes = 0.0f; - *sampleValues = GfMatrix4d(1.0); + *sampleValues = pxr::GfMatrix4d(1.0); return 1; } -size_t MeshData::sample_instancer_primvar(TfToken const &key, +size_t MeshData::sample_instancer_primvar(pxr::TfToken const &key, size_t maxSampleCount, float *sampleTimes, - VtValue *sampleValues) + pxr::VtValue *sampleValues) { - if (key == HdInstancerTokens->instanceTransform) { + if (key == pxr::HdInstancerTokens->instanceTransform) { if (maxSampleCount > 0) { sampleTimes[0] = 0.0f; sampleValues[0] = instances; @@ -144,7 +142,7 @@ void MeshData::add_instance(DupliObject *dupli) if (instances.empty()) { // USD hides the prototype mesh when instancing in contrary to the Blender, so we must add it // back implicitly - instances.push_back(GfMatrix4d(1.0)); + instances.push_back(pxr::GfMatrix4d(1.0)); } instances.push_back(transform().GetInverse() * gf_matrix_from_transform(dupli->mat)); LOG(INFO) << "Add instance: " << instancer_id.GetAsString() << " " << dupli->random_id; @@ -161,7 +159,7 @@ void MeshData::set_mesh(Mesh *mesh) blender::Span loopTris = mesh->looptris(); /* face_vertex_counts */ - face_vertex_counts = VtIntArray(tris_len, 3); + face_vertex_counts = pxr::VtIntArray(tris_len, 3); /* face_vertex_indices */ blender::Span loops = mesh->loops(); @@ -176,7 +174,7 @@ void MeshData::set_mesh(Mesh *mesh) vertices.reserve(mesh->totvert); blender::Span verts = mesh->vert_positions(); for (blender::float3 v : verts) { - vertices.push_back(GfVec3f(v.x, v.y, v.z)); + vertices.push_back(pxr::GfVec3f(v.x, v.y, v.z)); } /* normals */ @@ -184,9 +182,9 @@ void MeshData::set_mesh(Mesh *mesh) if (lnors) { normals.reserve(loopTris.size() * 3); for (MLoopTri lt : loopTris) { - normals.push_back(GfVec3f(lnors[lt.tri[0]])); - normals.push_back(GfVec3f(lnors[lt.tri[1]])); - normals.push_back(GfVec3f(lnors[lt.tri[2]])); + normals.push_back(pxr::GfVec3f(lnors[lt.tri[0]])); + normals.push_back(pxr::GfVec3f(lnors[lt.tri[1]])); + normals.push_back(pxr::GfVec3f(lnors[lt.tri[2]])); } } @@ -195,9 +193,9 @@ void MeshData::set_mesh(Mesh *mesh) if (luvs) { uvs.reserve(loopTris.size() * 3); for (MLoopTri lt : loopTris) { - uvs.push_back(GfVec2f(luvs[lt.tri[0]])); - uvs.push_back(GfVec2f(luvs[lt.tri[1]])); - uvs.push_back(GfVec2f(luvs[lt.tri[2]])); + uvs.push_back(pxr::GfVec2f(luvs[lt.tri[0]])); + uvs.push_back(pxr::GfVec2f(luvs[lt.tri[1]])); + uvs.push_back(pxr::GfVec2f(luvs[lt.tri[2]])); } } } @@ -208,14 +206,14 @@ void MeshData::insert_prim() return; } - SdfPath p_id = prim_id(scene_delegate, (Object *)id); - scene_delegate->GetRenderIndex().InsertRprim(HdPrimTypeTokens->mesh, scene_delegate, p_id); + pxr::SdfPath p_id = prim_id(scene_delegate, (Object *)id); + scene_delegate->GetRenderIndex().InsertRprim(pxr::HdPrimTypeTokens->mesh, scene_delegate, p_id); LOG(INFO) << "Add mesh: " << name() << " id=" << p_id.GetAsString(); } void MeshData::remove_prim() { - SdfPath p_id = prim_id(scene_delegate, (Object *)id); + pxr::SdfPath p_id = prim_id(scene_delegate, (Object *)id); if (!scene_delegate->GetRenderIndex().HasRprim(p_id)) { return; } @@ -226,7 +224,7 @@ void MeshData::remove_prim() void MeshData::mark_prim_dirty(DirtyBits dirty_bits) { - SdfPath p_id = prim_id(scene_delegate, (Object *)id); + pxr::SdfPath p_id = prim_id(scene_delegate, (Object *)id); if (!scene_delegate->GetRenderIndex().HasRprim(p_id)) { /* Trying to insert prim */ insert_prim(); @@ -239,19 +237,19 @@ void MeshData::mark_prim_dirty(DirtyBits dirty_bits) return; } - HdDirtyBits bits = HdChangeTracker::Clean; + pxr::HdDirtyBits bits = pxr::HdChangeTracker::Clean; switch (dirty_bits) { case DirtyBits::DirtyTransform: - bits = HdChangeTracker::DirtyTransform; + bits = pxr::HdChangeTracker::DirtyTransform; break; case DirtyBits::DirtyVisibility: - bits = HdChangeTracker::DirtyVisibility; + bits = pxr::HdChangeTracker::DirtyVisibility; break; case DirtyBits::DirtyMaterial: - bits = HdChangeTracker::DirtyMaterialId; + bits = pxr::HdChangeTracker::DirtyMaterialId; break; case DirtyBits::AllDirty: - bits = HdChangeTracker::AllDirty; + bits = pxr::HdChangeTracker::AllDirty; break; default: break; diff --git a/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.cc b/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.cc index 9cb6c26a4826..0c1de955e0c7 100644 --- a/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.cc +++ b/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.cc @@ -22,56 +22,52 @@ namespace mx = MaterialX; -PXR_NAMESPACE_OPEN_SCOPE - void HdMtlxConvertToMaterialNetworkMap(std::string const &mtlxPath, - TfTokenVector const &shaderSourceTypes, - TfTokenVector const &renderContexts, - HdMaterialNetworkMap *out) + pxr::TfTokenVector const &shaderSourceTypes, + pxr::TfTokenVector const &renderContexts, + pxr::HdMaterialNetworkMap *out) { if (mtlxPath.empty()) { return; } - std::string basePath = TfGetPathName(mtlxPath); + std::string basePath = pxr::TfGetPathName(mtlxPath); - ArResolver &resolver = ArGetResolver(); - const ArResolverContext context = resolver.CreateDefaultContextForAsset(mtlxPath); - ArResolverContextBinder binder(context); - ArResolverScopedCache resolverCache; + pxr::ArResolver &resolver = pxr::ArGetResolver(); + const pxr::ArResolverContext context = resolver.CreateDefaultContextForAsset(mtlxPath); + pxr::ArResolverContextBinder binder(context); + pxr::ArResolverScopedCache resolverCache; - std::string mtlxName = TfGetBaseName(mtlxPath); - std::string stageId = TfStringPrintf( + std::string mtlxName = pxr::TfGetBaseName(mtlxPath); + std::string stageId = pxr::TfStringPrintf( "%s%s%s.usda", basePath.c_str(), ARCH_PATH_SEP, mtlxName.c_str()); - UsdStageRefPtr stage = UsdStage::CreateInMemory(stageId, context); + pxr::UsdStageRefPtr stage = pxr::UsdStage::CreateInMemory(stageId, context); try { - mx::DocumentPtr doc = UsdMtlxReadDocument(mtlxPath); - UsdMtlxRead(doc, stage); + mx::DocumentPtr doc = pxr::UsdMtlxReadDocument(mtlxPath); + pxr::UsdMtlxRead(doc, stage); } catch (mx::ExceptionFoundCycle &x) { - TF_RUNTIME_ERROR("MaterialX cycle found: %s\n", x.what()); + Tf_PostErrorHelper(pxr::TF_CALL_CONTEXT, pxr::TF_DIAGNOSTIC_RUNTIME_ERROR_TYPE, "MaterialX cycle found: %s\n", x.what()); return; } catch (mx::Exception &x) { - TF_RUNTIME_ERROR("MaterialX error: %s\n", x.what()); + Tf_PostErrorHelper(pxr::TF_CALL_CONTEXT, pxr::TF_DIAGNOSTIC_RUNTIME_ERROR_TYPE, "MaterialX error: %s\n", x.what()); return; } - if (UsdPrim materials = stage->GetPrimAtPath(SdfPath("/MaterialX/Materials"))) { - if (UsdPrimSiblingRange children = materials.GetChildren()) { - if (auto material = UsdShadeMaterial(*children.begin())) { - if (UsdShadeShader mtlxSurface = material.ComputeSurfaceSource(renderContexts)) { + if (pxr::UsdPrim materials = stage->GetPrimAtPath(pxr::SdfPath("/MaterialX/Materials"))) { + if (pxr::UsdPrimSiblingRange children = materials.GetChildren()) { + if (auto material = pxr::UsdShadeMaterial(*children.begin())) { + if (pxr::UsdShadeShader mtlxSurface = material.ComputeSurfaceSource(renderContexts)) { UsdImagingBuildHdMaterialNetworkFromTerminal(mtlxSurface.GetPrim(), - HdMaterialTerminalTokens->surface, + pxr::HdMaterialTerminalTokens->surface, shaderSourceTypes, renderContexts, out, - UsdTimeCode::Default()); + pxr::UsdTimeCode::Default()); } } } } } - -PXR_NAMESPACE_CLOSE_SCOPE diff --git a/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.h b/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.h index 7bfcafd40cc1..4164ff204bdb 100644 --- a/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.h +++ b/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.h @@ -8,13 +8,9 @@ #include -PXR_NAMESPACE_OPEN_SCOPE - -struct HdMaterialNetworkMap; +struct pxr::HdMaterialNetworkMap; void HdMtlxConvertToMaterialNetworkMap(std::string const &mtlxPath, - TfTokenVector const &shaderSourceTypes, - TfTokenVector const &renderContexts, - HdMaterialNetworkMap *out); - -PXR_NAMESPACE_CLOSE_SCOPE + pxr::TfTokenVector const &shaderSourceTypes, + pxr::TfTokenVector const &renderContexts, + pxr::HdMaterialNetworkMap *out); diff --git a/source/blender/render/hydra/scene_delegate/object.cc b/source/blender/render/hydra/scene_delegate/object.cc index ef48433aea9f..f3386f9c153d 100644 --- a/source/blender/render/hydra/scene_delegate/object.cc +++ b/source/blender/render/hydra/scene_delegate/object.cc @@ -9,8 +9,6 @@ #include "mesh.h" #include "object.h" -using namespace pxr; - namespace blender::render::hydra { bool ObjectData::supported(Object *object) @@ -69,7 +67,7 @@ int ObjectData::type() return ((Object *)id)->type; } -GfMatrix4d ObjectData::transform() +pxr::GfMatrix4d ObjectData::transform() { return gf_matrix_from_transform(((Object *)id)->object_to_world); } diff --git a/source/blender/render/hydra/scene_delegate/world.cc b/source/blender/render/hydra/scene_delegate/world.cc index 091a57fa1c68..a14dc4618557 100644 --- a/source/blender/render/hydra/scene_delegate/world.cc +++ b/source/blender/render/hydra/scene_delegate/world.cc @@ -28,8 +28,6 @@ /* TODO : add custom tftoken "transparency"? */ -using namespace pxr; - namespace blender::render::hydra { std::unique_ptr WorldData::init(BlenderSceneDelegate *scene_delegate, @@ -39,7 +37,7 @@ std::unique_ptr WorldData::init(BlenderSceneDelegate *scene_delegate, return std::make_unique(scene_delegate, world, context); } -SdfPath WorldData::prim_id(BlenderSceneDelegate *scene_delegate) +pxr::SdfPath WorldData::prim_id(BlenderSceneDelegate *scene_delegate) { return scene_delegate->GetDelegateID().AppendElementString("World"); } @@ -47,7 +45,7 @@ SdfPath WorldData::prim_id(BlenderSceneDelegate *scene_delegate) WorldData::WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContext *context) : IdData(scene_delegate, (ID *)world) { - data[UsdLuxTokens->orientToStageUpAxis] = true; + data[pxr::UsdLuxTokens->orientToStageUpAxis] = true; if (world->use_nodes) { /* TODO: Create nodes parsing system */ @@ -69,9 +67,9 @@ WorldData::WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContex float const *strength = strength_input.default_value_typed(); float const *color = color_input.default_value_typed(); - data[HdLightTokens->intensity] = strength[1]; - data[HdLightTokens->exposure] = 1.0f; - data[HdLightTokens->color] = GfVec3f(color[0], color[1], color[2]); + data[pxr::HdLightTokens->intensity] = strength[1]; + data[pxr::HdLightTokens->exposure] = 1.0f; + data[pxr::HdLightTokens->color] = pxr::GfVec3f(color[0], color[1], color[2]); if (!color_input.directly_linked_links().is_empty()) { bNode *color_input_node = color_input.directly_linked_links()[0]->fromnode; @@ -89,34 +87,34 @@ WorldData::WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContex std::string image_path = cache_image(bmain, scene, image, &tex->iuser, &opts, &reports); if (!image_path.empty()) { - data[HdLightTokens->textureFile] = SdfAssetPath(image_path, image_path); + data[pxr::HdLightTokens->textureFile] = pxr::SdfAssetPath(image_path, image_path); } } } } } else { - data[HdLightTokens->intensity] = 1.0f; - data[HdLightTokens->exposure] = world->exposure; - data[HdLightTokens->color] = GfVec3f(world->horr, world->horg, world->horb); + data[pxr::HdLightTokens->intensity] = 1.0f; + data[pxr::HdLightTokens->exposure] = world->exposure; + data[pxr::HdLightTokens->color] = pxr::GfVec3f(world->horr, world->horg, world->horb); } } -GfMatrix4d WorldData::transform() +pxr::GfMatrix4d WorldData::transform() { - GfMatrix4d transform = GfMatrix4d(GfRotation(GfVec3d(1.0, 0.0, 0.0), -90), GfVec3d()); + pxr::GfMatrix4d transform = pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), -90), pxr::GfVec3d()); /* TODO : do this check via RenderSettings*/ if (scene_delegate->GetRenderIndex().GetRenderDelegate()->GetRendererDisplayName() == "RPR") { - transform *= GfMatrix4d(GfRotation(GfVec3d(1.0, 0.0, 0.0), -180), GfVec3d()); - transform *= GfMatrix4d(GfRotation(GfVec3d(0.0, 0.0, 1.0), 90.0), GfVec3d()); + transform *= pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), -180), pxr::GfVec3d()); + transform *= pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(0.0, 0.0, 1.0), 90.0), pxr::GfVec3d()); } return transform; } -VtValue WorldData::get_data(TfToken const &key) +pxr::VtValue WorldData::get_data(pxr::TfToken const &key) { - VtValue ret; + pxr::VtValue ret; auto it = data.find(key); if (it != data.end()) { ret = it->second; @@ -126,29 +124,29 @@ VtValue WorldData::get_data(TfToken const &key) void WorldData::insert_prim() { - SdfPath p_id = prim_id(scene_delegate); - scene_delegate->GetRenderIndex().InsertSprim(HdPrimTypeTokens->domeLight, scene_delegate, p_id); + pxr::SdfPath p_id = prim_id(scene_delegate); + scene_delegate->GetRenderIndex().InsertSprim(pxr::HdPrimTypeTokens->domeLight, scene_delegate, p_id); LOG(INFO) << "Add World: id=" << p_id.GetAsString(); } void WorldData::remove_prim() { - SdfPath p_id = prim_id(scene_delegate); - scene_delegate->GetRenderIndex().RemoveSprim(HdPrimTypeTokens->domeLight, p_id); + pxr::SdfPath p_id = prim_id(scene_delegate); + scene_delegate->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->domeLight, p_id); LOG(INFO) << "Remove World"; } void WorldData::mark_prim_dirty(DirtyBits dirty_bits) { - HdDirtyBits bits = HdLight::Clean; + pxr::HdDirtyBits bits = pxr::HdLight::Clean; switch (dirty_bits) { case DirtyBits::AllDirty: - bits = HdLight::AllDirty; + bits = pxr::HdLight::AllDirty; break; default: break; } - SdfPath p_id = prim_id(scene_delegate); + pxr::SdfPath p_id = prim_id(scene_delegate); scene_delegate->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id, bits); LOG(INFO) << "Update World"; } diff --git a/source/blender/render/hydra/simple_light_task_delegate.cc b/source/blender/render/hydra/simple_light_task_delegate.cc index ec483b74bce6..43a223b8dd5f 100644 --- a/source/blender/render/hydra/simple_light_task_delegate.cc +++ b/source/blender/render/hydra/simple_light_task_delegate.cc @@ -7,35 +7,35 @@ namespace blender::render::hydra { -SimpleLightTaskDelegate::SimpleLightTaskDelegate(HdRenderIndex *parentIndex, - SdfPath const &delegateID) - : HdSceneDelegate(parentIndex, delegateID) +SimpleLightTaskDelegate::SimpleLightTaskDelegate(pxr::HdRenderIndex *parentIndex, + pxr::SdfPath const &delegateID) + : pxr::HdSceneDelegate(parentIndex, delegateID) { - SdfPath taskId = GetTaskID(); - GetRenderIndex().InsertTask(this, taskId); + pxr::SdfPath taskId = GetTaskID(); + GetRenderIndex().InsertTask(this, taskId); } -SdfPath SimpleLightTaskDelegate::GetTaskID() const +pxr::SdfPath SimpleLightTaskDelegate::GetTaskID() const { return GetDelegateID().AppendElementString("task"); } -HdTaskSharedPtr SimpleLightTaskDelegate::GetTask() +pxr::HdTaskSharedPtr SimpleLightTaskDelegate::GetTask() { return GetRenderIndex().GetTask(GetTaskID()); } -void SimpleLightTaskDelegate::SetCameraPath(SdfPath const &cameraPath) +void SimpleLightTaskDelegate::SetCameraPath(pxr::SdfPath const &cameraPath) { taskParams.cameraPath = cameraPath; } -VtValue SimpleLightTaskDelegate::Get(SdfPath const &id, TfToken const &key) +pxr::VtValue SimpleLightTaskDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const &key) { - if (key == HdTokens->params) { - return VtValue(taskParams); + if (key == pxr::HdTokens->params) { + return pxr::VtValue(taskParams); } - return VtValue(); + return pxr::VtValue(); } } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/simple_light_task_delegate.h b/source/blender/render/hydra/simple_light_task_delegate.h index 9a2b11b8f3a7..04460232450d 100644 --- a/source/blender/render/hydra/simple_light_task_delegate.h +++ b/source/blender/render/hydra/simple_light_task_delegate.h @@ -6,24 +6,22 @@ #include #include -using namespace pxr; - namespace blender::render::hydra { -class SimpleLightTaskDelegate : public HdSceneDelegate { +class SimpleLightTaskDelegate : public pxr::HdSceneDelegate { public: - SimpleLightTaskDelegate(HdRenderIndex *parentIndex, SdfPath const &delegateID); + SimpleLightTaskDelegate(pxr::HdRenderIndex *parentIndex, pxr::SdfPath const &delegateID); ~SimpleLightTaskDelegate() override = default; - SdfPath GetTaskID() const; + pxr::SdfPath GetTaskID() const; - HdTaskSharedPtr GetTask(); - void SetCameraPath(SdfPath const &); + pxr::HdTaskSharedPtr GetTask(); + void SetCameraPath(pxr::SdfPath const &); - VtValue Get(SdfPath const &id, TfToken const &key) override; + pxr::VtValue Get(pxr::SdfPath const &id, pxr::TfToken const &key) override; private: - HdxSimpleLightTaskParams taskParams; + pxr::HdxSimpleLightTaskParams taskParams; }; } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/utils.cc b/source/blender/render/hydra/utils.cc index 2dff5f6ecf94..146d1b7bfd69 100644 --- a/source/blender/render/hydra/utils.cc +++ b/source/blender/render/hydra/utils.cc @@ -3,6 +3,7 @@ #include #include +#include #include @@ -15,14 +16,11 @@ #include "utils.h" -using namespace std; -using namespace pxr; - namespace blender::render::hydra { -GfMatrix4d gf_matrix_from_transform(float m[4][4]) + pxr::GfMatrix4d gf_matrix_from_transform(float m[4][4]) { - return GfMatrix4d(m[0][0], + return pxr::GfMatrix4d(m[0][0], m[0][1], m[0][2], m[0][3], @@ -40,43 +38,43 @@ GfMatrix4d gf_matrix_from_transform(float m[4][4]) m[3][3]); } -string format_duration(chrono::milliseconds millisecs) +std::string format_duration(std::chrono::milliseconds millisecs) { - stringstream ss; - bool neg = millisecs < 0ms; + std::stringstream ss; + bool neg = millisecs < std::chrono::milliseconds(0); if (neg) { millisecs = -millisecs; } - auto m = chrono::duration_cast(millisecs); + auto m = std::chrono::duration_cast(millisecs); millisecs -= m; - auto s = chrono::duration_cast(millisecs); + auto s = std::chrono::duration_cast(millisecs); millisecs -= s; if (neg) { ss << "-"; } - if (m < 10min) { + if (m < std::chrono::minutes(10)) { ss << "0"; } - ss << to_string(m / 1min) << ":"; - if (s < 10s) { + ss << std::to_string(m / std::chrono::minutes(1)) << ":"; + if (s < std::chrono::seconds(10)) { ss << "0"; } - ss << to_string(s / 1s) << ":"; - if (millisecs < 10ms) { + ss << std::to_string(s / std::chrono::seconds(1)) << ":"; + if (millisecs < std::chrono::milliseconds(10)) { ss << "0"; } - ss << to_string(millisecs / 1ms / 10); + ss << std::to_string(millisecs / std::chrono::milliseconds(1) / 10); return ss.str(); } -string cache_image(Main *bmain, +std::string cache_image(Main *bmain, Scene *scene, Image *image, ImageUser *iuser, ImageSaveOptions *opts, ReportList *reports) { - const string default_format = ".png"; + const std::string default_format = ".png"; char tempfile[FILE_MAX]; @@ -85,15 +83,15 @@ string cache_image(Main *bmain, return ""; } - string image_name; + std::string image_name; if (image->source == IMA_SRC_GENERATED) { - image_name = TfMakeValidIdentifier(image_name.append(image->id.name + 2)); + image_name = pxr::TfMakeValidIdentifier(image_name.append(image->id.name + 2)); } else { image_name = image->filepath == NULL ? image->filepath : image->id.name + 2; image_name = std::filesystem::path(image_name).filename().replace_extension().string(); - image_name = TfMakeValidIdentifier(image_name); + image_name = pxr::TfMakeValidIdentifier(image_name); } image_name.append(default_format); @@ -110,13 +108,13 @@ string cache_image(Main *bmain, return tempfile; } -void set_env_paths(string const &name, vector path_dirs) +void set_env_paths(std::string const &name, std::vector path_dirs) { const char *env = BLI_getenv(name.c_str()); ; - stringstream ss; + std::stringstream ss; int i = 0; - for (string &s : path_dirs) { + for (std::string &s : path_dirs) { ++i; ss << s; if (i < path_dirs.size() || env) { diff --git a/source/blender/render/hydra/viewport_engine.cc b/source/blender/render/hydra/viewport_engine.cc index 47cbc2b25ec0..e498cf6efee2 100644 --- a/source/blender/render/hydra/viewport_engine.cc +++ b/source/blender/render/hydra/viewport_engine.cc @@ -21,10 +21,6 @@ #include "camera.h" #include "utils.h" - -using namespace std; -using namespace pxr; - namespace blender::render::hydra { struct ViewSettings { @@ -33,13 +29,13 @@ struct ViewSettings { int width(); int height(); - GfCamera gf_camera(); + pxr::GfCamera gf_camera(); CameraData camera_data; int screen_width; int screen_height; - GfVec4i border; + pxr::GfVec4i border; }; ViewSettings::ViewSettings(bContext *context) : camera_data(context) @@ -80,13 +76,13 @@ ViewSettings::ViewSettings(bContext *context) : camera_data(context) } // getting camera view region - float x1_f = min( + float x1_f = std::min( {screen_points[0][0], screen_points[1][0], screen_points[2][0], screen_points[3][0]}); - float x2_f = max( + float x2_f = std::max( {screen_points[0][0], screen_points[1][0], screen_points[2][0], screen_points[3][0]}); - float y1_f = min( + float y1_f = std::min( {screen_points[0][1], screen_points[1][1], screen_points[2][1], screen_points[3][1]}); - float y2_f = max( + float y2_f = std::max( {screen_points[0][1], screen_points[1][1], screen_points[2][1], screen_points[3][1]}); // adjusting region to border @@ -99,10 +95,10 @@ ViewSettings::ViewSettings(bContext *context) : camera_data(context) y2 = y + scene->r.border.ymax * dy; // adjusting to region screen resolution - x1 = max(min(x1, screen_width), 0); - x2 = max(min(x2, screen_width), 0); - y1 = max(min(y1, screen_height), 0); - y2 = max(min(y2, screen_height), 0); + x1 = std::max(std::min(x1, screen_width), 0); + x2 = std::max(std::min(x2, screen_width), 0); + y1 = std::max(std::min(y1, screen_height), 0); + y2 = std::max(std::min(y2, screen_height), 0); } } else { @@ -117,7 +113,7 @@ ViewSettings::ViewSettings(bContext *context) : camera_data(context) } } - border = GfVec4i(x1, y1, x2 - x1, y2 - y1); + border = pxr::GfVec4i(x1, y1, x2 - x1, y2 - y1); } int ViewSettings::width() @@ -130,9 +126,9 @@ int ViewSettings::height() return border[3]; } -GfCamera ViewSettings::gf_camera() +pxr::GfCamera ViewSettings::gf_camera() { - return camera_data.gf_camera(GfVec4f((float)border[0] / screen_width, + return camera_data.gf_camera(pxr::GfVec4f((float)border[0] / screen_width, (float)border[1] / screen_height, (float)border[2] / screen_width, (float)border[3] / screen_height)); @@ -149,7 +145,7 @@ GLTexture::~GLTexture() } } -void GLTexture::setBuffer(HdRenderBuffer *buffer) +void GLTexture::setBuffer(pxr::HdRenderBuffer *buffer) { if (!textureId) { create(buffer); @@ -169,11 +165,11 @@ void GLTexture::setBuffer(HdRenderBuffer *buffer) buffer->Unmap(); } -void GLTexture::create(HdRenderBuffer *buffer) +void GLTexture::create(pxr::HdRenderBuffer *buffer) { width = buffer->GetWidth(); height = buffer->GetHeight(); - channels = HdGetComponentCount(buffer->GetFormat()); + channels = pxr::HdGetComponentCount(buffer->GetFormat()); glGenTextures(1, &textureId); glBindTexture(GL_TEXTURE_2D, textureId); @@ -246,12 +242,12 @@ void GLTexture::draw(GLfloat x, GLfloat y) void ViewportEngine::sync(Depsgraph *depsgraph, bContext *context, - HdRenderSettingsMap &renderSettings) + pxr::HdRenderSettingsMap &renderSettings) { if (!scene_delegate) { scene_delegate = std::make_unique( render_index.get(), - SdfPath::AbsoluteRootPath().AppendElementString("scene"), + pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"), BlenderSceneDelegate::EngineType::Viewport); } scene_delegate->populate(depsgraph, context); @@ -268,10 +264,10 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context) return; }; - GfCamera gfCamera = viewSettings.gf_camera(); + pxr::GfCamera gfCamera = viewSettings.gf_camera(); free_camera_delegate->SetCamera(gfCamera); render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(), - GfVec4d(viewSettings.border[0], + pxr::GfVec4d(viewSettings.border[0], viewSettings.border[1], viewSettings.border[2], viewSettings.border[3])); @@ -280,17 +276,17 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context) } if ((bl_engine->type->flag & RE_USE_GPU_CONTEXT) == 0) { - render_task_delegate->SetRendererAov(HdAovTokens->color); + render_task_delegate->SetRendererAov(pxr::HdAovTokens->color); } if (renderer_percent_done() == 0.0f) { - timeBegin = chrono::steady_clock::now(); + timeBegin = std::chrono::steady_clock::now(); } GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_IMAGE); GPU_shader_bind(shader); - HdTaskSharedPtrVector tasks; + pxr::HdTaskSharedPtrVector tasks; if (simple_light_task_delegate) { tasks.push_back(simple_light_task_delegate->GetTask()); } @@ -298,26 +294,26 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context) { /* Release the GIL before calling into hydra, in case any hydra plugins call into python. */ - TF_PY_ALLOW_THREADS_IN_SCOPE(); + pxr::TF_PY_ALLOW_THREADS_IN_SCOPE(); engine->Execute(render_index.get(), &tasks); if ((bl_engine->type->flag & RE_USE_GPU_CONTEXT) == 0) { - texture.setBuffer(render_task_delegate->GetRendererAov(HdAovTokens->color)); + texture.setBuffer(render_task_delegate->GetRendererAov(pxr::HdAovTokens->color)); texture.draw((GLfloat)viewSettings.border[0], (GLfloat)viewSettings.border[1]); } } GPU_shader_unbind(); - chrono::time_point timeCurrent = chrono::steady_clock::now(); - chrono::milliseconds elapsedTime = chrono::duration_cast(timeCurrent - + std::chrono::time_point timeCurrent = std::chrono::steady_clock::now(); + std::chrono::milliseconds elapsedTime = std::chrono::duration_cast(timeCurrent - timeBegin); - string formattedTime = format_duration(elapsedTime); + std::string formattedTime = format_duration(elapsedTime); if (!render_task_delegate->IsConverged()) { notify_status("Time: " + formattedTime + - " | Done: " + to_string(int(renderer_percent_done())) + "%", + " | Done: " + std::to_string(int(renderer_percent_done())) + "%", "Render"); bl_engine->flag |= RE_ENGINE_DO_DRAW; } @@ -331,7 +327,7 @@ void ViewportEngine::render(Depsgraph *depsgraph) /* Empty function */ } -void ViewportEngine::notify_status(const string &info, const string &status) +void ViewportEngine::notify_status(const std::string &info, const std::string &status) { RE_engine_update_stats(bl_engine, status.c_str(), info.c_str()); } -- 2.30.2 From 8bd5ccb5252f358a2db71c8b9eb19c98231dee49 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Tue, 14 Mar 2023 14:44:52 +0300 Subject: [PATCH 04/11] run `make format` --- source/blender/render/hydra/camera.cc | 11 ++--- source/blender/render/hydra/engine.cc | 7 +-- source/blender/render/hydra/final_engine.cc | 35 ++++++++------- source/blender/render/hydra/preview_engine.cc | 8 ++-- source/blender/render/hydra/preview_engine.h | 2 +- source/blender/render/hydra/python.cc | 9 ++-- .../render/hydra/render_task_delegate.cc | 42 +++++++++++------- .../render/hydra/render_task_delegate.h | 5 ++- .../scene_delegate/blender_scene_delegate.cc | 13 +++--- .../render/hydra/scene_delegate/light.cc | 6 +-- .../render/hydra/scene_delegate/material.cc | 3 +- .../render/hydra/scene_delegate/mesh.cc | 20 +++++---- .../scene_delegate/mtlx_hydra_adapter.cc | 20 ++++++--- .../hydra/scene_delegate/mtlx_hydra_adapter.h | 6 +-- .../render/hydra/scene_delegate/world.cc | 12 +++-- .../hydra/simple_light_task_delegate.cc | 2 +- source/blender/render/hydra/utils.cc | 44 +++++++++---------- .../blender/render/hydra/viewport_engine.cc | 29 ++++++------ 18 files changed, 154 insertions(+), 120 deletions(-) diff --git a/source/blender/render/hydra/camera.cc b/source/blender/render/hydra/camera.cc index b6c74ccda302..f2201e53518d 100644 --- a/source/blender/render/hydra/camera.cc +++ b/source/blender/render/hydra/camera.cc @@ -26,8 +26,8 @@ CameraData::CameraData(Object *camera_obj, pxr::GfVec2i res, pxr::GfVec4f tile) } else { pxr::GfVec3f obj_pos(camera->dof.focus_object->object_to_world[0][3], - camera->dof.focus_object->object_to_world[1][3], - camera->dof.focus_object->object_to_world[2][3]); + camera->dof.focus_object->object_to_world[1][3], + camera->dof.focus_object->object_to_world[2][3]); pxr::GfVec3f cam_pos(transform[0][3], transform[1][3], transform[2][3]); focus_distance = (obj_pos - cam_pos).GetLength(); } @@ -58,8 +58,9 @@ CameraData::CameraData(Object *camera_obj, pxr::GfVec2i res, pxr::GfVec4f tile) break; } - lens_shift = pxr::GfVec2f(lens_shift[0] / t_size[0] + (t_pos[0] + t_size[0] * 0.5 - 0.5) / t_size[0], - lens_shift[1] / t_size[1] + (t_pos[1] + t_size[1] * 0.5 - 0.5) / t_size[1]); + lens_shift = pxr::GfVec2f( + lens_shift[0] / t_size[0] + (t_pos[0] + t_size[0] * 0.5 - 0.5) / t_size[0], + lens_shift[1] / t_size[1] + (t_pos[1] + t_size[1] * 0.5 - 0.5) / t_size[1]); switch (camera->type) { case CAM_PERSP: @@ -203,7 +204,7 @@ CameraData::CameraData(bContext *context) // Updating l_shift due to viewport zoom and view_camera_offset // view_camera_offset should be multiplied by 2 lens_shift = pxr::GfVec2f((lens_shift[0] + region_data->camdx * 2) / zoom, - (lens_shift[1] + region_data->camdy * 2) / zoom); + (lens_shift[1] + region_data->camdy * 2) / zoom); if (mode == CAM_ORTHO) { ortho_size *= zoom; diff --git a/source/blender/render/hydra/engine.cc b/source/blender/render/hydra/engine.cc index 84d2719d2720..b86871b6d9ea 100644 --- a/source/blender/render/hydra/engine.cc +++ b/source/blender/render/hydra/engine.cc @@ -18,9 +18,9 @@ Engine::Engine(RenderEngine *bl_engine, const std::string &delegateId) : bl_engi { pxr::HdRendererPluginRegistry ®istry = pxr::HdRendererPluginRegistry::GetInstance(); - //TF_PY_ALLOW_THREADS_IN_SCOPE(); + pxr::TF_PY_ALLOW_THREADS_IN_SCOPE(); render_delegate = registry.CreateRenderDelegate(pxr::TfToken(delegateId)); - + pxr::HdDriverVector hd_drivers; if (bl_engine->type->flag & RE_USE_GPU_CONTEXT) { hgi = pxr::Hgi::CreatePlatformDefaultHgi(); @@ -37,7 +37,8 @@ Engine::Engine(RenderEngine *bl_engine, const std::string &delegateId) : bl_engi render_index.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("renderTask")); if (render_delegate->GetRendererDisplayName() == "GL") { simple_light_task_delegate = std::make_unique( - render_index.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("simpleLightTask")); + render_index.get(), + pxr::SdfPath::AbsoluteRootPath().AppendElementString("simpleLightTask")); } engine = std::make_unique(); diff --git a/source/blender/render/hydra/final_engine.cc b/source/blender/render/hydra/final_engine.cc index 4a1ffc59e6b7..7951e5172c57 100644 --- a/source/blender/render/hydra/final_engine.cc +++ b/source/blender/render/hydra/final_engine.cc @@ -16,11 +16,11 @@ namespace blender::render::hydra { void FinalEngine::sync(Depsgraph *depsgraph, bContext *context, - pxr::HdRenderSettingsMap &renderSettings) + pxr::HdRenderSettingsMap &renderSettings) { scene_delegate = std::make_unique( render_index.get(), - pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"), + pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"), BlenderSceneDelegate::EngineType::Final); scene_delegate->populate(depsgraph, context); @@ -42,17 +42,18 @@ void FinalEngine::render(Depsgraph *depsgraph) pxr::GfVec4f border(0, 0, 1, 1); if (r.mode & R_BORDER) { border = pxr::GfVec4f(r.border.xmin, - r.border.ymin, - r.border.xmax - r.border.xmin, - r.border.ymax - r.border.ymin); + r.border.ymin, + r.border.xmax - r.border.xmin, + r.border.ymax - r.border.ymin); } pxr::GfVec2i image_res(r.xsch * r.size / 100, r.ysch * r.size / 100); pxr::GfVec2i res(int(image_res[0] * border[2]), int(image_res[1] * border[3])); - pxr::GfCamera camera = CameraData(scene->camera, image_res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(border); + pxr::GfCamera camera = + CameraData(scene->camera, image_res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(border); free_camera_delegate->SetCamera(camera); render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(), - pxr::GfVec4d(0, 0, res[0], res[1])); + pxr::GfVec4d(0, 0, res[0], res[1])); render_task_delegate->SetRendererAov(pxr::HdAovTokens->color); if (simple_light_task_delegate) { simple_light_task_delegate->SetCameraPath(free_camera_delegate->GetCameraId()); @@ -64,7 +65,8 @@ void FinalEngine::render(Depsgraph *depsgraph) } tasks.push_back(render_task_delegate->GetTask()); - std::chrono::time_point timeBegin = std::chrono::steady_clock::now(), timeCurrent; + std::chrono::time_point timeBegin = std::chrono::steady_clock::now(), + timeCurrent; std::chrono::milliseconds elapsedTime; float percentDone = 0.0; @@ -113,7 +115,8 @@ pxr::GfVec2i FinalEngine::get_resolution(Scene *scene) border_w = r.border.xmax - r.border.xmin; border_h = r.border.ymax - r.border.ymin; } - return pxr::GfVec2i(int(r.xsch * border_w * r.size / 100), int(r.ysch * border_h * r.size / 100)); + return pxr::GfVec2i(int(r.xsch * border_w * r.size / 100), + int(r.ysch * border_h * r.size / 100)); } void FinalEngine::updateRenderResult(std::map> &renderImages, @@ -158,17 +161,18 @@ void FinalEngineGL::render(Depsgraph *depsgraph) pxr::GfVec4f border(0, 0, 1, 1); if (r.mode & R_BORDER) { border = pxr::GfVec4f(r.border.xmin, - r.border.ymin, - r.border.xmax - r.border.xmin, - r.border.ymax - r.border.ymin); + r.border.ymin, + r.border.xmax - r.border.xmin, + r.border.ymax - r.border.ymin); } pxr::GfVec2i image_res = {r.xsch * r.size / 100, r.ysch * r.size / 100}; pxr::GfVec2i res = {int(image_res[0] * border[2]), int(image_res[1] * border[3])}; - pxr::GfCamera camera = CameraData(scene->camera, image_res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(border); + pxr::GfCamera camera = + CameraData(scene->camera, image_res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(border); free_camera_delegate->SetCamera(camera); render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(), - pxr::GfVec4d(0, 0, res[0], res[1])); + pxr::GfVec4d(0, 0, res[0], res[1])); if (simple_light_task_delegate) { simple_light_task_delegate->SetCameraPath(free_camera_delegate->GetCameraId()); } @@ -182,7 +186,8 @@ void FinalEngineGL::render(Depsgraph *depsgraph) } tasks.push_back(render_task_delegate->GetTask()); - std::chrono::time_point timeBegin = std::chrono::steady_clock::now(), timeCurrent; + std::chrono::time_point timeBegin = std::chrono::steady_clock::now(), + timeCurrent; std::chrono::milliseconds elapsedTime; float percentDone = 0.0; diff --git a/source/blender/render/hydra/preview_engine.cc b/source/blender/render/hydra/preview_engine.cc index bdaf6f878695..304bae29017f 100644 --- a/source/blender/render/hydra/preview_engine.cc +++ b/source/blender/render/hydra/preview_engine.cc @@ -10,11 +10,11 @@ namespace blender::render::hydra { void PreviewEngine::sync(Depsgraph *depsgraph, bContext *context, - pxr::HdRenderSettingsMap &renderSettings) + pxr::HdRenderSettingsMap &renderSettings) { scene_delegate = std::make_unique( render_index.get(), - pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"), + pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"), BlenderSceneDelegate::EngineType::Preview); scene_delegate->populate(depsgraph, context); @@ -36,7 +36,7 @@ void PreviewEngine::render(Depsgraph *depsgraph) free_camera_delegate->SetCamera(camera); render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(), - pxr::GfVec4d(0, 0, res[0], res[1])); + pxr::GfVec4d(0, 0, res[0], res[1])); render_task_delegate->SetRendererAov(pxr::HdAovTokens->color); pxr::HdTaskSharedPtrVector tasks; @@ -73,7 +73,7 @@ void PreviewEngine::render(Depsgraph *depsgraph) void PreviewEngine::updateRenderResult(const std::string &layerName, int width, int height, - std::vector &pixels) + std::vector &pixels) { RenderResult *result = RE_engine_begin_result( bl_engine, 0, 0, width, height, layerName.c_str(), nullptr); diff --git a/source/blender/render/hydra/preview_engine.h b/source/blender/render/hydra/preview_engine.h index 3a8444bbaa91..4fcf5ec8cf5b 100644 --- a/source/blender/render/hydra/preview_engine.h +++ b/source/blender/render/hydra/preview_engine.h @@ -22,7 +22,7 @@ class PreviewEngine : public FinalEngine { std::vector &pixels); protected: - pxr::HdRenderSettingsMap renderSettings; + pxr::HdRenderSettingsMap renderSettings; }; } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/python.cc b/source/blender/render/hydra/python.cc index 5860a7a4cbca..eb3334d4d788 100644 --- a/source/blender/render/hydra/python.cc +++ b/source/blender/render/hydra/python.cc @@ -107,10 +107,11 @@ static PyObject *get_render_plugins_func(PyObject * /*self*/, PyObject *args) PyDict_SetItemString(descr, "id", val = PyUnicode_FromString(plugin_ids[i].GetText())); Py_DECREF(val); - PyDict_SetItemString(descr, - "name", - val = PyUnicode_FromString( - pxr::UsdImagingGLEngine::GetRendererDisplayName(plugin_ids[i]).c_str())); + PyDict_SetItemString( + descr, + "name", + val = PyUnicode_FromString( + pxr::UsdImagingGLEngine::GetRendererDisplayName(plugin_ids[i]).c_str())); Py_DECREF(val); std::string plugin_name = plugin_ids[i]; diff --git a/source/blender/render/hydra/render_task_delegate.cc b/source/blender/render/hydra/render_task_delegate.cc index 6bc92a0c994f..9b9ac47f6b1d 100644 --- a/source/blender/render/hydra/render_task_delegate.cc +++ b/source/blender/render/hydra/render_task_delegate.cc @@ -13,15 +13,16 @@ namespace blender::render::hydra { -RenderTaskDelegate::RenderTaskDelegate(pxr::HdRenderIndex *parentIndex, pxr::SdfPath const &delegateID) +RenderTaskDelegate::RenderTaskDelegate(pxr::HdRenderIndex *parentIndex, + pxr::SdfPath const &delegateID) : pxr::HdSceneDelegate(parentIndex, delegateID) { pxr::SdfPath renderTaskId = GetTaskID(); GetRenderIndex().InsertTask(this, renderTaskId); GetRenderIndex().GetChangeTracker().MarkTaskDirty(renderTaskId, - pxr::HdChangeTracker::DirtyCollection); + pxr::HdChangeTracker::DirtyCollection); GetRenderIndex().GetChangeTracker().MarkTaskDirty(renderTaskId, - pxr::HdChangeTracker::DirtyRenderTags); + pxr::HdChangeTracker::DirtyRenderTags); taskParams.enableLighting = true; taskParams.alphaThreshold = 0.1f; @@ -44,8 +45,10 @@ pxr::VtValue RenderTaskDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const return pxr::VtValue(taskParams); } if (key == pxr::HdTokens->collection) { - pxr::HdRprimCollection rprimCollection( - pxr::HdTokens->geometry, pxr::HdReprSelector(pxr::HdReprTokens->smoothHull), false, pxr::TfToken()); + pxr::HdRprimCollection rprimCollection(pxr::HdTokens->geometry, + pxr::HdReprSelector(pxr::HdReprTokens->smoothHull), + false, + pxr::TfToken()); rprimCollection.SetRootPath(pxr::SdfPath::AbsoluteRootPath()); return pxr::VtValue(rprimCollection); } @@ -72,16 +75,19 @@ bool RenderTaskDelegate::IsConverged() void RenderTaskDelegate::SetRendererAov(pxr::TfToken const &aov) { - pxr::HdAovDescriptor aovDesc = GetRenderIndex().GetRenderDelegate()->GetDefaultAovDescriptor(aov); - pxr::HdRenderBufferDescriptor desc(pxr::GfVec3i(taskParams.viewport[2], taskParams.viewport[3], 1), - aovDesc.format, - aovDesc.multiSampled); + pxr::HdAovDescriptor aovDesc = GetRenderIndex().GetRenderDelegate()->GetDefaultAovDescriptor( + aov); + pxr::HdRenderBufferDescriptor desc( + pxr::GfVec3i(taskParams.viewport[2], taskParams.viewport[3], 1), + aovDesc.format, + aovDesc.multiSampled); pxr::SdfPath bufferId = GetAovID(aov); if (bufferDescriptors.find(bufferId) == bufferDescriptors.end()) { GetRenderIndex().InsertBprim(pxr::HdPrimTypeTokens->renderBuffer, this, bufferId); bufferDescriptors[bufferId] = desc; - GetRenderIndex().GetChangeTracker().MarkBprimDirty(bufferId, pxr::HdRenderBuffer::DirtyDescription); + GetRenderIndex().GetChangeTracker().MarkBprimDirty(bufferId, + pxr::HdRenderBuffer::DirtyDescription); pxr::HdRenderPassAovBinding binding; binding.aovName = aov; @@ -89,18 +95,20 @@ void RenderTaskDelegate::SetRendererAov(pxr::TfToken const &aov) binding.aovSettings = aovDesc.aovSettings; taskParams.aovBindings.push_back(binding); - GetRenderIndex().GetChangeTracker().MarkTaskDirty(GetTaskID(), pxr::HdChangeTracker::DirtyParams); + GetRenderIndex().GetChangeTracker().MarkTaskDirty(GetTaskID(), + pxr::HdChangeTracker::DirtyParams); } else if (bufferDescriptors[bufferId] != desc) { bufferDescriptors[bufferId] = desc; - GetRenderIndex().GetChangeTracker().MarkBprimDirty(bufferId, pxr::HdRenderBuffer::DirtyDescription); + GetRenderIndex().GetChangeTracker().MarkBprimDirty(bufferId, + pxr::HdRenderBuffer::DirtyDescription); } } pxr::HdRenderBuffer *RenderTaskDelegate::GetRendererAov(pxr::TfToken const &aov) { - return ( - pxr::HdRenderBuffer *)(GetRenderIndex().GetBprim(pxr::HdPrimTypeTokens->renderBuffer, GetAovID(aov))); + return (pxr::HdRenderBuffer *)(GetRenderIndex().GetBprim(pxr::HdPrimTypeTokens->renderBuffer, + GetAovID(aov))); } void RenderTaskDelegate::GetRendererAovData(pxr::TfToken const &aov, void *data) @@ -118,12 +126,14 @@ pxr::HdTaskSharedPtr RenderTaskDelegate::GetTask() return GetRenderIndex().GetTask(GetTaskID()); } -void RenderTaskDelegate::SetCameraAndViewport(pxr::SdfPath const &cameraId, pxr::GfVec4d const &viewport) +void RenderTaskDelegate::SetCameraAndViewport(pxr::SdfPath const &cameraId, + pxr::GfVec4d const &viewport) { if (taskParams.viewport != viewport || taskParams.camera != cameraId) { taskParams.viewport = viewport; taskParams.camera = cameraId; - GetRenderIndex().GetChangeTracker().MarkTaskDirty(GetTaskID(), pxr::HdChangeTracker::DirtyParams); + GetRenderIndex().GetChangeTracker().MarkTaskDirty(GetTaskID(), + pxr::HdChangeTracker::DirtyParams); } } diff --git a/source/blender/render/hydra/render_task_delegate.h b/source/blender/render/hydra/render_task_delegate.h index aaa36a2a9b5a..42965648c90a 100644 --- a/source/blender/render/hydra/render_task_delegate.h +++ b/source/blender/render/hydra/render_task_delegate.h @@ -29,8 +29,9 @@ class RenderTaskDelegate : public pxr::HdSceneDelegate { void SetCameraAndViewport(pxr::SdfPath const &cameraId, pxr::GfVec4d const &viewport); private: - pxr::HdxRenderTaskParams taskParams; - pxr::TfHashMap bufferDescriptors; + pxr::HdxRenderTaskParams taskParams; + pxr::TfHashMap + bufferDescriptors; }; } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc index 2010bbf9294e..7dfd5919584a 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -98,7 +98,7 @@ pxr::SdfPathVector BlenderSceneDelegate::GetInstancerPrototypes(pxr::SdfPath con } pxr::VtIntArray BlenderSceneDelegate::GetInstanceIndices(pxr::SdfPath const &instancerId, - pxr::SdfPath const &prototypeId) + pxr::SdfPath const &prototypeId) { LOG(INFO) << "GetInstanceIndices: " << instancerId.GetString() << " " << prototypeId.GetString(); MeshData *m_data = mesh_data(prototypeId); @@ -117,7 +117,7 @@ pxr::GfMatrix4d BlenderSceneDelegate::GetInstancerTransform(pxr::SdfPath const & size_t BlenderSceneDelegate::SampleInstancerTransform(pxr::SdfPath const &instancerId, size_t maxSampleCount, float *sampleTimes, - pxr::GfMatrix4d *sampleValues) + pxr::GfMatrix4d *sampleValues) { LOG(INFO) << "SampleInstancerTransform: " << instancerId.GetString(); size_t ret = 0; @@ -127,10 +127,10 @@ size_t BlenderSceneDelegate::SampleInstancerTransform(pxr::SdfPath const &instan } size_t BlenderSceneDelegate::SamplePrimvar(pxr::SdfPath const &id, - pxr::TfToken const &key, + pxr::TfToken const &key, size_t maxSampleCount, float *sampleTimes, - pxr::VtValue *sampleValues) + pxr::VtValue *sampleValues) { // TODO: add a separate object for instancer for cleaner handling code if (id.GetName() == "Instancer") { @@ -416,7 +416,7 @@ pxr::VtValue BlenderSceneDelegate::Get(pxr::SdfPath const &id, pxr::TfToken cons } pxr::HdPrimvarDescriptorVector BlenderSceneDelegate::GetPrimvarDescriptors( - pxr::SdfPath const &id, pxr::HdInterpolation interpolation) + pxr::SdfPath const &id, pxr::HdInterpolation interpolation) { LOG(INFO) << "GetPrimvarDescriptors: " << id.GetString() << " " << interpolation; if (mesh_data(id)) { @@ -465,7 +465,8 @@ pxr::GfMatrix4d BlenderSceneDelegate::GetTransform(pxr::SdfPath const &id) return pxr::GfMatrix4d(); } -pxr::VtValue BlenderSceneDelegate::GetLightParamValue(pxr::SdfPath const &id, pxr::TfToken const &key) +pxr::VtValue BlenderSceneDelegate::GetLightParamValue(pxr::SdfPath const &id, + pxr::TfToken const &key) { LightData *l_data = light_data(id); if (l_data) { diff --git a/source/blender/render/hydra/scene_delegate/light.cc b/source/blender/render/hydra/scene_delegate/light.cc index 949db040c208..f328745506c5 100644 --- a/source/blender/render/hydra/scene_delegate/light.cc +++ b/source/blender/render/hydra/scene_delegate/light.cc @@ -23,9 +23,9 @@ LightData::LightData(BlenderSceneDelegate *scene_delegate, Object *object) Light *light = (Light *)((Object *)id)->data; data[pxr::HdLightTokens->intensity] = scene_delegate->engine_type == - BlenderSceneDelegate::EngineType::Preview ? - light->energy / 1000 : - light->energy; + BlenderSceneDelegate::EngineType::Preview ? + light->energy / 1000 : + light->energy; data[pxr::HdLightTokens->color] = pxr::GfVec3f(light->r, light->g, light->b); diff --git a/source/blender/render/hydra/scene_delegate/material.cc b/source/blender/render/hydra/scene_delegate/material.cc index 501477f45d04..b72ee790d381 100644 --- a/source/blender/render/hydra/scene_delegate/material.cc +++ b/source/blender/render/hydra/scene_delegate/material.cc @@ -93,7 +93,8 @@ void MaterialData::export_mtlx() void MaterialData::insert_prim() { pxr::SdfPath p_id = prim_id(scene_delegate, (Material *)id); - scene_delegate->GetRenderIndex().InsertSprim(pxr::HdPrimTypeTokens->material, scene_delegate, p_id); + scene_delegate->GetRenderIndex().InsertSprim( + pxr::HdPrimTypeTokens->material, scene_delegate, p_id); LOG(INFO) << "Add material: " << name() << " id=" << p_id.GetAsString(); } diff --git a/source/blender/render/hydra/scene_delegate/mesh.cc b/source/blender/render/hydra/scene_delegate/mesh.cc index f80040f33813..90b63b0f8076 100644 --- a/source/blender/render/hydra/scene_delegate/mesh.cc +++ b/source/blender/render/hydra/scene_delegate/mesh.cc @@ -63,9 +63,9 @@ Material *MeshData::material() pxr::HdMeshTopology MeshData::mesh_topology() { return pxr::HdMeshTopology(pxr::PxOsdOpenSubdivTokens->catmullClark, - pxr::HdTokens->rightHanded, - face_vertex_counts, - face_vertex_indices); + pxr::HdTokens->rightHanded, + face_vertex_counts, + face_vertex_indices); } pxr::HdPrimvarDescriptorVector MeshData::primvar_descriptors(pxr::HdInterpolation interpolation) @@ -78,23 +78,25 @@ pxr::HdPrimvarDescriptorVector MeshData::primvar_descriptors(pxr::HdInterpolatio } else if (interpolation == pxr::HdInterpolationFaceVarying) { if (!normals.empty()) { - primvars.emplace_back(pxr::HdTokens->normals, interpolation, pxr::HdPrimvarRoleTokens->normal); + primvars.emplace_back( + pxr::HdTokens->normals, interpolation, pxr::HdPrimvarRoleTokens->normal); } if (!uvs.empty()) { primvars.emplace_back(pxr::HdPrimvarRoleTokens->textureCoordinate, interpolation, - pxr::HdPrimvarRoleTokens->textureCoordinate); + pxr::HdPrimvarRoleTokens->textureCoordinate); } } return primvars; } -pxr::HdPrimvarDescriptorVector MeshData::instancer_primvar_descriptors(pxr::HdInterpolation interpolation) +pxr::HdPrimvarDescriptorVector MeshData::instancer_primvar_descriptors( + pxr::HdInterpolation interpolation) { pxr::HdPrimvarDescriptorVector primvars; if (interpolation == pxr::HdInterpolationInstance) { primvars.emplace_back( - pxr::HdInstancerTokens->instanceTransform, interpolation, pxr::HdPrimvarRoleTokens->none); + pxr::HdInstancerTokens->instanceTransform, interpolation, pxr::HdPrimvarRoleTokens->none); } return primvars; } @@ -110,7 +112,7 @@ pxr::VtIntArray MeshData::instance_indices() size_t MeshData::sample_instancer_transform(size_t maxSampleCount, float *sampleTimes, - pxr::GfMatrix4d *sampleValues) + pxr::GfMatrix4d *sampleValues) { *sampleTimes = 0.0f; *sampleValues = pxr::GfMatrix4d(1.0); @@ -120,7 +122,7 @@ size_t MeshData::sample_instancer_transform(size_t maxSampleCount, size_t MeshData::sample_instancer_primvar(pxr::TfToken const &key, size_t maxSampleCount, float *sampleTimes, - pxr::VtValue *sampleValues) + pxr::VtValue *sampleValues) { if (key == pxr::HdInstancerTokens->instanceTransform) { if (maxSampleCount > 0) { diff --git a/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.cc b/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.cc index 0c1de955e0c7..555f9c42567f 100644 --- a/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.cc +++ b/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.cc @@ -23,9 +23,9 @@ namespace mx = MaterialX; void HdMtlxConvertToMaterialNetworkMap(std::string const &mtlxPath, - pxr::TfTokenVector const &shaderSourceTypes, - pxr::TfTokenVector const &renderContexts, - pxr::HdMaterialNetworkMap *out) + pxr::TfTokenVector const &shaderSourceTypes, + pxr::TfTokenVector const &renderContexts, + pxr::HdMaterialNetworkMap *out) { if (mtlxPath.empty()) { return; @@ -48,11 +48,17 @@ void HdMtlxConvertToMaterialNetworkMap(std::string const &mtlxPath, pxr::UsdMtlxRead(doc, stage); } catch (mx::ExceptionFoundCycle &x) { - Tf_PostErrorHelper(pxr::TF_CALL_CONTEXT, pxr::TF_DIAGNOSTIC_RUNTIME_ERROR_TYPE, "MaterialX cycle found: %s\n", x.what()); + Tf_PostErrorHelper(pxr::TF_CALL_CONTEXT, + pxr::TF_DIAGNOSTIC_RUNTIME_ERROR_TYPE, + "MaterialX cycle found: %s\n", + x.what()); return; } catch (mx::Exception &x) { - Tf_PostErrorHelper(pxr::TF_CALL_CONTEXT, pxr::TF_DIAGNOSTIC_RUNTIME_ERROR_TYPE, "MaterialX error: %s\n", x.what()); + Tf_PostErrorHelper(pxr::TF_CALL_CONTEXT, + pxr::TF_DIAGNOSTIC_RUNTIME_ERROR_TYPE, + "MaterialX error: %s\n", + x.what()); return; } @@ -61,11 +67,11 @@ void HdMtlxConvertToMaterialNetworkMap(std::string const &mtlxPath, if (auto material = pxr::UsdShadeMaterial(*children.begin())) { if (pxr::UsdShadeShader mtlxSurface = material.ComputeSurfaceSource(renderContexts)) { UsdImagingBuildHdMaterialNetworkFromTerminal(mtlxSurface.GetPrim(), - pxr::HdMaterialTerminalTokens->surface, + pxr::HdMaterialTerminalTokens->surface, shaderSourceTypes, renderContexts, out, - pxr::UsdTimeCode::Default()); + pxr::UsdTimeCode::Default()); } } } diff --git a/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.h b/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.h index 4164ff204bdb..09841d5f84e6 100644 --- a/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.h +++ b/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.h @@ -11,6 +11,6 @@ struct pxr::HdMaterialNetworkMap; void HdMtlxConvertToMaterialNetworkMap(std::string const &mtlxPath, - pxr::TfTokenVector const &shaderSourceTypes, - pxr::TfTokenVector const &renderContexts, - pxr::HdMaterialNetworkMap *out); + pxr::TfTokenVector const &shaderSourceTypes, + pxr::TfTokenVector const &renderContexts, + pxr::HdMaterialNetworkMap *out); diff --git a/source/blender/render/hydra/scene_delegate/world.cc b/source/blender/render/hydra/scene_delegate/world.cc index a14dc4618557..95ab57b2ac77 100644 --- a/source/blender/render/hydra/scene_delegate/world.cc +++ b/source/blender/render/hydra/scene_delegate/world.cc @@ -102,12 +102,15 @@ WorldData::WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContex pxr::GfMatrix4d WorldData::transform() { - pxr::GfMatrix4d transform = pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), -90), pxr::GfVec3d()); + pxr::GfMatrix4d transform = pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), -90), + pxr::GfVec3d()); /* TODO : do this check via RenderSettings*/ if (scene_delegate->GetRenderIndex().GetRenderDelegate()->GetRendererDisplayName() == "RPR") { - transform *= pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), -180), pxr::GfVec3d()); - transform *= pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(0.0, 0.0, 1.0), 90.0), pxr::GfVec3d()); + transform *= pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), -180), + pxr::GfVec3d()); + transform *= pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(0.0, 0.0, 1.0), 90.0), + pxr::GfVec3d()); } return transform; } @@ -125,7 +128,8 @@ pxr::VtValue WorldData::get_data(pxr::TfToken const &key) void WorldData::insert_prim() { pxr::SdfPath p_id = prim_id(scene_delegate); - scene_delegate->GetRenderIndex().InsertSprim(pxr::HdPrimTypeTokens->domeLight, scene_delegate, p_id); + scene_delegate->GetRenderIndex().InsertSprim( + pxr::HdPrimTypeTokens->domeLight, scene_delegate, p_id); LOG(INFO) << "Add World: id=" << p_id.GetAsString(); } diff --git a/source/blender/render/hydra/simple_light_task_delegate.cc b/source/blender/render/hydra/simple_light_task_delegate.cc index 43a223b8dd5f..2043ba4c65e7 100644 --- a/source/blender/render/hydra/simple_light_task_delegate.cc +++ b/source/blender/render/hydra/simple_light_task_delegate.cc @@ -8,7 +8,7 @@ namespace blender::render::hydra { SimpleLightTaskDelegate::SimpleLightTaskDelegate(pxr::HdRenderIndex *parentIndex, - pxr::SdfPath const &delegateID) + pxr::SdfPath const &delegateID) : pxr::HdSceneDelegate(parentIndex, delegateID) { pxr::SdfPath taskId = GetTaskID(); diff --git a/source/blender/render/hydra/utils.cc b/source/blender/render/hydra/utils.cc index 146d1b7bfd69..c691ff926deb 100644 --- a/source/blender/render/hydra/utils.cc +++ b/source/blender/render/hydra/utils.cc @@ -1,9 +1,9 @@ /* SPDX-License-Identifier: Apache-2.0 * Copyright 2011-2022 Blender Foundation */ +#include #include #include -#include #include @@ -18,24 +18,24 @@ namespace blender::render::hydra { - pxr::GfMatrix4d gf_matrix_from_transform(float m[4][4]) +pxr::GfMatrix4d gf_matrix_from_transform(float m[4][4]) { return pxr::GfMatrix4d(m[0][0], - m[0][1], - m[0][2], - m[0][3], - m[1][0], - m[1][1], - m[1][2], - m[1][3], - m[2][0], - m[2][1], - m[2][2], - m[2][3], - m[3][0], - m[3][1], - m[3][2], - m[3][3]); + m[0][1], + m[0][2], + m[0][3], + m[1][0], + m[1][1], + m[1][2], + m[1][3], + m[2][0], + m[2][1], + m[2][2], + m[2][3], + m[3][0], + m[3][1], + m[3][2], + m[3][3]); } std::string format_duration(std::chrono::milliseconds millisecs) @@ -68,11 +68,11 @@ std::string format_duration(std::chrono::milliseconds millisecs) } std::string cache_image(Main *bmain, - Scene *scene, - Image *image, - ImageUser *iuser, - ImageSaveOptions *opts, - ReportList *reports) + Scene *scene, + Image *image, + ImageUser *iuser, + ImageSaveOptions *opts, + ReportList *reports) { const std::string default_format = ".png"; diff --git a/source/blender/render/hydra/viewport_engine.cc b/source/blender/render/hydra/viewport_engine.cc index e498cf6efee2..fdb976140a7e 100644 --- a/source/blender/render/hydra/viewport_engine.cc +++ b/source/blender/render/hydra/viewport_engine.cc @@ -7,19 +7,19 @@ #include #include -#include "DNA_vec_types.h" #include "BKE_camera.h" #include "BLI_math_matrix.h" #include "DEG_depsgraph_query.h" #include "DNA_camera_types.h" #include "DNA_screen_types.h" +#include "DNA_vec_types.h" #include "GPU_shader.h" #include "glog/logging.h" -#include "viewport_engine.h" #include "camera.h" #include "utils.h" +#include "viewport_engine.h" namespace blender::render::hydra { @@ -129,9 +129,9 @@ int ViewSettings::height() pxr::GfCamera ViewSettings::gf_camera() { return camera_data.gf_camera(pxr::GfVec4f((float)border[0] / screen_width, - (float)border[1] / screen_height, - (float)border[2] / screen_width, - (float)border[3] / screen_height)); + (float)border[1] / screen_height, + (float)border[2] / screen_width, + (float)border[3] / screen_height)); } GLTexture::GLTexture() : textureId(0), width(0), height(0), channels(4) @@ -242,12 +242,12 @@ void GLTexture::draw(GLfloat x, GLfloat y) void ViewportEngine::sync(Depsgraph *depsgraph, bContext *context, - pxr::HdRenderSettingsMap &renderSettings) + pxr::HdRenderSettingsMap &renderSettings) { if (!scene_delegate) { scene_delegate = std::make_unique( render_index.get(), - pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"), + pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"), BlenderSceneDelegate::EngineType::Viewport); } scene_delegate->populate(depsgraph, context); @@ -267,10 +267,10 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context) pxr::GfCamera gfCamera = viewSettings.gf_camera(); free_camera_delegate->SetCamera(gfCamera); render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(), - pxr::GfVec4d(viewSettings.border[0], - viewSettings.border[1], - viewSettings.border[2], - viewSettings.border[3])); + pxr::GfVec4d(viewSettings.border[0], + viewSettings.border[1], + viewSettings.border[2], + viewSettings.border[3])); if (simple_light_task_delegate) { simple_light_task_delegate->SetCameraPath(free_camera_delegate->GetCameraId()); } @@ -305,9 +305,10 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context) GPU_shader_unbind(); - std::chrono::time_point timeCurrent = std::chrono::steady_clock::now(); - std::chrono::milliseconds elapsedTime = std::chrono::duration_cast(timeCurrent - - timeBegin); + std::chrono::time_point timeCurrent = + std::chrono::steady_clock::now(); + std::chrono::milliseconds elapsedTime = std::chrono::duration_cast( + timeCurrent - timeBegin); std::string formattedTime = format_duration(elapsedTime); -- 2.30.2 From 80af3c861ce25d9667507b561e114aaceb0aa283 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Tue, 14 Mar 2023 15:14:00 +0300 Subject: [PATCH 05/11] rewritten gf_matrix_from_transform include fix --- source/blender/render/hydra/utils.cc | 23 ++++++------------- .../blender/render/hydra/viewport_engine.cc | 6 ++--- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/source/blender/render/hydra/utils.cc b/source/blender/render/hydra/utils.cc index c691ff926deb..a1ad16654aa4 100644 --- a/source/blender/render/hydra/utils.cc +++ b/source/blender/render/hydra/utils.cc @@ -20,22 +20,13 @@ namespace blender::render::hydra { pxr::GfMatrix4d gf_matrix_from_transform(float m[4][4]) { - return pxr::GfMatrix4d(m[0][0], - m[0][1], - m[0][2], - m[0][3], - m[1][0], - m[1][1], - m[1][2], - m[1][3], - m[2][0], - m[2][1], - m[2][2], - m[2][3], - m[3][0], - m[3][1], - m[3][2], - m[3][3]); + pxr::GfMatrix4d ret = pxr::GfMatrix4d(); + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + ret[i][j] = m[i][j]; + } + } + return ret; } std::string format_duration(std::chrono::milliseconds millisecs) diff --git a/source/blender/render/hydra/viewport_engine.cc b/source/blender/render/hydra/viewport_engine.cc index fdb976140a7e..2ee3f2468785 100644 --- a/source/blender/render/hydra/viewport_engine.cc +++ b/source/blender/render/hydra/viewport_engine.cc @@ -7,12 +7,12 @@ #include #include +#include "DNA_camera_types.h" +#include "DNA_screen_types.h" +#include "DNA_vec_types.h" /* this include should be before BKE_camera.h due to "rctf" type */ #include "BKE_camera.h" #include "BLI_math_matrix.h" #include "DEG_depsgraph_query.h" -#include "DNA_camera_types.h" -#include "DNA_screen_types.h" -#include "DNA_vec_types.h" #include "GPU_shader.h" #include "glog/logging.h" -- 2.30.2 From e1bc7f43126cc7f818f92605754e76cd7b79eb04 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Tue, 14 Mar 2023 17:44:53 +0300 Subject: [PATCH 06/11] camelCase -> snake_case run make format --- source/blender/render/hydra/engine.cc | 4 +- source/blender/render/hydra/engine.h | 2 +- source/blender/render/hydra/final_engine.cc | 130 +++++++++--------- source/blender/render/hydra/final_engine.h | 12 +- source/blender/render/hydra/preview_engine.cc | 38 ++--- source/blender/render/hydra/preview_engine.h | 12 +- source/blender/render/hydra/python.cc | 8 +- .../render/hydra/render_task_delegate.cc | 108 +++++++-------- .../render/hydra/render_task_delegate.h | 22 +-- .../scene_delegate/blender_scene_delegate.cc | 59 ++++---- .../scene_delegate/blender_scene_delegate.h | 32 ++--- .../render/hydra/scene_delegate/light.cc | 2 +- .../render/hydra/scene_delegate/mesh.cc | 22 +-- .../render/hydra/scene_delegate/mesh.h | 12 +- .../scene_delegate/mtlx_hydra_adapter.cc | 30 ++-- .../hydra/scene_delegate/mtlx_hydra_adapter.h | 6 +- .../hydra/simple_light_task_delegate.cc | 22 +-- .../render/hydra/simple_light_task_delegate.h | 10 +- .../blender/render/hydra/viewport_engine.cc | 70 +++++----- source/blender/render/hydra/viewport_engine.h | 8 +- 20 files changed, 306 insertions(+), 303 deletions(-) diff --git a/source/blender/render/hydra/engine.cc b/source/blender/render/hydra/engine.cc index b86871b6d9ea..c5ad682883d3 100644 --- a/source/blender/render/hydra/engine.cc +++ b/source/blender/render/hydra/engine.cc @@ -14,12 +14,12 @@ namespace blender::render::hydra { -Engine::Engine(RenderEngine *bl_engine, const std::string &delegateId) : bl_engine(bl_engine) +Engine::Engine(RenderEngine *bl_engine, const std::string &delegate_id) : bl_engine(bl_engine) { pxr::HdRendererPluginRegistry ®istry = pxr::HdRendererPluginRegistry::GetInstance(); pxr::TF_PY_ALLOW_THREADS_IN_SCOPE(); - render_delegate = registry.CreateRenderDelegate(pxr::TfToken(delegateId)); + render_delegate = registry.CreateRenderDelegate(pxr::TfToken(delegate_id)); pxr::HdDriverVector hd_drivers; if (bl_engine->type->flag & RE_USE_GPU_CONTEXT) { diff --git a/source/blender/render/hydra/engine.h b/source/blender/render/hydra/engine.h index 879fdc097d02..79b55e11d372 100644 --- a/source/blender/render/hydra/engine.h +++ b/source/blender/render/hydra/engine.h @@ -28,7 +28,7 @@ class Engine { virtual void sync(Depsgraph *depsgraph, bContext *context, - pxr::HdRenderSettingsMap &renderSettings) = 0; + pxr::HdRenderSettingsMap &render_settings) = 0; virtual void render(Depsgraph *depsgraph) = 0; protected: diff --git a/source/blender/render/hydra/final_engine.cc b/source/blender/render/hydra/final_engine.cc index 7951e5172c57..2150169fa627 100644 --- a/source/blender/render/hydra/final_engine.cc +++ b/source/blender/render/hydra/final_engine.cc @@ -16,15 +16,15 @@ namespace blender::render::hydra { void FinalEngine::sync(Depsgraph *depsgraph, bContext *context, - pxr::HdRenderSettingsMap &renderSettings) + pxr::HdRenderSettingsMap &render_settings) { scene_delegate = std::make_unique( render_index.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"), - BlenderSceneDelegate::EngineType::Final); + BlenderSceneDelegate::EngineType::FINAL); scene_delegate->populate(depsgraph, context); - for (auto const &setting : renderSettings) { + for (auto const &setting : render_settings) { render_delegate->SetRenderSetting(setting.first, setting.second); } } @@ -52,28 +52,28 @@ void FinalEngine::render(Depsgraph *depsgraph) CameraData(scene->camera, image_res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(border); free_camera_delegate->SetCamera(camera); - render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(), - pxr::GfVec4d(0, 0, res[0], res[1])); - render_task_delegate->SetRendererAov(pxr::HdAovTokens->color); + render_task_delegate->set_camera_and_viewport(free_camera_delegate->GetCameraId(), + pxr::GfVec4d(0, 0, res[0], res[1])); + render_task_delegate->set_renderer_aov(pxr::HdAovTokens->color); if (simple_light_task_delegate) { - simple_light_task_delegate->SetCameraPath(free_camera_delegate->GetCameraId()); + simple_light_task_delegate->set_camera_path(free_camera_delegate->GetCameraId()); } pxr::HdTaskSharedPtrVector tasks; if (simple_light_task_delegate) { - tasks.push_back(simple_light_task_delegate->GetTask()); + tasks.push_back(simple_light_task_delegate->get_task()); } - tasks.push_back(render_task_delegate->GetTask()); + tasks.push_back(render_task_delegate->get_task()); - std::chrono::time_point timeBegin = std::chrono::steady_clock::now(), - timeCurrent; - std::chrono::milliseconds elapsedTime; + std::chrono::time_point time_begin = std::chrono::steady_clock::now(), + time_current; + std::chrono::milliseconds elapsed_time; - float percentDone = 0.0; + float percent_done = 0.0; - std::map> renderImages{ + std::map> render_images{ {"Combined", std::vector(res[0] * res[1] * 4)}}; // 4 - number of channels - std::vector &pixels = renderImages["Combined"]; + std::vector &pixels = render_images["Combined"]; { // Release the GIL before calling into hydra, in case any hydra plugins call into python. @@ -86,25 +86,26 @@ void FinalEngine::render(Depsgraph *depsgraph) break; } - percentDone = renderer_percent_done(); - timeCurrent = std::chrono::steady_clock::now(); - elapsedTime = std::chrono::duration_cast(timeCurrent - timeBegin); + percent_done = renderer_percent_done(); + time_current = std::chrono::steady_clock::now(); + elapsed_time = std::chrono::duration_cast(time_current - + time_begin); - notify_status(percentDone / 100.0, + notify_status(percent_done / 100.0, scene_name + ": " + layer_name, - "Render Time: " + format_duration(elapsedTime) + - " | Done: " + std::to_string(int(percentDone)) + "%"); + "Render Time: " + format_duration(elapsed_time) + + " | Done: " + std::to_string(int(percent_done)) + "%"); - if (render_task_delegate->IsConverged()) { + if (render_task_delegate->is_converged()) { break; } - render_task_delegate->GetRendererAovData(pxr::HdAovTokens->color, pixels.data()); - updateRenderResult(renderImages, layer_name, res[0], res[1]); + render_task_delegate->get_renderer_aov_data(pxr::HdAovTokens->color, pixels.data()); + update_render_result(render_images, layer_name, res[0], res[1]); } - render_task_delegate->GetRendererAovData(pxr::HdAovTokens->color, pixels.data()); - updateRenderResult(renderImages, layer_name, res[0], res[1]); + render_task_delegate->get_renderer_aov_data(pxr::HdAovTokens->color, pixels.data()); + update_render_result(render_images, layer_name, res[0], res[1]); } pxr::GfVec2i FinalEngine::get_resolution(Scene *scene) @@ -119,19 +120,19 @@ pxr::GfVec2i FinalEngine::get_resolution(Scene *scene) int(r.ysch * border_h * r.size / 100)); } -void FinalEngine::updateRenderResult(std::map> &renderImages, - const std::string &layerName, - int width, - int height) +void FinalEngine::update_render_result(std::map> &render_images, + const std::string &layer_name, + int width, + int height) { RenderResult *result = RE_engine_begin_result( - bl_engine, 0, 0, width, height, layerName.c_str(), nullptr); + bl_engine, 0, 0, width, height, layer_name.c_str(), nullptr); /* TODO: only for the first render layer */ RenderLayer *layer = (RenderLayer *)result->layers.first; for (RenderPass *pass = (RenderPass *)layer->passes.first; pass != nullptr; pass = pass->next) { - auto it_image = renderImages.find(pass->name); - if (it_image == renderImages.end()) { + auto it_image = render_images.find(pass->name); + if (it_image == render_images.end()) { continue; } memcpy(pass->rect, @@ -171,10 +172,10 @@ void FinalEngineGL::render(Depsgraph *depsgraph) CameraData(scene->camera, image_res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(border); free_camera_delegate->SetCamera(camera); - render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(), - pxr::GfVec4d(0, 0, res[0], res[1])); + render_task_delegate->set_camera_and_viewport(free_camera_delegate->GetCameraId(), + pxr::GfVec4d(0, 0, res[0], res[1])); if (simple_light_task_delegate) { - simple_light_task_delegate->SetCameraPath(free_camera_delegate->GetCameraId()); + simple_light_task_delegate->set_camera_path(free_camera_delegate->GetCameraId()); } pxr::HdTaskSharedPtrVector tasks; @@ -182,30 +183,30 @@ void FinalEngineGL::render(Depsgraph *depsgraph) /* TODO: Uncomment this and fix GL error: invalid operation, reported from void __cdecl pxrInternal_v0_22__pxrReserved__::HgiGLResourceBindings::BindResources(void) */ - // tasks.push_back(simple_light_task_delegate->GetTask()); + // tasks.push_back(simple_light_task_delegate->get_task()); } - tasks.push_back(render_task_delegate->GetTask()); + tasks.push_back(render_task_delegate->get_task()); - std::chrono::time_point timeBegin = std::chrono::steady_clock::now(), - timeCurrent; - std::chrono::milliseconds elapsedTime; + std::chrono::time_point time_begin = std::chrono::steady_clock::now(), + time_current; + std::chrono::milliseconds elapsed_time; - float percentDone = 0.0; + float percent_done = 0.0; - std::map> renderImages{ + std::map> render_images{ {"Combined", std::vector(res[0] * res[1] * 4)}}; // 4 - number of channels - std::vector &pixels = renderImages["Combined"]; + std::vector &pixels = render_images["Combined"]; - GLuint FramebufferName = 0; - glGenFramebuffers(1, &FramebufferName); - glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName); + GLuint framebuffer_name = 0; + glGenFramebuffers(1, &framebuffer_name); + glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_name); // The texture we're going to render to - GLuint renderedTexture; - glGenTextures(1, &renderedTexture); + GLuint rendered_texture; + glGenTextures(1, &rendered_texture); // "Bind" the newly created texture : all future texture functions will modify this texture - glBindTexture(GL_TEXTURE_2D, renderedTexture); + glBindTexture(GL_TEXTURE_2D, rendered_texture); // Give an empty image to OpenGL ( the last "0" ) glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, res[0], res[1], 0, GL_RGBA, GL_FLOAT, 0); @@ -214,13 +215,13 @@ void FinalEngineGL::render(Depsgraph *depsgraph) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - // Set "renderedTexture" as our colour attachement #0 - glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, renderedTexture, 0); + // Set "rendered_texture" as our colour attachement #0 + glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, rendered_texture, 0); // Generate vertex array - GLuint VAO; - glGenVertexArrays(1, &VAO); - glBindVertexArray(VAO); + GLuint vao; + glGenVertexArrays(1, &vao); + glBindVertexArray(vao); { // Release the GIL before calling into hydra, in case any hydra plugins call into python. @@ -233,25 +234,26 @@ void FinalEngineGL::render(Depsgraph *depsgraph) break; } - percentDone = renderer_percent_done(); - timeCurrent = std::chrono::steady_clock::now(); - elapsedTime = std::chrono::duration_cast(timeCurrent - timeBegin); + percent_done = renderer_percent_done(); + time_current = std::chrono::steady_clock::now(); + elapsed_time = std::chrono::duration_cast(time_current - + time_begin); - notify_status(percentDone / 100.0, + notify_status(percent_done / 100.0, scene_name + ": " + layer_name, - "Render Time: " + format_duration(elapsedTime) + - " | Done: " + std::to_string(int(percentDone)) + "%"); + "Render Time: " + format_duration(elapsed_time) + + " | Done: " + std::to_string(int(percent_done)) + "%"); - if (render_task_delegate->IsConverged()) { + if (render_task_delegate->is_converged()) { break; } glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, pixels.data()); - updateRenderResult(renderImages, layer_name, res[0], res[1]); + update_render_result(render_images, layer_name, res[0], res[1]); } glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, pixels.data()); - updateRenderResult(renderImages, layer_name, res[0], res[1]); + update_render_result(render_images, layer_name, res[0], res[1]); } } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/final_engine.h b/source/blender/render/hydra/final_engine.h index a4345d0f9148..28c1cf6c7cec 100644 --- a/source/blender/render/hydra/final_engine.h +++ b/source/blender/render/hydra/final_engine.h @@ -14,19 +14,19 @@ class FinalEngine : public Engine { using Engine::Engine; virtual void sync(Depsgraph *depsgraph, bContext *context, - pxr::HdRenderSettingsMap &renderSettings) override; + pxr::HdRenderSettingsMap &render_settings) override; virtual void render(Depsgraph *b_depsgraph) override; protected: pxr::GfVec2i get_resolution(Scene *scene); - void updateRenderResult(std::map> &render_images, - const std::string &layerName, - int width, - int height); + void update_render_result(std::map> &render_images, + const std::string &layer_name, + int width, + int height); void notify_status(float progress, const std::string &title, const std::string &info); protected: - pxr::HdRenderSettingsMap renderSettings; + pxr::HdRenderSettingsMap render_settings; }; class FinalEngineGL : public FinalEngine { diff --git a/source/blender/render/hydra/preview_engine.cc b/source/blender/render/hydra/preview_engine.cc index 304bae29017f..d135da4ce785 100644 --- a/source/blender/render/hydra/preview_engine.cc +++ b/source/blender/render/hydra/preview_engine.cc @@ -10,15 +10,15 @@ namespace blender::render::hydra { void PreviewEngine::sync(Depsgraph *depsgraph, bContext *context, - pxr::HdRenderSettingsMap &renderSettings) + pxr::HdRenderSettingsMap &render_settings) { scene_delegate = std::make_unique( render_index.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"), - BlenderSceneDelegate::EngineType::Preview); + BlenderSceneDelegate::EngineType::PREVIEW); scene_delegate->populate(depsgraph, context); - for (auto const &setting : renderSettings) { + for (auto const &setting : render_settings) { render_delegate->SetRenderSetting(setting.first, setting.second); } } @@ -28,22 +28,22 @@ void PreviewEngine::render(Depsgraph *depsgraph) Scene *scene = DEG_get_input_scene(depsgraph); ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph); - std::string layerName = view_layer->name; + std::string layer_name = view_layer->name; pxr::GfVec2i res(scene->r.xsch, scene->r.ysch); pxr::GfCamera camera = CameraData(scene->camera, res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(pxr::GfVec4f(0, 0, 1, 1)); free_camera_delegate->SetCamera(camera); - render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(), - pxr::GfVec4d(0, 0, res[0], res[1])); - render_task_delegate->SetRendererAov(pxr::HdAovTokens->color); + render_task_delegate->set_camera_and_viewport(free_camera_delegate->GetCameraId(), + pxr::GfVec4d(0, 0, res[0], res[1])); + render_task_delegate->set_renderer_aov(pxr::HdAovTokens->color); pxr::HdTaskSharedPtrVector tasks; if (simple_light_task_delegate) { - tasks.push_back(simple_light_task_delegate->GetTask()); + tasks.push_back(simple_light_task_delegate->get_task()); } - tasks.push_back(render_task_delegate->GetTask()); + tasks.push_back(render_task_delegate->get_task()); std::vector pixels = std::vector(res[0] * res[1] * 4); // 4 - number of channels @@ -58,25 +58,25 @@ void PreviewEngine::render(Depsgraph *depsgraph) break; } - if (render_task_delegate->IsConverged()) { + if (render_task_delegate->is_converged()) { break; } - render_task_delegate->GetRendererAovData(pxr::HdAovTokens->color, pixels.data()); - updateRenderResult(layerName, res[0], res[1], pixels); + render_task_delegate->get_renderer_aov_data(pxr::HdAovTokens->color, pixels.data()); + update_render_result(layer_name, res[0], res[1], pixels); } - render_task_delegate->GetRendererAovData(pxr::HdAovTokens->color, pixels.data()); - updateRenderResult(layerName, res[0], res[1], pixels); + render_task_delegate->get_renderer_aov_data(pxr::HdAovTokens->color, pixels.data()); + update_render_result(layer_name, res[0], res[1], pixels); } -void PreviewEngine::updateRenderResult(const std::string &layerName, - int width, - int height, - std::vector &pixels) +void PreviewEngine::update_render_result(const std::string &layer_name, + int width, + int height, + std::vector &pixels) { RenderResult *result = RE_engine_begin_result( - bl_engine, 0, 0, width, height, layerName.c_str(), nullptr); + bl_engine, 0, 0, width, height, layer_name.c_str(), nullptr); RenderLayer *layer = (RenderLayer *)result->layers.first; RenderPass *pass = (RenderPass *)layer->passes.first; diff --git a/source/blender/render/hydra/preview_engine.h b/source/blender/render/hydra/preview_engine.h index 4fcf5ec8cf5b..a0b38b1d0653 100644 --- a/source/blender/render/hydra/preview_engine.h +++ b/source/blender/render/hydra/preview_engine.h @@ -12,17 +12,17 @@ class PreviewEngine : public FinalEngine { using FinalEngine::FinalEngine; void sync(Depsgraph *depsgraph, bContext *context, - pxr::HdRenderSettingsMap &renderSettings) override; + pxr::HdRenderSettingsMap &render_settings) override; void render(Depsgraph *depsgraph) override; protected: - void updateRenderResult(const std::string &layerName, - int width, - int height, - std::vector &pixels); + void update_render_result(const std::string &layer_name, + int width, + int height, + std::vector &pixels); protected: - pxr::HdRenderSettingsMap renderSettings; + pxr::HdRenderSettingsMap render_settings; }; } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/python.cc b/source/blender/render/hydra/python.cc index eb3334d4d788..157edf200fc8 100644 --- a/source/blender/render/hydra/python.cc +++ b/source/blender/render/hydra/python.cc @@ -135,8 +135,8 @@ static PyObject *engine_create_func(PyObject * /*self*/, PyObject *args) LOG(INFO) << "create_func"; PyObject *pyengine; - char *engineType, *render_delegate_id; - if (!PyArg_ParseTuple(args, "Oss", &pyengine, &engineType, &render_delegate_id)) { + char *engine_type, *render_delegate_id; + if (!PyArg_ParseTuple(args, "Oss", &pyengine, &engine_type, &render_delegate_id)) { Py_RETURN_NONE; } @@ -144,10 +144,10 @@ static PyObject *engine_create_func(PyObject * /*self*/, PyObject *args) Engine *engine; - if (std::string(engineType) == "VIEWPORT") { + if (std::string(engine_type) == "VIEWPORT") { engine = new ViewportEngine(bl_engine, render_delegate_id); } - else if (std::string(engineType) == "PREVIEW") { + else if (std::string(engine_type) == "PREVIEW") { engine = new PreviewEngine(bl_engine, render_delegate_id); } else { diff --git a/source/blender/render/hydra/render_task_delegate.cc b/source/blender/render/hydra/render_task_delegate.cc index 9b9ac47f6b1d..989613cdb5e1 100644 --- a/source/blender/render/hydra/render_task_delegate.cc +++ b/source/blender/render/hydra/render_task_delegate.cc @@ -13,27 +13,27 @@ namespace blender::render::hydra { -RenderTaskDelegate::RenderTaskDelegate(pxr::HdRenderIndex *parentIndex, - pxr::SdfPath const &delegateID) - : pxr::HdSceneDelegate(parentIndex, delegateID) +RenderTaskDelegate::RenderTaskDelegate(pxr::HdRenderIndex *parent_index, + pxr::SdfPath const &delegate_id) + : pxr::HdSceneDelegate(parent_index, delegate_id) { - pxr::SdfPath renderTaskId = GetTaskID(); - GetRenderIndex().InsertTask(this, renderTaskId); - GetRenderIndex().GetChangeTracker().MarkTaskDirty(renderTaskId, + pxr::SdfPath render_task_id = get_task_id(); + GetRenderIndex().InsertTask(this, render_task_id); + GetRenderIndex().GetChangeTracker().MarkTaskDirty(render_task_id, pxr::HdChangeTracker::DirtyCollection); - GetRenderIndex().GetChangeTracker().MarkTaskDirty(renderTaskId, + GetRenderIndex().GetChangeTracker().MarkTaskDirty(render_task_id, pxr::HdChangeTracker::DirtyRenderTags); - taskParams.enableLighting = true; - taskParams.alphaThreshold = 0.1f; + task_params.enableLighting = true; + task_params.alphaThreshold = 0.1f; } -pxr::SdfPath RenderTaskDelegate::GetTaskID() const +pxr::SdfPath RenderTaskDelegate::get_task_id() const { return GetDelegateID().AppendElementString("task"); } -pxr::SdfPath RenderTaskDelegate::GetAovID(pxr::TfToken const &aov) const +pxr::SdfPath RenderTaskDelegate::get_aov_id(pxr::TfToken const &aov) const { return GetDelegateID().AppendElementString("aov_" + aov.GetString()); } @@ -42,15 +42,15 @@ pxr::VtValue RenderTaskDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const { LOG(INFO) << "RenderTaskDelegate::Get - " << id.GetAsString() << " " << key.GetString() << "\n"; if (key == pxr::HdTokens->params) { - return pxr::VtValue(taskParams); + return pxr::VtValue(task_params); } if (key == pxr::HdTokens->collection) { - pxr::HdRprimCollection rprimCollection(pxr::HdTokens->geometry, - pxr::HdReprSelector(pxr::HdReprTokens->smoothHull), - false, - pxr::TfToken()); - rprimCollection.SetRootPath(pxr::SdfPath::AbsoluteRootPath()); - return pxr::VtValue(rprimCollection); + pxr::HdRprimCollection rprim_collection(pxr::HdTokens->geometry, + pxr::HdReprSelector(pxr::HdReprTokens->smoothHull), + false, + pxr::TfToken()); + rprim_collection.SetRootPath(pxr::SdfPath::AbsoluteRootPath()); + return pxr::VtValue(rprim_collection); } return pxr::VtValue(); } @@ -58,81 +58,81 @@ pxr::VtValue RenderTaskDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const pxr::HdRenderBufferDescriptor RenderTaskDelegate::GetRenderBufferDescriptor(pxr::SdfPath const &id) { LOG(INFO) << "RenderTaskDelegate::GetRenderBufferDescriptor - " << id.GetAsString() << "\n"; - return bufferDescriptors[id]; + return buffer_descriptors[id]; } -pxr::TfTokenVector RenderTaskDelegate::GetTaskRenderTags(pxr::SdfPath const &taskId) +pxr::TfTokenVector RenderTaskDelegate::GetTaskRenderTags(pxr::SdfPath const &task_id) { - LOG(INFO) << "RenderTaskDelegate::GetTaskRenderTags - " << taskId.GetAsString() << "\n"; + LOG(INFO) << "RenderTaskDelegate::GetTaskRenderTags - " << task_id.GetAsString() << "\n"; return {pxr::HdRenderTagTokens->geometry}; } -bool RenderTaskDelegate::IsConverged() +bool RenderTaskDelegate::is_converged() { - pxr::HdTaskSharedPtr renderTask = GetRenderIndex().GetTask(GetTaskID()); + pxr::HdTaskSharedPtr renderTask = GetRenderIndex().GetTask(get_task_id()); return ((pxr::HdxRenderTask &)*renderTask).IsConverged(); } -void RenderTaskDelegate::SetRendererAov(pxr::TfToken const &aov) +void RenderTaskDelegate::set_renderer_aov(pxr::TfToken const &aov) { - pxr::HdAovDescriptor aovDesc = GetRenderIndex().GetRenderDelegate()->GetDefaultAovDescriptor( + pxr::HdAovDescriptor aov_desc = GetRenderIndex().GetRenderDelegate()->GetDefaultAovDescriptor( aov); pxr::HdRenderBufferDescriptor desc( - pxr::GfVec3i(taskParams.viewport[2], taskParams.viewport[3], 1), - aovDesc.format, - aovDesc.multiSampled); - pxr::SdfPath bufferId = GetAovID(aov); + pxr::GfVec3i(task_params.viewport[2], task_params.viewport[3], 1), + aov_desc.format, + aov_desc.multiSampled); + pxr::SdfPath buffer_id = get_aov_id(aov); - if (bufferDescriptors.find(bufferId) == bufferDescriptors.end()) { - GetRenderIndex().InsertBprim(pxr::HdPrimTypeTokens->renderBuffer, this, bufferId); - bufferDescriptors[bufferId] = desc; - GetRenderIndex().GetChangeTracker().MarkBprimDirty(bufferId, + if (buffer_descriptors.find(buffer_id) == buffer_descriptors.end()) { + GetRenderIndex().InsertBprim(pxr::HdPrimTypeTokens->renderBuffer, this, buffer_id); + buffer_descriptors[buffer_id] = desc; + GetRenderIndex().GetChangeTracker().MarkBprimDirty(buffer_id, pxr::HdRenderBuffer::DirtyDescription); pxr::HdRenderPassAovBinding binding; binding.aovName = aov; - binding.renderBufferId = bufferId; - binding.aovSettings = aovDesc.aovSettings; - taskParams.aovBindings.push_back(binding); + binding.renderBufferId = buffer_id; + binding.aovSettings = aov_desc.aovSettings; + task_params.aovBindings.push_back(binding); - GetRenderIndex().GetChangeTracker().MarkTaskDirty(GetTaskID(), + GetRenderIndex().GetChangeTracker().MarkTaskDirty(get_task_id(), pxr::HdChangeTracker::DirtyParams); } - else if (bufferDescriptors[bufferId] != desc) { - bufferDescriptors[bufferId] = desc; - GetRenderIndex().GetChangeTracker().MarkBprimDirty(bufferId, + else if (buffer_descriptors[buffer_id] != desc) { + buffer_descriptors[buffer_id] = desc; + GetRenderIndex().GetChangeTracker().MarkBprimDirty(buffer_id, pxr::HdRenderBuffer::DirtyDescription); } } -pxr::HdRenderBuffer *RenderTaskDelegate::GetRendererAov(pxr::TfToken const &aov) +pxr::HdRenderBuffer *RenderTaskDelegate::get_renderer_aov(pxr::TfToken const &aov) { return (pxr::HdRenderBuffer *)(GetRenderIndex().GetBprim(pxr::HdPrimTypeTokens->renderBuffer, - GetAovID(aov))); + get_aov_id(aov))); } -void RenderTaskDelegate::GetRendererAovData(pxr::TfToken const &aov, void *data) +void RenderTaskDelegate::get_renderer_aov_data(pxr::TfToken const &aov, void *data) { - pxr::HdRenderBuffer *buffer = GetRendererAov(aov); - void *bufData = buffer->Map(); + pxr::HdRenderBuffer *buffer = get_renderer_aov(aov); + void *buf_data = buffer->Map(); memcpy(data, - bufData, + buf_data, buffer->GetWidth() * buffer->GetHeight() * pxr::HdDataSizeOfFormat(buffer->GetFormat())); buffer->Unmap(); } -pxr::HdTaskSharedPtr RenderTaskDelegate::GetTask() +pxr::HdTaskSharedPtr RenderTaskDelegate::get_task() { - return GetRenderIndex().GetTask(GetTaskID()); + return GetRenderIndex().GetTask(get_task_id()); } -void RenderTaskDelegate::SetCameraAndViewport(pxr::SdfPath const &cameraId, - pxr::GfVec4d const &viewport) +void RenderTaskDelegate::set_camera_and_viewport(pxr::SdfPath const &camera_id, + pxr::GfVec4d const &viewport) { - if (taskParams.viewport != viewport || taskParams.camera != cameraId) { - taskParams.viewport = viewport; - taskParams.camera = cameraId; - GetRenderIndex().GetChangeTracker().MarkTaskDirty(GetTaskID(), + if (task_params.viewport != viewport || task_params.camera != camera_id) { + task_params.viewport = viewport; + task_params.camera = camera_id; + GetRenderIndex().GetChangeTracker().MarkTaskDirty(get_task_id(), pxr::HdChangeTracker::DirtyParams); } } diff --git a/source/blender/render/hydra/render_task_delegate.h b/source/blender/render/hydra/render_task_delegate.h index 42965648c90a..f7119fc83e2a 100644 --- a/source/blender/render/hydra/render_task_delegate.h +++ b/source/blender/render/hydra/render_task_delegate.h @@ -10,28 +10,28 @@ namespace blender::render::hydra { class RenderTaskDelegate : public pxr::HdSceneDelegate { public: - RenderTaskDelegate(pxr::HdRenderIndex *parentIndex, pxr::SdfPath const &delegateID); + RenderTaskDelegate(pxr::HdRenderIndex *parent_index, pxr::SdfPath const &delegate_id); ~RenderTaskDelegate() override = default; - pxr::SdfPath GetTaskID() const; - pxr::SdfPath GetAovID(pxr::TfToken const &aov) const; + pxr::SdfPath get_task_id() const; + pxr::SdfPath get_aov_id(pxr::TfToken const &aov) const; pxr::VtValue Get(pxr::SdfPath const &id, pxr::TfToken const &key) override; pxr::HdRenderBufferDescriptor GetRenderBufferDescriptor(pxr::SdfPath const &id) override; pxr::TfTokenVector GetTaskRenderTags(pxr::SdfPath const &taskId) override; - bool IsConverged(); - void SetRendererAov(pxr::TfToken const &aovId); - pxr::HdRenderBuffer *GetRendererAov(pxr::TfToken const &id); - void GetRendererAovData(pxr::TfToken const &id, void *buf); + bool is_converged(); + void set_renderer_aov(pxr::TfToken const &aovId); + pxr::HdRenderBuffer *get_renderer_aov(pxr::TfToken const &id); + void get_renderer_aov_data(pxr::TfToken const &id, void *buf); - pxr::HdTaskSharedPtr GetTask(); - void SetCameraAndViewport(pxr::SdfPath const &cameraId, pxr::GfVec4d const &viewport); + pxr::HdTaskSharedPtr get_task(); + void set_camera_and_viewport(pxr::SdfPath const &cameraId, pxr::GfVec4d const &viewport); private: - pxr::HdxRenderTaskParams taskParams; + pxr::HdxRenderTaskParams task_params; pxr::TfHashMap - bufferDescriptors; + buffer_descriptors; }; } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc index 7dfd5919584a..a8b7137d1465 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -10,10 +10,10 @@ namespace blender::render::hydra { -BlenderSceneDelegate::BlenderSceneDelegate(pxr::HdRenderIndex *parentIndex, - pxr::SdfPath const &delegateID, +BlenderSceneDelegate::BlenderSceneDelegate(pxr::HdRenderIndex *parent_index, + pxr::SdfPath const &delegate_id, BlenderSceneDelegate::EngineType engine_type) - : HdSceneDelegate(parentIndex, delegateID), + : HdSceneDelegate(parent_index, delegate_id), engine_type(engine_type), depsgraph(nullptr), context(nullptr), @@ -79,67 +79,68 @@ bool BlenderSceneDelegate::GetVisible(pxr::SdfPath const &id) return object_data(id)->visible; } -pxr::SdfPath BlenderSceneDelegate::GetInstancerId(pxr::SdfPath const &primId) +pxr::SdfPath BlenderSceneDelegate::GetInstancerId(pxr::SdfPath const &prim_id) { - LOG(INFO) << "GetInstancerId: " << primId.GetAsString(); - MeshData *m_data = mesh_data(primId); + LOG(INFO) << "GetInstancerId: " << prim_id.GetAsString(); + MeshData *m_data = mesh_data(prim_id); if (m_data) { return m_data->instancer_id; } return pxr::SdfPath(); } -pxr::SdfPathVector BlenderSceneDelegate::GetInstancerPrototypes(pxr::SdfPath const &instancerId) +pxr::SdfPathVector BlenderSceneDelegate::GetInstancerPrototypes(pxr::SdfPath const &instancer_id) { - LOG(INFO) << "GetInstancerPrototypes: " << instancerId.GetString(); + LOG(INFO) << "GetInstancerPrototypes: " << instancer_id.GetString(); pxr::SdfPathVector paths; - paths.push_back(instancerId.GetParentPath()); + paths.push_back(instancer_id.GetParentPath()); return paths; } -pxr::VtIntArray BlenderSceneDelegate::GetInstanceIndices(pxr::SdfPath const &instancerId, - pxr::SdfPath const &prototypeId) +pxr::VtIntArray BlenderSceneDelegate::GetInstanceIndices(pxr::SdfPath const &instancer_id, + pxr::SdfPath const &prototype_id) { - LOG(INFO) << "GetInstanceIndices: " << instancerId.GetString() << " " << prototypeId.GetString(); - MeshData *m_data = mesh_data(prototypeId); + LOG(INFO) << "GetInstanceIndices: " << instancer_id.GetString() << " " + << prototype_id.GetString(); + MeshData *m_data = mesh_data(prototype_id); pxr::VtIntArray ret = m_data->instance_indices(); return ret; } -pxr::GfMatrix4d BlenderSceneDelegate::GetInstancerTransform(pxr::SdfPath const &instancerId) +pxr::GfMatrix4d BlenderSceneDelegate::get_instancer_transform(pxr::SdfPath const &instancer_id) { - LOG(INFO) << "GetInstancerTransform: " << instancerId.GetString(); + LOG(INFO) << "get_instancer_transform: " << instancer_id.GetString(); // TODO: add a separate object for instancer for cleaner handling code // Actual instancer transform is get here return pxr::GfMatrix4d(1.0); } -size_t BlenderSceneDelegate::SampleInstancerTransform(pxr::SdfPath const &instancerId, - size_t maxSampleCount, - float *sampleTimes, - pxr::GfMatrix4d *sampleValues) +size_t BlenderSceneDelegate::SampleInstancerTransform(pxr::SdfPath const &instancer_id, + size_t max_sample_count, + float *sample_times, + pxr::GfMatrix4d *sample_values) { - LOG(INFO) << "SampleInstancerTransform: " << instancerId.GetString(); + LOG(INFO) << "SampleInstancerTransform: " << instancer_id.GetString(); size_t ret = 0; - MeshData *m_data = mesh_data(instancerId.GetParentPath()); - ret = m_data->sample_instancer_transform(maxSampleCount, sampleTimes, sampleValues); + MeshData *m_data = mesh_data(instancer_id.GetParentPath()); + ret = m_data->sample_instancer_transform(max_sample_count, sample_times, sample_values); return ret; } size_t BlenderSceneDelegate::SamplePrimvar(pxr::SdfPath const &id, pxr::TfToken const &key, - size_t maxSampleCount, - float *sampleTimes, - pxr::VtValue *sampleValues) + size_t max_sample_count, + float *sample_times, + pxr::VtValue *sample_values) { // TODO: add a separate object for instancer for cleaner handling code if (id.GetName() == "Instancer") { MeshData *m_data = mesh_data(id.GetParentPath()); if (m_data) { - return m_data->sample_instancer_primvar(key, maxSampleCount, sampleTimes, sampleValues); + return m_data->sample_instancer_primvar(key, max_sample_count, sample_times, sample_values); } } - return HdSceneDelegate::SamplePrimvar(id, key, maxSampleCount, sampleTimes, sampleValues); + return HdSceneDelegate::SamplePrimvar(id, key, max_sample_count, sample_times, sample_values); } void BlenderSceneDelegate::update_collection(bool remove, bool visibility) @@ -432,9 +433,9 @@ pxr::HdPrimvarDescriptorVector BlenderSceneDelegate::GetPrimvarDescriptors( return primvars; } -pxr::SdfPath BlenderSceneDelegate::GetMaterialId(pxr::SdfPath const &rprimId) +pxr::SdfPath BlenderSceneDelegate::GetMaterialId(pxr::SdfPath const &rprim_id) { - return mesh_data(rprimId)->material_id; + return mesh_data(rprim_id)->material_id; } pxr::VtValue BlenderSceneDelegate::GetMaterialResource(pxr::SdfPath const &id) diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h index 67b3e024296c..3f9d534243b5 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h @@ -17,10 +17,10 @@ namespace blender::render::hydra { class BlenderSceneDelegate : public pxr::HdSceneDelegate { public: - enum class EngineType { Viewport = 1, Final, Preview }; + enum class EngineType { VIEWPORT = 1, FINAL, PREVIEW }; BlenderSceneDelegate(pxr::HdRenderIndex *render_index, - pxr::SdfPath const &delegateId, + pxr::SdfPath const &delegate_id, BlenderSceneDelegate::EngineType engine_type); ~BlenderSceneDelegate() override = default; @@ -33,23 +33,23 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate { pxr::VtValue GetLightParamValue(pxr::SdfPath const &id, pxr::TfToken const &key) override; pxr::HdPrimvarDescriptorVector GetPrimvarDescriptors( pxr::SdfPath const &id, pxr::HdInterpolation interpolation) override; - pxr::SdfPath GetMaterialId(pxr::SdfPath const &rprimId) override; - pxr::VtValue GetMaterialResource(pxr::SdfPath const &materialId) override; + pxr::SdfPath GetMaterialId(pxr::SdfPath const &rprim_id) override; + pxr::VtValue GetMaterialResource(pxr::SdfPath const &material_id) override; bool GetVisible(pxr::SdfPath const &id) override; - pxr::SdfPath GetInstancerId(pxr::SdfPath const &primId) override; - pxr::SdfPathVector GetInstancerPrototypes(pxr::SdfPath const &instancerId) override; - pxr::VtIntArray GetInstanceIndices(pxr::SdfPath const &instancerId, - pxr::SdfPath const &prototypeId) override; - pxr::GfMatrix4d GetInstancerTransform(pxr::SdfPath const &instancerId); - size_t SampleInstancerTransform(pxr::SdfPath const &instancerId, - size_t maxSampleCount, - float *sampleTimes, - pxr::GfMatrix4d *sampleValues) override; + pxr::SdfPath GetInstancerId(pxr::SdfPath const &prim_id) override; + pxr::SdfPathVector GetInstancerPrototypes(pxr::SdfPath const &instancer_id) override; + pxr::VtIntArray GetInstanceIndices(pxr::SdfPath const &instancer_id, + pxr::SdfPath const &prototype_id) override; + pxr::GfMatrix4d get_instancer_transform(pxr::SdfPath const &instancer_id); + size_t SampleInstancerTransform(pxr::SdfPath const &instancer_id, + size_t max_sample_count, + float *sample_times, + pxr::GfMatrix4d *sample_values) override; size_t SamplePrimvar(pxr::SdfPath const &id, pxr::TfToken const &key, - size_t maxSampleCount, - float *sampleTimes, - pxr::VtValue *sampleValues) override; + size_t max_sample_count, + float *sample_times, + pxr::VtValue *sample_values) override; EngineType engine_type; diff --git a/source/blender/render/hydra/scene_delegate/light.cc b/source/blender/render/hydra/scene_delegate/light.cc index f328745506c5..f52c6450dd87 100644 --- a/source/blender/render/hydra/scene_delegate/light.cc +++ b/source/blender/render/hydra/scene_delegate/light.cc @@ -23,7 +23,7 @@ LightData::LightData(BlenderSceneDelegate *scene_delegate, Object *object) Light *light = (Light *)((Object *)id)->data; data[pxr::HdLightTokens->intensity] = scene_delegate->engine_type == - BlenderSceneDelegate::EngineType::Preview ? + BlenderSceneDelegate::EngineType::PREVIEW ? light->energy / 1000 : light->energy; diff --git a/source/blender/render/hydra/scene_delegate/mesh.cc b/source/blender/render/hydra/scene_delegate/mesh.cc index 90b63b0f8076..eff60319097f 100644 --- a/source/blender/render/hydra/scene_delegate/mesh.cc +++ b/source/blender/render/hydra/scene_delegate/mesh.cc @@ -110,24 +110,24 @@ pxr::VtIntArray MeshData::instance_indices() return ret; } -size_t MeshData::sample_instancer_transform(size_t maxSampleCount, - float *sampleTimes, - pxr::GfMatrix4d *sampleValues) +size_t MeshData::sample_instancer_transform(size_t max_sample_count, + float *sample_times, + pxr::GfMatrix4d *sample_values) { - *sampleTimes = 0.0f; - *sampleValues = pxr::GfMatrix4d(1.0); + *sample_times = 0.0f; + *sample_values = pxr::GfMatrix4d(1.0); return 1; } size_t MeshData::sample_instancer_primvar(pxr::TfToken const &key, - size_t maxSampleCount, - float *sampleTimes, - pxr::VtValue *sampleValues) + size_t max_sample_count, + float *sample_times, + pxr::VtValue *sample_values) { if (key == pxr::HdInstancerTokens->instanceTransform) { - if (maxSampleCount > 0) { - sampleTimes[0] = 0.0f; - sampleValues[0] = instances; + if (max_sample_count > 0) { + sample_times[0] = 0.0f; + sample_values[0] = instances; return 1; } } diff --git a/source/blender/render/hydra/scene_delegate/mesh.h b/source/blender/render/hydra/scene_delegate/mesh.h index 9836207f1ec1..1338e5e599d7 100644 --- a/source/blender/render/hydra/scene_delegate/mesh.h +++ b/source/blender/render/hydra/scene_delegate/mesh.h @@ -27,13 +27,13 @@ class MeshData : public ObjectData { pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation); pxr::HdPrimvarDescriptorVector instancer_primvar_descriptors(pxr::HdInterpolation interpolation); pxr::VtIntArray instance_indices(); - size_t sample_instancer_transform(size_t maxSampleCount, - float *sampleTimes, - pxr::GfMatrix4d *sampleValues); + size_t sample_instancer_transform(size_t max_sample_count, + float *sample_times, + pxr::GfMatrix4d *sample_values); size_t sample_instancer_primvar(pxr::TfToken const &key, - size_t maxSampleCount, - float *sampleTimes, - pxr::VtValue *sampleValues); + size_t max_sample_count, + float *sample_times, + pxr::VtValue *sample_values); void add_instance(DupliObject *dupli); diff --git a/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.cc b/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.cc index 555f9c42567f..2a7d1e717098 100644 --- a/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.cc +++ b/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.cc @@ -22,29 +22,29 @@ namespace mx = MaterialX; -void HdMtlxConvertToMaterialNetworkMap(std::string const &mtlxPath, - pxr::TfTokenVector const &shaderSourceTypes, - pxr::TfTokenVector const &renderContexts, +void HdMtlxConvertToMaterialNetworkMap(std::string const &mtlx_path, + pxr::TfTokenVector const &shader_source_types, + pxr::TfTokenVector const &render_contexts, pxr::HdMaterialNetworkMap *out) { - if (mtlxPath.empty()) { + if (mtlx_path.empty()) { return; } - std::string basePath = pxr::TfGetPathName(mtlxPath); + std::string basePath = pxr::TfGetPathName(mtlx_path); pxr::ArResolver &resolver = pxr::ArGetResolver(); - const pxr::ArResolverContext context = resolver.CreateDefaultContextForAsset(mtlxPath); + const pxr::ArResolverContext context = resolver.CreateDefaultContextForAsset(mtlx_path); pxr::ArResolverContextBinder binder(context); - pxr::ArResolverScopedCache resolverCache; + pxr::ArResolverScopedCache resolver_cache; - std::string mtlxName = pxr::TfGetBaseName(mtlxPath); - std::string stageId = pxr::TfStringPrintf( + std::string mtlxName = pxr::TfGetBaseName(mtlx_path); + std::string stage_id = pxr::TfStringPrintf( "%s%s%s.usda", basePath.c_str(), ARCH_PATH_SEP, mtlxName.c_str()); - pxr::UsdStageRefPtr stage = pxr::UsdStage::CreateInMemory(stageId, context); + pxr::UsdStageRefPtr stage = pxr::UsdStage::CreateInMemory(stage_id, context); try { - mx::DocumentPtr doc = pxr::UsdMtlxReadDocument(mtlxPath); + mx::DocumentPtr doc = pxr::UsdMtlxReadDocument(mtlx_path); pxr::UsdMtlxRead(doc, stage); } catch (mx::ExceptionFoundCycle &x) { @@ -65,11 +65,11 @@ void HdMtlxConvertToMaterialNetworkMap(std::string const &mtlxPath, if (pxr::UsdPrim materials = stage->GetPrimAtPath(pxr::SdfPath("/MaterialX/Materials"))) { if (pxr::UsdPrimSiblingRange children = materials.GetChildren()) { if (auto material = pxr::UsdShadeMaterial(*children.begin())) { - if (pxr::UsdShadeShader mtlxSurface = material.ComputeSurfaceSource(renderContexts)) { - UsdImagingBuildHdMaterialNetworkFromTerminal(mtlxSurface.GetPrim(), + if (pxr::UsdShadeShader mtlx_surface = material.ComputeSurfaceSource(render_contexts)) { + UsdImagingBuildHdMaterialNetworkFromTerminal(mtlx_surface.GetPrim(), pxr::HdMaterialTerminalTokens->surface, - shaderSourceTypes, - renderContexts, + shader_source_types, + render_contexts, out, pxr::UsdTimeCode::Default()); } diff --git a/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.h b/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.h index 09841d5f84e6..9ffd92895c2b 100644 --- a/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.h +++ b/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.h @@ -10,7 +10,7 @@ struct pxr::HdMaterialNetworkMap; -void HdMtlxConvertToMaterialNetworkMap(std::string const &mtlxPath, - pxr::TfTokenVector const &shaderSourceTypes, - pxr::TfTokenVector const &renderContexts, +void HdMtlxConvertToMaterialNetworkMap(std::string const &mtlx_path, + pxr::TfTokenVector const &shader_source_types, + pxr::TfTokenVector const &render_contexts, pxr::HdMaterialNetworkMap *out); diff --git a/source/blender/render/hydra/simple_light_task_delegate.cc b/source/blender/render/hydra/simple_light_task_delegate.cc index 2043ba4c65e7..712e3c5e2cca 100644 --- a/source/blender/render/hydra/simple_light_task_delegate.cc +++ b/source/blender/render/hydra/simple_light_task_delegate.cc @@ -7,33 +7,33 @@ namespace blender::render::hydra { -SimpleLightTaskDelegate::SimpleLightTaskDelegate(pxr::HdRenderIndex *parentIndex, - pxr::SdfPath const &delegateID) - : pxr::HdSceneDelegate(parentIndex, delegateID) +SimpleLightTaskDelegate::SimpleLightTaskDelegate(pxr::HdRenderIndex *parent_index, + pxr::SdfPath const &delegate_id) + : pxr::HdSceneDelegate(parent_index, delegate_id) { - pxr::SdfPath taskId = GetTaskID(); - GetRenderIndex().InsertTask(this, taskId); + pxr::SdfPath task_id = get_task_id(); + GetRenderIndex().InsertTask(this, task_id); } -pxr::SdfPath SimpleLightTaskDelegate::GetTaskID() const +pxr::SdfPath SimpleLightTaskDelegate::get_task_id() const { return GetDelegateID().AppendElementString("task"); } -pxr::HdTaskSharedPtr SimpleLightTaskDelegate::GetTask() +pxr::HdTaskSharedPtr SimpleLightTaskDelegate::get_task() { - return GetRenderIndex().GetTask(GetTaskID()); + return GetRenderIndex().GetTask(get_task_id()); } -void SimpleLightTaskDelegate::SetCameraPath(pxr::SdfPath const &cameraPath) +void SimpleLightTaskDelegate::set_camera_path(pxr::SdfPath const &camera_path) { - taskParams.cameraPath = cameraPath; + task_params.cameraPath = camera_path; } pxr::VtValue SimpleLightTaskDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const &key) { if (key == pxr::HdTokens->params) { - return pxr::VtValue(taskParams); + return pxr::VtValue(task_params); } return pxr::VtValue(); } diff --git a/source/blender/render/hydra/simple_light_task_delegate.h b/source/blender/render/hydra/simple_light_task_delegate.h index 04460232450d..4c8f8ed20b27 100644 --- a/source/blender/render/hydra/simple_light_task_delegate.h +++ b/source/blender/render/hydra/simple_light_task_delegate.h @@ -10,18 +10,18 @@ namespace blender::render::hydra { class SimpleLightTaskDelegate : public pxr::HdSceneDelegate { public: - SimpleLightTaskDelegate(pxr::HdRenderIndex *parentIndex, pxr::SdfPath const &delegateID); + SimpleLightTaskDelegate(pxr::HdRenderIndex *parentIndex, pxr::SdfPath const &delegate_id); ~SimpleLightTaskDelegate() override = default; - pxr::SdfPath GetTaskID() const; + pxr::SdfPath get_task_id() const; - pxr::HdTaskSharedPtr GetTask(); - void SetCameraPath(pxr::SdfPath const &); + pxr::HdTaskSharedPtr get_task(); + void set_camera_path(pxr::SdfPath const &); pxr::VtValue Get(pxr::SdfPath const &id, pxr::TfToken const &key) override; private: - pxr::HdxSimpleLightTaskParams taskParams; + pxr::HdxSimpleLightTaskParams task_params; }; } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/viewport_engine.cc b/source/blender/render/hydra/viewport_engine.cc index 2ee3f2468785..9bbc9198b9de 100644 --- a/source/blender/render/hydra/viewport_engine.cc +++ b/source/blender/render/hydra/viewport_engine.cc @@ -134,20 +134,20 @@ pxr::GfCamera ViewSettings::gf_camera() (float)border[3] / screen_height)); } -GLTexture::GLTexture() : textureId(0), width(0), height(0), channels(4) +GLTexture::GLTexture() : texture_id(0), width(0), height(0), channels(4) { } GLTexture::~GLTexture() { - if (textureId) { + if (texture_id) { free(); } } -void GLTexture::setBuffer(pxr::HdRenderBuffer *buffer) +void GLTexture::set_buffer(pxr::HdRenderBuffer *buffer) { - if (!textureId) { + if (!texture_id) { create(buffer); return; } @@ -158,7 +158,7 @@ void GLTexture::setBuffer(pxr::HdRenderBuffer *buffer) return; } - glBindTexture(GL_TEXTURE_2D, textureId); + glBindTexture(GL_TEXTURE_2D, texture_id); void *data = buffer->Map(); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_FLOAT, data); @@ -171,8 +171,8 @@ void GLTexture::create(pxr::HdRenderBuffer *buffer) height = buffer->GetHeight(); channels = pxr::HdGetComponentCount(buffer->GetFormat()); - glGenTextures(1, &textureId); - glBindTexture(GL_TEXTURE_2D, textureId); + glGenTextures(1, &texture_id); + glBindTexture(GL_TEXTURE_2D, texture_id); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); @@ -185,8 +185,8 @@ void GLTexture::create(pxr::HdRenderBuffer *buffer) void GLTexture::free() { - glDeleteTextures(1, &textureId); - textureId = 0; + glDeleteTextures(1, &texture_id); + texture_id = 0; } void GLTexture::draw(GLfloat x, GLfloat y) @@ -218,7 +218,7 @@ void GLTexture::draw(GLfloat x, GLfloat y) // DRAWING glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, textureId); + glBindTexture(GL_TEXTURE_2D, texture_id); glBindVertexArray(vertex_array); glEnableVertexAttribArray(texturecoord_location); @@ -242,45 +242,45 @@ void GLTexture::draw(GLfloat x, GLfloat y) void ViewportEngine::sync(Depsgraph *depsgraph, bContext *context, - pxr::HdRenderSettingsMap &renderSettings) + pxr::HdRenderSettingsMap &render_settings) { if (!scene_delegate) { scene_delegate = std::make_unique( render_index.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"), - BlenderSceneDelegate::EngineType::Viewport); + BlenderSceneDelegate::EngineType::VIEWPORT); } scene_delegate->populate(depsgraph, context); - for (auto const &setting : renderSettings) { + for (auto const &setting : render_settings) { render_delegate->SetRenderSetting(setting.first, setting.second); } } void ViewportEngine::render(Depsgraph *depsgraph, bContext *context) { - ViewSettings viewSettings(context); - if (viewSettings.width() * viewSettings.height() == 0) { + ViewSettings view_settings(context); + if (view_settings.width() * view_settings.height() == 0) { return; }; - pxr::GfCamera gfCamera = viewSettings.gf_camera(); + pxr::GfCamera gfCamera = view_settings.gf_camera(); free_camera_delegate->SetCamera(gfCamera); - render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(), - pxr::GfVec4d(viewSettings.border[0], - viewSettings.border[1], - viewSettings.border[2], - viewSettings.border[3])); + render_task_delegate->set_camera_and_viewport(free_camera_delegate->GetCameraId(), + pxr::GfVec4d(view_settings.border[0], + view_settings.border[1], + view_settings.border[2], + view_settings.border[3])); if (simple_light_task_delegate) { - simple_light_task_delegate->SetCameraPath(free_camera_delegate->GetCameraId()); + simple_light_task_delegate->set_camera_path(free_camera_delegate->GetCameraId()); } if ((bl_engine->type->flag & RE_USE_GPU_CONTEXT) == 0) { - render_task_delegate->SetRendererAov(pxr::HdAovTokens->color); + render_task_delegate->set_renderer_aov(pxr::HdAovTokens->color); } if (renderer_percent_done() == 0.0f) { - timeBegin = std::chrono::steady_clock::now(); + time_begin = std::chrono::steady_clock::now(); } GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_IMAGE); @@ -288,9 +288,9 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context) pxr::HdTaskSharedPtrVector tasks; if (simple_light_task_delegate) { - tasks.push_back(simple_light_task_delegate->GetTask()); + tasks.push_back(simple_light_task_delegate->get_task()); } - tasks.push_back(render_task_delegate->GetTask()); + tasks.push_back(render_task_delegate->get_task()); { /* Release the GIL before calling into hydra, in case any hydra plugins call into python. */ @@ -298,28 +298,28 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context) engine->Execute(render_index.get(), &tasks); if ((bl_engine->type->flag & RE_USE_GPU_CONTEXT) == 0) { - texture.setBuffer(render_task_delegate->GetRendererAov(pxr::HdAovTokens->color)); - texture.draw((GLfloat)viewSettings.border[0], (GLfloat)viewSettings.border[1]); + texture.set_buffer(render_task_delegate->get_renderer_aov(pxr::HdAovTokens->color)); + texture.draw((GLfloat)view_settings.border[0], (GLfloat)view_settings.border[1]); } } GPU_shader_unbind(); - std::chrono::time_point timeCurrent = + std::chrono::time_point time_current = std::chrono::steady_clock::now(); - std::chrono::milliseconds elapsedTime = std::chrono::duration_cast( - timeCurrent - timeBegin); + std::chrono::milliseconds elapsed_time = std::chrono::duration_cast( + time_current - time_begin); - std::string formattedTime = format_duration(elapsedTime); + std::string formatted_time = format_duration(elapsed_time); - if (!render_task_delegate->IsConverged()) { - notify_status("Time: " + formattedTime + + if (!render_task_delegate->is_converged()) { + notify_status("Time: " + formatted_time + " | Done: " + std::to_string(int(renderer_percent_done())) + "%", "Render"); bl_engine->flag |= RE_ENGINE_DO_DRAW; } else { - notify_status(("Time: " + formattedTime).c_str(), "Rendering Done"); + notify_status(("Time: " + formatted_time).c_str(), "Rendering Done"); } } diff --git a/source/blender/render/hydra/viewport_engine.h b/source/blender/render/hydra/viewport_engine.h index b842f54c59a5..3e44d2bb5acd 100644 --- a/source/blender/render/hydra/viewport_engine.h +++ b/source/blender/render/hydra/viewport_engine.h @@ -17,14 +17,14 @@ class GLTexture { public: GLTexture(); ~GLTexture(); - void setBuffer(pxr::HdRenderBuffer *buffer); + void set_buffer(pxr::HdRenderBuffer *buffer); void draw(GLfloat x, GLfloat y); private: void create(pxr::HdRenderBuffer *buffer); void free(); - GLuint textureId; + GLuint texture_id; int width, height, channels; }; @@ -33,7 +33,7 @@ class ViewportEngine : public Engine { using Engine::Engine; void sync(Depsgraph *depsgraph, bContext *context, - pxr::HdRenderSettingsMap &renderSettings) override; + pxr::HdRenderSettingsMap &render_settings) override; void render(Depsgraph *depsgraph) override; void render(Depsgraph *depsgraph, bContext *context); @@ -41,7 +41,7 @@ class ViewportEngine : public Engine { void notify_status(const std::string &title, const std::string &info); private: - std::chrono::time_point timeBegin; + std::chrono::time_point time_begin; GLTexture texture; }; -- 2.30.2 From 560b742b9a4bac23e3f68429aaead3bb19777b34 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Tue, 14 Mar 2023 17:56:37 +0300 Subject: [PATCH 07/11] fix format --- source/blender/render/hydra/python.cc | 14 ++++++++------ source/blender/render/hydra/viewport_engine.cc | 8 ++++---- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/source/blender/render/hydra/python.cc b/source/blender/render/hydra/python.cc index 157edf200fc8..61d8ededeb3e 100644 --- a/source/blender/render/hydra/python.cc +++ b/source/blender/render/hydra/python.cc @@ -224,10 +224,11 @@ static PyObject *engine_render_func(PyObject * /*self*/, PyObject *args) Depsgraph *depsgraph = (Depsgraph *)PyLong_AsVoidPtr(pydepsgraph); /* Allow Blender to execute other Python scripts. */ - Py_BEGIN_ALLOW_THREADS engine->render(depsgraph); - Py_END_ALLOW_THREADS + Py_BEGIN_ALLOW_THREADS; + engine->render(depsgraph); + Py_END_ALLOW_THREADS; - Py_RETURN_NONE; + Py_RETURN_NONE; } static PyObject *engine_view_draw_func(PyObject * /*self*/, PyObject *args) @@ -242,10 +243,11 @@ static PyObject *engine_view_draw_func(PyObject * /*self*/, PyObject *args) bContext *context = (bContext *)PyLong_AsVoidPtr(pycontext); /* Allow Blender to execute other Python scripts. */ - Py_BEGIN_ALLOW_THREADS engine->render(depsgraph, context); - Py_END_ALLOW_THREADS + Py_BEGIN_ALLOW_THREADS; + engine->render(depsgraph, context); + Py_END_ALLOW_THREADS; - Py_RETURN_NONE; + Py_RETURN_NONE; } static PyMethodDef methods[] = { diff --git a/source/blender/render/hydra/viewport_engine.cc b/source/blender/render/hydra/viewport_engine.cc index 9bbc9198b9de..3d8945fa1fc6 100644 --- a/source/blender/render/hydra/viewport_engine.cc +++ b/source/blender/render/hydra/viewport_engine.cc @@ -267,10 +267,10 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context) pxr::GfCamera gfCamera = view_settings.gf_camera(); free_camera_delegate->SetCamera(gfCamera); render_task_delegate->set_camera_and_viewport(free_camera_delegate->GetCameraId(), - pxr::GfVec4d(view_settings.border[0], - view_settings.border[1], - view_settings.border[2], - view_settings.border[3])); + pxr::GfVec4d(view_settings.border[0], + view_settings.border[1], + view_settings.border[2], + view_settings.border[3])); if (simple_light_task_delegate) { simple_light_task_delegate->set_camera_path(free_camera_delegate->GetCameraId()); } -- 2.30.2 From e79aa12278710b196b14d0492de2df2c1f83da7a Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Tue, 14 Mar 2023 18:06:45 +0300 Subject: [PATCH 08/11] capitalized enum DirtyBits --- source/blender/render/hydra/scene_delegate/id.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/render/hydra/scene_delegate/id.h b/source/blender/render/hydra/scene_delegate/id.h index b31187f1266b..43e50e33d931 100644 --- a/source/blender/render/hydra/scene_delegate/id.h +++ b/source/blender/render/hydra/scene_delegate/id.h @@ -22,7 +22,7 @@ class IdData { virtual pxr::VtValue get_data(pxr::TfToken const &key); template const T get_data(pxr::TfToken const &key); - enum class DirtyBits { DirtyTransform = 1, DirtyVisibility, DirtyMaterial, AllDirty }; + enum class DirtyBits { DIRTY_TRANSFORM = 1, DIRTY_VISIBILITY, DIRTY_MATERIAL, ALL_DIRTY }; virtual void insert_prim() = 0; virtual void remove_prim() = 0; -- 2.30.2 From 70b66f4bd9b7335cda6f890c2d590e1091bd664e Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Tue, 14 Mar 2023 18:10:57 +0300 Subject: [PATCH 09/11] fix comment and enums --- source/blender/render/hydra/scene_delegate/light.cc | 6 +++--- source/blender/render/hydra/viewport_engine.cc | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/light.cc b/source/blender/render/hydra/scene_delegate/light.cc index f52c6450dd87..6ebce8295b7b 100644 --- a/source/blender/render/hydra/scene_delegate/light.cc +++ b/source/blender/render/hydra/scene_delegate/light.cc @@ -157,13 +157,13 @@ void LightData::mark_prim_dirty(DirtyBits dirty_bits) pxr::HdDirtyBits bits = pxr::HdLight::Clean; switch (dirty_bits) { - case DirtyBits::DirtyTransform: + case DirtyBits::DIRTY_TRANSFORM: bits = pxr::HdLight::DirtyTransform; break; - case DirtyBits::DirtyVisibility: + case DirtyBits::DIRTY_VISIBILITY: bits = pxr::HdLight::DirtyParams; break; - case DirtyBits::AllDirty: + case DirtyBits::ALL_DIRTY: bits = pxr::HdLight::AllDirty; break; default: diff --git a/source/blender/render/hydra/viewport_engine.cc b/source/blender/render/hydra/viewport_engine.cc index 3d8945fa1fc6..f0fd403fa7b8 100644 --- a/source/blender/render/hydra/viewport_engine.cc +++ b/source/blender/render/hydra/viewport_engine.cc @@ -9,7 +9,7 @@ #include "DNA_camera_types.h" #include "DNA_screen_types.h" -#include "DNA_vec_types.h" /* this include should be before BKE_camera.h due to "rctf" type */ +#include "DNA_vec_types.h" /* this include must be before BKE_camera.h due to "rctf" type */ #include "BKE_camera.h" #include "BLI_math_matrix.h" #include "DEG_depsgraph_query.h" -- 2.30.2 From 6c9561fc39e2db5df6b6e7d35c02ba53be91c2a2 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Tue, 14 Mar 2023 18:13:33 +0300 Subject: [PATCH 10/11] rename variable --- source/blender/render/hydra/viewport_engine.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/blender/render/hydra/viewport_engine.cc b/source/blender/render/hydra/viewport_engine.cc index f0fd403fa7b8..682f39e6dbfd 100644 --- a/source/blender/render/hydra/viewport_engine.cc +++ b/source/blender/render/hydra/viewport_engine.cc @@ -264,8 +264,8 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context) return; }; - pxr::GfCamera gfCamera = view_settings.gf_camera(); - free_camera_delegate->SetCamera(gfCamera); + pxr::GfCamera gf_camera = view_settings.gf_camera(); + free_camera_delegate->SetCamera(gf_camera); render_task_delegate->set_camera_and_viewport(free_camera_delegate->GetCameraId(), pxr::GfVec4d(view_settings.border[0], view_settings.border[1], -- 2.30.2 From 533d9006aa0e215555f8e253d3bbdbb2c9924366 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Tue, 14 Mar 2023 19:25:02 +0300 Subject: [PATCH 11/11] fix enum names --- .../hydra/scene_delegate/blender_scene_delegate.cc | 12 ++++++------ .../blender/render/hydra/scene_delegate/material.cc | 2 +- source/blender/render/hydra/scene_delegate/mesh.cc | 8 ++++---- source/blender/render/hydra/scene_delegate/world.cc | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc index a8b7137d1465..efd744c27ed4 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -44,7 +44,7 @@ void BlenderSceneDelegate::update_material(Material *material) MaterialData *mat_data = material_data(MaterialData::prim_id(this, material)); if (mat_data) { mat_data->export_mtlx(); - mat_data->mark_prim_dirty(IdData::DirtyBits::AllDirty); + mat_data->mark_prim_dirty(IdData::DirtyBits::ALL_DIRTY); } } @@ -61,7 +61,7 @@ void BlenderSceneDelegate::update_world() else { if (world) { world_data = WorldData::init(this, world, context); - world_data->mark_prim_dirty(IdData::DirtyBits::AllDirty); + world_data->mark_prim_dirty(IdData::DirtyBits::ALL_DIRTY); } else { world_data->remove_prim(); @@ -149,7 +149,7 @@ void BlenderSceneDelegate::update_collection(bool remove, bool visibility) /* Check and update visibility */ for (auto &obj : objects) { if (obj.second->update_visibility(view3d)) { - obj.second->mark_prim_dirty(IdData::DirtyBits::DirtyVisibility); + obj.second->mark_prim_dirty(IdData::DirtyBits::DIRTY_VISIBILITY); }; } } @@ -250,16 +250,16 @@ void BlenderSceneDelegate::add_update_object(Object *object, if (m_data) { set_material(*m_data); } - obj_data->mark_prim_dirty(IdData::DirtyBits::AllDirty); + obj_data->mark_prim_dirty(IdData::DirtyBits::ALL_DIRTY); return; } if (transform) { - obj_data->mark_prim_dirty(IdData::DirtyBits::DirtyTransform); + obj_data->mark_prim_dirty(IdData::DirtyBits::DIRTY_TRANSFORM); } if (shading) { - obj_data->mark_prim_dirty(IdData::DirtyBits::DirtyMaterial); + obj_data->mark_prim_dirty(IdData::DirtyBits::DIRTY_MATERIAL); } } diff --git a/source/blender/render/hydra/scene_delegate/material.cc b/source/blender/render/hydra/scene_delegate/material.cc index b72ee790d381..d32b634708cd 100644 --- a/source/blender/render/hydra/scene_delegate/material.cc +++ b/source/blender/render/hydra/scene_delegate/material.cc @@ -109,7 +109,7 @@ void MaterialData::mark_prim_dirty(DirtyBits dirty_bits) { pxr::HdDirtyBits bits = pxr::HdMaterial::Clean; switch (dirty_bits) { - case DirtyBits::AllDirty: + case DirtyBits::ALL_DIRTY: bits = pxr::HdMaterial::AllDirty; break; default: diff --git a/source/blender/render/hydra/scene_delegate/mesh.cc b/source/blender/render/hydra/scene_delegate/mesh.cc index eff60319097f..ab6672c150b9 100644 --- a/source/blender/render/hydra/scene_delegate/mesh.cc +++ b/source/blender/render/hydra/scene_delegate/mesh.cc @@ -241,16 +241,16 @@ void MeshData::mark_prim_dirty(DirtyBits dirty_bits) pxr::HdDirtyBits bits = pxr::HdChangeTracker::Clean; switch (dirty_bits) { - case DirtyBits::DirtyTransform: + case DirtyBits::DIRTY_TRANSFORM: bits = pxr::HdChangeTracker::DirtyTransform; break; - case DirtyBits::DirtyVisibility: + case DirtyBits::DIRTY_VISIBILITY: bits = pxr::HdChangeTracker::DirtyVisibility; break; - case DirtyBits::DirtyMaterial: + case DirtyBits::DIRTY_MATERIAL: bits = pxr::HdChangeTracker::DirtyMaterialId; break; - case DirtyBits::AllDirty: + case DirtyBits::ALL_DIRTY: bits = pxr::HdChangeTracker::AllDirty; break; default: diff --git a/source/blender/render/hydra/scene_delegate/world.cc b/source/blender/render/hydra/scene_delegate/world.cc index 95ab57b2ac77..c27b6033df78 100644 --- a/source/blender/render/hydra/scene_delegate/world.cc +++ b/source/blender/render/hydra/scene_delegate/world.cc @@ -144,7 +144,7 @@ void WorldData::mark_prim_dirty(DirtyBits dirty_bits) { pxr::HdDirtyBits bits = pxr::HdLight::Clean; switch (dirty_bits) { - case DirtyBits::AllDirty: + case DirtyBits::ALL_DIRTY: bits = pxr::HdLight::AllDirty; break; default: -- 2.30.2