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 39 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  pipelines_[{PipelineKey{GeometryType::kUnskinned, MaterialType::kUnlit}}] =
44  MakePipelineVariants<UnskinnedVertexShader, UnlitFragmentShader>(
45  *context_);
46  pipelines_[{PipelineKey{GeometryType::kSkinned, MaterialType::kUnlit}}] =
47  MakePipelineVariants<SkinnedVertexShader, UnlitFragmentShader>(*context_);
48 
49  {
50  impeller::TextureDescriptor texture_descriptor;
52  texture_descriptor.format = PixelFormat::kR8G8B8A8UNormInt;
53  texture_descriptor.size = {1, 1};
54  texture_descriptor.mip_count = 1u;
55 
56  placeholder_texture_ =
57  context_->GetResourceAllocator()->CreateTexture(texture_descriptor);
58  placeholder_texture_->SetLabel("Placeholder Texture");
59  if (!placeholder_texture_) {
60  FML_LOG(ERROR) << "Could not create placeholder texture.";
61  return;
62  }
63 
64  uint8_t pixel[] = {0xFF, 0xFF, 0xFF, 0xFF};
65  if (!placeholder_texture_->SetContents(pixel, 4)) {
66  FML_LOG(ERROR) << "Could not set contents of placeholder texture.";
67  return;
68  }
69  }
70 
71  is_valid_ = true;
72 }

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 76 of file scene_context.cc.

78  {
79  if (!IsValid()) {
80  return nullptr;
81  }
82  if (auto found = pipelines_.find(key); found != pipelines_.end()) {
83  return found->second->GetPipeline(*context_, opts);
84  }
85  return nullptr;
86 }

References IsValid().

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

◆ GetPlaceholderTexture()

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

Definition at line 96 of file scene_context.cc.

96  {
97  return placeholder_texture_;
98 }

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

◆ IsValid()

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

Definition at line 88 of file scene_context.cc.

88  {
89  return is_valid_;
90 }

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:42
impeller::TextureDescriptor::mip_count
size_t mip_count
Definition: texture_descriptor.h:44
impeller::PixelFormat::kR8G8B8A8UNormInt
@ kR8G8B8A8UNormInt
impeller::StorageMode::kHostVisible
@ kHostVisible
impeller::scene::SceneContext::IsValid
bool IsValid() const
Definition: scene_context.cc:88
impeller::scene::MaterialType::kUnlit
@ kUnlit
impeller::TextureDescriptor::size
ISize size
Definition: texture_descriptor.h:43
impeller::scene::GeometryType::kSkinned
@ kSkinned
impeller::TextureDescriptor::storage_mode
StorageMode storage_mode
Definition: texture_descriptor.h:40
impeller::TextureDescriptor
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
Definition: texture_descriptor.h:39