texture_storage.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. /*************************************************************************/
  2. /* texture_storage.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 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 TEXTURE_STORAGE_RD_H
  31. #define TEXTURE_STORAGE_RD_H
  32. #include "core/templates/rid_owner.h"
  33. #include "servers/rendering/renderer_rd/shaders/canvas_sdf.glsl.gen.h"
  34. #include "servers/rendering/storage/texture_storage.h"
  35. #include "servers/rendering/storage/utilities.h"
  36. namespace RendererRD {
  37. class LightStorage;
  38. class MaterialStorage;
  39. class TextureStorage : public RendererTextureStorage {
  40. public:
  41. enum DefaultRDTexture {
  42. DEFAULT_RD_TEXTURE_WHITE,
  43. DEFAULT_RD_TEXTURE_BLACK,
  44. DEFAULT_RD_TEXTURE_TRANSPARENT,
  45. DEFAULT_RD_TEXTURE_NORMAL,
  46. DEFAULT_RD_TEXTURE_ANISO,
  47. DEFAULT_RD_TEXTURE_DEPTH,
  48. DEFAULT_RD_TEXTURE_MULTIMESH_BUFFER,
  49. DEFAULT_RD_TEXTURE_CUBEMAP_BLACK,
  50. DEFAULT_RD_TEXTURE_CUBEMAP_ARRAY_BLACK,
  51. DEFAULT_RD_TEXTURE_CUBEMAP_WHITE,
  52. DEFAULT_RD_TEXTURE_CUBEMAP_ARRAY_WHITE,
  53. DEFAULT_RD_TEXTURE_3D_WHITE,
  54. DEFAULT_RD_TEXTURE_3D_BLACK,
  55. DEFAULT_RD_TEXTURE_2D_ARRAY_WHITE,
  56. DEFAULT_RD_TEXTURE_2D_UINT,
  57. DEFAULT_RD_TEXTURE_VRS,
  58. DEFAULT_RD_TEXTURE_MAX
  59. };
  60. enum TextureType {
  61. TYPE_2D,
  62. TYPE_LAYERED,
  63. TYPE_3D
  64. };
  65. private:
  66. friend class LightStorage;
  67. friend class MaterialStorage;
  68. static TextureStorage *singleton;
  69. RID default_rd_textures[DEFAULT_RD_TEXTURE_MAX];
  70. /* Canvas Texture API */
  71. class CanvasTexture {
  72. public:
  73. RID diffuse;
  74. RID normal_map;
  75. RID specular;
  76. Color specular_color = Color(1, 1, 1, 1);
  77. float shininess = 1.0;
  78. RS::CanvasItemTextureFilter texture_filter = RS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT;
  79. RS::CanvasItemTextureRepeat texture_repeat = RS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT;
  80. RID uniform_sets[RS::CANVAS_ITEM_TEXTURE_FILTER_MAX][RS::CANVAS_ITEM_TEXTURE_REPEAT_MAX];
  81. Size2i size_cache = Size2i(1, 1);
  82. bool use_normal_cache = false;
  83. bool use_specular_cache = false;
  84. bool cleared_cache = true;
  85. void clear_sets();
  86. ~CanvasTexture();
  87. };
  88. RID_Owner<CanvasTexture, true> canvas_texture_owner;
  89. /* Texture API */
  90. class Texture {
  91. public:
  92. TextureType type;
  93. RS::TextureLayeredType layered_type = RS::TEXTURE_LAYERED_2D_ARRAY;
  94. RenderingDevice::TextureType rd_type;
  95. RID rd_texture;
  96. RID rd_texture_srgb;
  97. RenderingDevice::DataFormat rd_format;
  98. RenderingDevice::DataFormat rd_format_srgb;
  99. RD::TextureView rd_view;
  100. Image::Format format;
  101. Image::Format validated_format;
  102. int width;
  103. int height;
  104. int depth;
  105. int layers;
  106. int mipmaps;
  107. int height_2d;
  108. int width_2d;
  109. struct BufferSlice3D {
  110. Size2i size;
  111. uint32_t offset = 0;
  112. uint32_t buffer_size = 0;
  113. };
  114. Vector<BufferSlice3D> buffer_slices_3d;
  115. uint32_t buffer_size_3d = 0;
  116. bool is_render_target;
  117. bool is_proxy;
  118. Ref<Image> image_cache_2d;
  119. String path;
  120. RID proxy_to;
  121. Vector<RID> proxies;
  122. HashSet<RID> lightmap_users;
  123. RS::TextureDetectCallback detect_3d_callback = nullptr;
  124. void *detect_3d_callback_ud = nullptr;
  125. RS::TextureDetectCallback detect_normal_callback = nullptr;
  126. void *detect_normal_callback_ud = nullptr;
  127. RS::TextureDetectRoughnessCallback detect_roughness_callback = nullptr;
  128. void *detect_roughness_callback_ud = nullptr;
  129. CanvasTexture *canvas_texture = nullptr;
  130. void cleanup();
  131. };
  132. //textures can be created from threads, so this RID_Owner is thread safe
  133. mutable RID_Owner<Texture, true> texture_owner;
  134. Texture *get_texture(RID p_rid) { return texture_owner.get_or_null(p_rid); };
  135. struct TextureToRDFormat {
  136. RD::DataFormat format;
  137. RD::DataFormat format_srgb;
  138. RD::TextureSwizzle swizzle_r;
  139. RD::TextureSwizzle swizzle_g;
  140. RD::TextureSwizzle swizzle_b;
  141. RD::TextureSwizzle swizzle_a;
  142. TextureToRDFormat() {
  143. format = RD::DATA_FORMAT_MAX;
  144. format_srgb = RD::DATA_FORMAT_MAX;
  145. swizzle_r = RD::TEXTURE_SWIZZLE_R;
  146. swizzle_g = RD::TEXTURE_SWIZZLE_G;
  147. swizzle_b = RD::TEXTURE_SWIZZLE_B;
  148. swizzle_a = RD::TEXTURE_SWIZZLE_A;
  149. }
  150. };
  151. Ref<Image> _validate_texture_format(const Ref<Image> &p_image, TextureToRDFormat &r_format);
  152. void _texture_2d_update(RID p_texture, const Ref<Image> &p_image, int p_layer = 0, bool p_immediate = false);
  153. /* DECAL API */
  154. struct DecalAtlas {
  155. struct Texture {
  156. int panorama_to_dp_users;
  157. int users;
  158. Rect2 uv_rect;
  159. };
  160. struct SortItem {
  161. RID texture;
  162. Size2i pixel_size;
  163. Size2i size;
  164. Point2i pos;
  165. bool operator<(const SortItem &p_item) const {
  166. //sort larger to smaller
  167. if (size.height == p_item.size.height) {
  168. return size.width > p_item.size.width;
  169. } else {
  170. return size.height > p_item.size.height;
  171. }
  172. }
  173. };
  174. HashMap<RID, Texture> textures;
  175. bool dirty = true;
  176. int mipmaps = 5;
  177. RID texture;
  178. RID texture_srgb;
  179. struct MipMap {
  180. RID fb;
  181. RID texture;
  182. Size2i size;
  183. };
  184. Vector<MipMap> texture_mipmaps;
  185. Size2i size;
  186. } decal_atlas;
  187. struct Decal {
  188. Vector3 extents = Vector3(1, 1, 1);
  189. RID textures[RS::DECAL_TEXTURE_MAX];
  190. float emission_energy = 1.0;
  191. float albedo_mix = 1.0;
  192. Color modulate = Color(1, 1, 1, 1);
  193. uint32_t cull_mask = (1 << 20) - 1;
  194. float upper_fade = 0.3;
  195. float lower_fade = 0.3;
  196. bool distance_fade = false;
  197. float distance_fade_begin = 40.0;
  198. float distance_fade_length = 10.0;
  199. float normal_fade = 0.0;
  200. Dependency dependency;
  201. };
  202. mutable RID_Owner<Decal, true> decal_owner;
  203. Decal *get_decal(RID p_rid) const { return decal_owner.get_or_null(p_rid); };
  204. /* RENDER TARGET API */
  205. struct RenderTarget {
  206. Size2i size;
  207. uint32_t view_count;
  208. RID framebuffer;
  209. RID color;
  210. RID color_multisample; // Needed when MSAA is enabled.
  211. RS::ViewportMSAA msaa = RS::VIEWPORT_MSAA_DISABLED;
  212. //used for retrieving from CPU
  213. RD::DataFormat color_format = RD::DATA_FORMAT_R4G4_UNORM_PACK8;
  214. RD::DataFormat color_format_srgb = RD::DATA_FORMAT_R4G4_UNORM_PACK8;
  215. Image::Format image_format = Image::FORMAT_L8;
  216. bool is_transparent = false;
  217. bool sdf_enabled = false;
  218. RID backbuffer; //used for effects
  219. RID backbuffer_fb;
  220. RID backbuffer_mipmap0;
  221. Vector<RID> backbuffer_mipmaps;
  222. RID framebuffer_uniform_set;
  223. RID backbuffer_uniform_set;
  224. RID sdf_buffer_write;
  225. RID sdf_buffer_write_fb;
  226. RID sdf_buffer_process[2];
  227. RID sdf_buffer_read;
  228. RID sdf_buffer_process_uniform_sets[2];
  229. RS::ViewportSDFOversize sdf_oversize = RS::VIEWPORT_SDF_OVERSIZE_120_PERCENT;
  230. RS::ViewportSDFScale sdf_scale = RS::VIEWPORT_SDF_SCALE_50_PERCENT;
  231. Size2i process_size;
  232. // VRS
  233. RS::ViewportVRSMode vrs_mode = RS::VIEWPORT_VRS_DISABLED;
  234. RID vrs_texture;
  235. //texture generated for this owner (nor RD).
  236. RID texture;
  237. bool was_used;
  238. //clear request
  239. bool clear_requested;
  240. Color clear_color;
  241. };
  242. mutable RID_Owner<RenderTarget> render_target_owner;
  243. RenderTarget *get_render_target(RID p_rid) const { return render_target_owner.get_or_null(p_rid); };
  244. void _clear_render_target(RenderTarget *rt);
  245. void _update_render_target(RenderTarget *rt);
  246. void _create_render_target_backbuffer(RenderTarget *rt);
  247. void _render_target_allocate_sdf(RenderTarget *rt);
  248. void _render_target_clear_sdf(RenderTarget *rt);
  249. Rect2i _render_target_get_sdf_rect(const RenderTarget *rt) const;
  250. struct RenderTargetSDF {
  251. enum {
  252. SHADER_LOAD,
  253. SHADER_LOAD_SHRINK,
  254. SHADER_PROCESS,
  255. SHADER_PROCESS_OPTIMIZED,
  256. SHADER_STORE,
  257. SHADER_STORE_SHRINK,
  258. SHADER_MAX
  259. };
  260. struct PushConstant {
  261. int32_t size[2];
  262. int32_t stride;
  263. int32_t shift;
  264. int32_t base_size[2];
  265. int32_t pad[2];
  266. };
  267. CanvasSdfShaderRD shader;
  268. RID shader_version;
  269. RID pipelines[SHADER_MAX];
  270. } rt_sdf;
  271. public:
  272. static TextureStorage *get_singleton();
  273. _FORCE_INLINE_ RID texture_rd_get_default(DefaultRDTexture p_texture) {
  274. return default_rd_textures[p_texture];
  275. }
  276. TextureStorage();
  277. virtual ~TextureStorage();
  278. /* Canvas Texture API */
  279. bool owns_canvas_texture(RID p_rid) { return canvas_texture_owner.owns(p_rid); };
  280. virtual RID canvas_texture_allocate() override;
  281. virtual void canvas_texture_initialize(RID p_rid) override;
  282. virtual void canvas_texture_free(RID p_rid) override;
  283. virtual void canvas_texture_set_channel(RID p_canvas_texture, RS::CanvasTextureChannel p_channel, RID p_texture) override;
  284. virtual void canvas_texture_set_shading_parameters(RID p_canvas_texture, const Color &p_base_color, float p_shininess) override;
  285. virtual void canvas_texture_set_texture_filter(RID p_item, RS::CanvasItemTextureFilter p_filter) override;
  286. virtual void canvas_texture_set_texture_repeat(RID p_item, RS::CanvasItemTextureRepeat p_repeat) override;
  287. bool canvas_texture_get_uniform_set(RID p_texture, RS::CanvasItemTextureFilter p_base_filter, RS::CanvasItemTextureRepeat p_base_repeat, RID p_base_shader, int p_base_set, RID &r_uniform_set, Size2i &r_size, Color &r_specular_shininess, bool &r_use_normal, bool &r_use_specular);
  288. /* Texture API */
  289. bool owns_texture(RID p_rid) const { return texture_owner.owns(p_rid); };
  290. virtual bool can_create_resources_async() const override;
  291. virtual RID texture_allocate() override;
  292. virtual void texture_free(RID p_rid) override;
  293. virtual void texture_2d_initialize(RID p_texture, const Ref<Image> &p_image) override;
  294. virtual void texture_2d_layered_initialize(RID p_texture, const Vector<Ref<Image>> &p_layers, RS::TextureLayeredType p_layered_type) override;
  295. virtual void texture_3d_initialize(RID p_texture, Image::Format, int p_width, int p_height, int p_depth, bool p_mipmaps, const Vector<Ref<Image>> &p_data) override;
  296. virtual void texture_proxy_initialize(RID p_texture, RID p_base) override; //all slices, then all the mipmaps, must be coherent
  297. virtual void texture_2d_update(RID p_texture, const Ref<Image> &p_image, int p_layer = 0) override;
  298. virtual void texture_3d_update(RID p_texture, const Vector<Ref<Image>> &p_data) override;
  299. virtual void texture_proxy_update(RID p_proxy, RID p_base) override;
  300. //these two APIs can be used together or in combination with the others.
  301. virtual void texture_2d_placeholder_initialize(RID p_texture) override;
  302. virtual void texture_2d_layered_placeholder_initialize(RID p_texture, RenderingServer::TextureLayeredType p_layered_type) override;
  303. virtual void texture_3d_placeholder_initialize(RID p_texture) override;
  304. virtual Ref<Image> texture_2d_get(RID p_texture) const override;
  305. virtual Ref<Image> texture_2d_layer_get(RID p_texture, int p_layer) const override;
  306. virtual Vector<Ref<Image>> texture_3d_get(RID p_texture) const override;
  307. virtual void texture_replace(RID p_texture, RID p_by_texture) override;
  308. virtual void texture_set_size_override(RID p_texture, int p_width, int p_height) override;
  309. virtual void texture_set_path(RID p_texture, const String &p_path) override;
  310. virtual String texture_get_path(RID p_texture) const override;
  311. virtual void texture_set_detect_3d_callback(RID p_texture, RS::TextureDetectCallback p_callback, void *p_userdata) override;
  312. virtual void texture_set_detect_normal_callback(RID p_texture, RS::TextureDetectCallback p_callback, void *p_userdata) override;
  313. virtual void texture_set_detect_roughness_callback(RID p_texture, RS::TextureDetectRoughnessCallback p_callback, void *p_userdata) override;
  314. virtual void texture_debug_usage(List<RS::TextureInfo> *r_info) override;
  315. virtual void texture_set_force_redraw_if_visible(RID p_texture, bool p_enable) override;
  316. virtual Size2 texture_size_with_proxy(RID p_proxy) override;
  317. //internal usage
  318. _FORCE_INLINE_ TextureType texture_get_type(RID p_texture) {
  319. RendererRD::TextureStorage::Texture *tex = texture_owner.get_or_null(p_texture);
  320. if (tex == nullptr) {
  321. return TYPE_2D;
  322. }
  323. return tex->type;
  324. }
  325. _FORCE_INLINE_ int texture_get_layers(RID p_texture) {
  326. RendererRD::TextureStorage::Texture *tex = texture_owner.get_or_null(p_texture);
  327. if (tex == nullptr) {
  328. return 1;
  329. }
  330. return tex->layers;
  331. }
  332. _FORCE_INLINE_ RID texture_get_rd_texture(RID p_texture, bool p_srgb = false) {
  333. if (p_texture.is_null()) {
  334. return RID();
  335. }
  336. RendererRD::TextureStorage::Texture *tex = texture_owner.get_or_null(p_texture);
  337. if (!tex) {
  338. return RID();
  339. }
  340. return (p_srgb && tex->rd_texture_srgb.is_valid()) ? tex->rd_texture_srgb : tex->rd_texture;
  341. }
  342. _FORCE_INLINE_ Size2i texture_2d_get_size(RID p_texture) {
  343. if (p_texture.is_null()) {
  344. return Size2i();
  345. }
  346. RendererRD::TextureStorage::Texture *tex = texture_owner.get_or_null(p_texture);
  347. if (!tex) {
  348. return Size2i();
  349. }
  350. return Size2i(tex->width_2d, tex->height_2d);
  351. }
  352. /* DECAL API */
  353. void update_decal_atlas();
  354. bool owns_decal(RID p_rid) const { return decal_owner.owns(p_rid); };
  355. RID decal_atlas_get_texture() const;
  356. RID decal_atlas_get_texture_srgb() const;
  357. _FORCE_INLINE_ Rect2 decal_atlas_get_texture_rect(RID p_texture) {
  358. DecalAtlas::Texture *t = decal_atlas.textures.getptr(p_texture);
  359. if (!t) {
  360. return Rect2();
  361. }
  362. return t->uv_rect;
  363. }
  364. virtual RID decal_allocate() override;
  365. virtual void decal_initialize(RID p_decal) override;
  366. virtual void decal_free(RID p_rid) override;
  367. virtual void decal_set_extents(RID p_decal, const Vector3 &p_extents) override;
  368. virtual void decal_set_texture(RID p_decal, RS::DecalTexture p_type, RID p_texture) override;
  369. virtual void decal_set_emission_energy(RID p_decal, float p_energy) override;
  370. virtual void decal_set_albedo_mix(RID p_decal, float p_mix) override;
  371. virtual void decal_set_modulate(RID p_decal, const Color &p_modulate) override;
  372. virtual void decal_set_cull_mask(RID p_decal, uint32_t p_layers) override;
  373. virtual void decal_set_distance_fade(RID p_decal, bool p_enabled, float p_begin, float p_length) override;
  374. virtual void decal_set_fade(RID p_decal, float p_above, float p_below) override;
  375. virtual void decal_set_normal_fade(RID p_decal, float p_fade) override;
  376. void decal_atlas_mark_dirty_on_texture(RID p_texture);
  377. void decal_atlas_remove_texture(RID p_texture);
  378. virtual void texture_add_to_decal_atlas(RID p_texture, bool p_panorama_to_dp = false) override;
  379. virtual void texture_remove_from_decal_atlas(RID p_texture, bool p_panorama_to_dp = false) override;
  380. _FORCE_INLINE_ Vector3 decal_get_extents(RID p_decal) {
  381. const Decal *decal = decal_owner.get_or_null(p_decal);
  382. return decal->extents;
  383. }
  384. _FORCE_INLINE_ RID decal_get_texture(RID p_decal, RS::DecalTexture p_texture) {
  385. const Decal *decal = decal_owner.get_or_null(p_decal);
  386. return decal->textures[p_texture];
  387. }
  388. _FORCE_INLINE_ Color decal_get_modulate(RID p_decal) {
  389. const Decal *decal = decal_owner.get_or_null(p_decal);
  390. return decal->modulate;
  391. }
  392. _FORCE_INLINE_ float decal_get_emission_energy(RID p_decal) {
  393. const Decal *decal = decal_owner.get_or_null(p_decal);
  394. return decal->emission_energy;
  395. }
  396. _FORCE_INLINE_ float decal_get_albedo_mix(RID p_decal) {
  397. const Decal *decal = decal_owner.get_or_null(p_decal);
  398. return decal->albedo_mix;
  399. }
  400. _FORCE_INLINE_ uint32_t decal_get_cull_mask(RID p_decal) {
  401. const Decal *decal = decal_owner.get_or_null(p_decal);
  402. return decal->cull_mask;
  403. }
  404. _FORCE_INLINE_ float decal_get_upper_fade(RID p_decal) {
  405. const Decal *decal = decal_owner.get_or_null(p_decal);
  406. return decal->upper_fade;
  407. }
  408. _FORCE_INLINE_ float decal_get_lower_fade(RID p_decal) {
  409. const Decal *decal = decal_owner.get_or_null(p_decal);
  410. return decal->lower_fade;
  411. }
  412. _FORCE_INLINE_ float decal_get_normal_fade(RID p_decal) {
  413. const Decal *decal = decal_owner.get_or_null(p_decal);
  414. return decal->normal_fade;
  415. }
  416. _FORCE_INLINE_ bool decal_is_distance_fade_enabled(RID p_decal) {
  417. const Decal *decal = decal_owner.get_or_null(p_decal);
  418. return decal->distance_fade;
  419. }
  420. _FORCE_INLINE_ float decal_get_distance_fade_begin(RID p_decal) {
  421. const Decal *decal = decal_owner.get_or_null(p_decal);
  422. return decal->distance_fade_begin;
  423. }
  424. _FORCE_INLINE_ float decal_get_distance_fade_length(RID p_decal) {
  425. const Decal *decal = decal_owner.get_or_null(p_decal);
  426. return decal->distance_fade_length;
  427. }
  428. virtual AABB decal_get_aabb(RID p_decal) const override;
  429. Dependency *decal_get_dependency(RID p_decal);
  430. /* RENDER TARGET API */
  431. bool owns_render_target(RID p_rid) const { return render_target_owner.owns(p_rid); };
  432. virtual RID render_target_create() override;
  433. virtual void render_target_free(RID p_rid) override;
  434. virtual void render_target_set_position(RID p_render_target, int p_x, int p_y) override;
  435. virtual void render_target_set_size(RID p_render_target, int p_width, int p_height, uint32_t p_view_count) override;
  436. virtual RID render_target_get_texture(RID p_render_target) override;
  437. virtual void render_target_set_external_texture(RID p_render_target, unsigned int p_texture_id) override;
  438. virtual void render_target_set_transparent(RID p_render_target, bool p_is_transparent) override;
  439. virtual void render_target_set_direct_to_screen(RID p_render_target, bool p_direct_to_screen) override;
  440. virtual bool render_target_was_used(RID p_render_target) override;
  441. virtual void render_target_set_as_unused(RID p_render_target) override;
  442. virtual void render_target_set_msaa(RID p_render_target, RS::ViewportMSAA p_msaa) override;
  443. void render_target_copy_to_back_buffer(RID p_render_target, const Rect2i &p_region, bool p_gen_mipmaps);
  444. void render_target_clear_back_buffer(RID p_render_target, const Rect2i &p_region, const Color &p_color);
  445. void render_target_gen_back_buffer_mipmaps(RID p_render_target, const Rect2i &p_region);
  446. RID render_target_get_back_buffer_uniform_set(RID p_render_target, RID p_base_shader);
  447. virtual void render_target_request_clear(RID p_render_target, const Color &p_clear_color) override;
  448. virtual bool render_target_is_clear_requested(RID p_render_target) override;
  449. virtual Color render_target_get_clear_request_color(RID p_render_target) override;
  450. virtual void render_target_disable_clear_request(RID p_render_target) override;
  451. virtual void render_target_do_clear_request(RID p_render_target) override;
  452. virtual void render_target_set_sdf_size_and_scale(RID p_render_target, RS::ViewportSDFOversize p_size, RS::ViewportSDFScale p_scale) override;
  453. RID render_target_get_sdf_texture(RID p_render_target);
  454. RID render_target_get_sdf_framebuffer(RID p_render_target);
  455. void render_target_sdf_process(RID p_render_target);
  456. virtual Rect2i render_target_get_sdf_rect(RID p_render_target) const override;
  457. virtual void render_target_mark_sdf_enabled(RID p_render_target, bool p_enabled) override;
  458. bool render_target_is_sdf_enabled(RID p_render_target) const;
  459. virtual void render_target_set_vrs_mode(RID p_render_target, RS::ViewportVRSMode p_mode) override;
  460. virtual void render_target_set_vrs_texture(RID p_render_target, RID p_texture) override;
  461. RS::ViewportVRSMode render_target_get_vrs_mode(RID p_render_target) const;
  462. RID render_target_get_vrs_texture(RID p_render_target) const;
  463. Size2 render_target_get_size(RID p_render_target);
  464. RID render_target_get_rd_framebuffer(RID p_render_target);
  465. RID render_target_get_rd_texture(RID p_render_target);
  466. RID render_target_get_rd_backbuffer(RID p_render_target);
  467. RID render_target_get_rd_backbuffer_framebuffer(RID p_render_target);
  468. RID render_target_get_framebuffer_uniform_set(RID p_render_target);
  469. RID render_target_get_backbuffer_uniform_set(RID p_render_target);
  470. void render_target_set_framebuffer_uniform_set(RID p_render_target, RID p_uniform_set);
  471. void render_target_set_backbuffer_uniform_set(RID p_render_target, RID p_uniform_set);
  472. };
  473. } // namespace RendererRD
  474. #endif // TEXTURE_STORAGE_RD_H