| Flutter Impeller |

shadow_vertices_contents.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "shadow_vertices_contents.h"
6
7 #include <format>
8
9 #include "fml/logging.h"
10 #include "impeller/base/validation.h"
11 #include "impeller/core/formats.h"
12 #include "impeller/entity/contents/content_context.h"
13 #include "impeller/entity/contents/contents.h"
14 #include "impeller/entity/contents/filters/blend_filter_contents.h"
15 #include "impeller/entity/contents/pipelines.h"
16 #include "impeller/entity/geometry/geometry.h"
17 #include "impeller/entity/geometry/vertices_geometry.h"
18 #include "impeller/geometry/color.h"
19 #include "impeller/renderer/render_pass.h"
20
21 namespace impeller {
22
23 //------------------------------------------------------
24 // ShadowVerticesContents
25
26 ShadowVerticesContents::ShadowVerticesContents(
27 const std::shared_ptr<ShadowVertices>& geometry)
28 : geometry_(geometry) {}
29
30 ShadowVerticesContents::~ShadowVerticesContents() {}
31
32 std::shared_ptr<ShadowVerticesContents> ShadowVerticesContents::Make(
33 const std::shared_ptr<ShadowVertices>& geometry) {
34 return std::make_shared<ShadowVerticesContents>(geometry);
35 }
36
37 std::optional<Rect> ShadowVerticesContents::GetCoverage(
38 const Entity& entity) const {
39 return geometry_->GetBounds();
40 }
41
42 void ShadowVerticesContents::SetColor(Color color) {
43 shadow_color_ = color;
44 }
45
46 bool ShadowVerticesContents::Render(const ContentContext& renderer,
47 const Entity& entity,
48 RenderPass& pass) const {
49 using VS = ShadowVerticesVertexShader;
50 using FS = ShadowVerticesFragmentShader;
51
52 GeometryResult geometry_result =
53 geometry_->GetPositionBuffer(renderer, entity, pass);
54 if (geometry_result.vertex_buffer.vertex_count == 0) {
55 return true;
56 }
57 FML_DCHECK(geometry_result.mode == GeometryResult::Mode::kNormal);
58
59 #ifdef IMPELLER_DEBUG
60 pass.SetCommandLabel("DrawShadow VertexMesh");
61 #endif // IMPELLER_DEBUG
62
63 pass.SetVertexBuffer(std::move(geometry_result.vertex_buffer));
64
65 auto options = OptionsFromPassAndEntity(pass, entity);
66 options.primitive_type = geometry_result.type;
67 pass.SetPipeline(renderer.GetDrawShadowVerticesPipeline(options));
68
69 VS::FrameInfo frame_info;
70 FS::FragInfo frag_info;
71
72 frame_info.mvp = entity.GetShaderTransform(pass);
73
74 frag_info.shadow_color = shadow_color_.Premultiply();
75
76 auto& host_buffer = renderer.GetTransientsDataBuffer();
77 FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
78 VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
79
80 return pass.Draw().ok();
81 }
82
83 } // namespace impeller
blend_filter_contents.h
impeller::ContentContext
Definition: content_context.h:122
impeller::ContentContext::GetDrawShadowVerticesPipeline
PipelineRef GetDrawShadowVerticesPipeline(ContentContextOptions opts) const
Definition: content_context.cc:1513
impeller::ContentContext::GetTransientsDataBuffer
HostBuffer & GetTransientsDataBuffer() const
Retrieve the current host buffer for transient storage of other non-index data.
Definition: content_context.h:299
impeller::Entity
Definition: entity.h:26
impeller::Entity::GetShaderTransform
Matrix GetShaderTransform(const RenderPass &pass) const
Definition: entity.cc:50
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:30
impeller::RenderPass::SetVertexBuffer
virtual bool SetVertexBuffer(VertexBuffer buffer)
Specify the vertex and index buffer to use for this command.
Definition: render_pass.cc:127
impeller::RenderPass::SetPipeline
virtual void SetPipeline(PipelineRef pipeline)
The pipeline to use for this command.
Definition: render_pass.cc:86
impeller::RenderPass::Draw
virtual fml::Status Draw()
Record the currently pending command.
Definition: render_pass.cc:208
impeller::RenderPass::SetCommandLabel
virtual void SetCommandLabel(std::string_view label)
The debugging label to use for the command.
Definition: render_pass.cc:97
impeller::ShadowVerticesContents::ShadowVerticesContents
ShadowVerticesContents(const std::shared_ptr< ShadowVertices > &geometry)
Definition: shadow_vertices_contents.cc:26
impeller::ShadowVerticesContents::Render
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Definition: shadow_vertices_contents.cc:46
impeller::ShadowVerticesContents::~ShadowVerticesContents
~ShadowVerticesContents() override
Definition: shadow_vertices_contents.cc:30
impeller::ShadowVerticesContents::Make
static std::shared_ptr< ShadowVerticesContents > Make(const std::shared_ptr< ShadowVertices > &geometry)
Definition: shadow_vertices_contents.cc:32
impeller::ShadowVerticesContents::GetCoverage
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.
Definition: shadow_vertices_contents.cc:37
impeller::ShadowVerticesContents::SetColor
void SetColor(Color color) override
Definition: shadow_vertices_contents.cc:42
color.h
content_context.h
contents.h
formats.h
geometry.h
impeller
Definition: allocation.cc:12
impeller::FS
LinePipeline::FragmentShader FS
Definition: line_contents.cc:14
impeller::VS
LinePipeline::VertexShader VS
Definition: line_contents.cc:13
impeller::OptionsFromPassAndEntity
ContentContextOptions OptionsFromPassAndEntity(const RenderPass &pass, const Entity &entity)
Definition: contents.cc:34
pipelines.h
render_pass.h
shadow_vertices_contents.h
impeller::Color
Definition: color.h:124
impeller::Color::Premultiply
constexpr Color Premultiply() const
Definition: color.h:212
impeller::GeometryResult
Definition: geometry.h:21
impeller::GeometryResult::type
PrimitiveType type
Definition: geometry.h:37
impeller::GeometryResult::Mode::kNormal
@ kNormal
The geometry has no overlapping triangles.
impeller::GeometryResult::vertex_buffer
VertexBuffer vertex_buffer
Definition: geometry.h:38
impeller::GeometryResult::mode
Mode mode
Definition: geometry.h:40
impeller::VertexBuffer::vertex_count
size_t vertex_count
Definition: vertex_buffer.h:25
validation.h
vertices_geometry.h