forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscene_context.cc
101 lines (83 loc) · 3.15 KB
/
scene_context.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "impeller/scene/scene_context.h"
#include "impeller/core/formats.h"
#include "impeller/scene/material.h"
#include "impeller/scene/shaders/skinned.vert.h"
#include "impeller/scene/shaders/unlit.frag.h"
#include "impeller/scene/shaders/unskinned.vert.h"
namespace impeller {
namespace scene {
void SceneContextOptions::ApplyToPipelineDescriptor(
const Capabilities& capabilities,
PipelineDescriptor& desc) const {
DepthAttachmentDescriptor depth;
depth.depth_compare = CompareFunction::kLess;
depth.depth_write_enabled = true;
desc.SetDepthStencilAttachmentDescriptor(depth);
desc.SetDepthPixelFormat(capabilities.GetDefaultDepthStencilFormat());
StencilAttachmentDescriptor stencil;
stencil.stencil_compare = CompareFunction::kAlways;
stencil.depth_stencil_pass = StencilOperation::kKeep;
desc.SetStencilAttachmentDescriptors(stencil);
desc.SetStencilPixelFormat(capabilities.GetDefaultDepthStencilFormat());
desc.SetSampleCount(sample_count);
desc.SetPrimitiveType(primitive_type);
desc.SetWindingOrder(WindingOrder::kCounterClockwise);
desc.SetCullMode(CullMode::kBackFace);
}
SceneContext::SceneContext(std::shared_ptr<Context> context)
: context_(std::move(context)) {
if (!context_ || !context_->IsValid()) {
return;
}
pipelines_[{PipelineKey{GeometryType::kUnskinned, MaterialType::kUnlit}}] =
MakePipelineVariants<UnskinnedVertexShader, UnlitFragmentShader>(
*context_);
pipelines_[{PipelineKey{GeometryType::kSkinned, MaterialType::kUnlit}}] =
MakePipelineVariants<SkinnedVertexShader, UnlitFragmentShader>(*context_);
{
impeller::TextureDescriptor texture_descriptor;
texture_descriptor.storage_mode = impeller::StorageMode::kHostVisible;
texture_descriptor.format = PixelFormat::kR8G8B8A8UNormInt;
texture_descriptor.size = {1, 1};
texture_descriptor.mip_count = 1u;
placeholder_texture_ =
context_->GetResourceAllocator()->CreateTexture(texture_descriptor);
placeholder_texture_->SetLabel("Placeholder Texture");
if (!placeholder_texture_) {
FML_LOG(ERROR) << "Could not create placeholder texture.";
return;
}
uint8_t pixel[] = {0xFF, 0xFF, 0xFF, 0xFF};
if (!placeholder_texture_->SetContents(pixel, 4)) {
FML_LOG(ERROR) << "Could not set contents of placeholder texture.";
return;
}
}
is_valid_ = true;
}
SceneContext::~SceneContext() = default;
std::shared_ptr<Pipeline<PipelineDescriptor>> SceneContext::GetPipeline(
PipelineKey key,
SceneContextOptions opts) const {
if (!IsValid()) {
return nullptr;
}
if (auto found = pipelines_.find(key); found != pipelines_.end()) {
return found->second->GetPipeline(*context_, opts);
}
return nullptr;
}
bool SceneContext::IsValid() const {
return is_valid_;
}
std::shared_ptr<Context> SceneContext::GetContext() const {
return context_;
}
std::shared_ptr<Texture> SceneContext::GetPlaceholderTexture() const {
return placeholder_texture_;
}
} // namespace scene
} // namespace impeller