forked from blender/blender
BLEN-365: Improve creation algorithm of PreviewEngine #21
@ -54,12 +54,6 @@ Engine::~Engine()
|
||||
render_delegate = nullptr;
|
||||
engine = nullptr;
|
||||
hgi = nullptr;
|
||||
bl_engine = nullptr;
|
||||
}
|
||||
|
||||
bool Engine::is_converged()
|
||||
{
|
||||
return render_task_delegate->is_converged();
|
||||
}
|
||||
DagerD marked this conversation as resolved
Outdated
|
||||
|
||||
float Engine::renderer_percent_done()
|
||||
|
@ -34,7 +34,6 @@ class Engine {
|
||||
bContext *context,
|
||||
pxr::HdRenderSettingsMap &render_settings) = 0;
|
||||
virtual void render(Depsgraph *depsgraph) = 0;
|
||||
bool is_converged();
|
||||
|
||||
protected:
|
||||
float renderer_percent_done();
|
||||
|
@ -5,9 +5,38 @@
|
||||
|
||||
#include "camera.h"
|
||||
#include "preview_engine.h"
|
||||
#include "BLI_timer.h"
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
std::unique_ptr<PreviewEngine> PreviewEngine::preview_engine;
|
||||
|
||||
void PreviewEngine::free()
|
||||
{
|
||||
if (preview_engine) {
|
||||
BLI_timer_register((uintptr_t)preview_engine.get(),
|
||||
DagerD marked this conversation as resolved
Outdated
Bogdan Nagirniak
commented
Move this to clear() Move this to clear()
|
||||
preview_engine->delete_preview_engine,
|
||||
&preview_engine,
|
||||
nullptr,
|
||||
preview_engine->preview_engine_lifetime,
|
||||
true);
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<PreviewEngine> *PreviewEngine::get(RenderEngine *bl_engine,
|
||||
char *render_delegate_id)
|
||||
{
|
||||
if (!preview_engine) {
|
||||
preview_engine = std::make_unique<PreviewEngine>(bl_engine, render_delegate_id);
|
||||
}
|
||||
if (BLI_timer_is_registered((uintptr_t)preview_engine.get())) {
|
||||
BLI_timer_unregister((uintptr_t)preview_engine.get());
|
||||
}
|
||||
preview_engine->update_bl_engine(bl_engine);
|
||||
|
||||
return &preview_engine;
|
||||
}
|
||||
|
||||
void PreviewEngine::sync(Depsgraph *depsgraph,
|
||||
bContext *context,
|
||||
pxr::HdRenderSettingsMap &render_settings)
|
||||
@ -81,8 +110,8 @@ void PreviewEngine::update_bl_engine(RenderEngine *bl_engine)
|
||||
double PreviewEngine::delete_preview_engine(uintptr_t uuid, void *user_data)
|
||||
{
|
||||
std::unique_ptr<PreviewEngine> *preview_engine = static_cast<std::unique_ptr<PreviewEngine>*>(user_data);
|
||||
if (preview_engine && preview_engine->get()->is_converged()) {
|
||||
CLOG_INFO(LOG_EN, 1, "Delete preview engine");
|
||||
if (preview_engine && preview_engine->get()->render_task_delegate->is_converged()) {
|
||||
CLOG_INFO(LOG_EN, uuid, "Delete preview engine");
|
||||
preview_engine->reset();
|
||||
return -1;
|
||||
}
|
||||
|
@ -10,6 +10,9 @@ namespace blender::render::hydra {
|
||||
class PreviewEngine : public FinalEngine {
|
||||
public:
|
||||
using FinalEngine::FinalEngine;
|
||||
static void free();
|
||||
static std::unique_ptr<PreviewEngine> *get(RenderEngine *bl_engine = nullptr,
|
||||
char *render_delegate_id = nullptr);
|
||||
void sync(Depsgraph *depsgraph,
|
||||
bContext *context,
|
||||
pxr::HdRenderSettingsMap &render_settings) override;
|
||||
@ -27,6 +30,7 @@ class PreviewEngine : public FinalEngine {
|
||||
static inline double preview_engine_lifetime = 180.0;
|
||||
|
||||
protected:
|
||||
static std::unique_ptr<PreviewEngine> preview_engine;
|
||||
pxr::HdRenderSettingsMap render_settings;
|
||||
};
|
||||
|
||||
|
@ -20,8 +20,6 @@
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
static std::unique_ptr<PreviewEngine> preview_engine;
|
||||
|
||||
static PyObject *init_func(PyObject * /*self*/, PyObject *args)
|
||||
DagerD marked this conversation as resolved
Outdated
Bogdan Nagirniak
commented
move to PreviewEngine class as static move to PreviewEngine class as static
|
||||
{
|
||||
DagerD marked this conversation as resolved
Outdated
Bogdan Nagirniak
commented
Use unique_ptr Use unique_ptr
|
||||
CLOG_INFO(LOG_EN, 1, "Init");
|
||||
@ -116,16 +114,7 @@ static PyObject *engine_create_func(PyObject * /*self*/, PyObject *args)
|
||||
engine = new ViewportEngine(bl_engine, render_delegate_id);
|
||||
}
|
||||
else if (STREQ(engine_type, "PREVIEW")) {
|
||||
if (!preview_engine) {
|
||||
preview_engine = std::make_unique<PreviewEngine>(bl_engine, render_delegate_id);
|
||||
}
|
||||
if (BLI_timer_is_registered(1)) {
|
||||
BLI_timer_unregister(1);
|
||||
}
|
||||
preview_engine->update_bl_engine(bl_engine);
|
||||
|
||||
CLOG_INFO(LOG_EN, 2, "Engine %016llx %s", engine, engine_type);
|
||||
return PyLong_FromVoidPtr(preview_engine.get());
|
||||
engine = PreviewEngine::get(bl_engine, render_delegate_id)->get();
|
||||
}
|
||||
else {
|
||||
if (bl_engine->type->flag & RE_USE_GPU_CONTEXT) {
|
||||
@ -149,15 +138,9 @@ static PyObject *engine_free_func(PyObject * /*self*/, PyObject *args)
|
||||
}
|
||||
DagerD marked this conversation as resolved
Outdated
Bogdan Nagirniak
commented
Add PreviewEngine::update_engine() instead public usage of bl_engine Add PreviewEngine::update_engine() instead public usage of bl_engine
|
||||
|
||||
Engine *engine = (Engine *)PyLong_AsVoidPtr(pyengine);
|
||||
|
||||
PreviewEngine *preview_engine = dynamic_cast<PreviewEngine *>(engine);
|
||||
if (preview_engine) {
|
||||
BLI_timer_register(1,
|
||||
preview_engine->delete_preview_engine,
|
||||
&preview_engine,
|
||||
nullptr,
|
||||
preview_engine->preview_engine_lifetime,
|
||||
true);
|
||||
CLOG_INFO(LOG_EN, 2, "Engine %016llx", engine);
|
||||
preview_engine->free();
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
@ -436,12 +436,12 @@ pxr::VtValue BlenderSceneDelegate::GetLightParamValue(pxr::SdfPath const &id,
|
||||
|
||||
void BlenderSceneDelegate::clear()
|
||||
{
|
||||
for (auto it = materials.begin(); it != materials.end(); ++it) {
|
||||
it->second->remove();
|
||||
for (auto &it : materials) {
|
||||
DagerD marked this conversation as resolved
Outdated
Bogdan Nagirniak
commented
```
for (auto &it : materials) {
it.second->remove();
}
```
|
||||
it.second->remove();
|
||||
}
|
||||
|
||||
for (auto it = objects.begin(); it != objects.end(); ++it) {
|
||||
it->second->remove();
|
||||
for (auto &it : objects) {
|
||||
it.second->remove();
|
||||
}
|
||||
|
||||
materials.clear();
|
||||
|
@ -7,7 +7,6 @@
|
||||
#include <pxr/imaging/hd/tokens.h>
|
||||
#include <pxr/usd/usdLux/tokens.h>
|
||||
|
||||
#include "BKE_light.h"
|
||||
#include "DNA_light_types.h"
|
||||
|
||||
#include "blender_scene_delegate.h"
|
||||
@ -80,17 +79,16 @@ void LightData::init()
|
||||
break;
|
||||
}
|
||||
|
||||
p_type = light->type;
|
||||
p_shape = light->area_shape;
|
||||
p_type = prim_type(light);
|
||||
|
||||
/* TODO: temporary value, it should be delivered through Python UI */
|
||||
data[pxr::HdLightTokens->exposure] = 1.0f;
|
||||
}
|
||||
|
||||
pxr::TfToken LightData::prim_type()
|
||||
pxr::TfToken LightData::prim_type(Light *light)
|
||||
{
|
||||
pxr::TfToken ret;
|
||||
switch (p_type) {
|
||||
switch (light->type) {
|
||||
case LA_LOCAL:
|
||||
case LA_SPOT:
|
||||
ret = pxr::HdPrimTypeTokens->sphereLight;
|
||||
@ -101,7 +99,7 @@ pxr::TfToken LightData::prim_type()
|
||||
break;
|
||||
|
||||
case LA_AREA:
|
||||
switch (p_shape) {
|
||||
switch (light->area_shape) {
|
||||
case LA_AREA_SQUARE:
|
||||
case LA_AREA_RECT:
|
||||
ret = pxr::HdPrimTypeTokens->rectLight;
|
||||
@ -157,13 +155,13 @@ bool LightData::update_visibility(View3D *view3d)
|
||||
void LightData::insert()
|
||||
{
|
||||
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
|
||||
scene_delegate->GetRenderIndex().InsertSprim(prim_type(), scene_delegate, p_id);
|
||||
scene_delegate->GetRenderIndex().InsertSprim(p_type, scene_delegate, p_id);
|
||||
}
|
||||
|
||||
void LightData::remove()
|
||||
{
|
||||
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
|
||||
scene_delegate->GetRenderIndex().RemoveSprim(prim_type(), p_id);
|
||||
scene_delegate->GetRenderIndex().RemoveSprim(p_type, p_id);
|
||||
}
|
||||
|
||||
void LightData::update()
|
||||
@ -171,7 +169,7 @@ void LightData::update()
|
||||
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
|
||||
|
||||
Light *light = (Light *)((Object *)id)->data;
|
||||
if (light->type != p_type || light->area_shape != p_shape) {
|
||||
if (prim_type(light) != p_type) {
|
||||
remove();
|
||||
init();
|
||||
insert();
|
||||
|
@ -7,6 +7,8 @@
|
||||
#include <pxr/usd/sdf/assetPath.h>
|
||||
#include <pxr/usd/sdf/path.h>
|
||||
|
||||
#include "BKE_light.h"
|
||||
|
||||
#include "object.h"
|
||||
|
||||
namespace blender::render::hydra {
|
||||
@ -24,9 +26,8 @@ class LightData : public ObjectData {
|
||||
|
||||
private:
|
||||
std::map<pxr::TfToken, pxr::VtValue> data;
|
||||
DagerD marked this conversation as resolved
Outdated
Bogdan Nagirniak
commented
`pxr::TfToken p_type;`
make prim_type() with `Light *` parameter
|
||||
short p_type;
|
||||
short p_shape;
|
||||
pxr::TfToken prim_type();
|
||||
pxr::TfToken p_type;
|
||||
pxr::TfToken prim_type(Light *light);
|
||||
};
|
||||
|
||||
} // namespace blender::render::hydra
|
||||
|
Loading…
Reference in New Issue
Block a user
no need