From 875716a7f87145940167bfaa83c1d0858db27847 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Mon, 24 Jul 2023 12:13:05 +0200 Subject: [PATCH 1/6] Fix GCC compiler warnings --- source/blender/render/hydra/camera.cc | 14 ++++++++++---- source/blender/render/hydra/preview_engine.cc | 6 +++--- source/blender/render/hydra/python.cc | 2 ++ .../blender/render/hydra/scene_delegate/image.cc | 2 +- .../render/hydra/scene_delegate/instancer.cc | 8 ++++---- source/blender/render/hydra/scene_delegate/mesh.cc | 4 ++-- .../blender/render/hydra/scene_delegate/object.cc | 6 +++--- 7 files changed, 25 insertions(+), 17 deletions(-) diff --git a/source/blender/render/hydra/camera.cc b/source/blender/render/hydra/camera.cc index 09a7b923b4fc..21295bfb29bc 100644 --- a/source/blender/render/hydra/camera.cc +++ b/source/blender/render/hydra/camera.cc @@ -141,7 +141,7 @@ CameraData::CameraData(Object *camera_obj, pxr::GfVec2i res, pxr::GfVec4f tile) 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: + case CAM_PERSP: { focal_length_ = camera->lens; switch (camera->sensor_fit) { @@ -165,8 +165,9 @@ CameraData::CameraData(Object *camera_obj, pxr::GfVec2i res, pxr::GfVec4f tile) } sensor_size_ = pxr::GfVec2f(sensor_size_[0] * t_size[0], sensor_size_[1] * t_size[1]); break; + } - case CAM_ORTHO: + case CAM_ORTHO: { focal_length_ = 0.0f; switch (camera->sensor_fit) { case CAMERA_SENSOR_FIT_VERT: @@ -189,8 +190,9 @@ CameraData::CameraData(Object *camera_obj, pxr::GfVec2i res, pxr::GfVec4f tile) } ortho_size_ = pxr::GfVec2f(ortho_size_[0] * t_size[0], ortho_size_[1] * t_size[1]); break; + } - case CAM_PANO: + case CAM_PANO: { /* TODO: Recheck parameters for PANO camera */ focal_length_ = camera->lens; @@ -214,10 +216,14 @@ CameraData::CameraData(Object *camera_obj, pxr::GfVec2i res, pxr::GfVec4f tile) break; } sensor_size_ = pxr::GfVec2f(sensor_size_[0] * t_size[0], sensor_size_[1] * t_size[1]); + break; + } - default: + default: { focal_length_ = camera->lens; sensor_size_ = pxr::GfVec2f(camera->sensor_y * ratio, camera->sensor_y); + break; + } } } diff --git a/source/blender/render/hydra/preview_engine.cc b/source/blender/render/hydra/preview_engine.cc index c0086fe2e0b0..67aff0cf4898 100644 --- a/source/blender/render/hydra/preview_engine.cc +++ b/source/blender/render/hydra/preview_engine.cc @@ -5,9 +5,9 @@ namespace blender::render::hydra { -void PreviewEngine::notify_status(float progress, - const std::string &title, - const std::string &info) +void PreviewEngine::notify_status(float /* progress */, + const std::string & /* title */, + const std::string & /* info */) { /* Empty fucntion */ } diff --git a/source/blender/render/hydra/python.cc b/source/blender/render/hydra/python.cc index cc4ab4bbe00d..b46696c77805 100644 --- a/source/blender/render/hydra/python.cc +++ b/source/blender/render/hydra/python.cc @@ -258,6 +258,8 @@ static struct PyModuleDef module = { extern "C" { #endif +PyObject *BPyInit_hydra(void); + PyObject *BPyInit_hydra(void) { PyObject *mod = PyModule_Create(&blender::render::hydra::module); diff --git a/source/blender/render/hydra/scene_delegate/image.cc b/source/blender/render/hydra/scene_delegate/image.cc index d54dfb3fb682..f1f8d825032e 100644 --- a/source/blender/render/hydra/scene_delegate/image.cc +++ b/source/blender/render/hydra/scene_delegate/image.cc @@ -96,7 +96,7 @@ std::string cache_image_color(float color[4]) char name[128]; snprintf(name, sizeof(name), - "color_%02x%02x%02x.hdr", + "color_%02d%02d%02d.hdr", int(color[0] * 255), int(color[1] * 255), int(color[2] * 255)); diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index cbff055139aa..9463bdb57ea3 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -128,7 +128,7 @@ void InstancerData::pre_update() } } -void InstancerData::update_instance(Object *parent_ob, DupliObject *dupli) +void InstancerData::update_instance(Object * /* parent_ob */, DupliObject *dupli) { Object *object = dupli->ob; pxr::SdfPath p_id = object_prim_id(object); @@ -207,14 +207,14 @@ pxr::SdfPath InstancerData::object_prim_id(Object *object) const pxr::SdfPath InstancerData::nonmesh_prim_id(pxr::SdfPath const &prim_id, int index) const { char name[16]; - snprintf(name, sizeof(name), "NM_%08x", index); + snprintf(name, sizeof(name), "NM_%08d", index); return prim_id.AppendElementString(name); } int InstancerData::nonmesh_prim_id_index(pxr::SdfPath const &id) const { int index; - sscanf(id.GetName().c_str(), "NM_%x", &index); + sscanf(id.GetName().c_str(), "NM_%d", &index); return index; } @@ -275,7 +275,7 @@ InstancerData::MeshInstance *InstancerData::mesh_instance(pxr::SdfPath const &id InstancerData::NonmeshInstance *InstancerData::nonmesh_instance(pxr::SdfPath const &id) const { auto nm_inst = nonmesh_instances_.lookup_ptr(id.GetPathElementCount() == 4 ? id.GetParentPath() : - id); + id); if (!nm_inst) { return nullptr; } diff --git a/source/blender/render/hydra/scene_delegate/mesh.cc b/source/blender/render/hydra/scene_delegate/mesh.cc index ba94fdbfad65..a177330ca4f1 100644 --- a/source/blender/render/hydra/scene_delegate/mesh.cc +++ b/source/blender/render/hydra/scene_delegate/mesh.cc @@ -202,14 +202,14 @@ void MeshData::write_materials() pxr::SdfPath MeshData::submesh_prim_id(int index) const { char name[16]; - snprintf(name, sizeof(name), "SM_%04x", index); + snprintf(name, sizeof(name), "SM_%04d", index); return prim_id.AppendElementString(name); } const MeshData::SubMesh &MeshData::submesh(pxr::SdfPath const &id) const { int index; - sscanf(id.GetName().c_str(), "SM_%x", &index); + sscanf(id.GetName().c_str(), "SM_%d", &index); return submeshes_[index]; } diff --git a/source/blender/render/hydra/scene_delegate/object.cc b/source/blender/render/hydra/scene_delegate/object.cc index e4250ab75320..20162cc7e904 100644 --- a/source/blender/render/hydra/scene_delegate/object.cc +++ b/source/blender/render/hydra/scene_delegate/object.cc @@ -101,7 +101,7 @@ bool ObjectData::is_visible(BlenderSceneDelegate *scene_delegate, Object *object return ret; } -pxr::VtValue ObjectData::get_data(pxr::SdfPath const &id, pxr::TfToken const &key) const +pxr::VtValue ObjectData::get_data(pxr::SdfPath const & /* id */, pxr::TfToken const &key) const { return get_data(key); } @@ -111,12 +111,12 @@ pxr::SdfPath ObjectData::material_id() const return pxr::SdfPath(); } -pxr::SdfPath ObjectData::material_id(pxr::SdfPath const &id) const +pxr::SdfPath ObjectData::material_id(pxr::SdfPath const & /* id */) const { return material_id(); } -void ObjectData::available_materials(Set &paths) const {} +void ObjectData::available_materials(Set & /* paths */) const {} void ObjectData::write_transform() { -- 2.30.2 From daa85797faefcd100b9a22de590bf479e78d43f3 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Mon, 24 Jul 2023 14:54:09 +0200 Subject: [PATCH 2/6] Fix OpenGL core profile issue with rendering when selecting objects Use same workaround as for final render in the viewport. --- source/blender/render/hydra/viewport_engine.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/source/blender/render/hydra/viewport_engine.cc b/source/blender/render/hydra/viewport_engine.cc index 229ec9fff309..438d5b172569 100644 --- a/source/blender/render/hydra/viewport_engine.cc +++ b/source/blender/render/hydra/viewport_engine.cc @@ -13,6 +13,8 @@ #include "DEG_depsgraph_query.h" #include "DNA_camera_types.h" #include "DNA_screen_types.h" + +#include "GPU_context.h" #include "GPU_matrix.h" #include "PIL_time.h" @@ -232,6 +234,14 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context) render_task_delegate_->add_aov(pxr::HdAovTokens->color); } + /* Workaround missing/buggy VAOs in hgiGL and hdSt. For OpenGL compatibility + * profile this is not a problem, but for core profile it is. */ + GLuint VAO; + if (GPU_backend_get_type() == GPU_BACKEND_OPENGL) { + glGenVertexArrays(1, &VAO); + glBindVertexArray(VAO); + } + GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_IMAGE); GPU_shader_bind(shader); @@ -253,6 +263,10 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context) GPU_shader_unbind(); + if (GPU_backend_get_type() == GPU_BACKEND_OPENGL) { + glDeleteVertexArrays(1, &VAO); + } + if (renderer_percent_done() == 0.0f) { time_begin_ = PIL_check_seconds_timer(); } -- 2.30.2 From f54b2310a0cb992b3f68abd475cd008f838199bb Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Tue, 25 Jul 2023 16:42:04 +0200 Subject: [PATCH 3/6] Fix assert when due to use of filtering stencil texture None of these textures need filtering or mipmaps. These are not scaled for drawing, and even if they were used for image editor drawing with zoom the consistent thing would still be to use nearest interpolation. --- source/blender/render/hydra/viewport_engine.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/source/blender/render/hydra/viewport_engine.cc b/source/blender/render/hydra/viewport_engine.cc index 438d5b172569..4cf6815ff5aa 100644 --- a/source/blender/render/hydra/viewport_engine.cc +++ b/source/blender/render/hydra/viewport_engine.cc @@ -177,8 +177,6 @@ void DrawTexture::write_data(int width, int height, const void *data) GPU_RGBA16F, GPU_TEXTURE_USAGE_GENERAL, (float *)data); - GPU_texture_filter_mode(texture_, true); - GPU_texture_mipmap_mode(texture_, true, true); } void DrawTexture::draw(GPUShader *shader, const pxr::GfVec4d &viewport) -- 2.30.2 From 03f24159b8f89acf4728609a4bce58aadf7fde2f Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Mon, 17 Jul 2023 14:51:58 +0200 Subject: [PATCH 4/6] Fix multi render layer rendering writing to the wrong buffers --- source/blender/render/hydra/final_engine.cc | 27 ++++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/source/blender/render/hydra/final_engine.cc b/source/blender/render/hydra/final_engine.cc index 68e763736afc..e0e196c69f31 100644 --- a/source/blender/render/hydra/final_engine.cc +++ b/source/blender/render/hydra/final_engine.cc @@ -98,23 +98,26 @@ void FinalEngine::notify_status(float progress, const std::string &title, const void FinalEngine::update_render_result() { - RenderResult *result = RE_engine_begin_result( + RenderResult *rr = RE_engine_begin_result( bl_engine_, 0, 0, resolution_[0], resolution_[1], 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) { - pxr::TfToken aov_key; - if (STREQ(pass->name, "Combined")) { - aov_key = pxr::HdAovTokens->color; + RenderLayer *rlayer = static_cast( + BLI_findstring(&rr->layers, layer_name_.c_str(), offsetof(RenderLayer, name))); + + if (rlayer) { + LISTBASE_FOREACH (RenderPass *, rpass, &rlayer->passes) { + pxr::TfToken aov_key; + if (STREQ(rpass->name, "Combined")) { + aov_key = pxr::HdAovTokens->color; + } + else if (STREQ(rpass->name, "Depth")) { + aov_key = pxr::HdAovTokens->depth; + } + render_task_delegate_->read_aov(aov_key, rpass->ibuf->float_buffer.data); } - else if (STREQ(pass->name, "Depth")) { - aov_key = pxr::HdAovTokens->depth; - } - render_task_delegate_->read_aov(aov_key, pass->ibuf->float_buffer.data); } - RE_engine_end_result(bl_engine_, result, false, false, false); + RE_engine_end_result(bl_engine_, rr, false, false, false); } } // namespace blender::render::hydra -- 2.30.2 From 278981c26e350c44e62a2b56b67a3a4cb0e5266e Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Tue, 25 Jul 2023 18:27:30 +0200 Subject: [PATCH 5/6] Fix invalid memory write, causing crashes with longer scene names --- source/blender/render/hydra/final_engine.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/blender/render/hydra/final_engine.cc b/source/blender/render/hydra/final_engine.cc index e0e196c69f31..0318bb9ff9c0 100644 --- a/source/blender/render/hydra/final_engine.cc +++ b/source/blender/render/hydra/final_engine.cc @@ -23,8 +23,8 @@ void FinalEngine::render(Depsgraph *depsgraph) const Scene *scene = DEG_get_evaluated_scene(depsgraph); const ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph); - char scene_name[MAX_NAME]; - BKE_id_full_name_get(scene_name, (ID *)scene, 0); + char scene_name[MAX_ID_FULL_NAME]; + BKE_id_full_name_get(scene_name, &scene->id, 0); scene_name_ = scene_name; layer_name_ = view_layer->name; -- 2.30.2 From 3b325ca3491e788ac4d80c5f51da514b01821355 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Mon, 17 Jul 2023 14:17:21 +0200 Subject: [PATCH 6/6] Fix invalid context access in scene delegate The context is temporary and changes over time depending on the operation Blender is doing. That means holding on to it in the scene delegate is not safe. Instead extract the members from it beforehand. --- source/blender/render/hydra/camera.cc | 17 +++++++------ source/blender/render/hydra/camera.h | 8 +++---- source/blender/render/hydra/engine.cc | 6 +++-- source/blender/render/hydra/python.cc | 5 +++- .../scene_delegate/blender_scene_delegate.cc | 8 +++---- .../scene_delegate/blender_scene_delegate.h | 11 ++++++--- .../render/hydra/scene_delegate/image.cc | 24 ++++++++----------- .../render/hydra/scene_delegate/image.h | 10 +++++--- .../scene_delegate/usd_scene_delegate.cc | 2 +- .../scene_delegate/usd_scene_delegate.hh | 3 +-- .../render/hydra/scene_delegate/volume.cc | 3 +-- .../render/hydra/scene_delegate/world.cc | 10 ++++---- .../blender/render/hydra/viewport_engine.cc | 7 +++++- 13 files changed, 64 insertions(+), 50 deletions(-) diff --git a/source/blender/render/hydra/camera.cc b/source/blender/render/hydra/camera.cc index 21295bfb29bc..023422768384 100644 --- a/source/blender/render/hydra/camera.cc +++ b/source/blender/render/hydra/camera.cc @@ -2,6 +2,7 @@ * Copyright 2011-2022 Blender Foundation */ #include "DNA_camera_types.h" +#include "DNA_object_types.h" #include "DNA_screen_types.h" #include "DNA_view3d_types.h" @@ -10,11 +11,9 @@ namespace blender::render::hydra { -CameraData::CameraData(bContext *context) +CameraData::CameraData(View3D *v3d, ARegion *region) { - View3D *view3d = CTX_wm_view3d(context); - RegionView3D *region_data = (RegionView3D *)CTX_wm_region_data(context); - ARegion *region = CTX_wm_region(context); + RegionView3D *region_data = (RegionView3D *)region->regiondata; /* This constant was found experimentally, didn't find such option in * context.view3d or context.region_data. */ @@ -27,9 +26,9 @@ CameraData::CameraData(bContext *context) switch (region_data->persp) { case RV3D_PERSP: { mode_ = CAM_PERSP; - clip_range_ = pxr::GfRange1f(view3d->clip_start, view3d->clip_end); + clip_range_ = pxr::GfRange1f(v3d->clip_start, v3d->clip_end); lens_shift_ = pxr::GfVec2f(0.0, 0.0); - focal_length_ = view3d->lens; + focal_length_ = v3d->lens; if (ratio > 1.0) { sensor_size_ = pxr::GfVec2f(VIEWPORT_SENSOR_SIZE, VIEWPORT_SENSOR_SIZE / ratio); @@ -44,8 +43,8 @@ CameraData::CameraData(bContext *context) mode_ = CAM_ORTHO; 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; + float o_size = region_data->dist * VIEWPORT_SENSOR_SIZE / v3d->lens; + float o_depth = v3d->clip_end; clip_range_ = pxr::GfRange1f(-o_depth * 0.5, o_depth * 0.5); @@ -60,7 +59,7 @@ CameraData::CameraData(bContext *context) case RV3D_CAMOB: { pxr::GfMatrix4d mat = transform_; - *this = CameraData(view3d->camera, res, pxr::GfVec4f(0, 0, 1, 1)); + *this = CameraData(v3d->camera, res, pxr::GfVec4f(0, 0, 1, 1)); transform_ = mat; /* This formula was taken from previous plugin with corresponded comment. diff --git a/source/blender/render/hydra/camera.h b/source/blender/render/hydra/camera.h index 6e3a482ae007..1a7081656212 100644 --- a/source/blender/render/hydra/camera.h +++ b/source/blender/render/hydra/camera.h @@ -8,15 +8,15 @@ #include #include -#include "BKE_context.h" - -#include "DNA_object_types.h" +struct ARegion; +struct Object; +struct View3D; namespace blender::render::hydra { class CameraData { public: - CameraData(bContext *context); + CameraData(View3D *v3d, ARegion *region); CameraData(Object *camera_obj, pxr::GfVec2i res, pxr::GfVec4f tile); pxr::GfCamera gf_camera(); diff --git a/source/blender/render/hydra/engine.cc b/source/blender/render/hydra/engine.cc index dfe39edee02c..aac947de51fb 100644 --- a/source/blender/render/hydra/engine.cc +++ b/source/blender/render/hydra/engine.cc @@ -10,6 +10,8 @@ #include "BLI_path_util.h" +#include "BKE_context.h" + #include "GPU_context.h" #include "DEG_depsgraph_query.h" @@ -83,7 +85,7 @@ void Engine::sync(Depsgraph *depsgraph, bContext *context) hydra_scene_delegate_ = std::make_unique( render_index_.get(), scene_path, scene_delegate_settings_); } - hydra_scene_delegate_->populate(depsgraph, context); + hydra_scene_delegate_->populate(depsgraph, CTX_wm_view3d(context)); } else { /* Slow USD export for reference. */ @@ -98,7 +100,7 @@ void Engine::sync(Depsgraph *depsgraph, bContext *context) usd_scene_delegate_ = std::make_unique( render_index_.get(), scene_path, scene_delegate_settings_); } - usd_scene_delegate_->populate(depsgraph, context); + usd_scene_delegate_->populate(depsgraph); } } diff --git a/source/blender/render/hydra/python.cc b/source/blender/render/hydra/python.cc index b46696c77805..d4be373d90c9 100644 --- a/source/blender/render/hydra/python.cc +++ b/source/blender/render/hydra/python.cc @@ -11,6 +11,8 @@ #include #include "BKE_appdir.h" +#include "BKE_context.h" + #include "BLI_fileops.h" #include "BLI_path_util.h" @@ -220,7 +222,8 @@ static PyObject *cache_or_get_image_file_func(PyObject * /*self*/, PyObject *arg bContext *context = (bContext *)PyLong_AsVoidPtr(pycontext); Image *image = (Image *)PyLong_AsVoidPtr(pyimage); - std::string image_path = cache_or_get_image_file(image, context, nullptr); + std::string image_path = cache_or_get_image_file( + CTX_data_main(context), CTX_data_scene(context), image, nullptr); return PyUnicode_FromString(image_path.c_str()); } 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 65b7312f4f16..ebec28e64afb 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -198,14 +198,14 @@ pxr::HdVolumeFieldDescriptorVector BlenderSceneDelegate::GetVolumeFieldDescripto return v_data->field_descriptors(); } -void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont) +void BlenderSceneDelegate::populate(Depsgraph *deps, View3D *v3d) { bool is_populated = depsgraph != nullptr; depsgraph = deps; - context = cont; + bmain = DEG_get_bmain(deps); scene = DEG_get_input_scene(depsgraph); - view3d = CTX_wm_view3d(context); + view3d = v3d; if (is_populated) { check_updates(); @@ -231,7 +231,7 @@ void BlenderSceneDelegate::clear() materials_.clear(); depsgraph = nullptr; - context = nullptr; + bmain = nullptr; scene = nullptr; view3d = nullptr; } 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 e8d84af886c7..2c673fcfd3f6 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h @@ -6,8 +6,8 @@ #include #include -#include "BKE_context.h" #include "BLI_map.hh" + #include "DEG_depsgraph.h" #include "CLG_log.h" @@ -22,6 +22,11 @@ #include "volume_modifier.h" #include "world.h" +struct Depsgraph; +struct Main; +struct Scene; +struct View3D; + namespace blender::render::hydra { extern struct CLG_LogRef *LOG_RENDER_HYDRA_SCENE; @@ -69,12 +74,12 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate { pxr::HdVolumeFieldDescriptorVector GetVolumeFieldDescriptors( pxr::SdfPath const &volume_id) override; - void populate(Depsgraph *depsgraph, bContext *context); + void populate(Depsgraph *depsgraph, View3D *v3d); void clear(); Depsgraph *depsgraph = nullptr; - bContext *context = nullptr; View3D *view3d = nullptr; + Main *bmain = nullptr; Scene *scene = nullptr; const SceneDelegateSettings &settings; ShadingSettings shading_settings; diff --git a/source/blender/render/hydra/scene_delegate/image.cc b/source/blender/render/hydra/scene_delegate/image.cc index f1f8d825032e..9f45e4fde4bf 100644 --- a/source/blender/render/hydra/scene_delegate/image.cc +++ b/source/blender/render/hydra/scene_delegate/image.cc @@ -4,6 +4,7 @@ #include #include "BKE_appdir.h" +#include "BKE_image.h" #include "BKE_image_format.h" #include "BKE_image_save.h" #include "BLI_fileops.h" @@ -29,16 +30,12 @@ static std::string get_cache_file(const std::string &file_name, bool mkdir = tru return file_path; } -static std::string cache_image_file(Image *image, - bContext *context, - ImageUser *iuser, - bool check_exist) +static std::string cache_image_file( + Main *bmain, Scene *scene, Image *image, ImageUser *iuser, bool check_exist) { std::string file_path; - Main *main = CTX_data_main(context); - Scene *scene = CTX_data_scene(context); ImageSaveOptions opts; - if (BKE_image_save_options_init(&opts, main, scene, image, iuser, false, false)) { + if (BKE_image_save_options_init(&opts, bmain, scene, image, iuser, false, false)) { char file_name[32]; const char *r_ext = BLI_path_extension_or_end(image->id.name); if (!pxr::HioImageRegistry::GetInstance().IsSupportedImageFile(image->id.name)) { @@ -55,7 +52,7 @@ static std::string cache_image_file(Image *image, opts.save_copy = true; STRNCPY(opts.filepath, file_path.c_str()); - if (BKE_image_save(nullptr, main, image, iuser, &opts)) { + if (BKE_image_save(nullptr, bmain, image, iuser, &opts)) { CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 1, "%s -> %s", image->id.name, file_path.c_str()); } else { @@ -67,23 +64,22 @@ static std::string cache_image_file(Image *image, return file_path; } -std::string cache_or_get_image_file(Image *image, bContext *context, ImageUser *iuser) +std::string cache_or_get_image_file(Main *bmain, Scene *scene, Image *image, ImageUser *iuser) { std::string file_path; if (image->source == IMA_SRC_GENERATED) { - file_path = cache_image_file(image, context, iuser, false); + file_path = cache_image_file(bmain, scene, image, iuser, false); } else if (BKE_image_has_packedfile(image)) { - file_path = cache_image_file(image, context, iuser, true); + file_path = cache_image_file(bmain, scene, image, iuser, true); } else { - Main *main = CTX_data_main(context); char str[FILE_MAX]; - BKE_image_user_file_path_ex(main, iuser, image, str, false, true); + BKE_image_user_file_path_ex(bmain, iuser, image, str, false, true); file_path = str; if (!pxr::HioImageRegistry::GetInstance().IsSupportedImageFile(file_path)) { - file_path = cache_image_file(image, context, iuser, true); + file_path = cache_image_file(bmain, scene, image, iuser, true); } } diff --git a/source/blender/render/hydra/scene_delegate/image.h b/source/blender/render/hydra/scene_delegate/image.h index 9693e8e15255..8124f6bf7f48 100644 --- a/source/blender/render/hydra/scene_delegate/image.h +++ b/source/blender/render/hydra/scene_delegate/image.h @@ -3,12 +3,16 @@ #pragma once -#include "BKE_context.h" -#include "BKE_image.h" +#include + +struct Main; +struct Scene; +struct Image; +struct ImageUser; namespace blender::render::hydra { -std::string cache_or_get_image_file(Image *image, bContext *context, ImageUser *iuser); +std::string cache_or_get_image_file(Main *bmain, Scene *Scene, Image *image, ImageUser *iuser); std::string cache_image_color(float color[4]); } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/scene_delegate/usd_scene_delegate.cc b/source/blender/render/hydra/scene_delegate/usd_scene_delegate.cc index 12122e1125c1..027f1a88f7ed 100644 --- a/source/blender/render/hydra/scene_delegate/usd_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/usd_scene_delegate.cc @@ -42,7 +42,7 @@ USDSceneDelegate::~USDSceneDelegate() BLI_delete(temp_dir_.c_str(), true, true); } -void USDSceneDelegate::populate(Depsgraph *depsgraph, bContext * /*context*/) +void USDSceneDelegate::populate(Depsgraph *depsgraph) { /* TODO: implement MaterialX support in USD exporter. */ const bool use_materialx = !settings_.mx_filename_key.IsEmpty(); diff --git a/source/blender/render/hydra/scene_delegate/usd_scene_delegate.hh b/source/blender/render/hydra/scene_delegate/usd_scene_delegate.hh index df22089bc9ea..0a5c3a64ce0c 100644 --- a/source/blender/render/hydra/scene_delegate/usd_scene_delegate.hh +++ b/source/blender/render/hydra/scene_delegate/usd_scene_delegate.hh @@ -11,7 +11,6 @@ #include "settings.h" struct Depsgraph; -struct bContext; namespace blender::render::hydra { @@ -32,7 +31,7 @@ class USDSceneDelegate { const SceneDelegateSettings &settings_); ~USDSceneDelegate(); - void populate(Depsgraph *depsgraph, bContext *context); + void populate(Depsgraph *depsgraph); }; } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/scene_delegate/volume.cc b/source/blender/render/hydra/scene_delegate/volume.cc index 27586a99e887..fc73a0fd499c 100644 --- a/source/blender/render/hydra/scene_delegate/volume.cc +++ b/source/blender/render/hydra/scene_delegate/volume.cc @@ -30,8 +30,7 @@ void VolumeData::init() field_descriptors_.clear(); Volume *volume = (Volume *)((Object *)this->id)->data; - Main *main = CTX_data_main(scene_delegate_->context); - if (!BKE_volume_load(volume, main)) { + if (!BKE_volume_load(volume, scene_delegate_->bmain)) { return; } filepath_ = BKE_volume_grids_frame_filepath(volume); diff --git a/source/blender/render/hydra/scene_delegate/world.cc b/source/blender/render/hydra/scene_delegate/world.cc index 998a84def18e..e39077126f73 100644 --- a/source/blender/render/hydra/scene_delegate/world.cc +++ b/source/blender/render/hydra/scene_delegate/world.cc @@ -11,14 +11,16 @@ #include #include -#include "BKE_context.h" #include "DNA_node_types.h" +#include "DNA_scene_types.h" + +#include "BLI_math_rotation.h" +#include "BLI_path_util.h" #include "BKE_node.h" #include "BKE_node_runtime.hh" #include "BKE_studiolight.h" -#include "BLI_math_rotation.h" -#include "BLI_path_util.h" + #include "NOD_shader.h" #include "../engine.h" @@ -94,7 +96,7 @@ void WorldData::init() Image *image = (Image *)color_input_node->id; if (image) { std::string image_path = cache_or_get_image_file( - image, scene_delegate_->context, &tex->iuser); + scene_delegate_->bmain, scene_delegate_->scene, image, &tex->iuser); if (!image_path.empty()) { texture_file = pxr::SdfAssetPath(image_path, image_path); } diff --git a/source/blender/render/hydra/viewport_engine.cc b/source/blender/render/hydra/viewport_engine.cc index 4cf6815ff5aa..c2f8b5d2d0c5 100644 --- a/source/blender/render/hydra/viewport_engine.cc +++ b/source/blender/render/hydra/viewport_engine.cc @@ -6,12 +6,16 @@ #include #include "DNA_vec_types.h" /* this include must be before BKE_camera.h due to "rctf" type */ +#include "DNA_view3d_types.h" #include "BKE_camera.h" +#include "BKE_context.h" + #include "BLI_math_matrix.h" #include "BLI_timecode.h" #include "DEG_depsgraph_query.h" #include "DNA_camera_types.h" +#include "DNA_scene_types.h" #include "DNA_screen_types.h" #include "GPU_context.h" @@ -38,7 +42,8 @@ struct ViewSettings { pxr::GfVec4i border; }; -ViewSettings::ViewSettings(bContext *context) : camera_data(context) +ViewSettings::ViewSettings(bContext *context) + : camera_data(CTX_wm_view3d(context), CTX_wm_region(context)) { View3D *view3d = CTX_wm_view3d(context); RegionView3D *region_data = (RegionView3D *)CTX_wm_region_data(context); -- 2.30.2