18 std::shared_ptr<Allocator> allocator)
19 : allocator_(
std::move(allocator)) {}
27 return allocator_->CreateTexture(desc);
38 <<
"Render target does not have color attachment at index 0.";
44 std::optional<ISize> size;
45 bool sizes_are_same =
true;
46 auto iterator = [&](
const Attachment& attachment) ->
bool {
47 if (!size.has_value()) {
48 size = attachment.texture->GetSize();
50 if (size != attachment.texture->GetSize()) {
51 sizes_are_same =
false;
57 if (!sizes_are_same) {
59 <<
"Sizes of all render target attachments are not the same.";
66 std::optional<TextureType> texture_type;
67 std::optional<SampleCount> sample_count;
68 bool passes_type_validation =
true;
69 auto iterator = [&](
const Attachment& attachment) ->
bool {
70 if (!texture_type.has_value() || !sample_count.has_value()) {
71 texture_type = attachment.texture->GetTextureDescriptor().type;
72 sample_count = attachment.texture->GetTextureDescriptor().sample_count;
75 if (texture_type != attachment.texture->GetTextureDescriptor().type) {
76 passes_type_validation =
false;
80 attachment.texture->GetTextureDescriptor().type)
86 attachment.texture->GetTextureDescriptor().sample_count) {
87 passes_type_validation =
false;
89 <<
") has incompatible sample counts.";
97 if (!passes_type_validation) {
106 const std::function<
bool(
const Attachment& attachment)>& iterator)
const {
107 for (
const auto& color : colors_) {
108 if (!iterator(color.second)) {
113 if (depth_.has_value()) {
114 if (!iterator(depth_.value())) {
119 if (stencil_.has_value()) {
120 if (!iterator(stencil_.value())) {
127 if (
auto found = colors_.find(0u); found != colors_.end()) {
128 return found->second.texture->GetTextureDescriptor().sample_count;
134 if (
auto found = colors_.find(index); found != colors_.end()) {
141 auto found = colors_.find(index);
143 if (found == colors_.end()) {
147 return found->second.texture->GetSize();
152 return size.has_value() ? size.value() :
ISize{};
156 auto found = colors_.find(0u);
157 if (found == colors_.end()) {
160 return found->second.resolve_texture ? found->second.resolve_texture
161 : found->second.texture;
166 return texture->GetTextureDescriptor().format;
174 for (
const auto& color : colors_) {
175 max = std::max(color.first, max);
184 colors_[index] = attachment;
190 std::optional<DepthAttachment> attachment) {
191 if (!attachment.has_value()) {
192 depth_ = std::nullopt;
193 }
else if (attachment->IsValid()) {
194 depth_ = std::move(attachment);
200 std::optional<StencilAttachment> attachment) {
201 if (!attachment.has_value()) {
202 stencil_ = std::nullopt;
203 }
else if (attachment->IsValid()) {
204 stencil_ = std::move(attachment);
227 const std::string& label,
229 std::optional<AttachmentConfig> stencil_attachment_config) {
235 #ifdef FML_OS_ANDROID
236 FML_DCHECK(stencil_attachment_config.has_value());
237 #endif // FML_OS_ANDROID
243 color_tex0.
format = pixel_format;
244 color_tex0.
size = size;
257 color0.
texture->SetLabel(
SPrintF(
"%s Color Texture", label.c_str()));
260 if (stencil_attachment_config.has_value()) {
262 stencil_attachment_config.value());
274 const std::string& label,
276 std::optional<AttachmentConfig> stencil_attachment_config) {
282 #ifdef FML_OS_ANDROID
283 FML_DCHECK(stencil_attachment_config.has_value());
284 #endif // FML_OS_ANDROID
295 color0_tex_desc.
format = pixel_format;
296 color0_tex_desc.
size = size;
299 auto color0_msaa_tex = allocator.
CreateTexture(color0_tex_desc);
300 if (!color0_msaa_tex) {
304 color0_msaa_tex->SetLabel(
305 SPrintF(
"%s Color Texture (Multisample)", label.c_str()));
312 color0_resolve_tex_desc.
format = pixel_format;
313 color0_resolve_tex_desc.
size = size;
315 color0_resolve_tex_desc.
usage =
319 auto color0_resolve_tex = allocator.
CreateTexture(color0_resolve_tex_desc);
320 if (!color0_resolve_tex) {
324 color0_resolve_tex->SetLabel(
SPrintF(
"%s Color Texture", label.c_str()));
332 color0.
texture = color0_msaa_tex;
339 if (stencil_attachment_config.has_value()) {
341 stencil_attachment_config.value());
354 const std::string& label,
363 stencil_tex0.
size = size;
376 stencil0.
texture->SetLabel(
SPrintF(
"%s Stencil Texture", label.c_str()));
382 for (
const auto& [_, color] : colors_) {
386 if (color.resolve_texture) {
390 if (depth_.has_value()) {
393 if (stencil_.has_value()) {
400 std::stringstream stream;
402 for (
const auto& [index, color] : colors_) {
403 stream <<
SPrintF(
"Color[%zu]=(%s)", index,
408 stream <<
SPrintF(
"Depth=(%s)",
413 stream <<
SPrintF(
"Stencil=(%s)",