renderer_storage_rd.h 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288
  1. /*************************************************************************/
  2. /* renderer_storage_rd.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 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 RENDERING_SERVER_STORAGE_RD_H
  31. #define RENDERING_SERVER_STORAGE_RD_H
  32. #include "core/templates/list.h"
  33. #include "core/templates/local_vector.h"
  34. #include "core/templates/rid_owner.h"
  35. #include "servers/rendering/renderer_compositor.h"
  36. #include "servers/rendering/renderer_rd/effects_rd.h"
  37. #include "servers/rendering/renderer_rd/shader_compiler_rd.h"
  38. #include "servers/rendering/renderer_rd/shaders/canvas_sdf.glsl.gen.h"
  39. #include "servers/rendering/renderer_rd/shaders/giprobe_sdf.glsl.gen.h"
  40. #include "servers/rendering/renderer_rd/shaders/particles.glsl.gen.h"
  41. #include "servers/rendering/renderer_rd/shaders/particles_copy.glsl.gen.h"
  42. #include "servers/rendering/renderer_rd/shaders/skeleton.glsl.gen.h"
  43. #include "servers/rendering/renderer_scene_render.h"
  44. #include "servers/rendering/rendering_device.h"
  45. class RendererStorageRD : public RendererStorage {
  46. public:
  47. static _FORCE_INLINE_ void store_transform(const Transform &p_mtx, float *p_array) {
  48. p_array[0] = p_mtx.basis.elements[0][0];
  49. p_array[1] = p_mtx.basis.elements[1][0];
  50. p_array[2] = p_mtx.basis.elements[2][0];
  51. p_array[3] = 0;
  52. p_array[4] = p_mtx.basis.elements[0][1];
  53. p_array[5] = p_mtx.basis.elements[1][1];
  54. p_array[6] = p_mtx.basis.elements[2][1];
  55. p_array[7] = 0;
  56. p_array[8] = p_mtx.basis.elements[0][2];
  57. p_array[9] = p_mtx.basis.elements[1][2];
  58. p_array[10] = p_mtx.basis.elements[2][2];
  59. p_array[11] = 0;
  60. p_array[12] = p_mtx.origin.x;
  61. p_array[13] = p_mtx.origin.y;
  62. p_array[14] = p_mtx.origin.z;
  63. p_array[15] = 1;
  64. }
  65. static _FORCE_INLINE_ void store_basis_3x4(const Basis &p_mtx, float *p_array) {
  66. p_array[0] = p_mtx.elements[0][0];
  67. p_array[1] = p_mtx.elements[1][0];
  68. p_array[2] = p_mtx.elements[2][0];
  69. p_array[3] = 0;
  70. p_array[4] = p_mtx.elements[0][1];
  71. p_array[5] = p_mtx.elements[1][1];
  72. p_array[6] = p_mtx.elements[2][1];
  73. p_array[7] = 0;
  74. p_array[8] = p_mtx.elements[0][2];
  75. p_array[9] = p_mtx.elements[1][2];
  76. p_array[10] = p_mtx.elements[2][2];
  77. p_array[11] = 0;
  78. }
  79. static _FORCE_INLINE_ void store_transform_3x3(const Basis &p_mtx, float *p_array) {
  80. p_array[0] = p_mtx.elements[0][0];
  81. p_array[1] = p_mtx.elements[1][0];
  82. p_array[2] = p_mtx.elements[2][0];
  83. p_array[3] = 0;
  84. p_array[4] = p_mtx.elements[0][1];
  85. p_array[5] = p_mtx.elements[1][1];
  86. p_array[6] = p_mtx.elements[2][1];
  87. p_array[7] = 0;
  88. p_array[8] = p_mtx.elements[0][2];
  89. p_array[9] = p_mtx.elements[1][2];
  90. p_array[10] = p_mtx.elements[2][2];
  91. p_array[11] = 0;
  92. }
  93. static _FORCE_INLINE_ void store_transform_transposed_3x4(const Transform &p_mtx, float *p_array) {
  94. p_array[0] = p_mtx.basis.elements[0][0];
  95. p_array[1] = p_mtx.basis.elements[0][1];
  96. p_array[2] = p_mtx.basis.elements[0][2];
  97. p_array[3] = p_mtx.origin.x;
  98. p_array[4] = p_mtx.basis.elements[1][0];
  99. p_array[5] = p_mtx.basis.elements[1][1];
  100. p_array[6] = p_mtx.basis.elements[1][2];
  101. p_array[7] = p_mtx.origin.y;
  102. p_array[8] = p_mtx.basis.elements[2][0];
  103. p_array[9] = p_mtx.basis.elements[2][1];
  104. p_array[10] = p_mtx.basis.elements[2][2];
  105. p_array[11] = p_mtx.origin.z;
  106. }
  107. static _FORCE_INLINE_ void store_camera(const CameraMatrix &p_mtx, float *p_array) {
  108. for (int i = 0; i < 4; i++) {
  109. for (int j = 0; j < 4; j++) {
  110. p_array[i * 4 + j] = p_mtx.matrix[i][j];
  111. }
  112. }
  113. }
  114. static _FORCE_INLINE_ void store_soft_shadow_kernel(const float *p_kernel, float *p_array) {
  115. for (int i = 0; i < 128; i++) {
  116. p_array[i] = p_kernel[i];
  117. }
  118. }
  119. enum ShaderType {
  120. SHADER_TYPE_2D,
  121. SHADER_TYPE_3D,
  122. SHADER_TYPE_PARTICLES,
  123. SHADER_TYPE_SKY,
  124. SHADER_TYPE_MAX
  125. };
  126. struct ShaderData {
  127. virtual void set_code(const String &p_Code) = 0;
  128. virtual void set_default_texture_param(const StringName &p_name, RID p_texture) = 0;
  129. virtual void get_param_list(List<PropertyInfo> *p_param_list) const = 0;
  130. virtual void get_instance_param_list(List<InstanceShaderParam> *p_param_list) const = 0;
  131. virtual bool is_param_texture(const StringName &p_param) const = 0;
  132. virtual bool is_animated() const = 0;
  133. virtual bool casts_shadows() const = 0;
  134. virtual Variant get_default_parameter(const StringName &p_parameter) const = 0;
  135. virtual RS::ShaderNativeSourceCode get_native_source_code() const { return RS::ShaderNativeSourceCode(); }
  136. virtual ~ShaderData() {}
  137. };
  138. typedef ShaderData *(*ShaderDataRequestFunction)();
  139. struct MaterialData {
  140. void update_uniform_buffer(const Map<StringName, ShaderLanguage::ShaderNode::Uniform> &p_uniforms, const uint32_t *p_uniform_offsets, const Map<StringName, Variant> &p_parameters, uint8_t *p_buffer, uint32_t p_buffer_size, bool p_use_linear_color);
  141. void update_textures(const Map<StringName, Variant> &p_parameters, const Map<StringName, RID> &p_default_textures, const Vector<ShaderCompilerRD::GeneratedCode::Texture> &p_texture_uniforms, RID *p_textures, bool p_use_linear_color);
  142. virtual void set_render_priority(int p_priority) = 0;
  143. virtual void set_next_pass(RID p_pass) = 0;
  144. virtual void update_parameters(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty) = 0;
  145. virtual ~MaterialData();
  146. private:
  147. friend class RendererStorageRD;
  148. RID self;
  149. List<RID>::Element *global_buffer_E = nullptr;
  150. List<RID>::Element *global_texture_E = nullptr;
  151. uint64_t global_textures_pass = 0;
  152. Map<StringName, uint64_t> used_global_textures;
  153. };
  154. typedef MaterialData *(*MaterialDataRequestFunction)(ShaderData *);
  155. enum DefaultRDTexture {
  156. DEFAULT_RD_TEXTURE_WHITE,
  157. DEFAULT_RD_TEXTURE_BLACK,
  158. DEFAULT_RD_TEXTURE_NORMAL,
  159. DEFAULT_RD_TEXTURE_ANISO,
  160. DEFAULT_RD_TEXTURE_MULTIMESH_BUFFER,
  161. DEFAULT_RD_TEXTURE_CUBEMAP_BLACK,
  162. DEFAULT_RD_TEXTURE_CUBEMAP_ARRAY_BLACK,
  163. DEFAULT_RD_TEXTURE_CUBEMAP_WHITE,
  164. DEFAULT_RD_TEXTURE_3D_WHITE,
  165. DEFAULT_RD_TEXTURE_2D_ARRAY_WHITE,
  166. DEFAULT_RD_TEXTURE_2D_UINT,
  167. DEFAULT_RD_TEXTURE_MAX
  168. };
  169. enum DefaultRDBuffer {
  170. DEFAULT_RD_BUFFER_VERTEX,
  171. DEFAULT_RD_BUFFER_NORMAL,
  172. DEFAULT_RD_BUFFER_TANGENT,
  173. DEFAULT_RD_BUFFER_COLOR,
  174. DEFAULT_RD_BUFFER_TEX_UV,
  175. DEFAULT_RD_BUFFER_TEX_UV2,
  176. DEFAULT_RD_BUFFER_CUSTOM0,
  177. DEFAULT_RD_BUFFER_CUSTOM1,
  178. DEFAULT_RD_BUFFER_CUSTOM2,
  179. DEFAULT_RD_BUFFER_CUSTOM3,
  180. DEFAULT_RD_BUFFER_BONES,
  181. DEFAULT_RD_BUFFER_WEIGHTS,
  182. DEFAULT_RD_BUFFER_MAX,
  183. };
  184. private:
  185. /* CANVAS TEXTURE API (2D) */
  186. struct CanvasTexture {
  187. RID diffuse;
  188. RID normal_map;
  189. RID specular;
  190. Color specular_color = Color(1, 1, 1, 1);
  191. float shininess = 1.0;
  192. RS::CanvasItemTextureFilter texture_filter = RS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT;
  193. RS::CanvasItemTextureRepeat texture_repeat = RS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT;
  194. RID uniform_sets[RS::CANVAS_ITEM_TEXTURE_FILTER_MAX][RS::CANVAS_ITEM_TEXTURE_REPEAT_MAX];
  195. Size2i size_cache = Size2i(1, 1);
  196. bool use_normal_cache = false;
  197. bool use_specular_cache = false;
  198. bool cleared_cache = true;
  199. void clear_sets();
  200. ~CanvasTexture();
  201. };
  202. RID_PtrOwner<CanvasTexture, true> canvas_texture_owner;
  203. /* TEXTURE API */
  204. struct Texture {
  205. enum Type {
  206. TYPE_2D,
  207. TYPE_LAYERED,
  208. TYPE_3D
  209. };
  210. Type type;
  211. RS::TextureLayeredType layered_type = RS::TEXTURE_LAYERED_2D_ARRAY;
  212. RenderingDevice::TextureType rd_type;
  213. RID rd_texture;
  214. RID rd_texture_srgb;
  215. RenderingDevice::DataFormat rd_format;
  216. RenderingDevice::DataFormat rd_format_srgb;
  217. RD::TextureView rd_view;
  218. Image::Format format;
  219. Image::Format validated_format;
  220. int width;
  221. int height;
  222. int depth;
  223. int layers;
  224. int mipmaps;
  225. int height_2d;
  226. int width_2d;
  227. struct BufferSlice3D {
  228. Size2i size;
  229. uint32_t offset = 0;
  230. uint32_t buffer_size = 0;
  231. };
  232. Vector<BufferSlice3D> buffer_slices_3d;
  233. uint32_t buffer_size_3d = 0;
  234. bool is_render_target;
  235. bool is_proxy;
  236. Ref<Image> image_cache_2d;
  237. String path;
  238. RID proxy_to;
  239. Vector<RID> proxies;
  240. Set<RID> lightmap_users;
  241. RS::TextureDetectCallback detect_3d_callback = nullptr;
  242. void *detect_3d_callback_ud = nullptr;
  243. RS::TextureDetectCallback detect_normal_callback = nullptr;
  244. void *detect_normal_callback_ud = nullptr;
  245. RS::TextureDetectRoughnessCallback detect_roughness_callback = nullptr;
  246. void *detect_roughness_callback_ud = nullptr;
  247. CanvasTexture *canvas_texture = nullptr;
  248. };
  249. struct TextureToRDFormat {
  250. RD::DataFormat format;
  251. RD::DataFormat format_srgb;
  252. RD::TextureSwizzle swizzle_r;
  253. RD::TextureSwizzle swizzle_g;
  254. RD::TextureSwizzle swizzle_b;
  255. RD::TextureSwizzle swizzle_a;
  256. TextureToRDFormat() {
  257. format = RD::DATA_FORMAT_MAX;
  258. format_srgb = RD::DATA_FORMAT_MAX;
  259. swizzle_r = RD::TEXTURE_SWIZZLE_R;
  260. swizzle_g = RD::TEXTURE_SWIZZLE_G;
  261. swizzle_b = RD::TEXTURE_SWIZZLE_B;
  262. swizzle_a = RD::TEXTURE_SWIZZLE_A;
  263. }
  264. };
  265. //textures can be created from threads, so this RID_Owner is thread safe
  266. mutable RID_Owner<Texture, true> texture_owner;
  267. Ref<Image> _validate_texture_format(const Ref<Image> &p_image, TextureToRDFormat &r_format);
  268. RID default_rd_textures[DEFAULT_RD_TEXTURE_MAX];
  269. RID default_rd_samplers[RS::CANVAS_ITEM_TEXTURE_FILTER_MAX][RS::CANVAS_ITEM_TEXTURE_REPEAT_MAX];
  270. RID default_rd_storage_buffer;
  271. /* DECAL ATLAS */
  272. struct DecalAtlas {
  273. struct Texture {
  274. int panorama_to_dp_users;
  275. int users;
  276. Rect2 uv_rect;
  277. };
  278. struct SortItem {
  279. RID texture;
  280. Size2i pixel_size;
  281. Size2i size;
  282. Point2i pos;
  283. bool operator<(const SortItem &p_item) const {
  284. //sort larger to smaller
  285. if (size.height == p_item.size.height) {
  286. return size.width > p_item.size.width;
  287. } else {
  288. return size.height > p_item.size.height;
  289. }
  290. }
  291. };
  292. HashMap<RID, Texture> textures;
  293. bool dirty = true;
  294. int mipmaps = 5;
  295. RID texture;
  296. RID texture_srgb;
  297. struct MipMap {
  298. RID fb;
  299. RID texture;
  300. Size2i size;
  301. };
  302. Vector<MipMap> texture_mipmaps;
  303. Size2i size;
  304. } decal_atlas;
  305. void _update_decal_atlas();
  306. /* SHADER */
  307. struct Material;
  308. struct Shader {
  309. ShaderData *data;
  310. String code;
  311. ShaderType type;
  312. Map<StringName, RID> default_texture_parameter;
  313. Set<Material *> owners;
  314. };
  315. ShaderDataRequestFunction shader_data_request_func[SHADER_TYPE_MAX];
  316. mutable RID_Owner<Shader, true> shader_owner;
  317. /* Material */
  318. struct Material {
  319. RID self;
  320. MaterialData *data;
  321. Shader *shader;
  322. //shortcut to shader data and type
  323. ShaderType shader_type;
  324. uint32_t shader_id = 0;
  325. bool update_requested;
  326. bool uniform_dirty;
  327. bool texture_dirty;
  328. Material *update_next;
  329. Map<StringName, Variant> params;
  330. int32_t priority;
  331. RID next_pass;
  332. Dependency dependency;
  333. };
  334. MaterialDataRequestFunction material_data_request_func[SHADER_TYPE_MAX];
  335. mutable RID_Owner<Material, true> material_owner;
  336. Material *material_update_list;
  337. void _material_queue_update(Material *material, bool p_uniform, bool p_texture);
  338. void _update_queued_materials();
  339. /* Mesh */
  340. struct MeshInstance;
  341. struct Mesh {
  342. struct Surface {
  343. RS::PrimitiveType primitive = RS::PRIMITIVE_POINTS;
  344. uint32_t format = 0;
  345. RID vertex_buffer;
  346. RID attribute_buffer;
  347. RID skin_buffer;
  348. uint32_t vertex_count = 0;
  349. uint32_t vertex_buffer_size = 0;
  350. uint32_t skin_buffer_size = 0;
  351. // A different pipeline needs to be allocated
  352. // depending on the inputs available in the
  353. // material.
  354. // There are never that many geometry/material
  355. // combinations, so a simple array is the most
  356. // cache-efficient structure.
  357. struct Version {
  358. uint32_t input_mask = 0;
  359. RD::VertexFormatID vertex_format = 0;
  360. RID vertex_array;
  361. };
  362. SpinLock version_lock; //needed to access versions
  363. Version *versions = nullptr; //allocated on demand
  364. uint32_t version_count = 0;
  365. RID index_buffer;
  366. RID index_array;
  367. uint32_t index_count = 0;
  368. struct LOD {
  369. float edge_length = 0.0;
  370. RID index_buffer;
  371. RID index_array;
  372. };
  373. LOD *lods = nullptr;
  374. uint32_t lod_count = 0;
  375. AABB aabb;
  376. Vector<AABB> bone_aabbs;
  377. RID blend_shape_buffer;
  378. RID material;
  379. uint32_t render_index = 0;
  380. uint64_t render_pass = 0;
  381. uint32_t multimesh_render_index = 0;
  382. uint64_t multimesh_render_pass = 0;
  383. uint32_t particles_render_index = 0;
  384. uint64_t particles_render_pass = 0;
  385. RID uniform_set;
  386. };
  387. uint32_t blend_shape_count = 0;
  388. RS::BlendShapeMode blend_shape_mode = RS::BLEND_SHAPE_MODE_NORMALIZED;
  389. Surface **surfaces = nullptr;
  390. uint32_t surface_count = 0;
  391. Vector<AABB> bone_aabbs;
  392. bool has_bone_weights = false;
  393. AABB aabb;
  394. AABB custom_aabb;
  395. Vector<RID> material_cache;
  396. List<MeshInstance *> instances;
  397. RID shadow_mesh;
  398. Set<Mesh *> shadow_owners;
  399. Dependency dependency;
  400. };
  401. mutable RID_Owner<Mesh, true> mesh_owner;
  402. struct MeshInstance {
  403. Mesh *mesh;
  404. RID skeleton;
  405. struct Surface {
  406. RID vertex_buffer;
  407. RID uniform_set;
  408. Mesh::Surface::Version *versions = nullptr; //allocated on demand
  409. uint32_t version_count = 0;
  410. };
  411. LocalVector<Surface> surfaces;
  412. LocalVector<float> blend_weights;
  413. RID blend_weights_buffer;
  414. List<MeshInstance *>::Element *I = nullptr; //used to erase itself
  415. uint64_t skeleton_version = 0;
  416. bool dirty = false;
  417. bool weights_dirty = false;
  418. SelfList<MeshInstance> weight_update_list;
  419. SelfList<MeshInstance> array_update_list;
  420. MeshInstance() :
  421. weight_update_list(this), array_update_list(this) {}
  422. };
  423. void _mesh_instance_clear(MeshInstance *mi);
  424. void _mesh_instance_add_surface(MeshInstance *mi, Mesh *mesh, uint32_t p_surface);
  425. mutable RID_PtrOwner<MeshInstance> mesh_instance_owner;
  426. SelfList<MeshInstance>::List dirty_mesh_instance_weights;
  427. SelfList<MeshInstance>::List dirty_mesh_instance_arrays;
  428. struct SkeletonShader {
  429. struct PushConstant {
  430. uint32_t has_normal;
  431. uint32_t has_tangent;
  432. uint32_t has_skeleton;
  433. uint32_t has_blend_shape;
  434. uint32_t vertex_count;
  435. uint32_t vertex_stride;
  436. uint32_t skin_stride;
  437. uint32_t skin_weight_offset;
  438. uint32_t blend_shape_count;
  439. uint32_t normalized_blend_shapes;
  440. uint32_t pad0;
  441. uint32_t pad1;
  442. };
  443. enum {
  444. UNIFORM_SET_INSTANCE = 0,
  445. UNIFORM_SET_SURFACE = 1,
  446. UNIFORM_SET_SKELETON = 2,
  447. };
  448. enum {
  449. SHADER_MODE_2D,
  450. SHADER_MODE_3D,
  451. SHADER_MODE_MAX
  452. };
  453. SkeletonShaderRD shader;
  454. RID version;
  455. RID version_shader[SHADER_MODE_MAX];
  456. RID pipeline[SHADER_MODE_MAX];
  457. RID default_skeleton_uniform_set;
  458. } skeleton_shader;
  459. void _mesh_surface_generate_version_for_input_mask(Mesh::Surface::Version &v, Mesh::Surface *s, uint32_t p_input_mask, MeshInstance::Surface *mis = nullptr);
  460. RID mesh_default_rd_buffers[DEFAULT_RD_BUFFER_MAX];
  461. /* MultiMesh */
  462. struct MultiMesh {
  463. RID mesh;
  464. int instances = 0;
  465. RS::MultimeshTransformFormat xform_format = RS::MULTIMESH_TRANSFORM_3D;
  466. bool uses_colors = false;
  467. bool uses_custom_data = false;
  468. int visible_instances = -1;
  469. AABB aabb;
  470. bool aabb_dirty = false;
  471. bool buffer_set = false;
  472. uint32_t stride_cache = 0;
  473. uint32_t color_offset_cache = 0;
  474. uint32_t custom_data_offset_cache = 0;
  475. Vector<float> data_cache; //used if individual setting is used
  476. bool *data_cache_dirty_regions = nullptr;
  477. uint32_t data_cache_used_dirty_regions = 0;
  478. RID buffer; //storage buffer
  479. RID uniform_set_3d;
  480. bool dirty = false;
  481. MultiMesh *dirty_list = nullptr;
  482. Dependency dependency;
  483. };
  484. mutable RID_Owner<MultiMesh, true> multimesh_owner;
  485. MultiMesh *multimesh_dirty_list = nullptr;
  486. _FORCE_INLINE_ void _multimesh_make_local(MultiMesh *multimesh) const;
  487. _FORCE_INLINE_ void _multimesh_mark_dirty(MultiMesh *multimesh, int p_index, bool p_aabb);
  488. _FORCE_INLINE_ void _multimesh_mark_all_dirty(MultiMesh *multimesh, bool p_data, bool p_aabb);
  489. _FORCE_INLINE_ void _multimesh_re_create_aabb(MultiMesh *multimesh, const float *p_data, int p_instances);
  490. void _update_dirty_multimeshes();
  491. /* PARTICLES */
  492. struct ParticleData {
  493. float xform[16];
  494. float velocity[3];
  495. uint32_t active;
  496. float color[4];
  497. float custom[3];
  498. float lifetime;
  499. uint32_t pad[3];
  500. };
  501. struct ParticlesFrameParams {
  502. enum {
  503. MAX_ATTRACTORS = 32,
  504. MAX_COLLIDERS = 32,
  505. MAX_3D_TEXTURES = 7
  506. };
  507. enum AttractorType {
  508. ATTRACTOR_TYPE_SPHERE,
  509. ATTRACTOR_TYPE_BOX,
  510. ATTRACTOR_TYPE_VECTOR_FIELD,
  511. };
  512. struct Attractor {
  513. float transform[16];
  514. float extents[3]; //exents or radius
  515. uint32_t type;
  516. uint32_t texture_index; //texture index for vector field
  517. float strength;
  518. float attenuation;
  519. float directionality;
  520. };
  521. enum CollisionType {
  522. COLLISION_TYPE_SPHERE,
  523. COLLISION_TYPE_BOX,
  524. COLLISION_TYPE_SDF,
  525. COLLISION_TYPE_HEIGHT_FIELD
  526. };
  527. struct Collider {
  528. float transform[16];
  529. float extents[3]; //exents or radius
  530. uint32_t type;
  531. uint32_t texture_index; //texture index for vector field
  532. float scale;
  533. uint32_t pad[2];
  534. };
  535. uint32_t emitting;
  536. float system_phase;
  537. float prev_system_phase;
  538. uint32_t cycle;
  539. float explosiveness;
  540. float randomness;
  541. float time;
  542. float delta;
  543. uint32_t random_seed;
  544. uint32_t attractor_count;
  545. uint32_t collider_count;
  546. float particle_size;
  547. float emission_transform[16];
  548. Attractor attractors[MAX_ATTRACTORS];
  549. Collider colliders[MAX_COLLIDERS];
  550. };
  551. struct ParticleEmissionBufferData {
  552. };
  553. struct ParticleEmissionBuffer {
  554. struct Data {
  555. float xform[16];
  556. float velocity[3];
  557. uint32_t flags;
  558. float color[4];
  559. float custom[4];
  560. };
  561. int32_t particle_count;
  562. int32_t particle_max;
  563. uint32_t pad1;
  564. uint32_t pad2;
  565. Data data[1]; //its 2020 and empty arrays are still non standard in C++
  566. };
  567. struct Particles {
  568. bool inactive;
  569. float inactive_time;
  570. bool emitting;
  571. bool one_shot;
  572. int amount;
  573. float lifetime;
  574. float pre_process_time;
  575. float explosiveness;
  576. float randomness;
  577. bool restart_request;
  578. AABB custom_aabb;
  579. bool use_local_coords;
  580. RID process_material;
  581. RS::ParticlesDrawOrder draw_order;
  582. Vector<RID> draw_passes;
  583. RID particle_buffer;
  584. RID particle_instance_buffer;
  585. RID frame_params_buffer;
  586. RID particles_material_uniform_set;
  587. RID particles_copy_uniform_set;
  588. RID particles_transforms_buffer_uniform_set;
  589. RID collision_textures_uniform_set;
  590. RID collision_3d_textures[ParticlesFrameParams::MAX_3D_TEXTURES];
  591. uint32_t collision_3d_textures_used = 0;
  592. RID collision_heightmap_texture;
  593. RID particles_sort_buffer;
  594. RID particles_sort_uniform_set;
  595. bool dirty = false;
  596. Particles *update_list = nullptr;
  597. RID sub_emitter;
  598. float phase;
  599. float prev_phase;
  600. uint64_t prev_ticks;
  601. uint32_t random_seed;
  602. uint32_t cycle_number;
  603. float speed_scale;
  604. int fixed_fps;
  605. bool fractional_delta;
  606. float frame_remainder;
  607. float collision_base_size;
  608. bool clear;
  609. bool force_sub_emit = false;
  610. Transform emission_transform;
  611. Vector<uint8_t> emission_buffer_data;
  612. ParticleEmissionBuffer *emission_buffer = nullptr;
  613. RID emission_storage_buffer;
  614. Set<RID> collisions;
  615. Particles() :
  616. inactive(true),
  617. inactive_time(0.0),
  618. emitting(false),
  619. one_shot(false),
  620. amount(0),
  621. lifetime(1.0),
  622. pre_process_time(0.0),
  623. explosiveness(0.0),
  624. randomness(0.0),
  625. restart_request(false),
  626. custom_aabb(AABB(Vector3(-4, -4, -4), Vector3(8, 8, 8))),
  627. use_local_coords(true),
  628. draw_order(RS::PARTICLES_DRAW_ORDER_INDEX),
  629. prev_ticks(0),
  630. random_seed(0),
  631. cycle_number(0),
  632. speed_scale(1.0),
  633. fixed_fps(0),
  634. fractional_delta(false),
  635. frame_remainder(0),
  636. collision_base_size(0.01),
  637. clear(true) {
  638. }
  639. Dependency dependency;
  640. ParticlesFrameParams frame_params;
  641. };
  642. void _particles_process(Particles *p_particles, float p_delta);
  643. void _particles_allocate_emission_buffer(Particles *particles);
  644. void _particles_free_data(Particles *particles);
  645. struct ParticlesShader {
  646. struct PushConstant {
  647. float lifetime;
  648. uint32_t clear;
  649. uint32_t total_particles;
  650. uint32_t trail_size;
  651. uint32_t use_fractional_delta;
  652. uint32_t sub_emitter_mode;
  653. uint32_t can_emit;
  654. uint32_t pad;
  655. };
  656. ParticlesShaderRD shader;
  657. ShaderCompilerRD compiler;
  658. RID default_shader;
  659. RID default_material;
  660. RID default_shader_rd;
  661. RID base_uniform_set;
  662. struct CopyPushConstant {
  663. float sort_direction[3];
  664. uint32_t total_particles;
  665. };
  666. enum {
  667. COPY_MODE_FILL_INSTANCES,
  668. COPY_MODE_FILL_SORT_BUFFER,
  669. COPY_MODE_FILL_INSTANCES_WITH_SORT_BUFFER,
  670. COPY_MODE_MAX,
  671. };
  672. ParticlesCopyShaderRD copy_shader;
  673. RID copy_shader_version;
  674. RID copy_pipelines[COPY_MODE_MAX];
  675. } particles_shader;
  676. Particles *particle_update_list = nullptr;
  677. struct ParticlesShaderData : public ShaderData {
  678. bool valid;
  679. RID version;
  680. //PipelineCacheRD pipelines[SKY_VERSION_MAX];
  681. Map<StringName, ShaderLanguage::ShaderNode::Uniform> uniforms;
  682. Vector<ShaderCompilerRD::GeneratedCode::Texture> texture_uniforms;
  683. Vector<uint32_t> ubo_offsets;
  684. uint32_t ubo_size;
  685. String path;
  686. String code;
  687. Map<StringName, RID> default_texture_params;
  688. RID pipeline;
  689. bool uses_time;
  690. virtual void set_code(const String &p_Code);
  691. virtual void set_default_texture_param(const StringName &p_name, RID p_texture);
  692. virtual void get_param_list(List<PropertyInfo> *p_param_list) const;
  693. virtual void get_instance_param_list(List<RendererStorage::InstanceShaderParam> *p_param_list) const;
  694. virtual bool is_param_texture(const StringName &p_param) const;
  695. virtual bool is_animated() const;
  696. virtual bool casts_shadows() const;
  697. virtual Variant get_default_parameter(const StringName &p_parameter) const;
  698. virtual RS::ShaderNativeSourceCode get_native_source_code() const;
  699. ParticlesShaderData();
  700. virtual ~ParticlesShaderData();
  701. };
  702. ShaderData *_create_particles_shader_func();
  703. static RendererStorageRD::ShaderData *_create_particles_shader_funcs() {
  704. return base_singleton->_create_particles_shader_func();
  705. }
  706. struct ParticlesMaterialData : public MaterialData {
  707. uint64_t last_frame;
  708. ParticlesShaderData *shader_data;
  709. RID uniform_buffer;
  710. RID uniform_set;
  711. Vector<RID> texture_cache;
  712. Vector<uint8_t> ubo_data;
  713. bool uniform_set_updated;
  714. virtual void set_render_priority(int p_priority) {}
  715. virtual void set_next_pass(RID p_pass) {}
  716. virtual void update_parameters(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty);
  717. virtual ~ParticlesMaterialData();
  718. };
  719. MaterialData *_create_particles_material_func(ParticlesShaderData *p_shader);
  720. static RendererStorageRD::MaterialData *_create_particles_material_funcs(ShaderData *p_shader) {
  721. return base_singleton->_create_particles_material_func(static_cast<ParticlesShaderData *>(p_shader));
  722. }
  723. void update_particles();
  724. mutable RID_Owner<Particles, true> particles_owner;
  725. /* Particles Collision */
  726. struct ParticlesCollision {
  727. RS::ParticlesCollisionType type = RS::PARTICLES_COLLISION_TYPE_SPHERE_ATTRACT;
  728. uint32_t cull_mask = 0xFFFFFFFF;
  729. float radius = 1.0;
  730. Vector3 extents = Vector3(1, 1, 1);
  731. float attractor_strength = 1.0;
  732. float attractor_attenuation = 1.0;
  733. float attractor_directionality = 0.0;
  734. RID field_texture;
  735. RID heightfield_texture;
  736. RID heightfield_fb;
  737. Size2i heightfield_fb_size;
  738. RS::ParticlesCollisionHeightfieldResolution heightfield_resolution = RS::PARTICLES_COLLISION_HEIGHTFIELD_RESOLUTION_1024;
  739. Dependency dependency;
  740. };
  741. mutable RID_Owner<ParticlesCollision, true> particles_collision_owner;
  742. struct ParticlesCollisionInstance {
  743. RID collision;
  744. Transform transform;
  745. bool active = false;
  746. };
  747. mutable RID_Owner<ParticlesCollisionInstance> particles_collision_instance_owner;
  748. /* Skeleton */
  749. struct Skeleton {
  750. bool use_2d = false;
  751. int size = 0;
  752. Vector<float> data;
  753. RID buffer;
  754. bool dirty = false;
  755. Skeleton *dirty_list = nullptr;
  756. Transform2D base_transform_2d;
  757. RID uniform_set_3d;
  758. RID uniform_set_mi;
  759. uint64_t version = 1;
  760. Dependency dependency;
  761. };
  762. mutable RID_Owner<Skeleton, true> skeleton_owner;
  763. _FORCE_INLINE_ void _skeleton_make_dirty(Skeleton *skeleton);
  764. Skeleton *skeleton_dirty_list = nullptr;
  765. void _update_dirty_skeletons();
  766. /* LIGHT */
  767. struct Light {
  768. RS::LightType type;
  769. float param[RS::LIGHT_PARAM_MAX];
  770. Color color = Color(1, 1, 1, 1);
  771. Color shadow_color;
  772. RID projector;
  773. bool shadow = false;
  774. bool negative = false;
  775. bool reverse_cull = false;
  776. RS::LightBakeMode bake_mode = RS::LIGHT_BAKE_DYNAMIC;
  777. uint32_t max_sdfgi_cascade = 2;
  778. uint32_t cull_mask = 0xFFFFFFFF;
  779. RS::LightOmniShadowMode omni_shadow_mode = RS::LIGHT_OMNI_SHADOW_DUAL_PARABOLOID;
  780. RS::LightDirectionalShadowMode directional_shadow_mode = RS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL;
  781. RS::LightDirectionalShadowDepthRangeMode directional_range_mode = RS::LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_STABLE;
  782. bool directional_blend_splits = false;
  783. bool directional_sky_only = false;
  784. uint64_t version = 0;
  785. Dependency dependency;
  786. };
  787. mutable RID_Owner<Light, true> light_owner;
  788. /* REFLECTION PROBE */
  789. struct ReflectionProbe {
  790. RS::ReflectionProbeUpdateMode update_mode = RS::REFLECTION_PROBE_UPDATE_ONCE;
  791. int resolution = 256;
  792. float intensity = 1.0;
  793. RS::ReflectionProbeAmbientMode ambient_mode = RS::REFLECTION_PROBE_AMBIENT_ENVIRONMENT;
  794. Color ambient_color;
  795. float ambient_color_energy = 1.0;
  796. float max_distance = 0;
  797. Vector3 extents = Vector3(1, 1, 1);
  798. Vector3 origin_offset;
  799. bool interior = false;
  800. bool box_projection = false;
  801. bool enable_shadows = false;
  802. uint32_t cull_mask = (1 << 20) - 1;
  803. float lod_threshold = 0.01;
  804. Dependency dependency;
  805. };
  806. mutable RID_Owner<ReflectionProbe, true> reflection_probe_owner;
  807. /* DECAL */
  808. struct Decal {
  809. Vector3 extents = Vector3(1, 1, 1);
  810. RID textures[RS::DECAL_TEXTURE_MAX];
  811. float emission_energy = 1.0;
  812. float albedo_mix = 1.0;
  813. Color modulate = Color(1, 1, 1, 1);
  814. uint32_t cull_mask = (1 << 20) - 1;
  815. float upper_fade = 0.3;
  816. float lower_fade = 0.3;
  817. bool distance_fade = false;
  818. float distance_fade_begin = 10;
  819. float distance_fade_length = 1;
  820. float normal_fade = 0.0;
  821. Dependency dependency;
  822. };
  823. mutable RID_Owner<Decal, true> decal_owner;
  824. /* GI PROBE */
  825. struct GIProbe {
  826. RID octree_buffer;
  827. RID data_buffer;
  828. RID sdf_texture;
  829. uint32_t octree_buffer_size = 0;
  830. uint32_t data_buffer_size = 0;
  831. Vector<int> level_counts;
  832. int cell_count = 0;
  833. Transform to_cell_xform;
  834. AABB bounds;
  835. Vector3i octree_size;
  836. float dynamic_range = 4.0;
  837. float energy = 1.0;
  838. float ao = 0.0;
  839. float ao_size = 0.5;
  840. float bias = 1.4;
  841. float normal_bias = 0.0;
  842. float propagation = 0.7;
  843. bool interior = false;
  844. bool use_two_bounces = false;
  845. float anisotropy_strength = 0.5;
  846. uint32_t version = 1;
  847. uint32_t data_version = 1;
  848. Dependency dependency;
  849. };
  850. GiprobeSdfShaderRD giprobe_sdf_shader;
  851. RID giprobe_sdf_shader_version;
  852. RID giprobe_sdf_shader_version_shader;
  853. RID giprobe_sdf_shader_pipeline;
  854. mutable RID_Owner<GIProbe, true> gi_probe_owner;
  855. /* REFLECTION PROBE */
  856. struct Lightmap {
  857. RID light_texture;
  858. bool uses_spherical_harmonics = false;
  859. bool interior = false;
  860. AABB bounds = AABB(Vector3(), Vector3(1, 1, 1));
  861. int32_t array_index = -1; //unassigned
  862. PackedVector3Array points;
  863. PackedColorArray point_sh;
  864. PackedInt32Array tetrahedra;
  865. PackedInt32Array bsp_tree;
  866. struct BSP {
  867. static const int32_t EMPTY_LEAF = INT32_MIN;
  868. float plane[4];
  869. int32_t over = EMPTY_LEAF, under = EMPTY_LEAF;
  870. };
  871. Dependency dependency;
  872. };
  873. bool using_lightmap_array; //high end uses this
  874. /* for high end */
  875. Vector<RID> lightmap_textures;
  876. uint64_t lightmap_array_version = 0;
  877. mutable RID_Owner<Lightmap, true> lightmap_owner;
  878. float lightmap_probe_capture_update_speed = 4;
  879. /* RENDER TARGET */
  880. struct RenderTarget {
  881. Size2i size;
  882. RID framebuffer;
  883. RID color;
  884. //used for retrieving from CPU
  885. RD::DataFormat color_format = RD::DATA_FORMAT_R4G4_UNORM_PACK8;
  886. RD::DataFormat color_format_srgb = RD::DATA_FORMAT_R4G4_UNORM_PACK8;
  887. Image::Format image_format = Image::FORMAT_L8;
  888. bool flags[RENDER_TARGET_FLAG_MAX];
  889. RID backbuffer; //used for effects
  890. RID backbuffer_fb;
  891. RID backbuffer_mipmap0;
  892. struct BackbufferMipmap {
  893. RID mipmap;
  894. RID mipmap_copy;
  895. };
  896. Vector<BackbufferMipmap> backbuffer_mipmaps;
  897. RID framebuffer_uniform_set;
  898. RID backbuffer_uniform_set;
  899. RID sdf_buffer_write;
  900. RID sdf_buffer_write_fb;
  901. RID sdf_buffer_process[2];
  902. RID sdf_buffer_read;
  903. RID sdf_buffer_process_uniform_sets[2];
  904. RS::ViewportSDFOversize sdf_oversize = RS::VIEWPORT_SDF_OVERSIZE_120_PERCENT;
  905. RS::ViewportSDFScale sdf_scale = RS::VIEWPORT_SDF_SCALE_50_PERCENT;
  906. Size2i process_size;
  907. //texture generated for this owner (nor RD).
  908. RID texture;
  909. bool was_used;
  910. //clear request
  911. bool clear_requested;
  912. Color clear_color;
  913. };
  914. mutable RID_Owner<RenderTarget> render_target_owner;
  915. void _clear_render_target(RenderTarget *rt);
  916. void _update_render_target(RenderTarget *rt);
  917. void _create_render_target_backbuffer(RenderTarget *rt);
  918. void _render_target_allocate_sdf(RenderTarget *rt);
  919. void _render_target_clear_sdf(RenderTarget *rt);
  920. Rect2i _render_target_get_sdf_rect(const RenderTarget *rt) const;
  921. struct RenderTargetSDF {
  922. enum {
  923. SHADER_LOAD,
  924. SHADER_LOAD_SHRINK,
  925. SHADER_PROCESS,
  926. SHADER_PROCESS_OPTIMIZED,
  927. SHADER_STORE,
  928. SHADER_STORE_SHRINK,
  929. SHADER_MAX
  930. };
  931. struct PushConstant {
  932. int32_t size[2];
  933. int32_t stride;
  934. int32_t shift;
  935. int32_t base_size[2];
  936. int32_t pad[2];
  937. };
  938. CanvasSdfShaderRD shader;
  939. RID shader_version;
  940. RID pipelines[SHADER_MAX];
  941. } rt_sdf;
  942. /* GLOBAL SHADER VARIABLES */
  943. struct GlobalVariables {
  944. enum {
  945. BUFFER_DIRTY_REGION_SIZE = 1024
  946. };
  947. struct Variable {
  948. Set<RID> texture_materials; // materials using this
  949. RS::GlobalVariableType type;
  950. Variant value;
  951. Variant override;
  952. int32_t buffer_index; //for vectors
  953. int32_t buffer_elements; //for vectors
  954. };
  955. HashMap<StringName, Variable> variables;
  956. struct Value {
  957. float x;
  958. float y;
  959. float z;
  960. float w;
  961. };
  962. struct ValueInt {
  963. int32_t x;
  964. int32_t y;
  965. int32_t z;
  966. int32_t w;
  967. };
  968. struct ValueUInt {
  969. uint32_t x;
  970. uint32_t y;
  971. uint32_t z;
  972. uint32_t w;
  973. };
  974. struct ValueUsage {
  975. uint32_t elements = 0;
  976. };
  977. List<RID> materials_using_buffer;
  978. List<RID> materials_using_texture;
  979. RID buffer;
  980. Value *buffer_values;
  981. ValueUsage *buffer_usage;
  982. bool *buffer_dirty_regions;
  983. uint32_t buffer_dirty_region_count = 0;
  984. uint32_t buffer_size;
  985. bool must_update_texture_materials = false;
  986. bool must_update_buffer_materials = false;
  987. HashMap<RID, int32_t> instance_buffer_pos;
  988. } global_variables;
  989. int32_t _global_variable_allocate(uint32_t p_elements);
  990. void _global_variable_store_in_buffer(int32_t p_index, RS::GlobalVariableType p_type, const Variant &p_value);
  991. void _global_variable_mark_buffer_dirty(int32_t p_index, int32_t p_elements);
  992. void _update_global_variables();
  993. /* EFFECTS */
  994. EffectsRD effects;
  995. public:
  996. virtual bool can_create_resources_async() const;
  997. /* TEXTURE API */
  998. virtual RID texture_allocate();
  999. virtual void texture_2d_initialize(RID p_texture, const Ref<Image> &p_image);
  1000. virtual void texture_2d_layered_initialize(RID p_texture, const Vector<Ref<Image>> &p_layers, RS::TextureLayeredType p_layered_type);
  1001. virtual void texture_3d_initialize(RID p_texture, Image::Format p_format, int p_width, int p_height, int p_depth, bool p_mipmaps, const Vector<Ref<Image>> &p_data); //all slices, then all the mipmaps, must be coherent
  1002. virtual void texture_proxy_initialize(RID p_texture, RID p_base);
  1003. virtual void _texture_2d_update(RID p_texture, const Ref<Image> &p_image, int p_layer, bool p_immediate);
  1004. virtual void texture_2d_update_immediate(RID p_texture, const Ref<Image> &p_image, int p_layer = 0); //mostly used for video and streaming
  1005. virtual void texture_2d_update(RID p_texture, const Ref<Image> &p_image, int p_layer = 0);
  1006. virtual void texture_3d_update(RID p_texture, const Vector<Ref<Image>> &p_data);
  1007. virtual void texture_proxy_update(RID p_texture, RID p_proxy_to);
  1008. //these two APIs can be used together or in combination with the others.
  1009. virtual void texture_2d_placeholder_initialize(RID p_texture);
  1010. virtual void texture_2d_layered_placeholder_initialize(RID p_texture, RenderingServer::TextureLayeredType p_layered_type);
  1011. virtual void texture_3d_placeholder_initialize(RID p_texture);
  1012. virtual Ref<Image> texture_2d_get(RID p_texture) const;
  1013. virtual Ref<Image> texture_2d_layer_get(RID p_texture, int p_layer) const;
  1014. virtual Vector<Ref<Image>> texture_3d_get(RID p_texture) const;
  1015. virtual void texture_replace(RID p_texture, RID p_by_texture);
  1016. virtual void texture_set_size_override(RID p_texture, int p_width, int p_height);
  1017. virtual void texture_set_path(RID p_texture, const String &p_path);
  1018. virtual String texture_get_path(RID p_texture) const;
  1019. virtual void texture_set_detect_3d_callback(RID p_texture, RS::TextureDetectCallback p_callback, void *p_userdata);
  1020. virtual void texture_set_detect_normal_callback(RID p_texture, RS::TextureDetectCallback p_callback, void *p_userdata);
  1021. virtual void texture_set_detect_roughness_callback(RID p_texture, RS::TextureDetectRoughnessCallback p_callback, void *p_userdata);
  1022. virtual void texture_debug_usage(List<RS::TextureInfo> *r_info);
  1023. virtual void texture_set_proxy(RID p_proxy, RID p_base);
  1024. virtual void texture_set_force_redraw_if_visible(RID p_texture, bool p_enable);
  1025. virtual Size2 texture_size_with_proxy(RID p_proxy);
  1026. virtual void texture_add_to_decal_atlas(RID p_texture, bool p_panorama_to_dp = false);
  1027. virtual void texture_remove_from_decal_atlas(RID p_texture, bool p_panorama_to_dp = false);
  1028. RID decal_atlas_get_texture() const;
  1029. RID decal_atlas_get_texture_srgb() const;
  1030. _FORCE_INLINE_ Rect2 decal_atlas_get_texture_rect(RID p_texture) {
  1031. DecalAtlas::Texture *t = decal_atlas.textures.getptr(p_texture);
  1032. if (!t) {
  1033. return Rect2();
  1034. }
  1035. return t->uv_rect;
  1036. }
  1037. //internal usage
  1038. _FORCE_INLINE_ RID texture_get_rd_texture(RID p_texture, bool p_srgb = false) {
  1039. if (p_texture.is_null()) {
  1040. return RID();
  1041. }
  1042. Texture *tex = texture_owner.getornull(p_texture);
  1043. if (!tex) {
  1044. return RID();
  1045. }
  1046. return (p_srgb && tex->rd_texture_srgb.is_valid()) ? tex->rd_texture_srgb : tex->rd_texture;
  1047. }
  1048. _FORCE_INLINE_ Size2i texture_2d_get_size(RID p_texture) {
  1049. if (p_texture.is_null()) {
  1050. return Size2i();
  1051. }
  1052. Texture *tex = texture_owner.getornull(p_texture);
  1053. if (!tex) {
  1054. return Size2i();
  1055. }
  1056. return Size2i(tex->width_2d, tex->height_2d);
  1057. }
  1058. _FORCE_INLINE_ RID texture_rd_get_default(DefaultRDTexture p_texture) {
  1059. return default_rd_textures[p_texture];
  1060. }
  1061. _FORCE_INLINE_ RID sampler_rd_get_default(RS::CanvasItemTextureFilter p_filter, RS::CanvasItemTextureRepeat p_repeat) {
  1062. return default_rd_samplers[p_filter][p_repeat];
  1063. }
  1064. /* CANVAS TEXTURE API */
  1065. RID canvas_texture_allocate();
  1066. void canvas_texture_initialize(RID p_canvas_texture);
  1067. virtual void canvas_texture_set_channel(RID p_canvas_texture, RS::CanvasTextureChannel p_channel, RID p_texture);
  1068. virtual void canvas_texture_set_shading_parameters(RID p_canvas_texture, const Color &p_specular_color, float p_shininess);
  1069. virtual void canvas_texture_set_texture_filter(RID p_canvas_texture, RS::CanvasItemTextureFilter p_filter);
  1070. virtual void canvas_texture_set_texture_repeat(RID p_canvas_texture, RS::CanvasItemTextureRepeat p_repeat);
  1071. 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);
  1072. /* SHADER API */
  1073. RID shader_allocate();
  1074. void shader_initialize(RID p_shader);
  1075. void shader_set_code(RID p_shader, const String &p_code);
  1076. String shader_get_code(RID p_shader) const;
  1077. void shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const;
  1078. void shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture);
  1079. RID shader_get_default_texture_param(RID p_shader, const StringName &p_name) const;
  1080. Variant shader_get_param_default(RID p_shader, const StringName &p_param) const;
  1081. void shader_set_data_request_function(ShaderType p_shader_type, ShaderDataRequestFunction p_function);
  1082. virtual RS::ShaderNativeSourceCode shader_get_native_source_code(RID p_shader) const;
  1083. /* COMMON MATERIAL API */
  1084. RID material_allocate();
  1085. void material_initialize(RID p_material);
  1086. void material_set_shader(RID p_material, RID p_shader);
  1087. void material_set_param(RID p_material, const StringName &p_param, const Variant &p_value);
  1088. Variant material_get_param(RID p_material, const StringName &p_param) const;
  1089. void material_set_next_pass(RID p_material, RID p_next_material);
  1090. void material_set_render_priority(RID p_material, int priority);
  1091. bool material_is_animated(RID p_material);
  1092. bool material_casts_shadows(RID p_material);
  1093. void material_get_instance_shader_parameters(RID p_material, List<InstanceShaderParam> *r_parameters);
  1094. void material_update_dependency(RID p_material, DependencyTracker *p_instance);
  1095. void material_force_update_textures(RID p_material, ShaderType p_shader_type);
  1096. void material_set_data_request_function(ShaderType p_shader_type, MaterialDataRequestFunction p_function);
  1097. _FORCE_INLINE_ uint32_t material_get_shader_id(RID p_material) {
  1098. Material *material = material_owner.getornull(p_material);
  1099. return material->shader_id;
  1100. }
  1101. _FORCE_INLINE_ MaterialData *material_get_data(RID p_material, ShaderType p_shader_type) {
  1102. Material *material = material_owner.getornull(p_material);
  1103. if (!material || material->shader_type != p_shader_type) {
  1104. return nullptr;
  1105. } else {
  1106. return material->data;
  1107. }
  1108. }
  1109. /* MESH API */
  1110. RID mesh_allocate();
  1111. void mesh_initialize(RID p_mesh);
  1112. virtual void mesh_set_blend_shape_count(RID p_mesh, int p_blend_shape_count);
  1113. /// Return stride
  1114. virtual void mesh_add_surface(RID p_mesh, const RS::SurfaceData &p_surface);
  1115. virtual int mesh_get_blend_shape_count(RID p_mesh) const;
  1116. virtual void mesh_set_blend_shape_mode(RID p_mesh, RS::BlendShapeMode p_mode);
  1117. virtual RS::BlendShapeMode mesh_get_blend_shape_mode(RID p_mesh) const;
  1118. virtual void mesh_surface_update_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data);
  1119. virtual void mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material);
  1120. virtual RID mesh_surface_get_material(RID p_mesh, int p_surface) const;
  1121. virtual RS::SurfaceData mesh_get_surface(RID p_mesh, int p_surface) const;
  1122. virtual int mesh_get_surface_count(RID p_mesh) const;
  1123. virtual void mesh_set_custom_aabb(RID p_mesh, const AABB &p_aabb);
  1124. virtual AABB mesh_get_custom_aabb(RID p_mesh) const;
  1125. virtual AABB mesh_get_aabb(RID p_mesh, RID p_skeleton = RID());
  1126. virtual void mesh_set_shadow_mesh(RID p_mesh, RID p_shadow_mesh);
  1127. virtual void mesh_clear(RID p_mesh);
  1128. virtual bool mesh_needs_instance(RID p_mesh, bool p_has_skeleton);
  1129. /* MESH INSTANCE */
  1130. virtual RID mesh_instance_create(RID p_base);
  1131. virtual void mesh_instance_set_skeleton(RID p_mesh_instance, RID p_skeleton);
  1132. virtual void mesh_instance_set_blend_shape_weight(RID p_mesh_instance, int p_shape, float p_weight);
  1133. virtual void mesh_instance_check_for_update(RID p_mesh_instance);
  1134. virtual void update_mesh_instances();
  1135. _FORCE_INLINE_ const RID *mesh_get_surface_count_and_materials(RID p_mesh, uint32_t &r_surface_count) {
  1136. Mesh *mesh = mesh_owner.getornull(p_mesh);
  1137. ERR_FAIL_COND_V(!mesh, nullptr);
  1138. r_surface_count = mesh->surface_count;
  1139. if (r_surface_count == 0) {
  1140. return nullptr;
  1141. }
  1142. if (mesh->material_cache.is_empty()) {
  1143. mesh->material_cache.resize(mesh->surface_count);
  1144. for (uint32_t i = 0; i < r_surface_count; i++) {
  1145. mesh->material_cache.write[i] = mesh->surfaces[i]->material;
  1146. }
  1147. }
  1148. return mesh->material_cache.ptr();
  1149. }
  1150. _FORCE_INLINE_ void *mesh_get_surface(RID p_mesh, uint32_t p_surface_index) {
  1151. Mesh *mesh = mesh_owner.getornull(p_mesh);
  1152. ERR_FAIL_COND_V(!mesh, nullptr);
  1153. ERR_FAIL_UNSIGNED_INDEX_V(p_surface_index, mesh->surface_count, nullptr);
  1154. return mesh->surfaces[p_surface_index];
  1155. }
  1156. _FORCE_INLINE_ RID mesh_get_shadow_mesh(RID p_mesh) {
  1157. Mesh *mesh = mesh_owner.getornull(p_mesh);
  1158. ERR_FAIL_COND_V(!mesh, RID());
  1159. return mesh->shadow_mesh;
  1160. }
  1161. _FORCE_INLINE_ RS::PrimitiveType mesh_surface_get_primitive(void *p_surface) {
  1162. Mesh::Surface *surface = reinterpret_cast<Mesh::Surface *>(p_surface);
  1163. return surface->primitive;
  1164. }
  1165. _FORCE_INLINE_ bool mesh_surface_has_lod(void *p_surface) const {
  1166. Mesh::Surface *s = reinterpret_cast<Mesh::Surface *>(p_surface);
  1167. return s->lod_count > 0;
  1168. }
  1169. _FORCE_INLINE_ uint32_t mesh_surface_get_lod(void *p_surface, float p_model_scale, float p_distance_threshold, float p_lod_threshold) const {
  1170. Mesh::Surface *s = reinterpret_cast<Mesh::Surface *>(p_surface);
  1171. int32_t current_lod = -1;
  1172. for (uint32_t i = 0; i < s->lod_count; i++) {
  1173. float screen_size = s->lods[i].edge_length * p_model_scale / p_distance_threshold;
  1174. if (screen_size > p_lod_threshold) {
  1175. break;
  1176. }
  1177. current_lod = i;
  1178. }
  1179. if (current_lod == -1) {
  1180. return 0;
  1181. } else {
  1182. return current_lod + 1;
  1183. }
  1184. }
  1185. _FORCE_INLINE_ RID mesh_surface_get_index_array(void *p_surface, uint32_t p_lod) const {
  1186. Mesh::Surface *s = reinterpret_cast<Mesh::Surface *>(p_surface);
  1187. if (p_lod == 0) {
  1188. return s->index_array;
  1189. } else {
  1190. return s->lods[p_lod - 1].index_array;
  1191. }
  1192. }
  1193. _FORCE_INLINE_ void mesh_surface_get_vertex_arrays_and_format(void *p_surface, uint32_t p_input_mask, RID &r_vertex_array_rd, RD::VertexFormatID &r_vertex_format) {
  1194. Mesh::Surface *s = reinterpret_cast<Mesh::Surface *>(p_surface);
  1195. s->version_lock.lock();
  1196. //there will never be more than, at much, 3 or 4 versions, so iterating is the fastest way
  1197. for (uint32_t i = 0; i < s->version_count; i++) {
  1198. if (s->versions[i].input_mask != p_input_mask) {
  1199. continue;
  1200. }
  1201. //we have this version, hooray
  1202. r_vertex_format = s->versions[i].vertex_format;
  1203. r_vertex_array_rd = s->versions[i].vertex_array;
  1204. s->version_lock.unlock();
  1205. return;
  1206. }
  1207. uint32_t version = s->version_count;
  1208. s->version_count++;
  1209. s->versions = (Mesh::Surface::Version *)memrealloc(s->versions, sizeof(Mesh::Surface::Version) * s->version_count);
  1210. _mesh_surface_generate_version_for_input_mask(s->versions[version], s, p_input_mask);
  1211. r_vertex_format = s->versions[version].vertex_format;
  1212. r_vertex_array_rd = s->versions[version].vertex_array;
  1213. s->version_lock.unlock();
  1214. }
  1215. _FORCE_INLINE_ void mesh_instance_surface_get_vertex_arrays_and_format(RID p_mesh_instance, uint32_t p_surface_index, uint32_t p_input_mask, RID &r_vertex_array_rd, RD::VertexFormatID &r_vertex_format) {
  1216. MeshInstance *mi = mesh_instance_owner.getornull(p_mesh_instance);
  1217. ERR_FAIL_COND(!mi);
  1218. Mesh *mesh = mi->mesh;
  1219. ERR_FAIL_UNSIGNED_INDEX(p_surface_index, mesh->surface_count);
  1220. MeshInstance::Surface *mis = &mi->surfaces[p_surface_index];
  1221. Mesh::Surface *s = mesh->surfaces[p_surface_index];
  1222. s->version_lock.lock();
  1223. //there will never be more than, at much, 3 or 4 versions, so iterating is the fastest way
  1224. for (uint32_t i = 0; i < mis->version_count; i++) {
  1225. if (mis->versions[i].input_mask != p_input_mask) {
  1226. continue;
  1227. }
  1228. //we have this version, hooray
  1229. r_vertex_format = mis->versions[i].vertex_format;
  1230. r_vertex_array_rd = mis->versions[i].vertex_array;
  1231. s->version_lock.unlock();
  1232. return;
  1233. }
  1234. uint32_t version = mis->version_count;
  1235. mis->version_count++;
  1236. mis->versions = (Mesh::Surface::Version *)memrealloc(mis->versions, sizeof(Mesh::Surface::Version) * mis->version_count);
  1237. _mesh_surface_generate_version_for_input_mask(mis->versions[version], s, p_input_mask, mis);
  1238. r_vertex_format = mis->versions[version].vertex_format;
  1239. r_vertex_array_rd = mis->versions[version].vertex_array;
  1240. s->version_lock.unlock();
  1241. }
  1242. _FORCE_INLINE_ RID mesh_get_default_rd_buffer(DefaultRDBuffer p_buffer) {
  1243. ERR_FAIL_INDEX_V(p_buffer, DEFAULT_RD_BUFFER_MAX, RID());
  1244. return mesh_default_rd_buffers[p_buffer];
  1245. }
  1246. _FORCE_INLINE_ uint32_t mesh_surface_get_render_pass_index(RID p_mesh, uint32_t p_surface_index, uint64_t p_render_pass, uint32_t *r_index) {
  1247. Mesh *mesh = mesh_owner.getornull(p_mesh);
  1248. Mesh::Surface *s = mesh->surfaces[p_surface_index];
  1249. if (s->render_pass != p_render_pass) {
  1250. (*r_index)++;
  1251. s->render_pass = p_render_pass;
  1252. s->render_index = *r_index;
  1253. }
  1254. return s->render_index;
  1255. }
  1256. _FORCE_INLINE_ uint32_t mesh_surface_get_multimesh_render_pass_index(RID p_mesh, uint32_t p_surface_index, uint64_t p_render_pass, uint32_t *r_index) {
  1257. Mesh *mesh = mesh_owner.getornull(p_mesh);
  1258. Mesh::Surface *s = mesh->surfaces[p_surface_index];
  1259. if (s->multimesh_render_pass != p_render_pass) {
  1260. (*r_index)++;
  1261. s->multimesh_render_pass = p_render_pass;
  1262. s->multimesh_render_index = *r_index;
  1263. }
  1264. return s->multimesh_render_index;
  1265. }
  1266. _FORCE_INLINE_ uint32_t mesh_surface_get_particles_render_pass_index(RID p_mesh, uint32_t p_surface_index, uint64_t p_render_pass, uint32_t *r_index) {
  1267. Mesh *mesh = mesh_owner.getornull(p_mesh);
  1268. Mesh::Surface *s = mesh->surfaces[p_surface_index];
  1269. if (s->particles_render_pass != p_render_pass) {
  1270. (*r_index)++;
  1271. s->particles_render_pass = p_render_pass;
  1272. s->particles_render_index = *r_index;
  1273. }
  1274. return s->particles_render_index;
  1275. }
  1276. /* MULTIMESH API */
  1277. RID multimesh_allocate();
  1278. void multimesh_initialize(RID p_multimesh);
  1279. void multimesh_allocate_data(RID p_multimesh, int p_instances, RS::MultimeshTransformFormat p_transform_format, bool p_use_colors = false, bool p_use_custom_data = false);
  1280. int multimesh_get_instance_count(RID p_multimesh) const;
  1281. void multimesh_set_mesh(RID p_multimesh, RID p_mesh);
  1282. void multimesh_instance_set_transform(RID p_multimesh, int p_index, const Transform &p_transform);
  1283. void multimesh_instance_set_transform_2d(RID p_multimesh, int p_index, const Transform2D &p_transform);
  1284. void multimesh_instance_set_color(RID p_multimesh, int p_index, const Color &p_color);
  1285. void multimesh_instance_set_custom_data(RID p_multimesh, int p_index, const Color &p_color);
  1286. RID multimesh_get_mesh(RID p_multimesh) const;
  1287. Transform multimesh_instance_get_transform(RID p_multimesh, int p_index) const;
  1288. Transform2D multimesh_instance_get_transform_2d(RID p_multimesh, int p_index) const;
  1289. Color multimesh_instance_get_color(RID p_multimesh, int p_index) const;
  1290. Color multimesh_instance_get_custom_data(RID p_multimesh, int p_index) const;
  1291. void multimesh_set_buffer(RID p_multimesh, const Vector<float> &p_buffer);
  1292. Vector<float> multimesh_get_buffer(RID p_multimesh) const;
  1293. void multimesh_set_visible_instances(RID p_multimesh, int p_visible);
  1294. int multimesh_get_visible_instances(RID p_multimesh) const;
  1295. AABB multimesh_get_aabb(RID p_multimesh) const;
  1296. _FORCE_INLINE_ RS::MultimeshTransformFormat multimesh_get_transform_format(RID p_multimesh) const {
  1297. MultiMesh *multimesh = multimesh_owner.getornull(p_multimesh);
  1298. return multimesh->xform_format;
  1299. }
  1300. _FORCE_INLINE_ bool multimesh_uses_colors(RID p_multimesh) const {
  1301. MultiMesh *multimesh = multimesh_owner.getornull(p_multimesh);
  1302. return multimesh->uses_colors;
  1303. }
  1304. _FORCE_INLINE_ bool multimesh_uses_custom_data(RID p_multimesh) const {
  1305. MultiMesh *multimesh = multimesh_owner.getornull(p_multimesh);
  1306. return multimesh->uses_custom_data;
  1307. }
  1308. _FORCE_INLINE_ uint32_t multimesh_get_instances_to_draw(RID p_multimesh) const {
  1309. MultiMesh *multimesh = multimesh_owner.getornull(p_multimesh);
  1310. if (multimesh->visible_instances >= 0) {
  1311. return multimesh->visible_instances;
  1312. }
  1313. return multimesh->instances;
  1314. }
  1315. _FORCE_INLINE_ RID multimesh_get_3d_uniform_set(RID p_multimesh, RID p_shader, uint32_t p_set) const {
  1316. MultiMesh *multimesh = multimesh_owner.getornull(p_multimesh);
  1317. if (!multimesh->uniform_set_3d.is_valid()) {
  1318. Vector<RD::Uniform> uniforms;
  1319. RD::Uniform u;
  1320. u.uniform_type = RD::UNIFORM_TYPE_STORAGE_BUFFER;
  1321. u.binding = 0;
  1322. u.ids.push_back(multimesh->buffer);
  1323. uniforms.push_back(u);
  1324. multimesh->uniform_set_3d = RD::get_singleton()->uniform_set_create(uniforms, p_shader, p_set);
  1325. }
  1326. return multimesh->uniform_set_3d;
  1327. }
  1328. /* IMMEDIATE API */
  1329. RID immediate_allocate() { return RID(); }
  1330. void immediate_initialize(RID p_immediate) {}
  1331. virtual void immediate_begin(RID p_immediate, RS::PrimitiveType p_rimitive, RID p_texture = RID()) {}
  1332. virtual void immediate_vertex(RID p_immediate, const Vector3 &p_vertex) {}
  1333. virtual void immediate_normal(RID p_immediate, const Vector3 &p_normal) {}
  1334. virtual void immediate_tangent(RID p_immediate, const Plane &p_tangent) {}
  1335. virtual void immediate_color(RID p_immediate, const Color &p_color) {}
  1336. virtual void immediate_uv(RID p_immediate, const Vector2 &tex_uv) {}
  1337. virtual void immediate_uv2(RID p_immediate, const Vector2 &tex_uv) {}
  1338. virtual void immediate_end(RID p_immediate) {}
  1339. virtual void immediate_clear(RID p_immediate) {}
  1340. virtual void immediate_set_material(RID p_immediate, RID p_material) {}
  1341. virtual RID immediate_get_material(RID p_immediate) const { return RID(); }
  1342. virtual AABB immediate_get_aabb(RID p_immediate) const { return AABB(); }
  1343. /* SKELETON API */
  1344. RID skeleton_allocate();
  1345. void skeleton_initialize(RID p_skeleton);
  1346. void skeleton_allocate_data(RID p_skeleton, int p_bones, bool p_2d_skeleton = false);
  1347. void skeleton_set_base_transform_2d(RID p_skeleton, const Transform2D &p_base_transform);
  1348. void skeleton_set_world_transform(RID p_skeleton, bool p_enable, const Transform &p_world_transform);
  1349. int skeleton_get_bone_count(RID p_skeleton) const;
  1350. void skeleton_bone_set_transform(RID p_skeleton, int p_bone, const Transform &p_transform);
  1351. Transform skeleton_bone_get_transform(RID p_skeleton, int p_bone) const;
  1352. void skeleton_bone_set_transform_2d(RID p_skeleton, int p_bone, const Transform2D &p_transform);
  1353. Transform2D skeleton_bone_get_transform_2d(RID p_skeleton, int p_bone) const;
  1354. _FORCE_INLINE_ bool skeleton_is_valid(RID p_skeleton) {
  1355. return skeleton_owner.getornull(p_skeleton) != nullptr;
  1356. }
  1357. _FORCE_INLINE_ RID skeleton_get_3d_uniform_set(RID p_skeleton, RID p_shader, uint32_t p_set) const {
  1358. Skeleton *skeleton = skeleton_owner.getornull(p_skeleton);
  1359. ERR_FAIL_COND_V(!skeleton, RID());
  1360. ERR_FAIL_COND_V(skeleton->size == 0, RID());
  1361. if (skeleton->use_2d) {
  1362. return RID();
  1363. }
  1364. if (!skeleton->uniform_set_3d.is_valid()) {
  1365. Vector<RD::Uniform> uniforms;
  1366. RD::Uniform u;
  1367. u.uniform_type = RD::UNIFORM_TYPE_STORAGE_BUFFER;
  1368. u.binding = 0;
  1369. u.ids.push_back(skeleton->buffer);
  1370. uniforms.push_back(u);
  1371. skeleton->uniform_set_3d = RD::get_singleton()->uniform_set_create(uniforms, p_shader, p_set);
  1372. }
  1373. return skeleton->uniform_set_3d;
  1374. }
  1375. /* Light API */
  1376. void _light_initialize(RID p_rid, RS::LightType p_type);
  1377. RID directional_light_allocate();
  1378. void directional_light_initialize(RID p_light);
  1379. RID omni_light_allocate();
  1380. void omni_light_initialize(RID p_light);
  1381. RID spot_light_allocate();
  1382. void spot_light_initialize(RID p_light);
  1383. void light_set_color(RID p_light, const Color &p_color);
  1384. void light_set_param(RID p_light, RS::LightParam p_param, float p_value);
  1385. void light_set_shadow(RID p_light, bool p_enabled);
  1386. void light_set_shadow_color(RID p_light, const Color &p_color);
  1387. void light_set_projector(RID p_light, RID p_texture);
  1388. void light_set_negative(RID p_light, bool p_enable);
  1389. void light_set_cull_mask(RID p_light, uint32_t p_mask);
  1390. void light_set_reverse_cull_face_mode(RID p_light, bool p_enabled);
  1391. void light_set_bake_mode(RID p_light, RS::LightBakeMode p_bake_mode);
  1392. void light_set_max_sdfgi_cascade(RID p_light, uint32_t p_cascade);
  1393. void light_omni_set_shadow_mode(RID p_light, RS::LightOmniShadowMode p_mode);
  1394. void light_directional_set_shadow_mode(RID p_light, RS::LightDirectionalShadowMode p_mode);
  1395. void light_directional_set_blend_splits(RID p_light, bool p_enable);
  1396. bool light_directional_get_blend_splits(RID p_light) const;
  1397. void light_directional_set_sky_only(RID p_light, bool p_sky_only);
  1398. bool light_directional_is_sky_only(RID p_light) const;
  1399. void light_directional_set_shadow_depth_range_mode(RID p_light, RS::LightDirectionalShadowDepthRangeMode p_range_mode);
  1400. RS::LightDirectionalShadowDepthRangeMode light_directional_get_shadow_depth_range_mode(RID p_light) const;
  1401. RS::LightDirectionalShadowMode light_directional_get_shadow_mode(RID p_light);
  1402. RS::LightOmniShadowMode light_omni_get_shadow_mode(RID p_light);
  1403. _FORCE_INLINE_ RS::LightType light_get_type(RID p_light) const {
  1404. const Light *light = light_owner.getornull(p_light);
  1405. ERR_FAIL_COND_V(!light, RS::LIGHT_DIRECTIONAL);
  1406. return light->type;
  1407. }
  1408. AABB light_get_aabb(RID p_light) const;
  1409. _FORCE_INLINE_ float light_get_param(RID p_light, RS::LightParam p_param) {
  1410. const Light *light = light_owner.getornull(p_light);
  1411. ERR_FAIL_COND_V(!light, 0);
  1412. return light->param[p_param];
  1413. }
  1414. _FORCE_INLINE_ RID light_get_projector(RID p_light) {
  1415. const Light *light = light_owner.getornull(p_light);
  1416. ERR_FAIL_COND_V(!light, RID());
  1417. return light->projector;
  1418. }
  1419. _FORCE_INLINE_ Color light_get_color(RID p_light) {
  1420. const Light *light = light_owner.getornull(p_light);
  1421. ERR_FAIL_COND_V(!light, Color());
  1422. return light->color;
  1423. }
  1424. _FORCE_INLINE_ Color light_get_shadow_color(RID p_light) {
  1425. const Light *light = light_owner.getornull(p_light);
  1426. ERR_FAIL_COND_V(!light, Color());
  1427. return light->shadow_color;
  1428. }
  1429. _FORCE_INLINE_ uint32_t light_get_cull_mask(RID p_light) {
  1430. const Light *light = light_owner.getornull(p_light);
  1431. ERR_FAIL_COND_V(!light, 0);
  1432. return light->cull_mask;
  1433. }
  1434. _FORCE_INLINE_ bool light_has_shadow(RID p_light) const {
  1435. const Light *light = light_owner.getornull(p_light);
  1436. ERR_FAIL_COND_V(!light, RS::LIGHT_DIRECTIONAL);
  1437. return light->shadow;
  1438. }
  1439. _FORCE_INLINE_ bool light_is_negative(RID p_light) const {
  1440. const Light *light = light_owner.getornull(p_light);
  1441. ERR_FAIL_COND_V(!light, RS::LIGHT_DIRECTIONAL);
  1442. return light->negative;
  1443. }
  1444. _FORCE_INLINE_ float light_get_transmittance_bias(RID p_light) const {
  1445. const Light *light = light_owner.getornull(p_light);
  1446. ERR_FAIL_COND_V(!light, 0.0);
  1447. return light->param[RS::LIGHT_PARAM_TRANSMITTANCE_BIAS];
  1448. }
  1449. _FORCE_INLINE_ float light_get_shadow_volumetric_fog_fade(RID p_light) const {
  1450. const Light *light = light_owner.getornull(p_light);
  1451. ERR_FAIL_COND_V(!light, 0.0);
  1452. return light->param[RS::LIGHT_PARAM_SHADOW_VOLUMETRIC_FOG_FADE];
  1453. }
  1454. RS::LightBakeMode light_get_bake_mode(RID p_light);
  1455. uint32_t light_get_max_sdfgi_cascade(RID p_light);
  1456. uint64_t light_get_version(RID p_light) const;
  1457. /* PROBE API */
  1458. RID reflection_probe_allocate();
  1459. void reflection_probe_initialize(RID p_reflection_probe);
  1460. void reflection_probe_set_update_mode(RID p_probe, RS::ReflectionProbeUpdateMode p_mode);
  1461. void reflection_probe_set_intensity(RID p_probe, float p_intensity);
  1462. void reflection_probe_set_ambient_mode(RID p_probe, RS::ReflectionProbeAmbientMode p_mode);
  1463. void reflection_probe_set_ambient_color(RID p_probe, const Color &p_color);
  1464. void reflection_probe_set_ambient_energy(RID p_probe, float p_energy);
  1465. void reflection_probe_set_max_distance(RID p_probe, float p_distance);
  1466. void reflection_probe_set_extents(RID p_probe, const Vector3 &p_extents);
  1467. void reflection_probe_set_origin_offset(RID p_probe, const Vector3 &p_offset);
  1468. void reflection_probe_set_as_interior(RID p_probe, bool p_enable);
  1469. void reflection_probe_set_enable_box_projection(RID p_probe, bool p_enable);
  1470. void reflection_probe_set_enable_shadows(RID p_probe, bool p_enable);
  1471. void reflection_probe_set_cull_mask(RID p_probe, uint32_t p_layers);
  1472. void reflection_probe_set_resolution(RID p_probe, int p_resolution);
  1473. void reflection_probe_set_lod_threshold(RID p_probe, float p_ratio);
  1474. AABB reflection_probe_get_aabb(RID p_probe) const;
  1475. RS::ReflectionProbeUpdateMode reflection_probe_get_update_mode(RID p_probe) const;
  1476. uint32_t reflection_probe_get_cull_mask(RID p_probe) const;
  1477. Vector3 reflection_probe_get_extents(RID p_probe) const;
  1478. Vector3 reflection_probe_get_origin_offset(RID p_probe) const;
  1479. float reflection_probe_get_origin_max_distance(RID p_probe) const;
  1480. float reflection_probe_get_lod_threshold(RID p_probe) const;
  1481. int reflection_probe_get_resolution(RID p_probe) const;
  1482. bool reflection_probe_renders_shadows(RID p_probe) const;
  1483. float reflection_probe_get_intensity(RID p_probe) const;
  1484. bool reflection_probe_is_interior(RID p_probe) const;
  1485. bool reflection_probe_is_box_projection(RID p_probe) const;
  1486. RS::ReflectionProbeAmbientMode reflection_probe_get_ambient_mode(RID p_probe) const;
  1487. Color reflection_probe_get_ambient_color(RID p_probe) const;
  1488. float reflection_probe_get_ambient_color_energy(RID p_probe) const;
  1489. void base_update_dependency(RID p_base, DependencyTracker *p_instance);
  1490. void skeleton_update_dependency(RID p_skeleton, DependencyTracker *p_instance);
  1491. /* DECAL API */
  1492. RID decal_allocate();
  1493. void decal_initialize(RID p_decal);
  1494. virtual void decal_set_extents(RID p_decal, const Vector3 &p_extents);
  1495. virtual void decal_set_texture(RID p_decal, RS::DecalTexture p_type, RID p_texture);
  1496. virtual void decal_set_emission_energy(RID p_decal, float p_energy);
  1497. virtual void decal_set_albedo_mix(RID p_decal, float p_mix);
  1498. virtual void decal_set_modulate(RID p_decal, const Color &p_modulate);
  1499. virtual void decal_set_cull_mask(RID p_decal, uint32_t p_layers);
  1500. virtual void decal_set_distance_fade(RID p_decal, bool p_enabled, float p_begin, float p_length);
  1501. virtual void decal_set_fade(RID p_decal, float p_above, float p_below);
  1502. virtual void decal_set_normal_fade(RID p_decal, float p_fade);
  1503. _FORCE_INLINE_ Vector3 decal_get_extents(RID p_decal) {
  1504. const Decal *decal = decal_owner.getornull(p_decal);
  1505. return decal->extents;
  1506. }
  1507. _FORCE_INLINE_ RID decal_get_texture(RID p_decal, RS::DecalTexture p_texture) {
  1508. const Decal *decal = decal_owner.getornull(p_decal);
  1509. return decal->textures[p_texture];
  1510. }
  1511. _FORCE_INLINE_ Color decal_get_modulate(RID p_decal) {
  1512. const Decal *decal = decal_owner.getornull(p_decal);
  1513. return decal->modulate;
  1514. }
  1515. _FORCE_INLINE_ float decal_get_emission_energy(RID p_decal) {
  1516. const Decal *decal = decal_owner.getornull(p_decal);
  1517. return decal->emission_energy;
  1518. }
  1519. _FORCE_INLINE_ float decal_get_albedo_mix(RID p_decal) {
  1520. const Decal *decal = decal_owner.getornull(p_decal);
  1521. return decal->albedo_mix;
  1522. }
  1523. _FORCE_INLINE_ uint32_t decal_get_cull_mask(RID p_decal) {
  1524. const Decal *decal = decal_owner.getornull(p_decal);
  1525. return decal->cull_mask;
  1526. }
  1527. _FORCE_INLINE_ float decal_get_upper_fade(RID p_decal) {
  1528. const Decal *decal = decal_owner.getornull(p_decal);
  1529. return decal->upper_fade;
  1530. }
  1531. _FORCE_INLINE_ float decal_get_lower_fade(RID p_decal) {
  1532. const Decal *decal = decal_owner.getornull(p_decal);
  1533. return decal->lower_fade;
  1534. }
  1535. _FORCE_INLINE_ float decal_get_normal_fade(RID p_decal) {
  1536. const Decal *decal = decal_owner.getornull(p_decal);
  1537. return decal->normal_fade;
  1538. }
  1539. _FORCE_INLINE_ bool decal_is_distance_fade_enabled(RID p_decal) {
  1540. const Decal *decal = decal_owner.getornull(p_decal);
  1541. return decal->distance_fade;
  1542. }
  1543. _FORCE_INLINE_ float decal_get_distance_fade_begin(RID p_decal) {
  1544. const Decal *decal = decal_owner.getornull(p_decal);
  1545. return decal->distance_fade_begin;
  1546. }
  1547. _FORCE_INLINE_ float decal_get_distance_fade_length(RID p_decal) {
  1548. const Decal *decal = decal_owner.getornull(p_decal);
  1549. return decal->distance_fade_length;
  1550. }
  1551. virtual AABB decal_get_aabb(RID p_decal) const;
  1552. /* GI PROBE API */
  1553. RID gi_probe_allocate();
  1554. void gi_probe_initialize(RID p_gi_probe);
  1555. void gi_probe_allocate_data(RID p_gi_probe, const Transform &p_to_cell_xform, const AABB &p_aabb, const Vector3i &p_octree_size, const Vector<uint8_t> &p_octree_cells, const Vector<uint8_t> &p_data_cells, const Vector<uint8_t> &p_distance_field, const Vector<int> &p_level_counts);
  1556. AABB gi_probe_get_bounds(RID p_gi_probe) const;
  1557. Vector3i gi_probe_get_octree_size(RID p_gi_probe) const;
  1558. Vector<uint8_t> gi_probe_get_octree_cells(RID p_gi_probe) const;
  1559. Vector<uint8_t> gi_probe_get_data_cells(RID p_gi_probe) const;
  1560. Vector<uint8_t> gi_probe_get_distance_field(RID p_gi_probe) const;
  1561. Vector<int> gi_probe_get_level_counts(RID p_gi_probe) const;
  1562. Transform gi_probe_get_to_cell_xform(RID p_gi_probe) const;
  1563. void gi_probe_set_dynamic_range(RID p_gi_probe, float p_range);
  1564. float gi_probe_get_dynamic_range(RID p_gi_probe) const;
  1565. void gi_probe_set_propagation(RID p_gi_probe, float p_range);
  1566. float gi_probe_get_propagation(RID p_gi_probe) const;
  1567. void gi_probe_set_energy(RID p_gi_probe, float p_energy);
  1568. float gi_probe_get_energy(RID p_gi_probe) const;
  1569. void gi_probe_set_ao(RID p_gi_probe, float p_ao);
  1570. float gi_probe_get_ao(RID p_gi_probe) const;
  1571. void gi_probe_set_ao_size(RID p_gi_probe, float p_strength);
  1572. float gi_probe_get_ao_size(RID p_gi_probe) const;
  1573. void gi_probe_set_bias(RID p_gi_probe, float p_bias);
  1574. float gi_probe_get_bias(RID p_gi_probe) const;
  1575. void gi_probe_set_normal_bias(RID p_gi_probe, float p_range);
  1576. float gi_probe_get_normal_bias(RID p_gi_probe) const;
  1577. void gi_probe_set_interior(RID p_gi_probe, bool p_enable);
  1578. bool gi_probe_is_interior(RID p_gi_probe) const;
  1579. void gi_probe_set_use_two_bounces(RID p_gi_probe, bool p_enable);
  1580. bool gi_probe_is_using_two_bounces(RID p_gi_probe) const;
  1581. void gi_probe_set_anisotropy_strength(RID p_gi_probe, float p_strength);
  1582. float gi_probe_get_anisotropy_strength(RID p_gi_probe) const;
  1583. uint32_t gi_probe_get_version(RID p_probe);
  1584. uint32_t gi_probe_get_data_version(RID p_probe);
  1585. RID gi_probe_get_octree_buffer(RID p_gi_probe) const;
  1586. RID gi_probe_get_data_buffer(RID p_gi_probe) const;
  1587. RID gi_probe_get_sdf_texture(RID p_gi_probe);
  1588. /* LIGHTMAP CAPTURE */
  1589. RID lightmap_allocate();
  1590. void lightmap_initialize(RID p_lightmap);
  1591. virtual void lightmap_set_textures(RID p_lightmap, RID p_light, bool p_uses_spherical_haromics);
  1592. virtual void lightmap_set_probe_bounds(RID p_lightmap, const AABB &p_bounds);
  1593. virtual void lightmap_set_probe_interior(RID p_lightmap, bool p_interior);
  1594. virtual void lightmap_set_probe_capture_data(RID p_lightmap, const PackedVector3Array &p_points, const PackedColorArray &p_point_sh, const PackedInt32Array &p_tetrahedra, const PackedInt32Array &p_bsp_tree);
  1595. virtual PackedVector3Array lightmap_get_probe_capture_points(RID p_lightmap) const;
  1596. virtual PackedColorArray lightmap_get_probe_capture_sh(RID p_lightmap) const;
  1597. virtual PackedInt32Array lightmap_get_probe_capture_tetrahedra(RID p_lightmap) const;
  1598. virtual PackedInt32Array lightmap_get_probe_capture_bsp_tree(RID p_lightmap) const;
  1599. virtual AABB lightmap_get_aabb(RID p_lightmap) const;
  1600. virtual bool lightmap_is_interior(RID p_lightmap) const;
  1601. virtual void lightmap_tap_sh_light(RID p_lightmap, const Vector3 &p_point, Color *r_sh);
  1602. virtual void lightmap_set_probe_capture_update_speed(float p_speed);
  1603. _FORCE_INLINE_ float lightmap_get_probe_capture_update_speed() const {
  1604. return lightmap_probe_capture_update_speed;
  1605. }
  1606. _FORCE_INLINE_ RID lightmap_get_texture(RID p_lightmap) const {
  1607. const Lightmap *lm = lightmap_owner.getornull(p_lightmap);
  1608. ERR_FAIL_COND_V(!lm, RID());
  1609. return lm->light_texture;
  1610. }
  1611. _FORCE_INLINE_ int32_t lightmap_get_array_index(RID p_lightmap) const {
  1612. ERR_FAIL_COND_V(!using_lightmap_array, -1); //only for arrays
  1613. const Lightmap *lm = lightmap_owner.getornull(p_lightmap);
  1614. return lm->array_index;
  1615. }
  1616. _FORCE_INLINE_ bool lightmap_uses_spherical_harmonics(RID p_lightmap) const {
  1617. ERR_FAIL_COND_V(!using_lightmap_array, false); //only for arrays
  1618. const Lightmap *lm = lightmap_owner.getornull(p_lightmap);
  1619. return lm->uses_spherical_harmonics;
  1620. }
  1621. _FORCE_INLINE_ uint64_t lightmap_array_get_version() const {
  1622. ERR_FAIL_COND_V(!using_lightmap_array, 0); //only for arrays
  1623. return lightmap_array_version;
  1624. }
  1625. _FORCE_INLINE_ int lightmap_array_get_size() const {
  1626. ERR_FAIL_COND_V(!using_lightmap_array, 0); //only for arrays
  1627. return lightmap_textures.size();
  1628. }
  1629. _FORCE_INLINE_ const Vector<RID> &lightmap_array_get_textures() const {
  1630. ERR_FAIL_COND_V(!using_lightmap_array, lightmap_textures); //only for arrays
  1631. return lightmap_textures;
  1632. }
  1633. /* PARTICLES */
  1634. RID particles_allocate();
  1635. void particles_initialize(RID p_particles_collision);
  1636. void particles_set_emitting(RID p_particles, bool p_emitting);
  1637. void particles_set_amount(RID p_particles, int p_amount);
  1638. void particles_set_lifetime(RID p_particles, float p_lifetime);
  1639. void particles_set_one_shot(RID p_particles, bool p_one_shot);
  1640. void particles_set_pre_process_time(RID p_particles, float p_time);
  1641. void particles_set_explosiveness_ratio(RID p_particles, float p_ratio);
  1642. void particles_set_randomness_ratio(RID p_particles, float p_ratio);
  1643. void particles_set_custom_aabb(RID p_particles, const AABB &p_aabb);
  1644. void particles_set_speed_scale(RID p_particles, float p_scale);
  1645. void particles_set_use_local_coordinates(RID p_particles, bool p_enable);
  1646. void particles_set_process_material(RID p_particles, RID p_material);
  1647. void particles_set_fixed_fps(RID p_particles, int p_fps);
  1648. void particles_set_fractional_delta(RID p_particles, bool p_enable);
  1649. void particles_set_collision_base_size(RID p_particles, float p_size);
  1650. void particles_restart(RID p_particles);
  1651. void particles_emit(RID p_particles, const Transform &p_transform, const Vector3 &p_velocity, const Color &p_color, const Color &p_custom, uint32_t p_emit_flags);
  1652. void particles_set_subemitter(RID p_particles, RID p_subemitter_particles);
  1653. void particles_set_draw_order(RID p_particles, RS::ParticlesDrawOrder p_order);
  1654. void particles_set_draw_passes(RID p_particles, int p_count);
  1655. void particles_set_draw_pass_mesh(RID p_particles, int p_pass, RID p_mesh);
  1656. void particles_request_process(RID p_particles);
  1657. AABB particles_get_current_aabb(RID p_particles);
  1658. AABB particles_get_aabb(RID p_particles) const;
  1659. void particles_set_emission_transform(RID p_particles, const Transform &p_transform);
  1660. bool particles_get_emitting(RID p_particles);
  1661. int particles_get_draw_passes(RID p_particles) const;
  1662. RID particles_get_draw_pass_mesh(RID p_particles, int p_pass) const;
  1663. void particles_set_view_axis(RID p_particles, const Vector3 &p_axis);
  1664. virtual bool particles_is_inactive(RID p_particles) const;
  1665. _FORCE_INLINE_ uint32_t particles_get_amount(RID p_particles) {
  1666. Particles *particles = particles_owner.getornull(p_particles);
  1667. ERR_FAIL_COND_V(!particles, 0);
  1668. return particles->amount;
  1669. }
  1670. _FORCE_INLINE_ uint32_t particles_is_using_local_coords(RID p_particles) {
  1671. Particles *particles = particles_owner.getornull(p_particles);
  1672. ERR_FAIL_COND_V(!particles, false);
  1673. return particles->use_local_coords;
  1674. }
  1675. _FORCE_INLINE_ RID particles_get_instance_buffer_uniform_set(RID p_particles, RID p_shader, uint32_t p_set) {
  1676. Particles *particles = particles_owner.getornull(p_particles);
  1677. ERR_FAIL_COND_V(!particles, RID());
  1678. if (particles->particles_transforms_buffer_uniform_set.is_null()) {
  1679. Vector<RD::Uniform> uniforms;
  1680. {
  1681. RD::Uniform u;
  1682. u.uniform_type = RD::UNIFORM_TYPE_STORAGE_BUFFER;
  1683. u.binding = 0;
  1684. u.ids.push_back(particles->particle_instance_buffer);
  1685. uniforms.push_back(u);
  1686. }
  1687. particles->particles_transforms_buffer_uniform_set = RD::get_singleton()->uniform_set_create(uniforms, p_shader, p_set);
  1688. }
  1689. return particles->particles_transforms_buffer_uniform_set;
  1690. }
  1691. virtual void particles_add_collision(RID p_particles, RID p_particles_collision_instance);
  1692. virtual void particles_remove_collision(RID p_particles, RID p_particles_collision_instance);
  1693. /* PARTICLES COLLISION */
  1694. RID particles_collision_allocate();
  1695. void particles_collision_initialize(RID p_particles_collision);
  1696. virtual void particles_collision_set_collision_type(RID p_particles_collision, RS::ParticlesCollisionType p_type);
  1697. virtual void particles_collision_set_cull_mask(RID p_particles_collision, uint32_t p_cull_mask);
  1698. virtual void particles_collision_set_sphere_radius(RID p_particles_collision, float p_radius); //for spheres
  1699. virtual void particles_collision_set_box_extents(RID p_particles_collision, const Vector3 &p_extents); //for non-spheres
  1700. virtual void particles_collision_set_attractor_strength(RID p_particles_collision, float p_strength);
  1701. virtual void particles_collision_set_attractor_directionality(RID p_particles_collision, float p_directionality);
  1702. virtual void particles_collision_set_attractor_attenuation(RID p_particles_collision, float p_curve);
  1703. virtual void particles_collision_set_field_texture(RID p_particles_collision, RID p_texture); //for SDF and vector field, heightfield is dynamic
  1704. virtual void particles_collision_height_field_update(RID p_particles_collision); //for SDF and vector field
  1705. virtual void particles_collision_set_height_field_resolution(RID p_particles_collision, RS::ParticlesCollisionHeightfieldResolution p_resolution); //for SDF and vector field
  1706. virtual AABB particles_collision_get_aabb(RID p_particles_collision) const;
  1707. virtual Vector3 particles_collision_get_extents(RID p_particles_collision) const;
  1708. virtual bool particles_collision_is_heightfield(RID p_particles_collision) const;
  1709. RID particles_collision_get_heightfield_framebuffer(RID p_particles_collision) const;
  1710. //used from 2D and 3D
  1711. virtual RID particles_collision_instance_create(RID p_collision);
  1712. virtual void particles_collision_instance_set_transform(RID p_collision_instance, const Transform &p_transform);
  1713. virtual void particles_collision_instance_set_active(RID p_collision_instance, bool p_active);
  1714. /* GLOBAL VARIABLES API */
  1715. virtual void global_variable_add(const StringName &p_name, RS::GlobalVariableType p_type, const Variant &p_value);
  1716. virtual void global_variable_remove(const StringName &p_name);
  1717. virtual Vector<StringName> global_variable_get_list() const;
  1718. virtual void global_variable_set(const StringName &p_name, const Variant &p_value);
  1719. virtual void global_variable_set_override(const StringName &p_name, const Variant &p_value);
  1720. virtual Variant global_variable_get(const StringName &p_name) const;
  1721. virtual RS::GlobalVariableType global_variable_get_type(const StringName &p_name) const;
  1722. RS::GlobalVariableType global_variable_get_type_internal(const StringName &p_name) const;
  1723. virtual void global_variables_load_settings(bool p_load_textures = true);
  1724. virtual void global_variables_clear();
  1725. virtual int32_t global_variables_instance_allocate(RID p_instance);
  1726. virtual void global_variables_instance_free(RID p_instance);
  1727. virtual void global_variables_instance_update(RID p_instance, int p_index, const Variant &p_value);
  1728. RID global_variables_get_storage_buffer() const;
  1729. /* RENDER TARGET API */
  1730. RID render_target_create();
  1731. void render_target_set_position(RID p_render_target, int p_x, int p_y);
  1732. void render_target_set_size(RID p_render_target, int p_width, int p_height);
  1733. RID render_target_get_texture(RID p_render_target);
  1734. void render_target_set_external_texture(RID p_render_target, unsigned int p_texture_id);
  1735. void render_target_set_flag(RID p_render_target, RenderTargetFlags p_flag, bool p_value);
  1736. bool render_target_was_used(RID p_render_target);
  1737. void render_target_set_as_unused(RID p_render_target);
  1738. void render_target_copy_to_back_buffer(RID p_render_target, const Rect2i &p_region, bool p_gen_mipmaps);
  1739. void render_target_clear_back_buffer(RID p_render_target, const Rect2i &p_region, const Color &p_color);
  1740. void render_target_gen_back_buffer_mipmaps(RID p_render_target, const Rect2i &p_region);
  1741. RID render_target_get_back_buffer_uniform_set(RID p_render_target, RID p_base_shader);
  1742. virtual void render_target_request_clear(RID p_render_target, const Color &p_clear_color);
  1743. virtual bool render_target_is_clear_requested(RID p_render_target);
  1744. virtual Color render_target_get_clear_request_color(RID p_render_target);
  1745. virtual void render_target_disable_clear_request(RID p_render_target);
  1746. virtual void render_target_do_clear_request(RID p_render_target);
  1747. virtual void render_target_set_sdf_size_and_scale(RID p_render_target, RS::ViewportSDFOversize p_size, RS::ViewportSDFScale p_scale);
  1748. RID render_target_get_sdf_texture(RID p_render_target);
  1749. RID render_target_get_sdf_framebuffer(RID p_render_target);
  1750. void render_target_sdf_process(RID p_render_target);
  1751. virtual Rect2i render_target_get_sdf_rect(RID p_render_target) const;
  1752. Size2 render_target_get_size(RID p_render_target);
  1753. RID render_target_get_rd_framebuffer(RID p_render_target);
  1754. RID render_target_get_rd_texture(RID p_render_target);
  1755. RID render_target_get_rd_backbuffer(RID p_render_target);
  1756. RID render_target_get_rd_backbuffer_framebuffer(RID p_render_target);
  1757. RID render_target_get_framebuffer_uniform_set(RID p_render_target);
  1758. RID render_target_get_backbuffer_uniform_set(RID p_render_target);
  1759. void render_target_set_framebuffer_uniform_set(RID p_render_target, RID p_uniform_set);
  1760. void render_target_set_backbuffer_uniform_set(RID p_render_target, RID p_uniform_set);
  1761. RS::InstanceType get_base_type(RID p_rid) const;
  1762. bool free(RID p_rid);
  1763. bool has_os_feature(const String &p_feature) const;
  1764. void update_dirty_resources();
  1765. void set_debug_generate_wireframes(bool p_generate) {}
  1766. void render_info_begin_capture() {}
  1767. void render_info_end_capture() {}
  1768. int get_captured_render_info(RS::RenderInfo p_info) { return 0; }
  1769. int get_render_info(RS::RenderInfo p_info) { return 0; }
  1770. String get_video_adapter_name() const { return String(); }
  1771. String get_video_adapter_vendor() const { return String(); }
  1772. virtual void capture_timestamps_begin();
  1773. virtual void capture_timestamp(const String &p_name);
  1774. virtual uint32_t get_captured_timestamps_count() const;
  1775. virtual uint64_t get_captured_timestamps_frame() const;
  1776. virtual uint64_t get_captured_timestamp_gpu_time(uint32_t p_index) const;
  1777. virtual uint64_t get_captured_timestamp_cpu_time(uint32_t p_index) const;
  1778. virtual String get_captured_timestamp_name(uint32_t p_index) const;
  1779. RID get_default_rd_storage_buffer() { return default_rd_storage_buffer; }
  1780. static RendererStorageRD *base_singleton;
  1781. EffectsRD *get_effects();
  1782. RendererStorageRD();
  1783. ~RendererStorageRD();
  1784. };
  1785. #endif // RASTERIZER_STORAGE_RD_H