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 
6 
7 #include <format>
8 
9 #include "fml/logging.h"
11 #include "impeller/core/formats.h"
20 
21 namespace impeller {
22 
23 //------------------------------------------------------
24 // ShadowVerticesContents
25 
27  const std::shared_ptr<ShadowVertices>& geometry)
28  : geometry_(geometry) {}
29 
31 
32 std::shared_ptr<ShadowVerticesContents> ShadowVerticesContents::Make(
33  const std::shared_ptr<ShadowVertices>& geometry) {
34  return std::make_shared<ShadowVerticesContents>(geometry);
35 }
36 
38  const Entity& entity) const {
39  return geometry_->GetBounds();
40 }
41 
43  shadow_color_ = color;
44 }
45 
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
PipelineRef GetDrawShadowVerticesPipeline(ContentContextOptions opts) const
HostBuffer & GetTransientsDataBuffer() const
Retrieve the current host buffer for transient storage of other non-index data.
Matrix GetShaderTransform(const RenderPass &pass) const
Definition: entity.cc:50
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:30
virtual bool SetVertexBuffer(VertexBuffer buffer)
Specify the vertex and index buffer to use for this command.
Definition: render_pass.cc:127
virtual void SetPipeline(PipelineRef pipeline)
The pipeline to use for this command.
Definition: render_pass.cc:86
virtual fml::Status Draw()
Record the currently pending command.
Definition: render_pass.cc:208
virtual void SetCommandLabel(std::string_view label)
The debugging label to use for the command.
Definition: render_pass.cc:97
ShadowVerticesContents(const std::shared_ptr< ShadowVertices > &geometry)
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
static std::shared_ptr< ShadowVerticesContents > Make(const std::shared_ptr< ShadowVertices > &geometry)
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.
LinePipeline::FragmentShader FS
LinePipeline::VertexShader VS
ContentContextOptions OptionsFromPassAndEntity(const RenderPass &pass, const Entity &entity)
Definition: contents.cc:34
constexpr Color Premultiply() const
Definition: color.h:212
PrimitiveType type
Definition: geometry.h:37
@ kNormal
The geometry has no overlapping triangles.
VertexBuffer vertex_buffer
Definition: geometry.h:38