forked from blender/blender
Hydra tasks refactor #73
@ -121,6 +121,18 @@ void RenderTaskDelegate::read_aov(pxr::TfToken const &aov_key, void *data)
|
|||||||
buffer->Unmap();
|
buffer->Unmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RenderTaskDelegate::read_aov(pxr::TfToken const &aov_key, GPUTexture *texture)
|
||||||
|
{
|
||||||
|
pxr::HdRenderBuffer *buffer = (pxr::HdRenderBuffer *)GetRenderIndex().GetBprim(
|
||||||
|
pxr::HdPrimTypeTokens->renderBuffer, buffer_id(aov_key));
|
||||||
|
if (!buffer) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
void *buf_data = buffer->Map();
|
||||||
|
GPU_texture_update(texture, GPU_DATA_FLOAT, buf_data);
|
||||||
|
buffer->Unmap();
|
||||||
|
}
|
||||||
|
|
||||||
void RenderTaskDelegate::bind() {}
|
void RenderTaskDelegate::bind() {}
|
||||||
|
|
||||||
void RenderTaskDelegate::unbind() {}
|
void RenderTaskDelegate::unbind() {}
|
||||||
@ -202,6 +214,27 @@ void GPURenderTaskDelegate::read_aov(pxr::TfToken const &aov_key, void *data)
|
|||||||
MEM_freeN(tex_data);
|
MEM_freeN(tex_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GPURenderTaskDelegate::read_aov(pxr::TfToken const &aov_key, GPUTexture *texture)
|
||||||
|
{
|
||||||
|
GPUTexture *tex = nullptr;
|
||||||
|
int c;
|
||||||
|
if (aov_key == pxr::HdAovTokens->color) {
|
||||||
|
tex = tex_color_;
|
||||||
|
c = 4;
|
||||||
|
}
|
||||||
|
else if (aov_key == pxr::HdAovTokens->depth) {
|
||||||
|
tex = tex_depth_;
|
||||||
|
c = 1;
|
||||||
|
}
|
||||||
|
if (!tex) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *tex_data = GPU_texture_read(tex, GPU_DATA_FLOAT, 0);
|
||||||
|
GPU_texture_update(texture, GPU_DATA_FLOAT, tex_data);
|
||||||
|
MEM_freeN(tex_data);
|
||||||
|
}
|
||||||
|
|
||||||
void GPURenderTaskDelegate::bind()
|
void GPURenderTaskDelegate::bind()
|
||||||
{
|
{
|
||||||
if (!framebuffer_) {
|
if (!framebuffer_) {
|
||||||
|
@ -27,6 +27,7 @@ class RenderTaskDelegate : public pxr::HdSceneDelegate {
|
|||||||
virtual void set_viewport(pxr::GfVec4d const &viewport);
|
virtual void set_viewport(pxr::GfVec4d const &viewport);
|
||||||
virtual void add_aov(pxr::TfToken const &aov_key);
|
virtual void add_aov(pxr::TfToken const &aov_key);
|
||||||
virtual void read_aov(pxr::TfToken const &aov_key, void *data);
|
virtual void read_aov(pxr::TfToken const &aov_key, void *data);
|
||||||
|
virtual void read_aov(pxr::TfToken const &aov_key, GPUTexture *texture);
|
||||||
virtual void bind();
|
virtual void bind();
|
||||||
virtual void unbind();
|
virtual void unbind();
|
||||||
|
|
||||||
@ -46,6 +47,7 @@ class GPURenderTaskDelegate : public RenderTaskDelegate {
|
|||||||
void set_viewport(pxr::GfVec4d const &viewport) override;
|
void set_viewport(pxr::GfVec4d const &viewport) override;
|
||||||
void add_aov(pxr::TfToken const &aov_key) override;
|
void add_aov(pxr::TfToken const &aov_key) override;
|
||||||
void read_aov(pxr::TfToken const &aov_key, void *data) override;
|
void read_aov(pxr::TfToken const &aov_key, void *data) override;
|
||||||
|
void read_aov(pxr::TfToken const &aov_key, GPUTexture *texture) override;
|
||||||
void bind() override;
|
void bind() override;
|
||||||
void unbind() override;
|
void unbind() override;
|
||||||
|
|
||||||
|
@ -158,7 +158,9 @@ DrawTexture::~DrawTexture()
|
|||||||
void DrawTexture::write_data(int width, int height, const void *data)
|
void DrawTexture::write_data(int width, int height, const void *data)
|
||||||
{
|
{
|
||||||
if (texture_ && width == GPU_texture_width(texture_) && height == GPU_texture_height(texture_)) {
|
if (texture_ && width == GPU_texture_width(texture_) && height == GPU_texture_height(texture_)) {
|
||||||
|
if (data) {
|
||||||
GPU_texture_update(texture_, GPU_DATA_FLOAT, data);
|
GPU_texture_update(texture_, GPU_DATA_FLOAT, data);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,6 +198,11 @@ void DrawTexture::draw(GPUShader *shader, GPUTexture *tex, const pxr::GfVec4d &v
|
|||||||
GPU_matrix_pop();
|
GPU_matrix_pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GPUTexture *DrawTexture::texture() const
|
||||||
|
{
|
||||||
|
return texture_;
|
||||||
|
}
|
||||||
|
|
||||||
void ViewportEngine::render(Depsgraph * /* depsgraph */)
|
void ViewportEngine::render(Depsgraph * /* depsgraph */)
|
||||||
{
|
{
|
||||||
/* Empty function */
|
/* Empty function */
|
||||||
@ -236,9 +243,8 @@ void ViewportEngine::render(Depsgraph * /* depsgraph */, bContext *context)
|
|||||||
engine_->Execute(render_index_.get(), &tasks);
|
engine_->Execute(render_index_.get(), &tasks);
|
||||||
|
|
||||||
if ((bl_engine_->type->flag & RE_USE_GPU_CONTEXT) == 0) {
|
if ((bl_engine_->type->flag & RE_USE_GPU_CONTEXT) == 0) {
|
||||||
std::vector<float> data(view_settings.width() * view_settings.height() * 4, 0.0f);
|
draw_texture_.write_data(view_settings.width(), view_settings.height(), nullptr);
|
||||||
render_task_delegate_->read_aov(pxr::HdAovTokens->color, data.data());
|
render_task_delegate_->read_aov(pxr::HdAovTokens->color, draw_texture_.texture());
|
||||||
draw_texture_.write_data(view_settings.width(), view_settings.height(), data.data());
|
|
||||||
draw_texture_.draw(shader, viewport);
|
draw_texture_.draw(shader, viewport);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ class 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);
|
||||||
void draw(GPUShader *shader, GPUTexture *tex, const pxr::GfVec4d &viewport);
|
void draw(GPUShader *shader, GPUTexture *tex, const pxr::GfVec4d &viewport);
|
||||||
|
GPUTexture *texture() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GPUTexture *texture_ = nullptr;
|
GPUTexture *texture_ = nullptr;
|
||||||
|
Loading…
Reference in New Issue
Block a user