forked from blender/blender
Move to use blender::Map container instead std::unordered_map #47
@ -1,62 +1,21 @@
|
||||
/* SPDX-License-Identifier: Apache-2.0
|
||||
* Copyright 2011-2022 Blender Foundation */
|
||||
|
||||
#include "DEG_depsgraph_query.h"
|
||||
|
||||
#include "BLI_timer.h"
|
||||
#include "camera.h"
|
||||
#include "preview_engine.h"
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
const double LIFETIME = 180.0;
|
||||
|
||||
std::unique_ptr<PreviewEngine> PreviewEngine::instance_;
|
||||
|
||||
PreviewEngine *PreviewEngine::create(RenderEngine *bl_engine,
|
||||
const std::string &render_delegate_name)
|
||||
{
|
||||
if (!instance_) {
|
||||
instance_ = std::make_unique<PreviewEngine>(bl_engine, render_delegate_name);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
instance_->scene_delegate_->clear();
|
||||
|
||||
if (BLI_timer_is_registered((uintptr_t)&instance_)) {
|
||||
/* Unregister timer while PreviewEngine is working */
|
||||
BLI_timer_unregister((uintptr_t)&instance_);
|
||||
}
|
||||
|
||||
return instance_.get();
|
||||
}
|
||||
|
||||
void PreviewEngine::free()
|
||||
{
|
||||
instance_->render_delegate_->Stop();
|
||||
|
||||
/* Register timer for schedule free PreviewEngine instance */
|
||||
BLI_timer_register((uintptr_t)&instance_, free_instance, nullptr, nullptr, LIFETIME, true);
|
||||
}
|
||||
|
||||
void PreviewEngine::render(Depsgraph *depsgraph)
|
||||
{
|
||||
prepare_for_render(depsgraph);
|
||||
|
||||
std::vector<float> &pixels = render_images_["Combined"];
|
||||
|
||||
{
|
||||
/* Release the GIL before calling into hydra, in case any hydra plugins call into python. */
|
||||
pxr::TF_PY_ALLOW_THREADS_IN_SCOPE();
|
||||
engine_->Execute(render_index_.get(), &tasks_);
|
||||
}
|
||||
|
||||
std::vector<float> &pixels = render_images_["Combined"];
|
||||
while (true) {
|
||||
if (RE_engine_test_break(bl_engine_)) {
|
||||
break;
|
||||
@ -74,18 +33,6 @@ void PreviewEngine::render(Depsgraph *depsgraph)
|
||||
update_render_result(pixels);
|
||||
}
|
||||
|
||||
double PreviewEngine::free_instance(uintptr_t uuid, void *user_data)
|
||||
{
|
||||
if (!instance_->render_task_delegate_->is_converged()) {
|
||||
/* Restart timer if render isn't completed */
|
||||
return LIFETIME;
|
||||
}
|
||||
|
||||
CLOG_INFO(LOG_RENDER_HYDRA, 2, "");
|
||||
instance_ = nullptr;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void PreviewEngine::update_render_result(std::vector<float> &pixels)
|
||||
{
|
||||
RenderResult *result = RE_engine_begin_result(
|
||||
|
@ -9,19 +9,12 @@ namespace blender::render::hydra {
|
||||
|
||||
class PreviewEngine : public FinalEngine {
|
||||
public:
|
||||
static PreviewEngine *create(RenderEngine *bl_engine, const std::string &render_delegate_name);
|
||||
static void free();
|
||||
using FinalEngine::FinalEngine;
|
||||
|
||||
void render(Depsgraph *depsgraph) override;
|
||||
|
||||
private:
|
||||
using FinalEngine::FinalEngine;
|
||||
static double free_instance(uintptr_t uuid, void *user_data);
|
||||
|
||||
void update_render_result(std::vector<float> &pixels);
|
||||
|
||||
/* Singleton class instance */
|
||||
static std::unique_ptr<PreviewEngine> instance_;
|
||||
};
|
||||
|
||||
} // namespace blender::render::hydra
|
||||
|
@ -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::create(bl_engine, render_delegate_id);
|
||||
engine = new PreviewEngine(bl_engine, render_delegate_id);
|
||||
}
|
||||
else {
|
||||
if (bl_engine->type->flag & RE_USE_GPU_CONTEXT) {
|
||||
@ -134,13 +134,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::free();
|
||||
}
|
||||
else {
|
||||
delete engine;
|
||||
}
|
||||
delete engine;
|
||||
|
||||
CLOG_INFO(LOG_RENDER_HYDRA, 2, "Engine %016llx", engine);
|
||||
Py_RETURN_NONE;
|
||||
|
Loading…
Reference in New Issue
Block a user