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
7
namespace
esengine
{
8
9
void
FrameCapture::beginFrame
() {
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
21
void
FrameCapture::endFrame
() {
22
if
(!capturing_)
return
;
23
capturing_ =
false
;
24
has_data_ = !records_.empty();
25
pass_count_ =
static_cast<
u32
>
(pass_ + 1);
26
}
27
28
void
FrameCapture::beginPass
(
CapturePass
kind) {
29
++pass_;
30
pass_kind_ = kind;
31
}
32
33
void
FrameCapture::record
(
const
DrawCommand
& cmd, std::span<const Entity> entities) {
34
if
(!capturing_)
return
;
35
36
DrawCallRecord
r;
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;
44
r.
material_id
= cmd.
material_id
;
45
r.
shader_id
= cmd.
shader_id
;
46
r.
index_count
= cmd.
index_count
;
47
r.
instance_count
= cmd.
instance_count
;
48
r.
triangle_count
= cmd.
index_count
/ 3 * std::max(cmd.
instance_count
, 1u);
49
r.
layer
= cmd.
layer
;
50
r.
break_reason
= cmd.
break_reason
;
51
r.
scissor
= cmd.
scissor
;
52
r.
scissor_enabled
= (cmd.
state_flags
&
CMD_STATE_SCISSOR
) != 0;
53
r.
stencil_write
= (cmd.
state_flags
&
CMD_STATE_STENCIL_WRITE
) != 0;
54
r.
stencil_test
= (cmd.
state_flags
&
CMD_STATE_STENCIL_TEST
) != 0;
55
r.
stencil_ref
= cmd.
stencil_ref
;
56
r.
texture_slot_usage
= cmd.
texture_count
;
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
65
u32
FrameCapture::recordsInPass
(
i32
pass)
const
{
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
70
void
FrameCapture::setReplayMode
(
i32
limit) {
71
replay_mode_ =
true
;
72
replay_counter_ = 0;
73
replay_limit_ = limit;
74
}
75
76
void
FrameCapture::clearReplayMode
() {
77
replay_mode_ =
false
;
78
replay_counter_ = 0;
79
replay_limit_ = -1;
80
}
81
82
}
// namespace esengine
FrameCapture.hpp
One frame's draw calls as the device received them, for the frame debugger.
esengine::FrameCapture::record
void record(const DrawCommand &cmd, std::span< const Entity > entities)
Definition
FrameCapture.cpp:33
esengine::FrameCapture::beginPass
void beginPass(CapturePass kind)
Definition
FrameCapture.cpp:28
esengine::FrameCapture::endFrame
void endFrame()
Definition
FrameCapture.cpp:21
esengine::FrameCapture::beginFrame
void beginFrame()
Definition
FrameCapture.cpp:9
esengine::FrameCapture::clearReplayMode
void clearReplayMode()
Definition
FrameCapture.cpp:76
esengine::FrameCapture::recordsInPass
u32 recordsInPass(i32 pass) const
Definition
FrameCapture.cpp:65
esengine::FrameCapture::setReplayMode
void setReplayMode(i32 limit)
Definition
FrameCapture.cpp:70
esengine
Definition
EasingFunctions.hpp:10
esengine::i32
std::int32_t i32
Signed 32-bit integer.
Definition
Types.hpp:54
esengine::CMD_STATE_SCISSOR
static constexpr u16 CMD_STATE_SCISSOR
Definition
DrawCommand.hpp:22
esengine::u32
std::uint32_t u32
Unsigned 32-bit integer.
Definition
Types.hpp:45
esengine::CapturePass
CapturePass
Definition
FrameCapture.hpp:22
esengine::CMD_STATE_STENCIL_WRITE
static constexpr u16 CMD_STATE_STENCIL_WRITE
Definition
DrawCommand.hpp:23
esengine::CMD_STATE_STENCIL_TEST
static constexpr u16 CMD_STATE_STENCIL_TEST
Definition
DrawCommand.hpp:28
esengine::DrawCallRecord
Definition
FrameCapture.hpp:27
esengine::DrawCallRecord::stencil_test
bool stencil_test
Definition
FrameCapture.hpp:46
esengine::DrawCallRecord::stencil_write
bool stencil_write
Definition
FrameCapture.hpp:45
esengine::DrawCallRecord::index
u32 index
Definition
FrameCapture.hpp:28
esengine::DrawCallRecord::stencil_ref
i32 stencil_ref
Definition
FrameCapture.hpp:47
esengine::DrawCallRecord::type
RenderType type
Definition
FrameCapture.hpp:31
esengine::DrawCallRecord::texture_id
u32 texture_id
Definition
FrameCapture.hpp:34
esengine::DrawCallRecord::pass_kind
CapturePass pass_kind
Definition
FrameCapture.hpp:33
esengine::DrawCallRecord::material_id
u32 material_id
Definition
FrameCapture.hpp:35
esengine::DrawCallRecord::instance_count
u32 instance_count
Definition
FrameCapture.hpp:49
esengine::DrawCallRecord::entity_count
u32 entity_count
Definition
FrameCapture.hpp:39
esengine::DrawCallRecord::break_reason
BatchBreak break_reason
Definition
FrameCapture.hpp:42
esengine::DrawCallRecord::pass
u32 pass
Definition
FrameCapture.hpp:29
esengine::DrawCallRecord::scissor
ScissorRect scissor
Definition
FrameCapture.hpp:43
esengine::DrawCallRecord::triangle_count
u32 triangle_count
Definition
FrameCapture.hpp:38
esengine::DrawCallRecord::texture_slot_usage
u8 texture_slot_usage
Definition
FrameCapture.hpp:48
esengine::DrawCallRecord::texture_offset
u32 texture_offset
Definition
FrameCapture.hpp:52
esengine::DrawCallRecord::index_count
u32 index_count
Definition
FrameCapture.hpp:37
esengine::DrawCallRecord::scissor_enabled
bool scissor_enabled
Definition
FrameCapture.hpp:44
esengine::DrawCallRecord::layer
i32 layer
Definition
FrameCapture.hpp:41
esengine::DrawCallRecord::blend_mode
BlendMode blend_mode
Definition
FrameCapture.hpp:32
esengine::DrawCallRecord::stage
RenderStage stage
Definition
FrameCapture.hpp:30
esengine::DrawCallRecord::shader_id
u32 shader_id
Definition
FrameCapture.hpp:36
esengine::DrawCallRecord::entity_offset
u32 entity_offset
Definition
FrameCapture.hpp:40
esengine::DrawCommand
Definition
DrawCommand.hpp:99
esengine::DrawCommand::layer
i32 layer
Definition
DrawCommand.hpp:139
esengine::DrawCommand::material_id
u32 material_id
Definition
DrawCommand.hpp:115
esengine::DrawCommand::texture_count
u8 texture_count
Definition
DrawCommand.hpp:125
esengine::DrawCommand::scissor
ScissorRect scissor
Definition
DrawCommand.hpp:129
esengine::DrawCommand::stage
RenderStage stage
Definition
DrawCommand.hpp:138
esengine::DrawCommand::break_reason
BatchBreak break_reason
Why this draw call started.
Definition
DrawCommand.hpp:123
esengine::DrawCommand::stencil_ref
i32 stencil_ref
Definition
DrawCommand.hpp:130
esengine::DrawCommand::texture_ids
u32 texture_ids[MAX_CMD_TEXTURE_SLOTS]
Definition
DrawCommand.hpp:126
esengine::DrawCommand::instance_count
u32 instance_count
Definition
DrawCommand.hpp:147
esengine::DrawCommand::state_flags
u16 state_flags
Definition
DrawCommand.hpp:128
esengine::DrawCommand::shader_id
u32 shader_id
Definition
DrawCommand.hpp:106
esengine::DrawCommand::type
RenderType type
Definition
DrawCommand.hpp:134
esengine::DrawCommand::blend_mode
BlendMode blend_mode
Definition
DrawCommand.hpp:110
esengine::DrawCommand::index_count
u32 index_count
Definition
DrawCommand.hpp:103
src
esengine
renderer
frame
FrameCapture.cpp
Generated by
1.15.0