BLEN-367: Fix code style #14

Merged
Bogdan Nagirniak merged 11 commits from BLEN-367 into hydra-render 2023-03-15 09:42:17 +01:00
20 changed files with 306 additions and 303 deletions
Showing only changes of commit e1bc7f4312 - Show all commits

View File

@ -14,12 +14,12 @@
namespace blender::render::hydra {
Engine::Engine(RenderEngine *bl_engine, const std::string &delegateId) : bl_engine(bl_engine)
Engine::Engine(RenderEngine *bl_engine, const std::string &delegate_id) : bl_engine(bl_engine)
{
pxr::HdRendererPluginRegistry &registry = pxr::HdRendererPluginRegistry::GetInstance();
pxr::TF_PY_ALLOW_THREADS_IN_SCOPE();
render_delegate = registry.CreateRenderDelegate(pxr::TfToken(delegateId));
render_delegate = registry.CreateRenderDelegate(pxr::TfToken(delegate_id));
pxr::HdDriverVector hd_drivers;
if (bl_engine->type->flag & RE_USE_GPU_CONTEXT) {

View File

@ -28,7 +28,7 @@ class Engine {
virtual void sync(Depsgraph *depsgraph,
bContext *context,
pxr::HdRenderSettingsMap &renderSettings) = 0;
pxr::HdRenderSettingsMap &render_settings) = 0;
virtual void render(Depsgraph *depsgraph) = 0;
protected:

View File

@ -16,15 +16,15 @@ namespace blender::render::hydra {
void FinalEngine::sync(Depsgraph *depsgraph,
bContext *context,
pxr::HdRenderSettingsMap &renderSettings)
pxr::HdRenderSettingsMap &render_settings)
{
scene_delegate = std::make_unique<BlenderSceneDelegate>(
render_index.get(),
pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"),
BlenderSceneDelegate::EngineType::Final);
BlenderSceneDelegate::EngineType::FINAL);
scene_delegate->populate(depsgraph, context);
for (auto const &setting : renderSettings) {
for (auto const &setting : render_settings) {
render_delegate->SetRenderSetting(setting.first, setting.second);
}
}
@ -52,28 +52,28 @@ void FinalEngine::render(Depsgraph *depsgraph)
CameraData(scene->camera, image_res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(border);
free_camera_delegate->SetCamera(camera);
render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(),
pxr::GfVec4d(0, 0, res[0], res[1]));
render_task_delegate->SetRendererAov(pxr::HdAovTokens->color);
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);
if (simple_light_task_delegate) {
simple_light_task_delegate->SetCameraPath(free_camera_delegate->GetCameraId());
simple_light_task_delegate->set_camera_path(free_camera_delegate->GetCameraId());
}
pxr::HdTaskSharedPtrVector tasks;
if (simple_light_task_delegate) {
tasks.push_back(simple_light_task_delegate->GetTask());
tasks.push_back(simple_light_task_delegate->get_task());
}
tasks.push_back(render_task_delegate->GetTask());
tasks.push_back(render_task_delegate->get_task());
std::chrono::time_point<std::chrono::steady_clock> timeBegin = std::chrono::steady_clock::now(),
timeCurrent;
std::chrono::milliseconds elapsedTime;
std::chrono::time_point<std::chrono::steady_clock> time_begin = std::chrono::steady_clock::now(),
time_current;
std::chrono::milliseconds elapsed_time;
float percentDone = 0.0;
float percent_done = 0.0;
std::map<std::string, std::vector<float>> renderImages{
std::map<std::string, std::vector<float>> render_images{
{"Combined", std::vector<float>(res[0] * res[1] * 4)}}; // 4 - number of channels
std::vector<float> &pixels = renderImages["Combined"];
std::vector<float> &pixels = render_images["Combined"];
{
// Release the GIL before calling into hydra, in case any hydra plugins call into python.
@ -86,25 +86,26 @@ void FinalEngine::render(Depsgraph *depsgraph)
break;
}
percentDone = renderer_percent_done();
timeCurrent = std::chrono::steady_clock::now();
elapsedTime = std::chrono::duration_cast<std::chrono::milliseconds>(timeCurrent - timeBegin);
percent_done = renderer_percent_done();
time_current = std::chrono::steady_clock::now();
elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(time_current -
time_begin);
notify_status(percentDone / 100.0,
notify_status(percent_done / 100.0,
scene_name + ": " + layer_name,
"Render Time: " + format_duration(elapsedTime) +
" | Done: " + std::to_string(int(percentDone)) + "%");
"Render Time: " + format_duration(elapsed_time) +
" | Done: " + std::to_string(int(percent_done)) + "%");
if (render_task_delegate->IsConverged()) {
if (render_task_delegate->is_converged()) {
break;
}
render_task_delegate->GetRendererAovData(pxr::HdAovTokens->color, pixels.data());
updateRenderResult(renderImages, layer_name, res[0], res[1]);
render_task_delegate->get_renderer_aov_data(pxr::HdAovTokens->color, pixels.data());
update_render_result(render_images, layer_name, res[0], res[1]);
}
render_task_delegate->GetRendererAovData(pxr::HdAovTokens->color, pixels.data());
updateRenderResult(renderImages, layer_name, res[0], res[1]);
render_task_delegate->get_renderer_aov_data(pxr::HdAovTokens->color, pixels.data());
update_render_result(render_images, layer_name, res[0], res[1]);
}
pxr::GfVec2i FinalEngine::get_resolution(Scene *scene)
@ -119,19 +120,19 @@ pxr::GfVec2i FinalEngine::get_resolution(Scene *scene)
int(r.ysch * border_h * r.size / 100));
}
void FinalEngine::updateRenderResult(std::map<std::string, std::vector<float>> &renderImages,
const std::string &layerName,
int width,
int height)
void FinalEngine::update_render_result(std::map<std::string, std::vector<float>> &render_images,
const std::string &layer_name,
int width,
int height)
{
RenderResult *result = RE_engine_begin_result(
bl_engine, 0, 0, width, height, layerName.c_str(), nullptr);
bl_engine, 0, 0, width, height, layer_name.c_str(), nullptr);
/* TODO: only for the first render layer */
RenderLayer *layer = (RenderLayer *)result->layers.first;
for (RenderPass *pass = (RenderPass *)layer->passes.first; pass != nullptr; pass = pass->next) {
auto it_image = renderImages.find(pass->name);
if (it_image == renderImages.end()) {
auto it_image = render_images.find(pass->name);
if (it_image == render_images.end()) {
continue;
}
memcpy(pass->rect,
@ -171,10 +172,10 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
CameraData(scene->camera, image_res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(border);
free_camera_delegate->SetCamera(camera);
render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(),
pxr::GfVec4d(0, 0, res[0], res[1]));
render_task_delegate->set_camera_and_viewport(free_camera_delegate->GetCameraId(),
pxr::GfVec4d(0, 0, res[0], res[1]));
if (simple_light_task_delegate) {
simple_light_task_delegate->SetCameraPath(free_camera_delegate->GetCameraId());
simple_light_task_delegate->set_camera_path(free_camera_delegate->GetCameraId());
}
pxr::HdTaskSharedPtrVector tasks;
@ -182,30 +183,30 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
/* TODO: Uncomment this and fix GL error:
invalid operation, reported from void __cdecl
pxrInternal_v0_22__pxrReserved__::HgiGLResourceBindings::BindResources(void) */
// tasks.push_back(simple_light_task_delegate->GetTask());
// tasks.push_back(simple_light_task_delegate->get_task());
}
tasks.push_back(render_task_delegate->GetTask());
tasks.push_back(render_task_delegate->get_task());
std::chrono::time_point<std::chrono::steady_clock> timeBegin = std::chrono::steady_clock::now(),
timeCurrent;
std::chrono::milliseconds elapsedTime;
std::chrono::time_point<std::chrono::steady_clock> time_begin = std::chrono::steady_clock::now(),
time_current;
std::chrono::milliseconds elapsed_time;
float percentDone = 0.0;
float percent_done = 0.0;
std::map<std::string, std::vector<float>> renderImages{
std::map<std::string, std::vector<float>> render_images{
{"Combined", std::vector<float>(res[0] * res[1] * 4)}}; // 4 - number of channels
std::vector<float> &pixels = renderImages["Combined"];
std::vector<float> &pixels = render_images["Combined"];
GLuint FramebufferName = 0;
glGenFramebuffers(1, &FramebufferName);
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
GLuint framebuffer_name = 0;
glGenFramebuffers(1, &framebuffer_name);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_name);
// The texture we're going to render to
GLuint renderedTexture;
glGenTextures(1, &renderedTexture);
GLuint rendered_texture;
glGenTextures(1, &rendered_texture);
// "Bind" the newly created texture : all future texture functions will modify this texture
glBindTexture(GL_TEXTURE_2D, renderedTexture);
glBindTexture(GL_TEXTURE_2D, rendered_texture);
// Give an empty image to OpenGL ( the last "0" )
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, res[0], res[1], 0, GL_RGBA, GL_FLOAT, 0);
@ -214,13 +215,13 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
// Set "renderedTexture" as our colour attachement #0
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, renderedTexture, 0);
// Set "rendered_texture" as our colour attachement #0
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, rendered_texture, 0);
// Generate vertex array
GLuint VAO;
glGenVertexArrays(1, &VAO);
glBindVertexArray(VAO);
GLuint vao;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
{
// Release the GIL before calling into hydra, in case any hydra plugins call into python.
@ -233,25 +234,26 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
break;
}
percentDone = renderer_percent_done();
timeCurrent = std::chrono::steady_clock::now();
elapsedTime = std::chrono::duration_cast<std::chrono::milliseconds>(timeCurrent - timeBegin);
percent_done = renderer_percent_done();
time_current = std::chrono::steady_clock::now();
elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(time_current -
time_begin);
notify_status(percentDone / 100.0,
notify_status(percent_done / 100.0,
scene_name + ": " + layer_name,
"Render Time: " + format_duration(elapsedTime) +
" | Done: " + std::to_string(int(percentDone)) + "%");
"Render Time: " + format_duration(elapsed_time) +
" | Done: " + std::to_string(int(percent_done)) + "%");
if (render_task_delegate->IsConverged()) {
if (render_task_delegate->is_converged()) {
break;
}
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, pixels.data());
updateRenderResult(renderImages, layer_name, res[0], res[1]);
update_render_result(render_images, layer_name, res[0], res[1]);
}
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, pixels.data());
updateRenderResult(renderImages, layer_name, res[0], res[1]);
update_render_result(render_images, layer_name, res[0], res[1]);
}
} // namespace blender::render::hydra

