| Flutter Impeller |

geometry.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef FLUTTER_IMPELLER_SCENE_GEOMETRY_H_
6 #define FLUTTER_IMPELLER_SCENE_GEOMETRY_H_
7
8 #include <memory>
9
10 #include "flutter/fml/macros.h"
11 #include "impeller/core/allocator.h"
12 #include "impeller/core/device_buffer.h"
13 #include "impeller/core/host_buffer.h"
14 #include "impeller/core/vertex_buffer.h"
15 #include "impeller/geometry/matrix.h"
16 #include "impeller/geometry/vector.h"
17 #include "impeller/renderer/command.h"
18 #include "impeller/scene/importer/scene_flatbuffers.h"
19 #include "impeller/scene/pipeline_key.h"
20 #include "impeller/scene/scene_context.h"
21
22 namespace impeller {
23 namespace scene {
24
25 class CuboidGeometry;
26 class UnskinnedVertexBufferGeometry;
27
28 class Geometry {
29 public:
30 virtual ~Geometry();
31
32 static std::shared_ptr<CuboidGeometry> MakeCuboid(Vector3 size);
33
34 static std::shared_ptr<Geometry> MakeVertexBuffer(VertexBuffer vertex_buffer,
35 bool is_skinned);
36
37 static std::shared_ptr<Geometry> MakeFromFlatbuffer(
38 const fb::MeshPrimitive& mesh,
39 Allocator& allocator);
40
41 virtual GeometryType GetGeometryType() const = 0;
42
43 virtual VertexBuffer GetVertexBuffer(Allocator& allocator) const = 0;
44
45 virtual void BindToCommand(const SceneContext& scene_context,
46 HostBuffer& buffer,
47 const Matrix& transform,
48 Command& command) const = 0;
49
50 virtual void SetJointsTexture(const std::shared_ptr<Texture>& texture);
51 };
52
53 class CuboidGeometry final : public Geometry {
54 public:
55 CuboidGeometry();
56
57 ~CuboidGeometry() override;
58
59 void SetSize(Vector3 size);
60
61 // |Geometry|
62 GeometryType GetGeometryType() const override;
63
64 // |Geometry|
65 VertexBuffer GetVertexBuffer(Allocator& allocator) const override;
66
67 // |Geometry|
68 void BindToCommand(const SceneContext& scene_context,
69 HostBuffer& buffer,
70 const Matrix& transform,
71 Command& command) const override;
72
73 private:
74 Vector3 size_;
75
76 CuboidGeometry(const CuboidGeometry&) = delete;
77
78 CuboidGeometry& operator=(const CuboidGeometry&) = delete;
79 };
80
81 class UnskinnedVertexBufferGeometry final : public Geometry {
82 public:
83 UnskinnedVertexBufferGeometry();
84
85 ~UnskinnedVertexBufferGeometry() override;
86
87 void SetVertexBuffer(VertexBuffer vertex_buffer);
88
89 // |Geometry|
90 GeometryType GetGeometryType() const override;
91
92 // |Geometry|
93 VertexBuffer GetVertexBuffer(Allocator& allocator) const override;
94
95 // |Geometry|
96 void BindToCommand(const SceneContext& scene_context,
97 HostBuffer& buffer,
98 const Matrix& transform,
99 Command& command) const override;
100
101 private:
102 VertexBuffer vertex_buffer_;
103
104 UnskinnedVertexBufferGeometry(const UnskinnedVertexBufferGeometry&) = delete;
105
106 UnskinnedVertexBufferGeometry& operator=(
107 const UnskinnedVertexBufferGeometry&) = delete;
108 };
109
110 class SkinnedVertexBufferGeometry final : public Geometry {
111 public:
112 SkinnedVertexBufferGeometry();
113
114 ~SkinnedVertexBufferGeometry() override;
115
116 void SetVertexBuffer(VertexBuffer vertex_buffer);
117
118 // |Geometry|
119 GeometryType GetGeometryType() const override;
120
121 // |Geometry|
122 VertexBuffer GetVertexBuffer(Allocator& allocator) const override;
123
124 // |Geometry|
125 void BindToCommand(const SceneContext& scene_context,
126 HostBuffer& buffer,
127 const Matrix& transform,
128 Command& command) const override;
129
130 // |Geometry|
131 void SetJointsTexture(const std::shared_ptr<Texture>& texture) override;
132
133 private:
134 VertexBuffer vertex_buffer_;
135 std::shared_ptr<Texture> joints_texture_;
136
137 SkinnedVertexBufferGeometry(const SkinnedVertexBufferGeometry&) = delete;
138
139 SkinnedVertexBufferGeometry& operator=(const SkinnedVertexBufferGeometry&) =
140 delete;
141 };
142
143 } // namespace scene
144 } // namespace impeller
145
146 #endif // FLUTTER_IMPELLER_SCENE_GEOMETRY_H_
impeller::scene::CuboidGeometry
Definition: geometry.h:53
impeller::scene::SkinnedVertexBufferGeometry::~SkinnedVertexBufferGeometry
~SkinnedVertexBufferGeometry() override
impeller::scene::Geometry::SetJointsTexture
virtual void SetJointsTexture(const std::shared_ptr< Texture > &texture)
Definition: geometry.cc:120
impeller::Command
An object used to specify work to the GPU along with references to resources the GPU will used when d...
Definition: command.h:92
pipeline_key.h
host_buffer.h
scene_context.h
impeller::scene::SkinnedVertexBufferGeometry
Definition: geometry.h:110
impeller::scene::Geometry::MakeCuboid
static std::shared_ptr< CuboidGeometry > MakeCuboid(Vector3 size)
Definition: geometry.cc:30
vertex_buffer.h
device_buffer.h
impeller::scene::CuboidGeometry::BindToCommand
void BindToCommand(const SceneContext &scene_context, HostBuffer &buffer, const Matrix &transform, Command &command) const override
Definition: geometry.cc:162
impeller::HostBuffer
Definition: host_buffer.h:20
impeller::VertexBuffer
Definition: vertex_buffer.h:13
impeller::scene::UnskinnedVertexBufferGeometry::UnskinnedVertexBufferGeometry
UnskinnedVertexBufferGeometry()
impeller::scene::SkinnedVertexBufferGeometry::SkinnedVertexBufferGeometry
SkinnedVertexBufferGeometry()
impeller::scene::UnskinnedVertexBufferGeometry::GetGeometryType
GeometryType GetGeometryType() const override
Definition: geometry.cc:188
impeller::scene::CuboidGeometry::~CuboidGeometry
~CuboidGeometry() override
impeller::scene::CuboidGeometry::GetGeometryType
GeometryType GetGeometryType() const override
Definition: geometry.cc:135
impeller::scene::UnskinnedVertexBufferGeometry::GetVertexBuffer
VertexBuffer GetVertexBuffer(Allocator &allocator) const override
Definition: geometry.cc:193
impeller::scene::SceneContext
Definition: scene_context.h:40
impeller::scene::Geometry::GetVertexBuffer
virtual VertexBuffer GetVertexBuffer(Allocator &allocator) const =0
matrix.h
command.h
impeller::scene::SkinnedVertexBufferGeometry::GetGeometryType
GeometryType GetGeometryType() const override
Definition: geometry.cc:225
impeller::scene::SkinnedVertexBufferGeometry::GetVertexBuffer
VertexBuffer GetVertexBuffer(Allocator &allocator) const override
Definition: geometry.cc:230
impeller::scene::SkinnedVertexBufferGeometry::BindToCommand
void BindToCommand(const SceneContext &scene_context, HostBuffer &buffer, const Matrix &transform, Command &command) const override
Definition: geometry.cc:236
impeller::scene::UnskinnedVertexBufferGeometry::BindToCommand
void BindToCommand(const SceneContext &scene_context, HostBuffer &buffer, const Matrix &transform, Command &command) const override
Definition: geometry.cc:199
impeller::scene::UnskinnedVertexBufferGeometry::SetVertexBuffer
void SetVertexBuffer(VertexBuffer vertex_buffer)
Definition: geometry.cc:182
impeller::scene::Geometry::~Geometry
virtual ~Geometry()
impeller::scene::UnskinnedVertexBufferGeometry
Definition: geometry.h:81
impeller::Allocator
An object that allocates device memory.
Definition: allocator.h:22
impeller::scene::Geometry::MakeFromFlatbuffer
static std::shared_ptr< Geometry > MakeFromFlatbuffer(const fb::MeshPrimitive &mesh, Allocator &allocator)
Definition: geometry.cc:49
impeller::scene::Geometry::MakeVertexBuffer
static std::shared_ptr< Geometry > MakeVertexBuffer(VertexBuffer vertex_buffer, bool is_skinned)
Definition: geometry.cc:36
impeller::scene::UnskinnedVertexBufferGeometry::~UnskinnedVertexBufferGeometry
~UnskinnedVertexBufferGeometry() override
impeller::scene::Geometry
Definition: geometry.h:28
allocator.h
impeller::scene::GeometryType
GeometryType
Definition: pipeline_key.h:13
impeller::scene::CuboidGeometry::CuboidGeometry
CuboidGeometry()
vector.h
impeller::scene::SkinnedVertexBufferGeometry::SetVertexBuffer
void SetVertexBuffer(VertexBuffer vertex_buffer)
Definition: geometry.cc:220
impeller::scene::Geometry::BindToCommand
virtual void BindToCommand(const SceneContext &scene_context, HostBuffer &buffer, const Matrix &transform, Command &command) const =0
impeller::scene::CuboidGeometry::GetVertexBuffer
VertexBuffer GetVertexBuffer(Allocator &allocator) const override
Definition: geometry.cc:140
impeller::scene::SkinnedVertexBufferGeometry::SetJointsTexture
void SetJointsTexture(const std::shared_ptr< Texture > &texture) override
Definition: geometry.cc:266
impeller
Definition: aiks_context.cc:10
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::Vector3
Definition: vector.h:20
impeller::scene::CuboidGeometry::SetSize
void SetSize(Vector3 size)
Definition: geometry.cc:130
impeller::scene::Geometry::GetGeometryType
virtual GeometryType GetGeometryType() const =0