| Flutter Impeller |

Public Member Functions | Static Public Member Functions | List of all members
impeller::scene::Geometry Class Referenceabstract

`#include <geometry.h>`

Inheritance diagram for impeller::scene::Geometry:

## Public Member Functions
virtual | ~Geometry ()
virtual GeometryType | GetGeometryType () const =0
virtual VertexBuffer | GetVertexBuffer (Allocator &allocator) const =0
virtual void | BindToCommand (const SceneContext &scene_context, HostBuffer &buffer, const Matrix &transform, Command &command) const =0
virtual void | SetJointsTexture (const std::shared_ptr< Texture > &texture)

## Static Public Member Functions
static std::shared_ptr< CuboidGeometry > | MakeCuboid (Vector3 size)
static std::shared_ptr< Geometry > | MakeVertexBuffer (VertexBuffer vertex_buffer, bool is_skinned)
static std::shared_ptr< Geometry > | MakeFromFlatbuffer (const fb::MeshPrimitive &mesh, Allocator &allocator)

## Detailed Description

Definition at line 28 of file geometry.h.

## Constructor & Destructor Documentation

## ◆ ~Geometry()

impeller::scene::Geometry::~Geometry | ( |  | ) |
| virtual default

Geometry

## Member Function Documentation

## ◆ BindToCommand()

virtual void impeller::scene::Geometry::BindToCommand | ( | const SceneContext & | scene_context,
|  | HostBuffer & | buffer,
|  | const Matrix & | transform,
|  | Command & | command
| ) |  | const
| pure virtual

Implemented in impeller::scene::SkinnedVertexBufferGeometry, impeller::scene::UnskinnedVertexBufferGeometry, and impeller::scene::CuboidGeometry.

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

## ◆ GetGeometryType()

virtual GeometryType impeller::scene::Geometry::GetGeometryType | ( |  | ) | const
| pure virtual

Implemented in impeller::scene::SkinnedVertexBufferGeometry, impeller::scene::UnskinnedVertexBufferGeometry, and impeller::scene::CuboidGeometry.

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

## ◆ GetVertexBuffer()

virtual VertexBuffer impeller::scene::Geometry::GetVertexBuffer | ( | Allocator & | allocator | ) | const
| pure virtual

Implemented in impeller::scene::SkinnedVertexBufferGeometry, impeller::scene::UnskinnedVertexBufferGeometry, and impeller::scene::CuboidGeometry.

## ◆ MakeCuboid()

std::shared_ptr< CuboidGeometry > impeller::scene::Geometry::MakeCuboid | ( | Vector3 | size | ) |
| static

Definition at line 30 of file geometry.cc.

30 {
31 auto result = std::make_shared<CuboidGeometry>();
32 result->SetSize(size);
33 return result;
34 }

Referenced by impeller::scene::testing::TEST_P().

## ◆ MakeFromFlatbuffer()

std::shared_ptr< Geometry > impeller::scene::Geometry::MakeFromFlatbuffer | ( | const fb::MeshPrimitive & | mesh,
|  | Allocator & | allocator
| ) |  |
| static

Definition at line 49 of file geometry.cc.

