Hydra code cleanup #81

Merged
Bogdan Nagirniak merged 7 commits from hydra-code-cleanup into hydra-render 2023-08-01 21:35:28 +02:00
16 changed files with 96 additions and 106 deletions
Showing only changes of commit bf9221581b - Show all commits

View File

@ -13,7 +13,7 @@
namespace blender::io::hydra { namespace blender::io::hydra {
CLG_LOGREF_DECLARE_GLOBAL(LOG_RENDER_HYDRA_SCENE, "render.hydra.scene"); CLG_LOGREF_DECLARE_GLOBAL(LOG_HYDRA_SCENE, "hydra.scene");
bool HydraSceneDelegate::ShadingSettings::operator==(const ShadingSettings &other) bool HydraSceneDelegate::ShadingSettings::operator==(const ShadingSettings &other)
{ {
@ -38,21 +38,21 @@ HydraSceneDelegate::HydraSceneDelegate(pxr::HdRenderIndex *parent_index,
pxr::HdMeshTopology HydraSceneDelegate::GetMeshTopology(pxr::SdfPath const &id) pxr::HdMeshTopology HydraSceneDelegate::GetMeshTopology(pxr::SdfPath const &id)
{ {
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", id.GetText()); CLOG_INFO(LOG_HYDRA_SCENE, 3, "%s", id.GetText());
MeshData *m_data = mesh_data(id); MeshData *m_data = mesh_data(id);
return m_data->topology(id); return m_data->topology(id);
} }
pxr::HdBasisCurvesTopology HydraSceneDelegate::GetBasisCurvesTopology(pxr::SdfPath const &id) pxr::HdBasisCurvesTopology HydraSceneDelegate::GetBasisCurvesTopology(pxr::SdfPath const &id)
{ {
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", id.GetText()); CLOG_INFO(LOG_HYDRA_SCENE, 3, "%s", id.GetText());
CurvesData *c_data = curves_data(id); CurvesData *c_data = curves_data(id);
return c_data->topology(); return c_data->topology();
}; };
pxr::GfMatrix4d HydraSceneDelegate::GetTransform(pxr::SdfPath const &id) pxr::GfMatrix4d HydraSceneDelegate::GetTransform(pxr::SdfPath const &id)
{ {
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", id.GetText()); CLOG_INFO(LOG_HYDRA_SCENE, 3, "%s", id.GetText());
InstancerData *i_data = instancer_data(id, true); InstancerData *i_data = instancer_data(id, true);
if (i_data) { if (i_data) {
return i_data->transform(id); return i_data->transform(id);
@ -69,7 +69,7 @@ pxr::GfMatrix4d HydraSceneDelegate::GetTransform(pxr::SdfPath const &id)
pxr::VtValue HydraSceneDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const &key) pxr::VtValue HydraSceneDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const &key)
{ {
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s, %s", id.GetText(), key.GetText()); CLOG_INFO(LOG_HYDRA_SCENE, 3, "%s, %s", id.GetText(), key.GetText());
ObjectData *obj_data = object_data(id); ObjectData *obj_data = object_data(id);
if (obj_data) { if (obj_data) {
return obj_data->get_data(id, key); return obj_data->get_data(id, key);
@ -88,7 +88,7 @@ pxr::VtValue HydraSceneDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const
pxr::VtValue HydraSceneDelegate::GetLightParamValue(pxr::SdfPath const &id, pxr::VtValue HydraSceneDelegate::GetLightParamValue(pxr::SdfPath const &id,
pxr::TfToken const &key) pxr::TfToken const &key)
{ {
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s, %s", id.GetText(), key.GetText()); CLOG_INFO(LOG_HYDRA_SCENE, 3, "%s, %s", id.GetText(), key.GetText());
LightData *l_data = light_data(id); LightData *l_data = light_data(id);
if (l_data) { if (l_data) {
return l_data->get_data(key); return l_data->get_data(key);
@ -99,7 +99,7 @@ pxr::VtValue HydraSceneDelegate::GetLightParamValue(pxr::SdfPath const &id,
pxr::HdPrimvarDescriptorVector HydraSceneDelegate::GetPrimvarDescriptors( pxr::HdPrimvarDescriptorVector HydraSceneDelegate::GetPrimvarDescriptors(
pxr::SdfPath const &id, pxr::HdInterpolation interpolation) pxr::SdfPath const &id, pxr::HdInterpolation interpolation)
{ {
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s, %d", id.GetText(), interpolation); CLOG_INFO(LOG_HYDRA_SCENE, 3, "%s, %d", id.GetText(), interpolation);
MeshData *m_data = mesh_data(id); MeshData *m_data = mesh_data(id);
if (m_data) { if (m_data) {
return m_data->primvar_descriptors(interpolation); return m_data->primvar_descriptors(interpolation);
@ -117,7 +117,7 @@ pxr::HdPrimvarDescriptorVector HydraSceneDelegate::GetPrimvarDescriptors(
pxr::SdfPath HydraSceneDelegate::GetMaterialId(pxr::SdfPath const &rprim_id) pxr::SdfPath HydraSceneDelegate::GetMaterialId(pxr::SdfPath const &rprim_id)
{ {
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", rprim_id.GetText()); CLOG_INFO(LOG_HYDRA_SCENE, 3, "%s", rprim_id.GetText());
ObjectData *obj_data = object_data(rprim_id); ObjectData *obj_data = object_data(rprim_id);
if (obj_data) { if (obj_data) {
return obj_data->material_id(rprim_id); return obj_data->material_id(rprim_id);
@ -127,7 +127,7 @@ pxr::SdfPath HydraSceneDelegate::GetMaterialId(pxr::SdfPath const &rprim_id)
pxr::VtValue HydraSceneDelegate::GetMaterialResource(pxr::SdfPath const &id) pxr::VtValue HydraSceneDelegate::GetMaterialResource(pxr::SdfPath const &id)
{ {
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", id.GetText()); CLOG_INFO(LOG_HYDRA_SCENE, 3, "%s", id.GetText());
MaterialData *mat_data = material_data(id); MaterialData *mat_data = material_data(id);
if (mat_data) { if (mat_data) {
return mat_data->get_material_resource(); return mat_data->get_material_resource();
@ -137,7 +137,7 @@ pxr::VtValue HydraSceneDelegate::GetMaterialResource(pxr::SdfPath const &id)
bool HydraSceneDelegate::GetVisible(pxr::SdfPath const &id) bool HydraSceneDelegate::GetVisible(pxr::SdfPath const &id)
{ {
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", id.GetText()); CLOG_INFO(LOG_HYDRA_SCENE, 3, "%s", id.GetText());
if (id == world_prim_id()) { if (id == world_prim_id()) {
return true; return true;
} }
@ -150,19 +150,19 @@ bool HydraSceneDelegate::GetVisible(pxr::SdfPath const &id)
bool HydraSceneDelegate::GetDoubleSided(pxr::SdfPath const &id) bool HydraSceneDelegate::GetDoubleSided(pxr::SdfPath const &id)
{ {
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", id.GetText()); CLOG_INFO(LOG_HYDRA_SCENE, 3, "%s", id.GetText());
return mesh_data(id)->double_sided(id); return mesh_data(id)->double_sided(id);
} }
pxr::HdCullStyle HydraSceneDelegate::GetCullStyle(pxr::SdfPath const &id) pxr::HdCullStyle HydraSceneDelegate::GetCullStyle(pxr::SdfPath const &id)
{ {
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", id.GetText()); CLOG_INFO(LOG_HYDRA_SCENE, 3, "%s", id.GetText());
return mesh_data(id)->cull_style(id); return mesh_data(id)->cull_style(id);
} }
pxr::SdfPath HydraSceneDelegate::GetInstancerId(pxr::SdfPath const &prim_id) pxr::SdfPath HydraSceneDelegate::GetInstancerId(pxr::SdfPath const &prim_id)
{ {
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", prim_id.GetText()); CLOG_INFO(LOG_HYDRA_SCENE, 3, "%s", prim_id.GetText());
InstancerData *i_data = instancer_data(prim_id, true); InstancerData *i_data = instancer_data(prim_id, true);
if (i_data && mesh_data(prim_id)) { if (i_data && mesh_data(prim_id)) {
return i_data->prim_id; return i_data->prim_id;
@ -172,7 +172,7 @@ pxr::SdfPath HydraSceneDelegate::GetInstancerId(pxr::SdfPath const &prim_id)
pxr::SdfPathVector HydraSceneDelegate::GetInstancerPrototypes(pxr::SdfPath const &instancer_id) pxr::SdfPathVector HydraSceneDelegate::GetInstancerPrototypes(pxr::SdfPath const &instancer_id)
{ {
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", instancer_id.GetText()); CLOG_INFO(LOG_HYDRA_SCENE, 3, "%s", instancer_id.GetText());
InstancerData *i_data = instancer_data(instancer_id); InstancerData *i_data = instancer_data(instancer_id);
return i_data->prototypes(); return i_data->prototypes();
} }
@ -180,14 +180,14 @@ pxr::SdfPathVector HydraSceneDelegate::GetInstancerPrototypes(pxr::SdfPath const
pxr::VtIntArray HydraSceneDelegate::GetInstanceIndices(pxr::SdfPath const &instancer_id, pxr::VtIntArray HydraSceneDelegate::GetInstanceIndices(pxr::SdfPath const &instancer_id,
pxr::SdfPath const &prototype_id) pxr::SdfPath const &prototype_id)
{ {
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s, %s", instancer_id.GetText(), prototype_id.GetText()); CLOG_INFO(LOG_HYDRA_SCENE, 3, "%s, %s", instancer_id.GetText(), prototype_id.GetText());
InstancerData *i_data = instancer_data(instancer_id); InstancerData *i_data = instancer_data(instancer_id);
return i_data->indices(prototype_id); return i_data->indices(prototype_id);
} }
pxr::GfMatrix4d HydraSceneDelegate::GetInstancerTransform(pxr::SdfPath const &instancer_id) pxr::GfMatrix4d HydraSceneDelegate::GetInstancerTransform(pxr::SdfPath const &instancer_id)
{ {
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", instancer_id.GetText()); CLOG_INFO(LOG_HYDRA_SCENE, 3, "%s", instancer_id.GetText());
InstancerData *i_data = instancer_data(instancer_id); InstancerData *i_data = instancer_data(instancer_id);
return i_data->transform(instancer_id); return i_data->transform(instancer_id);
} }
@ -195,7 +195,7 @@ pxr::GfMatrix4d HydraSceneDelegate::GetInstancerTransform(pxr::SdfPath const &in
pxr::HdVolumeFieldDescriptorVector HydraSceneDelegate::GetVolumeFieldDescriptors( pxr::HdVolumeFieldDescriptorVector HydraSceneDelegate::GetVolumeFieldDescriptors(
pxr::SdfPath const &volume_id) pxr::SdfPath const &volume_id)
{ {
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", volume_id.GetText()); CLOG_INFO(LOG_HYDRA_SCENE, 3, "%s", volume_id.GetText());
VolumeData *v_data = volume_data(volume_id); VolumeData *v_data = volume_data(volume_id);
return v_data->field_descriptors(); return v_data->field_descriptors();
} }
@ -271,8 +271,8 @@ ObjectData *HydraSceneDelegate::object_data(pxr::SdfPath const &id) const
if (id == world_prim_id()) { if (id == world_prim_id()) {
return world_data_.get(); return world_data_.get();
} }
auto name = id.GetName();
pxr::SdfPath p_id = (id.GetName().find("SM_") == 0 || id.GetName().find("VF_") == 0) ? pxr::SdfPath p_id = (STRPREFIX(name.c_str(), "SM_") || STRPREFIX(name.c_str(), "VF_")) ?
id.GetParentPath() : id.GetParentPath() :
id; id;
auto obj_data = objects_.lookup_ptr(p_id); auto obj_data = objects_.lookup_ptr(p_id);
@ -378,7 +378,7 @@ void HydraSceneDelegate::check_updates()
data.only_updated = true; 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)
{ {
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, CLOG_INFO(LOG_HYDRA_SCENE,
0, 0,
"Update: %s [%s]", "Update: %s [%s]",
id->name, id->name,
@ -459,7 +459,7 @@ void HydraSceneDelegate::update_collection()
continue; continue;
} }
instancer_data_->update_instance(data.dupli_parent, dupli); instancer_data_->update_instance(dupli);
continue; continue;
} }

View File

@ -29,7 +29,7 @@ struct View3D;
namespace blender::io::hydra { namespace blender::io::hydra {
extern struct CLG_LogRef *LOG_RENDER_HYDRA_SCENE; extern struct CLG_LogRef *LOG_HYDRA_SCENE;
class Engine; class Engine;

View File

@ -50,10 +50,10 @@ class IdData {
}; };
#define ID_LOG(level, msg, ...) \ #define ID_LOG(level, msg, ...) \
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, level, "%s: " msg, prim_id.GetText(), ##__VA_ARGS__); CLOG_INFO(LOG_HYDRA_SCENE, level, "%s: " msg, prim_id.GetText(), ##__VA_ARGS__);
#define ID_LOGN(level, msg, ...) \ #define ID_LOGN(level, msg, ...) \
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, \ CLOG_INFO(LOG_HYDRA_SCENE, \
level, \ level, \
"%s (%s): " msg, \ "%s (%s): " msg, \
prim_id.GetText(), \ prim_id.GetText(), \

View File

@ -56,10 +56,10 @@ static std::string cache_image_file(
opts.save_copy = true; opts.save_copy = true;
STRNCPY(opts.filepath, file_path.c_str()); STRNCPY(opts.filepath, file_path.c_str());
if (BKE_image_save(nullptr, bmain, 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()); CLOG_INFO(LOG_HYDRA_SCENE, 1, "%s -> %s", image->id.name, file_path.c_str());
} }
else { else {
CLOG_ERROR(LOG_RENDER_HYDRA_SCENE, "Can't save %s", file_path.c_str()); CLOG_ERROR(LOG_HYDRA_SCENE, "Can't save %s", file_path.c_str());
file_path = ""; file_path = "";
} }
} }
@ -86,7 +86,7 @@ std::string cache_or_get_image_file(Main *bmain, Scene *scene, Image *image, Ima
} }
} }
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 1, "%s -> %s", image->id.name, file_path.c_str()); CLOG_INFO(LOG_HYDRA_SCENE, 1, "%s -> %s", image->id.name, file_path.c_str());
return file_path; return file_path;
} }
@ -109,10 +109,10 @@ std::string cache_image_color(float color[4])
ibuf->ftype = IMB_FTYPE_RADHDR; ibuf->ftype = IMB_FTYPE_RADHDR;
if (IMB_saveiff(ibuf, file_path.c_str(), IB_rectfloat)) { if (IMB_saveiff(ibuf, file_path.c_str(), IB_rectfloat)) {
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 1, "%s", file_path.c_str()); CLOG_INFO(LOG_HYDRA_SCENE, 1, "%s", file_path.c_str());
} }
else { else {
CLOG_ERROR(LOG_RENDER_HYDRA_SCENE, "Can't save %s", file_path.c_str()); CLOG_ERROR(LOG_HYDRA_SCENE, "Can't save %s", file_path.c_str());
file_path = ""; file_path = "";
} }
IMB_freeImBuf(ibuf); IMB_freeImBuf(ibuf);

View File

@ -23,7 +23,7 @@ void InstancerData::insert() {}
void InstancerData::remove() void InstancerData::remove()
{ {
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 1, "%s", prim_id.GetText()); CLOG_INFO(LOG_HYDRA_SCENE, 1, "%s", prim_id.GetText());
for (auto &m_inst : mesh_instances_.values()) { for (auto &m_inst : mesh_instances_.values()) {
m_inst.data->remove(); m_inst.data->remove();
} }
@ -129,7 +129,7 @@ void InstancerData::pre_update()
} }
} }
void InstancerData::update_instance(Object * /* parent_ob */, DupliObject *dupli) void InstancerData::update_instance(DupliObject *dupli)
{ {
Object *object = dupli->ob; Object *object = dupli->ob;
pxr::SdfPath p_id = object_prim_id(object); pxr::SdfPath p_id = object_prim_id(object);

View File

@ -51,7 +51,7 @@ class InstancerData : public IdData {
... ...
post_update() */ post_update() */
void pre_update(); void pre_update();
void update_instance(Object *parent_ob, DupliObject *dupli); void update_instance(DupliObject *dupli);
void post_update(); void post_update();
private: private:

View File

@ -155,28 +155,28 @@ pxr::TfToken LightData::prim_type(Light *light)
switch (light->area_shape) { switch (light->area_shape) {
case LA_AREA_SQUARE: case LA_AREA_SQUARE:
case LA_AREA_RECT: case LA_AREA_RECT:
return pxr::TfToken(pxr::HdPrimTypeTokens->rectLight); return pxr::HdPrimTypeTokens->rectLight;
case LA_AREA_DISK: case LA_AREA_DISK:
case LA_AREA_ELLIPSE: case LA_AREA_ELLIPSE:
return pxr::TfToken(pxr::HdPrimTypeTokens->diskLight); return pxr::HdPrimTypeTokens->diskLight;
default: default:
return pxr::TfToken(pxr::HdPrimTypeTokens->rectLight); return pxr::HdPrimTypeTokens->rectLight;
} }
break; break;
case LA_LOCAL: case LA_LOCAL:
case LA_SPOT: case LA_SPOT:
return pxr::TfToken(pxr::HdPrimTypeTokens->sphereLight); return pxr::HdPrimTypeTokens->sphereLight;
case LA_SUN: case LA_SUN:
return pxr::TfToken(pxr::HdPrimTypeTokens->distantLight); return pxr::HdPrimTypeTokens->distantLight;
default: default:
BLI_assert_unreachable(); BLI_assert_unreachable();
return pxr::TfToken(pxr::HdPrimTypeTokens->sphereLight);
} }
return pxr::TfToken();
} }
} // namespace blender::io::hydra } // namespace blender::io::hydra

View File

@ -151,7 +151,7 @@ void MaterialData::export_mtlx()
err_str += PyUnicode_AsUTF8(pstr); err_str += PyUnicode_AsUTF8(pstr);
Py_DECREF(pstr); Py_DECREF(pstr);
} }
CLOG_ERROR(LOG_RENDER_HYDRA_SCENE, CLOG_ERROR(LOG_HYDRA_SCENE,
"Export error for %s (%s): %s", "Export error for %s (%s): %s",
prim_id.GetText(), prim_id.GetText(),
id->name, id->name,

View File

@ -50,7 +50,7 @@ void VolumeModifierData::init()
scene_delegate_->depsgraph, object, md); scene_delegate_->depsgraph, object, md);
if ((modifier_->domain->cache_data_format & FLUID_DOMAIN_FILE_OPENVDB) == 0) { if ((modifier_->domain->cache_data_format & FLUID_DOMAIN_FILE_OPENVDB) == 0) {
CLOG_WARN(LOG_RENDER_HYDRA_SCENE, CLOG_WARN(LOG_HYDRA_SCENE,
"Volume %s is't exported: only OpenVDB file format supported", "Volume %s is't exported: only OpenVDB file format supported",
prim_id.GetText()); prim_id.GetText());
return; return;

View File

@ -24,7 +24,7 @@
namespace blender::render::hydra { namespace blender::render::hydra {
CLG_LOGREF_DECLARE_GLOBAL(LOG_RENDER_HYDRA, "render.hydra"); CLG_LOGREF_DECLARE_GLOBAL(LOG_HYDRA_RENDER, "hydra.render");
Engine::Engine(RenderEngine *bl_engine, const std::string &render_delegate_name) Engine::Engine(RenderEngine *bl_engine, const std::string &render_delegate_name)
: render_delegate_name_(render_delegate_name), bl_engine_(bl_engine) : render_delegate_name_(render_delegate_name), bl_engine_(bl_engine)
@ -78,9 +78,11 @@ Engine::Engine(RenderEngine *bl_engine, const std::string &render_delegate_name)
void Engine::sync(Depsgraph *depsgraph, bContext *context) void Engine::sync(Depsgraph *depsgraph, bContext *context)
{ {
const Scene *scene = DEG_get_evaluated_scene(depsgraph); depsgraph_ = depsgraph;
context_ = context;
scene_ = DEG_get_evaluated_scene(depsgraph);
if (scene->hydra.export_method == SCE_HYDRA_EXPORT_HYDRA) { if (scene_->hydra.export_method == SCE_HYDRA_EXPORT_HYDRA) {
/* Fast path. */ /* Fast path. */
usd_scene_delegate_.reset(); usd_scene_delegate_.reset();
@ -128,7 +130,7 @@ float Engine::renderer_percent_done()
pxr::VtDictionary render_stats = render_delegate_->GetRenderStats(); pxr::VtDictionary render_stats = render_delegate_->GetRenderStats();
auto it = render_stats.find("percentDone"); auto it = render_stats.find("percentDone");
if (it == render_stats.end()) { if (it == render_stats.end()) {
return 0.0; return 0.0f;
} }
return (float)it->second.UncheckedGet<double>(); return (float)it->second.UncheckedGet<double>();
} }

View File

@ -27,12 +27,15 @@ struct CLG_LogRef;
namespace blender::render::hydra { namespace blender::render::hydra {
extern struct CLG_LogRef *LOG_RENDER_HYDRA; extern struct CLG_LogRef *LOG_HYDRA_RENDER;
class Engine { class Engine {
protected: protected:
std::string render_delegate_name_; std::string render_delegate_name_;
RenderEngine *bl_engine_ = nullptr; RenderEngine *bl_engine_ = nullptr;
Depsgraph *depsgraph_ = nullptr;
bContext *context_ = nullptr;
Scene *scene_ = nullptr;
/* The order is important due to deletion order */ /* The order is important due to deletion order */
pxr::HgiUniquePtr hgi_; pxr::HgiUniquePtr hgi_;
@ -54,13 +57,14 @@ class Engine {
virtual ~Engine() = default; virtual ~Engine() = default;
void sync(Depsgraph *depsgraph, bContext *context); void sync(Depsgraph *depsgraph, bContext *context);
virtual void render(Depsgraph *depsgraph) = 0; virtual void render() = 0;
void set_sync_setting(const std::string &key, const pxr::VtValue &val); void set_sync_setting(const std::string &key, const pxr::VtValue &val);
void set_render_setting(const std::string &key, const pxr::VtValue &val); void set_render_setting(const std::string &key, const pxr::VtValue &val);
protected: protected:
float renderer_percent_done(); float renderer_percent_done();
virtual void notify_status(float progress, const std::string &title, const std::string &info) = 0;
}; };
} // namespace blender::render::hydra } // namespace blender::render::hydra

View File

@ -23,19 +23,14 @@
namespace blender::render::hydra { namespace blender::render::hydra {
/* FinalEngine implementation */ void FinalEngine::render()
void FinalEngine::render(Depsgraph *depsgraph)
{ {
const Scene *scene = DEG_get_evaluated_scene(depsgraph); const ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph_);
const ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph);
char scene_name[MAX_ID_FULL_NAME]; char scene_name[MAX_ID_FULL_NAME];
BKE_id_full_name_get(scene_name, &scene->id, 0); BKE_id_full_name_get(scene_name, &scene_->id, 0);
scene_name_ = scene_name;
layer_name_ = view_layer->name;
const RenderData &r = scene->r; const RenderData &r = scene_->r;
pxr::GfVec4f border(0, 0, 1, 1); pxr::GfVec4f border(0, 0, 1, 1);
if (r.mode & R_BORDER) { if (r.mode & R_BORDER) {
border.Set(r.border.xmin, border.Set(r.border.xmin,
@ -44,14 +39,15 @@ void FinalEngine::render(Depsgraph *depsgraph)
r.border.ymax - r.border.ymin); r.border.ymax - r.border.ymin);
} }
pxr::GfVec2i image_res(r.xsch * r.size / 100, r.ysch * r.size / 100); pxr::GfVec2i image_res(r.xsch * r.size / 100, r.ysch * r.size / 100);
resolution_ = pxr::GfVec2i(int(image_res[0] * border[2]), int(image_res[1] * border[3])); int width = image_res[0] * border[2];
int height = image_res[1] * border[3];
pxr::GfCamera camera = pxr::GfCamera camera =
io::hydra::CameraData(scene->camera, image_res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(border); io::hydra::CameraData(scene_->camera, image_res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(border);
free_camera_delegate_->SetCamera(camera); free_camera_delegate_->SetCamera(camera);
render_task_delegate_->set_viewport(pxr::GfVec4d(0, 0, resolution_[0], resolution_[1])); render_task_delegate_->set_viewport(pxr::GfVec4d(0, 0, width, height));
if (light_tasks_delegate_) { if (light_tasks_delegate_) {
light_tasks_delegate_->set_viewport(pxr::GfVec4d(0, 0, resolution_[0], resolution_[1])); light_tasks_delegate_->set_viewport(pxr::GfVec4d(0, 0, width, height));
} }
render_task_delegate_->add_aov(pxr::HdAovTokens->color); render_task_delegate_->add_aov(pxr::HdAovTokens->color);
@ -61,7 +57,7 @@ void FinalEngine::render(Depsgraph *depsgraph)
pxr::HdTaskSharedPtrVector tasks; pxr::HdTaskSharedPtrVector tasks;
if (light_tasks_delegate_) { if (light_tasks_delegate_) {
if (scene->r.alphamode != R_ALPHAPREMUL) { if (scene_->r.alphamode != R_ALPHAPREMUL) {
tasks.push_back(light_tasks_delegate_->skydome_task()); tasks.push_back(light_tasks_delegate_->skydome_task());
} }
tasks.push_back(light_tasks_delegate_->simple_task()); tasks.push_back(light_tasks_delegate_->simple_task());
@ -82,7 +78,7 @@ void FinalEngine::render(Depsgraph *depsgraph)
BLI_timecode_string_from_time_simple( BLI_timecode_string_from_time_simple(
elapsed_time, sizeof(elapsed_time), PIL_check_seconds_timer() - time_begin); elapsed_time, sizeof(elapsed_time), PIL_check_seconds_timer() - time_begin);
notify_status(percent_done / 100.0, notify_status(percent_done / 100.0,
scene_name_ + ": " + layer_name_, std::string(scene_name) + ": " + view_layer->name,
std::string("Render Time: ") + elapsed_time + std::string("Render Time: ") + elapsed_time +
" | Done: " + std::to_string(int(percent_done)) + "%"); " | Done: " + std::to_string(int(percent_done)) + "%");
@ -90,10 +86,10 @@ void FinalEngine::render(Depsgraph *depsgraph)
break; break;
} }
update_render_result(); update_render_result(width, height, view_layer->name);
} }
update_render_result(); update_render_result(width, height, view_layer->name);
render_task_delegate_->unbind(); render_task_delegate_->unbind();
} }
@ -103,13 +99,12 @@ void FinalEngine::notify_status(float progress, const std::string &title, const
RE_engine_update_stats(bl_engine_, title.c_str(), info.c_str()); RE_engine_update_stats(bl_engine_, title.c_str(), info.c_str());
} }
void FinalEngine::update_render_result() void FinalEngine::update_render_result(int width, int height, const char *layer_name)
{ {
RenderResult *rr = RE_engine_begin_result( RenderResult *rr = RE_engine_begin_result(bl_engine_, 0, 0, width, height, layer_name, nullptr);
bl_engine_, 0, 0, resolution_[0], resolution_[1], layer_name_.c_str(), nullptr);
RenderLayer *rlayer = static_cast<RenderLayer *>( RenderLayer *rlayer = static_cast<RenderLayer *>(
BLI_findstring(&rr->layers, layer_name_.c_str(), offsetof(RenderLayer, name))); BLI_findstring(&rr->layers, layer_name, offsetof(RenderLayer, name)));
if (rlayer) { if (rlayer) {
LISTBASE_FOREACH (RenderPass *, rpass, &rlayer->passes) { LISTBASE_FOREACH (RenderPass *, rpass, &rlayer->passes) {

View File

@ -8,19 +8,16 @@
namespace blender::render::hydra { namespace blender::render::hydra {
class FinalEngine : public Engine { class FinalEngine : public Engine {
protected:
std::string scene_name_;
std::string layer_name_;
pxr::GfVec2i resolution_;
public: public:
using Engine::Engine; using Engine::Engine;
void render(Depsgraph *depsgraph) override; void render() override;
protected: protected:
virtual void notify_status(float progress, const std::string &title, const std::string &info); void notify_status(float progress, const std::string &title, const std::string &info) override;
void update_render_result();
private:
void update_render_result(int width, int height, const char *layer_name);
}; };
} // namespace blender::render::hydra } // namespace blender::render::hydra

View File

@ -50,11 +50,11 @@ static PyObject *engine_create_func(PyObject * /*self*/, PyObject *args)
} }
} }
catch (std::runtime_error &e) { catch (std::runtime_error &e) {
CLOG_ERROR(LOG_RENDER_HYDRA, "%s", e.what()); CLOG_ERROR(LOG_HYDRA_RENDER, "%s", e.what());
} }
if (engine) { if (engine) {
CLOG_INFO(LOG_RENDER_HYDRA, 1, "Engine %p %s", engine, engine_type); CLOG_INFO(LOG_HYDRA_RENDER, 1, "Engine %p %s", engine, engine_type);
} }
return PyLong_FromVoidPtr(engine); return PyLong_FromVoidPtr(engine);
} }
@ -69,7 +69,7 @@ static PyObject *engine_free_func(PyObject * /*self*/, PyObject *args)
Engine *engine = static_cast<Engine *>(PyLong_AsVoidPtr(pyengine)); Engine *engine = static_cast<Engine *>(PyLong_AsVoidPtr(pyengine));
delete engine; delete engine;
CLOG_INFO(LOG_RENDER_HYDRA, 1, "Engine %p", engine); CLOG_INFO(LOG_HYDRA_RENDER, 1, "Engine %p", engine);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -84,7 +84,7 @@ static PyObject *engine_update_func(PyObject * /*self*/, PyObject *args)
Depsgraph *depsgraph = pyrna_to_pointer<Depsgraph>(pydepsgraph, &RNA_Depsgraph); Depsgraph *depsgraph = pyrna_to_pointer<Depsgraph>(pydepsgraph, &RNA_Depsgraph);
bContext *context = pyrna_to_pointer<bContext>(pycontext, &RNA_Context); bContext *context = pyrna_to_pointer<bContext>(pycontext, &RNA_Context);
CLOG_INFO(LOG_RENDER_HYDRA, 2, "Engine %p", engine); CLOG_INFO(LOG_HYDRA_RENDER, 2, "Engine %p", engine);
engine->sync(depsgraph, context); engine->sync(depsgraph, context);
Py_RETURN_NONE; Py_RETURN_NONE;
@ -93,19 +93,17 @@ static PyObject *engine_update_func(PyObject * /*self*/, PyObject *args)
static PyObject *engine_render_func(PyObject * /*self*/, PyObject *args) static PyObject *engine_render_func(PyObject * /*self*/, PyObject *args)
{ {
PyObject *pyengine, *pydepsgraph; PyObject *pyengine, *pydepsgraph;
if (!PyArg_ParseTuple(args, "OO", &pyengine, &pydepsgraph)) { if (!PyArg_ParseTuple(args, "OO", &pyengine, &pydepsgraph)) {
Py_RETURN_NONE; Py_RETURN_NONE;
} }
Engine *engine = static_cast<Engine *>(PyLong_AsVoidPtr(pyengine)); Engine *engine = static_cast<Engine *>(PyLong_AsVoidPtr(pyengine));
Depsgraph *depsgraph = pyrna_to_pointer<Depsgraph>(pydepsgraph, &RNA_Depsgraph);
CLOG_INFO(LOG_RENDER_HYDRA, 2, "Engine %p", engine); CLOG_INFO(LOG_HYDRA_RENDER, 2, "Engine %p", engine);
/* Allow Blender to execute other Python scripts. */ /* Allow Blender to execute other Python scripts. */
Py_BEGIN_ALLOW_THREADS; Py_BEGIN_ALLOW_THREADS;
engine->render(depsgraph); engine->render();
Py_END_ALLOW_THREADS; Py_END_ALLOW_THREADS;
Py_RETURN_NONE; Py_RETURN_NONE;
@ -119,14 +117,12 @@ static PyObject *engine_view_draw_func(PyObject * /*self*/, PyObject *args)
} }
ViewportEngine *engine = static_cast<ViewportEngine *>(PyLong_AsVoidPtr(pyengine)); ViewportEngine *engine = static_cast<ViewportEngine *>(PyLong_AsVoidPtr(pyengine));
Depsgraph *depsgraph = pyrna_to_pointer<Depsgraph>(pydepsgraph, &RNA_Depsgraph);
bContext *context = pyrna_to_pointer<bContext>(pycontext, &RNA_Context);
CLOG_INFO(LOG_RENDER_HYDRA, 3, "Engine %p", engine); CLOG_INFO(LOG_HYDRA_RENDER, 3, "Engine %p", engine);
/* Allow Blender to execute other Python scripts. */ /* Allow Blender to execute other Python scripts. */
Py_BEGIN_ALLOW_THREADS; Py_BEGIN_ALLOW_THREADS;
engine->render(depsgraph, context); engine->render();
Py_END_ALLOW_THREADS; Py_END_ALLOW_THREADS;
Py_RETURN_NONE; Py_RETURN_NONE;
@ -160,7 +156,7 @@ static PyObject *engine_set_sync_setting_func(PyObject * /*self*/, PyObject *arg
Engine *engine = static_cast<Engine *>(PyLong_AsVoidPtr(pyengine)); Engine *engine = static_cast<Engine *>(PyLong_AsVoidPtr(pyengine));
CLOG_INFO(LOG_RENDER_HYDRA, 3, "Engine %p: %s", engine, key); CLOG_INFO(LOG_HYDRA_RENDER, 3, "Engine %p: %s", engine, key);
engine->set_sync_setting(key, get_setting_val(pyval)); engine->set_sync_setting(key, get_setting_val(pyval));
Py_RETURN_NONE; Py_RETURN_NONE;
@ -176,7 +172,7 @@ static PyObject *engine_set_render_setting_func(PyObject * /*self*/, PyObject *a
Engine *engine = static_cast<Engine *>(PyLong_AsVoidPtr(pyengine)); Engine *engine = static_cast<Engine *>(PyLong_AsVoidPtr(pyengine));
CLOG_INFO(LOG_RENDER_HYDRA, 3, "Engine %p: %s", engine, key); CLOG_INFO(LOG_HYDRA_RENDER, 3, "Engine %p: %s", engine, key);
engine->set_render_setting(key, get_setting_val(pyval)); engine->set_render_setting(key, get_setting_val(pyval));
Py_RETURN_NONE; Py_RETURN_NONE;

View File

@ -212,15 +212,9 @@ GPUTexture *DrawTexture::texture() const
return texture_; return texture_;
} }
void ViewportEngine::render(Depsgraph * /* depsgraph */) void ViewportEngine::render()
{ {
/* Empty function */ ViewSettings view_settings(context_);
}
void ViewportEngine::render(Depsgraph *depsgraph, bContext *context)
{
ViewSettings view_settings(context);
const Scene *scene = DEG_get_evaluated_scene(depsgraph);
if (view_settings.width() * view_settings.height() == 0) { if (view_settings.width() * view_settings.height() == 0) {
return; return;
}; };
@ -254,7 +248,7 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context)
pxr::HdTaskSharedPtrVector tasks; pxr::HdTaskSharedPtrVector tasks;
if (light_tasks_delegate_) { if (light_tasks_delegate_) {
if (scene->r.alphamode != R_ALPHAPREMUL) { if (scene_->r.alphamode != R_ALPHAPREMUL) {
tasks.push_back(light_tasks_delegate_->skydome_task()); tasks.push_back(light_tasks_delegate_->skydome_task());
} }
tasks.push_back(light_tasks_delegate_->simple_task()); tasks.push_back(light_tasks_delegate_->simple_task());
@ -283,18 +277,21 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context)
BLI_timecode_string_from_time_simple( BLI_timecode_string_from_time_simple(
elapsed_time, sizeof(elapsed_time), PIL_check_seconds_timer() - time_begin_); elapsed_time, sizeof(elapsed_time), PIL_check_seconds_timer() - time_begin_);
float percent_done = renderer_percent_done();
if (!render_task_delegate_->is_converged()) { if (!render_task_delegate_->is_converged()) {
notify_status(std::string("Time: ") + elapsed_time + notify_status(percent_done / 100.0,
" | Done: " + std::to_string(int(renderer_percent_done())) + "%", std ::string("Time: ") + elapsed_time +
" | Done: " + std::to_string(int(percent_done)) + "%",
"Render"); "Render");
bl_engine_->flag |= RE_ENGINE_DO_DRAW; bl_engine_->flag |= RE_ENGINE_DO_DRAW;
} }
else { else {
notify_status((std::string("Time: ") + elapsed_time).c_str(), "Rendering Done"); notify_status(percent_done / 100.0, std::string("Time: ") + elapsed_time, "Rendering Done");
} }
} }
void ViewportEngine::notify_status(const std::string &info, const std::string &status) void ViewportEngine::notify_status(float /*progress*/, const std::string &info,
const std::string &status)
{ {
RE_engine_update_stats(bl_engine_, status.c_str(), info.c_str()); RE_engine_update_stats(bl_engine_, status.c_str(), info.c_str());
} }

View File

@ -38,11 +38,10 @@ class ViewportEngine : public Engine {
public: public:
using Engine::Engine; using Engine::Engine;
void render(Depsgraph *depsgraph) override; void render() override;
void render(Depsgraph *depsgraph, bContext *context);
private: protected:
void notify_status(const std::string &title, const std::string &info); void notify_status(float progress, const std::string &title, const std::string &info) override;
}; };
} // namespace blender::render::hydra } // namespace blender::render::hydra