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);
GPUFrameBuffer *framebuffer = GPU_framebuffer_create("fb_hydra_render_final");
GPUTexture *texture = GPU_texture_create_2d("tex_hydra_render_final",
resolution_[0],
resolution_[1],
1,
GPU_RGBA32F,
GPU_TEXTURE_USAGE_ATTACHMENT,
nullptr);
GPU_texture_filter_mode(texture, true);
GPU_texture_mipmap_mode(texture, true, true);
GPUFrameBuffer *framebuffer = GPU_framebuffer_create("fb_render_hydra");
GPUTexture *tex_color = GPU_texture_create_2d("tex_render_hydra_color",
resolution_[0],
resolution_[1],
1,
GPU_RGBA32F,
GPU_TEXTURE_USAGE_GENERAL,
nullptr);
GPUTexture *tex_depth = GPU_texture_create_2d("tex_render_hydra_depth",
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_texture_attach(framebuffer, texture, 0, 0);
float clear_color[4] = {0.1f, 0.1f, 0.1f, 1.0f};
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_);
std::vector<float> &pixels = render_images_["Combined"];
@ -161,19 +177,20 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
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));
MEM_freeN(data);
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));
MEM_freeN(data);
update_render_result();
GPU_framebuffer_free(framebuffer);
GPU_texture_free(texture);
GPU_texture_free(tex_color);
GPU_texture_free(tex_depth);
}
void FinalEngineGL::render0(Depsgraph *depsgraph)
@ -282,13 +299,17 @@ void FinalEngineGL::render1(Depsgraph *depsgraph)
{
prepare_for_render(depsgraph);
// pxr::TraceCollector::GetInstance().SetEnabled(true);
auto d = pxr::GlfDrawTarget::New(resolution_);
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_);
// d->Unbind();
std::vector<float> &pixels = render_images_["Combined"];
char elapsed_time[32];
@ -315,11 +336,10 @@ void FinalEngineGL::render1(Depsgraph *depsgraph)
}
}
GLuint rendered_texture;
// glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, pixels.data());
// update_render_result();
pxr::TraceCollector::GetInstance().SetEnabled(false);
GLuint t = d->GetAttachment("color")->GetGlTextureName();
glBindTexture(GL_TEXTURE_2D, t);
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, pixels.data());
update_render_result();
}
} // namespace blender::render::hydra