BLEN-365: Improve creation algorithm of PreviewEngine #21

Merged
Bogdan Nagirniak merged 11 commits from BLEN-365 into hydra-render 2023-04-10 12:44:48 +02:00
4 changed files with 7 additions and 23 deletions
Showing only changes of commit cca11e5b17 - Show all commits

View File

@ -34,13 +34,14 @@ class Engine {
bContext *context,
pxr::HdRenderSettingsMap &render_settings) = 0;
virtual void render(Depsgraph *depsgraph) = 0;
public:
RenderEngine *bl_engine;
protected:
float renderer_percent_done();
protected:
pxr::HdPluginRenderDelegateUniqueHandle render_delegate;
std::unique_ptr<pxr::HdRenderIndex> render_index;
std::unique_ptr<BlenderSceneDelegate> scene_delegate;

View File

@ -12,37 +12,22 @@ void PreviewEngine::sync(Depsgraph *depsgraph,
bContext *context,
pxr::HdRenderSettingsMap &render_settings)
{
is_synced = false;
scene_delegate->clear_data();
for (auto &prim : render_index->GetRprimIds()) {
render_index->RemoveRprim(prim);
render_index->RemoveInstancer(prim);
std::cout << "sync RemoveRprim: " << prim.GetText() << " " << render_index->HasRprim(prim)
<< "\n";
}
for (auto &prim : render_index->GetRprimIds()) {
std::cout << "sync after Remove: " << prim.GetText() << "\n";
}
scene_delegate->populate(depsgraph, context);
for (auto &prim : render_index->GetRprimIds()) {
std::cout << "sync populate: " << prim.GetText() << "\n";
}
for (auto const &setting : render_settings) {
render_delegate->SetRenderSetting(setting.first, setting.second);
}
is_synced = true;
}
void PreviewEngine::render(Depsgraph *depsgraph)
{
//if (!is_synced) {
// return;
//}
Scene *scene = DEG_get_input_scene(depsgraph);
ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph);
@ -53,7 +38,6 @@ void PreviewEngine::render(Depsgraph *depsgraph)
CameraData(scene->camera, res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(pxr::GfVec4f(0, 0, 1, 1));
free_camera_delegate->SetCamera(camera);
//render_task_delegate->clear_renderer_aovs();
render_task_delegate->set_camera_and_viewport(free_camera_delegate->GetCameraId(),
pxr::GfVec4d(0, 0, res[0], res[1]));
render_task_delegate->set_renderer_aov(pxr::HdAovTokens->color);

View File

@ -16,8 +16,6 @@ class PreviewEngine : public FinalEngine {
void render(Depsgraph *depsgraph) override;
void stop_renderer();
bool is_synced = false;
protected:
void update_render_result(const std::string &layer_name,
int width,

View File

@ -23,7 +23,7 @@ namespace blender::render::hydra {
static double preview_engine_lifetime = 60.0;
static PreviewEngine *preview_engine;
double timer_func(uintptr_t uuid, void *user_data)
double delete_preview_engine(uintptr_t uuid, void *user_data)
{
if (preview_engine) {
preview_engine->stop_renderer();
@ -164,7 +164,8 @@ static PyObject *engine_free_func(PyObject * /*self*/, PyObject *args)
Engine *engine = (Engine *)PyLong_AsVoidPtr(pyengine);
if (preview_engine) {
BLI_timer_register(1, timer_func, nullptr, nullptr, preview_engine_lifetime, true);
BLI_timer_register(1, delete_preview_engine, nullptr, nullptr, preview_engine_lifetime, true);
CLOG_INFO(LOG_EN, 2, "Engine %016llx", engine);
Py_RETURN_NONE;
}