 |
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_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;
63 inherited_opacity_ = opacity;
67 return opacity_ * inherited_opacity_;
80 std::optional<Rect> coverage_limit,
81 const std::optional<SamplerDescriptor>& sampler_descriptor,
83 const std::string& label)
const {
86 auto bounds = destination_rect_;
90 auto scale =
Vector2(bounds.size /
Size(texture_->GetSize()));
96 .sampler_descriptor = sampler_descriptor.value_or(sampler_descriptor_),
103 sampler_descriptor.value_or(sampler_descriptor_),
113 using VS = TextureFillVertexShader;
114 using FS = TextureFillFragmentShader;
115 using FSExternal = TextureFillExternalFragmentShader;
118 texture_ ==
nullptr || texture_->GetSize().IsEmpty()) {
122 bool is_external_texture =
127 auto texture_coords =
129 .
Project(capture.AddRect(
"Source rect", source_rect_).Expand(0.5));
133 auto destination_rect =
134 capture.AddRect(
"Destination rect", destination_rect_);
136 {destination_rect.GetLeftTop(), texture_coords.GetLeftTop()},
137 {destination_rect.GetRightTop(), texture_coords.GetRightTop()},
138 {destination_rect.GetLeftBottom(), texture_coords.GetLeftBottom()},
139 {destination_rect.GetRightBottom(), texture_coords.GetRightBottom()},
144 VS::FrameInfo frame_info;
147 frame_info.texture_sampler_y_coord_scale = texture_->GetYCoordScale();
148 frame_info.alpha = capture.AddScalar(
"Alpha",
GetOpacity());
151 if (label_.empty()) {
158 if (!stencil_enabled_) {
163 #ifdef IMPELLER_ENABLE_OPENGLES
164 if (is_external_texture) {
165 cmd.
pipeline = renderer.GetTextureExternalPipeline(pipeline_options);
171 #endif // IMPELLER_ENABLE_OPENGLES
175 VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));
176 if (is_external_texture) {
177 FSExternal::BindSAMPLEREXTERNALOESTextureSampler(
179 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(
180 sampler_descriptor_));
182 FS::BindTextureSampler(
184 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(
185 sampler_descriptor_));
193 source_rect_ = source_rect;
201 sampler_descriptor_ = std::move(desc);
205 return sampler_descriptor_;
209 defer_applying_opacity_ = defer_applying_opacity;
std::shared_ptr< Pipeline< PipelineDescriptor > > GetTexturePipeline(ContentContextOptions opts) const
void SetSamplerDescriptor(SamplerDescriptor desc)
An object used to specify work to the GPU along with references to resources the GPU will used when d...
Capture CreateChild(const std::string &label)
#define DEBUG_COMMAND_INFO(obj, arg)
uint32_t GetStencilDepth() const
void SetOpacity(Scalar opacity)
Capture & GetCapture() const
void SetInheritedOpacity(Scalar opacity) override
Inherit the provided opacity.
constexpr float kEhCloseEnough
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
std::optional< Rect > GetCoverage(const Entity &entity) const override
Get the screen space bounding rectangle that this contents affects.
void SetSourceRect(const Rect &source_rect)
void SetStencilEnabled(bool enabled)
VertexBufferBuilder & AddVertices(std::initializer_list< VertexType_ > vertices)
static constexpr Matrix MakeTranslation(const Vector3 &t)
Scalar GetOpacity() const
const Matrix & GetTransformation() const
constexpr bool IsEmpty() const
ContentContextOptions OptionsFromPassAndEntity(const RenderPass &pass, const Entity &entity)
ISize GetRenderTargetSize() const
~TextureContents() override
const Rect & GetSourceRect() const
bool CanInheritOpacity(const Entity &entity) const override
Whether or not this contents can accept the opacity peephole optimization.
std::shared_ptr< Context > GetContext() const
void SetLabel(std::string label)
Represents a texture and its intended draw transform/sampler configuration.
std::shared_ptr< Texture > GetTexture() const
VertexBuffer CreateVertexBuffer(HostBuffer &host_buffer) const
Render passes encode render commands directed as one specific render target into an underlying comman...
void SetDeferApplyingOpacity(bool defer_applying_opacity)
uint32_t stencil_reference
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
@ kAlways
Comparison test passes always passes.
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....
static constexpr Matrix MakeOrthographic(TSize< T > size)
void SetTexture(std::shared_ptr< Texture > texture)
constexpr bool IsEmpty() const
bool BindVertices(const VertexBuffer &buffer)
Specify the vertex and index buffer to use for this command.
std::shared_ptr< Texture > texture
std::shared_ptr< Pipeline< PipelineDescriptor > > pipeline
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
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, const std::string &label="Texture Snapshot") const override
Render this contents to a snapshot, respecting the entity's transform, path, stencil depth,...
bool AddCommand(Command &&command)
Record a command for subsequent encoding to the underlying command buffer. No work is encoded into th...
static constexpr Matrix MakeScale(const Vector3 &s)
HostBuffer & GetTransientsBuffer()
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, const std::string &label="Snapshot") const
Render this contents to a snapshot, respecting the entity's transform, path, stencil depth,...