1 /*************************************************************************/
2 /*  rasterizer_storage_gles2.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 RASTERIZERSTORAGEGLES2_H
32 #define RASTERIZERSTORAGEGLES2_H
33 
34 #include "core/pool_vector.h"
35 #include "core/self_list.h"
36 #include "servers/visual/rasterizer.h"
37 #include "servers/visual/shader_language.h"
38 #include "shader_compiler_gles2.h"
39 #include "shader_gles2.h"
40 
41 #include "shaders/copy.glsl.gen.h"
42 #include "shaders/cubemap_filter.glsl.gen.h"
43 /*
44 #include "shaders/blend_shape.glsl.gen.h"
45 #include "shaders/canvas.glsl.gen.h"
46 #include "shaders/particles.glsl.gen.h"
47 */
48 
49 class RasterizerCanvasGLES2;
50 class RasterizerSceneGLES2;
51 
52 class RasterizerStorageGLES2 : public RasterizerStorage {
53 public:
54 	RasterizerCanvasGLES2 *canvas;
55 	RasterizerSceneGLES2 *scene;
56 
57 	static GLuint system_fbo;
58 
59 	struct Config {
60 
61 		bool shrink_textures_x2;
62 		bool use_fast_texture_filter;
63 		bool use_skeleton_software;
64 
65 		int max_vertex_texture_image_units;
66 		int max_texture_image_units;
67 		int max_texture_size;
68 
69 		// TODO implement wireframe in GLES2
70 		// bool generate_wireframes;
71 
72 		Set<String> extensions;
73 
74 		bool float_texture_supported;
75 		bool s3tc_supported;
76 		bool etc1_supported;
77 		bool pvrtc_supported;
78 		bool rgtc_supported;
79 		bool bptc_supported;
80 
81 		bool keep_original_textures;
82 
83 		bool force_vertex_shading;
84 
85 		bool use_rgba_2d_shadows;
86 		bool use_rgba_3d_shadows;
87 
88 		bool support_32_bits_indices;
89 		bool support_write_depth;
90 		bool support_half_float_vertices;
91 		bool support_npot_repeat_mipmap;
92 		bool support_depth_texture;
93 		bool support_depth_cubemaps;
94 
95 		bool support_shadow_cubemaps;
96 
97 		bool multisample_supported;
98 		bool render_to_mipmap_supported;
99 
100 		GLuint depth_internalformat;
101 		GLuint depth_type;
102 		GLuint depth_buffer_internalformat;
103 
104 	} config;
105 
106 	struct Resources {
107 
108 		GLuint white_tex;
109 		GLuint black_tex;
110 		GLuint normal_tex;
111 		GLuint aniso_tex;
112 
113 		GLuint mipmap_blur_fbo;
114 		GLuint mipmap_blur_color;
115 
116 		GLuint radical_inverse_vdc_cache_tex;
117 		bool use_rgba_2d_shadows;
118 
119 		GLuint quadie;
120 
121 		size_t skeleton_transform_buffer_size;
122 		GLuint skeleton_transform_buffer;
123 		PoolVector<float> skeleton_transform_cpu_buffer;
124 
125 	} resources;
126 
127 	mutable struct Shaders {
128 
129 		ShaderCompilerGLES2 compiler;
130 
131 		CopyShaderGLES2 copy;
132 		CubemapFilterShaderGLES2 cubemap_filter;
133 
134 		ShaderCompilerGLES2::IdentifierActions actions_canvas;
135 		ShaderCompilerGLES2::IdentifierActions actions_scene;
136 		ShaderCompilerGLES2::IdentifierActions actions_particles;
137 
138 	} shaders;
139 
140 	struct Info {
141 
142 		uint64_t texture_mem;
143 		uint64_t vertex_mem;
144 
145 		struct Render {
146 			uint32_t object_count;
147 			uint32_t draw_call_count;
148 			uint32_t material_switch_count;
149 			uint32_t surface_switch_count;
150 			uint32_t shader_rebind_count;
151 			uint32_t vertices_count;
152 			uint32_t _2d_item_count;
153 			uint32_t _2d_draw_call_count;
154 
resetInfo::Render155 			void reset() {
156 				object_count = 0;
157 				draw_call_count = 0;
158 				material_switch_count = 0;
159 				surface_switch_count = 0;
160 				shader_rebind_count = 0;
161 				vertices_count = 0;
162 				_2d_item_count = 0;
163 				_2d_draw_call_count = 0;
164 			}
165 		} render, render_final, snap;
166 
InfoInfo167 		Info() :
168 				texture_mem(0),
169 				vertex_mem(0) {
170 			render.reset();
171 			render_final.reset();
172 		}
173 
174 	} info;
175 
176 	void bind_quad_array() const;
177 
178 	/////////////////////////////////////////////////////////////////////////////////////////
179 	//////////////////////////////////DATA///////////////////////////////////////////////////
180 	/////////////////////////////////////////////////////////////////////////////////////////
181 
182 	struct Instantiable : public RID_Data {
183 		SelfList<RasterizerScene::InstanceBase>::List instance_list;
184 
instance_change_notifyInstantiable185 		_FORCE_INLINE_ void instance_change_notify(bool p_aabb, bool p_materials) {
186 
187 			SelfList<RasterizerScene::InstanceBase> *instances = instance_list.first();
188 			while (instances) {
189 
190 				instances->self()->base_changed(p_aabb, p_materials);
191 				instances = instances->next();
192 			}
193 		}
194 
instance_remove_depsInstantiable195 		_FORCE_INLINE_ void instance_remove_deps() {
196 			SelfList<RasterizerScene::InstanceBase> *instances = instance_list.first();
197 
198 			while (instances) {
199 				instances->self()->base_removed();
200 				instances = instances->next();
201 			}
202 		}
203 
InstantiableInstantiable204 		Instantiable() {}
205 
~InstantiableInstantiable206 		virtual ~Instantiable() {}
207 	};
208 
209 	struct GeometryOwner : public Instantiable {
210 	};
211 
212 	struct Geometry : public Instantiable {
213 
214 		enum Type {
215 			GEOMETRY_INVALID,
216 			GEOMETRY_SURFACE,
217 			GEOMETRY_IMMEDIATE,
218 			GEOMETRY_MULTISURFACE
219 		};
220 
221 		Type type;
222 		RID material;
223 		uint64_t last_pass;
224 		uint32_t index;
225 
material_changed_notifyGeometry226 		virtual void material_changed_notify() {}
227 
GeometryGeometry228 		Geometry() {
229 			last_pass = 0;
230 			index = 0;
231 		}
232 	};
233 
234 	/////////////////////////////////////////////////////////////////////////////////////////
235 	//////////////////////////////////API////////////////////////////////////////////////////
236 	/////////////////////////////////////////////////////////////////////////////////////////
237 
238 	/* TEXTURE API */
239 
240 	struct RenderTarget;
241 
242 	struct Texture : RID_Data {
243 
244 		Texture *proxy;
245 		Set<Texture *> proxy_owners;
246 
247 		String path;
248 		uint32_t flags;
249 		int width, height, depth;
250 		int alloc_width, alloc_height;
251 		Image::Format format;
252 		VS::TextureType type;
253 
254 		GLenum target;
255 		GLenum gl_format_cache;
256 		GLenum gl_internal_format_cache;
257 		GLenum gl_type_cache;
258 
259 		int data_size;
260 		int total_data_size;
261 		bool ignore_mipmaps;
262 
263 		bool compressed;
264 
265 		bool srgb;
266 
267 		int mipmaps;
268 
269 		bool resize_to_po2;
270 
271 		bool active;
272 		GLenum tex_id;
273 
274 		uint16_t stored_cube_sides;
275 
276 		RenderTarget *render_target;
277 
278 		Vector<Ref<Image> > images;
279 
280 		bool redraw_if_visible;
281 
282 		VisualServer::TextureDetectCallback detect_3d;
283 		void *detect_3d_ud;
284 
285 		VisualServer::TextureDetectCallback detect_srgb;
286 		void *detect_srgb_ud;
287 
288 		VisualServer::TextureDetectCallback detect_normal;
289 		void *detect_normal_ud;
290 
TextureTexture291 		Texture() :
292 				proxy(NULL),
293 				flags(0),
294 				width(0),
295 				height(0),
296 				alloc_width(0),
297 				alloc_height(0),
298 				format(Image::FORMAT_L8),
299 				type(VS::TEXTURE_TYPE_2D),
300 				target(0),
301 				data_size(0),
302 				total_data_size(0),
303 				ignore_mipmaps(false),
304 				compressed(false),
305 				mipmaps(0),
306 				resize_to_po2(false),
307 				active(false),
308 				tex_id(0),
309 				stored_cube_sides(0),
310 				render_target(NULL),
311 				redraw_if_visible(false),
312 				detect_3d(NULL),
313 				detect_3d_ud(NULL),
314 				detect_srgb(NULL),
315 				detect_srgb_ud(NULL),
316 				detect_normal(NULL),
317 				detect_normal_ud(NULL) {
318 		}
319 
get_ptrTexture320 		_ALWAYS_INLINE_ Texture *get_ptr() {
321 			if (proxy) {
322 				return proxy; //->get_ptr(); only one level of indirection, else not inlining possible.
323 			} else {
324 				return this;
325 			}
326 		}
327 
~TextureTexture328 		~Texture() {
329 			if (tex_id != 0) {
330 				glDeleteTextures(1, &tex_id);
331 			}
332 
333 			for (Set<Texture *>::Element *E = proxy_owners.front(); E; E = E->next()) {
334 				E->get()->proxy = NULL;
335 			}
336 
337 			if (proxy) {
338 				proxy->proxy_owners.erase(this);
339 			}
340 		}
341 	};
342 
343 	mutable RID_Owner<Texture> texture_owner;
344 
345 	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 p_force_decompress) const;
346 
347 	virtual RID texture_create();
348 	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);
349 	virtual void texture_set_data(RID p_texture, const Ref<Image> &p_image, int p_layer = 0);
350 	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);
351 	virtual Ref<Image> texture_get_data(RID p_texture, int p_layer = 0) const;
352 	virtual void texture_set_flags(RID p_texture, uint32_t p_flags);
353 	virtual uint32_t texture_get_flags(RID p_texture) const;
354 	virtual Image::Format texture_get_format(RID p_texture) const;
355 	virtual VS::TextureType texture_get_type(RID p_texture) const;
356 	virtual uint32_t texture_get_texid(RID p_texture) const;
357 	virtual uint32_t texture_get_width(RID p_texture) const;
358 	virtual uint32_t texture_get_height(RID p_texture) const;
359 	virtual uint32_t texture_get_depth(RID p_texture) const;
360 	virtual void texture_set_size_override(RID p_texture, int p_width, int p_height, int p_depth);
361 	virtual void texture_bind(RID p_texture, uint32_t p_texture_no);
362 
363 	virtual void texture_set_path(RID p_texture, const String &p_path);
364 	virtual String texture_get_path(RID p_texture) const;
365 
366 	virtual void texture_set_shrink_all_x2_on_set_data(bool p_enable);
367 
368 	virtual void texture_debug_usage(List<VS::TextureInfo> *r_info);
369 
370 	virtual RID texture_create_radiance_cubemap(RID p_source, int p_resolution = -1) const;
371 
372 	virtual void textures_keep_original(bool p_enable);
373 
374 	virtual void texture_set_proxy(RID p_texture, RID p_proxy);
375 	virtual Size2 texture_size_with_proxy(RID p_texture) const;
376 
377 	virtual void texture_set_detect_3d_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata);
378 	virtual void texture_set_detect_srgb_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata);
379 	virtual void texture_set_detect_normal_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata);
380 
381 	virtual void texture_set_force_redraw_if_visible(RID p_texture, bool p_enable);
382 
383 	/* SKY API */
384 
385 	struct Sky : public RID_Data {
386 
387 		RID panorama;
388 		GLuint radiance;
389 		int radiance_size;
390 	};
391 
392 	mutable RID_Owner<Sky> sky_owner;
393 
394 	virtual RID sky_create();
395 	virtual void sky_set_texture(RID p_sky, RID p_panorama, int p_radiance_size);
396 
397 	/* SHADER API */
398 
399 	struct Material;
400 
401 	struct Shader : public RID_Data {
402 
403 		RID self;
404 
405 		VS::ShaderMode mode;
406 		ShaderGLES2 *shader;
407 		String code;
408 		SelfList<Material>::List materials;
409 
410 		Map<StringName, ShaderLanguage::ShaderNode::Uniform> uniforms;
411 
412 		uint32_t texture_count;
413 
414 		uint32_t custom_code_id;
415 		uint32_t version;
416 
417 		SelfList<Shader> dirty_list;
418 
419 		Map<StringName, RID> default_textures;
420 
421 		Vector<ShaderLanguage::ShaderNode::Uniform::Hint> texture_hints;
422 
423 		bool valid;
424 
425 		String path;
426 
427 		uint32_t index;
428 		uint64_t last_pass;
429 
430 		struct CanvasItem {
431 
432 			enum BlendMode {
433 				BLEND_MODE_MIX,
434 				BLEND_MODE_ADD,
435 				BLEND_MODE_SUB,
436 				BLEND_MODE_MUL,
437 				BLEND_MODE_PMALPHA,
438 			};
439 
440 			int blend_mode;
441 
442 			enum LightMode {
443 				LIGHT_MODE_NORMAL,
444 				LIGHT_MODE_UNSHADED,
445 				LIGHT_MODE_LIGHT_ONLY
446 			};
447 
448 			int light_mode;
449 
450 			// these flags are specifically for batching
451 			// some of the logic is thus in rasterizer_storage.cpp
452 			// we could alternatively set bitflags for each 'uses' and test on the fly
453 			enum BatchFlags {
454 				PREVENT_COLOR_BAKING = 1 << 0,
455 				PREVENT_VERTEX_BAKING = 1 << 1,
456 			};
457 			unsigned int batch_flags;
458 
459 			bool uses_screen_texture;
460 			bool uses_screen_uv;
461 			bool uses_time;
462 			bool uses_modulate;
463 			bool uses_color;
464 			bool uses_vertex;
465 
466 		} canvas_item;
467 
468 		struct Spatial {
469 
470 			enum BlendMode {
471 				BLEND_MODE_MIX,
472 				BLEND_MODE_ADD,
473 				BLEND_MODE_SUB,
474 				BLEND_MODE_MUL,
475 			};
476 
477 			int blend_mode;
478 
479 			enum DepthDrawMode {
480 				DEPTH_DRAW_OPAQUE,
481 				DEPTH_DRAW_ALWAYS,
482 				DEPTH_DRAW_NEVER,
483 				DEPTH_DRAW_ALPHA_PREPASS,
484 			};
485 
486 			int depth_draw_mode;
487 
488 			enum CullMode {
489 				CULL_MODE_FRONT,
490 				CULL_MODE_BACK,
491 				CULL_MODE_DISABLED,
492 			};
493 
494 			int cull_mode;
495 
496 			bool uses_alpha;
497 			bool uses_alpha_scissor;
498 			bool unshaded;
499 			bool no_depth_test;
500 			bool uses_vertex;
501 			bool uses_discard;
502 			bool uses_sss;
503 			bool uses_screen_texture;
504 			bool uses_depth_texture;
505 			bool uses_time;
506 			bool writes_modelview_or_projection;
507 			bool uses_vertex_lighting;
508 			bool uses_world_coordinates;
509 
510 		} spatial;
511 
512 		struct Particles {
513 
514 		} particles;
515 
516 		bool uses_vertex_time;
517 		bool uses_fragment_time;
518 
ShaderShader519 		Shader() :
520 				dirty_list(this) {
521 
522 			shader = NULL;
523 			valid = false;
524 			custom_code_id = 0;
525 			version = 1;
526 			last_pass = 0;
527 		}
528 	};
529 
530 	mutable RID_Owner<Shader> shader_owner;
531 	mutable SelfList<Shader>::List _shader_dirty_list;
532 
533 	void _shader_make_dirty(Shader *p_shader);
534 
535 	virtual RID shader_create();
536 
537 	virtual void shader_set_code(RID p_shader, const String &p_code);
538 	virtual String shader_get_code(RID p_shader) const;
539 	virtual void shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const;
540 
541 	virtual void shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture);
542 	virtual RID shader_get_default_texture_param(RID p_shader, const StringName &p_name) const;
543 
544 	virtual void shader_add_custom_define(RID p_shader, const String &p_define);
545 	virtual void shader_get_custom_defines(RID p_shader, Vector<String> *p_defines) const;
546 	virtual void shader_remove_custom_define(RID p_shader, const String &p_define);
547 
548 	void _update_shader(Shader *p_shader) const;
549 	void update_dirty_shaders();
550 
551 	/* COMMON MATERIAL API */
552 
553 	struct Material : public RID_Data {
554 
555 		Shader *shader;
556 		Map<StringName, Variant> params;
557 		SelfList<Material> list;
558 		SelfList<Material> dirty_list;
559 		Vector<Pair<StringName, 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 				list(this),
576 				dirty_list(this) {
577 			can_cast_shadow_cache = false;
578 			is_animated_cache = false;
579 			shader = NULL;
580 			line_width = 1.0;
581 			last_pass = 0;
582 			render_priority = 0;
583 		}
584 	};
585 
586 	mutable SelfList<Material>::List _material_dirty_list;
587 	void _material_make_dirty(Material *p_material) const;
588 
589 	void _material_add_geometry(RID p_material, Geometry *p_geometry);
590 	void _material_remove_geometry(RID p_material, Geometry *p_geometry);
591 
592 	void _update_material(Material *p_material);
593 
594 	mutable RID_Owner<Material> material_owner;
595 
596 	virtual RID material_create();
597 
598 	virtual void material_set_shader(RID p_material, RID p_shader);
599 	virtual RID material_get_shader(RID p_material) const;
600 
601 	virtual void material_set_param(RID p_material, const StringName &p_param, const Variant &p_value);
602 	virtual Variant material_get_param(RID p_material, const StringName &p_param) const;
603 	virtual Variant material_get_param_default(RID p_material, const StringName &p_param) const;
604 
605 	virtual void material_set_line_width(RID p_material, float p_width);
606 	virtual void material_set_next_pass(RID p_material, RID p_next_material);
607 
608 	virtual bool material_is_animated(RID p_material);
609 	virtual bool material_casts_shadows(RID p_material);
610 
611 	virtual void material_add_instance_owner(RID p_material, RasterizerScene::InstanceBase *p_instance);
612 	virtual void material_remove_instance_owner(RID p_material, RasterizerScene::InstanceBase *p_instance);
613 
614 	virtual void material_set_render_priority(RID p_material, int priority);
615 
616 	void update_dirty_materials();
617 
618 	/* MESH API */
619 
620 	struct Mesh;
621 
622 	struct Surface : public Geometry {
623 
624 		struct Attrib {
625 			bool enabled;
626 			bool integer;
627 			GLuint index;
628 			GLint size;
629 			GLenum type;
630 			GLboolean normalized;
631 			GLsizei stride;
632 			uint32_t offset;
633 		};
634 
635 		Attrib attribs[VS::ARRAY_MAX];
636 
637 		Mesh *mesh;
638 		uint32_t format;
639 
640 		GLuint vertex_id;
641 		GLuint index_id;
642 
643 		struct BlendShape {
644 			GLuint vertex_id;
645 			GLuint array_id;
646 		};
647 
648 		Vector<BlendShape> blend_shapes;
649 
650 		AABB aabb;
651 
652 		int array_len;
653 		int index_array_len;
654 		int max_bone;
655 
656 		int array_byte_size;
657 		int index_array_byte_size;
658 
659 		VS::PrimitiveType primitive;
660 
661 		Vector<AABB> skeleton_bone_aabb;
662 		Vector<bool> skeleton_bone_used;
663 
664 		bool active;
665 
666 		PoolVector<uint8_t> data;
667 		PoolVector<uint8_t> index_data;
668 		Vector<PoolVector<uint8_t> > blend_shape_data;
669 
670 		int total_data_size;
671 
SurfaceSurface672 		Surface() :
673 				mesh(NULL),
674 				array_len(0),
675 				index_array_len(0),
676 				array_byte_size(0),
677 				index_array_byte_size(0),
678 				primitive(VS::PRIMITIVE_POINTS),
679 				active(false),
680 				total_data_size(0) {
681 		}
682 	};
683 
684 	struct MultiMesh;
685 
686 	struct Mesh : public GeometryOwner {
687 
688 		bool active;
689 
690 		Vector<Surface *> surfaces;
691 
692 		int blend_shape_count;
693 		VS::BlendShapeMode blend_shape_mode;
694 
695 		AABB custom_aabb;
696 
697 		mutable uint64_t last_pass;
698 
699 		SelfList<MultiMesh>::List multimeshes;
700 
update_multimeshesMesh701 		_FORCE_INLINE_ void update_multimeshes() {
702 			SelfList<MultiMesh> *mm = multimeshes.first();
703 
704 			while (mm) {
705 				mm->self()->instance_change_notify(false, true);
706 				mm = mm->next();
707 			}
708 		}
709 
MeshMesh710 		Mesh() :
711 				blend_shape_count(0),
712 				blend_shape_mode(VS::BLEND_SHAPE_MODE_NORMALIZED) {
713 		}
714 	};
715 
716 	mutable RID_Owner<Mesh> mesh_owner;
717 
718 	virtual RID mesh_create();
719 
720 	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>());
721 
722 	virtual void mesh_set_blend_shape_count(RID p_mesh, int p_amount);
723 	virtual int mesh_get_blend_shape_count(RID p_mesh) const;
724 
725 	virtual void mesh_set_blend_shape_mode(RID p_mesh, VS::BlendShapeMode p_mode);
726 	virtual VS::BlendShapeMode mesh_get_blend_shape_mode(RID p_mesh) const;
727 
728 	virtual void mesh_surface_update_region(RID p_mesh, int p_surface, int p_offset, const PoolVector<uint8_t> &p_data);
729 
730 	virtual void mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material);
731 	virtual RID mesh_surface_get_material(RID p_mesh, int p_surface) const;
732 
733 	virtual int mesh_surface_get_array_len(RID p_mesh, int p_surface) const;
734 	virtual int mesh_surface_get_array_index_len(RID p_mesh, int p_surface) const;
735 
736 	virtual PoolVector<uint8_t> mesh_surface_get_array(RID p_mesh, int p_surface) const;
737 	virtual PoolVector<uint8_t> mesh_surface_get_index_array(RID p_mesh, int p_surface) const;
738 
739 	virtual uint32_t mesh_surface_get_format(RID p_mesh, int p_surface) const;
740 	virtual VS::PrimitiveType mesh_surface_get_primitive_type(RID p_mesh, int p_surface) const;
741 
742 	virtual AABB mesh_surface_get_aabb(RID p_mesh, int p_surface) const;
743 	virtual Vector<PoolVector<uint8_t> > mesh_surface_get_blend_shapes(RID p_mesh, int p_surface) const;
744 	virtual Vector<AABB> mesh_surface_get_skeleton_aabb(RID p_mesh, int p_surface) const;
745 
746 	virtual void mesh_remove_surface(RID p_mesh, int p_surface);
747 	virtual int mesh_get_surface_count(RID p_mesh) const;
748 
749 	virtual void mesh_set_custom_aabb(RID p_mesh, const AABB &p_aabb);
750 	virtual AABB mesh_get_custom_aabb(RID p_mesh) const;
751 
752 	virtual AABB mesh_get_aabb(RID p_mesh, RID p_skeleton) const;
753 	virtual void mesh_clear(RID p_mesh);
754 
755 	/* MULTIMESH API */
756 
757 	struct MultiMesh : public GeometryOwner {
758 
759 		RID mesh;
760 		int size;
761 
762 		VS::MultimeshTransformFormat transform_format;
763 		VS::MultimeshColorFormat color_format;
764 		VS::MultimeshCustomDataFormat custom_data_format;
765 
766 		Vector<float> data;
767 
768 		AABB aabb;
769 
770 		SelfList<MultiMesh> update_list;
771 		SelfList<MultiMesh> mesh_list;
772 
773 		int visible_instances;
774 
775 		int xform_floats;
776 		int color_floats;
777 		int custom_data_floats;
778 
779 		bool dirty_aabb;
780 		bool dirty_data;
781 
MultiMeshMultiMesh782 		MultiMesh() :
783 				size(0),
784 				transform_format(VS::MULTIMESH_TRANSFORM_2D),
785 				color_format(VS::MULTIMESH_COLOR_NONE),
786 				custom_data_format(VS::MULTIMESH_CUSTOM_DATA_NONE),
787 				update_list(this),
788 				mesh_list(this),
789 				visible_instances(-1),
790 				xform_floats(0),
791 				color_floats(0),
792 				custom_data_floats(0),
793 				dirty_aabb(true),
794 				dirty_data(true) {
795 		}
796 	};
797 
798 	mutable RID_Owner<MultiMesh> multimesh_owner;
799 
800 	SelfList<MultiMesh>::List multimesh_update_list;
801 
802 	virtual RID multimesh_create();
803 
804 	virtual void multimesh_allocate(RID p_multimesh, int p_instances, VS::MultimeshTransformFormat p_transform_format, VS::MultimeshColorFormat p_color_format, VS::MultimeshCustomDataFormat p_data = VS::MULTIMESH_CUSTOM_DATA_NONE);
805 	virtual int multimesh_get_instance_count(RID p_multimesh) const;
806 
807 	virtual void multimesh_set_mesh(RID p_multimesh, RID p_mesh);
808 	virtual void multimesh_instance_set_transform(RID p_multimesh, int p_index, const Transform &p_transform);
809 	virtual void multimesh_instance_set_transform_2d(RID p_multimesh, int p_index, const Transform2D &p_transform);
810 	virtual void multimesh_instance_set_color(RID p_multimesh, int p_index, const Color &p_color);
811 	virtual void multimesh_instance_set_custom_data(RID p_multimesh, int p_index, const Color &p_custom_data);
812 
813 	virtual RID multimesh_get_mesh(RID p_multimesh) const;
814 
815 	virtual Transform multimesh_instance_get_transform(RID p_multimesh, int p_index) const;
816 	virtual Transform2D multimesh_instance_get_transform_2d(RID p_multimesh, int p_index) const;
817 	virtual Color multimesh_instance_get_color(RID p_multimesh, int p_index) const;
818 	virtual Color multimesh_instance_get_custom_data(RID p_multimesh, int p_index) const;
819 
820 	virtual void multimesh_set_as_bulk_array(RID p_multimesh, const PoolVector<float> &p_array);
821 
822 	virtual void multimesh_set_visible_instances(RID p_multimesh, int p_visible);
823 	virtual int multimesh_get_visible_instances(RID p_multimesh) const;
824 
825 	virtual AABB multimesh_get_aabb(RID p_multimesh) const;
826 
827 	void update_dirty_multimeshes();
828 
829 	/* IMMEDIATE API */
830 
831 	struct Immediate : public Geometry {
832 
833 		struct Chunk {
834 			RID texture;
835 			VS::PrimitiveType primitive;
836 			Vector<Vector3> vertices;
837 			Vector<Vector3> normals;
838 			Vector<Plane> tangents;
839 			Vector<Color> colors;
840 			Vector<Vector2> uvs;
841 			Vector<Vector2> uv2s;
842 		};
843 
844 		List<Chunk> chunks;
845 		bool building;
846 		int mask;
847 		AABB aabb;
848 
ImmediateImmediate849 		Immediate() {
850 			type = GEOMETRY_IMMEDIATE;
851 			building = false;
852 		}
853 	};
854 
855 	Vector3 chunk_normal;
856 	Plane chunk_tangent;
857 	Color chunk_color;
858 	Vector2 chunk_uv;
859 	Vector2 chunk_uv2;
860 
861 	mutable RID_Owner<Immediate> immediate_owner;
862 
863 	virtual RID immediate_create();
864 	virtual void immediate_begin(RID p_immediate, VS::PrimitiveType p_primitive, RID p_texture = RID());
865 	virtual void immediate_vertex(RID p_immediate, const Vector3 &p_vertex);
866 	virtual void immediate_normal(RID p_immediate, const Vector3 &p_normal);
867 	virtual void immediate_tangent(RID p_immediate, const Plane &p_tangent);
868 	virtual void immediate_color(RID p_immediate, const Color &p_color);
869 	virtual void immediate_uv(RID p_immediate, const Vector2 &tex_uv);
870 	virtual void immediate_uv2(RID p_immediate, const Vector2 &tex_uv);
871 	virtual void immediate_end(RID p_immediate);
872 	virtual void immediate_clear(RID p_immediate);
873 	virtual void immediate_set_material(RID p_immediate, RID p_material);
874 	virtual RID immediate_get_material(RID p_immediate) const;
875 	virtual AABB immediate_get_aabb(RID p_immediate) const;
876 
877 	/* SKELETON API */
878 
879 	struct Skeleton : RID_Data {
880 
881 		bool use_2d;
882 
883 		int size;
884 
885 		// TODO use float textures for storage
886 
887 		Vector<float> bone_data;
888 
889 		GLuint tex_id;
890 
891 		SelfList<Skeleton> update_list;
892 		Set<RasterizerScene::InstanceBase *> instances;
893 
894 		Transform2D base_transform_2d;
895 
SkeletonSkeleton896 		Skeleton() :
897 				use_2d(false),
898 				size(0),
899 				tex_id(0),
900 				update_list(this) {
901 		}
902 	};
903 
904 	mutable RID_Owner<Skeleton> skeleton_owner;
905 
906 	SelfList<Skeleton>::List skeleton_update_list;
907 
908 	void update_dirty_skeletons();
909 
910 	virtual RID skeleton_create();
911 	virtual void skeleton_allocate(RID p_skeleton, int p_bones, bool p_2d_skeleton = false);
912 	virtual int skeleton_get_bone_count(RID p_skeleton) const;
913 	virtual void skeleton_bone_set_transform(RID p_skeleton, int p_bone, const Transform &p_transform);
914 	virtual Transform skeleton_bone_get_transform(RID p_skeleton, int p_bone) const;
915 	virtual void skeleton_bone_set_transform_2d(RID p_skeleton, int p_bone, const Transform2D &p_transform);
916 	virtual Transform2D skeleton_bone_get_transform_2d(RID p_skeleton, int p_bone) const;
917 	virtual void skeleton_set_base_transform_2d(RID p_skeleton, const Transform2D &p_base_transform);
918 
919 	void _update_skeleton_transform_buffer(const PoolVector<float> &p_data, size_t p_size);
920 
921 	/* Light API */
922 
923 	struct Light : Instantiable {
924 		VS::LightType type;
925 		float param[VS::LIGHT_PARAM_MAX];
926 
927 		Color color;
928 		Color shadow_color;
929 
930 		RID projector;
931 
932 		bool shadow;
933 		bool negative;
934 		bool reverse_cull;
935 		bool use_gi;
936 
937 		uint32_t cull_mask;
938 
939 		VS::LightOmniShadowMode omni_shadow_mode;
940 		VS::LightOmniShadowDetail omni_shadow_detail;
941 
942 		VS::LightDirectionalShadowMode directional_shadow_mode;
943 		VS::LightDirectionalShadowDepthRangeMode directional_range_mode;
944 
945 		bool directional_blend_splits;
946 
947 		uint64_t version;
948 	};
949 
950 	mutable RID_Owner<Light> light_owner;
951 
952 	virtual RID light_create(VS::LightType p_type);
953 
954 	virtual void light_set_color(RID p_light, const Color &p_color);
955 	virtual void light_set_param(RID p_light, VS::LightParam p_param, float p_value);
956 	virtual void light_set_shadow(RID p_light, bool p_enabled);
957 	virtual void light_set_shadow_color(RID p_light, const Color &p_color);
958 	virtual void light_set_projector(RID p_light, RID p_texture);
959 	virtual void light_set_negative(RID p_light, bool p_enable);
960 	virtual void light_set_cull_mask(RID p_light, uint32_t p_mask);
961 	virtual void light_set_reverse_cull_face_mode(RID p_light, bool p_enabled);
962 	virtual void light_set_use_gi(RID p_light, bool p_enabled);
963 
964 	virtual void light_omni_set_shadow_mode(RID p_light, VS::LightOmniShadowMode p_mode);
965 	virtual void light_omni_set_shadow_detail(RID p_light, VS::LightOmniShadowDetail p_detail);
966 
967 	virtual void light_directional_set_shadow_mode(RID p_light, VS::LightDirectionalShadowMode p_mode);
968 	virtual void light_directional_set_blend_splits(RID p_light, bool p_enable);
969 	virtual bool light_directional_get_blend_splits(RID p_light) const;
970 
971 	virtual VS::LightDirectionalShadowMode light_directional_get_shadow_mode(RID p_light);
972 	virtual VS::LightOmniShadowMode light_omni_get_shadow_mode(RID p_light);
973 
974 	virtual void light_directional_set_shadow_depth_range_mode(RID p_light, VS::LightDirectionalShadowDepthRangeMode p_range_mode);
975 	virtual VS::LightDirectionalShadowDepthRangeMode light_directional_get_shadow_depth_range_mode(RID p_light) const;
976 
977 	virtual bool light_has_shadow(RID p_light) const;
978 
979 	virtual VS::LightType light_get_type(RID p_light) const;
980 	virtual float light_get_param(RID p_light, VS::LightParam p_param);
981 	virtual Color light_get_color(RID p_light);
982 	virtual bool light_get_use_gi(RID p_light);
983 
984 	virtual AABB light_get_aabb(RID p_light) const;
985 	virtual uint64_t light_get_version(RID p_light) const;
986 
987 	/* PROBE API */
988 
989 	struct ReflectionProbe : Instantiable {
990 
991 		VS::ReflectionProbeUpdateMode update_mode;
992 		float intensity;
993 		Color interior_ambient;
994 		float interior_ambient_energy;
995 		float interior_ambient_probe_contrib;
996 		float max_distance;
997 		Vector3 extents;
998 		Vector3 origin_offset;
999 		bool interior;
1000 		bool box_projection;
1001 		bool enable_shadows;
1002 		uint32_t cull_mask;
1003 		int resolution;
1004 	};
1005 
1006 	mutable RID_Owner<ReflectionProbe> reflection_probe_owner;
1007 
1008 	virtual RID reflection_probe_create();
1009 
1010 	virtual void reflection_probe_set_update_mode(RID p_probe, VS::ReflectionProbeUpdateMode p_mode);
1011 	virtual void reflection_probe_set_intensity(RID p_probe, float p_intensity);
1012 	virtual void reflection_probe_set_interior_ambient(RID p_probe, const Color &p_ambient);
1013 	virtual void reflection_probe_set_interior_ambient_energy(RID p_probe, float p_energy);
1014 	virtual void reflection_probe_set_interior_ambient_probe_contribution(RID p_probe, float p_contrib);
1015 	virtual void reflection_probe_set_max_distance(RID p_probe, float p_distance);
1016 	virtual void reflection_probe_set_extents(RID p_probe, const Vector3 &p_extents);
1017 	virtual void reflection_probe_set_origin_offset(RID p_probe, const Vector3 &p_offset);
1018 	virtual void reflection_probe_set_as_interior(RID p_probe, bool p_enable);
1019 	virtual void reflection_probe_set_enable_box_projection(RID p_probe, bool p_enable);
1020 	virtual void reflection_probe_set_enable_shadows(RID p_probe, bool p_enable);
1021 	virtual void reflection_probe_set_cull_mask(RID p_probe, uint32_t p_layers);
1022 	virtual void reflection_probe_set_resolution(RID p_probe, int p_resolution);
1023 
1024 	virtual AABB reflection_probe_get_aabb(RID p_probe) const;
1025 	virtual VS::ReflectionProbeUpdateMode reflection_probe_get_update_mode(RID p_probe) const;
1026 	virtual uint32_t reflection_probe_get_cull_mask(RID p_probe) const;
1027 
1028 	virtual int reflection_probe_get_resolution(RID p_probe) const;
1029 
1030 	virtual Vector3 reflection_probe_get_extents(RID p_probe) const;
1031 	virtual Vector3 reflection_probe_get_origin_offset(RID p_probe) const;
1032 	virtual float reflection_probe_get_origin_max_distance(RID p_probe) const;
1033 	virtual bool reflection_probe_renders_shadows(RID p_probe) const;
1034 
1035 	/* GI PROBE API */
1036 	virtual RID gi_probe_create();
1037 
1038 	virtual void gi_probe_set_bounds(RID p_probe, const AABB &p_bounds);
1039 	virtual AABB gi_probe_get_bounds(RID p_probe) const;
1040 
1041 	virtual void gi_probe_set_cell_size(RID p_probe, float p_size);
1042 	virtual float gi_probe_get_cell_size(RID p_probe) const;
1043 
1044 	virtual void gi_probe_set_to_cell_xform(RID p_probe, const Transform &p_xform);
1045 	virtual Transform gi_probe_get_to_cell_xform(RID p_probe) const;
1046 
1047 	virtual void gi_probe_set_dynamic_data(RID p_probe, const PoolVector<int> &p_data);
1048 	virtual PoolVector<int> gi_probe_get_dynamic_data(RID p_probe) const;
1049 
1050 	virtual void gi_probe_set_dynamic_range(RID p_probe, int p_range);
1051 	virtual int gi_probe_get_dynamic_range(RID p_probe) const;
1052 
1053 	virtual void gi_probe_set_energy(RID p_probe, float p_range);
1054 	virtual float gi_probe_get_energy(RID p_probe) const;
1055 
1056 	virtual void gi_probe_set_bias(RID p_probe, float p_range);
1057 	virtual float gi_probe_get_bias(RID p_probe) const;
1058 
1059 	virtual void gi_probe_set_normal_bias(RID p_probe, float p_range);
1060 	virtual float gi_probe_get_normal_bias(RID p_probe) const;
1061 
1062 	virtual void gi_probe_set_propagation(RID p_probe, float p_range);
1063 	virtual float gi_probe_get_propagation(RID p_probe) const;
1064 
1065 	virtual void gi_probe_set_interior(RID p_probe, bool p_enable);
1066 	virtual bool gi_probe_is_interior(RID p_probe) const;
1067 
1068 	virtual void gi_probe_set_compress(RID p_probe, bool p_enable);
1069 	virtual bool gi_probe_is_compressed(RID p_probe) const;
1070 
1071 	virtual uint32_t gi_probe_get_version(RID p_probe);
1072 
1073 	virtual GIProbeCompression gi_probe_get_dynamic_data_get_preferred_compression() const;
1074 	virtual RID gi_probe_dynamic_data_create(int p_width, int p_height, int p_depth, GIProbeCompression p_compression);
1075 	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);
1076 
1077 	/* LIGHTMAP */
1078 
1079 	struct LightmapCapture : public Instantiable {
1080 
1081 		PoolVector<LightmapCaptureOctree> octree;
1082 		AABB bounds;
1083 		Transform cell_xform;
1084 		int cell_subdiv;
1085 		float energy;
LightmapCaptureLightmapCapture1086 		LightmapCapture() {
1087 			energy = 1.0;
1088 			cell_subdiv = 1;
1089 		}
1090 	};
1091 
1092 	mutable RID_Owner<LightmapCapture> lightmap_capture_data_owner;
1093 
1094 	virtual RID lightmap_capture_create();
1095 	virtual void lightmap_capture_set_bounds(RID p_capture, const AABB &p_bounds);
1096 	virtual AABB lightmap_capture_get_bounds(RID p_capture) const;
1097 	virtual void lightmap_capture_set_octree(RID p_capture, const PoolVector<uint8_t> &p_octree);
1098 	virtual PoolVector<uint8_t> lightmap_capture_get_octree(RID p_capture) const;
1099 	virtual void lightmap_capture_set_octree_cell_transform(RID p_capture, const Transform &p_xform);
1100 	virtual Transform lightmap_capture_get_octree_cell_transform(RID p_capture) const;
1101 	virtual void lightmap_capture_set_octree_cell_subdiv(RID p_capture, int p_subdiv);
1102 	virtual int lightmap_capture_get_octree_cell_subdiv(RID p_capture) const;
1103 	virtual void lightmap_capture_set_energy(RID p_capture, float p_energy);
1104 	virtual float lightmap_capture_get_energy(RID p_capture) const;
1105 	virtual const PoolVector<LightmapCaptureOctree> *lightmap_capture_get_octree_ptr(RID p_capture) const;
1106 
1107 	/* PARTICLES */
1108 	void update_particles();
1109 
1110 	virtual RID particles_create();
1111 
1112 	virtual void particles_set_emitting(RID p_particles, bool p_emitting);
1113 	virtual bool particles_get_emitting(RID p_particles);
1114 
1115 	virtual void particles_set_amount(RID p_particles, int p_amount);
1116 	virtual void particles_set_lifetime(RID p_particles, float p_lifetime);
1117 	virtual void particles_set_one_shot(RID p_particles, bool p_one_shot);
1118 	virtual void particles_set_pre_process_time(RID p_particles, float p_time);
1119 	virtual void particles_set_explosiveness_ratio(RID p_particles, float p_ratio);
1120 	virtual void particles_set_randomness_ratio(RID p_particles, float p_ratio);
1121 	virtual void particles_set_custom_aabb(RID p_particles, const AABB &p_aabb);
1122 	virtual void particles_set_speed_scale(RID p_particles, float p_scale);
1123 	virtual void particles_set_use_local_coordinates(RID p_particles, bool p_enable);
1124 	virtual void particles_set_process_material(RID p_particles, RID p_material);
1125 	virtual void particles_set_fixed_fps(RID p_particles, int p_fps);
1126 	virtual void particles_set_fractional_delta(RID p_particles, bool p_enable);
1127 	virtual void particles_restart(RID p_particles);
1128 
1129 	virtual void particles_set_draw_order(RID p_particles, VS::ParticlesDrawOrder p_order);
1130 
1131 	virtual void particles_set_draw_passes(RID p_particles, int p_passes);
1132 	virtual void particles_set_draw_pass_mesh(RID p_particles, int p_pass, RID p_mesh);
1133 
1134 	virtual void particles_request_process(RID p_particles);
1135 	virtual AABB particles_get_current_aabb(RID p_particles);
1136 	virtual AABB particles_get_aabb(RID p_particles) const;
1137 
1138 	virtual void particles_set_emission_transform(RID p_particles, const Transform &p_transform);
1139 
1140 	virtual int particles_get_draw_passes(RID p_particles) const;
1141 	virtual RID particles_get_draw_pass_mesh(RID p_particles, int p_pass) const;
1142 
1143 	virtual bool particles_is_inactive(RID p_particles) const;
1144 
1145 	/* INSTANCE */
1146 
1147 	virtual void instance_add_skeleton(RID p_skeleton, RasterizerScene::InstanceBase *p_instance);
1148 	virtual void instance_remove_skeleton(RID p_skeleton, RasterizerScene::InstanceBase *p_instance);
1149 
1150 	virtual void instance_add_dependency(RID p_base, RasterizerScene::InstanceBase *p_instance);
1151 	virtual void instance_remove_dependency(RID p_base, RasterizerScene::InstanceBase *p_instance);
1152 
1153 	/* RENDER TARGET */
1154 
1155 	struct RenderTarget : public RID_Data {
1156 		GLuint fbo;
1157 		GLuint color;
1158 		GLuint depth;
1159 
1160 		GLuint multisample_fbo;
1161 		GLuint multisample_color;
1162 		GLuint multisample_depth;
1163 		bool multisample_active;
1164 
1165 		struct Effect {
1166 			GLuint fbo;
1167 			int width;
1168 			int height;
1169 
1170 			GLuint color;
1171 
EffectRenderTarget::Effect1172 			Effect() :
1173 					fbo(0),
1174 					width(0),
1175 					height(0),
1176 					color(0) {
1177 			}
1178 		};
1179 
1180 		Effect copy_screen_effect;
1181 
1182 		struct MipMaps {
1183 
1184 			struct Size {
1185 				GLuint fbo;
1186 				GLuint color;
1187 				int width;
1188 				int height;
1189 			};
1190 
1191 			Vector<Size> sizes;
1192 			GLuint color;
1193 			int levels;
1194 
MipMapsRenderTarget::MipMaps1195 			MipMaps() :
1196 					color(0),
1197 					levels(0) {
1198 			}
1199 		};
1200 
1201 		MipMaps mip_maps[2];
1202 
1203 		struct External {
1204 			GLuint fbo;
1205 			GLuint color;
1206 			GLuint depth;
1207 			RID texture;
1208 
ExternalRenderTarget::External1209 			External() :
1210 					fbo(0),
1211 					color(0),
1212 					depth(0) {
1213 			}
1214 		} external;
1215 
1216 		int x, y, width, height;
1217 
1218 		bool flags[RENDER_TARGET_FLAG_MAX];
1219 
1220 		bool used_in_frame;
1221 		VS::ViewportMSAA msaa;
1222 
1223 		RID texture;
1224 
1225 		bool used_dof_blur_near;
1226 		bool mip_maps_allocated;
1227 
RenderTargetRenderTarget1228 		RenderTarget() :
1229 				fbo(0),
1230 				color(0),
1231 				depth(0),
1232 				multisample_fbo(0),
1233 				multisample_color(0),
1234 				multisample_depth(0),
1235 				multisample_active(false),
1236 				x(0),
1237 				y(0),
1238 				width(0),
1239 				height(0),
1240 				used_in_frame(false),
1241 				msaa(VS::VIEWPORT_MSAA_DISABLED),
1242 				used_dof_blur_near(false),
1243 				mip_maps_allocated(false) {
1244 			for (int i = 0; i < RENDER_TARGET_FLAG_MAX; ++i) {
1245 				flags[i] = false;
1246 			}
1247 			external.fbo = 0;
1248 		}
1249 	};
1250 
1251 	mutable RID_Owner<RenderTarget> render_target_owner;
1252 
1253 	void _render_target_clear(RenderTarget *rt);
1254 	void _render_target_allocate(RenderTarget *rt);
1255 
1256 	virtual RID render_target_create();
1257 	virtual void render_target_set_position(RID p_render_target, int p_x, int p_y);
1258 	virtual void render_target_set_size(RID p_render_target, int p_width, int p_height);
1259 	virtual RID render_target_get_texture(RID p_render_target) const;
1260 	virtual void render_target_set_external_texture(RID p_render_target, unsigned int p_texture_id);
1261 
1262 	virtual void render_target_set_flag(RID p_render_target, RenderTargetFlags p_flag, bool p_value);
1263 	virtual bool render_target_was_used(RID p_render_target);
1264 	virtual void render_target_clear_used(RID p_render_target);
1265 	virtual void render_target_set_msaa(RID p_render_target, VS::ViewportMSAA p_msaa);
1266 
1267 	/* CANVAS SHADOW */
1268 
1269 	struct CanvasLightShadow : public RID_Data {
1270 
1271 		int size;
1272 		int height;
1273 		GLuint fbo;
1274 		GLuint depth;
1275 		GLuint distance; //for older devices
1276 	};
1277 
1278 	RID_Owner<CanvasLightShadow> canvas_light_shadow_owner;
1279 
1280 	virtual RID canvas_light_shadow_buffer_create(int p_width);
1281 
1282 	/* LIGHT SHADOW MAPPING */
1283 
1284 	struct CanvasOccluder : public RID_Data {
1285 
1286 		GLuint vertex_id; // 0 means, unconfigured
1287 		GLuint index_id; // 0 means, unconfigured
1288 		PoolVector<Vector2> lines;
1289 		int len;
1290 	};
1291 
1292 	RID_Owner<CanvasOccluder> canvas_occluder_owner;
1293 
1294 	virtual RID canvas_light_occluder_create();
1295 	virtual void canvas_light_occluder_set_polylines(RID p_occluder, const PoolVector<Vector2> &p_lines);
1296 
1297 	virtual VS::InstanceType get_base_type(RID p_rid) const;
1298 
1299 	virtual bool free(RID p_rid);
1300 
1301 	struct Frame {
1302 
1303 		RenderTarget *current_rt;
1304 
1305 		bool clear_request;
1306 		Color clear_request_color;
1307 		float time[4];
1308 		float delta;
1309 		uint64_t count;
1310 
1311 	} frame;
1312 
1313 	void initialize();
1314 	void finalize();
1315 
1316 	void _copy_screen();
1317 
1318 	virtual bool has_os_feature(const String &p_feature) const;
1319 
1320 	virtual void update_dirty_resources();
1321 
1322 	virtual void set_debug_generate_wireframes(bool p_generate);
1323 
1324 	virtual void render_info_begin_capture();
1325 	virtual void render_info_end_capture();
1326 	virtual int get_captured_render_info(VS::RenderInfo p_info);
1327 
1328 	virtual int get_render_info(VS::RenderInfo p_info);
1329 	virtual String get_video_adapter_name() const;
1330 	virtual String get_video_adapter_vendor() const;
1331 
1332 	RasterizerStorageGLES2();
1333 };
1334 
1335 #endif // RASTERIZERSTORAGEGLES2_H
1336