rasterizer_storage_gles3.h 41 KB

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