Recreate PreviewEngine when render_delegate_name is changed #36

Merged
Bogdan Nagirniak merged 6 commits from BLEN-404 into hydra-render 2023-05-05 14:49:30 +02:00
2 changed files with 14 additions and 8 deletions
Showing only changes of commit 7c64910a27 - Show all commits

View File

@ -1,6 +1,9 @@
/* SPDX-License-Identifier: Apache-2.0
* Copyright 2011-2022 Blender Foundation */
#include <pxr/imaging/hd/rendererPluginRegistry.h>
#include <pxr/imaging/hgi/tokens.h>
#include "DEG_depsgraph_query.h"
#include "BLI_timer.h"
@ -14,16 +17,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 +99,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)

View File

@ -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);
};