forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scene.cc
66 lines (51 loc) · 1.69 KB
/
scene.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
54
55
56
57
58
59
60
61
62
63
64
65
66
// 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/scene.h"
#include <memory>
#include <utility>
#include "flutter/fml/logging.h"
#include "impeller/renderer/render_target.h"
#include "impeller/scene/scene_context.h"
#include "impeller/scene/scene_encoder.h"
namespace impeller {
namespace scene {
Scene::Scene(std::shared_ptr<SceneContext> scene_context)
: scene_context_(std::move(scene_context)) {
root_.is_root_ = true;
};
Scene::~Scene() {
for (auto& child : GetRoot().GetChildren()) {
child->parent_ = nullptr;
}
}
Node& Scene::GetRoot() {
return root_;
}
bool Scene::Render(const RenderTarget& render_target,
const Matrix& camera_transform) {
// Collect the render commands from the scene.
SceneEncoder encoder;
if (!root_.Render(encoder,
*scene_context_->GetContext()->GetResourceAllocator(),
Matrix())) {
FML_LOG(ERROR) << "Failed to render frame.";
return false;
}
// Encode the commands.
std::shared_ptr<CommandBuffer> command_buffer =
encoder.BuildSceneCommandBuffer(*scene_context_, camera_transform,
render_target);
// TODO(bdero): Do post processing.
if (!command_buffer->SubmitCommands()) {
FML_LOG(ERROR) << "Failed to submit command buffer.";
return false;
}
return true;
}
bool Scene::Render(const RenderTarget& render_target, const Camera& camera) {
return Render(render_target,
camera.GetTransform(render_target.GetRenderTargetSize()));
}
} // namespace scene
} // namespace impeller