rasterizer_storage_gles3.h 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484
  1. /*************************************************************************/
  2. /* rasterizer_storage_gles3.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 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 RASTERIZERSTORAGEGLES3_H
  31. #define RASTERIZERSTORAGEGLES3_H
  32. #include "core/self_list.h"
  33. #include "servers/visual/rasterizer.h"
  34. #include "servers/visual/shader_language.h"
  35. #include "shader_compiler_gles3.h"
  36. #include "shader_gles3.h"
  37. #include "shaders/blend_shape.glsl.gen.h"
  38. #include "shaders/canvas.glsl.gen.h"
  39. #include "shaders/copy.glsl.gen.h"
  40. #include "shaders/cubemap_filter.glsl.gen.h"
  41. #include "shaders/particles.glsl.gen.h"
  42. // WebGL 2.0 has no MapBufferRange/UnmapBuffer, but offers a non-ES style BufferSubData API instead.
  43. #ifdef __EMSCRIPTEN__
  44. void glGetBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, GLvoid *data);
  45. #endif
  46. class RasterizerCanvasGLES3;
  47. class RasterizerSceneGLES3;
  48. #define _TEXTURE_SRGB_DECODE_EXT 0x8A48
  49. #define _DECODE_EXT 0x8A49
  50. #define _SKIP_DECODE_EXT 0x8A4A
  51. void glTexStorage2DCustom(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type);
  52. class RasterizerStorageGLES3 : public RasterizerStorage {
  53. public:
  54. RasterizerCanvasGLES3 *canvas;
  55. RasterizerSceneGLES3 *scene;
  56. static GLuint system_fbo; //on some devices, such as apple, screen is rendered to yet another fbo.
  57. enum RenderArchitecture {
  58. RENDER_ARCH_MOBILE,
  59. RENDER_ARCH_DESKTOP,
  60. };
  61. struct Config {
  62. bool shrink_textures_x2;
  63. bool use_fast_texture_filter;
  64. bool use_anisotropic_filter;
  65. bool s3tc_supported;
  66. bool latc_supported;
  67. bool rgtc_supported;
  68. bool bptc_supported;
  69. bool etc_supported;
  70. bool etc2_supported;
  71. bool pvrtc_supported;
  72. bool srgb_decode_supported;
  73. bool texture_float_linear_supported;
  74. bool framebuffer_float_supported;
  75. bool framebuffer_half_float_supported;
  76. bool use_rgba_2d_shadows;
  77. float anisotropic_level;
  78. int max_texture_image_units;
  79. int max_texture_size;
  80. bool generate_wireframes;
  81. bool use_texture_array_environment;
  82. Set<String> extensions;
  83. bool keep_original_textures;
  84. bool use_depth_prepass;
  85. bool force_vertex_shading;
  86. } config;
  87. mutable struct Shaders {
  88. CopyShaderGLES3 copy;
  89. ShaderCompilerGLES3 compiler;
  90. CubemapFilterShaderGLES3 cubemap_filter;
  91. BlendShapeShaderGLES3 blend_shapes;
  92. ParticlesShaderGLES3 particles;
  93. ShaderCompilerGLES3::IdentifierActions actions_canvas;
  94. ShaderCompilerGLES3::IdentifierActions actions_scene;
  95. ShaderCompilerGLES3::IdentifierActions actions_particles;
  96. } shaders;
  97. struct Resources {
  98. GLuint white_tex;
  99. GLuint black_tex;
  100. GLuint normal_tex;
  101. GLuint aniso_tex;
  102. GLuint white_tex_3d;
  103. GLuint white_tex_array;
  104. GLuint quadie;
  105. GLuint quadie_array;
  106. GLuint transform_feedback_buffers[2];
  107. GLuint transform_feedback_array;
  108. } resources;
  109. struct Info {
  110. uint64_t texture_mem;
  111. uint64_t vertex_mem;
  112. struct Render {
  113. uint32_t object_count;
  114. uint32_t draw_call_count;
  115. uint32_t material_switch_count;
  116. uint32_t surface_switch_count;
  117. uint32_t shader_rebind_count;
  118. uint32_t vertices_count;
  119. uint32_t _2d_item_count;
  120. uint32_t _2d_draw_call_count;
  121. void reset() {
  122. object_count = 0;
  123. draw_call_count = 0;
  124. material_switch_count = 0;
  125. surface_switch_count = 0;
  126. shader_rebind_count = 0;
  127. vertices_count = 0;
  128. _2d_item_count = 0;
  129. _2d_draw_call_count = 0;
  130. }
  131. } render, render_final, snap;
  132. Info() {
  133. texture_mem = 0;
  134. vertex_mem = 0;
  135. render.reset();
  136. render_final.reset();
  137. }
  138. } info;
  139. /////////////////////////////////////////////////////////////////////////////////////////
  140. //////////////////////////////////DATA///////////////////////////////////////////////////
  141. /////////////////////////////////////////////////////////////////////////////////////////
  142. struct Instantiable : public RID_Data {
  143. SelfList<RasterizerScene::InstanceBase>::List instance_list;
  144. _FORCE_INLINE_ void instance_change_notify(bool p_aabb, bool p_materials) {
  145. SelfList<RasterizerScene::InstanceBase> *instances = instance_list.first();
  146. while (instances) {
  147. instances->self()->base_changed(p_aabb, p_materials);
  148. instances = instances->next();
  149. }
  150. }
  151. _FORCE_INLINE_ void instance_remove_deps() {
  152. SelfList<RasterizerScene::InstanceBase> *instances = instance_list.first();
  153. while (instances) {
  154. SelfList<RasterizerScene::InstanceBase> *next = instances->next();
  155. instances->self()->base_removed();
  156. instances = next;
  157. }
  158. }
  159. Instantiable() {}
  160. virtual ~Instantiable() {
  161. }
  162. };
  163. struct GeometryOwner : public Instantiable {
  164. virtual ~GeometryOwner() {}
  165. };
  166. struct Geometry : Instantiable {
  167. enum Type {
  168. GEOMETRY_INVALID,
  169. GEOMETRY_SURFACE,
  170. GEOMETRY_IMMEDIATE,
  171. GEOMETRY_MULTISURFACE,
  172. };
  173. Type type;
  174. RID material;
  175. uint64_t last_pass;
  176. uint32_t index;
  177. virtual void material_changed_notify() {}
  178. Geometry() {
  179. last_pass = 0;
  180. index = 0;
  181. }
  182. };
  183. /////////////////////////////////////////////////////////////////////////////////////////
  184. //////////////////////////////////API////////////////////////////////////////////////////
  185. /////////////////////////////////////////////////////////////////////////////////////////
  186. /* TEXTURE API */
  187. struct RenderTarget;
  188. struct Texture : public RID_Data {
  189. Texture *proxy;
  190. Set<Texture *> proxy_owners;
  191. String path;
  192. uint32_t flags;
  193. int width, height, depth;
  194. int alloc_width, alloc_height, alloc_depth;
  195. Image::Format format;
  196. VS::TextureType type;
  197. GLenum target;
  198. GLenum gl_format_cache;
  199. GLenum gl_internal_format_cache;
  200. GLenum gl_type_cache;
  201. int data_size; //original data size, useful for retrieving back
  202. bool compressed;
  203. bool srgb;
  204. int total_data_size;
  205. bool ignore_mipmaps;
  206. int mipmaps;
  207. bool is_npot_repeat_mipmap;
  208. bool active;
  209. GLuint tex_id;
  210. bool using_srgb;
  211. bool redraw_if_visible;
  212. uint16_t stored_cube_sides;
  213. RenderTarget *render_target;
  214. Vector<Ref<Image> > images;
  215. VisualServer::TextureDetectCallback detect_3d;
  216. void *detect_3d_ud;
  217. VisualServer::TextureDetectCallback detect_srgb;
  218. void *detect_srgb_ud;
  219. VisualServer::TextureDetectCallback detect_normal;
  220. void *detect_normal_ud;
  221. Texture() :
  222. proxy(NULL),
  223. flags(0),
  224. width(0),
  225. height(0),
  226. format(Image::FORMAT_L8),
  227. type(VS::TEXTURE_TYPE_2D),
  228. target(GL_TEXTURE_2D),
  229. data_size(0),
  230. compressed(false),
  231. srgb(false),
  232. total_data_size(0),
  233. ignore_mipmaps(false),
  234. mipmaps(0),
  235. active(false),
  236. tex_id(0),
  237. using_srgb(false),
  238. redraw_if_visible(false),
  239. stored_cube_sides(0),
  240. render_target(NULL),
  241. detect_3d(NULL),
  242. detect_3d_ud(NULL),
  243. detect_srgb(NULL),
  244. detect_srgb_ud(NULL),
  245. detect_normal(NULL),
  246. detect_normal_ud(NULL) {
  247. }
  248. _ALWAYS_INLINE_ Texture *get_ptr() {
  249. if (proxy) {
  250. return proxy; //->get_ptr(); only one level of indirection, else not inlining possible.
  251. } else {
  252. return this;
  253. }
  254. }
  255. ~Texture() {
  256. if (tex_id != 0) {
  257. glDeleteTextures(1, &tex_id);
  258. }
  259. for (Set<Texture *>::Element *E = proxy_owners.front(); E; E = E->next()) {
  260. E->get()->proxy = NULL;
  261. }
  262. if (proxy) {
  263. proxy->proxy_owners.erase(this);
  264. }
  265. }
  266. };
  267. mutable RID_Owner<Texture> texture_owner;
  268. Ref<Image> _get_gl_image_and_format(const Ref<Image> &p_image, Image::Format p_format, uint32_t p_flags, Image::Format &r_real_format, GLenum &r_gl_format, GLenum &r_gl_internal_format, GLenum &r_gl_type, bool &r_compressed, bool &r_srgb, bool p_force_decompress) const;
  269. virtual RID texture_create();
  270. virtual void texture_allocate(RID p_texture, int p_width, int p_height, int p_depth_3d, Image::Format p_format, VS::TextureType p_type, uint32_t p_flags = VS::TEXTURE_FLAGS_DEFAULT);
  271. virtual void texture_set_data(RID p_texture, const Ref<Image> &p_image, int p_layer = 0);
  272. virtual void texture_set_data_partial(RID p_texture, const Ref<Image> &p_image, int src_x, int src_y, int src_w, int src_h, int dst_x, int dst_y, int p_dst_mip, int p_layer = 0);
  273. virtual Ref<Image> texture_get_data(RID p_texture, int p_layer = 0) const;
  274. virtual void texture_set_flags(RID p_texture, uint32_t p_flags);
  275. virtual uint32_t texture_get_flags(RID p_texture) const;
  276. virtual Image::Format texture_get_format(RID p_texture) const;
  277. virtual VS::TextureType texture_get_type(RID p_texture) const;
  278. virtual uint32_t texture_get_texid(RID p_texture) const;
  279. virtual uint32_t texture_get_width(RID p_texture) const;
  280. virtual uint32_t texture_get_height(RID p_texture) const;
  281. virtual uint32_t texture_get_depth(RID p_texture) const;
  282. virtual void texture_set_size_override(RID p_texture, int p_width, int p_height, int p_depth);
  283. virtual void texture_bind(RID p_texture, uint32_t p_texture_no);
  284. virtual void texture_set_path(RID p_texture, const String &p_path);
  285. virtual String texture_get_path(RID p_texture) const;
  286. virtual void texture_set_shrink_all_x2_on_set_data(bool p_enable);
  287. virtual void texture_debug_usage(List<VS::TextureInfo> *r_info);
  288. virtual RID texture_create_radiance_cubemap(RID p_source, int p_resolution = -1) const;
  289. virtual void textures_keep_original(bool p_enable);
  290. virtual void texture_set_detect_3d_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata);
  291. virtual void texture_set_detect_srgb_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata);
  292. virtual void texture_set_detect_normal_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata);
  293. virtual void texture_set_proxy(RID p_texture, RID p_proxy);
  294. virtual Size2 texture_size_with_proxy(RID p_texture) const;
  295. virtual void texture_set_force_redraw_if_visible(RID p_texture, bool p_enable);
  296. /* SKY API */
  297. struct Sky : public RID_Data {
  298. RID panorama;
  299. GLuint radiance;
  300. GLuint irradiance;
  301. int radiance_size;
  302. };
  303. mutable RID_Owner<Sky> sky_owner;
  304. virtual RID sky_create();
  305. virtual void sky_set_texture(RID p_sky, RID p_panorama, int p_radiance_size);
  306. /* SHADER API */
  307. struct Material;
  308. struct Shader : public RID_Data {
  309. RID self;
  310. VS::ShaderMode mode;
  311. ShaderGLES3 *shader;
  312. String code;
  313. SelfList<Material>::List materials;
  314. Map<StringName, ShaderLanguage::ShaderNode::Uniform> uniforms;
  315. Vector<uint32_t> ubo_offsets;
  316. uint32_t ubo_size;
  317. uint32_t texture_count;
  318. uint32_t custom_code_id;
  319. uint32_t version;
  320. SelfList<Shader> dirty_list;
  321. Map<StringName, RID> default_textures;
  322. Vector<ShaderLanguage::DataType> texture_types;
  323. Vector<ShaderLanguage::ShaderNode::Uniform::Hint> texture_hints;
  324. bool valid;
  325. String path;
  326. struct CanvasItem {
  327. enum BlendMode {
  328. BLEND_MODE_MIX,
  329. BLEND_MODE_ADD,
  330. BLEND_MODE_SUB,
  331. BLEND_MODE_MUL,
  332. BLEND_MODE_PMALPHA,
  333. BLEND_MODE_DISABLED,
  334. };
  335. int blend_mode;
  336. enum LightMode {
  337. LIGHT_MODE_NORMAL,
  338. LIGHT_MODE_UNSHADED,
  339. LIGHT_MODE_LIGHT_ONLY
  340. };
  341. int light_mode;
  342. bool uses_screen_texture;
  343. bool uses_screen_uv;
  344. bool uses_time;
  345. } canvas_item;
  346. struct Spatial {
  347. enum BlendMode {
  348. BLEND_MODE_MIX,
  349. BLEND_MODE_ADD,
  350. BLEND_MODE_SUB,
  351. BLEND_MODE_MUL,
  352. };
  353. int blend_mode;
  354. enum DepthDrawMode {
  355. DEPTH_DRAW_OPAQUE,
  356. DEPTH_DRAW_ALWAYS,
  357. DEPTH_DRAW_NEVER,
  358. DEPTH_DRAW_ALPHA_PREPASS,
  359. };
  360. int depth_draw_mode;
  361. enum CullMode {
  362. CULL_MODE_FRONT,
  363. CULL_MODE_BACK,
  364. CULL_MODE_DISABLED,
  365. };
  366. int cull_mode;
  367. bool uses_alpha;
  368. bool uses_alpha_scissor;
  369. bool unshaded;
  370. bool no_depth_test;
  371. bool uses_vertex;
  372. bool uses_discard;
  373. bool uses_sss;
  374. bool uses_screen_texture;
  375. bool uses_depth_texture;
  376. bool uses_time;
  377. bool writes_modelview_or_projection;
  378. bool uses_vertex_lighting;
  379. bool uses_world_coordinates;
  380. } spatial;
  381. struct Particles {
  382. } particles;
  383. bool uses_vertex_time;
  384. bool uses_fragment_time;
  385. Shader() :
  386. dirty_list(this) {
  387. shader = NULL;
  388. ubo_size = 0;
  389. valid = false;
  390. custom_code_id = 0;
  391. version = 1;
  392. }
  393. };
  394. mutable SelfList<Shader>::List _shader_dirty_list;
  395. void _shader_make_dirty(Shader *p_shader);
  396. mutable RID_Owner<Shader> shader_owner;
  397. virtual RID shader_create();
  398. virtual void shader_set_code(RID p_shader, const String &p_code);
  399. virtual String shader_get_code(RID p_shader) const;
  400. virtual void shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const;
  401. virtual void shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture);
  402. virtual RID shader_get_default_texture_param(RID p_shader, const StringName &p_name) const;
  403. virtual void shader_add_custom_define(RID p_shader, const String &p_define);
  404. virtual void shader_get_custom_defines(RID p_shader, Vector<String> *p_defines) const;
  405. virtual void shader_remove_custom_define(RID p_shader, const String &p_define);
  406. void _update_shader(Shader *p_shader) const;
  407. void update_dirty_shaders();
  408. /* COMMON MATERIAL API */
  409. struct Material : public RID_Data {
  410. Shader *shader;
  411. GLuint ubo_id;
  412. uint32_t ubo_size;
  413. Map<StringName, Variant> params;
  414. SelfList<Material> list;
  415. SelfList<Material> dirty_list;
  416. Vector<bool> texture_is_3d;
  417. Vector<RID> textures;
  418. float line_width;
  419. int render_priority;
  420. RID next_pass;
  421. uint32_t index;
  422. uint64_t last_pass;
  423. Map<Geometry *, int> geometry_owners;
  424. Map<RasterizerScene::InstanceBase *, int> instance_owners;
  425. bool can_cast_shadow_cache;
  426. bool is_animated_cache;
  427. Material() :
  428. shader(NULL),
  429. ubo_id(0),
  430. ubo_size(0),
  431. list(this),
  432. dirty_list(this),
  433. line_width(1.0),
  434. render_priority(0),
  435. last_pass(0),
  436. can_cast_shadow_cache(false),
  437. is_animated_cache(false) {
  438. }
  439. };
  440. mutable SelfList<Material>::List _material_dirty_list;
  441. void _material_make_dirty(Material *p_material) const;
  442. void _material_add_geometry(RID p_material, Geometry *p_geometry);
  443. void _material_remove_geometry(RID p_material, Geometry *p_geometry);
  444. mutable RID_Owner<Material> material_owner;
  445. virtual RID material_create();
  446. virtual void material_set_shader(RID p_material, RID p_shader);
  447. virtual RID material_get_shader(RID p_material) const;
  448. virtual void material_set_param(RID p_material, const StringName &p_param, const Variant &p_value);
  449. virtual Variant material_get_param(RID p_material, const StringName &p_param) const;
  450. virtual Variant material_get_param_default(RID p_material, const StringName &p_param) const;
  451. virtual void material_set_line_width(RID p_material, float p_width);
  452. virtual void material_set_next_pass(RID p_material, RID p_next_material);
  453. virtual bool material_is_animated(RID p_material);
  454. virtual bool material_casts_shadows(RID p_material);
  455. virtual void material_add_instance_owner(RID p_material, RasterizerScene::InstanceBase *p_instance);
  456. virtual void material_remove_instance_owner(RID p_material, RasterizerScene::InstanceBase *p_instance);
  457. virtual void material_set_render_priority(RID p_material, int priority);
  458. void _update_material(Material *material);
  459. void update_dirty_materials();
  460. /* MESH API */
  461. struct Mesh;
  462. struct Surface : public Geometry {
  463. struct Attrib {
  464. bool enabled;
  465. bool integer;
  466. GLuint index;
  467. GLint size;
  468. GLenum type;
  469. GLboolean normalized;
  470. GLsizei stride;
  471. uint32_t offset;
  472. };
  473. Attrib attribs[VS::ARRAY_MAX];
  474. Mesh *mesh;
  475. uint32_t format;
  476. GLuint array_id;
  477. GLuint instancing_array_id;
  478. GLuint vertex_id;
  479. GLuint index_id;
  480. GLuint index_wireframe_id;
  481. GLuint array_wireframe_id;
  482. GLuint instancing_array_wireframe_id;
  483. int index_wireframe_len;
  484. Vector<AABB> skeleton_bone_aabb;
  485. Vector<bool> skeleton_bone_used;
  486. //bool packed;
  487. struct BlendShape {
  488. GLuint vertex_id;
  489. GLuint array_id;
  490. };
  491. Vector<BlendShape> blend_shapes;
  492. AABB aabb;
  493. int array_len;
  494. int index_array_len;
  495. int max_bone;
  496. int array_byte_size;
  497. int index_array_byte_size;
  498. VS::PrimitiveType primitive;
  499. bool active;
  500. virtual void material_changed_notify() {
  501. mesh->instance_change_notify(false, true);
  502. mesh->update_multimeshes();
  503. }
  504. int total_data_size;
  505. Surface() :
  506. mesh(NULL),
  507. format(0),
  508. array_id(0),
  509. vertex_id(0),
  510. index_id(0),
  511. index_wireframe_id(0),
  512. array_wireframe_id(0),
  513. instancing_array_wireframe_id(0),
  514. index_wireframe_len(0),
  515. array_len(0),
  516. index_array_len(0),
  517. array_byte_size(0),
  518. index_array_byte_size(0),
  519. primitive(VS::PRIMITIVE_POINTS),
  520. active(false),
  521. total_data_size(0) {
  522. type = GEOMETRY_SURFACE;
  523. }
  524. ~Surface() {
  525. }
  526. };
  527. struct MultiMesh;
  528. struct Mesh : public GeometryOwner {
  529. bool active;
  530. Vector<Surface *> surfaces;
  531. int blend_shape_count;
  532. VS::BlendShapeMode blend_shape_mode;
  533. AABB custom_aabb;
  534. mutable uint64_t last_pass;
  535. SelfList<MultiMesh>::List multimeshes;
  536. _FORCE_INLINE_ void update_multimeshes() {
  537. SelfList<MultiMesh> *mm = multimeshes.first();
  538. while (mm) {
  539. mm->self()->instance_change_notify(false, true);
  540. mm = mm->next();
  541. }
  542. }
  543. Mesh() :
  544. active(false),
  545. blend_shape_count(0),
  546. blend_shape_mode(VS::BLEND_SHAPE_MODE_NORMALIZED),
  547. last_pass(0) {
  548. }
  549. };
  550. mutable RID_Owner<Mesh> mesh_owner;
  551. virtual RID mesh_create();
  552. virtual void mesh_add_surface(RID p_mesh, uint32_t p_format, VS::PrimitiveType p_primitive, const PoolVector<uint8_t> &p_array, int p_vertex_count, const PoolVector<uint8_t> &p_index_array, int p_index_count, const AABB &p_aabb, const Vector<PoolVector<uint8_t> > &p_blend_shapes = Vector<PoolVector<uint8_t> >(), const Vector<AABB> &p_bone_aabbs = Vector<AABB>());
  553. virtual void mesh_set_blend_shape_count(RID p_mesh, int p_amount);
  554. virtual int mesh_get_blend_shape_count(RID p_mesh) const;
  555. virtual void mesh_set_blend_shape_mode(RID p_mesh, VS::BlendShapeMode p_mode);
  556. virtual VS::BlendShapeMode mesh_get_blend_shape_mode(RID p_mesh) const;
  557. virtual void mesh_surface_update_region(RID p_mesh, int p_surface, int p_offset, const PoolVector<uint8_t> &p_data);
  558. virtual void mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material);
  559. virtual RID mesh_surface_get_material(RID p_mesh, int p_surface) const;
  560. virtual int mesh_surface_get_array_len(RID p_mesh, int p_surface) const;
  561. virtual int mesh_surface_get_array_index_len(RID p_mesh, int p_surface) const;
  562. virtual PoolVector<uint8_t> mesh_surface_get_array(RID p_mesh, int p_surface) const;
  563. virtual PoolVector<uint8_t> mesh_surface_get_index_array(RID p_mesh, int p_surface) const;
  564. virtual uint32_t mesh_surface_get_format(RID p_mesh, int p_surface) const;
  565. virtual VS::PrimitiveType mesh_surface_get_primitive_type(RID p_mesh, int p_surface) const;
  566. virtual AABB mesh_surface_get_aabb(RID p_mesh, int p_surface) const;
  567. virtual Vector<PoolVector<uint8_t> > mesh_surface_get_blend_shapes(RID p_mesh, int p_surface) const;
  568. virtual Vector<AABB> mesh_surface_get_skeleton_aabb(RID p_mesh, int p_surface) const;
  569. virtual void mesh_remove_surface(RID p_mesh, int p_surface);
  570. virtual int mesh_get_surface_count(RID p_mesh) const;
  571. virtual void mesh_set_custom_aabb(RID p_mesh, const AABB &p_aabb);
  572. virtual AABB mesh_get_custom_aabb(RID p_mesh) const;
  573. virtual AABB mesh_get_aabb(RID p_mesh, RID p_skeleton) const;
  574. virtual void mesh_clear(RID p_mesh);
  575. void mesh_render_blend_shapes(Surface *s, const float *p_weights);
  576. /* MULTIMESH API */
  577. struct MultiMesh : public GeometryOwner {
  578. RID mesh;
  579. int size;
  580. VS::MultimeshTransformFormat transform_format;
  581. VS::MultimeshColorFormat color_format;
  582. VS::MultimeshCustomDataFormat custom_data_format;
  583. Vector<float> data;
  584. AABB aabb;
  585. SelfList<MultiMesh> update_list;
  586. SelfList<MultiMesh> mesh_list;
  587. GLuint buffer;
  588. int visible_instances;
  589. int xform_floats;
  590. int color_floats;
  591. int custom_data_floats;
  592. bool dirty_aabb;
  593. bool dirty_data;
  594. MultiMesh() :
  595. size(0),
  596. transform_format(VS::MULTIMESH_TRANSFORM_2D),
  597. color_format(VS::MULTIMESH_COLOR_NONE),
  598. custom_data_format(VS::MULTIMESH_CUSTOM_DATA_NONE),
  599. update_list(this),
  600. mesh_list(this),
  601. buffer(0),
  602. visible_instances(-1),
  603. xform_floats(0),
  604. color_floats(0),
  605. custom_data_floats(0),
  606. dirty_aabb(true),
  607. dirty_data(true) {
  608. }
  609. };
  610. mutable RID_Owner<MultiMesh> multimesh_owner;
  611. SelfList<MultiMesh>::List multimesh_update_list;
  612. void update_dirty_multimeshes();
  613. virtual RID multimesh_create();
  614. virtual void multimesh_allocate(RID p_multimesh, int p_instances, VS::MultimeshTransformFormat p_transform_format, VS::MultimeshColorFormat p_color_format, VS::MultimeshCustomDataFormat p_data_format = VS::MULTIMESH_CUSTOM_DATA_NONE);
  615. virtual int multimesh_get_instance_count(RID p_multimesh) const;
  616. virtual void multimesh_set_mesh(RID p_multimesh, RID p_mesh);
  617. virtual void multimesh_instance_set_transform(RID p_multimesh, int p_index, const Transform &p_transform);
  618. virtual void multimesh_instance_set_transform_2d(RID p_multimesh, int p_index, const Transform2D &p_transform);
  619. virtual void multimesh_instance_set_color(RID p_multimesh, int p_index, const Color &p_color);
  620. virtual void multimesh_instance_set_custom_data(RID p_multimesh, int p_index, const Color &p_custom_data);
  621. virtual RID multimesh_get_mesh(RID p_multimesh) const;
  622. virtual Transform multimesh_instance_get_transform(RID p_multimesh, int p_index) const;
  623. virtual Transform2D multimesh_instance_get_transform_2d(RID p_multimesh, int p_index) const;
  624. virtual Color multimesh_instance_get_color(RID p_multimesh, int p_index) const;
  625. virtual Color multimesh_instance_get_custom_data(RID p_multimesh, int p_index) const;
  626. virtual void multimesh_set_as_bulk_array(RID p_multimesh, const PoolVector<float> &p_array);
  627. virtual void multimesh_set_visible_instances(RID p_multimesh, int p_visible);
  628. virtual int multimesh_get_visible_instances(RID p_multimesh) const;
  629. virtual AABB multimesh_get_aabb(RID p_multimesh) const;
  630. /* IMMEDIATE API */
  631. struct Immediate : public Geometry {
  632. struct Chunk {
  633. RID texture;
  634. VS::PrimitiveType primitive;
  635. Vector<Vector3> vertices;
  636. Vector<Vector3> normals;
  637. Vector<Plane> tangents;
  638. Vector<Color> colors;
  639. Vector<Vector2> uvs;
  640. Vector<Vector2> uvs2;
  641. };
  642. List<Chunk> chunks;
  643. bool building;
  644. int mask;
  645. AABB aabb;
  646. Immediate() {
  647. type = GEOMETRY_IMMEDIATE;
  648. building = false;
  649. }
  650. };
  651. Vector3 chunk_vertex;
  652. Vector3 chunk_normal;
  653. Plane chunk_tangent;
  654. Color chunk_color;
  655. Vector2 chunk_uv;
  656. Vector2 chunk_uv2;
  657. mutable RID_Owner<Immediate> immediate_owner;
  658. virtual RID immediate_create();
  659. virtual void immediate_begin(RID p_immediate, VS::PrimitiveType p_primitive, RID p_texture = RID());
  660. virtual void immediate_vertex(RID p_immediate, const Vector3 &p_vertex);
  661. virtual void immediate_normal(RID p_immediate, const Vector3 &p_normal);
  662. virtual void immediate_tangent(RID p_immediate, const Plane &p_tangent);
  663. virtual void immediate_color(RID p_immediate, const Color &p_color);
  664. virtual void immediate_uv(RID p_immediate, const Vector2 &tex_uv);
  665. virtual void immediate_uv2(RID p_immediate, const Vector2 &tex_uv);
  666. virtual void immediate_end(RID p_immediate);
  667. virtual void immediate_clear(RID p_immediate);
  668. virtual void immediate_set_material(RID p_immediate, RID p_material);
  669. virtual RID immediate_get_material(RID p_immediate) const;
  670. virtual AABB immediate_get_aabb(RID p_immediate) const;
  671. /* SKELETON API */
  672. struct Skeleton : RID_Data {
  673. bool use_2d;
  674. int size;
  675. Vector<float> skel_texture;
  676. GLuint texture;
  677. SelfList<Skeleton> update_list;
  678. Set<RasterizerScene::InstanceBase *> instances; //instances using skeleton
  679. Transform2D base_transform_2d;
  680. Skeleton() :
  681. use_2d(false),
  682. size(0),
  683. texture(0),
  684. update_list(this) {
  685. }
  686. };
  687. mutable RID_Owner<Skeleton> skeleton_owner;
  688. SelfList<Skeleton>::List skeleton_update_list;
  689. void update_dirty_skeletons();
  690. virtual RID skeleton_create();
  691. virtual void skeleton_allocate(RID p_skeleton, int p_bones, bool p_2d_skeleton = false);
  692. virtual int skeleton_get_bone_count(RID p_skeleton) const;
  693. virtual void skeleton_bone_set_transform(RID p_skeleton, int p_bone, const Transform &p_transform);
  694. virtual Transform skeleton_bone_get_transform(RID p_skeleton, int p_bone) const;
  695. virtual void skeleton_bone_set_transform_2d(RID p_skeleton, int p_bone, const Transform2D &p_transform);
  696. virtual Transform2D skeleton_bone_get_transform_2d(RID p_skeleton, int p_bone) const;
  697. virtual void skeleton_set_base_transform_2d(RID p_skeleton, const Transform2D &p_base_transform);
  698. /* Light API */
  699. struct Light : Instantiable {
  700. VS::LightType type;
  701. float param[VS::LIGHT_PARAM_MAX];
  702. Color color;
  703. Color shadow_color;
  704. RID projector;
  705. bool shadow;
  706. bool negative;
  707. bool reverse_cull;
  708. bool use_gi;
  709. uint32_t cull_mask;
  710. VS::LightOmniShadowMode omni_shadow_mode;
  711. VS::LightOmniShadowDetail omni_shadow_detail;
  712. VS::LightDirectionalShadowMode directional_shadow_mode;
  713. VS::LightDirectionalShadowDepthRangeMode directional_range_mode;
  714. bool directional_blend_splits;
  715. uint64_t version;
  716. };
  717. mutable RID_Owner<Light> light_owner;
  718. virtual RID light_create(VS::LightType p_type);
  719. virtual void light_set_color(RID p_light, const Color &p_color);
  720. virtual void light_set_param(RID p_light, VS::LightParam p_param, float p_value);
  721. virtual void light_set_shadow(RID p_light, bool p_enabled);
  722. virtual void light_set_shadow_color(RID p_light, const Color &p_color);
  723. virtual void light_set_projector(RID p_light, RID p_texture);
  724. virtual void light_set_negative(RID p_light, bool p_enable);
  725. virtual void light_set_cull_mask(RID p_light, uint32_t p_mask);
  726. virtual void light_set_reverse_cull_face_mode(RID p_light, bool p_enabled);
  727. virtual void light_set_use_gi(RID p_light, bool p_enabled);
  728. virtual void light_omni_set_shadow_mode(RID p_light, VS::LightOmniShadowMode p_mode);
  729. virtual void light_omni_set_shadow_detail(RID p_light, VS::LightOmniShadowDetail p_detail);
  730. virtual void light_directional_set_shadow_mode(RID p_light, VS::LightDirectionalShadowMode p_mode);
  731. virtual void light_directional_set_blend_splits(RID p_light, bool p_enable);
  732. virtual bool light_directional_get_blend_splits(RID p_light) const;
  733. virtual VS::LightDirectionalShadowMode light_directional_get_shadow_mode(RID p_light);
  734. virtual VS::LightOmniShadowMode light_omni_get_shadow_mode(RID p_light);
  735. virtual void light_directional_set_shadow_depth_range_mode(RID p_light, VS::LightDirectionalShadowDepthRangeMode p_range_mode);
  736. virtual VS::LightDirectionalShadowDepthRangeMode light_directional_get_shadow_depth_range_mode(RID p_light) const;
  737. virtual bool light_has_shadow(RID p_light) const;
  738. virtual VS::LightType light_get_type(RID p_light) const;
  739. virtual float light_get_param(RID p_light, VS::LightParam p_param);
  740. virtual Color light_get_color(RID p_light);
  741. virtual bool light_get_use_gi(RID p_light);
  742. virtual AABB light_get_aabb(RID p_light) const;
  743. virtual uint64_t light_get_version(RID p_light) const;
  744. /* PROBE API */
  745. struct ReflectionProbe : Instantiable {
  746. VS::ReflectionProbeUpdateMode update_mode;
  747. float intensity;
  748. Color interior_ambient;
  749. float interior_ambient_energy;
  750. float interior_ambient_probe_contrib;
  751. float max_distance;
  752. Vector3 extents;
  753. Vector3 origin_offset;
  754. bool interior;
  755. bool box_projection;
  756. bool enable_shadows;
  757. uint32_t cull_mask;
  758. };
  759. mutable RID_Owner<ReflectionProbe> reflection_probe_owner;
  760. virtual RID reflection_probe_create();
  761. virtual void reflection_probe_set_update_mode(RID p_probe, VS::ReflectionProbeUpdateMode p_mode);
  762. virtual void reflection_probe_set_intensity(RID p_probe, float p_intensity);
  763. virtual void reflection_probe_set_interior_ambient(RID p_probe, const Color &p_ambient);
  764. virtual void reflection_probe_set_interior_ambient_energy(RID p_probe, float p_energy);
  765. virtual void reflection_probe_set_interior_ambient_probe_contribution(RID p_probe, float p_contrib);
  766. virtual void reflection_probe_set_max_distance(RID p_probe, float p_distance);
  767. virtual void reflection_probe_set_extents(RID p_probe, const Vector3 &p_extents);
  768. virtual void reflection_probe_set_origin_offset(RID p_probe, const Vector3 &p_offset);
  769. virtual void reflection_probe_set_as_interior(RID p_probe, bool p_enable);
  770. virtual void reflection_probe_set_enable_box_projection(RID p_probe, bool p_enable);
  771. virtual void reflection_probe_set_enable_shadows(RID p_probe, bool p_enable);
  772. virtual void reflection_probe_set_cull_mask(RID p_probe, uint32_t p_layers);
  773. virtual void reflection_probe_set_resolution(RID p_probe, int p_resolution);
  774. virtual AABB reflection_probe_get_aabb(RID p_probe) const;
  775. virtual VS::ReflectionProbeUpdateMode reflection_probe_get_update_mode(RID p_probe) const;
  776. virtual uint32_t reflection_probe_get_cull_mask(RID p_probe) const;
  777. virtual Vector3 reflection_probe_get_extents(RID p_probe) const;
  778. virtual Vector3 reflection_probe_get_origin_offset(RID p_probe) const;
  779. virtual float reflection_probe_get_origin_max_distance(RID p_probe) const;
  780. virtual bool reflection_probe_renders_shadows(RID p_probe) const;
  781. /* GI PROBE API */
  782. struct GIProbe : public Instantiable {
  783. AABB bounds;
  784. Transform to_cell;
  785. float cell_size;
  786. int dynamic_range;
  787. float energy;
  788. float bias;
  789. float normal_bias;
  790. float propagation;
  791. bool interior;
  792. bool compress;
  793. uint32_t version;
  794. PoolVector<int> dynamic_data;
  795. };
  796. mutable RID_Owner<GIProbe> gi_probe_owner;
  797. virtual RID gi_probe_create();
  798. virtual void gi_probe_set_bounds(RID p_probe, const AABB &p_bounds);
  799. virtual AABB gi_probe_get_bounds(RID p_probe) const;
  800. virtual void gi_probe_set_cell_size(RID p_probe, float p_size);
  801. virtual float gi_probe_get_cell_size(RID p_probe) const;
  802. virtual void gi_probe_set_to_cell_xform(RID p_probe, const Transform &p_xform);
  803. virtual Transform gi_probe_get_to_cell_xform(RID p_probe) const;
  804. virtual void gi_probe_set_dynamic_data(RID p_probe, const PoolVector<int> &p_data);
  805. virtual PoolVector<int> gi_probe_get_dynamic_data(RID p_probe) const;
  806. virtual void gi_probe_set_dynamic_range(RID p_probe, int p_range);
  807. virtual int gi_probe_get_dynamic_range(RID p_probe) const;
  808. virtual void gi_probe_set_energy(RID p_probe, float p_range);
  809. virtual float gi_probe_get_energy(RID p_probe) const;
  810. virtual void gi_probe_set_bias(RID p_probe, float p_range);
  811. virtual float gi_probe_get_bias(RID p_probe) const;
  812. virtual void gi_probe_set_normal_bias(RID p_probe, float p_range);
  813. virtual float gi_probe_get_normal_bias(RID p_probe) const;
  814. virtual void gi_probe_set_propagation(RID p_probe, float p_range);
  815. virtual float gi_probe_get_propagation(RID p_probe) const;
  816. virtual void gi_probe_set_interior(RID p_probe, bool p_enable);
  817. virtual bool gi_probe_is_interior(RID p_probe) const;
  818. virtual void gi_probe_set_compress(RID p_probe, bool p_enable);
  819. virtual bool gi_probe_is_compressed(RID p_probe) const;
  820. virtual uint32_t gi_probe_get_version(RID p_probe);
  821. struct GIProbeData : public RID_Data {
  822. int width;
  823. int height;
  824. int depth;
  825. int levels;
  826. GLuint tex_id;
  827. GIProbeCompression compression;
  828. GIProbeData() {
  829. }
  830. };
  831. mutable RID_Owner<GIProbeData> gi_probe_data_owner;
  832. virtual GIProbeCompression gi_probe_get_dynamic_data_get_preferred_compression() const;
  833. virtual RID gi_probe_dynamic_data_create(int p_width, int p_height, int p_depth, GIProbeCompression p_compression);
  834. virtual void gi_probe_dynamic_data_update(RID p_gi_probe_data, int p_depth_slice, int p_slice_count, int p_mipmap, const void *p_data);
  835. /* LIGHTMAP CAPTURE */
  836. virtual RID lightmap_capture_create();
  837. virtual void lightmap_capture_set_bounds(RID p_capture, const AABB &p_bounds);
  838. virtual AABB lightmap_capture_get_bounds(RID p_capture) const;
  839. virtual void lightmap_capture_set_octree(RID p_capture, const PoolVector<uint8_t> &p_octree);
  840. virtual PoolVector<uint8_t> lightmap_capture_get_octree(RID p_capture) const;
  841. virtual void lightmap_capture_set_octree_cell_transform(RID p_capture, const Transform &p_xform);
  842. virtual Transform lightmap_capture_get_octree_cell_transform(RID p_capture) const;
  843. virtual void lightmap_capture_set_octree_cell_subdiv(RID p_capture, int p_subdiv);
  844. virtual int lightmap_capture_get_octree_cell_subdiv(RID p_capture) const;
  845. virtual void lightmap_capture_set_energy(RID p_capture, float p_energy);
  846. virtual float lightmap_capture_get_energy(RID p_capture) const;
  847. virtual const PoolVector<LightmapCaptureOctree> *lightmap_capture_get_octree_ptr(RID p_capture) const;
  848. struct LightmapCapture : public Instantiable {
  849. PoolVector<LightmapCaptureOctree> octree;
  850. AABB bounds;
  851. Transform cell_xform;
  852. int cell_subdiv;
  853. float energy;
  854. LightmapCapture() {
  855. energy = 1.0;
  856. cell_subdiv = 1;
  857. }
  858. };
  859. mutable RID_Owner<LightmapCapture> lightmap_capture_data_owner;
  860. /* PARTICLES */
  861. struct Particles : public GeometryOwner {
  862. bool inactive;
  863. float inactive_time;
  864. bool emitting;
  865. bool one_shot;
  866. int amount;
  867. float lifetime;
  868. float pre_process_time;
  869. float explosiveness;
  870. float randomness;
  871. bool restart_request;
  872. AABB custom_aabb;
  873. bool use_local_coords;
  874. RID process_material;
  875. VS::ParticlesDrawOrder draw_order;
  876. Vector<RID> draw_passes;
  877. GLuint particle_buffers[2];
  878. GLuint particle_vaos[2];
  879. GLuint particle_buffer_histories[2];
  880. GLuint particle_vao_histories[2];
  881. bool particle_valid_histories[2];
  882. bool histories_enabled;
  883. SelfList<Particles> particle_element;
  884. float phase;
  885. float prev_phase;
  886. uint64_t prev_ticks;
  887. uint32_t random_seed;
  888. uint32_t cycle_number;
  889. float speed_scale;
  890. int fixed_fps;
  891. bool fractional_delta;
  892. float frame_remainder;
  893. bool clear;
  894. Transform emission_transform;
  895. Particles() :
  896. inactive(true),
  897. inactive_time(0.0),
  898. emitting(false),
  899. one_shot(false),
  900. amount(0),
  901. lifetime(1.0),
  902. pre_process_time(0.0),
  903. explosiveness(0.0),
  904. randomness(0.0),
  905. restart_request(false),
  906. custom_aabb(AABB(Vector3(-4, -4, -4), Vector3(8, 8, 8))),
  907. use_local_coords(true),
  908. draw_order(VS::PARTICLES_DRAW_ORDER_INDEX),
  909. histories_enabled(false),
  910. particle_element(this),
  911. prev_ticks(0),
  912. random_seed(0),
  913. cycle_number(0),
  914. speed_scale(1.0),
  915. fixed_fps(0),
  916. fractional_delta(false),
  917. frame_remainder(0),
  918. clear(true) {
  919. particle_buffers[0] = 0;
  920. particle_buffers[1] = 0;
  921. glGenBuffers(2, particle_buffers);
  922. glGenVertexArrays(2, particle_vaos);
  923. }
  924. ~Particles() {
  925. glDeleteBuffers(2, particle_buffers);
  926. glDeleteVertexArrays(2, particle_vaos);
  927. if (histories_enabled) {
  928. glDeleteBuffers(2, particle_buffer_histories);
  929. glDeleteVertexArrays(2, particle_vao_histories);
  930. }
  931. }
  932. };
  933. SelfList<Particles>::List particle_update_list;
  934. void update_particles();
  935. mutable RID_Owner<Particles> particles_owner;
  936. virtual RID particles_create();
  937. virtual void particles_set_emitting(RID p_particles, bool p_emitting);
  938. virtual bool particles_get_emitting(RID p_particles);
  939. virtual void particles_set_amount(RID p_particles, int p_amount);
  940. virtual void particles_set_lifetime(RID p_particles, float p_lifetime);
  941. virtual void particles_set_one_shot(RID p_particles, bool p_one_shot);
  942. virtual void particles_set_pre_process_time(RID p_particles, float p_time);
  943. virtual void particles_set_explosiveness_ratio(RID p_particles, float p_ratio);
  944. virtual void particles_set_randomness_ratio(RID p_particles, float p_ratio);
  945. virtual void particles_set_custom_aabb(RID p_particles, const AABB &p_aabb);
  946. virtual void particles_set_speed_scale(RID p_particles, float p_scale);
  947. virtual void particles_set_use_local_coordinates(RID p_particles, bool p_enable);
  948. virtual void particles_set_process_material(RID p_particles, RID p_material);
  949. virtual void particles_set_fixed_fps(RID p_particles, int p_fps);
  950. virtual void particles_set_fractional_delta(RID p_particles, bool p_enable);
  951. virtual void particles_restart(RID p_particles);
  952. virtual void particles_set_draw_order(RID p_particles, VS::ParticlesDrawOrder p_order);
  953. virtual void particles_set_draw_passes(RID p_particles, int p_passes);
  954. virtual void particles_set_draw_pass_mesh(RID p_particles, int p_pass, RID p_mesh);
  955. virtual void particles_request_process(RID p_particles);
  956. virtual AABB particles_get_current_aabb(RID p_particles);
  957. virtual AABB particles_get_aabb(RID p_particles) const;
  958. virtual void _particles_update_histories(Particles *particles);
  959. virtual void particles_set_emission_transform(RID p_particles, const Transform &p_transform);
  960. void _particles_process(Particles *p_particles, float p_delta);
  961. virtual int particles_get_draw_passes(RID p_particles) const;
  962. virtual RID particles_get_draw_pass_mesh(RID p_particles, int p_pass) const;
  963. virtual bool particles_is_inactive(RID p_particles) const;
  964. /* INSTANCE */
  965. virtual void instance_add_skeleton(RID p_skeleton, RasterizerScene::InstanceBase *p_instance);
  966. virtual void instance_remove_skeleton(RID p_skeleton, RasterizerScene::InstanceBase *p_instance);
  967. virtual void instance_add_dependency(RID p_base, RasterizerScene::InstanceBase *p_instance);
  968. virtual void instance_remove_dependency(RID p_base, RasterizerScene::InstanceBase *p_instance);
  969. /* RENDER TARGET */
  970. struct RenderTarget : public RID_Data {
  971. GLuint fbo;
  972. GLuint color;
  973. GLuint depth;
  974. struct Buffers {
  975. bool active;
  976. bool effects_active;
  977. GLuint fbo;
  978. GLuint depth;
  979. GLuint specular;
  980. GLuint diffuse;
  981. GLuint normal_rough;
  982. GLuint sss;
  983. GLuint effect_fbo;
  984. GLuint effect;
  985. } buffers;
  986. struct Effects {
  987. struct MipMaps {
  988. struct Size {
  989. GLuint fbo;
  990. int width;
  991. int height;
  992. };
  993. Vector<Size> sizes;
  994. GLuint color;
  995. int levels;
  996. MipMaps() :
  997. color(0),
  998. levels(0) {
  999. }
  1000. };
  1001. MipMaps mip_maps[2]; //first mipmap chain starts from full-screen
  1002. //GLuint depth2; //depth for the second mipmap chain, in case of desiring upsampling
  1003. struct SSAO {
  1004. GLuint blur_fbo[2]; // blur fbo
  1005. GLuint blur_red[2]; // 8 bits red buffer
  1006. GLuint linear_depth;
  1007. Vector<GLuint> depth_mipmap_fbos; //fbos for depth mipmapsla ver
  1008. SSAO() :
  1009. linear_depth(0) {
  1010. blur_fbo[0] = 0;
  1011. blur_fbo[1] = 0;
  1012. }
  1013. } ssao;
  1014. Effects() {}
  1015. } effects;
  1016. struct Exposure {
  1017. GLuint fbo;
  1018. GLuint color;
  1019. Exposure() :
  1020. fbo(0) {}
  1021. } exposure;
  1022. // External FBO to render our final result to (mostly used for ARVR)
  1023. struct External {
  1024. GLuint fbo;
  1025. RID texture;
  1026. External() :
  1027. fbo(0) {}
  1028. } external;
  1029. uint64_t last_exposure_tick;
  1030. int width, height;
  1031. bool flags[RENDER_TARGET_FLAG_MAX];
  1032. bool used_in_frame;
  1033. VS::ViewportMSAA msaa;
  1034. RID texture;
  1035. RenderTarget() :
  1036. fbo(0),
  1037. depth(0),
  1038. last_exposure_tick(0),
  1039. width(0),
  1040. height(0),
  1041. used_in_frame(false),
  1042. msaa(VS::VIEWPORT_MSAA_DISABLED) {
  1043. exposure.fbo = 0;
  1044. buffers.fbo = 0;
  1045. external.fbo = 0;
  1046. for (int i = 0; i < RENDER_TARGET_FLAG_MAX; i++) {
  1047. flags[i] = false;
  1048. }
  1049. flags[RENDER_TARGET_HDR] = true;
  1050. buffers.active = false;
  1051. buffers.effects_active = false;
  1052. }
  1053. };
  1054. mutable RID_Owner<RenderTarget> render_target_owner;
  1055. void _render_target_clear(RenderTarget *rt);
  1056. void _render_target_allocate(RenderTarget *rt);
  1057. virtual RID render_target_create();
  1058. virtual void render_target_set_position(RID p_render_target, int p_x, int p_y);
  1059. virtual void render_target_set_size(RID p_render_target, int p_width, int p_height);
  1060. virtual RID render_target_get_texture(RID p_render_target) const;
  1061. virtual void render_target_set_external_texture(RID p_render_target, unsigned int p_texture_id);
  1062. virtual void render_target_set_flag(RID p_render_target, RenderTargetFlags p_flag, bool p_value);
  1063. virtual bool render_target_was_used(RID p_render_target);
  1064. virtual void render_target_clear_used(RID p_render_target);
  1065. virtual void render_target_set_msaa(RID p_render_target, VS::ViewportMSAA p_msaa);
  1066. /* CANVAS SHADOW */
  1067. struct CanvasLightShadow : public RID_Data {
  1068. int size;
  1069. int height;
  1070. GLuint fbo;
  1071. GLuint depth;
  1072. GLuint distance; //for older devices
  1073. };
  1074. RID_Owner<CanvasLightShadow> canvas_light_shadow_owner;
  1075. virtual RID canvas_light_shadow_buffer_create(int p_width);
  1076. /* LIGHT SHADOW MAPPING */
  1077. struct CanvasOccluder : public RID_Data {
  1078. GLuint array_id; // 0 means, unconfigured
  1079. GLuint vertex_id; // 0 means, unconfigured
  1080. GLuint index_id; // 0 means, unconfigured
  1081. PoolVector<Vector2> lines;
  1082. int len;
  1083. };
  1084. RID_Owner<CanvasOccluder> canvas_occluder_owner;
  1085. virtual RID canvas_light_occluder_create();
  1086. virtual void canvas_light_occluder_set_polylines(RID p_occluder, const PoolVector<Vector2> &p_lines);
  1087. virtual VS::InstanceType get_base_type(RID p_rid) const;
  1088. virtual bool free(RID p_rid);
  1089. struct Frame {
  1090. RenderTarget *current_rt;
  1091. bool clear_request;
  1092. Color clear_request_color;
  1093. float time[4];
  1094. float delta;
  1095. uint64_t count;
  1096. } frame;
  1097. void initialize();
  1098. void finalize();
  1099. virtual bool has_os_feature(const String &p_feature) const;
  1100. virtual void update_dirty_resources();
  1101. virtual void set_debug_generate_wireframes(bool p_generate);
  1102. virtual void render_info_begin_capture();
  1103. virtual void render_info_end_capture();
  1104. virtual int get_captured_render_info(VS::RenderInfo p_info);
  1105. virtual int get_render_info(VS::RenderInfo p_info);
  1106. virtual String get_video_adapter_name() const;
  1107. virtual String get_video_adapter_vendor() const;
  1108. RasterizerStorageGLES3();
  1109. };
  1110. #endif // RASTERIZERSTORAGEGLES3_H