texture_storage.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  1. /**************************************************************************/
  2. /* texture_storage.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 TEXTURE_STORAGE_RD_H
  31. #define TEXTURE_STORAGE_RD_H
  32. #include "core/templates/local_vector.h"
  33. #include "core/templates/paged_array.h"
  34. #include "core/templates/rid_owner.h"
  35. #include "servers/rendering/renderer_rd/shaders/canvas_sdf.glsl.gen.h"
  36. #include "servers/rendering/renderer_rd/storage_rd/forward_id_storage.h"
  37. #include "servers/rendering/rendering_server_default.h"
  38. #include "servers/rendering/storage/texture_storage.h"
  39. #include "servers/rendering/storage/utilities.h"
  40. namespace RendererRD {
  41. class LightStorage;
  42. class MaterialStorage;
  43. class TextureStorage : public RendererTextureStorage {
  44. public:
  45. enum DefaultRDTexture {
  46. DEFAULT_RD_TEXTURE_WHITE,
  47. DEFAULT_RD_TEXTURE_BLACK,
  48. DEFAULT_RD_TEXTURE_TRANSPARENT,
  49. DEFAULT_RD_TEXTURE_NORMAL,
  50. DEFAULT_RD_TEXTURE_ANISO,
  51. DEFAULT_RD_TEXTURE_DEPTH,
  52. DEFAULT_RD_TEXTURE_MULTIMESH_BUFFER,
  53. DEFAULT_RD_TEXTURE_CUBEMAP_BLACK,
  54. DEFAULT_RD_TEXTURE_CUBEMAP_ARRAY_BLACK,
  55. DEFAULT_RD_TEXTURE_CUBEMAP_WHITE,
  56. DEFAULT_RD_TEXTURE_CUBEMAP_ARRAY_WHITE,
  57. DEFAULT_RD_TEXTURE_3D_WHITE,
  58. DEFAULT_RD_TEXTURE_3D_BLACK,
  59. DEFAULT_RD_TEXTURE_2D_ARRAY_WHITE,
  60. DEFAULT_RD_TEXTURE_2D_ARRAY_BLACK,
  61. DEFAULT_RD_TEXTURE_2D_ARRAY_NORMAL,
  62. DEFAULT_RD_TEXTURE_2D_ARRAY_DEPTH,
  63. DEFAULT_RD_TEXTURE_2D_UINT,
  64. DEFAULT_RD_TEXTURE_VRS,
  65. DEFAULT_RD_TEXTURE_MAX
  66. };
  67. enum TextureType {
  68. TYPE_2D,
  69. TYPE_LAYERED,
  70. TYPE_3D
  71. };
  72. private:
  73. friend class LightStorage;
  74. friend class MaterialStorage;
  75. static TextureStorage *singleton;
  76. RID default_rd_textures[DEFAULT_RD_TEXTURE_MAX];
  77. /* Canvas Texture API */
  78. class CanvasTexture {
  79. public:
  80. RID diffuse;
  81. RID normal_map;
  82. RID specular;
  83. Color specular_color = Color(1, 1, 1, 1);
  84. float shininess = 1.0;
  85. RS::CanvasItemTextureFilter texture_filter = RS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT;
  86. RS::CanvasItemTextureRepeat texture_repeat = RS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT;
  87. RID uniform_sets[RS::CANVAS_ITEM_TEXTURE_FILTER_MAX][RS::CANVAS_ITEM_TEXTURE_REPEAT_MAX];
  88. Size2i size_cache = Size2i(1, 1);
  89. bool use_normal_cache = false;
  90. bool use_specular_cache = false;
  91. bool cleared_cache = true;
  92. void clear_sets();
  93. ~CanvasTexture();
  94. };
  95. RID_Owner<CanvasTexture, true> canvas_texture_owner;
  96. /* Texture API */
  97. struct RenderTarget;
  98. class Texture {
  99. public:
  100. TextureType type;
  101. RS::TextureLayeredType layered_type = RS::TEXTURE_LAYERED_2D_ARRAY;
  102. RenderingDevice::TextureType rd_type;
  103. RID rd_texture;
  104. RID rd_texture_srgb;
  105. RenderingDevice::DataFormat rd_format;
  106. RenderingDevice::DataFormat rd_format_srgb;
  107. RD::TextureView rd_view;
  108. Image::Format format;
  109. Image::Format validated_format;
  110. int width;
  111. int height;
  112. int depth;
  113. int layers;
  114. int mipmaps;
  115. int height_2d;
  116. int width_2d;
  117. struct BufferSlice3D {
  118. Size2i size;
  119. uint32_t offset = 0;
  120. uint32_t buffer_size = 0;
  121. };
  122. Vector<BufferSlice3D> buffer_slices_3d;
  123. uint32_t buffer_size_3d = 0;
  124. RenderTarget *render_target = nullptr;
  125. bool is_render_target;
  126. bool is_proxy;
  127. Ref<Image> image_cache_2d;
  128. String path;
  129. RID proxy_to;
  130. Vector<RID> proxies;
  131. HashSet<RID> lightmap_users;
  132. RS::TextureDetectCallback detect_3d_callback = nullptr;
  133. void *detect_3d_callback_ud = nullptr;
  134. RS::TextureDetectCallback detect_normal_callback = nullptr;
  135. void *detect_normal_callback_ud = nullptr;
  136. RS::TextureDetectRoughnessCallback detect_roughness_callback = nullptr;
  137. void *detect_roughness_callback_ud = nullptr;
  138. CanvasTexture *canvas_texture = nullptr;
  139. void cleanup();
  140. };
  141. //textures can be created from threads, so this RID_Owner is thread safe
  142. mutable RID_Owner<Texture, true> texture_owner;
  143. Texture *get_texture(RID p_rid) { return texture_owner.get_or_null(p_rid); };
  144. struct TextureToRDFormat {
  145. RD::DataFormat format;
  146. RD::DataFormat format_srgb;
  147. RD::TextureSwizzle swizzle_r;
  148. RD::TextureSwizzle swizzle_g;
  149. RD::TextureSwizzle swizzle_b;
  150. RD::TextureSwizzle swizzle_a;
  151. TextureToRDFormat() {
  152. format = RD::DATA_FORMAT_MAX;
  153. format_srgb = RD::DATA_FORMAT_MAX;
  154. swizzle_r = RD::TEXTURE_SWIZZLE_R;
  155. swizzle_g = RD::TEXTURE_SWIZZLE_G;
  156. swizzle_b = RD::TEXTURE_SWIZZLE_B;
  157. swizzle_a = RD::TEXTURE_SWIZZLE_A;
  158. }
  159. };
  160. Ref<Image> _validate_texture_format(const Ref<Image> &p_image, TextureToRDFormat &r_format);
  161. void _texture_2d_update(RID p_texture, const Ref<Image> &p_image, int p_layer = 0, bool p_immediate = false);
  162. /* DECAL API */
  163. struct DecalAtlas {
  164. struct Texture {
  165. int panorama_to_dp_users;
  166. int users;
  167. Rect2 uv_rect;
  168. };
  169. struct SortItem {
  170. RID texture;
  171. Size2i pixel_size;
  172. Size2i size;
  173. Point2i pos;
  174. bool operator<(const SortItem &p_item) const {
  175. //sort larger to smaller
  176. if (size.height == p_item.size.height) {
  177. return size.width > p_item.size.width;
  178. } else {
  179. return size.height > p_item.size.height;
  180. }
  181. }
  182. };
  183. HashMap<RID, Texture> textures;
  184. bool dirty = true;
  185. int mipmaps = 5;
  186. RID texture;
  187. RID texture_srgb;
  188. struct MipMap {
  189. RID fb;
  190. RID texture;
  191. Size2i size;
  192. };
  193. Vector<MipMap> texture_mipmaps;
  194. Size2i size;
  195. } decal_atlas;
  196. struct Decal {
  197. Vector3 size = Vector3(2, 2, 2);
  198. RID textures[RS::DECAL_TEXTURE_MAX];
  199. float emission_energy = 1.0;
  200. float albedo_mix = 1.0;
  201. Color modulate = Color(1, 1, 1, 1);
  202. uint32_t cull_mask = (1 << 20) - 1;
  203. float upper_fade = 0.3;
  204. float lower_fade = 0.3;
  205. bool distance_fade = false;
  206. float distance_fade_begin = 40.0;
  207. float distance_fade_length = 10.0;
  208. float normal_fade = 0.0;
  209. Dependency dependency;
  210. };
  211. mutable RID_Owner<Decal, true> decal_owner;
  212. /* DECAL INSTANCE */
  213. struct DecalInstance {
  214. RID decal;
  215. Transform3D transform;
  216. float sorting_offset = 0.0;
  217. uint32_t cull_mask = 0;
  218. RendererRD::ForwardID forward_id = -1;
  219. };
  220. mutable RID_Owner<DecalInstance> decal_instance_owner;
  221. /* DECAL DATA (UBO) */
  222. struct DecalData {
  223. float xform[16];
  224. float inv_extents[3];
  225. float albedo_mix;
  226. float albedo_rect[4];
  227. float normal_rect[4];
  228. float orm_rect[4];
  229. float emission_rect[4];
  230. float modulate[4];
  231. float emission_energy;
  232. uint32_t mask;
  233. float upper_fade;
  234. float lower_fade;
  235. float normal_xform[12];
  236. float normal[3];
  237. float normal_fade;
  238. };
  239. struct DecalInstanceSort {
  240. float depth;
  241. DecalInstance *decal_instance;
  242. Decal *decal;
  243. bool operator<(const DecalInstanceSort &p_sort) const {
  244. return depth < p_sort.depth;
  245. }
  246. };
  247. uint32_t max_decals = 0;
  248. uint32_t decal_count = 0;
  249. DecalData *decals = nullptr;
  250. DecalInstanceSort *decal_sort = nullptr;
  251. RID decal_buffer;
  252. /* RENDER TARGET API */
  253. struct RenderTarget {
  254. Size2i size;
  255. uint32_t view_count;
  256. RID color;
  257. Vector<RID> color_slices;
  258. RID color_multisample; // Needed when MSAA is enabled.
  259. RS::ViewportMSAA msaa = RS::VIEWPORT_MSAA_DISABLED;
  260. //used for retrieving from CPU
  261. RD::DataFormat color_format = RD::DATA_FORMAT_R4G4_UNORM_PACK8;
  262. RD::DataFormat color_format_srgb = RD::DATA_FORMAT_R4G4_UNORM_PACK8;
  263. Image::Format image_format = Image::FORMAT_L8;
  264. bool is_transparent = false;
  265. bool sdf_enabled = false;
  266. RID backbuffer; //used for effects
  267. RID backbuffer_fb;
  268. RID backbuffer_mipmap0;
  269. Vector<RID> backbuffer_mipmaps;
  270. RID framebuffer_uniform_set;
  271. RID backbuffer_uniform_set;
  272. RID sdf_buffer_write;
  273. RID sdf_buffer_write_fb;
  274. RID sdf_buffer_process[2];
  275. RID sdf_buffer_read;
  276. RID sdf_buffer_process_uniform_sets[2];
  277. RS::ViewportSDFOversize sdf_oversize = RS::VIEWPORT_SDF_OVERSIZE_120_PERCENT;
  278. RS::ViewportSDFScale sdf_scale = RS::VIEWPORT_SDF_SCALE_50_PERCENT;
  279. Size2i process_size;
  280. // VRS
  281. RS::ViewportVRSMode vrs_mode = RS::VIEWPORT_VRS_DISABLED;
  282. RID vrs_texture;
  283. // overridden textures
  284. struct RTOverridden {
  285. RID color;
  286. RID depth;
  287. RID velocity;
  288. // In a multiview scenario, which is the most likely where we
  289. // override our destination textures, we need to obtain slices
  290. // for each layer of these textures.
  291. // These are likely changing every frame as we loop through
  292. // texture chains hence we add a cache to manage these slices.
  293. // For this we define a key using the RID of the texture and
  294. // the layer for which we create a slice.
  295. struct SliceKey {
  296. RID rid;
  297. uint32_t layer = 0;
  298. bool operator==(const SliceKey &p_val) const {
  299. return (rid == p_val.rid) && (layer == p_val.layer);
  300. }
  301. static uint32_t hash(const SliceKey &p_val) {
  302. uint32_t h = hash_one_uint64(p_val.rid.get_id());
  303. h = hash_murmur3_one_32(p_val.layer, h);
  304. return hash_fmix32(h);
  305. }
  306. SliceKey() {}
  307. SliceKey(RID p_rid, uint32_t p_layer) {
  308. rid = p_rid;
  309. layer = p_layer;
  310. }
  311. };
  312. mutable HashMap<SliceKey, RID, SliceKey> cached_slices;
  313. } overridden;
  314. //texture generated for this owner (nor RD).
  315. RID texture;
  316. bool was_used;
  317. //clear request
  318. bool clear_requested;
  319. Color clear_color;
  320. RID get_framebuffer();
  321. };
  322. mutable RID_Owner<RenderTarget> render_target_owner;
  323. RenderTarget *get_render_target(RID p_rid) const { return render_target_owner.get_or_null(p_rid); };
  324. void _clear_render_target(RenderTarget *rt);
  325. void _update_render_target(RenderTarget *rt);
  326. void _create_render_target_backbuffer(RenderTarget *rt);
  327. void _render_target_allocate_sdf(RenderTarget *rt);
  328. void _render_target_clear_sdf(RenderTarget *rt);
  329. Rect2i _render_target_get_sdf_rect(const RenderTarget *rt) const;
  330. struct RenderTargetSDF {
  331. enum {
  332. SHADER_LOAD,
  333. SHADER_LOAD_SHRINK,
  334. SHADER_PROCESS,
  335. SHADER_PROCESS_OPTIMIZED,
  336. SHADER_STORE,
  337. SHADER_STORE_SHRINK,
  338. SHADER_MAX
  339. };
  340. struct PushConstant {
  341. int32_t size[2];
  342. int32_t stride;
  343. int32_t shift;
  344. int32_t base_size[2];
  345. int32_t pad[2];
  346. };
  347. CanvasSdfShaderRD shader;
  348. RID shader_version;
  349. RID pipelines[SHADER_MAX];
  350. } rt_sdf;
  351. public:
  352. static TextureStorage *get_singleton();
  353. _FORCE_INLINE_ RID texture_rd_get_default(DefaultRDTexture p_texture) {
  354. return default_rd_textures[p_texture];
  355. }
  356. TextureStorage();
  357. virtual ~TextureStorage();
  358. bool free(RID p_rid);
  359. /* Canvas Texture API */
  360. bool owns_canvas_texture(RID p_rid) { return canvas_texture_owner.owns(p_rid); };
  361. virtual RID canvas_texture_allocate() override;
  362. virtual void canvas_texture_initialize(RID p_rid) override;
  363. virtual void canvas_texture_free(RID p_rid) override;
  364. virtual void canvas_texture_set_channel(RID p_canvas_texture, RS::CanvasTextureChannel p_channel, RID p_texture) override;
  365. virtual void canvas_texture_set_shading_parameters(RID p_canvas_texture, const Color &p_base_color, float p_shininess) override;
  366. virtual void canvas_texture_set_texture_filter(RID p_item, RS::CanvasItemTextureFilter p_filter) override;
  367. virtual void canvas_texture_set_texture_repeat(RID p_item, RS::CanvasItemTextureRepeat p_repeat) override;
  368. 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);
  369. /* Texture API */
  370. bool owns_texture(RID p_rid) const { return texture_owner.owns(p_rid); };
  371. virtual bool can_create_resources_async() const override;
  372. virtual RID texture_allocate() override;
  373. virtual void texture_free(RID p_rid) override;
  374. virtual void texture_2d_initialize(RID p_texture, const Ref<Image> &p_image) override;
  375. virtual void texture_2d_layered_initialize(RID p_texture, const Vector<Ref<Image>> &p_layers, RS::TextureLayeredType p_layered_type) override;
  376. 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;
  377. virtual void texture_proxy_initialize(RID p_texture, RID p_base) override; //all slices, then all the mipmaps, must be coherent
  378. virtual void texture_2d_update(RID p_texture, const Ref<Image> &p_image, int p_layer = 0) override;
  379. virtual void texture_3d_update(RID p_texture, const Vector<Ref<Image>> &p_data) override;
  380. virtual void texture_proxy_update(RID p_proxy, RID p_base) override;
  381. //these two APIs can be used together or in combination with the others.
  382. virtual void texture_2d_placeholder_initialize(RID p_texture) override;
  383. virtual void texture_2d_layered_placeholder_initialize(RID p_texture, RenderingServer::TextureLayeredType p_layered_type) override;
  384. virtual void texture_3d_placeholder_initialize(RID p_texture) override;
  385. virtual Ref<Image> texture_2d_get(RID p_texture) const override;
  386. virtual Ref<Image> texture_2d_layer_get(RID p_texture, int p_layer) const override;
  387. virtual Vector<Ref<Image>> texture_3d_get(RID p_texture) const override;
  388. virtual void texture_replace(RID p_texture, RID p_by_texture) override;
  389. virtual void texture_set_size_override(RID p_texture, int p_width, int p_height) override;
  390. virtual void texture_set_path(RID p_texture, const String &p_path) override;
  391. virtual String texture_get_path(RID p_texture) const override;
  392. virtual void texture_set_detect_3d_callback(RID p_texture, RS::TextureDetectCallback p_callback, void *p_userdata) override;
  393. virtual void texture_set_detect_normal_callback(RID p_texture, RS::TextureDetectCallback p_callback, void *p_userdata) override;
  394. virtual void texture_set_detect_roughness_callback(RID p_texture, RS::TextureDetectRoughnessCallback p_callback, void *p_userdata) override;
  395. virtual void texture_debug_usage(List<RS::TextureInfo> *r_info) override;
  396. virtual void texture_set_force_redraw_if_visible(RID p_texture, bool p_enable) override;
  397. virtual Size2 texture_size_with_proxy(RID p_proxy) override;
  398. virtual RID texture_get_rd_texture(RID p_texture, bool p_srgb = false) const override;
  399. virtual uint64_t texture_get_native_handle(RID p_texture, bool p_srgb = false) const override;
  400. //internal usage
  401. _FORCE_INLINE_ TextureType texture_get_type(RID p_texture) {
  402. RendererRD::TextureStorage::Texture *tex = texture_owner.get_or_null(p_texture);
  403. if (tex == nullptr) {
  404. return TYPE_2D;
  405. }
  406. return tex->type;
  407. }
  408. _FORCE_INLINE_ int texture_get_layers(RID p_texture) {
  409. RendererRD::TextureStorage::Texture *tex = texture_owner.get_or_null(p_texture);
  410. if (tex == nullptr) {
  411. return 1;
  412. }
  413. return tex->layers;
  414. }
  415. _FORCE_INLINE_ Size2i texture_2d_get_size(RID p_texture) {
  416. if (p_texture.is_null()) {
  417. return Size2i();
  418. }
  419. RendererRD::TextureStorage::Texture *tex = texture_owner.get_or_null(p_texture);
  420. if (!tex) {
  421. return Size2i();
  422. }
  423. return Size2i(tex->width_2d, tex->height_2d);
  424. }
  425. /* DECAL API */
  426. void update_decal_atlas();
  427. bool owns_decal(RID p_rid) const { return decal_owner.owns(p_rid); };
  428. RID decal_atlas_get_texture() const;
  429. RID decal_atlas_get_texture_srgb() const;
  430. _FORCE_INLINE_ Rect2 decal_atlas_get_texture_rect(RID p_texture) {
  431. DecalAtlas::Texture *t = decal_atlas.textures.getptr(p_texture);
  432. if (!t) {
  433. return Rect2();
  434. }
  435. return t->uv_rect;
  436. }
  437. virtual RID decal_allocate() override;
  438. virtual void decal_initialize(RID p_decal) override;
  439. virtual void decal_free(RID p_rid) override;
  440. virtual void decal_set_size(RID p_decal, const Vector3 &p_size) override;
  441. virtual void decal_set_texture(RID p_decal, RS::DecalTexture p_type, RID p_texture) override;
  442. virtual void decal_set_emission_energy(RID p_decal, float p_energy) override;
  443. virtual void decal_set_albedo_mix(RID p_decal, float p_mix) override;
  444. virtual void decal_set_modulate(RID p_decal, const Color &p_modulate) override;
  445. virtual void decal_set_cull_mask(RID p_decal, uint32_t p_layers) override;
  446. virtual void decal_set_distance_fade(RID p_decal, bool p_enabled, float p_begin, float p_length) override;
  447. virtual void decal_set_fade(RID p_decal, float p_above, float p_below) override;
  448. virtual void decal_set_normal_fade(RID p_decal, float p_fade) override;
  449. void decal_atlas_mark_dirty_on_texture(RID p_texture);
  450. void decal_atlas_remove_texture(RID p_texture);
  451. virtual void texture_add_to_decal_atlas(RID p_texture, bool p_panorama_to_dp = false) override;
  452. virtual void texture_remove_from_decal_atlas(RID p_texture, bool p_panorama_to_dp = false) override;
  453. _FORCE_INLINE_ Vector3 decal_get_size(RID p_decal) {
  454. const Decal *decal = decal_owner.get_or_null(p_decal);
  455. return decal->size;
  456. }
  457. _FORCE_INLINE_ RID decal_get_texture(RID p_decal, RS::DecalTexture p_texture) {
  458. const Decal *decal = decal_owner.get_or_null(p_decal);
  459. return decal->textures[p_texture];
  460. }
  461. _FORCE_INLINE_ Color decal_get_modulate(RID p_decal) {
  462. const Decal *decal = decal_owner.get_or_null(p_decal);
  463. return decal->modulate;
  464. }
  465. _FORCE_INLINE_ float decal_get_emission_energy(RID p_decal) {
  466. const Decal *decal = decal_owner.get_or_null(p_decal);
  467. return decal->emission_energy;
  468. }
  469. _FORCE_INLINE_ float decal_get_albedo_mix(RID p_decal) {
  470. const Decal *decal = decal_owner.get_or_null(p_decal);
  471. return decal->albedo_mix;
  472. }
  473. _FORCE_INLINE_ uint32_t decal_get_cull_mask(RID p_decal) {
  474. const Decal *decal = decal_owner.get_or_null(p_decal);
  475. return decal->cull_mask;
  476. }
  477. _FORCE_INLINE_ float decal_get_upper_fade(RID p_decal) {
  478. const Decal *decal = decal_owner.get_or_null(p_decal);
  479. return decal->upper_fade;
  480. }
  481. _FORCE_INLINE_ float decal_get_lower_fade(RID p_decal) {
  482. const Decal *decal = decal_owner.get_or_null(p_decal);
  483. return decal->lower_fade;
  484. }
  485. _FORCE_INLINE_ float decal_get_normal_fade(RID p_decal) {
  486. const Decal *decal = decal_owner.get_or_null(p_decal);
  487. return decal->normal_fade;
  488. }
  489. _FORCE_INLINE_ bool decal_is_distance_fade_enabled(RID p_decal) {
  490. const Decal *decal = decal_owner.get_or_null(p_decal);
  491. return decal->distance_fade;
  492. }
  493. _FORCE_INLINE_ float decal_get_distance_fade_begin(RID p_decal) {
  494. const Decal *decal = decal_owner.get_or_null(p_decal);
  495. return decal->distance_fade_begin;
  496. }
  497. _FORCE_INLINE_ float decal_get_distance_fade_length(RID p_decal) {
  498. const Decal *decal = decal_owner.get_or_null(p_decal);
  499. return decal->distance_fade_length;
  500. }
  501. virtual AABB decal_get_aabb(RID p_decal) const override;
  502. virtual uint32_t decal_get_cull_mask(RID p_decal) const override;
  503. Dependency *decal_get_dependency(RID p_decal);
  504. /* DECAL INSTANCE API */
  505. bool owns_decal_instance(RID p_rid) const { return decal_instance_owner.owns(p_rid); }
  506. virtual RID decal_instance_create(RID p_decal) override;
  507. virtual void decal_instance_free(RID p_decal_instance) override;
  508. virtual void decal_instance_set_transform(RID p_decal_instance, const Transform3D &p_transform) override;
  509. virtual void decal_instance_set_sorting_offset(RID p_decal_instance, float p_sorting_offset) override;
  510. _FORCE_INLINE_ RID decal_instance_get_base(RID p_decal_instance) const {
  511. DecalInstance *di = decal_instance_owner.get_or_null(p_decal_instance);
  512. return di->decal;
  513. }
  514. _FORCE_INLINE_ RendererRD::ForwardID decal_instance_get_forward_id(RID p_decal_instance) const {
  515. DecalInstance *di = decal_instance_owner.get_or_null(p_decal_instance);
  516. return di->forward_id;
  517. }
  518. _FORCE_INLINE_ Transform3D decal_instance_get_transform(RID p_decal_instance) const {
  519. DecalInstance *di = decal_instance_owner.get_or_null(p_decal_instance);
  520. return di->transform;
  521. }
  522. _FORCE_INLINE_ ForwardID decal_instance_get_forward_id(RID p_decal_instance) {
  523. DecalInstance *di = decal_instance_owner.get_or_null(p_decal_instance);
  524. return di->forward_id;
  525. }
  526. _FORCE_INLINE_ void decal_instance_set_cullmask(RID p_decal_instance, uint32_t p_cull_mask) const {
  527. DecalInstance *di = decal_instance_owner.get_or_null(p_decal_instance);
  528. di->cull_mask = p_cull_mask;
  529. }
  530. /* DECAL DATA API */
  531. void free_decal_data();
  532. void set_max_decals(const uint32_t p_max_decals);
  533. RID get_decal_buffer() { return decal_buffer; }
  534. void update_decal_buffer(const PagedArray<RID> &p_decals, const Transform3D &p_camera_xform);
  535. /* RENDER TARGET API */
  536. bool owns_render_target(RID p_rid) const { return render_target_owner.owns(p_rid); };
  537. virtual RID render_target_create() override;
  538. virtual void render_target_free(RID p_rid) override;
  539. virtual void render_target_set_position(RID p_render_target, int p_x, int p_y) override;
  540. virtual Point2i render_target_get_position(RID p_render_target) const override;
  541. virtual void render_target_set_size(RID p_render_target, int p_width, int p_height, uint32_t p_view_count) override;
  542. virtual Size2i render_target_get_size(RID p_render_target) const override;
  543. virtual void render_target_set_transparent(RID p_render_target, bool p_is_transparent) override;
  544. virtual bool render_target_get_transparent(RID p_render_target) const override;
  545. virtual void render_target_set_direct_to_screen(RID p_render_target, bool p_direct_to_screen) override;
  546. virtual bool render_target_get_direct_to_screen(RID p_render_target) const override;
  547. virtual bool render_target_was_used(RID p_render_target) const override;
  548. virtual void render_target_set_as_unused(RID p_render_target) override;
  549. virtual void render_target_set_msaa(RID p_render_target, RS::ViewportMSAA p_msaa) override;
  550. virtual RS::ViewportMSAA render_target_get_msaa(RID p_render_target) const override;
  551. void render_target_copy_to_back_buffer(RID p_render_target, const Rect2i &p_region, bool p_gen_mipmaps);
  552. void render_target_clear_back_buffer(RID p_render_target, const Rect2i &p_region, const Color &p_color);
  553. void render_target_gen_back_buffer_mipmaps(RID p_render_target, const Rect2i &p_region);
  554. RID render_target_get_back_buffer_uniform_set(RID p_render_target, RID p_base_shader);
  555. virtual void render_target_request_clear(RID p_render_target, const Color &p_clear_color) override;
  556. virtual bool render_target_is_clear_requested(RID p_render_target) override;
  557. virtual Color render_target_get_clear_request_color(RID p_render_target) override;
  558. virtual void render_target_disable_clear_request(RID p_render_target) override;
  559. virtual void render_target_do_clear_request(RID p_render_target) override;
  560. virtual void render_target_set_sdf_size_and_scale(RID p_render_target, RS::ViewportSDFOversize p_size, RS::ViewportSDFScale p_scale) override;
  561. RID render_target_get_sdf_texture(RID p_render_target);
  562. RID render_target_get_sdf_framebuffer(RID p_render_target);
  563. void render_target_sdf_process(RID p_render_target);
  564. virtual Rect2i render_target_get_sdf_rect(RID p_render_target) const override;
  565. virtual void render_target_mark_sdf_enabled(RID p_render_target, bool p_enabled) override;
  566. bool render_target_is_sdf_enabled(RID p_render_target) const;
  567. virtual void render_target_set_vrs_mode(RID p_render_target, RS::ViewportVRSMode p_mode) override;
  568. virtual RS::ViewportVRSMode render_target_get_vrs_mode(RID p_render_target) const override;
  569. virtual void render_target_set_vrs_texture(RID p_render_target, RID p_texture) override;
  570. virtual RID render_target_get_vrs_texture(RID p_render_target) const override;
  571. virtual void render_target_set_override(RID p_render_target, RID p_color_texture, RID p_depth_texture, RID p_velocity_texture) override;
  572. virtual RID render_target_get_override_color(RID p_render_target) const override;
  573. virtual RID render_target_get_override_depth(RID p_render_target) const override;
  574. RID render_target_get_override_depth_slice(RID p_render_target, const uint32_t p_layer) const;
  575. virtual RID render_target_get_override_velocity(RID p_render_target) const override;
  576. RID render_target_get_override_velocity_slice(RID p_render_target, const uint32_t p_layer) const;
  577. virtual RID render_target_get_texture(RID p_render_target) override;
  578. RID render_target_get_rd_framebuffer(RID p_render_target);
  579. RID render_target_get_rd_texture(RID p_render_target);
  580. RID render_target_get_rd_texture_slice(RID p_render_target, uint32_t p_layer);
  581. RID render_target_get_rd_texture_msaa(RID p_render_target);
  582. RID render_target_get_rd_backbuffer(RID p_render_target);
  583. RID render_target_get_rd_backbuffer_framebuffer(RID p_render_target);
  584. RID render_target_get_framebuffer_uniform_set(RID p_render_target);
  585. RID render_target_get_backbuffer_uniform_set(RID p_render_target);
  586. void render_target_set_framebuffer_uniform_set(RID p_render_target, RID p_uniform_set);
  587. void render_target_set_backbuffer_uniform_set(RID p_render_target, RID p_uniform_set);
  588. };
  589. } // namespace RendererRD
  590. #endif // TEXTURE_STORAGE_RD_H