| 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/renderer/render_pass.h"
19 #include "impeller/scene/importer/scene_flatbuffers.h"
20 #include "impeller/scene/pipeline_key.h"
21 #include "impeller/scene/scene_context.h"
22
23 namespace impeller {
24 namespace scene {
25
26 class CuboidGeometry;
27 class UnskinnedVertexBufferGeometry;
28
29 class Geometry {
30 public:
31 virtual ~Geometry();
32
33 static std::shared_ptr<CuboidGeometry> MakeCuboid(Vector3 size);
34
35 static std::shared_ptr<Geometry> MakeVertexBuffer(VertexBuffer vertex_buffer,
36 bool is_skinned);
37
38 static std::shared_ptr<Geometry> MakeFromFlatbuffer(
39 const fb::MeshPrimitive& mesh,
40 Allocator& allocator);
41
42 virtual GeometryType GetGeometryType() const = 0;
43
44 virtual VertexBuffer GetVertexBuffer(Allocator& allocator) const = 0;
45
46 virtual void BindToCommand(const SceneContext& scene_context,
47 HostBuffer& buffer,
48 const Matrix& transform,
49 RenderPass& pass) const = 0;
50
51 virtual void SetJointsTexture(const std::shared_ptr<Texture>& texture);
52 };
53
54 class CuboidGeometry final : public Geometry {
55 public:
56 CuboidGeometry();
57
58 ~CuboidGeometry() override;
59
60 void SetSize(Vector3 size);
61
62 // |Geometry|
63 GeometryType GetGeometryType() const override;
64
65 // |Geometry|
66 VertexBuffer GetVertexBuffer(Allocator& allocator) const override;
67
68 // |Geometry|
69 void BindToCommand(const SceneContext& scene_context,
70 HostBuffer& buffer,
71 const Matrix& transform,
72 RenderPass& pass) const override;
73
74 private:
75 Vector3 size_;
76
77 CuboidGeometry(const CuboidGeometry&) = delete;
78
79 CuboidGeometry& operator=(const CuboidGeometry&) = delete;
80 };
81
82 class UnskinnedVertexBufferGeometry final : public Geometry {
83 public:
84 UnskinnedVertexBufferGeometry();
85
86 ~UnskinnedVertexBufferGeometry() override;
87
88 void SetVertexBuffer(VertexBuffer vertex_buffer);
89
90 // |Geometry|
91 GeometryType GetGeometryType() const override;
92
93 // |Geometry|
94 VertexBuffer GetVertexBuffer(Allocator& allocator) const override;
95
96 // |Geometry|
97 void BindToCommand(const SceneContext& scene_context,
98 HostBuffer& buffer,
99 const Matrix& transform,
100 RenderPass& pass) const override;
101
102 private:
103 VertexBuffer vertex_buffer_;
104
105 UnskinnedVertexBufferGeometry(const UnskinnedVertexBufferGeometry&) = delete;
106
107 UnskinnedVertexBufferGeometry& operator=(
108 const UnskinnedVertexBufferGeometry&) = delete;
109 };
110
111 class SkinnedVertexBufferGeometry final : public Geometry {
112 public:
113 SkinnedVertexBufferGeometry();
114
115 ~SkinnedVertexBufferGeometry() override;
116
117 void SetVertexBuffer(VertexBuffer vertex_buffer);
118
119 // |Geometry|
120 GeometryType GetGeometryType() const override;
121
122 // |Geometry|
123 VertexBuffer GetVertexBuffer(Allocator& allocator) const override;
124
125 // |Geometry|
126 void BindToCommand(const SceneContext& scene_context,
127 HostBuffer& buffer,
128 const Matrix& transform,
129 RenderPass& pass) const override;
130
131 // |Geometry|
132 void SetJointsTexture(const std::shared_ptr<Texture>& texture) override;
133
134 private:
135 VertexBuffer vertex_buffer_;
136 std::shared_ptr<Texture> joints_texture_;
137
138 SkinnedVertexBufferGeometry(const SkinnedVertexBufferGeometry&) = delete;
139
140 SkinnedVertexBufferGeometry& operator=(const SkinnedVertexBufferGeometry&) =
141 delete;
142 };
143
144 } // namespace scene
145 } // namespace impeller
146
147 #endif // FLUTTER_IMPELLER_SCENE_GEOMETRY_H_
impeller::scene::SkinnedVertexBufferGeometry::BindToCommand
void BindToCommand(const SceneContext &scene_context, HostBuffer &buffer, const Matrix &transform, RenderPass &pass) const override
Definition: geometry.cc:237
impeller::scene::CuboidGeometry
Definition: geometry.h:54
impeller::scene::SkinnedVertexBufferGeometry::~SkinnedVertexBufferGeometry
~SkinnedVertexBufferGeometry() override
impeller::scene::Geometry::SetJointsTexture
virtual void SetJointsTexture(const std::shared_ptr< Texture > &texture)
Definition: geometry.cc:121
pipeline_key.h
host_buffer.h
scene_context.h
impeller::scene::SkinnedVertexBufferGeometry
Definition: geometry.h:111
impeller::scene::Geometry::MakeCuboid
static std::shared_ptr< CuboidGeometry > MakeCuboid(Vector3 size)
Definition: geometry.cc:31
vertex_buffer.h
device_buffer.h
impeller::HostBuffer
Definition: host_buffer.h:28
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:189
impeller::scene::CuboidGeometry::~CuboidGeometry
~CuboidGeometry() override
impeller::scene::CuboidGeometry::GetGeometryType
GeometryType GetGeometryType() const override
Definition: geometry.cc:136
impeller::scene::UnskinnedVertexBufferGeometry::GetVertexBuffer
VertexBuffer GetVertexBuffer(Allocator &allocator) const override
Definition: geometry.cc:194
impeller::scene::SceneContext
Definition: scene_context.h:41
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:226
impeller::scene::SkinnedVertexBufferGeometry::GetVertexBuffer
VertexBuffer GetVertexBuffer(Allocator &allocator) const override
Definition: geometry.cc:231
render_pass.h
impeller::scene::UnskinnedVertexBufferGeometry::SetVertexBuffer
void SetVertexBuffer(VertexBuffer vertex_buffer)
Definition: geometry.cc:183
impeller::scene::Geometry::~Geometry
virtual ~Geometry()
impeller::scene::CuboidGeometry::BindToCommand
void BindToCommand(const SceneContext &scene_context, HostBuffer &buffer, const Matrix &transform, RenderPass &pass) const override
Definition: geometry.cc:163
impeller::scene::UnskinnedVertexBufferGeometry
Definition: geometry.h:82
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:50
impeller::scene::Geometry::MakeVertexBuffer
static std::shared_ptr< Geometry > MakeVertexBuffer(VertexBuffer vertex_buffer, bool is_skinned)
Definition: geometry.cc:37
impeller::scene::UnskinnedVertexBufferGeometry::~UnskinnedVertexBufferGeometry
~UnskinnedVertexBufferGeometry() override
impeller::scene::Geometry
Definition: geometry.h:29
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:33
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:221
impeller::scene::UnskinnedVertexBufferGeometry::BindToCommand
void BindToCommand(const SceneContext &scene_context, HostBuffer &buffer, const Matrix &transform, RenderPass &pass) const override
Definition: geometry.cc:200
impeller::scene::CuboidGeometry::GetVertexBuffer
VertexBuffer GetVertexBuffer(Allocator &allocator) const override
Definition: geometry.cc:141
impeller::scene::SkinnedVertexBufferGeometry::SetJointsTexture
void SetJointsTexture(const std::shared_ptr< Texture > &texture) override
Definition: geometry.cc:267
impeller::scene::Geometry::BindToCommand
virtual void BindToCommand(const SceneContext &scene_context, HostBuffer &buffer, const Matrix &transform, RenderPass &pass) const =0
impeller
Definition: aiks_blur_unittests.cc:20
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:131
impeller::scene::Geometry::GetGeometryType
virtual GeometryType GetGeometryType() const =0