| Flutter Impeller |

Namespaces | Classes | Enumerations | Functions | Variables
impeller::scene Namespace Reference

## Namespaces
| importer
| testing

## Classes
class | Animation
class | AnimationClip
class | AnimationPlayer
struct | AnimationTransforms
class | Camera
class | CuboidGeometry
class | Geometry
class | Material
class | Mesh
class | Node
class | PhysicallyBasedMaterial
struct | PipelineKey
class | PropertyResolver
class | RotationTimelineResolver
class | ScaleTimelineResolver
class | Scene
struct | SceneCommand
class | SceneContext
struct | SceneContextOptions
class | SceneEncoder
class | Skin
class | SkinnedVertexBufferGeometry
class | TimelineResolver
class | TranslationTimelineResolver
class | UnlitMaterial
class | UnskinnedVertexBufferGeometry

## Enumerations
enum | GeometryType { GeometryType::kUnskinned = 0, GeometryType::kSkinned = 1, GeometryType::kLastType = kSkinned }
enum | MaterialType { MaterialType::kUnlit = 0, MaterialType::kLastType = kUnlit }

## Functions
static std::shared_ptr< Texture > | UnpackTextureFromFlatbuffer (const fb::Texture *iptexture, Allocator &allocator)
static void | EncodeCommand (const SceneContext &scene_context, const Matrix &view_transform, RenderPass &render_pass, const SceneCommand &scene_command)

## Variables
static std::atomic_uint64_t | kNextNodeID = 0

## Enumeration Type Documentation

## ◆ GeometryType

enum impeller::scene::GeometryType
| strong

Enumerator
kUnskinned |
kSkinned |
kLastType |

Definition at line 13 of file pipeline_key.h.

13 {
14 kUnskinned = 0,
15 kSkinned = 1,
16 kLastType = kSkinned,
17 };

## ◆ MaterialType

enum impeller::scene::MaterialType
| strong

Enumerator
kUnlit |
kLastType |

Definition at line 18 of file pipeline_key.h.

18 {
19 kUnlit = 0,
20 kLastType = kUnlit,
21 };

## Function Documentation

## ◆ EncodeCommand()

static void impeller::scene::EncodeCommand | ( | const SceneContext & | scene_context,
|  | const Matrix & | view_transform,
|  | RenderPass & | render_pass,
|  | const SceneCommand & | scene_command
| ) |  |
| static

Definition at line 23 of file scene_encoder.cc.

26 {
27 auto& host_buffer = scene_context.GetTransientsBuffer();
28
29 render_pass.SetCommandLabel(scene_command.label);
30 // TODO(bdero): Configurable stencil ref per-command.
31 render_pass.SetStencilReference(0);
32
33 render_pass.SetPipeline(scene_context.GetPipeline(
34 PipelineKey{scene_command.geometry->GetGeometryType(),
35 scene_command.material->GetMaterialType()},
36 scene_command.material->GetContextOptions(render_pass)));
37
38 scene_command.geometry->BindToCommand(
39 scene_context, host_buffer, view_transform * scene_command.transform,
40 render_pass);
41 scene_command.material->BindToCommand(scene_context, host_buffer,
42 render_pass);
43
44 render_pass.Draw();
45 ;
46 }

References impeller::scene::Geometry::BindToCommand(), impeller::scene::Material::BindToCommand(), impeller::RenderPass::Draw(), impeller::scene::SceneCommand::geometry, impeller::scene::Material::GetContextOptions(), impeller::scene::SceneContext::GetPipeline(), impeller::scene::SceneContext::GetTransientsBuffer(), impeller::scene::SceneCommand::label, impeller::scene::SceneCommand::material, impeller::RenderPass::SetCommandLabel(), impeller::RenderPass::SetPipeline(), impeller::RenderPass::SetStencilReference(), and impeller::scene::SceneCommand::transform.

## ◆ UnpackTextureFromFlatbuffer()

static std::shared_ptr<Texture> impeller::scene::UnpackTextureFromFlatbuffer | ( | const fb::Texture * | iptexture,
|  | Allocator & | allocator
| ) |  |
| static

Definition at line 61 of file node.cc.

63 {
64 if (iptexture == nullptr || iptexture->embedded_image() == nullptr ||
65 iptexture->embedded_image()->bytes() == nullptr) {
66 return nullptr;
67 }
68
69 auto embedded = iptexture->embedded_image();
70
71 uint8_t bytes_per_component = 0;
72 switch (embedded->component_type()) {
73 case fb::ComponentType::k8Bit:
74 bytes_per_component = 1;
75 break;
76 case fb::ComponentType::k16Bit:
77 // bytes_per_component = 2;
78 FML_LOG(WARNING) << "16 bit textures not yet supported.";
79 return nullptr;
80 }
81
82 switch (embedded->component_count()) {
83 case 4:
84 // RGBA.
85 break;
86 case 1:
87 case 3:
88 default:
89 FML_LOG(WARNING) << "Textures with " << embedded->component_count()
90 << " components are not supported." << std::endl;
91 return nullptr;
92 }
93 if (embedded->bytes()->size() != bytes_per_component *
94 embedded->component_count() *
95 embedded->width() * embedded->height()) {
96 FML_LOG(WARNING) << "Embedded texture has an unexpected size. Skipping."
97 << std::endl;
98 return nullptr;
99 }
100
101 auto image_mapping = std::make_shared<fml::NonOwnedMapping>(
102 embedded->bytes()->Data(), embedded->bytes()->size());
103
104 auto texture_descriptor = TextureDescriptor{};
105 texture_descriptor.storage_mode = StorageMode::kHostVisible;
106 texture_descriptor.format = PixelFormat::kR8G8B8A8UNormInt;
107 texture_descriptor.size = ISize(embedded->width(), embedded->height());
108 // TODO(bdero): Generate mipmaps for embedded textures.
109 texture_descriptor.mip_count = 1u;
110
111 auto texture = allocator.CreateTexture(texture_descriptor);
112 if (!texture) {
113 FML_LOG(ERROR) << "Could not allocate texture.";
114 return nullptr;
115 }
116
117 auto uploaded = texture->SetContents(image_mapping);
118 if (!uploaded) {
119 FML_LOG(ERROR) << "Could not upload texture to device memory.";
120 return nullptr;
121 }
122
123 return texture;
124 }

References impeller::Allocator::CreateTexture(), impeller::kHostVisible, impeller::kR8G8B8A8UNormInt, and impeller::TextureDescriptor::storage_mode.

Referenced by impeller::scene::Node::MakeFromFlatbuffer().

## Variable Documentation

## ◆ kNextNodeID

std::atomic_uint64_t impeller::scene::kNextNodeID = 0
| static

Definition at line 27 of file node.cc.

impeller::scene::GeometryType::kUnskinned
@ kUnskinned
impeller::scene::GeometryType::kLastType
@ kLastType
impeller::scene::MaterialType::kUnlit
@ kUnlit
impeller::ISize
TSize< int64_t > ISize
Definition: size.h:138
impeller::scene::GeometryType::kSkinned
@ kSkinned