Flutter Impeller
checkerboard_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 <memory>
8 
14 
15 namespace impeller {
16 
18 
20 
22  const Entity& entity,
23  RenderPass& pass) const {
24  auto& host_buffer = pass.GetTransientsBuffer();
25 
26  using VS = CheckerboardPipeline::VertexShader;
27  using FS = CheckerboardPipeline::FragmentShader;
28 
29  Command cmd;
30  DEBUG_COMMAND_INFO(cmd, "Checkerboard");
31 
32  auto options = OptionsFromPass(pass);
33  options.blend_mode = BlendMode::kSourceOver;
34  options.stencil_compare = CompareFunction::kAlways; // Ignore all clips.
35  options.stencil_operation = StencilOperation::kKeep;
36  options.primitive_type = PrimitiveType::kTriangleStrip;
37  cmd.pipeline = renderer.GetCheckerboardPipeline(options);
38 
40  vtx_builder.AddVertices({
41  {Point(-1, -1)},
42  {Point(1, -1)},
43  {Point(-1, 1)},
44  {Point(1, 1)},
45  });
46  cmd.BindVertices(vtx_builder.CreateVertexBuffer(host_buffer));
47 
48  FS::FragInfo frag_info;
49  frag_info.color = color_;
50  frag_info.square_size = square_size_;
51  FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
52 
53  pass.AddCommand(std::move(cmd));
54 
55  return true;
56 }
57 
59  const Entity& entity) const {
60  return std::nullopt;
61 }
62 
64  color_ = color;
65 }
66 
68  square_size_ = square_size;
69 }
70 
71 } // namespace impeller
impeller::OptionsFromPass
ContentContextOptions OptionsFromPass(const RenderPass &pass)
Definition: contents.cc:20
impeller::Command
An object used to specify work to the GPU along with references to resources the GPU will used when d...
Definition: command.h:92
DEBUG_COMMAND_INFO
#define DEBUG_COMMAND_INFO(obj, arg)
Definition: command.h:28
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::CheckerboardContents::~CheckerboardContents
~CheckerboardContents() override
impeller::Color
Definition: color.h:124
impeller::StencilOperation::kKeep
@ kKeep
Don't modify the current stencil value.
formats.h
impeller::VertexBufferBuilder::AddVertices
VertexBufferBuilder & AddVertices(std::initializer_list< VertexType_ > vertices)
Definition: vertex_buffer_builder.h:70
checkerboard_contents.h
impeller::Entity
Definition: entity.h:21
command.h
impeller::CheckerboardContents::SetSquareSize
void SetSquareSize(Scalar square_size)
Definition: checkerboard_contents.cc:67
impeller::PrimitiveType::kTriangleStrip
@ kTriangleStrip
impeller::Point
TPoint< Scalar > Point
Definition: point.h:308
render_pass.h
impeller::VertexBufferBuilder
Definition: vertex_buffer_builder.h:24
impeller::Command::BindVertices
bool BindVertices(VertexBuffer buffer)
Specify the vertex and index buffer to use for this command.
Definition: command.cc:15
impeller::CheckerboardContents::Render
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Definition: checkerboard_contents.cc:21
impeller::CompareFunction::kAlways
@ kAlways
Comparison test passes always passes.
impeller::VertexBufferBuilder::CreateVertexBuffer
VertexBuffer CreateVertexBuffer(HostBuffer &host_buffer) const
Definition: vertex_buffer_builder.h:84
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:29
impeller::CheckerboardContents::SetColor
void SetColor(Color color)
Definition: checkerboard_contents.cc:63
content_context.h
impeller::CheckerboardContents::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: checkerboard_contents.cc:58
impeller::Command::pipeline
std::shared_ptr< Pipeline< PipelineDescriptor > > pipeline
Definition: command.h:96
impeller::RenderPass::AddCommand
bool AddCommand(Command &&command)
Record a command for subsequent encoding to the underlying command buffer. No work is encoded into th...
Definition: render_pass.cc:67
impeller
Definition: aiks_context.cc:10
impeller::ContentContext
Definition: content_context.h:332
impeller::RenderPass::GetTransientsBuffer
HostBuffer & GetTransientsBuffer()
Definition: render_pass.cc:55
impeller::BlendMode::kSourceOver
@ kSourceOver
vertex_buffer_builder.h
impeller::CheckerboardContents::CheckerboardContents
CheckerboardContents()