12 uint32_t keep_alive_frame_count)
14 keep_alive_frame_count_(keep_alive_frame_count) {}
17 for (
auto& td : render_target_data_) {
18 td.used_this_frame =
false;
23 std::vector<RenderTargetData> retain;
25 for (RenderTargetData& td : render_target_data_) {
26 if (td.used_this_frame) {
28 }
else if (td.keep_alive_frame_count > 0) {
29 td.keep_alive_frame_count--;
33 render_target_data_.swap(retain);
40 std::string_view label,
42 std::optional<RenderTarget::AttachmentConfig> stencil_attachment_config,
43 const std::shared_ptr<Texture>& existing_color_texture,
44 const std::shared_ptr<Texture>& existing_depth_stencil_texture) {
49 FML_DCHECK(existing_color_texture ==
nullptr &&
50 existing_depth_stencil_texture ==
nullptr);
53 .mip_count =
static_cast<size_t>(mip_count),
55 .has_depth_stencil = stencil_attachment_config.has_value(),
57 for (RenderTargetData& render_target_data : render_target_data_) {
59 if (!render_target_data.used_this_frame && other_config == config) {
60 render_target_data.used_this_frame =
true;
61 render_target_data.keep_alive_frame_count = keep_alive_frame_count_;
63 render_target_data.render_target.GetColorAttachment(0);
64 std::optional<DepthAttachment> depth =
65 render_target_data.render_target.GetDepthAttachment();
66 std::shared_ptr<Texture> depth_tex = depth ? depth->
texture :
nullptr;
68 context, size, mip_count, label, color_attachment_config,
69 stencil_attachment_config, color0.
texture, depth_tex);
73 context, size, mip_count, label, color_attachment_config,
74 stencil_attachment_config);
75 if (!created_target.
IsValid()) {
76 return created_target;
78 render_target_data_.push_back(RenderTargetData{
79 .used_this_frame =
true,
80 .keep_alive_frame_count = keep_alive_frame_count_,
82 .render_target = created_target
84 return created_target;
91 std::string_view label,
93 std::optional<RenderTarget::AttachmentConfig> stencil_attachment_config,
94 const std::shared_ptr<Texture>& existing_color_msaa_texture,
95 const std::shared_ptr<Texture>& existing_color_resolve_texture,
96 const std::shared_ptr<Texture>& existing_depth_stencil_texture) {
101 FML_DCHECK(existing_color_msaa_texture ==
nullptr &&
102 existing_color_resolve_texture ==
nullptr &&
103 existing_depth_stencil_texture ==
nullptr);
106 .mip_count =
static_cast<size_t>(mip_count),
108 .has_depth_stencil = stencil_attachment_config.has_value(),
110 for (RenderTargetData& render_target_data : render_target_data_) {
112 if (!render_target_data.used_this_frame && other_config == config) {
113 render_target_data.used_this_frame =
true;
114 render_target_data.keep_alive_frame_count = keep_alive_frame_count_;
116 render_target_data.render_target.GetColorAttachment(0);
117 std::optional<DepthAttachment> depth =
118 render_target_data.render_target.GetDepthAttachment();
119 std::shared_ptr<Texture> depth_tex = depth ? depth->
texture :
nullptr;
121 context, size, mip_count, label, color_attachment_config,
127 context, size, mip_count, label, color_attachment_config,
128 stencil_attachment_config);
129 if (!created_target.
IsValid()) {
130 return created_target;
132 render_target_data_.push_back(RenderTargetData{
133 .used_this_frame =
true,
134 .keep_alive_frame_count = keep_alive_frame_count_,
136 .render_target = created_target
138 return created_target;
142 return render_target_data_.size();
To do anything rendering related with Impeller, you need a context.
a wrapper around the impeller [Allocator] instance that can be used to provide caching of allocated r...
virtual RenderTarget CreateOffscreenMSAA(const Context &context, ISize size, int mip_count, std::string_view label="Offscreen MSAA", RenderTarget::AttachmentConfigMSAA color_attachment_config=RenderTarget::kDefaultColorAttachmentConfigMSAA, std::optional< RenderTarget::AttachmentConfig > stencil_attachment_config=RenderTarget::kDefaultStencilAttachmentConfig, const std::shared_ptr< Texture > &existing_color_msaa_texture=nullptr, const std::shared_ptr< Texture > &existing_color_resolve_texture=nullptr, const std::shared_ptr< Texture > &existing_depth_stencil_texture=nullptr)
virtual RenderTarget CreateOffscreen(const Context &context, ISize size, int mip_count, std::string_view label="Offscreen", RenderTarget::AttachmentConfig color_attachment_config=RenderTarget::kDefaultColorAttachmentConfig, std::optional< RenderTarget::AttachmentConfig > stencil_attachment_config=RenderTarget::kDefaultStencilAttachmentConfig, const std::shared_ptr< Texture > &existing_color_texture=nullptr, const std::shared_ptr< Texture > &existing_depth_stencil_texture=nullptr)
RenderTarget CreateOffscreen(const Context &context, ISize size, int mip_count, std::string_view label="Offscreen", RenderTarget::AttachmentConfig color_attachment_config=RenderTarget::kDefaultColorAttachmentConfig, std::optional< RenderTarget::AttachmentConfig > stencil_attachment_config=RenderTarget::kDefaultStencilAttachmentConfig, const std::shared_ptr< Texture > &existing_color_texture=nullptr, const std::shared_ptr< Texture > &existing_depth_stencil_texture=nullptr) override
size_t CachedTextureCount() const
RenderTargetCache(std::shared_ptr< Allocator > allocator, uint32_t keep_alive_frame_count=4)
void End() override
Mark the end of a frame workload.
void Start() override
Mark the beginning of a frame workload.
RenderTarget CreateOffscreenMSAA(const Context &context, ISize size, int mip_count, std::string_view label="Offscreen MSAA", RenderTarget::AttachmentConfigMSAA color_attachment_config=RenderTarget::kDefaultColorAttachmentConfigMSAA, std::optional< RenderTarget::AttachmentConfig > stencil_attachment_config=RenderTarget::kDefaultStencilAttachmentConfig, const std::shared_ptr< Texture > &existing_color_msaa_texture=nullptr, const std::shared_ptr< Texture > &existing_color_resolve_texture=nullptr, const std::shared_ptr< Texture > &existing_depth_stencil_texture=nullptr) override
std::shared_ptr< Texture > resolve_texture
std::shared_ptr< Texture > texture
constexpr bool IsEmpty() const
Returns true if either of the width or height are 0, negative, or NaN.