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

References impeller::HostBuffer::Create(), impeller::TextureDescriptor::format, GetContext(), 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()

◆ 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 }

References IsValid().

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

◆ 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 }

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

◆ GetTransientsBuffer()

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

Definition at line 57 of file scene_context.h.

57 { return *host_buffer_; }

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

◆ IsValid()

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

Definition at line 102 of file scene_context.cc.

102  {
103  return is_valid_;
104 }

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::HostBuffer::Create
static std::shared_ptr< HostBuffer > Create(const std::shared_ptr< Allocator > &allocator)
Definition: host_buffer.cc:20
impeller::StorageMode::kHostVisible
@ kHostVisible
impeller::scene::SceneContext::IsValid
bool IsValid() const
Definition: scene_context.cc:102
impeller::scene::MaterialType::kUnlit
@ kUnlit
impeller::TextureDescriptor::size
ISize size
Definition: texture_descriptor.h:41
impeller::scene::GeometryType::kSkinned
@ kSkinned
impeller::scene::SceneContext::GetContext
std::shared_ptr< Context > GetContext() const
Definition: scene_context.cc:106
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