| 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 12 of file pipeline_key.h.

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

## ◆ MaterialType

enum impeller::scene::MaterialType
| strong

Enumerator
kUnlit |
kLastType |

Definition at line 17 of file pipeline_key.h.

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

## 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 = render_pass.GetTransientsBuffer();
28
29 Command cmd;
30 DEBUG_COMMAND_INFO(cmd, scene_command.label);
31 cmd.stencil_reference =
32 0; // TODO(bdero): Configurable stencil ref per-command.
33
34 cmd.pipeline = scene_context.GetPipeline(
35 PipelineKey{scene_command.geometry->GetGeometryType(),
36 scene_command.material->GetMaterialType()},
37 scene_command.material->GetContextOptions(render_pass));
38
39 scene_command.geometry->BindToCommand(
40 scene_context, host_buffer, view_transform * scene_command.transform,
41 cmd);
42 scene_command.material->BindToCommand(scene_context, host_buffer, cmd);
43
44 render_pass.AddCommand(std::move(cmd));
45 }

References impeller::RenderPass::AddCommand(), impeller::scene::Geometry::BindToCommand(), impeller::scene::Material::BindToCommand(), DEBUG_COMMAND_INFO, impeller::scene::SceneCommand::geometry, impeller::scene::Material::GetContextOptions(), impeller::scene::Geometry::GetGeometryType(), impeller::scene::Material::GetMaterialType(), impeller::scene::SceneContext::GetPipeline(), impeller::RenderPass::GetTransientsBuffer(), impeller::scene::SceneCommand::label, impeller::scene::SceneCommand::material, impeller::Command::pipeline, impeller::Command::stencil_reference, 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 DecompressedImage::Format format;
83 switch (embedded->component_count()) {
84 case 1:
85 format = DecompressedImage::Format::kGrey;
86 break;
87 case 3:
88 format = DecompressedImage::Format::kRGB;
89 break;
90 case 4:
91 format = DecompressedImage::Format::kRGBA;
92 break;
93 default:
94 FML_LOG(WARNING) << "Textures with " << embedded->component_count()
95 << " components are not supported." << std::endl;
96 return nullptr;
97 }
98 if (embedded->bytes()->size() != bytes_per_component *
99 embedded->component_count() *
100 embedded->width() * embedded->height()) {
101 FML_LOG(WARNING) << "Embedded texture has an unexpected size. Skipping."
102 << std::endl;
103 return nullptr;
104 }
105
106 auto image_mapping = std::make_shared<fml::NonOwnedMapping>(
107 embedded->bytes()->Data(), embedded->bytes()->size());
108 auto decompressed_image =
109 DecompressedImage(ISize(embedded->width(), embedded->height()), format,
110 image_mapping)
111 .ConvertToRGBA();
112
113 auto texture_descriptor = TextureDescriptor{};
114 texture_descriptor.storage_mode = StorageMode::kHostVisible;
115 texture_descriptor.format = PixelFormat::kR8G8B8A8UNormInt;
116 texture_descriptor.size = decompressed_image.GetSize();
117 // TODO(bdero): Generate mipmaps for embedded textures.
118 texture_descriptor.mip_count = 1u;
119
120 auto texture = allocator.CreateTexture(texture_descriptor);
121 if (!texture) {
122 FML_LOG(ERROR) << "Could not allocate texture.";
123 return nullptr;
124 }
125
126 auto uploaded = texture->SetContents(decompressed_image.GetAllocation());
127 if (!uploaded) {
128 FML_LOG(ERROR) << "Could not upload texture to device memory.";
129 return nullptr;
130 }
131
132 return texture;
133 }

References impeller::DecompressedImage::ConvertToRGBA(), impeller::Allocator::CreateTexture(), impeller::DecompressedImage::kGrey, impeller::kHostVisible, impeller::kR8G8B8A8UNormInt, impeller::DecompressedImage::kRGB, impeller::DecompressedImage::kRGBA, 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.

DEBUG_COMMAND_INFO
#define DEBUG_COMMAND_INFO(obj, arg)
Definition: command.h:31
impeller::scene::GeometryType::kUnskinned
@ kUnskinned
impeller::scene::GeometryType::kLastType
@ kLastType
impeller::scene::MaterialType::kUnlit
@ kUnlit
impeller::ISize
TSize< int64_t > ISize
Definition: size.h:136
impeller::scene::GeometryType::kSkinned
@ kSkinned