Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
impeller::scene::SceneContext Class Reference

#include <scene_context.h>

Public Member Functions

 SceneContext (std::shared_ptr< Context > context)
 
 ~SceneContext ()
 
bool IsValid () const
 
std::shared_ptr< Pipeline< PipelineDescriptor > > GetPipeline (PipelineKey key, SceneContextOptions opts) const
 
std::shared_ptr< ContextGetContext () const
 
std::shared_ptr< TextureGetPlaceholderTexture () const
 
HostBufferGetTransientsBuffer () const
 

Detailed Description

Definition at line 41 of file scene_context.h.

Constructor & Destructor Documentation

◆ SceneContext()

impeller::scene::SceneContext::SceneContext ( std::shared_ptr< Context context)
explicit

Definition at line 38 of file scene_context.cc.

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 }
51 pipelines_[{PipelineKey{GeometryType::kUnskinned, MaterialType::kUnlit}}] =
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 }
60 pipelines_[{PipelineKey{GeometryType::kSkinned, MaterialType::kUnlit}}] =
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}
static std::shared_ptr< HostBuffer > Create(const std::shared_ptr< Allocator > &allocator)
std::shared_ptr< Context > GetContext() const
#define FML_LOG(severity)
Definition logging.h:82
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
#define ERROR(message)

◆ ~SceneContext()

impeller::scene::SceneContext::~SceneContext ( )
default

Member Function Documentation

◆ GetContext()

std::shared_ptr< Context > impeller::scene::SceneContext::GetContext ( ) const

Definition at line 106 of file scene_context.cc.

106 {
107 return context_;
108}

◆ GetPipeline()

std::shared_ptr< Pipeline< PipelineDescriptor > > impeller::scene::SceneContext::GetPipeline ( PipelineKey  key,
SceneContextOptions  opts 
) const

Definition at line 90 of file scene_context.cc.

92 {
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}

◆ GetPlaceholderTexture()

std::shared_ptr< Texture > impeller::scene::SceneContext::GetPlaceholderTexture ( ) const

Definition at line 110 of file scene_context.cc.

110 {
111 return placeholder_texture_;
112}

◆ GetTransientsBuffer()

HostBuffer & impeller::scene::SceneContext::GetTransientsBuffer ( ) const
inline

Definition at line 57 of file scene_context.h.

57{ return *host_buffer_; }

◆ IsValid()

bool impeller::scene::SceneContext::IsValid ( ) const

Definition at line 102 of file scene_context.cc.

102 {
103 return is_valid_;
104}

The documentation for this class was generated from the following files: