rasterizer_storage_gles3.h 41 KB

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