View File

@ -14,19 +14,19 @@ class FinalEngine : public Engine {
using Engine::Engine;
virtual void sync(Depsgraph *depsgraph,
bContext *context,
pxr::HdRenderSettingsMap &renderSettings) override;
pxr::HdRenderSettingsMap &render_settings) override;
virtual void render(Depsgraph *b_depsgraph) override;
protected:
pxr::GfVec2i get_resolution(Scene *scene);
void updateRenderResult(std::map<std::string, std::vector<float>> &render_images,
const std::string &layerName,
int width,
int height);
void update_render_result(std::map<std::string, std::vector<float>> &render_images,
const std::string &layer_name,
int width,
int height);
void notify_status(float progress, const std::string &title, const std::string &info);
protected:
pxr::HdRenderSettingsMap renderSettings;
pxr::HdRenderSettingsMap render_settings;
};
class FinalEngineGL : public FinalEngine {

View File

@ -10,15 +10,15 @@ namespace blender::render::hydra {
void PreviewEngine::sync(Depsgraph *depsgraph,
bContext *context,
pxr::HdRenderSettingsMap &renderSettings)
pxr::HdRenderSettingsMap &render_settings)
{
scene_delegate = std::make_unique<BlenderSceneDelegate>(
render_index.get(),
pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"),
BlenderSceneDelegate::EngineType::Preview);
BlenderSceneDelegate::EngineType::PREVIEW);
scene_delegate->populate(depsgraph, context);
for (auto const &setting : renderSettings) {
for (auto const &setting : render_settings) {
render_delegate->SetRenderSetting(setting.first, setting.second);
}
}
@ -28,22 +28,22 @@ void PreviewEngine::render(Depsgraph *depsgraph)
Scene *scene = DEG_get_input_scene(depsgraph);
ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph);
std::string layerName = view_layer->name;
std::string layer_name = view_layer->name;
pxr::GfVec2i res(scene->r.xsch, scene->r.ysch);
pxr::GfCamera camera =
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->SetCameraAndViewport(free_camera_delegate->GetCameraId(),
pxr::GfVec4d(0, 0, res[0], res[1]));
render_task_delegate->SetRendererAov(pxr::HdAovTokens->color);
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);
pxr::HdTaskSharedPtrVector tasks;
if (simple_light_task_delegate) {
tasks.push_back(simple_light_task_delegate->GetTask());
tasks.push_back(simple_light_task_delegate->get_task());
}
tasks.push_back(render_task_delegate->GetTask());
tasks.push_back(render_task_delegate->get_task());
std::vector<float> pixels = std::vector<float>(res[0] * res[1] * 4); // 4 - number of channels
@ -58,25 +58,25 @@ void PreviewEngine::render(Depsgraph *depsgraph)
break;
}
if (render_task_delegate->IsConverged()) {
if (render_task_delegate->is_converged()) {
break;
}
render_task_delegate->GetRendererAovData(pxr::HdAovTokens->color, pixels.data());
updateRenderResult(layerName, res[0], res[1], pixels);
render_task_delegate->get_renderer_aov_data(pxr::HdAovTokens->color, pixels.data());
update_render_result(layer_name, res[0], res[1], pixels);
}
render_task_delegate->GetRendererAovData(pxr::HdAovTokens->color, pixels.data());
updateRenderResult(layerName, res[0], res[1], pixels);
render_task_delegate->get_renderer_aov_data(pxr::HdAovTokens->color, pixels.data());
update_render_result(layer_name, res[0], res[1], pixels);
}
void PreviewEngine::updateRenderResult(const std::string &layerName,
int width,
int height,
std::vector<float> &pixels)
void PreviewEngine::update_render_result(const std::string &layer_name,
int width,
int height,
std::vector<float> &pixels)
{
RenderResult *result = RE_engine_begin_result(
bl_engine, 0, 0, width, height, layerName.c_str(), nullptr);
bl_engine, 0, 0, width, height, layer_name.c_str(), nullptr);
RenderLayer *layer = (RenderLayer *)result->layers.first;
RenderPass *pass = (RenderPass *)layer->passes.first;

