修复在render_target_dx11在resize时的渲染失败问题
This commit is contained in:
parent
3a3d3caa1a
commit
c75cdff50f
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include "imgui.h"
|
||||
|
||||
class render_resource
|
||||
class render_resource : public std::enable_shared_from_this<render_resource>
|
||||
{
|
||||
public:
|
||||
virtual ~render_resource() = default;
|
||||
|
@ -26,10 +26,14 @@ public:
|
||||
width_ = width;
|
||||
height_ = height;
|
||||
on_resize(width, height);
|
||||
if (on_resize_callback)
|
||||
on_resize_callback(shared_from_this());
|
||||
}
|
||||
|
||||
virtual void* lock(lock_state state) = 0;
|
||||
virtual void unlock() = 0;
|
||||
|
||||
std::function<void(std::shared_ptr<render_resource>)> on_resize_callback;
|
||||
protected:
|
||||
virtual void on_resize(int width, int height) = 0;
|
||||
int width_ = 0;
|
||||
|
@ -137,6 +137,9 @@ void render_target_dx11::release()
|
||||
|
||||
void render_target_dx11::on_resize(int width, int height)
|
||||
{
|
||||
width_ = width;
|
||||
height_ = height;
|
||||
|
||||
D3D11_TEXTURE2D_DESC texture_desc;
|
||||
texture_->GetDesc(&texture_desc);
|
||||
texture_desc.Width = width;
|
||||
|
@ -43,11 +43,12 @@ void shader_cs_dx11::bind()
|
||||
auto p = srv.get_reference();
|
||||
g_d3d11_device_context->CSSetShaderResources(texture->binding_point, 1, &p);
|
||||
}
|
||||
|
||||
|
||||
for (const auto& texture : render_targets_ | std::views::values)
|
||||
{
|
||||
auto srv = texture->get_srv();
|
||||
auto p = srv.get_reference();
|
||||
|
||||
g_d3d11_device_context->CSSetShaderResources(texture->binding_point, 1, &p);
|
||||
}
|
||||
}
|
||||
@ -105,14 +106,17 @@ void shader_cs_dx11::set_render_target(const char* name, std::shared_ptr<render_
|
||||
if (find == uav_buffers_.end())
|
||||
{
|
||||
auto uav_buffer = std::make_shared<uav_buffer_dx11>();
|
||||
if (in_render_target)
|
||||
uav_buffer->create_from_render_target(rt);
|
||||
uav_buffer->create_from_render_target(rt);
|
||||
uav_buffer->binding_point = binding->second.binding;
|
||||
uav_buffers_.insert({name, uav_buffer});
|
||||
rt->on_resize_callback = [this, name](std::shared_ptr<render_resource> in_rt)
|
||||
{
|
||||
std::shared_ptr<render_target_dx11> new_rt = std::static_pointer_cast<render_target_dx11>(in_rt);
|
||||
uav_buffers_[name]->create_from_render_target(new_rt);
|
||||
};
|
||||
return;
|
||||
}
|
||||
if (in_render_target)
|
||||
find->second->create_from_render_target(rt);
|
||||
find->second->create_from_render_target(rt);
|
||||
}
|
||||
|
||||
void shader_cs_dx11::compute(int x, int y, int z)
|
||||
|
Loading…
x
Reference in New Issue
Block a user