forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mesh.cc
53 lines (43 loc) · 1.32 KB
/
mesh.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "impeller/scene/mesh.h"
#include <memory>
#include <optional>
#include "impeller/base/validation.h"
#include "impeller/scene/material.h"
#include "impeller/scene/pipeline_key.h"
#include "impeller/scene/scene_encoder.h"
namespace impeller {
namespace scene {
Mesh::Mesh() = default;
Mesh::~Mesh() = default;
void Mesh::AddPrimitive(Primitive mesh) {
if (mesh.geometry == nullptr) {
VALIDATION_LOG << "Mesh geometry cannot be null.";
}
if (mesh.material == nullptr) {
VALIDATION_LOG << "Mesh material cannot be null.";
}
primitives_.push_back(std::move(mesh));
}
std::vector<Mesh::Primitive>& Mesh::GetPrimitives() {
return primitives_;
}
bool Mesh::Render(SceneEncoder& encoder,
const Matrix& transform,
const std::shared_ptr<Texture>& joints) const {
for (const auto& mesh : primitives_) {
mesh.geometry->SetJointsTexture(joints);
SceneCommand command = {
.label = "Mesh Primitive",
.transform = transform,
.geometry = mesh.geometry.get(),
.material = mesh.material.get(),
};
encoder.Add(command);
}
return true;
}
} // namespace scene
} // namespace impeller