View File

@ -12,17 +12,17 @@ class PreviewEngine : public FinalEngine {
using FinalEngine::FinalEngine;
void sync(Depsgraph *depsgraph,
bContext *context,
pxr::HdRenderSettingsMap &renderSettings) override;
pxr::HdRenderSettingsMap &render_settings) override;
void render(Depsgraph *depsgraph) override;
protected:
void updateRenderResult(const std::string &layerName,
int width,
int height,
std::vector<float> &pixels);
void update_render_result(const std::string &layer_name,
int width,
int height,
std::vector<float> &pixels);
protected:
pxr::HdRenderSettingsMap renderSettings;
pxr::HdRenderSettingsMap render_settings;
};
} // namespace blender::render::hydra

View File

@ -135,8 +135,8 @@ static PyObject *engine_create_func(PyObject * /*self*/, PyObject *args)
LOG(INFO) << "create_func";
PyObject *pyengine;
char *engineType, *render_delegate_id;
if (!PyArg_ParseTuple(args, "Oss", &pyengine, &engineType, &render_delegate_id)) {
char *engine_type, *render_delegate_id;
if (!PyArg_ParseTuple(args, "Oss", &pyengine, &engine_type, &render_delegate_id)) {
Py_RETURN_NONE;
}
@ -144,10 +144,10 @@ static PyObject *engine_create_func(PyObject * /*self*/, PyObject *args)
Engine *engine;
if (std::string(engineType) == "VIEWPORT") {
if (std::string(engine_type) == "VIEWPORT") {
engine = new ViewportEngine(bl_engine, render_delegate_id);
}
else if (std::string(engineType) == "PREVIEW") {
else if (std::string(engine_type) == "PREVIEW") {
engine = new PreviewEngine(bl_engine, render_delegate_id);
}
else {

View File

@ -13,27 +13,27 @@
namespace blender::render::hydra {
RenderTaskDelegate::RenderTaskDelegate(pxr::HdRenderIndex *parentIndex,
pxr::SdfPath const &delegateID)
: pxr::HdSceneDelegate(parentIndex, delegateID)
RenderTaskDelegate::RenderTaskDelegate(pxr::HdRenderIndex *parent_index,
pxr::SdfPath const &delegate_id)
: pxr::HdSceneDelegate(parent_index, delegate_id)
{
pxr::SdfPath renderTaskId = GetTaskID();
GetRenderIndex().InsertTask<pxr::HdxRenderTask>(this, renderTaskId);
GetRenderIndex().GetChangeTracker().MarkTaskDirty(renderTaskId,
pxr::SdfPath render_task_id = get_task_id();
GetRenderIndex().InsertTask<pxr::HdxRenderTask>(this, render_task_id);
GetRenderIndex().GetChangeTracker().MarkTaskDirty(render_task_id,
pxr::HdChangeTracker::DirtyCollection);
GetRenderIndex().GetChangeTracker().MarkTaskDirty(renderTaskId,
GetRenderIndex().GetChangeTracker().MarkTaskDirty(render_task_id,
pxr::HdChangeTracker::DirtyRenderTags);
taskParams.enableLighting = true;
taskParams.alphaThreshold = 0.1f;
task_params.enableLighting = true;
task_params.alphaThreshold = 0.1f;
}
pxr::SdfPath RenderTaskDelegate::GetTaskID() const
pxr::SdfPath RenderTaskDelegate::get_task_id() const
{
return GetDelegateID().AppendElementString("task");
}
pxr::SdfPath RenderTaskDelegate::GetAovID(pxr::TfToken const &aov) const
pxr::SdfPath RenderTaskDelegate::get_aov_id(pxr::TfToken const &aov) const
{
return GetDelegateID().AppendElementString("aov_" + aov.GetString());
}
@ -42,15 +42,15 @@ pxr::VtValue RenderTaskDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const
{
LOG(INFO) << "RenderTaskDelegate::Get - " << id.GetAsString() << " " << key.GetString() << "\n";
if (key == pxr::HdTokens->params) {
return pxr::VtValue(taskParams);
return pxr::VtValue(task_params);
}
if (key == pxr::HdTokens->collection) {
pxr::HdRprimCollection rprimCollection(pxr::HdTokens->geometry,
pxr::HdReprSelector(pxr::HdReprTokens->smoothHull),
false,
pxr::TfToken());
rprimCollection.SetRootPath(pxr::SdfPath::AbsoluteRootPath());
return pxr::VtValue(rprimCollection);
pxr::HdRprimCollection rprim_collection(pxr::HdTokens->geometry,
pxr::HdReprSelector(pxr::HdReprTokens->smoothHull),
false,
pxr::TfToken());
rprim_collection.SetRootPath(pxr::SdfPath::AbsoluteRootPath());
return pxr::VtValue(rprim_collection);
}
return pxr::VtValue();
}
@ -58,81 +58,81 @@ pxr::VtValue RenderTaskDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const
pxr::HdRenderBufferDescriptor RenderTaskDelegate::GetRenderBufferDescriptor(pxr::SdfPath const &id)
{
LOG(INFO) << "RenderTaskDelegate::GetRenderBufferDescriptor - " << id.GetAsString() << "\n";
return bufferDescriptors[id];
return buffer_descriptors[id];
}
pxr::TfTokenVector RenderTaskDelegate::GetTaskRenderTags(pxr::SdfPath const &taskId)
pxr::TfTokenVector RenderTaskDelegate::GetTaskRenderTags(pxr::SdfPath const &task_id)
{
LOG(INFO) << "RenderTaskDelegate::GetTaskRenderTags - " << taskId.GetAsString() << "\n";
LOG(INFO) << "RenderTaskDelegate::GetTaskRenderTags - " << task_id.GetAsString() << "\n";
return {pxr::HdRenderTagTokens->geometry};
}
bool RenderTaskDelegate::IsConverged()
bool RenderTaskDelegate::is_converged()
{
pxr::HdTaskSharedPtr renderTask = GetRenderIndex().GetTask(GetTaskID());
pxr::HdTaskSharedPtr renderTask = GetRenderIndex().GetTask(get_task_id());
return ((pxr::HdxRenderTask &)*renderTask).IsConverged();
}
void RenderTaskDelegate::SetRendererAov(pxr::TfToken const &aov)
void RenderTaskDelegate::set_renderer_aov(pxr::TfToken const &aov)
{
pxr::HdAovDescriptor aovDesc = GetRenderIndex().GetRenderDelegate()->GetDefaultAovDescriptor(
pxr::HdAovDescriptor aov_desc = GetRenderIndex().GetRenderDelegate()->GetDefaultAovDescriptor(
aov);
pxr::HdRenderBufferDescriptor desc(
pxr::GfVec3i(taskParams.viewport[2], taskParams.viewport[3], 1),
aovDesc.format,
aovDesc.multiSampled);
pxr::SdfPath bufferId = GetAovID(aov);
pxr::GfVec3i(task_params.viewport[2], task_params.viewport[3], 1),
aov_desc.format,
aov_desc.multiSampled);
pxr::SdfPath buffer_id = get_aov_id(aov);
if (bufferDescriptors.find(bufferId) == bufferDescriptors.end()) {
GetRenderIndex().InsertBprim(pxr::HdPrimTypeTokens->renderBuffer, this, bufferId);
bufferDescriptors[bufferId] = desc;
GetRenderIndex().GetChangeTracker().MarkBprimDirty(bufferId,
if (buffer_descriptors.find(buffer_id) == buffer_descriptors.end()) {
GetRenderIndex().InsertBprim(pxr::HdPrimTypeTokens->renderBuffer, this, buffer_id);
buffer_descriptors[buffer_id] = desc;
GetRenderIndex().GetChangeTracker().MarkBprimDirty(buffer_id,
pxr::HdRenderBuffer::DirtyDescription);
pxr::HdRenderPassAovBinding binding;
binding.aovName = aov;
binding.renderBufferId = bufferId;
binding.aovSettings = aovDesc.aovSettings;
taskParams.aovBindings.push_back(binding);
binding.renderBufferId = buffer_id;
binding.aovSettings = aov_desc.aovSettings;
task_params.aovBindings.push_back(binding);
GetRenderIndex().GetChangeTracker().MarkTaskDirty(GetTaskID(),
GetRenderIndex().GetChangeTracker().MarkTaskDirty(get_task_id(),
pxr::HdChangeTracker::DirtyParams);
}
else if (bufferDescriptors[bufferId] != desc) {
bufferDescriptors[bufferId] = desc;
GetRenderIndex().GetChangeTracker().MarkBprimDirty(bufferId,
else if (buffer_descriptors[buffer_id] != desc) {
buffer_descriptors[buffer_id] = desc;
GetRenderIndex().GetChangeTracker().MarkBprimDirty(buffer_id,
pxr::HdRenderBuffer::DirtyDescription);
}
}
pxr::HdRenderBuffer *RenderTaskDelegate::GetRendererAov(pxr::TfToken const &aov)
pxr::HdRenderBuffer *RenderTaskDelegate::get_renderer_aov(pxr::TfToken const &aov)
{
return (pxr::HdRenderBuffer *)(GetRenderIndex().GetBprim(pxr::HdPrimTypeTokens->renderBuffer,
GetAovID(aov)));
get_aov_id(aov)));
}
void RenderTaskDelegate::GetRendererAovData(pxr::TfToken const &aov, void *data)
void RenderTaskDelegate::get_renderer_aov_data(pxr::TfToken const &aov, void *data)
{
pxr::HdRenderBuffer *buffer = GetRendererAov(aov);
void *bufData = buffer->Map();
pxr::HdRenderBuffer *buffer = get_renderer_aov(aov);
void *buf_data = buffer->Map();
memcpy(data,
bufData,
buf_data,
buffer->GetWidth() * buffer->GetHeight() * pxr::HdDataSizeOfFormat(buffer->GetFormat()));
buffer->Unmap();
}
pxr::HdTaskSharedPtr RenderTaskDelegate::GetTask()
pxr::HdTaskSharedPtr RenderTaskDelegate::get_task()
{
return GetRenderIndex().GetTask(GetTaskID());
return GetRenderIndex().GetTask(get_task_id());
}
void RenderTaskDelegate::SetCameraAndViewport(pxr::SdfPath const &cameraId,
pxr::GfVec4d const &viewport)
void RenderTaskDelegate::set_camera_and_viewport(pxr::SdfPath const &camera_id,
pxr::GfVec4d const &viewport)
{
if (taskParams.viewport != viewport || taskParams.camera != cameraId) {
taskParams.viewport = viewport;
taskParams.camera = cameraId;
GetRenderIndex().GetChangeTracker().MarkTaskDirty(GetTaskID(),
if (task_params.viewport != viewport || task_params.camera != camera_id) {
task_params.viewport = viewport;
task_params.camera = camera_id;
GetRenderIndex().GetChangeTracker().MarkTaskDirty(get_task_id(),
pxr::HdChangeTracker::DirtyParams);
}
}

View File

@ -10,28 +10,28 @@ namespace blender::render::hydra {
class RenderTaskDelegate : public pxr::HdSceneDelegate {
public:
RenderTaskDelegate(pxr::HdRenderIndex *parentIndex, pxr::SdfPath const &delegateID);
RenderTaskDelegate(pxr::HdRenderIndex *parent_index, pxr::SdfPath const &delegate_id);
~RenderTaskDelegate() override = default;
pxr::SdfPath GetTaskID() const;
pxr::SdfPath GetAovID(pxr::TfToken const &aov) const;
pxr::SdfPath get_task_id() const;
pxr::SdfPath get_aov_id(pxr::TfToken const &aov) const;
pxr::VtValue Get(pxr::SdfPath const &id, pxr::TfToken const &key) override;
pxr::HdRenderBufferDescriptor GetRenderBufferDescriptor(pxr::SdfPath const &id) override;
pxr::TfTokenVector GetTaskRenderTags(pxr::SdfPath const &taskId) override;
bool IsConverged();
void SetRendererAov(pxr::TfToken const &aovId);
pxr::HdRenderBuffer *GetRendererAov(pxr::TfToken const &id);
void GetRendererAovData(pxr::TfToken const &id, void *buf);
bool is_converged();
void set_renderer_aov(pxr::TfToken const &aovId);
pxr::HdRenderBuffer *get_renderer_aov(pxr::TfToken const &id);
void get_renderer_aov_data(pxr::TfToken const &id, void *buf);
pxr::HdTaskSharedPtr GetTask();
void SetCameraAndViewport(pxr::SdfPath const &cameraId, pxr::GfVec4d const &viewport);
pxr::HdTaskSharedPtr get_task();
void set_camera_and_viewport(pxr::SdfPath const &cameraId, pxr::GfVec4d const &viewport);
private:
pxr::HdxRenderTaskParams taskParams;
pxr::HdxRenderTaskParams task_params;
pxr::TfHashMap<pxr::SdfPath, pxr::HdRenderBufferDescriptor, pxr::SdfPath::Hash>
bufferDescriptors;
buffer_descriptors;
};
} // namespace blender::render::hydra

View File

@ -10,10 +10,10 @@
namespace blender::render::hydra {
BlenderSceneDelegate::BlenderSceneDelegate(pxr::HdRenderIndex *parentIndex,
pxr::SdfPath const &delegateID,
BlenderSceneDelegate::BlenderSceneDelegate(pxr::HdRenderIndex *parent_index,
pxr::SdfPath const &delegate_id,
BlenderSceneDelegate::EngineType engine_type)
: HdSceneDelegate(parentIndex, delegateID),
: HdSceneDelegate(parent_index, delegate_id),
engine_type(engine_type),
depsgraph(nullptr),
context(nullptr),
@ -79,67 +79,68 @@ bool BlenderSceneDelegate::GetVisible(pxr::SdfPath const &id)
return object_data(id)->visible;
}
pxr::SdfPath BlenderSceneDelegate::GetInstancerId(pxr::SdfPath const &primId)
pxr::SdfPath BlenderSceneDelegate::GetInstancerId(pxr::SdfPath const &prim_id)
{
LOG(INFO) << "GetInstancerId: " << primId.GetAsString();
MeshData *m_data = mesh_data(primId);
LOG(INFO) << "GetInstancerId: " << prim_id.GetAsString();
MeshData *m_data = mesh_data(prim_id);
if (m_data) {
return m_data->instancer_id;
}
return pxr::SdfPath();
}
pxr::SdfPathVector BlenderSceneDelegate::GetInstancerPrototypes(pxr::SdfPath const &instancerId)
pxr::SdfPathVector BlenderSceneDelegate::GetInstancerPrototypes(pxr::SdfPath const &instancer_id)
{
LOG(INFO) << "GetInstancerPrototypes: " << instancerId.GetString();
LOG(INFO) << "GetInstancerPrototypes: " << instancer_id.GetString();
pxr::SdfPathVector paths;
paths.push_back(instancerId.GetParentPath());
paths.push_back(instancer_id.GetParentPath());
return paths;
}
pxr::VtIntArray BlenderSceneDelegate::GetInstanceIndices(pxr::SdfPath const &instancerId,
pxr::SdfPath const &prototypeId)
pxr::VtIntArray BlenderSceneDelegate::GetInstanceIndices(pxr::SdfPath const &instancer_id,
pxr::SdfPath const &prototype_id)
{
LOG(INFO) << "GetInstanceIndices: " << instancerId.GetString() << " " << prototypeId.GetString();
MeshData *m_data = mesh_data(prototypeId);
LOG(INFO) << "GetInstanceIndices: " << instancer_id.GetString() << " "
<< prototype_id.GetString();
MeshData *m_data = mesh_data(prototype_id);
pxr::VtIntArray ret = m_data->instance_indices();
return ret;
}
pxr::GfMatrix4d BlenderSceneDelegate::GetInstancerTransform(pxr::SdfPath const &instancerId)
pxr::GfMatrix4d BlenderSceneDelegate::get_instancer_transform(pxr::SdfPath const &instancer_id)
{
LOG(INFO) << "GetInstancerTransform: " << instancerId.GetString();
LOG(INFO) << "get_instancer_transform: " << instancer_id.GetString();
// TODO: add a separate object for instancer for cleaner handling code
// Actual instancer transform is get here
return pxr::GfMatrix4d(1.0);
}
size_t BlenderSceneDelegate::SampleInstancerTransform(pxr::SdfPath const &instancerId,
size_t maxSampleCount,
float *sampleTimes,
pxr::GfMatrix4d *sampleValues)
size_t BlenderSceneDelegate::SampleInstancerTransform(pxr::SdfPath const &instancer_id,
size_t max_sample_count,
float *sample_times,
pxr::GfMatrix4d *sample_values)
{
LOG(INFO) << "SampleInstancerTransform: " << instancerId.GetString();
LOG(INFO) << "SampleInstancerTransform: " << instancer_id.GetString();
size_t ret = 0;
MeshData *m_data = mesh_data(instancerId.GetParentPath());
ret = m_data->sample_instancer_transform(maxSampleCount, sampleTimes, sampleValues);
MeshData *m_data = mesh_data(instancer_id.GetParentPath());
ret = m_data->sample_instancer_transform(max_sample_count, sample_times, sample_values);
return ret;
}
size_t BlenderSceneDelegate::SamplePrimvar(pxr::SdfPath const &id,
pxr::TfToken const &key,
size_t maxSampleCount,
float *sampleTimes,
pxr::VtValue *sampleValues)
size_t max_sample_count,
float *sample_times,
pxr::VtValue *sample_values)
{
// TODO: add a separate object for instancer for cleaner handling code
if (id.GetName() == "Instancer") {
MeshData *m_data = mesh_data(id.GetParentPath());
if (m_data) {
return m_data->sample_instancer_primvar(key, maxSampleCount, sampleTimes, sampleValues);
return m_data->sample_instancer_primvar(key, max_sample_count, sample_times, sample_values);
}
}
return HdSceneDelegate::SamplePrimvar(id, key, maxSampleCount, sampleTimes, sampleValues);
return HdSceneDelegate::SamplePrimvar(id, key, max_sample_count, sample_times, sample_values);
}
void BlenderSceneDelegate::update_collection(bool remove, bool visibility)
@ -432,9 +433,9 @@ pxr::HdPrimvarDescriptorVector BlenderSceneDelegate::GetPrimvarDescriptors(
return primvars;
}
pxr::SdfPath BlenderSceneDelegate::GetMaterialId(pxr::SdfPath const &rprimId)
pxr::SdfPath BlenderSceneDelegate::GetMaterialId(pxr::SdfPath const &rprim_id)
{
return mesh_data(rprimId)->material_id;
return mesh_data(rprim_id)->material_id;
}
pxr::VtValue BlenderSceneDelegate::GetMaterialResource(pxr::SdfPath const &id)

View File

@ -17,10 +17,10 @@ namespace blender::render::hydra {
class BlenderSceneDelegate : public pxr::HdSceneDelegate {
public:
enum class EngineType { Viewport = 1, Final, Preview };
enum class EngineType { VIEWPORT = 1, FINAL, PREVIEW };
BlenderSceneDelegate(pxr::HdRenderIndex *render_index,
pxr::SdfPath const &delegateId,
pxr::SdfPath const &delegate_id,
BlenderSceneDelegate::EngineType engine_type);
~BlenderSceneDelegate() override = default;
@ -33,23 +33,23 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
pxr::VtValue GetLightParamValue(pxr::SdfPath const &id, pxr::TfToken const &key) override;
pxr::HdPrimvarDescriptorVector GetPrimvarDescriptors(
pxr::SdfPath const &id, pxr::HdInterpolation interpolation) override;
pxr::SdfPath GetMaterialId(pxr::SdfPath const &rprimId) override;
pxr::VtValue GetMaterialResource(pxr::SdfPath const &materialId) override;
pxr::SdfPath GetMaterialId(pxr::SdfPath const &rprim_id) override;
pxr::VtValue GetMaterialResource(pxr::SdfPath const &material_id) override;
bool GetVisible(pxr::SdfPath const &id) override;
pxr::SdfPath GetInstancerId(pxr::SdfPath const &primId) override;
pxr::SdfPathVector GetInstancerPrototypes(pxr::SdfPath const &instancerId) override;
pxr::VtIntArray GetInstanceIndices(pxr::SdfPath const &instancerId,
pxr::SdfPath const &prototypeId) override;
pxr::GfMatrix4d GetInstancerTransform(pxr::SdfPath const &instancerId);
size_t SampleInstancerTransform(pxr::SdfPath const &instancerId,
size_t maxSampleCount,
float *sampleTimes,
pxr::GfMatrix4d *sampleValues) override;
pxr::SdfPath GetInstancerId(pxr::SdfPath const &prim_id) override;
pxr::SdfPathVector GetInstancerPrototypes(pxr::SdfPath const &instancer_id) override;
pxr::VtIntArray GetInstanceIndices(pxr::SdfPath const &instancer_id,
pxr::SdfPath const &prototype_id) override;
pxr::GfMatrix4d get_instancer_transform(pxr::SdfPath const &instancer_id);
size_t SampleInstancerTransform(pxr::SdfPath const &instancer_id,
size_t max_sample_count,
float *sample_times,
pxr::GfMatrix4d *sample_values) override;
size_t SamplePrimvar(pxr::SdfPath const &id,
pxr::TfToken const &key,
size_t maxSampleCount,
float *sampleTimes,
pxr::VtValue *sampleValues) override;
size_t max_sample_count,
float *sample_times,
pxr::VtValue *sample_values) override;
EngineType engine_type;

View File

@ -23,7 +23,7 @@ LightData::LightData(BlenderSceneDelegate *scene_delegate, Object *object)
Light *light = (Light *)((Object *)id)->data;
data[pxr::HdLightTokens->intensity] = scene_delegate->engine_type ==
BlenderSceneDelegate::EngineType::Preview ?
BlenderSceneDelegate::EngineType::PREVIEW ?
light->energy / 1000 :
light->energy;

View File

@ -110,24 +110,24 @@ pxr::VtIntArray MeshData::instance_indices()
return ret;
}
size_t MeshData::sample_instancer_transform(size_t maxSampleCount,
float *sampleTimes,
pxr::GfMatrix4d *sampleValues)
size_t MeshData::sample_instancer_transform(size_t max_sample_count,
float *sample_times,
pxr::GfMatrix4d *sample_values)
{
*sampleTimes = 0.0f;
*sampleValues = pxr::GfMatrix4d(1.0);
*sample_times = 0.0f;
*sample_values = pxr::GfMatrix4d(1.0);
return 1;
}
size_t MeshData::sample_instancer_primvar(pxr::TfToken const &key,
size_t maxSampleCount,
float *sampleTimes,
pxr::VtValue *sampleValues)
size_t max_sample_count,
float *sample_times,
pxr::VtValue *sample_values)
{
if (key == pxr::HdInstancerTokens->instanceTransform) {
if (maxSampleCount > 0) {
sampleTimes[0] = 0.0f;
sampleValues[0] = instances;
if (max_sample_count > 0) {
sample_times[0] = 0.0f;
sample_values[0] = instances;
return 1;
}
}

View File

@ -27,13 +27,13 @@ class MeshData : public ObjectData {
pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation);
pxr::HdPrimvarDescriptorVector instancer_primvar_descriptors(pxr::HdInterpolation interpolation);
pxr::VtIntArray instance_indices();
size_t sample_instancer_transform(size_t maxSampleCount,
float *sampleTimes,
pxr::GfMatrix4d *sampleValues);
size_t sample_instancer_transform(size_t max_sample_count,
float *sample_times,
pxr::GfMatrix4d *sample_values);
size_t sample_instancer_primvar(pxr::TfToken const &key,
size_t maxSampleCount,
float *sampleTimes,
pxr::VtValue *sampleValues);
size_t max_sample_count,
float *sample_times,
pxr::VtValue *sample_values);
void add_instance(DupliObject *dupli);

View File

@ -22,29 +22,29 @@
namespace mx = MaterialX;
void HdMtlxConvertToMaterialNetworkMap(std::string const &mtlxPath,
pxr::TfTokenVector const &shaderSourceTypes,
pxr::TfTokenVector const &renderContexts,
void HdMtlxConvertToMaterialNetworkMap(std::string const &mtlx_path,
pxr::TfTokenVector const &shader_source_types,
pxr::TfTokenVector const &render_contexts,
pxr::HdMaterialNetworkMap *out)
{
if (mtlxPath.empty()) {
if (mtlx_path.empty()) {
return;
}
std::string basePath = pxr::TfGetPathName(mtlxPath);
std::string basePath = pxr::TfGetPathName(mtlx_path);
pxr::ArResolver &resolver = pxr::ArGetResolver();
const pxr::ArResolverContext context = resolver.CreateDefaultContextForAsset(mtlxPath);
const pxr::ArResolverContext context = resolver.CreateDefaultContextForAsset(mtlx_path);
pxr::ArResolverContextBinder binder(context);
pxr::ArResolverScopedCache resolverCache;
pxr::ArResolverScopedCache resolver_cache;
std::string mtlxName = pxr::TfGetBaseName(mtlxPath);
std::string stageId = pxr::TfStringPrintf(
std::string mtlxName = pxr::TfGetBaseName(mtlx_path);
std::string stage_id = pxr::TfStringPrintf(
"%s%s%s.usda", basePath.c_str(), ARCH_PATH_SEP, mtlxName.c_str());
pxr::UsdStageRefPtr stage = pxr::UsdStage::CreateInMemory(stageId, context);
pxr::UsdStageRefPtr stage = pxr::UsdStage::CreateInMemory(stage_id, context);
try {
mx::DocumentPtr doc = pxr::UsdMtlxReadDocument(mtlxPath);
mx::DocumentPtr doc = pxr::UsdMtlxReadDocument(mtlx_path);
pxr::UsdMtlxRead(doc, stage);
}
catch (mx::ExceptionFoundCycle &x) {
@ -65,11 +65,11 @@ void HdMtlxConvertToMaterialNetworkMap(std::string const &mtlxPath,
if (pxr::UsdPrim materials = stage->GetPrimAtPath(pxr::SdfPath("/MaterialX/Materials"))) {
if (pxr::UsdPrimSiblingRange children = materials.GetChildren()) {
if (auto material = pxr::UsdShadeMaterial(*children.begin())) {
if (pxr::UsdShadeShader mtlxSurface = material.ComputeSurfaceSource(renderContexts)) {
UsdImagingBuildHdMaterialNetworkFromTerminal(mtlxSurface.GetPrim(),
if (pxr::UsdShadeShader mtlx_surface = material.ComputeSurfaceSource(render_contexts)) {
UsdImagingBuildHdMaterialNetworkFromTerminal(mtlx_surface.GetPrim(),
pxr::HdMaterialTerminalTokens->surface,
shaderSourceTypes,
renderContexts,
shader_source_types,
render_contexts,
out,
pxr::UsdTimeCode::Default());
}

View File

@ -10,7 +10,7 @@
struct pxr::HdMaterialNetworkMap;
void HdMtlxConvertToMaterialNetworkMap(std::string const &mtlxPath,
pxr::TfTokenVector const &shaderSourceTypes,
pxr::TfTokenVector const &renderContexts,
void HdMtlxConvertToMaterialNetworkMap(std::string const &mtlx_path,
pxr::TfTokenVector const &shader_source_types,
pxr::TfTokenVector const &render_contexts,
pxr::HdMaterialNetworkMap *out);

View File

@ -7,33 +7,33 @@
namespace blender::render::hydra {
SimpleLightTaskDelegate::SimpleLightTaskDelegate(pxr::HdRenderIndex *parentIndex,
pxr::SdfPath const &delegateID)
: pxr::HdSceneDelegate(parentIndex, delegateID)
SimpleLightTaskDelegate::SimpleLightTaskDelegate(pxr::HdRenderIndex *parent_index,
pxr::SdfPath const &delegate_id)
: pxr::HdSceneDelegate(parent_index, delegate_id)
{
pxr::SdfPath taskId = GetTaskID();
GetRenderIndex().InsertTask<pxr::HdxSimpleLightTask>(this, taskId);
pxr::SdfPath task_id = get_task_id();
GetRenderIndex().InsertTask<pxr::HdxSimpleLightTask>(this, task_id);
}
pxr::SdfPath SimpleLightTaskDelegate::GetTaskID() const
pxr::SdfPath SimpleLightTaskDelegate::get_task_id() const
{
return GetDelegateID().AppendElementString("task");
}
pxr::HdTaskSharedPtr SimpleLightTaskDelegate::GetTask()
pxr::HdTaskSharedPtr SimpleLightTaskDelegate::get_task()
{
return GetRenderIndex().GetTask(GetTaskID());
return GetRenderIndex().GetTask(get_task_id());
}
void SimpleLightTaskDelegate::SetCameraPath(pxr::SdfPath const &cameraPath)
void SimpleLightTaskDelegate::set_camera_path(pxr::SdfPath const &camera_path)
{
taskParams.cameraPath = cameraPath;
task_params.cameraPath = camera_path;
}
pxr::VtValue SimpleLightTaskDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const &key)
{
if (key == pxr::HdTokens->params) {
return pxr::VtValue(taskParams);
return pxr::VtValue(task_params);
}
return pxr::VtValue();
}

View File

@ -10,18 +10,18 @@ namespace blender::render::hydra {
class SimpleLightTaskDelegate : public pxr::HdSceneDelegate {
public:
SimpleLightTaskDelegate(pxr::HdRenderIndex *parentIndex, pxr::SdfPath const &delegateID);
SimpleLightTaskDelegate(pxr::HdRenderIndex *parentIndex, pxr::SdfPath const &delegate_id);
~SimpleLightTaskDelegate() override = default;
pxr::SdfPath GetTaskID() const;
pxr::SdfPath get_task_id() const;
pxr::HdTaskSharedPtr GetTask();
void SetCameraPath(pxr::SdfPath const &);
pxr::HdTaskSharedPtr get_task();
void set_camera_path(pxr::SdfPath const &);
pxr::VtValue Get(pxr::SdfPath const &id, pxr::TfToken const &key) override;
private:
pxr::HdxSimpleLightTaskParams taskParams;
pxr::HdxSimpleLightTaskParams task_params;
};
} // namespace blender::render::hydra

View File

@ -134,20 +134,20 @@ pxr::GfCamera ViewSettings::gf_camera()
(float)border[3] / screen_height));
}
GLTexture::GLTexture() : textureId(0), width(0), height(0), channels(4)
GLTexture::GLTexture() : texture_id(0), width(0), height(0), channels(4)
{
}
GLTexture::~GLTexture()
{
if (textureId) {
if (texture_id) {
free();
}
}
void GLTexture::setBuffer(pxr::HdRenderBuffer *buffer)
void GLTexture::set_buffer(pxr::HdRenderBuffer *buffer)
{
if (!textureId) {
if (!texture_id) {
create(buffer);
return;
}
@ -158,7 +158,7 @@ void GLTexture::setBuffer(pxr::HdRenderBuffer *buffer)
return;
}
glBindTexture(GL_TEXTURE_2D, textureId);
glBindTexture(GL_TEXTURE_2D, texture_id);
void *data = buffer->Map();
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_FLOAT, data);
@ -171,8 +171,8 @@ void GLTexture::create(pxr::HdRenderBuffer *buffer)
height = buffer->GetHeight();
channels = pxr::HdGetComponentCount(buffer->GetFormat());
glGenTextures(1, &textureId);
glBindTexture(GL_TEXTURE_2D, textureId);
glGenTextures(1, &texture_id);
glBindTexture(GL_TEXTURE_2D, texture_id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
@ -185,8 +185,8 @@ void GLTexture::create(pxr::HdRenderBuffer *buffer)
void GLTexture::free()
{
glDeleteTextures(1, &textureId);
textureId = 0;
glDeleteTextures(1, &texture_id);
texture_id = 0;
}
void GLTexture::draw(GLfloat x, GLfloat y)
@ -218,7 +218,7 @@ void GLTexture::draw(GLfloat x, GLfloat y)
// DRAWING
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textureId);
glBindTexture(GL_TEXTURE_2D, texture_id);
glBindVertexArray(vertex_array);
glEnableVertexAttribArray(texturecoord_location);
@ -242,45 +242,45 @@ void GLTexture::draw(GLfloat x, GLfloat y)
void ViewportEngine::sync(Depsgraph *depsgraph,
bContext *context,
pxr::HdRenderSettingsMap &renderSettings)
pxr::HdRenderSettingsMap &render_settings)
{
if (!scene_delegate) {
scene_delegate = std::make_unique<BlenderSceneDelegate>(
render_index.get(),
pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"),
BlenderSceneDelegate::EngineType::Viewport);
BlenderSceneDelegate::EngineType::VIEWPORT);
}
scene_delegate->populate(depsgraph, context);
for (auto const &setting : renderSettings) {
for (auto const &setting : render_settings) {
render_delegate->SetRenderSetting(setting.first, setting.second);
}
}
void ViewportEngine::render(Depsgraph *depsgraph, bContext *context)
{
ViewSettings viewSettings(context);
if (viewSettings.width() * viewSettings.height() == 0) {
ViewSettings view_settings(context);
if (view_settings.width() * view_settings.height() == 0) {
return;
};
pxr::GfCamera gfCamera = viewSettings.gf_camera();
pxr::GfCamera gfCamera = view_settings.gf_camera();
free_camera_delegate->SetCamera(gfCamera);
render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(),
pxr::GfVec4d(viewSettings.border[0],
viewSettings.border[1],
viewSettings.border[2],
viewSettings.border[3]));
render_task_delegate->set_camera_and_viewport(free_camera_delegate->GetCameraId(),
pxr::GfVec4d(view_settings.border[0],
view_settings.border[1],
view_settings.border[2],
view_settings.border[3]));
if (simple_light_task_delegate) {
simple_light_task_delegate->SetCameraPath(free_camera_delegate->GetCameraId());
simple_light_task_delegate->set_camera_path(free_camera_delegate->GetCameraId());
}
if ((bl_engine->type->flag & RE_USE_GPU_CONTEXT) == 0) {
render_task_delegate->SetRendererAov(pxr::HdAovTokens->color);
render_task_delegate->set_renderer_aov(pxr::HdAovTokens->color);
}
if (renderer_percent_done() == 0.0f) {
timeBegin = std::chrono::steady_clock::now();
time_begin = std::chrono::steady_clock::now();
}
GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_IMAGE);
@ -288,9 +288,9 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context)
pxr::HdTaskSharedPtrVector tasks;
if (simple_light_task_delegate) {
tasks.push_back(simple_light_task_delegate->GetTask());
tasks.push_back(simple_light_task_delegate->get_task());
}
tasks.push_back(render_task_delegate->GetTask());
tasks.push_back(render_task_delegate->get_task());
{
/* Release the GIL before calling into hydra, in case any hydra plugins call into python. */
@ -298,28 +298,28 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context)
engine->Execute(render_index.get(), &tasks);
if ((bl_engine->type->flag & RE_USE_GPU_CONTEXT) == 0) {
texture.setBuffer(render_task_delegate->GetRendererAov(pxr::HdAovTokens->color));
texture.draw((GLfloat)viewSettings.border[0], (GLfloat)viewSettings.border[1]);
texture.set_buffer(render_task_delegate->get_renderer_aov(pxr::HdAovTokens->color));
texture.draw((GLfloat)view_settings.border[0], (GLfloat)view_settings.border[1]);
}
}
GPU_shader_unbind();
std::chrono::time_point<std::chrono::steady_clock> timeCurrent =
std::chrono::time_point<std::chrono::steady_clock> time_current =
std::chrono::steady_clock::now();
std::chrono::milliseconds elapsedTime = std::chrono::duration_cast<std::chrono::milliseconds>(
timeCurrent - timeBegin);
std::chrono::milliseconds elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(
time_current - time_begin);
std::string formattedTime = format_duration(elapsedTime);
std::string formatted_time = format_duration(elapsed_time);
if (!render_task_delegate->IsConverged()) {
notify_status("Time: " + formattedTime +
if (!render_task_delegate->is_converged()) {
notify_status("Time: " + formatted_time +
" | Done: " + std::to_string(int(renderer_percent_done())) + "%",
"Render");
bl_engine->flag |= RE_ENGINE_DO_DRAW;
}
else {
notify_status(("Time: " + formattedTime).c_str(), "Rendering Done");
notify_status(("Time: " + formatted_time).c_str(), "Rendering Done");
}
}

View File

@ -17,14 +17,14 @@ class GLTexture {
public:
GLTexture();
~GLTexture();
void setBuffer(pxr::HdRenderBuffer *buffer);
void set_buffer(pxr::HdRenderBuffer *buffer);
void draw(GLfloat x, GLfloat y);
private:
void create(pxr::HdRenderBuffer *buffer);
void free();
GLuint textureId;
GLuint texture_id;
int width, height, channels;
};
@ -33,7 +33,7 @@ class ViewportEngine : public Engine {
using Engine::Engine;
void sync(Depsgraph *depsgraph,
bContext *context,
pxr::HdRenderSettingsMap &renderSettings) override;
pxr::HdRenderSettingsMap &render_settings) override;
void render(Depsgraph *depsgraph) override;
void render(Depsgraph *depsgraph, bContext *context);
@ -41,7 +41,7 @@ class ViewportEngine : public Engine {
void notify_status(const std::string &title, const std::string &info);
private:
std::chrono::time_point<std::chrono::steady_clock> timeBegin;
std::chrono::time_point<std::chrono::steady_clock> time_begin;
GLTexture texture;
};