25 texture_ = std::move(texture);
33 transforms_ = std::move(transforms);
34 bounding_box_cache_.reset();
38 texture_coords_ = std::move(texture_coords);
39 bounding_box_cache_.reset();
43 colors_ = std::move(colors);
51 blend_mode_ = blend_mode;
55 cull_rect_ = cull_rect;
59 if (cull_rect_.has_value()) {
60 return cull_rect_.value().TransformBounds(entity.
GetTransform());
65 Rect AtlasContents::ComputeBoundingBox()
const {
66 if (!bounding_box_cache_.has_value()) {
67 Rect bounding_box = {};
68 for (
size_t i = 0; i < texture_coords_.size(); i++) {
69 auto matrix = transforms_[i];
70 auto sample_rect = texture_coords_[i];
73 bounding_box = bounds.
Union(bounding_box);
75 bounding_box_cache_ = bounding_box;
77 return bounding_box_cache_.value();
81 sampler_descriptor_ = std::move(desc);
85 return sampler_descriptor_;
93 return texture_coords_;
109 if (colors_.empty()) {
113 constexpr
size_t indices[6] = {0, 1, 2, 1, 2, 3};
118 vtx_builder.
Reserve(texture_coords_.size() * 6);
119 const auto texture_size = texture_->GetSize();
121 bool has_colors = !colors_.empty();
122 for (
size_t i = 0; i < texture_coords_.size(); i++) {
123 auto sample_rect = texture_coords_[i];
124 auto matrix = transforms_[i];
125 auto points = sample_rect.GetPoints();
126 auto transformed_points =
130 for (
size_t j = 0; j < 6; j++) {
131 VS::PerVertexData
data;
132 data.vertices = transformed_points[indices[j]];
133 data.texture_coords = points[indices[j]] / texture_size;
139 auto dst_sampler_descriptor = sampler_descriptor_;
144 const std::unique_ptr<const Sampler>& dst_sampler =
145 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(
146 dst_sampler_descriptor);
151 #ifdef IMPELLER_DEBUG
154 #endif // IMPELLER_DEBUG
159 FS::FragInfo frag_info;
160 VS::FrameInfo frame_info;
162 FS::BindTextureSamplerDst(pass, texture_, dst_sampler);
163 frame_info.texture_sampler_y_coord_scale = texture_->GetYCoordScale();
165 frag_info.output_alpha = alpha_;
166 frag_info.input_alpha = 1.0;
168 auto inverted_blend_mode =
170 auto blend_coefficients =
172 frag_info.src_coeff = blend_coefficients[0];
173 frag_info.src_coeff_dst_alpha = blend_coefficients[1];
174 frag_info.dst_coeff = blend_coefficients[2];
175 frag_info.dst_coeff_src_alpha = blend_coefficients[3];
176 frag_info.dst_coeff_src_color = blend_coefficients[4];
181 FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
185 auto uniform_view = host_buffer.EmplaceUniform(frame_info);
186 VS::BindFrameInfo(pass, uniform_view);
188 return pass.
Draw().ok();
194 #ifdef IMPELLER_DEBUG
197 #endif // IMPELLER_DEBUG
201 FS::BindTextureSampler(pass, texture_, dst_sampler);
203 VUS::FrameInfo frame_info;
204 FS::FragInfo frag_info;
206 frame_info.texture_sampler_y_coord_scale = texture_->GetYCoordScale();
209 frag_info.alpha = alpha_;
210 frag_info.blend_mode =
static_cast<int>(blend_mode);
216 FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
217 VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
219 return pass.
Draw().ok();