class_viewport.rst 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the Viewport.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_Viewport:
  6. Viewport
  7. ========
  8. **Inherits:** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  9. **Category:** Core
  10. Brief Description
  11. -----------------
  12. Creates a sub-view into the screen.
  13. Properties
  14. ----------
  15. +---------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  16. | :ref:`bool<class_bool>` | :ref:`arvr<class_Viewport_property_arvr>` |
  17. +---------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  18. | :ref:`bool<class_bool>` | :ref:`audio_listener_enable_2d<class_Viewport_property_audio_listener_enable_2d>` |
  19. +---------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  20. | :ref:`bool<class_bool>` | :ref:`audio_listener_enable_3d<class_Viewport_property_audio_listener_enable_3d>` |
  21. +---------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  22. | :ref:`Transform2D<class_Transform2D>` | :ref:`canvas_transform<class_Viewport_property_canvas_transform>` |
  23. +---------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  24. | :ref:`DebugDraw<enum_Viewport_DebugDraw>` | :ref:`debug_draw<class_Viewport_property_debug_draw>` |
  25. +---------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  26. | :ref:`bool<class_bool>` | :ref:`disable_3d<class_Viewport_property_disable_3d>` |
  27. +---------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  28. | :ref:`Transform2D<class_Transform2D>` | :ref:`global_canvas_transform<class_Viewport_property_global_canvas_transform>` |
  29. +---------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  30. | :ref:`bool<class_bool>` | :ref:`gui_disable_input<class_Viewport_property_gui_disable_input>` |
  31. +---------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  32. | :ref:`bool<class_bool>` | :ref:`gui_snap_controls_to_pixels<class_Viewport_property_gui_snap_controls_to_pixels>` |
  33. +---------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  34. | :ref:`bool<class_bool>` | :ref:`handle_input_locally<class_Viewport_property_handle_input_locally>` |
  35. +---------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  36. | :ref:`bool<class_bool>` | :ref:`hdr<class_Viewport_property_hdr>` |
  37. +---------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  38. | :ref:`bool<class_bool>` | :ref:`keep_3d_linear<class_Viewport_property_keep_3d_linear>` |
  39. +---------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  40. | :ref:`MSAA<enum_Viewport_MSAA>` | :ref:`msaa<class_Viewport_property_msaa>` |
  41. +---------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  42. | :ref:`bool<class_bool>` | :ref:`own_world<class_Viewport_property_own_world>` |
  43. +---------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  44. | :ref:`bool<class_bool>` | :ref:`physics_object_picking<class_Viewport_property_physics_object_picking>` |
  45. +---------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  46. | :ref:`ClearMode<enum_Viewport_ClearMode>` | :ref:`render_target_clear_mode<class_Viewport_property_render_target_clear_mode>` |
  47. +---------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  48. | :ref:`UpdateMode<enum_Viewport_UpdateMode>` | :ref:`render_target_update_mode<class_Viewport_property_render_target_update_mode>` |
  49. +---------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  50. | :ref:`bool<class_bool>` | :ref:`render_target_v_flip<class_Viewport_property_render_target_v_flip>` |
  51. +---------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  52. | :ref:`ShadowAtlasQuadrantSubdiv<enum_Viewport_ShadowAtlasQuadrantSubdiv>` | :ref:`shadow_atlas_quad_0<class_Viewport_property_shadow_atlas_quad_0>` |
  53. +---------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  54. | :ref:`ShadowAtlasQuadrantSubdiv<enum_Viewport_ShadowAtlasQuadrantSubdiv>` | :ref:`shadow_atlas_quad_1<class_Viewport_property_shadow_atlas_quad_1>` |
  55. +---------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  56. | :ref:`ShadowAtlasQuadrantSubdiv<enum_Viewport_ShadowAtlasQuadrantSubdiv>` | :ref:`shadow_atlas_quad_2<class_Viewport_property_shadow_atlas_quad_2>` |
  57. +---------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  58. | :ref:`ShadowAtlasQuadrantSubdiv<enum_Viewport_ShadowAtlasQuadrantSubdiv>` | :ref:`shadow_atlas_quad_3<class_Viewport_property_shadow_atlas_quad_3>` |
  59. +---------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  60. | :ref:`int<class_int>` | :ref:`shadow_atlas_size<class_Viewport_property_shadow_atlas_size>` |
  61. +---------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  62. | :ref:`Vector2<class_Vector2>` | :ref:`size<class_Viewport_property_size>` |
  63. +---------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  64. | :ref:`bool<class_bool>` | :ref:`transparent_bg<class_Viewport_property_transparent_bg>` |
  65. +---------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  66. | :ref:`Usage<enum_Viewport_Usage>` | :ref:`usage<class_Viewport_property_usage>` |
  67. +---------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  68. | :ref:`World<class_World>` | :ref:`world<class_Viewport_property_world>` |
  69. +---------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  70. | :ref:`World2D<class_World2D>` | :ref:`world_2d<class_Viewport_property_world_2d>` |
  71. +---------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  72. Methods
  73. -------
  74. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  75. | :ref:`World<class_World>` | :ref:`find_world<class_Viewport_method_find_world>` **(** **)** const |
  76. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  77. | :ref:`World2D<class_World2D>` | :ref:`find_world_2d<class_Viewport_method_find_world_2d>` **(** **)** const |
  78. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  79. | :ref:`Camera<class_Camera>` | :ref:`get_camera<class_Viewport_method_get_camera>` **(** **)** const |
  80. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  81. | :ref:`Transform2D<class_Transform2D>` | :ref:`get_final_transform<class_Viewport_method_get_final_transform>` **(** **)** const |
  82. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  83. | :ref:`Control<class_Control>` | :ref:`get_modal_stack_top<class_Viewport_method_get_modal_stack_top>` **(** **)** const |
  84. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  85. | :ref:`Vector2<class_Vector2>` | :ref:`get_mouse_position<class_Viewport_method_get_mouse_position>` **(** **)** const |
  86. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  87. | :ref:`int<class_int>` | :ref:`get_render_info<class_Viewport_method_get_render_info>` **(** :ref:`RenderInfo<enum_Viewport_RenderInfo>` info **)** |
  88. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  89. | :ref:`Vector2<class_Vector2>` | :ref:`get_size_override<class_Viewport_method_get_size_override>` **(** **)** const |
  90. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  91. | :ref:`ViewportTexture<class_ViewportTexture>` | :ref:`get_texture<class_Viewport_method_get_texture>` **(** **)** const |
  92. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  93. | :ref:`RID<class_RID>` | :ref:`get_viewport_rid<class_Viewport_method_get_viewport_rid>` **(** **)** const |
  94. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  95. | :ref:`Rect2<class_Rect2>` | :ref:`get_visible_rect<class_Viewport_method_get_visible_rect>` **(** **)** const |
  96. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  97. | :ref:`Variant<class_Variant>` | :ref:`gui_get_drag_data<class_Viewport_method_gui_get_drag_data>` **(** **)** const |
  98. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  99. | :ref:`bool<class_bool>` | :ref:`gui_has_modal_stack<class_Viewport_method_gui_has_modal_stack>` **(** **)** const |
  100. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  101. | :ref:`bool<class_bool>` | :ref:`gui_is_dragging<class_Viewport_method_gui_is_dragging>` **(** **)** const |
  102. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  103. | void | :ref:`input<class_Viewport_method_input>` **(** :ref:`InputEvent<class_InputEvent>` local_event **)** |
  104. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  105. | :ref:`bool<class_bool>` | :ref:`is_input_handled<class_Viewport_method_is_input_handled>` **(** **)** const |
  106. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  107. | :ref:`bool<class_bool>` | :ref:`is_size_override_enabled<class_Viewport_method_is_size_override_enabled>` **(** **)** const |
  108. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  109. | :ref:`bool<class_bool>` | :ref:`is_size_override_stretch_enabled<class_Viewport_method_is_size_override_stretch_enabled>` **(** **)** const |
  110. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  111. | void | :ref:`set_attach_to_screen_rect<class_Viewport_method_set_attach_to_screen_rect>` **(** :ref:`Rect2<class_Rect2>` rect **)** |
  112. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  113. | void | :ref:`set_input_as_handled<class_Viewport_method_set_input_as_handled>` **(** **)** |
  114. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  115. | void | :ref:`set_size_override<class_Viewport_method_set_size_override>` **(** :ref:`bool<class_bool>` enable, :ref:`Vector2<class_Vector2>` size=Vector2( -1, -1 ), :ref:`Vector2<class_Vector2>` margin=Vector2( 0, 0 ) **)** |
  116. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  117. | void | :ref:`set_size_override_stretch<class_Viewport_method_set_size_override_stretch>` **(** :ref:`bool<class_bool>` enabled **)** |
  118. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  119. | void | :ref:`unhandled_input<class_Viewport_method_unhandled_input>` **(** :ref:`InputEvent<class_InputEvent>` local_event **)** |
  120. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  121. | void | :ref:`update_worlds<class_Viewport_method_update_worlds>` **(** **)** |
  122. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  123. | void | :ref:`warp_mouse<class_Viewport_method_warp_mouse>` **(** :ref:`Vector2<class_Vector2>` to_position **)** |
  124. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  125. Signals
  126. -------
  127. .. _class_Viewport_signal_size_changed:
  128. - **size_changed** **(** **)**
  129. Emitted when the size of the viewport is changed, whether by :ref:`set_size_override<class_Viewport_method_set_size_override>`, resize of window, or some other means.
  130. Enumerations
  131. ------------
  132. .. _enum_Viewport_UpdateMode:
  133. .. _class_Viewport_constant_UPDATE_DISABLED:
  134. .. _class_Viewport_constant_UPDATE_ONCE:
  135. .. _class_Viewport_constant_UPDATE_WHEN_VISIBLE:
  136. .. _class_Viewport_constant_UPDATE_ALWAYS:
  137. enum **UpdateMode**:
  138. - **UPDATE_DISABLED** = **0** --- Do not update the render target.
  139. - **UPDATE_ONCE** = **1** --- Update the render target once, then switch to :ref:`UPDATE_DISABLED<class_Viewport_constant_UPDATE_DISABLED>`.
  140. - **UPDATE_WHEN_VISIBLE** = **2** --- Update the render target only when it is visible. This is the default value.
  141. - **UPDATE_ALWAYS** = **3** --- Always update the render target.
  142. ----
  143. .. _enum_Viewport_ShadowAtlasQuadrantSubdiv:
  144. .. _class_Viewport_constant_SHADOW_ATLAS_QUADRANT_SUBDIV_DISABLED:
  145. .. _class_Viewport_constant_SHADOW_ATLAS_QUADRANT_SUBDIV_1:
  146. .. _class_Viewport_constant_SHADOW_ATLAS_QUADRANT_SUBDIV_4:
  147. .. _class_Viewport_constant_SHADOW_ATLAS_QUADRANT_SUBDIV_16:
  148. .. _class_Viewport_constant_SHADOW_ATLAS_QUADRANT_SUBDIV_64:
  149. .. _class_Viewport_constant_SHADOW_ATLAS_QUADRANT_SUBDIV_256:
  150. .. _class_Viewport_constant_SHADOW_ATLAS_QUADRANT_SUBDIV_1024:
  151. .. _class_Viewport_constant_SHADOW_ATLAS_QUADRANT_SUBDIV_MAX:
  152. enum **ShadowAtlasQuadrantSubdiv**:
  153. - **SHADOW_ATLAS_QUADRANT_SUBDIV_DISABLED** = **0**
  154. - **SHADOW_ATLAS_QUADRANT_SUBDIV_1** = **1**
  155. - **SHADOW_ATLAS_QUADRANT_SUBDIV_4** = **2**
  156. - **SHADOW_ATLAS_QUADRANT_SUBDIV_16** = **3**
  157. - **SHADOW_ATLAS_QUADRANT_SUBDIV_64** = **4**
  158. - **SHADOW_ATLAS_QUADRANT_SUBDIV_256** = **5**
  159. - **SHADOW_ATLAS_QUADRANT_SUBDIV_1024** = **6**
  160. - **SHADOW_ATLAS_QUADRANT_SUBDIV_MAX** = **7** --- Represents the size of the :ref:`ShadowAtlasQuadrantSubdiv<enum_Viewport_ShadowAtlasQuadrantSubdiv>` enum.
  161. ----
  162. .. _enum_Viewport_RenderInfo:
  163. .. _class_Viewport_constant_RENDER_INFO_OBJECTS_IN_FRAME:
  164. .. _class_Viewport_constant_RENDER_INFO_VERTICES_IN_FRAME:
  165. .. _class_Viewport_constant_RENDER_INFO_MATERIAL_CHANGES_IN_FRAME:
  166. .. _class_Viewport_constant_RENDER_INFO_SHADER_CHANGES_IN_FRAME:
  167. .. _class_Viewport_constant_RENDER_INFO_SURFACE_CHANGES_IN_FRAME:
  168. .. _class_Viewport_constant_RENDER_INFO_DRAW_CALLS_IN_FRAME:
  169. .. _class_Viewport_constant_RENDER_INFO_MAX:
  170. enum **RenderInfo**:
  171. - **RENDER_INFO_OBJECTS_IN_FRAME** = **0** --- Amount of objects in frame.
  172. - **RENDER_INFO_VERTICES_IN_FRAME** = **1** --- Amount of vertices in frame.
  173. - **RENDER_INFO_MATERIAL_CHANGES_IN_FRAME** = **2** --- Amount of material changes in frame.
  174. - **RENDER_INFO_SHADER_CHANGES_IN_FRAME** = **3** --- Amount of shader changes in frame.
  175. - **RENDER_INFO_SURFACE_CHANGES_IN_FRAME** = **4** --- Amount of surface changes in frame.
  176. - **RENDER_INFO_DRAW_CALLS_IN_FRAME** = **5** --- Amount of draw calls in frame.
  177. - **RENDER_INFO_MAX** = **6** --- Represents the size of the :ref:`RenderInfo<enum_Viewport_RenderInfo>` enum.
  178. ----
  179. .. _enum_Viewport_DebugDraw:
  180. .. _class_Viewport_constant_DEBUG_DRAW_DISABLED:
  181. .. _class_Viewport_constant_DEBUG_DRAW_UNSHADED:
  182. .. _class_Viewport_constant_DEBUG_DRAW_OVERDRAW:
  183. .. _class_Viewport_constant_DEBUG_DRAW_WIREFRAME:
  184. enum **DebugDraw**:
  185. - **DEBUG_DRAW_DISABLED** = **0** --- Objects are displayed normally.
  186. - **DEBUG_DRAW_UNSHADED** = **1** --- Objects are displayed without light information.
  187. - **DEBUG_DRAW_OVERDRAW** = **2** --- Objected are displayed semi-transparent with additive blending so you can see where they intersect.
  188. - **DEBUG_DRAW_WIREFRAME** = **3** --- Objects are displayed in wireframe style.
  189. ----
  190. .. _enum_Viewport_MSAA:
  191. .. _class_Viewport_constant_MSAA_DISABLED:
  192. .. _class_Viewport_constant_MSAA_2X:
  193. .. _class_Viewport_constant_MSAA_4X:
  194. .. _class_Viewport_constant_MSAA_8X:
  195. .. _class_Viewport_constant_MSAA_16X:
  196. enum **MSAA**:
  197. - **MSAA_DISABLED** = **0** --- Multisample anti-aliasing mode disabled. This is the default value.
  198. - **MSAA_2X** = **1**
  199. - **MSAA_4X** = **2**
  200. - **MSAA_8X** = **3**
  201. - **MSAA_16X** = **4**
  202. ----
  203. .. _enum_Viewport_Usage:
  204. .. _class_Viewport_constant_USAGE_2D:
  205. .. _class_Viewport_constant_USAGE_2D_NO_SAMPLING:
  206. .. _class_Viewport_constant_USAGE_3D:
  207. .. _class_Viewport_constant_USAGE_3D_NO_EFFECTS:
  208. enum **Usage**:
  209. - **USAGE_2D** = **0**
  210. - **USAGE_2D_NO_SAMPLING** = **1**
  211. - **USAGE_3D** = **2**
  212. - **USAGE_3D_NO_EFFECTS** = **3**
  213. ----
  214. .. _enum_Viewport_ClearMode:
  215. .. _class_Viewport_constant_CLEAR_MODE_ALWAYS:
  216. .. _class_Viewport_constant_CLEAR_MODE_NEVER:
  217. .. _class_Viewport_constant_CLEAR_MODE_ONLY_NEXT_FRAME:
  218. enum **ClearMode**:
  219. - **CLEAR_MODE_ALWAYS** = **0** --- Always clear the render target before drawing.
  220. - **CLEAR_MODE_NEVER** = **1** --- Never clear the render target.
  221. - **CLEAR_MODE_ONLY_NEXT_FRAME** = **2** --- Clear the render target next frame, then switch to :ref:`CLEAR_MODE_NEVER<class_Viewport_constant_CLEAR_MODE_NEVER>`.
  222. Description
  223. -----------
  224. A Viewport creates a different view into the screen, or a sub-view inside another viewport. Children 2D Nodes will display on it, and children Camera 3D nodes will render on it too.
  225. Optionally, a viewport can have its own 2D or 3D world, so they don't share what they draw with other viewports.
  226. If a viewport is a child of a :ref:`ViewportContainer<class_ViewportContainer>`, it will automatically take up its size, otherwise it must be set manually.
  227. Viewports can also choose to be audio listeners, so they generate positional audio depending on a 2D or 3D camera child of it.
  228. Also, viewports can be assigned to different screens in case the devices have multiple screens.
  229. Finally, viewports can also behave as render targets, in which case they will not be visible unless the associated texture is used to draw.
  230. Tutorials
  231. ---------
  232. - :doc:`../tutorials/2d/2d_transforms`
  233. - :doc:`../tutorials/viewports/index`
  234. Property Descriptions
  235. ---------------------
  236. .. _class_Viewport_property_arvr:
  237. - :ref:`bool<class_bool>` **arvr**
  238. +----------+---------------------+
  239. | *Setter* | set_use_arvr(value) |
  240. +----------+---------------------+
  241. | *Getter* | use_arvr() |
  242. +----------+---------------------+
  243. If ``true``, the viewport will be used in AR/VR process. Default value: ``false``.
  244. ----
  245. .. _class_Viewport_property_audio_listener_enable_2d:
  246. - :ref:`bool<class_bool>` **audio_listener_enable_2d**
  247. +----------+---------------------------------+
  248. | *Setter* | set_as_audio_listener_2d(value) |
  249. +----------+---------------------------------+
  250. | *Getter* | is_audio_listener_2d() |
  251. +----------+---------------------------------+
  252. If ``true``, the viewport will process 2D audio streams. Default value: ``false``.
  253. ----
  254. .. _class_Viewport_property_audio_listener_enable_3d:
  255. - :ref:`bool<class_bool>` **audio_listener_enable_3d**
  256. +----------+------------------------------+
  257. | *Setter* | set_as_audio_listener(value) |
  258. +----------+------------------------------+
  259. | *Getter* | is_audio_listener() |
  260. +----------+------------------------------+
  261. If ``true``, the viewport will process 3D audio streams. Default value: ``false``.
  262. ----
  263. .. _class_Viewport_property_canvas_transform:
  264. - :ref:`Transform2D<class_Transform2D>` **canvas_transform**
  265. +----------+-----------------------------+
  266. | *Setter* | set_canvas_transform(value) |
  267. +----------+-----------------------------+
  268. | *Getter* | get_canvas_transform() |
  269. +----------+-----------------------------+
  270. The canvas transform of the viewport, useful for changing the on-screen positions of all child :ref:`CanvasItem<class_CanvasItem>`\ s. This is relative to the global canvas transform of the viewport.
  271. ----
  272. .. _class_Viewport_property_debug_draw:
  273. - :ref:`DebugDraw<enum_Viewport_DebugDraw>` **debug_draw**
  274. +----------+-----------------------+
  275. | *Setter* | set_debug_draw(value) |
  276. +----------+-----------------------+
  277. | *Getter* | get_debug_draw() |
  278. +----------+-----------------------+
  279. The overlay mode for test rendered geometry in debug purposes. Default value: :ref:`DEBUG_DRAW_DISABLED<class_Viewport_constant_DEBUG_DRAW_DISABLED>`.
  280. ----
  281. .. _class_Viewport_property_disable_3d:
  282. - :ref:`bool<class_bool>` **disable_3d**
  283. +----------+-----------------------+
  284. | *Setter* | set_disable_3d(value) |
  285. +----------+-----------------------+
  286. | *Getter* | is_3d_disabled() |
  287. +----------+-----------------------+
  288. If ``true``, the viewport will disable 3D rendering. For actual disabling use ``usage``. Default value: ``false``.
  289. ----
  290. .. _class_Viewport_property_global_canvas_transform:
  291. - :ref:`Transform2D<class_Transform2D>` **global_canvas_transform**
  292. +----------+------------------------------------+
  293. | *Setter* | set_global_canvas_transform(value) |
  294. +----------+------------------------------------+
  295. | *Getter* | get_global_canvas_transform() |
  296. +----------+------------------------------------+
  297. The global canvas transform of the viewport. The canvas transform is relative to this.
  298. ----
  299. .. _class_Viewport_property_gui_disable_input:
  300. - :ref:`bool<class_bool>` **gui_disable_input**
  301. +----------+--------------------------+
  302. | *Setter* | set_disable_input(value) |
  303. +----------+--------------------------+
  304. | *Getter* | is_input_disabled() |
  305. +----------+--------------------------+
  306. If ``true``, the viewport will not receive input event. Default value: ``false``.
  307. ----
  308. .. _class_Viewport_property_gui_snap_controls_to_pixels:
  309. - :ref:`bool<class_bool>` **gui_snap_controls_to_pixels**
  310. +----------+--------------------------------------+
  311. | *Setter* | set_snap_controls_to_pixels(value) |
  312. +----------+--------------------------------------+
  313. | *Getter* | is_snap_controls_to_pixels_enabled() |
  314. +----------+--------------------------------------+
  315. If ``true``, the GUI controls on the viewport will lay pixel perfectly. Default value: ``true``.
  316. ----
  317. .. _class_Viewport_property_handle_input_locally:
  318. - :ref:`bool<class_bool>` **handle_input_locally**
  319. +----------+---------------------------------+
  320. | *Setter* | set_handle_input_locally(value) |
  321. +----------+---------------------------------+
  322. | *Getter* | is_handling_input_locally() |
  323. +----------+---------------------------------+
  324. ----
  325. .. _class_Viewport_property_hdr:
  326. - :ref:`bool<class_bool>` **hdr**
  327. +----------+----------------+
  328. | *Setter* | set_hdr(value) |
  329. +----------+----------------+
  330. | *Getter* | get_hdr() |
  331. +----------+----------------+
  332. If ``true``, the viewport rendering will receive benefits from High Dynamic Range algorithm. Default value: ``true``.
  333. ----
  334. .. _class_Viewport_property_keep_3d_linear:
  335. - :ref:`bool<class_bool>` **keep_3d_linear**
  336. +----------+---------------------------+
  337. | *Setter* | set_keep_3d_linear(value) |
  338. +----------+---------------------------+
  339. | *Getter* | get_keep_3d_linear() |
  340. +----------+---------------------------+
  341. If ``true``, the result after 3D rendering will not have a linear to sRGB color conversion applied. This is important when the viewport is used as a render target where the result is used as a texture on a 3D object rendered in another viewport. It is also important if the viewport is used to create data that is not color based (noise, heightmaps, pickmaps, etc.). Do not enable this when the viewport is used as a texture on a 2D object or if the viewport is your final output.
  342. ----
  343. .. _class_Viewport_property_msaa:
  344. - :ref:`MSAA<enum_Viewport_MSAA>` **msaa**
  345. +----------+-----------------+
  346. | *Setter* | set_msaa(value) |
  347. +----------+-----------------+
  348. | *Getter* | get_msaa() |
  349. +----------+-----------------+
  350. The multisample anti-aliasing mode. Default value: :ref:`MSAA_DISABLED<class_Viewport_constant_MSAA_DISABLED>`.
  351. ----
  352. .. _class_Viewport_property_own_world:
  353. - :ref:`bool<class_bool>` **own_world**
  354. +----------+--------------------------+
  355. | *Setter* | set_use_own_world(value) |
  356. +----------+--------------------------+
  357. | *Getter* | is_using_own_world() |
  358. +----------+--------------------------+
  359. If ``true``, the viewport will use :ref:`World<class_World>` defined in ``world`` property. Default value: ``false``.
  360. ----
  361. .. _class_Viewport_property_physics_object_picking:
  362. - :ref:`bool<class_bool>` **physics_object_picking**
  363. +----------+-----------------------------------+
  364. | *Setter* | set_physics_object_picking(value) |
  365. +----------+-----------------------------------+
  366. | *Getter* | get_physics_object_picking() |
  367. +----------+-----------------------------------+
  368. If ``true``, the objects rendered by viewport become subjects of mouse picking process. Default value: ``false``.
  369. ----
  370. .. _class_Viewport_property_render_target_clear_mode:
  371. - :ref:`ClearMode<enum_Viewport_ClearMode>` **render_target_clear_mode**
  372. +----------+-----------------------+
  373. | *Setter* | set_clear_mode(value) |
  374. +----------+-----------------------+
  375. | *Getter* | get_clear_mode() |
  376. +----------+-----------------------+
  377. The clear mode when viewport used as a render target. Default value: :ref:`CLEAR_MODE_ALWAYS<class_Viewport_constant_CLEAR_MODE_ALWAYS>`.
  378. ----
  379. .. _class_Viewport_property_render_target_update_mode:
  380. - :ref:`UpdateMode<enum_Viewport_UpdateMode>` **render_target_update_mode**
  381. +----------+------------------------+
  382. | *Setter* | set_update_mode(value) |
  383. +----------+------------------------+
  384. | *Getter* | get_update_mode() |
  385. +----------+------------------------+
  386. The update mode when viewport used as a render target. Default value: :ref:`UPDATE_WHEN_VISIBLE<class_Viewport_constant_UPDATE_WHEN_VISIBLE>`.
  387. ----
  388. .. _class_Viewport_property_render_target_v_flip:
  389. - :ref:`bool<class_bool>` **render_target_v_flip**
  390. +----------+------------------+
  391. | *Setter* | set_vflip(value) |
  392. +----------+------------------+
  393. | *Getter* | get_vflip() |
  394. +----------+------------------+
  395. If ``true``, the result of rendering will be flipped vertically. Default value: ``false``.
  396. ----
  397. .. _class_Viewport_property_shadow_atlas_quad_0:
  398. - :ref:`ShadowAtlasQuadrantSubdiv<enum_Viewport_ShadowAtlasQuadrantSubdiv>` **shadow_atlas_quad_0**
  399. +----------+-----------------------------------------+
  400. | *Setter* | set_shadow_atlas_quadrant_subdiv(value) |
  401. +----------+-----------------------------------------+
  402. | *Getter* | get_shadow_atlas_quadrant_subdiv() |
  403. +----------+-----------------------------------------+
  404. The subdivision amount of first quadrant on shadow atlas. Default value: ``SHADOW_ATLAS_QUADRANT_SUBDIV_4``.
  405. ----
  406. .. _class_Viewport_property_shadow_atlas_quad_1:
  407. - :ref:`ShadowAtlasQuadrantSubdiv<enum_Viewport_ShadowAtlasQuadrantSubdiv>` **shadow_atlas_quad_1**
  408. +----------+-----------------------------------------+
  409. | *Setter* | set_shadow_atlas_quadrant_subdiv(value) |
  410. +----------+-----------------------------------------+
  411. | *Getter* | get_shadow_atlas_quadrant_subdiv() |
  412. +----------+-----------------------------------------+
  413. The subdivision amount of second quadrant on shadow atlas. Default value: ``SHADOW_ATLAS_QUADRANT_SUBDIV_4``.
  414. ----
  415. .. _class_Viewport_property_shadow_atlas_quad_2:
  416. - :ref:`ShadowAtlasQuadrantSubdiv<enum_Viewport_ShadowAtlasQuadrantSubdiv>` **shadow_atlas_quad_2**
  417. +----------+-----------------------------------------+
  418. | *Setter* | set_shadow_atlas_quadrant_subdiv(value) |
  419. +----------+-----------------------------------------+
  420. | *Getter* | get_shadow_atlas_quadrant_subdiv() |
  421. +----------+-----------------------------------------+
  422. The subdivision amount of third quadrant on shadow atlas. Default value: ``SHADOW_ATLAS_QUADRANT_SUBDIV_16``.
  423. ----
  424. .. _class_Viewport_property_shadow_atlas_quad_3:
  425. - :ref:`ShadowAtlasQuadrantSubdiv<enum_Viewport_ShadowAtlasQuadrantSubdiv>` **shadow_atlas_quad_3**
  426. +----------+-----------------------------------------+
  427. | *Setter* | set_shadow_atlas_quadrant_subdiv(value) |
  428. +----------+-----------------------------------------+
  429. | *Getter* | get_shadow_atlas_quadrant_subdiv() |
  430. +----------+-----------------------------------------+
  431. The subdivision amount of fourth quadrant on shadow atlas. Default value: ``SHADOW_ATLAS_QUADRANT_SUBDIV_64``.
  432. ----
  433. .. _class_Viewport_property_shadow_atlas_size:
  434. - :ref:`int<class_int>` **shadow_atlas_size**
  435. +----------+------------------------------+
  436. | *Setter* | set_shadow_atlas_size(value) |
  437. +----------+------------------------------+
  438. | *Getter* | get_shadow_atlas_size() |
  439. +----------+------------------------------+
  440. The resolution of shadow atlas. Both width and height is equal to one value.
  441. ----
  442. .. _class_Viewport_property_size:
  443. - :ref:`Vector2<class_Vector2>` **size**
  444. +----------+-----------------+
  445. | *Setter* | set_size(value) |
  446. +----------+-----------------+
  447. | *Getter* | get_size() |
  448. +----------+-----------------+
  449. The width and height of viewport.
  450. ----
  451. .. _class_Viewport_property_transparent_bg:
  452. - :ref:`bool<class_bool>` **transparent_bg**
  453. +----------+-----------------------------------+
  454. | *Setter* | set_transparent_background(value) |
  455. +----------+-----------------------------------+
  456. | *Getter* | has_transparent_background() |
  457. +----------+-----------------------------------+
  458. If ``true``, the viewport should render its background as transparent. Default value: ``false``.
  459. ----
  460. .. _class_Viewport_property_usage:
  461. - :ref:`Usage<enum_Viewport_Usage>` **usage**
  462. +----------+------------------+
  463. | *Setter* | set_usage(value) |
  464. +----------+------------------+
  465. | *Getter* | get_usage() |
  466. +----------+------------------+
  467. The rendering mode of viewport. Default value: ``USAGE_3D``.
  468. ----
  469. .. _class_Viewport_property_world:
  470. - :ref:`World<class_World>` **world**
  471. +----------+------------------+
  472. | *Setter* | set_world(value) |
  473. +----------+------------------+
  474. | *Getter* | get_world() |
  475. +----------+------------------+
  476. The custom :ref:`World<class_World>` which can be used as 3D environment source.
  477. ----
  478. .. _class_Viewport_property_world_2d:
  479. - :ref:`World2D<class_World2D>` **world_2d**
  480. +----------+---------------------+
  481. | *Setter* | set_world_2d(value) |
  482. +----------+---------------------+
  483. | *Getter* | get_world_2d() |
  484. +----------+---------------------+
  485. The custom :ref:`World2D<class_World2D>` which can be used as 2D environment source.
  486. Method Descriptions
  487. -------------------
  488. .. _class_Viewport_method_find_world:
  489. - :ref:`World<class_World>` **find_world** **(** **)** const
  490. Returns the 3D world of the viewport, or if none the world of the parent viewport.
  491. ----
  492. .. _class_Viewport_method_find_world_2d:
  493. - :ref:`World2D<class_World2D>` **find_world_2d** **(** **)** const
  494. Returns the 2D world of the viewport.
  495. ----
  496. .. _class_Viewport_method_get_camera:
  497. - :ref:`Camera<class_Camera>` **get_camera** **(** **)** const
  498. Returns the active 3D camera.
  499. ----
  500. .. _class_Viewport_method_get_final_transform:
  501. - :ref:`Transform2D<class_Transform2D>` **get_final_transform** **(** **)** const
  502. Returns the total transform of the viewport.
  503. ----
  504. .. _class_Viewport_method_get_modal_stack_top:
  505. - :ref:`Control<class_Control>` **get_modal_stack_top** **(** **)** const
  506. Returns the topmost modal in the stack.
  507. ----
  508. .. _class_Viewport_method_get_mouse_position:
  509. - :ref:`Vector2<class_Vector2>` **get_mouse_position** **(** **)** const
  510. Returns the mouse position relative to the viewport.
  511. ----
  512. .. _class_Viewport_method_get_render_info:
  513. - :ref:`int<class_int>` **get_render_info** **(** :ref:`RenderInfo<enum_Viewport_RenderInfo>` info **)**
  514. Returns information about the viewport from the rendering pipeline.
  515. ----
  516. .. _class_Viewport_method_get_size_override:
  517. - :ref:`Vector2<class_Vector2>` **get_size_override** **(** **)** const
  518. Returns the size override set with :ref:`set_size_override<class_Viewport_method_set_size_override>`.
  519. ----
  520. .. _class_Viewport_method_get_texture:
  521. - :ref:`ViewportTexture<class_ViewportTexture>` **get_texture** **(** **)** const
  522. Returns the viewport's texture. Note that due to the way OpenGL works, the resulting :ref:`ViewportTexture<class_ViewportTexture>` is flipped vertically. You can use :ref:`Image.flip_y<class_Image_method_flip_y>` on the result of :ref:`Texture.get_data<class_Texture_method_get_data>` to flip it back, for example:
  523. ::
  524. var img = get_viewport().get_texture().get_data()
  525. img.flip_y()
  526. ----
  527. .. _class_Viewport_method_get_viewport_rid:
  528. - :ref:`RID<class_RID>` **get_viewport_rid** **(** **)** const
  529. Returns the viewport's RID from the :ref:`VisualServer<class_VisualServer>`.
  530. ----
  531. .. _class_Viewport_method_get_visible_rect:
  532. - :ref:`Rect2<class_Rect2>` **get_visible_rect** **(** **)** const
  533. Returns the visible rectangle in global screen coordinates.
  534. ----
  535. .. _class_Viewport_method_gui_get_drag_data:
  536. - :ref:`Variant<class_Variant>` **gui_get_drag_data** **(** **)** const
  537. Returns the drag data from the GUI, that was previously returned by :ref:`Control.get_drag_data<class_Control_method_get_drag_data>`.
  538. ----
  539. .. _class_Viewport_method_gui_has_modal_stack:
  540. - :ref:`bool<class_bool>` **gui_has_modal_stack** **(** **)** const
  541. Returns ``true`` if there are visible modals on-screen.
  542. ----
  543. .. _class_Viewport_method_gui_is_dragging:
  544. - :ref:`bool<class_bool>` **gui_is_dragging** **(** **)** const
  545. ----
  546. .. _class_Viewport_method_input:
  547. - void **input** **(** :ref:`InputEvent<class_InputEvent>` local_event **)**
  548. ----
  549. .. _class_Viewport_method_is_input_handled:
  550. - :ref:`bool<class_bool>` **is_input_handled** **(** **)** const
  551. ----
  552. .. _class_Viewport_method_is_size_override_enabled:
  553. - :ref:`bool<class_bool>` **is_size_override_enabled** **(** **)** const
  554. Returns ``true`` if the size override is enabled. See :ref:`set_size_override<class_Viewport_method_set_size_override>`.
  555. ----
  556. .. _class_Viewport_method_is_size_override_stretch_enabled:
  557. - :ref:`bool<class_bool>` **is_size_override_stretch_enabled** **(** **)** const
  558. ----
  559. .. _class_Viewport_method_set_attach_to_screen_rect:
  560. - void **set_attach_to_screen_rect** **(** :ref:`Rect2<class_Rect2>` rect **)**
  561. ----
  562. .. _class_Viewport_method_set_input_as_handled:
  563. - void **set_input_as_handled** **(** **)**
  564. ----
  565. .. _class_Viewport_method_set_size_override:
  566. - void **set_size_override** **(** :ref:`bool<class_bool>` enable, :ref:`Vector2<class_Vector2>` size=Vector2( -1, -1 ), :ref:`Vector2<class_Vector2>` margin=Vector2( 0, 0 ) **)**
  567. Sets the size override of the viewport. If the ``enable`` parameter is ``true`` the override is used, otherwise it uses the default size. If the size parameter is ``(-1, -1)``, it won't update the size.
  568. ----
  569. .. _class_Viewport_method_set_size_override_stretch:
  570. - void **set_size_override_stretch** **(** :ref:`bool<class_bool>` enabled **)**
  571. ----
  572. .. _class_Viewport_method_unhandled_input:
  573. - void **unhandled_input** **(** :ref:`InputEvent<class_InputEvent>` local_event **)**
  574. ----
  575. .. _class_Viewport_method_update_worlds:
  576. - void **update_worlds** **(** **)**
  577. Forces update of the 2D and 3D worlds.
  578. ----
  579. .. _class_Viewport_method_warp_mouse:
  580. - void **warp_mouse** **(** :ref:`Vector2<class_Vector2>` to_position **)**
  581. Warps the mouse to a position relative to the viewport.