forked from blender/blender
Recreate PreviewEngine when render_delegate_name is changed #36
@ -25,7 +25,7 @@ Engine::Engine(RenderEngine *bl_engine, const std::string &render_delegate_name)
|
||||
pxr::TF_PY_ALLOW_THREADS_IN_SCOPE();
|
||||
render_delegate_ = registry.CreateRenderDelegate(pxr::TfToken(render_delegate_name_));
|
||||
|
||||
/* Current USD (23.02) has limited support for Vulkan. To make it works USD should be built
|
||||
/* USD has limited support for Vulkan. To make it works USD should be built
|
||||
* with PXR_ENABLE_VULKAN_SUPPORT=TRUE which is not possible now */
|
||||
if (GPU_backend_get_type() == GPU_BACKEND_VULKAN) {
|
||||
BLI_setenv("HGI_ENABLE_VULKAN", "1");
|
||||
|
@ -14,16 +14,16 @@ const double LIFETIME = 180.0;
|
||||
std::unique_ptr<PreviewEngine> PreviewEngine::instance_;
|
||||
|
||||
PreviewEngine *PreviewEngine::get_instance(RenderEngine *bl_engine,
|
||||
const std::string &render_delegate_id)
|
||||
const std::string &render_delegate_name)
|
||||
{
|
||||
if (!instance_) {
|
||||
instance_ = std::make_unique<PreviewEngine>(bl_engine, render_delegate_id);
|
||||
instance_ = std::make_unique<PreviewEngine>(bl_engine, render_delegate_name);
|
||||
}
|
||||
if (BLI_timer_is_registered((uintptr_t)instance_.get())) {
|
||||
/* Unregister timer while PreviewEngine is working */
|
||||
BLI_timer_unregister((uintptr_t)instance_.get());
|
||||
}
|
||||
instance_->update(bl_engine, render_delegate_id);
|
||||
instance_->update(bl_engine, render_delegate_name);
|
||||
|
||||
return instance_.get();
|
||||
}
|
||||
@ -96,10 +96,13 @@ double PreviewEngine::free_instance(uintptr_t uuid, void *user_data)
|
||||
return -1;
|
||||
}
|
||||
|
||||
void PreviewEngine::update(RenderEngine *bl_engine, const std::string &render_delegate_id)
|
||||
void PreviewEngine::update(RenderEngine *bl_engine, const std::string &render_delegate_name)
|
||||
{
|
||||
this->bl_engine_ = bl_engine;
|
||||
/* TODO: recreate render_delegate when render_delegate_id is changed */
|
||||
bl_engine_ = bl_engine;
|
||||
if (render_delegate_name != render_delegate_name_) {
|
||||
render_delegate_->Stop();
|
||||
instance_.reset(new PreviewEngine(bl_engine, render_delegate_name));
|
||||
}
|
||||
}
|
||||
|
||||
void PreviewEngine::update_render_result(std::vector<float> &pixels)
|
||||
|
@ -12,7 +12,7 @@ class PreviewEngine : public FinalEngine {
|
||||
using FinalEngine::FinalEngine;
|
||||
|
||||
static PreviewEngine *get_instance(RenderEngine *bl_engine,
|
||||
const std::string &render_delegate_id);
|
||||
const std::string &render_delegate_name);
|
||||
static void schedule_free();
|
||||
|
||||
void sync(Depsgraph *depsgraph,
|
||||
@ -25,7 +25,7 @@ class PreviewEngine : public FinalEngine {
|
||||
static double free_instance(uintptr_t uuid, void *user_data);
|
||||
static std::unique_ptr<PreviewEngine> instance_;
|
||||
|
||||
void update(RenderEngine *bl_engine, const std::string &render_delegate_id);
|
||||
void update(RenderEngine *bl_engine, const std::string &render_delegate_name);
|
||||
void update_render_result(std::vector<float> &pixels);
|
||||
};
|
||||
|
||||
|
@ -15,7 +15,7 @@ CLG_LOGREF_DECLARE_GLOBAL(LOG_RENDER_HYDRA_SCENE, "render.hydra.scene");
|
||||
BlenderSceneDelegate::BlenderSceneDelegate(pxr::HdRenderIndex *parent_index,
|
||||
pxr::SdfPath const &delegate_id,
|
||||
BlenderSceneDelegate::EngineType engine_type,
|
||||
std::string render_delegate_name)
|
||||
const std::string &render_delegate_name)
|
||||
: HdSceneDelegate(parent_index, delegate_id),
|
||||
engine_type(engine_type),
|
||||
render_delegate_name(render_delegate_name)
|
||||
@ -187,6 +187,11 @@ void BlenderSceneDelegate::clear()
|
||||
objects_.clear();
|
||||
instancers_.clear();
|
||||
materials_.clear();
|
||||
|
||||
depsgraph = nullptr;
|
||||
context = nullptr;
|
||||
scene = nullptr;
|
||||
view3d = nullptr;
|
||||
}
|
||||
|
||||
pxr::SdfPath BlenderSceneDelegate::prim_id(ID *id, const char *prefix) const
|
||||
@ -253,6 +258,8 @@ InstancerData *BlenderSceneDelegate::instancer_data(pxr::SdfPath const &id, bool
|
||||
{
|
||||
pxr::SdfPath p_id;
|
||||
if (child_id) {
|
||||
/* Getting instancer path id from child Mesh instance (consist with 3 path elements) and
|
||||
* Light instance (consist with 4 path elements) */
|
||||
int n = id.GetPathElementCount();
|
||||
if (n == 3) {
|
||||
p_id = id.GetParentPath();
|
||||
|
@ -30,7 +30,7 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
||||
BlenderSceneDelegate(pxr::HdRenderIndex *parent_index,
|
||||
pxr::SdfPath const &delegate_id,
|
||||
BlenderSceneDelegate::EngineType engine_type,
|
||||
std::string render_delegate_name);
|
||||
const std::string &render_delegate_name);
|
||||
~BlenderSceneDelegate() override = default;
|
||||
|
||||
/* Delegate methods */
|
||||
|
Loading…
Reference in New Issue
Block a user