51 {
52 IndexType index_type;
53 switch (mesh.indices()->type()) {
54 case fb::IndexType::k16Bit:
55 index_type = IndexType::k16bit;
56 break;
57 case fb::IndexType::k32Bit:
58 index_type = IndexType::k32bit;
59 break;
60 }
61
62 const uint8_t* vertices_start;
63 size_t vertices_bytes;
64 bool is_skinned;
65
66 switch (mesh.vertices_type()) {
67 case fb::VertexBuffer::UnskinnedVertexBuffer: {
68 const auto* vertices =
69 mesh.vertices_as_UnskinnedVertexBuffer()->vertices();
70 vertices_start = reinterpret_cast<const uint8_t*>(vertices->Get(0));
71 vertices_bytes = vertices->size() * sizeof(fb::Vertex);
72 is_skinned = false;
73 break;
74 }
75 case fb::VertexBuffer::SkinnedVertexBuffer: {
76 const auto* vertices = mesh.vertices_as_SkinnedVertexBuffer()->vertices();
77 vertices_start = reinterpret_cast<const uint8_t*>(vertices->Get(0));
78 vertices_bytes = vertices->size() * sizeof(fb::SkinnedVertex);
79 is_skinned = true;
80 break;
81 }
82 case fb::VertexBuffer::NONE:
83 VALIDATION_LOG << "Invalid vertex buffer type.";
84 return nullptr;
85 }
86
87 const uint8_t* indices_start =
88 reinterpret_cast<const uint8_t*>(mesh.indices()->data()->Data());
89
90 const size_t indices_bytes = mesh.indices()->data()->size();
91 if (vertices_bytes == 0 || indices_bytes == 0) {
92 return nullptr;
93 }
94
95 DeviceBufferDescriptor buffer_desc;
96 buffer_desc.size = vertices_bytes + indices_bytes;
97 buffer_desc.storage_mode = StorageMode::kHostVisible;
98
99 auto buffer = allocator.CreateBuffer(buffer_desc);
100 buffer->SetLabel("Mesh vertices+indices");
101
102 if (!buffer->CopyHostBuffer(vertices_start, Range(0, vertices_bytes))) {
103 return nullptr;
104 }
105 if (!buffer->CopyHostBuffer(indices_start, Range(0, indices_bytes),
106 vertices_bytes)) {
107 return nullptr;
108 }
109
110 VertexBuffer vertex_buffer = {
111 .vertex_buffer = {.buffer = buffer, .range = Range(0, vertices_bytes)},
112 .index_buffer = {.buffer = buffer,
113 .range = Range(vertices_bytes, indices_bytes)},
114 .vertex_count = mesh.indices()->count(),
115 .index_type = index_type,
116 };
117 return MakeVertexBuffer(std::move(vertex_buffer), is_skinned);
118 }

References impeller::BufferView::buffer, impeller::Allocator::CreateBuffer(), impeller::k16bit, impeller::k32bit, impeller::kHostVisible, MakeVertexBuffer(), impeller::DeviceBufferDescriptor::size, impeller::DeviceBufferDescriptor::storage_mode, VALIDATION_LOG, and impeller::VertexBuffer::vertex_buffer.

## ◆ MakeVertexBuffer()

std::shared_ptr< Geometry > impeller::scene::Geometry::MakeVertexBuffer | ( | VertexBuffer | vertex_buffer,
|  | bool | is_skinned
| ) |  |
| static

Definition at line 36 of file geometry.cc.

37 {
38 if (is_skinned) {
39 auto result = std::make_shared<SkinnedVertexBufferGeometry>();
40 result->SetVertexBuffer(std::move(vertex_buffer));
41 return result;
42 } else {
43 auto result = std::make_shared<UnskinnedVertexBufferGeometry>();
44 result->SetVertexBuffer(std::move(vertex_buffer));
45 return result;
46 }
47 }

Referenced by MakeFromFlatbuffer().

## ◆ SetJointsTexture()

void impeller::scene::Geometry::SetJointsTexture | ( | const std::shared_ptr< Texture > & | texture | ) |
| virtual

Reimplemented in impeller::scene::SkinnedVertexBufferGeometry.

Definition at line 120 of file geometry.cc.

120 {}

The documentation for this class was generated from the following files:

- impeller/scene/geometry.h
- impeller/scene/geometry.cc

impeller::IndexType::k16bit
@ k16bit
impeller::IndexType::k32bit
@ k32bit
impeller::StorageMode::kHostVisible
@ kHostVisible
impeller::IndexType
IndexType
Definition: formats.h:341
impeller::scene::Geometry::MakeVertexBuffer
static std::shared_ptr< Geometry > MakeVertexBuffer(VertexBuffer vertex_buffer, bool is_skinned)
Definition: geometry.cc:36
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:67