| 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 27 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 32 of file geometry.cc.

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

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 51 of file geometry.cc.

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

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 38 of file geometry.cc.

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

Referenced by MakeFromFlatbuffer().

## ◆ SetJointsTexture()

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

Reimplemented in impeller::scene::SkinnedVertexBufferGeometry.

Definition at line 122 of file geometry.cc.

122 {}

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:320
impeller::scene::Geometry::MakeVertexBuffer
static std::shared_ptr< Geometry > MakeVertexBuffer(VertexBuffer vertex_buffer, bool is_skinned)
Definition: geometry.cc:38
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:60