forked from blender/blender
Create possibility to provide render settings via BlenderSceneDelegate #41
@ -17,8 +17,8 @@ namespace blender::render::hydra {
|
|||||||
|
|
||||||
CLG_LOGREF_DECLARE_GLOBAL(LOG_RENDER_HYDRA, "render.hydra");
|
CLG_LOGREF_DECLARE_GLOBAL(LOG_RENDER_HYDRA, "render.hydra");
|
||||||
|
|
||||||
Engine::Engine(RenderEngine *bl_engine, const std::string &render_delegate_name)
|
Engine::Engine(RenderEngine *bl_engine, const std::string &render_delegate_name, SettingsMap &settings)
|
||||||
: bl_engine_(bl_engine), render_delegate_name_(render_delegate_name)
|
: bl_engine_(bl_engine), render_delegate_name_(render_delegate_name), settings_(settings)
|
||||||
{
|
{
|
||||||
pxr::HdRendererPluginRegistry ®istry = pxr::HdRendererPluginRegistry::GetInstance();
|
pxr::HdRendererPluginRegistry ®istry = pxr::HdRendererPluginRegistry::GetInstance();
|
||||||
|
|
||||||
|
@ -23,14 +23,18 @@ namespace blender::render::hydra {
|
|||||||
|
|
||||||
extern struct CLG_LogRef *LOG_RENDER_HYDRA;
|
extern struct CLG_LogRef *LOG_RENDER_HYDRA;
|
||||||
|
|
||||||
|
typedef pxr::TfHashMap<pxr::TfToken, pxr::VtValue, pxr::TfToken::HashFunctor> SettingsMap;
|
||||||
|
|
||||||
class Engine {
|
class Engine {
|
||||||
public:
|
public:
|
||||||
Engine(RenderEngine *bl_engine, const std::string &render_delegate_name);
|
Engine(RenderEngine *bl_engine,
|
||||||
|
const std::string &render_delegate_name,
|
||||||
|
SettingsMap &settings);
|
||||||
virtual ~Engine() = default;
|
virtual ~Engine() = default;
|
||||||
|
|
||||||
virtual void sync(Depsgraph *depsgraph,
|
virtual void sync(Depsgraph *depsgraph,
|
||||||
bContext *context,
|
bContext *context,
|
||||||
pxr::HdRenderSettingsMap &render_settings) = 0;
|
SettingsMap &render_settings) = 0;
|
||||||
virtual void render(Depsgraph *depsgraph) = 0;
|
virtual void render(Depsgraph *depsgraph) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -38,6 +42,7 @@ class Engine {
|
|||||||
|
|
||||||
RenderEngine *bl_engine_;
|
RenderEngine *bl_engine_;
|
||||||
std::string render_delegate_name_;
|
std::string render_delegate_name_;
|
||||||
|
SettingsMap settings_;
|
||||||
|
|
||||||
/* The order is important due to deletion order */
|
/* The order is important due to deletion order */
|
||||||
pxr::HgiUniquePtr hgi_;
|
pxr::HgiUniquePtr hgi_;
|
||||||
|
@ -14,16 +14,17 @@ const double LIFETIME = 180.0;
|
|||||||
std::unique_ptr<PreviewEngine> PreviewEngine::instance_;
|
std::unique_ptr<PreviewEngine> PreviewEngine::instance_;
|
||||||
|
|
||||||
PreviewEngine *PreviewEngine::get_instance(RenderEngine *bl_engine,
|
PreviewEngine *PreviewEngine::get_instance(RenderEngine *bl_engine,
|
||||||
const std::string &render_delegate_name)
|
const std::string &render_delegate_name,
|
||||||
|
SettingsMap &settings)
|
||||||
{
|
{
|
||||||
if (!instance_) {
|
if (!instance_) {
|
||||||
instance_ = std::make_unique<PreviewEngine>(bl_engine, render_delegate_name);
|
instance_ = std::make_unique<PreviewEngine>(bl_engine, render_delegate_name, settings);
|
||||||
}
|
}
|
||||||
if (BLI_timer_is_registered((uintptr_t)instance_.get())) {
|
if (BLI_timer_is_registered((uintptr_t)instance_.get())) {
|
||||||
/* Unregister timer while PreviewEngine is working */
|
/* Unregister timer while PreviewEngine is working */
|
||||||
BLI_timer_unregister((uintptr_t)instance_.get());
|
BLI_timer_unregister((uintptr_t)instance_.get());
|
||||||
}
|
}
|
||||||
instance_->update(bl_engine, render_delegate_name);
|
instance_->update(bl_engine, render_delegate_name, settings);
|
||||||
|
|
||||||
return instance_.get();
|
return instance_.get();
|
||||||
}
|
}
|
||||||
@ -96,12 +97,14 @@ double PreviewEngine::free_instance(uintptr_t uuid, void *user_data)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewEngine::update(RenderEngine *bl_engine, const std::string &render_delegate_name)
|
void PreviewEngine::update(RenderEngine *bl_engine,
|
||||||
|
const std::string &render_delegate_name,
|
||||||
|
SettingsMap &settings)
|
||||||
{
|
{
|
||||||
bl_engine_ = bl_engine;
|
bl_engine_ = bl_engine;
|
||||||
if (render_delegate_name != render_delegate_name_) {
|
if (render_delegate_name != render_delegate_name_) {
|
||||||
render_delegate_->Stop();
|
render_delegate_->Stop();
|
||||||
instance_.reset(new PreviewEngine(bl_engine, render_delegate_name));
|
instance_.reset(new PreviewEngine(bl_engine, render_delegate_name, settings));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,8 @@ class PreviewEngine : public FinalEngine {
|
|||||||
using FinalEngine::FinalEngine;
|
using FinalEngine::FinalEngine;
|
||||||
|
|
||||||
static PreviewEngine *get_instance(RenderEngine *bl_engine,
|
static PreviewEngine *get_instance(RenderEngine *bl_engine,
|
||||||
const std::string &render_delegate_name);
|
const std::string &render_delegate_name,
|
||||||
|
SettingsMap &settings);
|
||||||
static void schedule_free();
|
static void schedule_free();
|
||||||
|
|
||||||
|
|||||||
void sync(Depsgraph *depsgraph,
|
void sync(Depsgraph *depsgraph,
|
||||||
@ -25,7 +26,9 @@ class PreviewEngine : public FinalEngine {
|
|||||||
static double free_instance(uintptr_t uuid, void *user_data);
|
static double free_instance(uintptr_t uuid, void *user_data);
|
||||||
static std::unique_ptr<PreviewEngine> instance_;
|
static std::unique_ptr<PreviewEngine> instance_;
|
||||||
|
|
||||||
void update(RenderEngine *bl_engine, const std::string &render_delegate_name);
|
void update(RenderEngine *bl_engine,
|
||||||
|
const std::string &render_delegate_name,
|
||||||
|
SettingsMap &settings);
|
||||||
void update_render_result(std::vector<float> &pixels);
|
void update_render_result(std::vector<float> &pixels);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -96,34 +96,60 @@ static PyObject *get_render_plugins_func(PyObject * /*self*/, PyObject *args)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static SettingsMap get_settings(PyObject *pysettings)
|
||||||
|
{
|
||||||
|
SettingsMap settings;
|
||||||
|
PyObject *pyiter = PyObject_GetIter(pysettings);
|
||||||
|
if (pyiter) {
|
||||||
|
PyObject *pykey, *pyval;
|
||||||
|
while (pykey = PyIter_Next(pyiter)) {
|
||||||
|
pxr::TfToken key(PyUnicode_AsUTF8(pykey));
|
||||||
|
pyval = PyDict_GetItem(pysettings, pykey);
|
||||||
|
|
||||||
|
if (PyLong_Check(pyval)) {
|
||||||
|
settings[key] = PyLong_AsLong(pyval);
|
||||||
|
}
|
||||||
|
else if (PyFloat_Check(pyval)) {
|
||||||
|
settings[key] = PyFloat_AsDouble(pyval);
|
||||||
|
}
|
||||||
|
else if (PyUnicode_Check(pyval)) {
|
||||||
|
settings[key] = PyUnicode_AsUTF8(pyval);
|
||||||
|
}
|
||||||
|
Py_DECREF(pykey);
|
||||||
|
}
|
||||||
|
Py_DECREF(pyiter);
|
||||||
|
}
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
|
||||||
static PyObject *engine_create_func(PyObject * /*self*/, PyObject *args)
|
static PyObject *engine_create_func(PyObject * /*self*/, PyObject *args)
|
||||||
{
|
{
|
||||||
PyObject *pyengine;
|
PyObject *pyengine, *pysettings;
|
||||||
char *engine_type, *render_delegate_id;
|
char *engine_type, *render_delegate_id;
|
||||||
if (!PyArg_ParseTuple(args, "Oss", &pyengine, &engine_type, &render_delegate_id)) {
|
if (!PyArg_ParseTuple(args, "OssO", &pyengine, &engine_type, &render_delegate_id, &pysettings)) {
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderEngine *bl_engine = (RenderEngine *)PyLong_AsVoidPtr(pyengine);
|
RenderEngine *bl_engine = (RenderEngine *)PyLong_AsVoidPtr(pyengine);
|
||||||
|
SettingsMap settings = get_settings(pysettings);
|
||||||
|
|
||||||
Engine *engine;
|
Engine *engine;
|
||||||
if (STREQ(engine_type, "VIEWPORT")) {
|
if (STREQ(engine_type, "VIEWPORT")) {
|
||||||
engine = new ViewportEngine(bl_engine, render_delegate_id);
|
engine = new ViewportEngine(bl_engine, render_delegate_id, settings);
|
||||||
}
|
}
|
||||||
else if (STREQ(engine_type, "PREVIEW")) {
|
else if (STREQ(engine_type, "PREVIEW")) {
|
||||||
engine = PreviewEngine::get_instance(bl_engine, render_delegate_id);
|
engine = PreviewEngine::get_instance(bl_engine, render_delegate_id, settings);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (bl_engine->type->flag & RE_USE_GPU_CONTEXT) {
|
if (bl_engine->type->flag & RE_USE_GPU_CONTEXT) {
|
||||||
engine = new FinalEngineGL(bl_engine, render_delegate_id);
|
engine = new FinalEngineGL(bl_engine, render_delegate_id, settings);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
engine = new FinalEngine(bl_engine, render_delegate_id);
|
engine = new FinalEngine(bl_engine, render_delegate_id, settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CLOG_INFO(LOG_RENDER_HYDRA, 2, "Engine %016llx %s", engine, engine_type);
|
CLOG_INFO(LOG_RENDER_HYDRA, 2, "Engine %016llx %s", engine, engine_type);
|
||||||
|
|
||||||
return PyLong_FromVoidPtr(engine);
|
return PyLong_FromVoidPtr(engine);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,28 +183,7 @@ static PyObject *engine_sync_func(PyObject * /*self*/, PyObject *args)
|
|||||||
Engine *engine = (Engine *)PyLong_AsVoidPtr(pyengine);
|
Engine *engine = (Engine *)PyLong_AsVoidPtr(pyengine);
|
||||||
Depsgraph *depsgraph = (Depsgraph *)PyLong_AsVoidPtr(pydepsgraph);
|
Depsgraph *depsgraph = (Depsgraph *)PyLong_AsVoidPtr(pydepsgraph);
|
||||||
bContext *context = (bContext *)PyLong_AsVoidPtr(pycontext);
|
bContext *context = (bContext *)PyLong_AsVoidPtr(pycontext);
|
||||||
|
SettingsMap settings = get_settings(pysettings);
|
||||||
pxr::HdRenderSettingsMap settings;
|
|
||||||
PyObject *pyiter = PyObject_GetIter(pysettings);
|
|
||||||
if (pyiter) {
|
|
||||||
PyObject *pykey, *pyval;
|
|
||||||
while (pykey = PyIter_Next(pyiter)) {
|
|
||||||
pxr::TfToken key(PyUnicode_AsUTF8(pykey));
|
|
||||||
pyval = PyDict_GetItem(pysettings, pykey);
|
|
||||||
|
|
||||||
if (PyLong_Check(pyval)) {
|
|
||||||
settings[key] = PyLong_AsLong(pyval);
|
|
||||||
}
|
|
||||||
else if (PyFloat_Check(pyval)) {
|
|
||||||
settings[key] = PyFloat_AsDouble(pyval);
|
|
||||||
}
|
|
||||||
else if (PyUnicode_Check(pyval)) {
|
|
||||||
settings[key] = PyUnicode_AsUTF8(pyval);
|
|
||||||
}
|
|
||||||
Py_DECREF(pykey);
|
|
||||||
}
|
|
||||||
Py_DECREF(pyiter);
|
|
||||||
}
|
|
||||||
|
|
||||||
engine->sync(depsgraph, context, settings);
|
engine->sync(depsgraph, context, settings);
|
||||||
|
|
||||||
|
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.