Flutter Impeller
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
 

Detailed Description

Definition at line 40 of file scene_context.h.

Constructor & Destructor Documentation

◆ SceneContext()

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

Definition at line 37 of file scene_context.cc.

38  : context_(std::move(context)) {
39  if (!context_ || !context_->IsValid()) {
40  return;
41  }
42 
43  auto unskinned_variant =
44  MakePipelineVariants<UnskinnedVertexShader, UnlitFragmentShader>(
45  *context_);
46  if (!unskinned_variant) {
47  FML_LOG(ERROR) << "Could not create unskinned pipeline variant.";
48  return;
49  }
50  pipelines_[{PipelineKey{GeometryType::kUnskinned, MaterialType::kUnlit}}] =
51  std::move(unskinned_variant);
52 
53  auto skinned_variant =
54  MakePipelineVariants<SkinnedVertexShader, UnlitFragmentShader>(*context_);
55  if (!skinned_variant) {
56  FML_LOG(ERROR) << "Could not create skinned pipeline variant.";
57  return;
58  }
59  pipelines_[{PipelineKey{GeometryType::kSkinned, MaterialType::kUnlit}}] =
60  std::move(skinned_variant);
61 
62  {
63  impeller::TextureDescriptor texture_descriptor;
65  texture_descriptor.format = PixelFormat::kR8G8B8A8UNormInt;
66  texture_descriptor.size = {1, 1};
67  texture_descriptor.mip_count = 1u;
68 
69  placeholder_texture_ =
70  context_->GetResourceAllocator()->CreateTexture(texture_descriptor);
71  placeholder_texture_->SetLabel("Placeholder Texture");
72  if (!placeholder_texture_) {
73  FML_LOG(ERROR) << "Could not create placeholder texture.";
74  return;
75  }
76 
77  uint8_t pixel[] = {0xFF, 0xFF, 0xFF, 0xFF};
78  if (!placeholder_texture_->SetContents(pixel, 4)) {
79  FML_LOG(ERROR) << "Could not set contents of placeholder texture.";
80  return;
81  }
82  }
83 
84  is_valid_ = true;
85 }

References impeller::TextureDescriptor::format, impeller::kHostVisible, impeller::kR8G8B8A8UNormInt, impeller::scene::kSkinned, impeller::scene::kUnlit, impeller::scene::kUnskinned, impeller::TextureDescriptor::mip_count, impeller::TextureDescriptor::size, and impeller::TextureDescriptor::storage_mode.

◆ ~SceneContext()

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

Member Function Documentation

◆ GetContext()

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

◆ GetPipeline()

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

Definition at line 89 of file scene_context.cc.

91  {
92  if (!IsValid()) {
93  return nullptr;
94  }
95  if (auto found = pipelines_.find(key); found != pipelines_.end()) {
96  return found->second->GetPipeline(*context_, opts);
97  }
98  return nullptr;
99 }

References IsValid().

Referenced by impeller::scene::EncodeCommand().

◆ GetPlaceholderTexture()

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

Definition at line 109 of file scene_context.cc.

109  {
110  return placeholder_texture_;
111 }

Referenced by impeller::scene::UnlitMaterial::BindToCommand(), and impeller::scene::SkinnedVertexBufferGeometry::BindToCommand().

◆ IsValid()

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

Definition at line 101 of file scene_context.cc.

101  {
102  return is_valid_;
103 }

Referenced by GetPipeline().


The documentation for this class was generated from the following files:
impeller::scene::GeometryType::kUnskinned
@ kUnskinned
impeller::TextureDescriptor::format
PixelFormat format
Definition: texture_descriptor.h:40
impeller::PixelFormat::kR8G8B8A8UNormInt
@ kR8G8B8A8UNormInt
impeller::TextureDescriptor::mip_count
size_t mip_count
Definition: texture_descriptor.h:42
impeller::StorageMode::kHostVisible
@ kHostVisible
impeller::scene::SceneContext::IsValid
bool IsValid() const
Definition: scene_context.cc:101
impeller::scene::MaterialType::kUnlit
@ kUnlit
impeller::TextureDescriptor::size
ISize size
Definition: texture_descriptor.h:41
impeller::scene::GeometryType::kSkinned
@ kSkinned
impeller::TextureDescriptor::storage_mode
StorageMode storage_mode
Definition: texture_descriptor.h:38
impeller::TextureDescriptor
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
Definition: texture_descriptor.h:37