1 /*************************************************************************/ 2 /* rasterizer_storage_gles3.h */ 3 /*************************************************************************/ 4 /* This file is part of: */ 5 /* GODOT ENGINE */ 6 /* https://godotengine.org */ 7 /*************************************************************************/ 8 /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ 9 /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ 10 /* */ 11 /* Permission is hereby granted, free of charge, to any person obtaining */ 12 /* a copy of this software and associated documentation files (the */ 13 /* "Software"), to deal in the Software without restriction, including */ 14 /* without limitation the rights to use, copy, modify, merge, publish, */ 15 /* distribute, sublicense, and/or sell copies of the Software, and to */ 16 /* permit persons to whom the Software is furnished to do so, subject to */ 17 /* the following conditions: */ 18 /* */ 19 /* The above copyright notice and this permission notice shall be */ 20 /* included in all copies or substantial portions of the Software. */ 21 /* */ 22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ 23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ 24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ 25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ 26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ 27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ 28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 29 /*************************************************************************/ 30 31 #ifndef RASTERIZERSTORAGEGLES3_H 32 #define RASTERIZERSTORAGEGLES3_H 33 34 #include "core/self_list.h" 35 #include "servers/visual/rasterizer.h" 36 #include "servers/visual/shader_language.h" 37 #include "shader_compiler_gles3.h" 38 #include "shader_gles3.h" 39 40 #include "shaders/blend_shape.glsl.gen.h" 41 #include "shaders/canvas.glsl.gen.h" 42 #include "shaders/copy.glsl.gen.h" 43 #include "shaders/cubemap_filter.glsl.gen.h" 44 #include "shaders/particles.glsl.gen.h" 45 46 // WebGL 2.0 has no MapBufferRange/UnmapBuffer, but offers a non-ES style BufferSubData API instead. 47 #ifdef __EMSCRIPTEN__ 48 void glGetBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, GLvoid *data); 49 #endif 50 51 class RasterizerCanvasGLES3; 52 class RasterizerSceneGLES3; 53 54 #define _TEXTURE_SRGB_DECODE_EXT 0x8A48 55 #define _DECODE_EXT 0x8A49 56 #define _SKIP_DECODE_EXT 0x8A4A 57 58 void glTexStorage2DCustom(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type); 59 60 class RasterizerStorageGLES3 : public RasterizerStorage { 61 public: 62 RasterizerCanvasGLES3 *canvas; 63 RasterizerSceneGLES3 *scene; 64 static GLuint system_fbo; //on some devices, such as apple, screen is rendered to yet another fbo. 65 66 enum RenderArchitecture { 67 RENDER_ARCH_MOBILE, 68 RENDER_ARCH_DESKTOP, 69 }; 70 71 struct Config { 72 73 bool shrink_textures_x2; 74 bool use_fast_texture_filter; 75 bool use_anisotropic_filter; 76 77 bool s3tc_supported; 78 bool latc_supported; 79 bool rgtc_supported; 80 bool bptc_supported; 81 bool etc_supported; 82 bool etc2_supported; 83 bool pvrtc_supported; 84 85 bool srgb_decode_supported; 86 87 bool texture_float_linear_supported; 88 bool framebuffer_float_supported; 89 bool framebuffer_half_float_supported; 90 91 bool use_rgba_2d_shadows; 92 93 float anisotropic_level; 94 95 int max_texture_image_units; 96 int max_texture_size; 97 98 bool generate_wireframes; 99 100 bool use_texture_array_environment; 101 102 Set<String> extensions; 103 104 bool keep_original_textures; 105 106 bool use_depth_prepass; 107 bool force_vertex_shading; 108 } config; 109 110 mutable struct Shaders { 111 112 CopyShaderGLES3 copy; 113 114 ShaderCompilerGLES3 compiler; 115 116 CubemapFilterShaderGLES3 cubemap_filter; 117 118 BlendShapeShaderGLES3 blend_shapes; 119 120 ParticlesShaderGLES3 particles; 121 122 ShaderCompilerGLES3::IdentifierActions actions_canvas; 123 ShaderCompilerGLES3::IdentifierActions actions_scene; 124 ShaderCompilerGLES3::IdentifierActions actions_particles; 125 } shaders; 126 127 struct Resources { 128 129 GLuint white_tex; 130 GLuint black_tex; 131 GLuint normal_tex; 132 GLuint aniso_tex; 133 134 GLuint white_tex_3d; 135 GLuint white_tex_array; 136 137 GLuint quadie; 138 GLuint quadie_array; 139 140 GLuint transform_feedback_buffers[2]; 141 GLuint transform_feedback_array; 142 143 } resources; 144 145 struct Info { 146 147 uint64_t texture_mem; 148 uint64_t vertex_mem; 149 150 struct Render { 151 uint32_t object_count; 152 uint32_t draw_call_count; 153 uint32_t material_switch_count; 154 uint32_t surface_switch_count; 155 uint32_t shader_rebind_count; 156 uint32_t vertices_count; 157 uint32_t _2d_item_count; 158 uint32_t _2d_draw_call_count; 159 resetInfo::Render160 void reset() { 161 object_count = 0; 162 draw_call_count = 0; 163 material_switch_count = 0; 164 surface_switch_count = 0; 165 shader_rebind_count = 0; 166 vertices_count = 0; 167 _2d_item_count = 0; 168 _2d_draw_call_count = 0; 169 } 170 } render, render_final, snap; 171 InfoInfo172 Info() { 173 174 texture_mem = 0; 175 vertex_mem = 0; 176 render.reset(); 177 render_final.reset(); 178 } 179 180 } info; 181 182 ///////////////////////////////////////////////////////////////////////////////////////// 183 //////////////////////////////////DATA/////////////////////////////////////////////////// 184 ///////////////////////////////////////////////////////////////////////////////////////// 185 186 struct Instantiable : public RID_Data { 187 188 SelfList<RasterizerScene::InstanceBase>::List instance_list; 189 instance_change_notifyInstantiable190 _FORCE_INLINE_ void instance_change_notify(bool p_aabb, bool p_materials) { 191 192 SelfList<RasterizerScene::InstanceBase> *instances = instance_list.first(); 193 while (instances) { 194 195 instances->self()->base_changed(p_aabb, p_materials); 196 instances = instances->next(); 197 } 198 } 199 instance_remove_depsInstantiable200 _FORCE_INLINE_ void instance_remove_deps() { 201 SelfList<RasterizerScene::InstanceBase> *instances = instance_list.first(); 202 while (instances) { 203 204 SelfList<RasterizerScene::InstanceBase> *next = instances->next(); 205 instances->self()->base_removed(); 206 instances = next; 207 } 208 } 209 InstantiableInstantiable210 Instantiable() {} ~InstantiableInstantiable211 virtual ~Instantiable() { 212 } 213 }; 214 215 struct GeometryOwner : public Instantiable { 216 ~GeometryOwnerGeometryOwner217 virtual ~GeometryOwner() {} 218 }; 219 struct Geometry : Instantiable { 220 221 enum Type { 222 GEOMETRY_INVALID, 223 GEOMETRY_SURFACE, 224 GEOMETRY_IMMEDIATE, 225 GEOMETRY_MULTISURFACE, 226 }; 227 228 Type type; 229 RID material; 230 uint64_t last_pass; 231 uint32_t index; 232 material_changed_notifyGeometry233 virtual void material_changed_notify() {} 234 GeometryGeometry235 Geometry() { 236 last_pass = 0; 237 index = 0; 238 } 239 }; 240 241 ///////////////////////////////////////////////////////////////////////////////////////// 242 //////////////////////////////////API//////////////////////////////////////////////////// 243 ///////////////////////////////////////////////////////////////////////////////////////// 244 245 /* TEXTURE API */ 246 247 struct RenderTarget; 248 249 struct Texture : public RID_Data { 250 251 Texture *proxy; 252 Set<Texture *> proxy_owners; 253 254 String path; 255 uint32_t flags; 256 int width, height, depth; 257 int alloc_width, alloc_height, alloc_depth; 258 Image::Format format; 259 VS::TextureType type; 260 261 GLenum target; 262 GLenum gl_format_cache; 263 GLenum gl_internal_format_cache; 264 GLenum gl_type_cache; 265 int data_size; //original data size, useful for retrieving back 266 bool compressed; 267 bool srgb; 268 int total_data_size; 269 bool ignore_mipmaps; 270 271 int mipmaps; 272 273 bool is_npot_repeat_mipmap; 274 275 bool active; 276 GLuint tex_id; 277 278 bool using_srgb; 279 bool redraw_if_visible; 280 281 uint16_t stored_cube_sides; 282 283 RenderTarget *render_target; 284 285 Vector<Ref<Image> > images; 286 287 VisualServer::TextureDetectCallback detect_3d; 288 void *detect_3d_ud; 289 290 VisualServer::TextureDetectCallback detect_srgb; 291 void *detect_srgb_ud; 292 293 VisualServer::TextureDetectCallback detect_normal; 294 void *detect_normal_ud; 295 TextureTexture296 Texture() : 297 proxy(NULL), 298 flags(0), 299 width(0), 300 height(0), 301 format(Image::FORMAT_L8), 302 type(VS::TEXTURE_TYPE_2D), 303 target(GL_TEXTURE_2D), 304 data_size(0), 305 compressed(false), 306 srgb(false), 307 total_data_size(0), 308 ignore_mipmaps(false), 309 mipmaps(0), 310 active(false), 311 tex_id(0), 312 using_srgb(false), 313 redraw_if_visible(false), 314 stored_cube_sides(0), 315 render_target(NULL), 316 detect_3d(NULL), 317 detect_3d_ud(NULL), 318 detect_srgb(NULL), 319 detect_srgb_ud(NULL), 320 detect_normal(NULL), 321 detect_normal_ud(NULL) { 322 } 323 get_ptrTexture324 _ALWAYS_INLINE_ Texture *get_ptr() { 325 if (proxy) { 326 return proxy; //->get_ptr(); only one level of indirection, else not inlining possible. 327 } else { 328 return this; 329 } 330 } 331 ~TextureTexture332 ~Texture() { 333 334 if (tex_id != 0) { 335 336 glDeleteTextures(1, &tex_id); 337 } 338 339 for (Set<Texture *>::Element *E = proxy_owners.front(); E; E = E->next()) { 340 E->get()->proxy = NULL; 341 } 342 343 if (proxy) { 344 proxy->proxy_owners.erase(this); 345 } 346 } 347 }; 348 349 mutable RID_Owner<Texture> texture_owner; 350 351 Ref<Image> _get_gl_image_and_format(const Ref<Image> &p_image, Image::Format p_format, uint32_t p_flags, Image::Format &r_real_format, GLenum &r_gl_format, GLenum &r_gl_internal_format, GLenum &r_gl_type, bool &r_compressed, bool &r_srgb, bool p_force_decompress) const; 352 353 virtual RID texture_create(); 354 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); 355 virtual void texture_set_data(RID p_texture, const Ref<Image> &p_image, int p_layer = 0); 356 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); 357 virtual Ref<Image> texture_get_data(RID p_texture, int p_layer = 0) const; 358 virtual void texture_set_flags(RID p_texture, uint32_t p_flags); 359 virtual uint32_t texture_get_flags(RID p_texture) const; 360 virtual Image::Format texture_get_format(RID p_texture) const; 361 virtual VS::TextureType texture_get_type(RID p_texture) const; 362 virtual uint32_t texture_get_texid(RID p_texture) const; 363 virtual uint32_t texture_get_width(RID p_texture) const; 364 virtual uint32_t texture_get_height(RID p_texture) const; 365 virtual uint32_t texture_get_depth(RID p_texture) const; 366 virtual void texture_set_size_override(RID p_texture, int p_width, int p_height, int p_depth); 367 virtual void texture_bind(RID p_texture, uint32_t p_texture_no); 368 369 virtual void texture_set_path(RID p_texture, const String &p_path); 370 virtual String texture_get_path(RID p_texture) const; 371 372 virtual void texture_set_shrink_all_x2_on_set_data(bool p_enable); 373 374 virtual void texture_debug_usage(List<VS::TextureInfo> *r_info); 375 376 virtual RID texture_create_radiance_cubemap(RID p_source, int p_resolution = -1) const; 377 378 virtual void textures_keep_original(bool p_enable); 379 380 virtual void texture_set_detect_3d_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata); 381 virtual void texture_set_detect_srgb_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata); 382 virtual void texture_set_detect_normal_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata); 383 384 virtual void texture_set_proxy(RID p_texture, RID p_proxy); 385 virtual Size2 texture_size_with_proxy(RID p_texture) const; 386 387 virtual void texture_set_force_redraw_if_visible(RID p_texture, bool p_enable); 388 389 /* SKY API */ 390 391 struct Sky : public RID_Data { 392 393 RID panorama; 394 GLuint radiance; 395 GLuint irradiance; 396 int radiance_size; 397 }; 398 399 mutable RID_Owner<Sky> sky_owner; 400 401 virtual RID sky_create(); 402 virtual void sky_set_texture(RID p_sky, RID p_panorama, int p_radiance_size); 403 404 /* SHADER API */ 405 406 struct Material; 407 408 struct Shader : public RID_Data { 409 410 RID self; 411 412 VS::ShaderMode mode; 413 ShaderGLES3 *shader; 414 String code; 415 SelfList<Material>::List materials; 416 417 Map<StringName, ShaderLanguage::ShaderNode::Uniform> uniforms; 418 Vector<uint32_t> ubo_offsets; 419 uint32_t ubo_size; 420 421 uint32_t texture_count; 422 423 uint32_t custom_code_id; 424 uint32_t version; 425 426 SelfList<Shader> dirty_list; 427 428 Map<StringName, RID> default_textures; 429 430 Vector<ShaderLanguage::DataType> texture_types; 431 Vector<ShaderLanguage::ShaderNode::Uniform::Hint> texture_hints; 432 433 bool valid; 434 435 String path; 436 437 struct CanvasItem { 438 439 enum BlendMode { 440 BLEND_MODE_MIX, 441 BLEND_MODE_ADD, 442 BLEND_MODE_SUB, 443 BLEND_MODE_MUL, 444 BLEND_MODE_PMALPHA, 445 BLEND_MODE_DISABLED, 446 }; 447 448 int blend_mode; 449 450 enum LightMode { 451 LIGHT_MODE_NORMAL, 452 LIGHT_MODE_UNSHADED, 453 LIGHT_MODE_LIGHT_ONLY 454 }; 455 456 int light_mode; 457 458 bool uses_screen_texture; 459 bool uses_screen_uv; 460 bool uses_time; 461 462 } canvas_item; 463 464 struct Spatial { 465 466 enum BlendMode { 467 BLEND_MODE_MIX, 468 BLEND_MODE_ADD, 469 BLEND_MODE_SUB, 470 BLEND_MODE_MUL, 471 }; 472 473 int blend_mode; 474 475 enum DepthDrawMode { 476 DEPTH_DRAW_OPAQUE, 477 DEPTH_DRAW_ALWAYS, 478 DEPTH_DRAW_NEVER, 479 DEPTH_DRAW_ALPHA_PREPASS, 480 }; 481 482 int depth_draw_mode; 483 484 enum CullMode { 485 CULL_MODE_FRONT, 486 CULL_MODE_BACK, 487 CULL_MODE_DISABLED, 488 }; 489 490 int cull_mode; 491 492 bool uses_alpha; 493 bool uses_alpha_scissor; 494 bool unshaded; 495 bool no_depth_test; 496 bool uses_vertex; 497 bool uses_discard; 498 bool uses_sss; 499 bool uses_screen_texture; 500 bool uses_depth_texture; 501 bool uses_time; 502 bool writes_modelview_or_projection; 503 bool uses_vertex_lighting; 504 bool uses_world_coordinates; 505 506 } spatial; 507 508 struct Particles { 509 510 } particles; 511 512 bool uses_vertex_time; 513 bool uses_fragment_time; 514 ShaderShader515 Shader() : 516 dirty_list(this) { 517 518 shader = NULL; 519 ubo_size = 0; 520 valid = false; 521 custom_code_id = 0; 522 version = 1; 523 } 524 }; 525 526 mutable SelfList<Shader>::List _shader_dirty_list; 527 void _shader_make_dirty(Shader *p_shader); 528 529 mutable RID_Owner<Shader> shader_owner; 530 531 virtual RID shader_create(); 532 533 virtual void shader_set_code(RID p_shader, const String &p_code); 534 virtual String shader_get_code(RID p_shader) const; 535 virtual void shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const; 536 537 virtual void shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture); 538 virtual RID shader_get_default_texture_param(RID p_shader, const StringName &p_name) const; 539 540 virtual void shader_add_custom_define(RID p_shader, const String &p_define); 541 virtual void shader_get_custom_defines(RID p_shader, Vector<String> *p_defines) const; 542 virtual void shader_remove_custom_define(RID p_shader, const String &p_define); 543 544 void _update_shader(Shader *p_shader) const; 545 546 void update_dirty_shaders(); 547 548 /* COMMON MATERIAL API */ 549 550 struct Material : public RID_Data { 551 552 Shader *shader; 553 GLuint ubo_id; 554 uint32_t ubo_size; 555 Map<StringName, Variant> params; 556 SelfList<Material> list; 557 SelfList<Material> dirty_list; 558 Vector<bool> texture_is_3d; 559 Vector<RID> textures; 560 float line_width; 561 int render_priority; 562 563 RID next_pass; 564 565 uint32_t index; 566 uint64_t last_pass; 567 568 Map<Geometry *, int> geometry_owners; 569 Map<RasterizerScene::InstanceBase *, int> instance_owners; 570 571 bool can_cast_shadow_cache; 572 bool is_animated_cache; 573 MaterialMaterial574 Material() : 575 shader(NULL), 576 ubo_id(0), 577 ubo_size(0), 578 list(this), 579 dirty_list(this), 580 line_width(1.0), 581 render_priority(0), 582 last_pass(0), 583 can_cast_shadow_cache(false), 584 is_animated_cache(false) { 585 } 586 }; 587 588 mutable SelfList<Material>::List _material_dirty_list; 589 void _material_make_dirty(Material *p_material) const; 590 void _material_add_geometry(RID p_material, Geometry *p_geometry); 591 void _material_remove_geometry(RID p_material, Geometry *p_geometry); 592 593 mutable RID_Owner<Material> material_owner; 594 595 virtual RID material_create(); 596 597 virtual void material_set_shader(RID p_material, RID p_shader); 598 virtual RID material_get_shader(RID p_material) const; 599 600 virtual void material_set_param(RID p_material, const StringName &p_param, const Variant &p_value); 601 virtual Variant material_get_param(RID p_material, const StringName &p_param) const; 602 virtual Variant material_get_param_default(RID p_material, const StringName &p_param) const; 603 604 virtual void material_set_line_width(RID p_material, float p_width); 605 virtual void material_set_next_pass(RID p_material, RID p_next_material); 606 607 virtual bool material_is_animated(RID p_material); 608 virtual bool material_casts_shadows(RID p_material); 609 610 virtual void material_add_instance_owner(RID p_material, RasterizerScene::InstanceBase *p_instance); 611 virtual void material_remove_instance_owner(RID p_material, RasterizerScene::InstanceBase *p_instance); 612 613 virtual void material_set_render_priority(RID p_material, int priority); 614 615 void _update_material(Material *material); 616 617 void update_dirty_materials(); 618 619 /* MESH API */ 620 621 struct Mesh; 622 struct Surface : public Geometry { 623 624 struct Attrib { 625 626 bool enabled; 627 bool integer; 628 GLuint index; 629 GLint size; 630 GLenum type; 631 GLboolean normalized; 632 GLsizei stride; 633 uint32_t offset; 634 }; 635 636 Attrib attribs[VS::ARRAY_MAX]; 637 638 Mesh *mesh; 639 uint32_t format; 640 641 GLuint array_id; 642 GLuint instancing_array_id; 643 GLuint vertex_id; 644 GLuint index_id; 645 646 GLuint index_wireframe_id; 647 GLuint array_wireframe_id; 648 GLuint instancing_array_wireframe_id; 649 int index_wireframe_len; 650 651 Vector<AABB> skeleton_bone_aabb; 652 Vector<bool> skeleton_bone_used; 653 654 //bool packed; 655 656 struct BlendShape { 657 GLuint vertex_id; 658 GLuint array_id; 659 }; 660 661 Vector<BlendShape> blend_shapes; 662 663 AABB aabb; 664 665 int array_len; 666 int index_array_len; 667 int max_bone; 668 669 int array_byte_size; 670 int index_array_byte_size; 671 672 VS::PrimitiveType primitive; 673 674 bool active; 675 material_changed_notifySurface676 virtual void material_changed_notify() { 677 mesh->instance_change_notify(false, true); 678 mesh->update_multimeshes(); 679 } 680 681 int total_data_size; 682 SurfaceSurface683 Surface() : 684 mesh(NULL), 685 format(0), 686 array_id(0), 687 vertex_id(0), 688 index_id(0), 689 index_wireframe_id(0), 690 array_wireframe_id(0), 691 instancing_array_wireframe_id(0), 692 index_wireframe_len(0), 693 array_len(0), 694 index_array_len(0), 695 array_byte_size(0), 696 index_array_byte_size(0), 697 primitive(VS::PRIMITIVE_POINTS), 698 active(false), 699 total_data_size(0) { 700 type = GEOMETRY_SURFACE; 701 } 702 ~SurfaceSurface703 ~Surface() { 704 } 705 }; 706 707 struct MultiMesh; 708 709 struct Mesh : public GeometryOwner { 710 711 bool active; 712 Vector<Surface *> surfaces; 713 int blend_shape_count; 714 VS::BlendShapeMode blend_shape_mode; 715 AABB custom_aabb; 716 mutable uint64_t last_pass; 717 SelfList<MultiMesh>::List multimeshes; update_multimeshesMesh718 _FORCE_INLINE_ void update_multimeshes() { 719 720 SelfList<MultiMesh> *mm = multimeshes.first(); 721 while (mm) { 722 mm->self()->instance_change_notify(false, true); 723 mm = mm->next(); 724 } 725 } 726 MeshMesh727 Mesh() : 728 active(false), 729 blend_shape_count(0), 730 blend_shape_mode(VS::BLEND_SHAPE_MODE_NORMALIZED), 731 last_pass(0) { 732 } 733 }; 734 735 mutable RID_Owner<Mesh> mesh_owner; 736 737 virtual RID mesh_create(); 738 739 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>()); 740 741 virtual void mesh_set_blend_shape_count(RID p_mesh, int p_amount); 742 virtual int mesh_get_blend_shape_count(RID p_mesh) const; 743 744 virtual void mesh_set_blend_shape_mode(RID p_mesh, VS::BlendShapeMode p_mode); 745 virtual VS::BlendShapeMode mesh_get_blend_shape_mode(RID p_mesh) const; 746 747 virtual void mesh_surface_update_region(RID p_mesh, int p_surface, int p_offset, const PoolVector<uint8_t> &p_data); 748 749 virtual void mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material); 750 virtual RID mesh_surface_get_material(RID p_mesh, int p_surface) const; 751 752 virtual int mesh_surface_get_array_len(RID p_mesh, int p_surface) const; 753 virtual int mesh_surface_get_array_index_len(RID p_mesh, int p_surface) const; 754 755 virtual PoolVector<uint8_t> mesh_surface_get_array(RID p_mesh, int p_surface) const; 756 virtual PoolVector<uint8_t> mesh_surface_get_index_array(RID p_mesh, int p_surface) const; 757 758 virtual uint32_t mesh_surface_get_format(RID p_mesh, int p_surface) const; 759 virtual VS::PrimitiveType mesh_surface_get_primitive_type(RID p_mesh, int p_surface) const; 760 761 virtual AABB mesh_surface_get_aabb(RID p_mesh, int p_surface) const; 762 virtual Vector<PoolVector<uint8_t> > mesh_surface_get_blend_shapes(RID p_mesh, int p_surface) const; 763 virtual Vector<AABB> mesh_surface_get_skeleton_aabb(RID p_mesh, int p_surface) const; 764 765 virtual void mesh_remove_surface(RID p_mesh, int p_surface); 766 virtual int mesh_get_surface_count(RID p_mesh) const; 767 768 virtual void mesh_set_custom_aabb(RID p_mesh, const AABB &p_aabb); 769 virtual AABB mesh_get_custom_aabb(RID p_mesh) const; 770 771 virtual AABB mesh_get_aabb(RID p_mesh, RID p_skeleton) const; 772 virtual void mesh_clear(RID p_mesh); 773 774 void mesh_render_blend_shapes(Surface *s, const float *p_weights); 775 776 /* MULTIMESH API */ 777 778 struct MultiMesh : public GeometryOwner { 779 RID mesh; 780 int size; 781 VS::MultimeshTransformFormat transform_format; 782 VS::MultimeshColorFormat color_format; 783 VS::MultimeshCustomDataFormat custom_data_format; 784 Vector<float> data; 785 AABB aabb; 786 SelfList<MultiMesh> update_list; 787 SelfList<MultiMesh> mesh_list; 788 GLuint buffer; 789 int visible_instances; 790 791 int xform_floats; 792 int color_floats; 793 int custom_data_floats; 794 795 bool dirty_aabb; 796 bool dirty_data; 797 MultiMeshMultiMesh798 MultiMesh() : 799 size(0), 800 transform_format(VS::MULTIMESH_TRANSFORM_2D), 801 color_format(VS::MULTIMESH_COLOR_NONE), 802 custom_data_format(VS::MULTIMESH_CUSTOM_DATA_NONE), 803 update_list(this), 804 mesh_list(this), 805 buffer(0), 806 visible_instances(-1), 807 xform_floats(0), 808 color_floats(0), 809 custom_data_floats(0), 810 dirty_aabb(true), 811 dirty_data(true) { 812 } 813 }; 814 815 mutable RID_Owner<MultiMesh> multimesh_owner; 816 817 SelfList<MultiMesh>::List multimesh_update_list; 818 819 void update_dirty_multimeshes(); 820 821 virtual RID multimesh_create(); 822 823 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); 824 virtual int multimesh_get_instance_count(RID p_multimesh) const; 825 826 virtual void multimesh_set_mesh(RID p_multimesh, RID p_mesh); 827 virtual void multimesh_instance_set_transform(RID p_multimesh, int p_index, const Transform &p_transform); 828 virtual void multimesh_instance_set_transform_2d(RID p_multimesh, int p_index, const Transform2D &p_transform); 829 virtual void multimesh_instance_set_color(RID p_multimesh, int p_index, const Color &p_color); 830 virtual void multimesh_instance_set_custom_data(RID p_multimesh, int p_index, const Color &p_custom_data); 831 832 virtual RID multimesh_get_mesh(RID p_multimesh) const; 833 834 virtual Transform multimesh_instance_get_transform(RID p_multimesh, int p_index) const; 835 virtual Transform2D multimesh_instance_get_transform_2d(RID p_multimesh, int p_index) const; 836 virtual Color multimesh_instance_get_color(RID p_multimesh, int p_index) const; 837 virtual Color multimesh_instance_get_custom_data(RID p_multimesh, int p_index) const; 838 839 virtual void multimesh_set_as_bulk_array(RID p_multimesh, const PoolVector<float> &p_array); 840 841 virtual void multimesh_set_visible_instances(RID p_multimesh, int p_visible); 842 virtual int multimesh_get_visible_instances(RID p_multimesh) const; 843 844 virtual AABB multimesh_get_aabb(RID p_multimesh) const; 845 846 /* IMMEDIATE API */ 847 848 struct Immediate : public Geometry { 849 850 struct Chunk { 851 852 RID texture; 853 VS::PrimitiveType primitive; 854 Vector<Vector3> vertices; 855 Vector<Vector3> normals; 856 Vector<Plane> tangents; 857 Vector<Color> colors; 858 Vector<Vector2> uvs; 859 Vector<Vector2> uvs2; 860 }; 861 862 List<Chunk> chunks; 863 bool building; 864 int mask; 865 AABB aabb; 866 ImmediateImmediate867 Immediate() { 868 type = GEOMETRY_IMMEDIATE; 869 building = false; 870 } 871 }; 872 873 Vector3 chunk_vertex; 874 Vector3 chunk_normal; 875 Plane chunk_tangent; 876 Color chunk_color; 877 Vector2 chunk_uv; 878 Vector2 chunk_uv2; 879 880 mutable RID_Owner<Immediate> immediate_owner; 881 882 virtual RID immediate_create(); 883 virtual void immediate_begin(RID p_immediate, VS::PrimitiveType p_primitive, RID p_texture = RID()); 884 virtual void immediate_vertex(RID p_immediate, const Vector3 &p_vertex); 885 virtual void immediate_normal(RID p_immediate, const Vector3 &p_normal); 886 virtual void immediate_tangent(RID p_immediate, const Plane &p_tangent); 887 virtual void immediate_color(RID p_immediate, const Color &p_color); 888 virtual void immediate_uv(RID p_immediate, const Vector2 &tex_uv); 889 virtual void immediate_uv2(RID p_immediate, const Vector2 &tex_uv); 890 virtual void immediate_end(RID p_immediate); 891 virtual void immediate_clear(RID p_immediate); 892 virtual void immediate_set_material(RID p_immediate, RID p_material); 893 virtual RID immediate_get_material(RID p_immediate) const; 894 virtual AABB immediate_get_aabb(RID p_immediate) const; 895 896 /* SKELETON API */ 897 898 struct Skeleton : RID_Data { 899 bool use_2d; 900 int size; 901 Vector<float> skel_texture; 902 GLuint texture; 903 SelfList<Skeleton> update_list; 904 Set<RasterizerScene::InstanceBase *> instances; //instances using skeleton 905 Transform2D base_transform_2d; 906 SkeletonSkeleton907 Skeleton() : 908 use_2d(false), 909 size(0), 910 texture(0), 911 update_list(this) { 912 } 913 }; 914 915 mutable RID_Owner<Skeleton> skeleton_owner; 916 917 SelfList<Skeleton>::List skeleton_update_list; 918 919 void update_dirty_skeletons(); 920 921 virtual RID skeleton_create(); 922 virtual void skeleton_allocate(RID p_skeleton, int p_bones, bool p_2d_skeleton = false); 923 virtual int skeleton_get_bone_count(RID p_skeleton) const; 924 virtual void skeleton_bone_set_transform(RID p_skeleton, int p_bone, const Transform &p_transform); 925 virtual Transform skeleton_bone_get_transform(RID p_skeleton, int p_bone) const; 926 virtual void skeleton_bone_set_transform_2d(RID p_skeleton, int p_bone, const Transform2D &p_transform); 927 virtual Transform2D skeleton_bone_get_transform_2d(RID p_skeleton, int p_bone) const; 928 virtual void skeleton_set_base_transform_2d(RID p_skeleton, const Transform2D &p_base_transform); 929 930 /* Light API */ 931 932 struct Light : Instantiable { 933 934 VS::LightType type; 935 float param[VS::LIGHT_PARAM_MAX]; 936 Color color; 937 Color shadow_color; 938 RID projector; 939 bool shadow; 940 bool negative; 941 bool reverse_cull; 942 bool use_gi; 943 uint32_t cull_mask; 944 VS::LightOmniShadowMode omni_shadow_mode; 945 VS::LightOmniShadowDetail omni_shadow_detail; 946 VS::LightDirectionalShadowMode directional_shadow_mode; 947 VS::LightDirectionalShadowDepthRangeMode directional_range_mode; 948 bool directional_blend_splits; 949 uint64_t version; 950 }; 951 952 mutable RID_Owner<Light> light_owner; 953 954 virtual RID light_create(VS::LightType p_type); 955 956 virtual void light_set_color(RID p_light, const Color &p_color); 957 virtual void light_set_param(RID p_light, VS::LightParam p_param, float p_value); 958 virtual void light_set_shadow(RID p_light, bool p_enabled); 959 virtual void light_set_shadow_color(RID p_light, const Color &p_color); 960 virtual void light_set_projector(RID p_light, RID p_texture); 961 virtual void light_set_negative(RID p_light, bool p_enable); 962 virtual void light_set_cull_mask(RID p_light, uint32_t p_mask); 963 virtual void light_set_reverse_cull_face_mode(RID p_light, bool p_enabled); 964 virtual void light_set_use_gi(RID p_light, bool p_enabled); 965 966 virtual void light_omni_set_shadow_mode(RID p_light, VS::LightOmniShadowMode p_mode); 967 virtual void light_omni_set_shadow_detail(RID p_light, VS::LightOmniShadowDetail p_detail); 968 969 virtual void light_directional_set_shadow_mode(RID p_light, VS::LightDirectionalShadowMode p_mode); 970 virtual void light_directional_set_blend_splits(RID p_light, bool p_enable); 971 virtual bool light_directional_get_blend_splits(RID p_light) const; 972 973 virtual VS::LightDirectionalShadowMode light_directional_get_shadow_mode(RID p_light); 974 virtual VS::LightOmniShadowMode light_omni_get_shadow_mode(RID p_light); 975 976 virtual void light_directional_set_shadow_depth_range_mode(RID p_light, VS::LightDirectionalShadowDepthRangeMode p_range_mode); 977 virtual VS::LightDirectionalShadowDepthRangeMode light_directional_get_shadow_depth_range_mode(RID p_light) const; 978 979 virtual bool light_has_shadow(RID p_light) const; 980 981 virtual VS::LightType light_get_type(RID p_light) const; 982 virtual float light_get_param(RID p_light, VS::LightParam p_param); 983 virtual Color light_get_color(RID p_light); 984 virtual bool light_get_use_gi(RID p_light); 985 986 virtual AABB light_get_aabb(RID p_light) const; 987 virtual uint64_t light_get_version(RID p_light) const; 988 989 /* PROBE API */ 990 991 struct ReflectionProbe : Instantiable { 992 993 VS::ReflectionProbeUpdateMode update_mode; 994 float intensity; 995 Color interior_ambient; 996 float interior_ambient_energy; 997 float interior_ambient_probe_contrib; 998 float max_distance; 999 Vector3 extents; 1000 Vector3 origin_offset; 1001 bool interior; 1002 bool box_projection; 1003 bool enable_shadows; 1004 uint32_t cull_mask; 1005 }; 1006 1007 mutable RID_Owner<ReflectionProbe> reflection_probe_owner; 1008 1009 virtual RID reflection_probe_create(); 1010 1011 virtual void reflection_probe_set_update_mode(RID p_probe, VS::ReflectionProbeUpdateMode p_mode); 1012 virtual void reflection_probe_set_intensity(RID p_probe, float p_intensity); 1013 virtual void reflection_probe_set_interior_ambient(RID p_probe, const Color &p_ambient); 1014 virtual void reflection_probe_set_interior_ambient_energy(RID p_probe, float p_energy); 1015 virtual void reflection_probe_set_interior_ambient_probe_contribution(RID p_probe, float p_contrib); 1016 virtual void reflection_probe_set_max_distance(RID p_probe, float p_distance); 1017 virtual void reflection_probe_set_extents(RID p_probe, const Vector3 &p_extents); 1018 virtual void reflection_probe_set_origin_offset(RID p_probe, const Vector3 &p_offset); 1019 virtual void reflection_probe_set_as_interior(RID p_probe, bool p_enable); 1020 virtual void reflection_probe_set_enable_box_projection(RID p_probe, bool p_enable); 1021 virtual void reflection_probe_set_enable_shadows(RID p_probe, bool p_enable); 1022 virtual void reflection_probe_set_cull_mask(RID p_probe, uint32_t p_layers); 1023 virtual void reflection_probe_set_resolution(RID p_probe, int p_resolution); 1024 1025 virtual AABB reflection_probe_get_aabb(RID p_probe) const; 1026 virtual VS::ReflectionProbeUpdateMode reflection_probe_get_update_mode(RID p_probe) const; 1027 virtual uint32_t reflection_probe_get_cull_mask(RID p_probe) const; 1028 1029 virtual Vector3 reflection_probe_get_extents(RID p_probe) const; 1030 virtual Vector3 reflection_probe_get_origin_offset(RID p_probe) const; 1031 virtual float reflection_probe_get_origin_max_distance(RID p_probe) const; 1032 virtual bool reflection_probe_renders_shadows(RID p_probe) const; 1033 1034 /* GI PROBE API */ 1035 1036 struct GIProbe : public Instantiable { 1037 1038 AABB bounds; 1039 Transform to_cell; 1040 float cell_size; 1041 1042 int dynamic_range; 1043 float energy; 1044 float bias; 1045 float normal_bias; 1046 float propagation; 1047 bool interior; 1048 bool compress; 1049 1050 uint32_t version; 1051 1052 PoolVector<int> dynamic_data; 1053 }; 1054 1055 mutable RID_Owner<GIProbe> gi_probe_owner; 1056 1057 virtual RID gi_probe_create(); 1058 1059 virtual void gi_probe_set_bounds(RID p_probe, const AABB &p_bounds); 1060 virtual AABB gi_probe_get_bounds(RID p_probe) const; 1061 1062 virtual void gi_probe_set_cell_size(RID p_probe, float p_size); 1063 virtual float gi_probe_get_cell_size(RID p_probe) const; 1064 1065 virtual void gi_probe_set_to_cell_xform(RID p_probe, const Transform &p_xform); 1066 virtual Transform gi_probe_get_to_cell_xform(RID p_probe) const; 1067 1068 virtual void gi_probe_set_dynamic_data(RID p_probe, const PoolVector<int> &p_data); 1069 virtual PoolVector<int> gi_probe_get_dynamic_data(RID p_probe) const; 1070 1071 virtual void gi_probe_set_dynamic_range(RID p_probe, int p_range); 1072 virtual int gi_probe_get_dynamic_range(RID p_probe) const; 1073 1074 virtual void gi_probe_set_energy(RID p_probe, float p_range); 1075 virtual float gi_probe_get_energy(RID p_probe) const; 1076 1077 virtual void gi_probe_set_bias(RID p_probe, float p_range); 1078 virtual float gi_probe_get_bias(RID p_probe) const; 1079 1080 virtual void gi_probe_set_normal_bias(RID p_probe, float p_range); 1081 virtual float gi_probe_get_normal_bias(RID p_probe) const; 1082 1083 virtual void gi_probe_set_propagation(RID p_probe, float p_range); 1084 virtual float gi_probe_get_propagation(RID p_probe) const; 1085 1086 virtual void gi_probe_set_interior(RID p_probe, bool p_enable); 1087 virtual bool gi_probe_is_interior(RID p_probe) const; 1088 1089 virtual void gi_probe_set_compress(RID p_probe, bool p_enable); 1090 virtual bool gi_probe_is_compressed(RID p_probe) const; 1091 1092 virtual uint32_t gi_probe_get_version(RID p_probe); 1093 1094 struct GIProbeData : public RID_Data { 1095 1096 int width; 1097 int height; 1098 int depth; 1099 int levels; 1100 GLuint tex_id; 1101 GIProbeCompression compression; 1102 GIProbeDataGIProbeData1103 GIProbeData() { 1104 } 1105 }; 1106 1107 mutable RID_Owner<GIProbeData> gi_probe_data_owner; 1108 1109 virtual GIProbeCompression gi_probe_get_dynamic_data_get_preferred_compression() const; 1110 virtual RID gi_probe_dynamic_data_create(int p_width, int p_height, int p_depth, GIProbeCompression p_compression); 1111 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); 1112 1113 /* LIGHTMAP CAPTURE */ 1114 1115 virtual RID lightmap_capture_create(); 1116 virtual void lightmap_capture_set_bounds(RID p_capture, const AABB &p_bounds); 1117 virtual AABB lightmap_capture_get_bounds(RID p_capture) const; 1118 virtual void lightmap_capture_set_octree(RID p_capture, const PoolVector<uint8_t> &p_octree); 1119 virtual PoolVector<uint8_t> lightmap_capture_get_octree(RID p_capture) const; 1120 virtual void lightmap_capture_set_octree_cell_transform(RID p_capture, const Transform &p_xform); 1121 virtual Transform lightmap_capture_get_octree_cell_transform(RID p_capture) const; 1122 virtual void lightmap_capture_set_octree_cell_subdiv(RID p_capture, int p_subdiv); 1123 virtual int lightmap_capture_get_octree_cell_subdiv(RID p_capture) const; 1124 1125 virtual void lightmap_capture_set_energy(RID p_capture, float p_energy); 1126 virtual float lightmap_capture_get_energy(RID p_capture) const; 1127 1128 virtual const PoolVector<LightmapCaptureOctree> *lightmap_capture_get_octree_ptr(RID p_capture) const; 1129 1130 struct LightmapCapture : public Instantiable { 1131 1132 PoolVector<LightmapCaptureOctree> octree; 1133 AABB bounds; 1134 Transform cell_xform; 1135 int cell_subdiv; 1136 float energy; LightmapCaptureLightmapCapture1137 LightmapCapture() { 1138 energy = 1.0; 1139 cell_subdiv = 1; 1140 } 1141 }; 1142 1143 mutable RID_Owner<LightmapCapture> lightmap_capture_data_owner; 1144 1145 /* PARTICLES */ 1146 1147 struct Particles : public GeometryOwner { 1148 1149 bool inactive; 1150 float inactive_time; 1151 bool emitting; 1152 bool one_shot; 1153 int amount; 1154 float lifetime; 1155 float pre_process_time; 1156 float explosiveness; 1157 float randomness; 1158 bool restart_request; 1159 AABB custom_aabb; 1160 bool use_local_coords; 1161 RID process_material; 1162 1163 VS::ParticlesDrawOrder draw_order; 1164 1165 Vector<RID> draw_passes; 1166 1167 GLuint particle_buffers[2]; 1168 GLuint particle_vaos[2]; 1169 1170 GLuint particle_buffer_histories[2]; 1171 GLuint particle_vao_histories[2]; 1172 bool particle_valid_histories[2]; 1173 bool histories_enabled; 1174 1175 SelfList<Particles> particle_element; 1176 1177 float phase; 1178 float prev_phase; 1179 uint64_t prev_ticks; 1180 uint32_t random_seed; 1181 1182 uint32_t cycle_number; 1183 1184 float speed_scale; 1185 1186 int fixed_fps; 1187 bool fractional_delta; 1188 float frame_remainder; 1189 1190 bool clear; 1191 1192 Transform emission_transform; 1193 ParticlesParticles1194 Particles() : 1195 inactive(true), 1196 inactive_time(0.0), 1197 emitting(false), 1198 one_shot(false), 1199 amount(0), 1200 lifetime(1.0), 1201 pre_process_time(0.0), 1202 explosiveness(0.0), 1203 randomness(0.0), 1204 restart_request(false), 1205 custom_aabb(AABB(Vector3(-4, -4, -4), Vector3(8, 8, 8))), 1206 use_local_coords(true), 1207 draw_order(VS::PARTICLES_DRAW_ORDER_INDEX), 1208 histories_enabled(false), 1209 particle_element(this), 1210 prev_ticks(0), 1211 random_seed(0), 1212 cycle_number(0), 1213 speed_scale(1.0), 1214 fixed_fps(0), 1215 fractional_delta(false), 1216 frame_remainder(0), 1217 clear(true) { 1218 particle_buffers[0] = 0; 1219 particle_buffers[1] = 0; 1220 glGenBuffers(2, particle_buffers); 1221 glGenVertexArrays(2, particle_vaos); 1222 } 1223 ~ParticlesParticles1224 ~Particles() { 1225 1226 glDeleteBuffers(2, particle_buffers); 1227 glDeleteVertexArrays(2, particle_vaos); 1228 if (histories_enabled) { 1229 glDeleteBuffers(2, particle_buffer_histories); 1230 glDeleteVertexArrays(2, particle_vao_histories); 1231 } 1232 } 1233 }; 1234 1235 SelfList<Particles>::List particle_update_list; 1236 1237 void update_particles(); 1238 1239 mutable RID_Owner<Particles> particles_owner; 1240 1241 virtual RID particles_create(); 1242 1243 virtual void particles_set_emitting(RID p_particles, bool p_emitting); 1244 virtual bool particles_get_emitting(RID p_particles); 1245 virtual void particles_set_amount(RID p_particles, int p_amount); 1246 virtual void particles_set_lifetime(RID p_particles, float p_lifetime); 1247 virtual void particles_set_one_shot(RID p_particles, bool p_one_shot); 1248 virtual void particles_set_pre_process_time(RID p_particles, float p_time); 1249 virtual void particles_set_explosiveness_ratio(RID p_particles, float p_ratio); 1250 virtual void particles_set_randomness_ratio(RID p_particles, float p_ratio); 1251 virtual void particles_set_custom_aabb(RID p_particles, const AABB &p_aabb); 1252 virtual void particles_set_speed_scale(RID p_particles, float p_scale); 1253 virtual void particles_set_use_local_coordinates(RID p_particles, bool p_enable); 1254 virtual void particles_set_process_material(RID p_particles, RID p_material); 1255 virtual void particles_set_fixed_fps(RID p_particles, int p_fps); 1256 virtual void particles_set_fractional_delta(RID p_particles, bool p_enable); 1257 virtual void particles_restart(RID p_particles); 1258 1259 virtual void particles_set_draw_order(RID p_particles, VS::ParticlesDrawOrder p_order); 1260 1261 virtual void particles_set_draw_passes(RID p_particles, int p_passes); 1262 virtual void particles_set_draw_pass_mesh(RID p_particles, int p_pass, RID p_mesh); 1263 1264 virtual void particles_request_process(RID p_particles); 1265 virtual AABB particles_get_current_aabb(RID p_particles); 1266 virtual AABB particles_get_aabb(RID p_particles) const; 1267 1268 virtual void _particles_update_histories(Particles *particles); 1269 1270 virtual void particles_set_emission_transform(RID p_particles, const Transform &p_transform); 1271 void _particles_process(Particles *p_particles, float p_delta); 1272 1273 virtual int particles_get_draw_passes(RID p_particles) const; 1274 virtual RID particles_get_draw_pass_mesh(RID p_particles, int p_pass) const; 1275 1276 virtual bool particles_is_inactive(RID p_particles) const; 1277 1278 /* INSTANCE */ 1279 1280 virtual void instance_add_skeleton(RID p_skeleton, RasterizerScene::InstanceBase *p_instance); 1281 virtual void instance_remove_skeleton(RID p_skeleton, RasterizerScene::InstanceBase *p_instance); 1282 1283 virtual void instance_add_dependency(RID p_base, RasterizerScene::InstanceBase *p_instance); 1284 virtual void instance_remove_dependency(RID p_base, RasterizerScene::InstanceBase *p_instance); 1285 1286 /* RENDER TARGET */ 1287 1288 struct RenderTarget : public RID_Data { 1289 1290 GLuint fbo; 1291 GLuint color; 1292 GLuint depth; 1293 1294 struct Buffers { 1295 1296 bool active; 1297 bool effects_active; 1298 GLuint fbo; 1299 GLuint depth; 1300 GLuint specular; 1301 GLuint diffuse; 1302 GLuint normal_rough; 1303 GLuint sss; 1304 1305 GLuint effect_fbo; 1306 GLuint effect; 1307 1308 } buffers; 1309 1310 struct Effects { 1311 1312 struct MipMaps { 1313 1314 struct Size { 1315 GLuint fbo; 1316 int width; 1317 int height; 1318 }; 1319 1320 Vector<Size> sizes; 1321 GLuint color; 1322 int levels; 1323 MipMapsRenderTarget::Effects::MipMaps1324 MipMaps() : 1325 color(0), 1326 levels(0) { 1327 } 1328 }; 1329 1330 MipMaps mip_maps[2]; //first mipmap chain starts from full-screen 1331 //GLuint depth2; //depth for the second mipmap chain, in case of desiring upsampling 1332 1333 struct SSAO { 1334 GLuint blur_fbo[2]; // blur fbo 1335 GLuint blur_red[2]; // 8 bits red buffer 1336 1337 GLuint linear_depth; 1338 1339 Vector<GLuint> depth_mipmap_fbos; //fbos for depth mipmapsla ver 1340 SSAORenderTarget::Effects::SSAO1341 SSAO() : 1342 linear_depth(0) { 1343 blur_fbo[0] = 0; 1344 blur_fbo[1] = 0; 1345 } 1346 } ssao; 1347 EffectsRenderTarget::Effects1348 Effects() {} 1349 1350 } effects; 1351 1352 struct Exposure { 1353 GLuint fbo; 1354 GLuint color; 1355 ExposureRenderTarget::Exposure1356 Exposure() : 1357 fbo(0) {} 1358 } exposure; 1359 1360 // External FBO to render our final result to (mostly used for ARVR) 1361 struct External { 1362 GLuint fbo; 1363 RID texture; 1364 ExternalRenderTarget::External1365 External() : 1366 fbo(0) {} 1367 } external; 1368 1369 uint64_t last_exposure_tick; 1370 1371 int width, height; 1372 1373 bool flags[RENDER_TARGET_FLAG_MAX]; 1374 1375 bool used_in_frame; 1376 VS::ViewportMSAA msaa; 1377 1378 RID texture; 1379 RenderTargetRenderTarget1380 RenderTarget() : 1381 fbo(0), 1382 depth(0), 1383 last_exposure_tick(0), 1384 width(0), 1385 height(0), 1386 used_in_frame(false), 1387 msaa(VS::VIEWPORT_MSAA_DISABLED) { 1388 exposure.fbo = 0; 1389 buffers.fbo = 0; 1390 external.fbo = 0; 1391 for (int i = 0; i < RENDER_TARGET_FLAG_MAX; i++) { 1392 flags[i] = false; 1393 } 1394 flags[RENDER_TARGET_HDR] = true; 1395 buffers.active = false; 1396 buffers.effects_active = false; 1397 } 1398 }; 1399 1400 mutable RID_Owner<RenderTarget> render_target_owner; 1401 1402 void _render_target_clear(RenderTarget *rt); 1403 void _render_target_allocate(RenderTarget *rt); 1404 1405 virtual RID render_target_create(); 1406 virtual void render_target_set_position(RID p_render_target, int p_x, int p_y); 1407 virtual void render_target_set_size(RID p_render_target, int p_width, int p_height); 1408 virtual RID render_target_get_texture(RID p_render_target) const; 1409 virtual void render_target_set_external_texture(RID p_render_target, unsigned int p_texture_id); 1410 1411 virtual void render_target_set_flag(RID p_render_target, RenderTargetFlags p_flag, bool p_value); 1412 virtual bool render_target_was_used(RID p_render_target); 1413 virtual void render_target_clear_used(RID p_render_target); 1414 virtual void render_target_set_msaa(RID p_render_target, VS::ViewportMSAA p_msaa); 1415 1416 /* CANVAS SHADOW */ 1417 1418 struct CanvasLightShadow : public RID_Data { 1419 1420 int size; 1421 int height; 1422 GLuint fbo; 1423 GLuint depth; 1424 GLuint distance; //for older devices 1425 }; 1426 1427 RID_Owner<CanvasLightShadow> canvas_light_shadow_owner; 1428 1429 virtual RID canvas_light_shadow_buffer_create(int p_width); 1430 1431 /* LIGHT SHADOW MAPPING */ 1432 1433 struct CanvasOccluder : public RID_Data { 1434 1435 GLuint array_id; // 0 means, unconfigured 1436 GLuint vertex_id; // 0 means, unconfigured 1437 GLuint index_id; // 0 means, unconfigured 1438 PoolVector<Vector2> lines; 1439 int len; 1440 }; 1441 1442 RID_Owner<CanvasOccluder> canvas_occluder_owner; 1443 1444 virtual RID canvas_light_occluder_create(); 1445 virtual void canvas_light_occluder_set_polylines(RID p_occluder, const PoolVector<Vector2> &p_lines); 1446 1447 virtual VS::InstanceType get_base_type(RID p_rid) const; 1448 1449 virtual bool free(RID p_rid); 1450 1451 struct Frame { 1452 1453 RenderTarget *current_rt; 1454 1455 bool clear_request; 1456 Color clear_request_color; 1457 float time[4]; 1458 float delta; 1459 uint64_t count; 1460 1461 } frame; 1462 1463 void initialize(); 1464 void finalize(); 1465 1466 virtual bool has_os_feature(const String &p_feature) const; 1467 1468 virtual void update_dirty_resources(); 1469 1470 virtual void set_debug_generate_wireframes(bool p_generate); 1471 1472 virtual void render_info_begin_capture(); 1473 virtual void render_info_end_capture(); 1474 virtual int get_captured_render_info(VS::RenderInfo p_info); 1475 1476 virtual int get_render_info(VS::RenderInfo p_info); 1477 virtual String get_video_adapter_name() const; 1478 virtual String get_video_adapter_vendor() const; 1479 1480 RasterizerStorageGLES3(); 1481 }; 1482 1483 #endif // RASTERIZERSTORAGEGLES3_H 1484