forked from blender/blender
Fix review comments 2 #31
@ -31,42 +31,12 @@ void FinalEngine::sync(Depsgraph *depsgraph,
|
|||||||
|
|
||||||
void FinalEngine::render(Depsgraph *depsgraph)
|
void FinalEngine::render(Depsgraph *depsgraph)
|
||||||
{
|
{
|
||||||
const Scene *scene = DEG_get_evaluated_scene(depsgraph);
|
prepare_for_render(depsgraph);
|
||||||
const ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph);
|
|
||||||
|
|
||||||
std::string scene_name(MAX_ID_FULL_NAME, 0);
|
|
||||||
BKE_id_full_name_get(scene_name.data(), (ID *)scene, 0);
|
|
||||||
std::string layer_name = view_layer->name;
|
|
||||||
|
|
||||||
const RenderData &r = scene->r;
|
|
||||||
pxr::GfVec4f border = get_resolution(scene);
|
|
||||||
pxr::GfVec2i image_res(r.xsch * r.size / 100, r.ysch * r.size / 100);
|
|
||||||
pxr::GfVec2i res(int(image_res[0] * border[2]), int(image_res[1] * border[3]));
|
|
||||||
pxr::GfCamera camera =
|
|
||||||
CameraData(scene->camera, image_res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(border);
|
|
||||||
|
|
||||||
free_camera_delegate_->SetCamera(camera);
|
|
||||||
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_->set_camera_path(free_camera_delegate_->GetCameraId());
|
|
||||||
}
|
|
||||||
|
|
||||||
pxr::HdTaskSharedPtrVector tasks;
|
|
||||||
if (simple_light_task_delegate_) {
|
|
||||||
tasks.push_back(simple_light_task_delegate_->get_task());
|
|
||||||
}
|
|
||||||
tasks.push_back(render_task_delegate_->get_task());
|
|
||||||
|
|
||||||
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 = render_images["Combined"];
|
|
||||||
|
|
||||||
{
|
{
|
||||||
/* Release the GIL before calling into hydra, in case any hydra plugins call into python. */
|
/* Release the GIL before calling into hydra, in case any hydra plugins call into python. */
|
||||||
pxr::TF_PY_ALLOW_THREADS_IN_SCOPE();
|
pxr::TF_PY_ALLOW_THREADS_IN_SCOPE();
|
||||||
engine_->Execute(render_index_.get(), &tasks);
|
engine_->Execute(render_index_.get(), &tasks_);
|
||||||
}
|
}
|
||||||
|
|
||||||
char elapsed_time[32];
|
char elapsed_time[32];
|
||||||
@ -84,7 +54,7 @@ void FinalEngine::render(Depsgraph *depsgraph)
|
|||||||
elapsed_time, sizeof(elapsed_time), PIL_check_seconds_timer() - time_begin);
|
elapsed_time, sizeof(elapsed_time), PIL_check_seconds_timer() - time_begin);
|
||||||
|
|
||||||
notify_status(percent_done / 100.0,
|
notify_status(percent_done / 100.0,
|
||||||
scene_name + ": " + layer_name,
|
scene_name_ + ": " + layer_name_,
|
||||||
std::string("Render Time: ") + elapsed_time +
|
std::string("Render Time: ") + elapsed_time +
|
||||||
" | Done: " + std::to_string(int(percent_done)) + "%");
|
" | Done: " + std::to_string(int(percent_done)) + "%");
|
||||||
|
|
||||||
@ -92,12 +62,12 @@ void FinalEngine::render(Depsgraph *depsgraph)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
render_task_delegate_->get_renderer_aov_data(pxr::HdAovTokens->color, pixels.data());
|
render_task_delegate_->get_renderer_aov_data(pxr::HdAovTokens->color, pixels_.data());
|
||||||
update_render_result(render_images, layer_name, res[0], res[1]);
|
update_render_result(render_images_, layer_name_, resolution_[0], resolution_[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
render_task_delegate_->get_renderer_aov_data(pxr::HdAovTokens->color, pixels.data());
|
render_task_delegate_->get_renderer_aov_data(pxr::HdAovTokens->color, pixels_.data());
|
||||||
update_render_result(render_images, layer_name, res[0], res[1]);
|
update_render_result(render_images_, layer_name_, resolution_[0], resolution_[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
pxr::GfVec4f FinalEngine::get_resolution(const Scene *scene)
|
pxr::GfVec4f FinalEngine::get_resolution(const Scene *scene)
|
||||||
|
|||||||
@ -140,46 +110,45 @@ void FinalEngine::notify_status(float progress, const std::string &title, const
|
|||||||
RE_engine_update_stats(bl_engine_, title.c_str(), info.c_str());
|
RE_engine_update_stats(bl_engine_, title.c_str(), info.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void FinalEngineGL::render(Depsgraph *depsgraph)
|
void FinalEngine::prepare_for_render(Depsgraph *depsgraph)
|
||||||
{
|
{
|
||||||
const Scene *scene = DEG_get_evaluated_scene(depsgraph);
|
const Scene *scene = DEG_get_evaluated_scene(depsgraph);
|
||||||
const ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph);
|
const ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph);
|
||||||
|
|
||||||
std::string scene_name(MAX_ID_FULL_NAME, 0);
|
BKE_id_full_name_get(scene_name_.data(), (ID *)scene, 0);
|
||||||
BKE_id_full_name_get(scene_name.data(), (ID *)scene, 0);
|
layer_name_ = view_layer->name;
|
||||||
std::string layer_name = view_layer->name;
|
|
||||||
|
|
||||||
const RenderData &r = scene->r;
|
const RenderData &r = scene->r;
|
||||||
pxr::GfVec4f border = get_resolution(scene);
|
pxr::GfVec4f border = get_resolution(scene);
|
||||||
pxr::GfVec2i image_res(r.xsch * r.size / 100, r.ysch * r.size / 100);
|
pxr::GfVec2i image_res(r.xsch * r.size / 100, r.ysch * r.size / 100);
|
||||||
pxr::GfVec2i res(int(image_res[0] * border[2]), int(image_res[1] * border[3]));
|
resolution_ = pxr::GfVec2i(int(image_res[0] * border[2]), int(image_res[1] * border[3]));
|
||||||
pxr::GfCamera camera =
|
pxr::GfCamera camera =
|
||||||
CameraData(scene->camera, image_res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(border);
|
CameraData(scene->camera, image_res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(border);
|
||||||
|
|
||||||
free_camera_delegate_->SetCamera(camera);
|
free_camera_delegate_->SetCamera(camera);
|
||||||
render_task_delegate_->set_camera_and_viewport(free_camera_delegate_->GetCameraId(),
|
render_task_delegate_->set_camera_and_viewport(free_camera_delegate_->GetCameraId(), pxr::GfVec4d(0, 0, resolution_[0], resolution_[1]));
|
||||||
pxr::GfVec4d(0, 0, res[0], res[1]));
|
render_task_delegate_->set_renderer_aov(pxr::HdAovTokens->color);
|
||||||
|
|
||||||
if (simple_light_task_delegate_) {
|
if (simple_light_task_delegate_) {
|
||||||
simple_light_task_delegate_->set_camera_path(free_camera_delegate_->GetCameraId());
|
simple_light_task_delegate_->set_camera_path(free_camera_delegate_->GetCameraId());
|
||||||
|
tasks_.push_back(simple_light_task_delegate_->get_task());
|
||||||
|
}
|
||||||
|
tasks_.push_back(render_task_delegate_->get_task());
|
||||||
|
|
||||||
|
render_images_.emplace(
|
||||||
|
"Combined",
|
||||||
|
std::vector<float>(resolution_[0] * resolution_[1] * 4)); /* 4 - number of channels. */
|
||||||
|
pixels_ = render_images_["Combined"];
|
||||||
}
|
}
|
||||||
|
|
||||||
pxr::HdTaskSharedPtrVector tasks;
|
void FinalEngineGL::render(Depsgraph *depsgraph)
|
||||||
if (simple_light_task_delegate_) {
|
{
|
||||||
/* TODO: Uncomment this and fix GL error:
|
prepare_for_render(depsgraph);
|
||||||
* invalid operation, reported from void __cdecl
|
|
||||||
* pxrInternal_v0_22__pxrReserved__::HgiGLResourceBindings::BindResources(void) */
|
|
||||||
// tasks.push_back(simple_light_task_delegate_->get_task());
|
|
||||||
}
|
|
||||||
tasks.push_back(render_task_delegate_->get_task());
|
|
||||||
|
|
||||||
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 = render_images["Combined"];
|
|
||||||
|
|
||||||
GPUFrameBuffer *framebuffer = GPU_framebuffer_create("fb_hdyra_render_final");
|
GPUFrameBuffer *framebuffer = GPU_framebuffer_create("fb_hdyra_render_final");
|
||||||
GPUTexture *texture = GPU_texture_create_2d("tex_hydra_render_final",
|
GPUTexture *texture = GPU_texture_create_2d("tex_hydra_render_final",
|
||||||
res[0],
|
resolution_[0],
|
||||||
res[1],
|
resolution_[1],
|
||||||
1,
|
1,
|
||||||
GPU_RGBA32F,
|
GPU_RGBA32F,
|
||||||
GPU_TEXTURE_USAGE_GENERAL,
|
GPU_TEXTURE_USAGE_GENERAL,
|
||||||
@ -195,7 +164,7 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
|
|||||||
{
|
{
|
||||||
/* Release the GIL before calling into hydra, in case any hydra plugins call into python. */
|
/* Release the GIL before calling into hydra, in case any hydra plugins call into python. */
|
||||||
pxr::TF_PY_ALLOW_THREADS_IN_SCOPE();
|
pxr::TF_PY_ALLOW_THREADS_IN_SCOPE();
|
||||||
engine_->Execute(render_index_.get(), &tasks);
|
engine_->Execute(render_index_.get(), &tasks_);
|
||||||
}
|
}
|
||||||
|
|
||||||
char elapsed_time[32];
|
char elapsed_time[32];
|
||||||
@ -213,7 +182,7 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
|
|||||||
elapsed_time, sizeof(elapsed_time), PIL_check_seconds_timer() - time_begin);
|
elapsed_time, sizeof(elapsed_time), PIL_check_seconds_timer() - time_begin);
|
||||||
|
|
||||||
notify_status(percent_done / 100.0,
|
notify_status(percent_done / 100.0,
|
||||||
scene_name + ": " + layer_name,
|
scene_name_ + ": " + layer_name_,
|
||||||
std::string("Render Time: ") + elapsed_time +
|
std::string("Render Time: ") + elapsed_time +
|
||||||
" | Done: " + std::to_string(int(percent_done)) + "%");
|
" | Done: " + std::to_string(int(percent_done)) + "%");
|
||||||
|
|
||||||
@ -222,15 +191,15 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void *data = GPU_texture_read(texture, GPU_DATA_FLOAT, 0);
|
void *data = GPU_texture_read(texture, GPU_DATA_FLOAT, 0);
|
||||||
memcpy(pixels.data(), data, pixels.size() * sizeof(float));
|
memcpy(pixels_.data(), data, pixels_.size() * sizeof(float));
|
||||||
MEM_freeN(data);
|
MEM_freeN(data);
|
||||||
update_render_result(render_images, layer_name, res[0], res[1]);
|
update_render_result(render_images_, layer_name_, resolution_[0], resolution_[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *data = GPU_texture_read(texture, GPU_DATA_FLOAT, 0);
|
void *data = GPU_texture_read(texture, GPU_DATA_FLOAT, 0);
|
||||||
memcpy(pixels.data(), data, pixels.size() * sizeof(float));
|
memcpy(pixels_.data(), data, pixels_.size() * sizeof(float));
|
||||||
MEM_freeN(data);
|
MEM_freeN(data);
|
||||||
update_render_result(render_images, layer_name, res[0], res[1]);
|
update_render_result(render_images_, layer_name_, resolution_[0], resolution_[1]);
|
||||||
|
|
||||||
Bogdan Nagirniak
commented
Simplify Simplify `update_render_result` - no need to provide parameters
|
|||||||
GPU_framebuffer_free(framebuffer);
|
GPU_framebuffer_free(framebuffer);
|
||||||
GPU_texture_free(texture);
|
GPU_texture_free(texture);
|
||||||
|
@ -23,8 +23,15 @@ class FinalEngine : public Engine {
|
|||||||
int width,
|
int width,
|
||||||
int height);
|
int height);
|
||||||
void notify_status(float progress, const std::string &title, const std::string &info);
|
void notify_status(float progress, const std::string &title, const std::string &info);
|
||||||
|
void prepare_for_render(Depsgraph *depsgraph);
|
||||||
|
|
||||||
pxr::HdRenderSettingsMap render_settings_;
|
pxr::HdRenderSettingsMap render_settings_;
|
||||||
|
pxr::HdTaskSharedPtrVector tasks_;
|
||||||
|
std::string scene_name_;
|
||||||
|
std::string layer_name_;
|
||||||
|
std::map<std::string, std::vector<float>> render_images_;
|
||||||
|
pxr::GfVec2i resolution_;
|
||||||
|
std::vector<float> pixels_;
|
||||||
Bogdan Nagirniak
commented
move pixels as local variable to render() move pixels as local variable to render()
|
|||||||
};
|
};
|
||||||
|
|
||||||
class FinalEngineGL : public FinalEngine {
|
class FinalEngineGL : public FinalEngine {
|
||||||
|
Loading…
Reference in New Issue
Block a user
rename to
get_render_border