| 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, RenderPass &pass) 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 29 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,
|  | RenderPass & | pass
| ) |  | 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.

## ◆ 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 31 of file geometry.cc.

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

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

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

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

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

Referenced by MakeFromFlatbuffer().

## ◆ SetJointsTexture()

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

Reimplemented in impeller::scene::SkinnedVertexBufferGeometry.

Definition at line 121 of file geometry.cc.

121 {}

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