visual_server_viewport.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*************************************************************************/
  2. /* visual_server_viewport.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  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 VISUALSERVERVIEWPORT_H
  31. #define VISUALSERVERVIEWPORT_H
  32. #include "core/self_list.h"
  33. #include "rasterizer.h"
  34. #include "servers/arvr/arvr_interface.h"
  35. #include "servers/visual_server.h"
  36. class VisualServerViewport {
  37. public:
  38. struct CanvasBase : public RID_Data {
  39. };
  40. struct Viewport : public RID_Data {
  41. RID self;
  42. RID parent;
  43. bool use_arvr; /* use arvr interface to override camera positioning and projection matrices and control output */
  44. Size2i size;
  45. RID camera;
  46. RID scenario;
  47. VS::ViewportUpdateMode update_mode;
  48. RID render_target;
  49. RID render_target_texture;
  50. int viewport_to_screen;
  51. Rect2 viewport_to_screen_rect;
  52. bool hide_scenario;
  53. bool hide_canvas;
  54. bool disable_environment;
  55. bool disable_3d;
  56. bool disable_3d_by_usage;
  57. bool keep_3d_linear;
  58. RID shadow_atlas;
  59. int shadow_atlas_size;
  60. int render_info[VS::VIEWPORT_RENDER_INFO_MAX];
  61. VS::ViewportDebugDraw debug_draw;
  62. VS::ViewportClearMode clear_mode;
  63. bool transparent_bg;
  64. struct CanvasKey {
  65. int64_t stacking;
  66. RID canvas;
  67. bool operator<(const CanvasKey &p_canvas) const {
  68. if (stacking == p_canvas.stacking)
  69. return canvas < p_canvas.canvas;
  70. return stacking < p_canvas.stacking;
  71. }
  72. CanvasKey() {
  73. stacking = 0;
  74. }
  75. CanvasKey(const RID &p_canvas, int p_layer, int p_sublayer) {
  76. canvas = p_canvas;
  77. stacking = ((int64_t)p_layer << 32) + p_sublayer;
  78. }
  79. int get_layer() const { return stacking >> 32; }
  80. };
  81. struct CanvasData {
  82. CanvasBase *canvas;
  83. Transform2D transform;
  84. int layer;
  85. int sublayer;
  86. };
  87. Transform2D global_transform;
  88. Map<RID, CanvasData> canvas_map;
  89. Viewport() {
  90. update_mode = VS::VIEWPORT_UPDATE_WHEN_VISIBLE;
  91. clear_mode = VS::VIEWPORT_CLEAR_ALWAYS;
  92. transparent_bg = false;
  93. disable_environment = false;
  94. viewport_to_screen = 0;
  95. shadow_atlas_size = 0;
  96. disable_3d = false;
  97. disable_3d_by_usage = false;
  98. keep_3d_linear = false;
  99. debug_draw = VS::VIEWPORT_DEBUG_DRAW_DISABLED;
  100. for (int i = 0; i < VS::VIEWPORT_RENDER_INFO_MAX; i++) {
  101. render_info[i] = 0;
  102. }
  103. use_arvr = false;
  104. }
  105. };
  106. mutable RID_Owner<Viewport> viewport_owner;
  107. struct ViewportSort {
  108. _FORCE_INLINE_ bool operator()(const Viewport *p_left, const Viewport *p_right) const {
  109. bool left_to_screen = p_left->viewport_to_screen_rect.size != Size2();
  110. bool right_to_screen = p_right->viewport_to_screen_rect.size != Size2();
  111. if (left_to_screen == right_to_screen) {
  112. return p_left->parent == p_right->self;
  113. } else {
  114. return right_to_screen;
  115. }
  116. }
  117. };
  118. Vector<Viewport *> active_viewports;
  119. private:
  120. Color clear_color;
  121. void _draw_viewport(Viewport *p_viewport, ARVRInterface::Eyes p_eye = ARVRInterface::EYE_MONO);
  122. public:
  123. RID viewport_create();
  124. void viewport_set_use_arvr(RID p_viewport, bool p_use_arvr);
  125. void viewport_set_size(RID p_viewport, int p_width, int p_height);
  126. void viewport_attach_to_screen(RID p_viewport, const Rect2 &p_rect = Rect2(), int p_screen = 0);
  127. void viewport_detach(RID p_viewport);
  128. void viewport_set_active(RID p_viewport, bool p_active);
  129. void viewport_set_parent_viewport(RID p_viewport, RID p_parent_viewport);
  130. void viewport_set_update_mode(RID p_viewport, VS::ViewportUpdateMode p_mode);
  131. void viewport_set_vflip(RID p_viewport, bool p_enable);
  132. void viewport_set_clear_mode(RID p_viewport, VS::ViewportClearMode p_clear_mode);
  133. RID viewport_get_texture(RID p_viewport) const;
  134. void viewport_set_hide_scenario(RID p_viewport, bool p_hide);
  135. void viewport_set_hide_canvas(RID p_viewport, bool p_hide);
  136. void viewport_set_disable_environment(RID p_viewport, bool p_disable);
  137. void viewport_set_disable_3d(RID p_viewport, bool p_disable);
  138. void viewport_set_keep_3d_linear(RID p_viewport, bool p_keep_3d_linear);
  139. void viewport_attach_camera(RID p_viewport, RID p_camera);
  140. void viewport_set_scenario(RID p_viewport, RID p_scenario);
  141. void viewport_attach_canvas(RID p_viewport, RID p_canvas);
  142. void viewport_remove_canvas(RID p_viewport, RID p_canvas);
  143. void viewport_set_canvas_transform(RID p_viewport, RID p_canvas, const Transform2D &p_offset);
  144. void viewport_set_transparent_background(RID p_viewport, bool p_enabled);
  145. void viewport_set_global_canvas_transform(RID p_viewport, const Transform2D &p_transform);
  146. void viewport_set_canvas_stacking(RID p_viewport, RID p_canvas, int p_layer, int p_sublayer);
  147. void viewport_set_shadow_atlas_size(RID p_viewport, int p_size);
  148. void viewport_set_shadow_atlas_quadrant_subdivision(RID p_viewport, int p_quadrant, int p_subdiv);
  149. void viewport_set_msaa(RID p_viewport, VS::ViewportMSAA p_msaa);
  150. void viewport_set_hdr(RID p_viewport, bool p_enabled);
  151. void viewport_set_usage(RID p_viewport, VS::ViewportUsage p_usage);
  152. virtual int viewport_get_render_info(RID p_viewport, VS::ViewportRenderInfo p_info);
  153. virtual void viewport_set_debug_draw(RID p_viewport, VS::ViewportDebugDraw p_draw);
  154. void set_default_clear_color(const Color &p_color);
  155. void draw_viewports();
  156. bool free(RID p_rid);
  157. VisualServerViewport();
  158. virtual ~VisualServerViewport() {}
  159. };
  160. #endif // VISUALSERVERVIEWPORT_H