camera_server.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. #ifndef CAMERA_SERVER_H
  31. #define CAMERA_SERVER_H
  32. #include "core/object.h"
  33. #include "core/os/thread_safe.h"
  34. #include "core/reference.h"
  35. #include "core/rid.h"
  36. #include "core/variant.h"
  37. /**
  38. @author Bastiaan Olij <mux213@gmail.com>
  39. The camera server is a singleton object that gives access to the various
  40. camera feeds that can be used as the background for our environment.
  41. **/
  42. class CameraFeed;
  43. class CameraServer : public Object {
  44. GDCLASS(CameraServer, Object);
  45. _THREAD_SAFE_CLASS_
  46. public:
  47. enum FeedImage {
  48. FEED_RGBA_IMAGE = 0,
  49. FEED_YCBCR_IMAGE = 0,
  50. FEED_Y_IMAGE = 0,
  51. FEED_CBCR_IMAGE = 1,
  52. FEED_IMAGES = 2
  53. };
  54. typedef CameraServer *(*CreateFunc)();
  55. private:
  56. protected:
  57. static CreateFunc create_func;
  58. Vector<Ref<CameraFeed>> feeds;
  59. static CameraServer *singleton;
  60. static void _bind_methods();
  61. template <class T>
  62. static CameraServer *_create_builtin() {
  63. return memnew(T);
  64. }
  65. public:
  66. static CameraServer *get_singleton();
  67. template <class T>
  68. static void make_default() {
  69. create_func = _create_builtin<T>;
  70. }
  71. static CameraServer *create() {
  72. CameraServer *server = create_func ? create_func() : memnew(CameraServer);
  73. return server;
  74. };
  75. // Right now we identify our feed by it's ID when it's used in the background.
  76. // May see if we can change this to purely relying on CameraFeed objects or by name.
  77. int get_free_id();
  78. int get_feed_index(int p_id);
  79. Ref<CameraFeed> get_feed_by_id(int p_id);
  80. // add and remove feeds
  81. void add_feed(const Ref<CameraFeed> &p_feed);
  82. void remove_feed(const Ref<CameraFeed> &p_feed);
  83. // get our feeds
  84. Ref<CameraFeed> get_feed(int p_index);
  85. int get_feed_count();
  86. Array get_feeds();
  87. RID feed_texture(int p_id, FeedImage p_texture);
  88. CameraServer();
  89. ~CameraServer();
  90. };
  91. VARIANT_ENUM_CAST(CameraServer::FeedImage);
  92. #endif // CAMERA_SERVER_H