Render fixes after refactoring #79

Merged
Bogdan Nagirniak merged 5 commits from hydra-refactor-fixes into hydra-render 2023-07-29 11:45:06 +02:00
4 changed files with 27 additions and 12 deletions
Showing only changes of commit 33c76373a4 - Show all commits

View File

@ -277,4 +277,15 @@ void GPURenderTaskDelegate::unbind()
GPU_framebuffer_free(framebuffer_); GPU_framebuffer_free(framebuffer_);
} }

Can you set VAO_ to 0 and framebuffer_ to null?

Not strictly required, but more future proof.

Can you set VAO_ to 0 and framebuffer_ to null? Not strictly required, but more future proof.
GPUTexture *GPURenderTaskDelegate::aov_texture(pxr::TfToken const &aov_key)
{
if (aov_key == pxr::HdAovTokens->color) {
return tex_color_;
}
if (aov_key == pxr::HdAovTokens->depth) {
return tex_depth_;
}
return nullptr;
}
} // namespace blender::render::hydra } // namespace blender::render::hydra

View File

@ -60,6 +60,7 @@ class GPURenderTaskDelegate : public RenderTaskDelegate {
void read_aov(pxr::TfToken const &aov_key, GPUTexture *texture) override; void read_aov(pxr::TfToken const &aov_key, GPUTexture *texture) override;
void bind() override; void bind() override;
void unbind() override; void unbind() override;
GPUTexture *aov_texture(pxr::TfToken const &aov_key);
}; };
} // namespace blender::render::hydra } // namespace blender::render::hydra

View File

@ -188,13 +188,11 @@ void DrawTexture::write_data(int width, int height, const void *data)
(float *)data); (float *)data);
} }
void DrawTexture::draw(GPUShader *shader, const pxr::GfVec4d &viewport) void DrawTexture::draw(GPUShader *shader, const pxr::GfVec4d &viewport, GPUTexture *tex)
{
draw(shader, texture_, viewport);
}
void DrawTexture::draw(GPUShader *shader, GPUTexture *tex, const pxr::GfVec4d &viewport)
{ {
if (!tex) {
tex = texture_;
}
int slot = GPU_shader_get_sampler_binding(shader, "image"); int slot = GPU_shader_get_sampler_binding(shader, "image");
GPU_texture_bind(tex, slot); GPU_texture_bind(tex, slot);
GPU_shader_uniform_1i(shader, "image", slot); GPU_shader_uniform_1i(shader, "image", slot);
@ -256,14 +254,20 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context)
render_task_delegate_->unbind(); render_task_delegate_->unbind();
draw_texture_.write_data(view_settings.width(), view_settings.height(), nullptr);
render_task_delegate_->read_aov(pxr::HdAovTokens->color, draw_texture_.texture());
GPU_framebuffer_bind(view_framebuffer); GPU_framebuffer_bind(view_framebuffer);
GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_IMAGE); GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_IMAGE);
GPU_shader_bind(shader); GPU_shader_bind(shader);
GPURenderTaskDelegate *gpu_task = dynamic_cast<GPURenderTaskDelegate *>(
render_task_delegate_.get());
if (gpu_task) {
draw_texture_.draw(shader, viewport, gpu_task->aov_texture(pxr::HdAovTokens->color));
}
else {
draw_texture_.write_data(view_settings.width(), view_settings.height(), nullptr);
render_task_delegate_->read_aov(pxr::HdAovTokens->color, draw_texture_.texture());
draw_texture_.draw(shader, viewport); draw_texture_.draw(shader, viewport);
}
GPU_shader_unbind(); GPU_shader_unbind();

View File

@ -23,8 +23,7 @@ class DrawTexture {
~DrawTexture(); ~DrawTexture();
void write_data(int width, int height, const void *data); void write_data(int width, int height, const void *data);
void draw(GPUShader *shader, const pxr::GfVec4d &viewport); void draw(GPUShader *shader, const pxr::GfVec4d &viewport, GPUTexture *tex = nullptr);
void draw(GPUShader *shader, GPUTexture *tex, const pxr::GfVec4d &viewport);
GPUTexture *texture() const; GPUTexture *texture() const;
private: private: