forked from blender/blender
Create possibility to provide render settings via BlenderSceneDelegate #41
@ -56,6 +56,11 @@ Engine::Engine(RenderEngine *bl_engine, const std::string &render_delegate_name)
|
||||
engine_ = std::make_unique<pxr::HdEngine>();
|
||||
}
|
||||
|
||||
void Engine::sync(Depsgraph *depsgraph, bContext *context)
|
||||
{
|
||||
scene_delegate_->populate(depsgraph, context);
|
||||
}
|
||||
|
||||
void Engine::set_sync_setting(const std::string &key, const pxr::VtValue &val)
|
||||
{
|
||||
scene_delegate_->set_setting(key, val);
|
||||
|
@ -28,7 +28,7 @@ class Engine {
|
||||
Engine(RenderEngine *bl_engine, const std::string &render_delegate_name);
|
||||
virtual ~Engine() = default;
|
||||
|
||||
virtual void sync(Depsgraph *depsgraph, bContext *context) = 0;
|
||||
void sync(Depsgraph *depsgraph, bContext *context);
|
||||
virtual void render(Depsgraph *depsgraph) = 0;
|
||||
|
||||
void set_sync_setting(const std::string &key, const pxr::VtValue &val);
|
||||
|
@ -13,11 +13,6 @@
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
void FinalEngine::sync(Depsgraph *depsgraph, bContext *context)
|
||||
{
|
||||
scene_delegate_->populate(depsgraph, context);
|
||||
}
|
||||
|
||||
void FinalEngine::render(Depsgraph *depsgraph)
|
||||
{
|
||||
prepare_for_render(depsgraph);
|
||||
|
@ -11,8 +11,7 @@ class FinalEngine : public Engine {
|
||||
public:
|
||||
using Engine::Engine;
|
||||
|
||||
virtual void sync(Depsgraph *depsgraph, bContext *context) override;
|
||||
virtual void render(Depsgraph *b_depsgraph) override;
|
||||
void render(Depsgraph *b_depsgraph) override;
|
||||
|
||||
protected:
|
||||
void update_render_result();
|
||||
|
@ -13,33 +13,35 @@ const double LIFETIME = 180.0;
|
||||
|
||||
std::unique_ptr<PreviewEngine> PreviewEngine::instance_;
|
||||
|
||||
PreviewEngine *PreviewEngine::get_instance(RenderEngine *bl_engine,
|
||||
PreviewEngine *PreviewEngine::create(RenderEngine *bl_engine,
|
||||
const std::string &render_delegate_name)
|
||||
{
|
||||
if (!instance_) {
|
||||
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());
|
||||
else if (instance_->render_delegate_name != render_delegate_name) {
|
||||
instance_->render_delegate_->Stop();
|
||||
instance_ = std::make_unique<PreviewEngine>(bl_engine, render_delegate_name);
|
||||
}
|
||||
else {
|
||||
instance_->bl_engine_ = bl_engine;
|
||||
}
|
||||
|
||||
if (BLI_timer_is_registered((uintptr_t)&instance_)) {
|
||||
/* Unregister timer while PreviewEngine is working */
|
||||
BLI_timer_unregister((uintptr_t)&instance_);
|
||||
}
|
||||
instance_->update(bl_engine, render_delegate_name);
|
||||
|
||||
return instance_.get();
|
||||
}
|
||||
|
||||
void PreviewEngine::schedule_free()
|
||||
void PreviewEngine::free()
|
||||
{
|
||||
instance_->render_delegate_->Stop();
|
||||
instance_->scene_delegate_->clear();
|
||||
|
||||
/* Register timer for schedule free PreviewEngine instance */
|
||||
BLI_timer_register((uintptr_t)instance_.get(), free_instance, nullptr, nullptr, LIFETIME, true);
|
||||
}
|
||||
|
||||
void PreviewEngine::sync(Depsgraph *depsgraph, bContext *context)
|
||||
{
|
||||
scene_delegate_->clear();
|
||||
scene_delegate_->populate(depsgraph, context);
|
||||
BLI_timer_register((uintptr_t)&instance_, free_instance, nullptr, nullptr, LIFETIME, true);
|
||||
}
|
||||
|
||||
void PreviewEngine::render(Depsgraph *depsgraph)
|
||||
@ -83,15 +85,6 @@ double PreviewEngine::free_instance(uintptr_t uuid, void *user_data)
|
||||
return -1;
|
||||
}
|
||||
|
||||
void PreviewEngine::update(RenderEngine *bl_engine, const std::string &render_delegate_name)
|
||||
{
|
||||
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)
|
||||
{
|
||||
RenderResult *result = RE_engine_begin_result(
|
||||
|
@ -9,18 +9,15 @@ namespace blender::render::hydra {
|
||||
|
||||
class PreviewEngine : public FinalEngine {
|
||||
public:
|
||||
using FinalEngine::FinalEngine;
|
||||
static PreviewEngine *get_instance(RenderEngine *bl_engine,
|
||||
const std::string &render_delegate_name);
|
||||
static void schedule_free();
|
||||
static PreviewEngine *create(RenderEngine *bl_engine, const std::string &render_delegate_name);
|
||||
static void free();
|
||||
|
||||
void sync(Depsgraph *depsgraph, bContext *context) override;
|
||||
void render(Depsgraph *depsgraph) override;
|
||||
|
||||
private:
|
||||
using FinalEngine::FinalEngine;
|
||||
|
||||
static double free_instance(uintptr_t uuid, void *user_data);
|
||||
|
||||
void update(RenderEngine *bl_engine, const std::string &render_delegate_name);
|
||||
void update_render_result(std::vector<float> &pixels);
|
||||
|
||||
/* Singleton class instance */
|
||||
|
@ -111,7 +111,7 @@ static PyObject *engine_create_func(PyObject * /*self*/, PyObject *args)
|
||||
engine = new ViewportEngine(bl_engine, render_delegate_id);
|
||||
}
|
||||
else if (STREQ(engine_type, "PREVIEW")) {
|
||||
engine = PreviewEngine::get_instance(bl_engine, render_delegate_id);
|
||||
engine = PreviewEngine::create(bl_engine, render_delegate_id);
|
||||
}
|
||||
else {
|
||||
if (bl_engine->type->flag & RE_USE_GPU_CONTEXT) {
|
||||
@ -136,7 +136,7 @@ static PyObject *engine_free_func(PyObject * /*self*/, PyObject *args)
|
||||
Engine *engine = (Engine *)PyLong_AsVoidPtr(pyengine);
|
||||
PreviewEngine *preview_engine = dynamic_cast<PreviewEngine *>(engine);
|
||||
if (preview_engine) {
|
||||
PreviewEngine::schedule_free();
|
||||
PreviewEngine::free();
|
||||
}
|
||||
else {
|
||||
delete engine;
|
||||
|
@ -217,11 +217,6 @@ void DrawTexture::free()
|
||||
texture_ = nullptr;
|
||||
}
|
||||
|
||||
void ViewportEngine::sync(Depsgraph *depsgraph, bContext *context)
|
||||
{
|
||||
scene_delegate_->populate(depsgraph, context);
|
||||
}
|
||||
|
||||
void ViewportEngine::render(Depsgraph *depsgraph)
|
||||
{
|
||||
/* Empty function */
|
||||
|
@ -34,7 +34,6 @@ class ViewportEngine : public Engine {
|
||||
public:
|
||||
using Engine::Engine;
|
||||
|
||||
void sync(Depsgraph *depsgraph, bContext *context) override;
|
||||
void render(Depsgraph *depsgraph) override;
|
||||
void render(Depsgraph *depsgraph, bContext *context);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user
Why did you move it here?
PreviewEngine
should be created viaPreviewEngine::create()
therefore constructor moved to private section.