Fix rendering of Final render for Storm delegate #61

Merged
Bogdan Nagirniak merged 11 commits from BLEN-437 into hydra-render 2023-07-12 23:18:03 +02:00
Showing only changes of commit 9da35493ac - Show all commits

View File

@ -118,23 +118,39 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
{ {
prepare_for_render(depsgraph); prepare_for_render(depsgraph);
GPUFrameBuffer *framebuffer = GPU_framebuffer_create("fb_hydra_render_final"); GPUFrameBuffer *framebuffer = GPU_framebuffer_create("fb_render_hydra");
GPUTexture *texture = GPU_texture_create_2d("tex_hydra_render_final", GPUTexture *tex_color = GPU_texture_create_2d("tex_render_hydra_color",
resolution_[0], resolution_[0],
resolution_[1], resolution_[1],
1, 1,
GPU_RGBA32F, GPU_RGBA32F,
GPU_TEXTURE_USAGE_ATTACHMENT, GPU_TEXTURE_USAGE_GENERAL,
nullptr); nullptr);
GPU_texture_filter_mode(texture, true); GPUTexture *tex_depth = GPU_texture_create_2d("tex_render_hydra_depth",
GPU_texture_mipmap_mode(texture, true, true); resolution_[0],
resolution_[1],
1,
GPU_DEPTH32F_STENCIL8,
GPU_TEXTURE_USAGE_GENERAL,
nullptr);
GPU_texture_filter_mode(tex_color, true);
GPU_texture_mipmap_mode(tex_color, true, true);
GPU_texture_filter_mode(tex_depth, true);
GPU_texture_mipmap_mode(tex_depth, true, true);
GPU_framebuffer_ensure_config(
&framebuffer, {GPU_ATTACHMENT_TEXTURE(tex_depth), GPU_ATTACHMENT_TEXTURE(tex_color)});
GPU_framebuffer_bind(framebuffer); GPU_framebuffer_bind(framebuffer);
GPU_framebuffer_texture_attach(framebuffer, texture, 0, 0);
float clear_color[4] = {0.1f, 0.1f, 0.1f, 1.0f}; float clear_color[4] = {0.1f, 0.1f, 0.1f, 1.0f};
GPU_framebuffer_clear_color_depth(framebuffer, clear_color, 1.0); GPU_framebuffer_clear_color_depth(framebuffer, clear_color, 1.0);
// Generate vertex array
GLuint vao;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
engine_->Execute(render_index_.get(), &tasks_); engine_->Execute(render_index_.get(), &tasks_);
std::vector<float> &pixels = render_images_["Combined"]; std::vector<float> &pixels = render_images_["Combined"];
@ -161,19 +177,20 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
break; break;
} }
void *data = GPU_texture_read(texture, GPU_DATA_FLOAT, 0); void *data = GPU_texture_read(tex_color, 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(); update_render_result();
} }
void *data = GPU_texture_read(texture, GPU_DATA_FLOAT, 0); void *data = GPU_texture_read(tex_color, 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(); update_render_result();
GPU_framebuffer_free(framebuffer); GPU_framebuffer_free(framebuffer);
GPU_texture_free(texture); GPU_texture_free(tex_color);
GPU_texture_free(tex_depth);
} }
void FinalEngineGL::render0(Depsgraph *depsgraph) void FinalEngineGL::render0(Depsgraph *depsgraph)
@ -282,13 +299,17 @@ void FinalEngineGL::render1(Depsgraph *depsgraph)
{ {
prepare_for_render(depsgraph); prepare_for_render(depsgraph);
// pxr::TraceCollector::GetInstance().SetEnabled(true);
auto d = pxr::GlfDrawTarget::New(resolution_); auto d = pxr::GlfDrawTarget::New(resolution_);
d->Bind(); d->Bind();
d->AddAttachment("color", GL_RGBA, GL_FLOAT, GL_RGBA); d->AddAttachment("color", GL_RGBA, GL_FLOAT, GL_RGBA32F);
d->AddAttachment("depth", GL_DEPTH_COMPONENT, GL_FLOAT, GL_DEPTH_COMPONENT32);
// Generate vertex array
GLuint vao;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
engine_->Execute(render_index_.get(), &tasks_); engine_->Execute(render_index_.get(), &tasks_);
// d->Unbind();
std::vector<float> &pixels = render_images_["Combined"]; std::vector<float> &pixels = render_images_["Combined"];
char elapsed_time[32]; char elapsed_time[32];
@ -315,11 +336,10 @@ void FinalEngineGL::render1(Depsgraph *depsgraph)
} }
} }
GLuint rendered_texture; GLuint t = d->GetAttachment("color")->GetGlTextureName();
glBindTexture(GL_TEXTURE_2D, t);
// glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, pixels.data()); glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, pixels.data());
// update_render_result(); update_render_result();
pxr::TraceCollector::GetInstance().SetEnabled(false);
} }
} // namespace blender::render::hydra } // namespace blender::render::hydra