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());
65Rect 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++) {
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();
120 auto& host_buffer =
renderer.GetTransientsBuffer();
121 bool has_colors = !colors_.empty();
122 for (
size_t i = 0;
i < texture_coords_.size();
i++) {
123 auto sample_rect = texture_coords_[
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_;
140 if (
renderer.GetDeviceCapabilities().SupportsDecalSamplerAddressMode()) {
144 const std::unique_ptr<const Sampler>& dst_sampler =
145 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
146 dst_sampler_descriptor);
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);
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));
static const int points[]
const SamplerDescriptor & GetSamplerDescriptor() const
const std::vector< Rect > & GetTextureCoordinates() const
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
std::optional< Rect > GetCoverage(const Entity &entity) const override
Get the area of the render pass that will be affected when this contents is rendered.
void SetTransforms(std::vector< Matrix > transforms)
const std::vector< Color > & GetColors() const
void SetAlpha(Scalar alpha)
void SetTexture(std::shared_ptr< Texture > texture)
void SetSamplerDescriptor(SamplerDescriptor desc)
void SetBlendMode(BlendMode blend_mode)
void SetCullRect(std::optional< Rect > cull_rect)
const std::vector< Matrix > & GetTransforms() const
~AtlasContents() override
void SetColors(std::vector< Color > colors)
std::shared_ptr< Texture > GetTexture() const
void SetTextureCoordinates(std::vector< Rect > texture_coords)
Matrix GetShaderTransform(const RenderPass &pass) const
Get the vertex shader transform used for drawing this Entity.
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
Render passes encode render commands directed as one specific render target into an underlying comman...
virtual bool SetVertexBuffer(VertexBuffer buffer)
Specify the vertex and index buffer to use for this command.
virtual void SetPipeline(const std::shared_ptr< Pipeline< PipelineDescriptor > > &pipeline)
The pipeline to use for this command.
virtual fml::Status Draw()
Record the currently pending command.
virtual void SetCommandLabel(std::string_view label)
The debugging label to use for the command.
VertexShader_ VertexShader
FragmentShader_ FragmentShader
VertexBuffer CreateVertexBuffer(HostBuffer &host_buffer) const
VertexBufferBuilder & AppendVertex(VertexType_ vertex)
void Reserve(size_t count)
unsigned useCenter Optional< SkMatrix > matrix
Optional< SkRect > bounds
PODArray< SkColor > colors
const char * BlendModeToString(BlendMode blend_mode)
@ kDecal
decal sampling mode is only supported on devices that pass the Capabilities.SupportsDecalSamplerAddre...
std::string SPrintF(const char *format,...)
constexpr std::array< std::array< Scalar, 5 >, 15 > kPorterDuffCoefficients
std::optional< BlendMode > InvertPorterDuffBlend(BlendMode blend_mode)
ContentContextOptions OptionsFromPass(const RenderPass &pass)
static constexpr Color BlackTransparent()
SamplerAddressMode width_address_mode
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
constexpr std::array< TPoint< T >, 4 > GetTransformedPoints(const Matrix &transform) const
static constexpr TRect MakeSize(const TSize< U > &size)
std::shared_ptr< const fml::Mapping > data