Flutter Engine
The Flutter Engine
scene_encoder.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#include "flutter/fml/logging.h"
9
10namespace impeller {
11namespace scene {
12
13SceneEncoder::SceneEncoder() = default;
14
16 // TODO(bdero): Manage multi-pass translucency ordering.
17 commands_.push_back(command);
18}
19
20static void EncodeCommand(const SceneContext& scene_context,
21 const Matrix& view_transform,
22 RenderPass& render_pass,
23 const SceneCommand& scene_command) {
24 auto& host_buffer = scene_context.GetTransientsBuffer();
25
26 render_pass.SetCommandLabel(scene_command.label);
27 // TODO(bdero): Configurable stencil ref per-command.
28 render_pass.SetStencilReference(0);
29
30 render_pass.SetPipeline(scene_context.GetPipeline(
31 PipelineKey{scene_command.geometry->GetGeometryType(),
32 scene_command.material->GetMaterialType()},
33 scene_command.material->GetContextOptions(render_pass)));
34
35 scene_command.geometry->BindToCommand(
36 scene_context, host_buffer, view_transform * scene_command.transform,
37 render_pass);
38 scene_command.material->BindToCommand(scene_context, host_buffer,
39 render_pass);
40
41 render_pass.Draw();
42 ;
43}
44
45std::shared_ptr<CommandBuffer> SceneEncoder::BuildSceneCommandBuffer(
46 const SceneContext& scene_context,
47 const Matrix& camera_transform,
48 RenderTarget render_target) const {
49 {
50 TextureDescriptor ds_texture;
53 ds_texture.size = render_target.GetRenderTargetSize();
57 auto texture =
58 scene_context.GetContext()->GetResourceAllocator()->CreateTexture(
59 ds_texture);
60
61 DepthAttachment depth;
64 depth.clear_depth = 1.0;
65 depth.texture = texture;
66 render_target.SetDepthAttachment(depth);
67
68 // The stencil and depth buffers must be the same texture for MacOS ARM
69 // and Vulkan.
70 StencilAttachment stencil;
73 stencil.clear_stencil = 0u;
74 stencil.texture = texture;
75 render_target.SetStencilAttachment(stencil);
76 }
77
78 auto command_buffer = scene_context.GetContext()->CreateCommandBuffer();
79 if (!command_buffer) {
80 FML_LOG(ERROR) << "Failed to create command buffer.";
81 return nullptr;
82 }
83
84 auto render_pass = command_buffer->CreateRenderPass(render_target);
85 if (!render_pass) {
86 FML_LOG(ERROR) << "Failed to create render pass.";
87 return nullptr;
88 }
89
90 for (auto& command : commands_) {
91 EncodeCommand(scene_context, camera_transform, *render_pass, command);
92 }
93
94 if (!render_pass->EncodeCommands()) {
95 FML_LOG(ERROR) << "Failed to encode render pass commands.";
96 return nullptr;
97 }
98
99 return command_buffer;
100}
101
102} // namespace scene
103} // namespace impeller
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:33
virtual void SetStencilReference(uint32_t value)
Definition: render_pass.cc:103
virtual void SetPipeline(const std::shared_ptr< Pipeline< PipelineDescriptor > > &pipeline)
The pipeline to use for this command.
Definition: render_pass.cc:92
virtual fml::Status Draw()
Record the currently pending command.
Definition: render_pass.cc:127
virtual void SetCommandLabel(std::string_view label)
The debugging label to use for the command.
Definition: render_pass.cc:97
RenderTarget & SetDepthAttachment(std::optional< DepthAttachment > attachment)
ISize GetRenderTargetSize() const
RenderTarget & SetStencilAttachment(std::optional< StencilAttachment > attachment)
virtual void BindToCommand(const SceneContext &scene_context, HostBuffer &buffer, const Matrix &transform, RenderPass &pass) const =0
virtual void BindToCommand(const SceneContext &scene_context, HostBuffer &buffer, RenderPass &pass) const =0
SceneContextOptions GetContextOptions(const RenderPass &pass) const
Definition: material.cc:62
std::shared_ptr< Pipeline< PipelineDescriptor > > GetPipeline(PipelineKey key, SceneContextOptions opts) const
HostBuffer & GetTransientsBuffer() const
Definition: scene_context.h:57
void Add(const SceneCommand &command)
#define FML_LOG(severity)
Definition: logging.h:82
FlTexture * texture
static void EncodeCommand(const SceneContext &scene_context, const Matrix &view_transform, RenderPass &render_pass, const SceneCommand &scene_command)
list command
Definition: valgrind.py:24
LoadAction load_action
Definition: formats.h:653
std::shared_ptr< Texture > texture
Definition: formats.h:651
StoreAction store_action
Definition: formats.h:654
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
#define ERROR(message)
Definition: elf_loader.cc:260