 |
Flutter Impeller
|
|
Go to the documentation of this file.
14 #include "impeller/entity/texture_fill.frag.h"
15 #include "impeller/entity/texture_fill.vert.h"
16 #include "impeller/entity/texture_fill_strict_src.frag.h"
17 #include "impeller/entity/tiled_texture_fill_external.frag.h"
29 auto contents = std::make_shared<TextureContents>();
30 contents->destination_rect_ = destination;
35 label_ = std::move(label);
39 destination_rect_ = rect;
43 texture_ = std::move(texture);
55 stencil_enabled_ = enabled;
59 inherited_opacity_ = opacity;
63 return opacity_ * inherited_opacity_;
76 std::optional<Rect> coverage_limit,
77 const std::optional<SamplerDescriptor>& sampler_descriptor,
80 const std::string& label)
const {
83 auto bounds = destination_rect_;
93 .sampler_descriptor = sampler_descriptor.value_or(sampler_descriptor_),
100 sampler_descriptor.value_or(sampler_descriptor_),
109 using VS = TextureFillVertexShader;
110 using FS = TextureFillFragmentShader;
111 using FSStrict = TextureFillStrictSrcFragmentShader;
114 texture_ ==
nullptr || texture_->GetSize().IsEmpty()) {
118 #ifdef IMPELLER_ENABLE_OPENGLES
119 using FSExternal = TiledTextureFillExternalFragmentShader;
120 bool is_external_texture =
122 #endif // IMPELLER_ENABLE_OPENGLES
124 auto texture_coords =
128 std::array<VS::PerVertexData, 4> vertices = {
129 VS::PerVertexData{destination_rect_.
GetLeftTop(),
130 texture_coords.GetLeftTop()},
132 texture_coords.GetRightTop()},
134 texture_coords.GetLeftBottom()},
136 texture_coords.GetRightBottom()},
140 VS::FrameInfo frame_info;
142 frame_info.texture_sampler_y_coord_scale = texture_->GetYCoordScale();
144 #ifdef IMPELLER_DEBUG
145 if (label_.empty()) {
150 #endif // IMPELLER_DEBUG
153 if (!stencil_enabled_) {
158 pipeline_options.depth_write_enabled =
161 #ifdef IMPELLER_ENABLE_OPENGLES
162 if (is_external_texture) {
164 renderer.GetTiledTextureExternalPipeline(pipeline_options));
167 strict_source_rect_enabled_
175 #endif // IMPELLER_ENABLE_OPENGLES
178 VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
180 if (strict_source_rect_enabled_) {
184 auto strict_texture_coords =
187 FSStrict::FragInfo frag_info;
188 frag_info.source_rect =
Vector4(strict_texture_coords.GetLTRB());
190 FSStrict::BindFragInfo(pass, host_buffer.EmplaceUniform((frag_info)));
191 FSStrict::BindTextureSampler(
193 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(
194 sampler_descriptor_));
195 #ifdef IMPELLER_ENABLE_OPENGLES
196 }
else if (is_external_texture) {
197 FSExternal::FragInfo frag_info;
198 frag_info.x_tile_mode =
200 frag_info.y_tile_mode =
203 FSExternal::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
211 FSExternal::BindSAMPLEREXTERNALOESTextureSampler(
213 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(sampler_desc));
214 #endif // IMPELLER_ENABLE_OPENGLES
216 FS::FragInfo frag_info;
218 FS::BindFragInfo(pass, host_buffer.EmplaceUniform((frag_info)));
219 FS::BindTextureSampler(
221 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(
222 sampler_descriptor_));
224 return pass.
Draw().ok();
228 source_rect_ = source_rect;
236 strict_source_rect_enabled_ = strict;
240 return strict_source_rect_enabled_;
244 sampler_descriptor_ = std::move(desc);
248 return sampler_descriptor_;
252 defer_applying_opacity_ = defer_applying_opacity;
std::shared_ptr< Pipeline< PipelineDescriptor > > GetTexturePipeline(ContentContextOptions opts) const
std::shared_ptr< Pipeline< PipelineDescriptor > > GetTextureStrictSrcPipeline(ContentContextOptions opts) const
Matrix GetShaderTransform(const RenderPass &pass) const
Get the vertex shader transform used for drawing this Entity.
void SetSamplerDescriptor(SamplerDescriptor desc)
void SetStrictSourceRect(bool strict)
void SetOpacity(Scalar opacity)
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
void SetInheritedOpacity(Scalar opacity) override
Inherit the provided opacity.
std::optional< Snapshot > RenderToSnapshot(const ContentContext &renderer, const Entity &entity, std::optional< Rect > coverage_limit=std::nullopt, const std::optional< SamplerDescriptor > &sampler_descriptor=std::nullopt, bool msaa_enabled=true, int32_t mip_count=1, const std::string &label="Texture Snapshot") const override
Render this contents to a snapshot, respecting the entity's transform, path, clip depth,...
constexpr float kEhCloseEnough
virtual std::optional< Snapshot > RenderToSnapshot(const ContentContext &renderer, const Entity &entity, std::optional< Rect > coverage_limit=std::nullopt, const std::optional< SamplerDescriptor > &sampler_descriptor=std::nullopt, bool msaa_enabled=true, int32_t mip_count=1, const std::string &label="Snapshot") const
Render this contents to a snapshot, respecting the entity's transform, path, clip depth,...
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
constexpr TPoint< T > GetLeftTop() const
bool GetStrictSourceRect() const
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.
virtual bool SetVertexBuffer(VertexBuffer buffer)
Specify the vertex and index buffer to use for this command.
void SetSourceRect(const Rect &source_rect)
void SetStencilEnabled(bool enabled)
static constexpr Matrix MakeTranslation(const Vector3 &t)
virtual void SetCommandLabel(std::string_view label)
The debugging label to use for the command.
constexpr TPoint< T > GetRightTop() const
Scalar GetOpacity() const
virtual fml::Status Draw()
Record the currently pending command.
constexpr bool IsEmpty() const
Returns true if either of the width or height are 0, negative, or NaN.
ContentContextOptions OptionsFromPassAndEntity(const RenderPass &pass, const Entity &entity)
~TextureContents() override
const Rect & GetSourceRect() const
VertexBuffer CreateVertexBuffer(std::array< VertexType, size > input, HostBuffer &host_buffer)
Create an index-less vertex buffer from a fixed size array.
std::shared_ptr< Context > GetContext() const
void SetLabel(std::string label)
constexpr TPoint< T > GetLeftBottom() const
Represents a texture and its intended draw transform/sampler configuration.
SamplerAddressMode width_address_mode
std::shared_ptr< Texture > GetTexture() const
Render passes encode render commands directed as one specific render target into an underlying comman...
void SetDeferApplyingOpacity(bool defer_applying_opacity)
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
constexpr static TRect MakeSize(const TSize< U > &size)
constexpr TRect< T > Project(TRect< T > source) const
Returns a new rectangle that represents the projection of the source rectangle onto this rectangle....
void SetTexture(std::shared_ptr< Texture > texture)
virtual void SetPipeline(const std::shared_ptr< Pipeline< PipelineDescriptor >> &pipeline)
The pipeline to use for this command.
std::shared_ptr< Texture > texture
constexpr TPoint< T > GetRightBottom() const
void SetDestinationRect(Rect rect)
static std::shared_ptr< TextureContents > MakeRect(Rect destination)
A common case factory that marks the texture contents as having a destination rectangle....
const SamplerDescriptor & GetSamplerDescriptor() const
SamplerAddressMode height_address_mode
static constexpr Matrix MakeScale(const Vector3 &s)
HostBuffer & GetTransientsBuffer() const
Retrieve the currnent host buffer for transient storage.
constexpr TRect< T > Expand(T left, T top, T right, T bottom) const
Returns a rectangle with expanded edges. Negative expansion results in shrinking.