Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
FrameCapture.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
3#include "./FrameCapture.hpp"
4
5#include <algorithm>
6
7namespace esengine {
8
10 pass_ = -1;
11 if (!capture_next_) return;
12 capture_next_ = false;
13 records_.clear();
14 entities_.clear();
15 textures_.clear();
16 pass_count_ = 0;
17 has_data_ = false;
18 capturing_ = true;
19}
20
22 if (!capturing_) return;
23 capturing_ = false;
24 has_data_ = !records_.empty();
25 pass_count_ = static_cast<u32>(pass_ + 1);
26}
27
29 ++pass_;
30 pass_kind_ = kind;
31}
32
33void FrameCapture::record(const DrawCommand& cmd, std::span<const Entity> entities) {
34 if (!capturing_) return;
35
37 r.index = static_cast<u32>(records_.size());
38 r.pass = static_cast<u32>(std::max(pass_, 0));
39 r.pass_kind = pass_kind_;
40 r.stage = cmd.stage;
41 r.type = cmd.type;
42 r.blend_mode = cmd.blend_mode;
43 r.texture_id = cmd.texture_count > 0 ? cmd.texture_ids[0] : 0;
45 r.shader_id = cmd.shader_id;
48 r.triangle_count = cmd.index_count / 3 * std::max(cmd.instance_count, 1u);
49 r.layer = cmd.layer;
51 r.scissor = cmd.scissor;
57 r.texture_offset = static_cast<u32>(textures_.size());
58 textures_.insert(textures_.end(), cmd.texture_ids, cmd.texture_ids + cmd.texture_count);
59 r.entity_offset = static_cast<u32>(entities_.size());
60 r.entity_count = static_cast<u32>(entities.size());
61 entities_.insert(entities_.end(), entities.begin(), entities.end());
62 records_.push_back(r);
63}
64
66 return static_cast<u32>(std::count_if(records_.begin(), records_.end(),
67 [pass](const DrawCallRecord& r) { return static_cast<i32>(r.pass) == pass; }));
68}
69
71 replay_mode_ = true;
72 replay_counter_ = 0;
73 replay_limit_ = limit;
74}
75
77 replay_mode_ = false;
78 replay_counter_ = 0;
79 replay_limit_ = -1;
80}
81
82} // namespace esengine
One frame's draw calls as the device received them, for the frame debugger.
void record(const DrawCommand &cmd, std::span< const Entity > entities)
void beginPass(CapturePass kind)
u32 recordsInPass(i32 pass) const
void setReplayMode(i32 limit)
std::int32_t i32
Signed 32-bit integer.
Definition Types.hpp:54
static constexpr u16 CMD_STATE_SCISSOR
std::uint32_t u32
Unsigned 32-bit integer.
Definition Types.hpp:45
static constexpr u16 CMD_STATE_STENCIL_WRITE
static constexpr u16 CMD_STATE_STENCIL_TEST
BatchBreak break_reason
Why this draw call started.
u32 texture_ids[MAX_CMD_TEXTURE_SLOTS]