Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/servers/camera_server.h
9887 views
1
/**************************************************************************/
2
/* camera_server.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#pragma once
32
33
#include "core/object/class_db.h"
34
#include "core/object/ref_counted.h"
35
#include "core/os/thread_safe.h"
36
#include "core/templates/rid.h"
37
#include "core/variant/variant.h"
38
39
/**
40
The camera server is a singleton object that gives access to the various
41
camera feeds that can be used as the background for our environment.
42
**/
43
44
class CameraFeed;
45
template <typename T>
46
class TypedArray;
47
48
class CameraServer : public Object {
49
GDCLASS(CameraServer, Object);
50
_THREAD_SAFE_CLASS_
51
52
public:
53
enum FeedImage {
54
FEED_RGBA_IMAGE = 0,
55
FEED_YCBCR_IMAGE = 0,
56
FEED_Y_IMAGE = 0,
57
FEED_CBCR_IMAGE = 1,
58
FEED_IMAGES = 2
59
};
60
61
typedef CameraServer *(*CreateFunc)();
62
static inline constexpr const char feeds_updated_signal_name[] = "camera_feeds_updated";
63
64
private:
65
protected:
66
static CreateFunc create_func;
67
68
bool monitoring_feeds = false;
69
Vector<Ref<CameraFeed>> feeds;
70
71
static CameraServer *singleton;
72
73
static void _bind_methods();
74
75
template <typename T>
76
static CameraServer *_create_builtin() {
77
return memnew(T);
78
}
79
80
public:
81
static CameraServer *get_singleton();
82
83
template <typename T>
84
static void make_default() {
85
create_func = _create_builtin<T>;
86
}
87
88
static CameraServer *create() {
89
CameraServer *server = create_func ? create_func() : memnew(CameraServer);
90
return server;
91
}
92
93
virtual void set_monitoring_feeds(bool p_monitoring_feeds);
94
_FORCE_INLINE_ bool is_monitoring_feeds() const { return monitoring_feeds; }
95
96
// Right now we identify our feed by it's ID when it's used in the background.
97
// May see if we can change this to purely relying on CameraFeed objects or by name.
98
int get_free_id();
99
int get_feed_index(int p_id);
100
Ref<CameraFeed> get_feed_by_id(int p_id);
101
102
// Add and remove feeds.
103
void add_feed(const Ref<CameraFeed> &p_feed);
104
void remove_feed(const Ref<CameraFeed> &p_feed);
105
106
// Get our feeds.
107
Ref<CameraFeed> get_feed(int p_index);
108
int get_feed_count();
109
TypedArray<CameraFeed> get_feeds();
110
111
// Intended for use with custom CameraServer implementation.
112
RID feed_texture(int p_id, FeedImage p_texture);
113
114
CameraServer();
115
~CameraServer();
116
};
117
118
VARIANT_ENUM_CAST(CameraServer::FeedImage);
119
120