-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathScreenCapture.h
More file actions
85 lines (69 loc) · 2.13 KB
/
ScreenCapture.h
File metadata and controls
85 lines (69 loc) · 2.13 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#pragma once
#include "XPLMDataAccess.h"
#include "XPLMGraphics.h"
#include <array>
#include <cstddef>
#include <functional>
#include <string>
#include <vector>
#if IBM
#include <windows.h>
#endif
#if LIN
#include <GL/gl.h>
#elif __GNUC__
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif
namespace vr_image_client
{
struct RawFrame
{
int width{0};
int height{0};
std::vector<unsigned char> rgb;
};
constexpr bool COROP_IMAGE_CAPTURE_TO_SPEED_UP = true;
constexpr bool USE_ASTC_FORMAT = false;
class ScreenCapture
{
public:
using LogCallback = std::function<void(const std::string &)>;
// Change this if you want to support other VR headsets
static constexpr float kMetaQuest3H_FOV = 110.0f;
static constexpr float kMetaQuest3V_FOV = 96.0f;
static constexpr int kBytesPerPixel = 3;
static constexpr int kPboCount = 3;
explicit ScreenCapture(LogCallback log_callback);
void InitializeDataRefs();
void ResetSession();
void ReleaseResources();
void SetScreenSize(int width, int height);
void SetCaptureWidthRatio(float ratio);
float GetCaptureWidthRatio() const { return capture_width_ratio_; }
bool GetCachedScreenSize(int &width, int &height) const;
bool CaptureFrame(RawFrame &out_frame, bool &frame_ready);
bool QueryFieldOfView(float &horizontal_fov, float &vertical_fov) const;
private:
void LogFirstCaptureInfo(int screen_width, int screen_height, int captured_width);
bool EnsureBuffers(int width, int height);
bool ResolveScreenSize(int &width, int &height);
bool TryGetCachedScreenSize(int &width, int &height) const;
LogCallback log_callback_;
bool logged_first_capture_info_{false};
XPLMDataRef horizontal_fov_ref_{nullptr};
XPLMDataRef vertical_fov_ref_{nullptr};
GLuint pbo_ids_[kPboCount]{0};
int pbo_index_{0};
int map_index_{0};
int ready_pbo_count_{0};
std::size_t buffer_size_{0};
int buffer_width_{0};
int buffer_height_{0};
bool buffers_initialized_{false};
int cached_screen_width_{0};
int cached_screen_height_{0};
float capture_width_ratio_{1.0f};
};
} // namespace vr_image_client