Flutter Engine
The Flutter Engine
scene_context.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
9#include "impeller/scene/shaders/skinned.vert.h"
10#include "impeller/scene/shaders/unlit.frag.h"
11#include "impeller/scene/shaders/unskinned.vert.h"
12
13namespace impeller {
14namespace scene {
15
17 const Capabilities& capabilities,
18 PipelineDescriptor& desc) const {
21 depth.depth_write_enabled = true;
22 desc.SetDepthStencilAttachmentDescriptor(depth);
23 desc.SetDepthPixelFormat(capabilities.GetDefaultDepthStencilFormat());
24
28 desc.SetStencilAttachmentDescriptors(stencil);
29 desc.SetStencilPixelFormat(capabilities.GetDefaultDepthStencilFormat());
30
31 desc.SetSampleCount(sample_count);
32 desc.SetPrimitiveType(primitive_type);
33
35 desc.SetCullMode(CullMode::kBackFace);
36}
37
38SceneContext::SceneContext(std::shared_ptr<Context> context)
39 : context_(std::move(context)) {
40 if (!context_ || !context_->IsValid()) {
41 return;
42 }
43
44 auto unskinned_variant =
45 MakePipelineVariants<UnskinnedVertexShader, UnlitFragmentShader>(
46 *context_);
47 if (!unskinned_variant) {
48 FML_LOG(ERROR) << "Could not create unskinned pipeline variant.";
49 return;
50 }
52 std::move(unskinned_variant);
53
54 auto skinned_variant =
55 MakePipelineVariants<SkinnedVertexShader, UnlitFragmentShader>(*context_);
56 if (!skinned_variant) {
57 FML_LOG(ERROR) << "Could not create skinned pipeline variant.";
58 return;
59 }
61 std::move(skinned_variant);
62
63 {
64 impeller::TextureDescriptor texture_descriptor;
66 texture_descriptor.format = PixelFormat::kR8G8B8A8UNormInt;
67 texture_descriptor.size = {1, 1};
68 texture_descriptor.mip_count = 1u;
69
70 placeholder_texture_ =
71 context_->GetResourceAllocator()->CreateTexture(texture_descriptor);
72 placeholder_texture_->SetLabel("Placeholder Texture");
73 if (!placeholder_texture_) {
74 FML_LOG(ERROR) << "Could not create placeholder texture.";
75 return;
76 }
77
78 uint8_t pixel[] = {0xFF, 0xFF, 0xFF, 0xFF};
79 if (!placeholder_texture_->SetContents(pixel, 4)) {
80 FML_LOG(ERROR) << "Could not set contents of placeholder texture.";
81 return;
82 }
83 }
84 host_buffer_ = HostBuffer::Create(GetContext()->GetResourceAllocator());
85 is_valid_ = true;
86}
87
89
90std::shared_ptr<Pipeline<PipelineDescriptor>> SceneContext::GetPipeline(
92 SceneContextOptions opts) const {
93 if (!IsValid()) {
94 return nullptr;
95 }
96 if (auto found = pipelines_.find(key); found != pipelines_.end()) {
97 return found->second->GetPipeline(*context_, opts);
98 }
99 return nullptr;
100}
101
103 return is_valid_;
104}
105
106std::shared_ptr<Context> SceneContext::GetContext() const {
107 return context_;
108}
109
110std::shared_ptr<Texture> SceneContext::GetPlaceholderTexture() const {
111 return placeholder_texture_;
112}
113
114} // namespace scene
115} // namespace impeller
virtual PixelFormat GetDefaultDepthStencilFormat() const =0
Returns a supported PixelFormat for textures that store both a stencil and depth component....
static std::shared_ptr< HostBuffer > Create(const std::shared_ptr< Allocator > &allocator)
Definition: host_buffer.cc:20
std::shared_ptr< Context > GetContext() const
SceneContext(std::shared_ptr< Context > context)
std::shared_ptr< Pipeline< PipelineDescriptor > > GetPipeline(PipelineKey key, SceneContextOptions opts) const
std::shared_ptr< Texture > GetPlaceholderTexture() const
#define FML_LOG(severity)
Definition: logging.h:82
@ kAlways
Comparison test passes always passes.
@ kLess
Comparison test passes if new_value < current_value.
@ kKeep
Don't modify the current stencil value.
Definition: ref_ptr.h:256
StencilOperation depth_stencil_pass
Definition: formats.h:623
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
void ApplyToPipelineDescriptor(const Capabilities &capabilities, PipelineDescriptor &desc) const
#define ERROR(message)
Definition: elf_loader.cc:260