Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/angle
Path: blob/main_old/samples/capture_replay/CaptureReplay.cpp
1693 views
1
//
2
// Copyright 2019 The ANGLE Project Authors. All rights reserved.
3
// Use of this source code is governed by a BSD-style license that can be
4
// found in the LICENSE file.
5
//
6
// CaptureReplay: Template for replaying a frame capture with ANGLE.
7
8
#include "SampleApplication.h"
9
10
#include <functional>
11
12
#include "util/frame_capture_test_utils.h"
13
14
// Build the right context header based on replay ID
15
// This will expand to "angle_capture_context<#>.h"
16
#include ANGLE_MACRO_STRINGIZE(ANGLE_CAPTURE_REPLAY_SAMPLE_HEADER)
17
18
// Assign the context numbered functions based on GN arg selecting replay ID
19
std::function<void()> SetupContextReplay = reinterpret_cast<void (*)()>(
20
ANGLE_MACRO_CONCAT(SetupContext,
21
ANGLE_MACRO_CONCAT(ANGLE_CAPTURE_REPLAY_SAMPLE_CONTEXT_ID, Replay)));
22
std::function<void(int)> ReplayContextFrame = reinterpret_cast<void (*)(int)>(
23
ANGLE_MACRO_CONCAT(ReplayContext,
24
ANGLE_MACRO_CONCAT(ANGLE_CAPTURE_REPLAY_SAMPLE_CONTEXT_ID, Frame)));
25
std::function<void()> ResetContextReplay = reinterpret_cast<void (*)()>(
26
ANGLE_MACRO_CONCAT(ResetContext,
27
ANGLE_MACRO_CONCAT(ANGLE_CAPTURE_REPLAY_SAMPLE_CONTEXT_ID, Replay)));
28
29
class CaptureReplaySample : public SampleApplication
30
{
31
public:
32
CaptureReplaySample(int argc, char **argv)
33
: SampleApplication("CaptureReplaySample",
34
argc,
35
argv,
36
3,
37
0,
38
kReplayDrawSurfaceWidth,
39
kReplayDrawSurfaceHeight)
40
{}
41
42
bool initialize() override
43
{
44
// Set CWD to executable directory.
45
std::string exeDir = angle::GetExecutableDirectory();
46
if (!angle::SetCWD(exeDir.c_str()))
47
return false;
48
if (kIsBinaryDataCompressed)
49
{
50
SetBinaryDataDecompressCallback(angle::DecompressBinaryData);
51
}
52
SetBinaryDataDir(ANGLE_CAPTURE_REPLAY_SAMPLE_DATA_DIR);
53
SetupContextReplay();
54
return true;
55
}
56
57
void destroy() override {}
58
59
void draw() override
60
{
61
// Compute the current frame, looping from kReplayFrameStart to kReplayFrameEnd.
62
uint32_t frame =
63
kReplayFrameStart + (mCurrentFrame % ((kReplayFrameEnd - kReplayFrameStart) + 1));
64
if (mPreviousFrame > frame)
65
{
66
ResetContextReplay();
67
}
68
ReplayContextFrame(frame);
69
mPreviousFrame = frame;
70
mCurrentFrame++;
71
}
72
73
private:
74
uint32_t mCurrentFrame = 0;
75
uint32_t mPreviousFrame = 0;
76
};
77
78
int main(int argc, char **argv)
79
{
80
CaptureReplaySample app(argc, argv);
81
return app.run();
82
}
83
84