rasterizer_gles2.h 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602
  1. /*************************************************************************/
  2. /* rasterizer_gles2.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef RASTERIZER_GLES2_H
  30. #define RASTERIZER_GLES2_H
  31. #include "servers/visual/rasterizer.h"
  32. #ifdef GLES2_ENABLED
  33. #include "image.h"
  34. #include "rid.h"
  35. #include "servers/visual_server.h"
  36. #include "list.h"
  37. #include "map.h"
  38. #include "camera_matrix.h"
  39. #include "sort.h"
  40. #include "self_list.h"
  41. #include "platform_config.h"
  42. #ifndef GLES2_INCLUDE_H
  43. #include <GLES2/gl2.h>
  44. #else
  45. #include GLES2_INCLUDE_H
  46. #endif
  47. #include "drivers/gles2/shaders/material.glsl.h"
  48. #include "drivers/gles2/shaders/canvas.glsl.h"
  49. #include "drivers/gles2/shaders/blur.glsl.h"
  50. #include "drivers/gles2/shaders/copy.glsl.h"
  51. #include "drivers/gles2/shader_compiler_gles2.h"
  52. #include "servers/visual/particle_system_sw.h"
  53. /**
  54. @author Juan Linietsky <[email protected]>
  55. */
  56. class RasterizerGLES2 : public Rasterizer {
  57. enum {
  58. MAX_SCENE_LIGHTS=2048,
  59. LIGHT_SPOT_BIT=0x80,
  60. DEFAULT_SKINNED_BUFFER_SIZE = 2048 * 1024, // 10k vertices
  61. MAX_HW_LIGHTS = 1,
  62. };
  63. uint8_t *skinned_buffer;
  64. int skinned_buffer_size;
  65. bool pvr_supported;
  66. bool pvr_srgb_supported;
  67. bool s3tc_supported;
  68. bool s3tc_srgb_supported;
  69. bool latc_supported;
  70. bool etc_supported;
  71. bool atitc_supported;
  72. bool npo2_textures_available;
  73. bool read_depth_supported;
  74. bool use_framebuffers;
  75. bool full_float_fb_supported;
  76. bool use_shadow_mapping;
  77. bool use_fp16_fb;
  78. bool srgb_supported;
  79. bool float_supported;
  80. bool float_linear_supported;
  81. ShadowFilterTechnique shadow_filter;
  82. bool use_shadow_esm;
  83. bool use_shadow_pcf;
  84. bool use_hw_skeleton_xform;
  85. bool use_depth24;
  86. bool use_texture_instancing;
  87. bool use_attribute_instancing;
  88. bool use_rgba_shadowmaps;
  89. bool use_anisotropic_filter;
  90. float anisotropic_level;
  91. bool use_half_float;
  92. Vector<float> skel_default;
  93. Image _get_gl_image_and_format(const Image& p_image, Image::Format p_format, uint32_t p_flags,GLenum& r_gl_format,GLenum& r_gl_internal_format,int &r_gl_components,bool &r_has_alpha_cache,bool &r_compressed);
  94. class RenderTarget;
  95. struct Texture {
  96. uint32_t flags;
  97. int width,height;
  98. int alloc_width, alloc_height;
  99. Image::Format format;
  100. GLenum target;
  101. GLenum gl_format_cache;
  102. GLenum gl_internal_format_cache;
  103. int gl_components_cache;
  104. int data_size; //original data size, useful for retrieving back
  105. bool has_alpha;
  106. bool format_has_alpha;
  107. bool compressed;
  108. bool disallow_mipmaps;
  109. int total_data_size;
  110. bool ignore_mipmaps;
  111. ObjectID reloader;
  112. StringName reloader_func;
  113. Image image[6];
  114. bool active;
  115. GLuint tex_id;
  116. RenderTarget *render_target;
  117. Texture() {
  118. ignore_mipmaps=false;
  119. render_target=NULL;
  120. flags=width=height=0;
  121. tex_id=0;
  122. data_size=0;
  123. format=Image::FORMAT_GRAYSCALE;
  124. gl_components_cache=0;
  125. format_has_alpha=false;
  126. has_alpha=false;
  127. active=false;
  128. disallow_mipmaps=false;
  129. compressed=false;
  130. total_data_size=0;
  131. target=GL_TEXTURE_2D;
  132. reloader=0;
  133. }
  134. ~Texture() {
  135. if (tex_id!=0) {
  136. glDeleteTextures(1,&tex_id);
  137. }
  138. }
  139. };
  140. mutable RID_Owner<Texture> texture_owner;
  141. struct Shader {
  142. String vertex_code;
  143. String fragment_code;
  144. String light_code;
  145. int vertex_line;
  146. int fragment_line;
  147. int light_line;
  148. VS::ShaderMode mode;
  149. uint32_t custom_code_id;
  150. uint32_t version;
  151. bool valid;
  152. bool has_alpha;
  153. bool can_zpass;
  154. bool has_texscreen;
  155. bool has_screen_uv;
  156. bool writes_vertex;
  157. bool uses_discard;
  158. bool uses_time;
  159. Map<StringName,ShaderLanguage::Uniform> uniforms;
  160. StringName first_texture;
  161. Map<StringName,RID> default_textures;
  162. SelfList<Shader> dirty_list;
  163. Shader() : dirty_list(this) {
  164. valid=false;
  165. custom_code_id=0;
  166. has_alpha=false;
  167. version=1;
  168. vertex_line=0;
  169. fragment_line=0;
  170. light_line=0;
  171. can_zpass=true;
  172. has_texscreen=false;
  173. has_screen_uv=false;
  174. writes_vertex=false;
  175. uses_discard=false;
  176. uses_time=false;
  177. }
  178. };
  179. mutable RID_Owner<Shader> shader_owner;
  180. mutable SelfList<Shader>::List _shader_dirty_list;
  181. _FORCE_INLINE_ void _shader_make_dirty(Shader* p_shader);
  182. void _update_shader( Shader* p_shader) const;
  183. struct Material {
  184. bool flags[VS::MATERIAL_FLAG_MAX];
  185. VS::MaterialBlendMode blend_mode;
  186. VS::MaterialDepthDrawMode depth_draw_mode;
  187. float line_width;
  188. bool has_alpha;
  189. mutable uint32_t shader_version;
  190. RID shader; // shader material
  191. Shader *shader_cache;
  192. struct UniformData {
  193. bool inuse;
  194. bool istexture;
  195. Variant value;
  196. int index;
  197. };
  198. mutable Map<StringName,UniformData> shader_params;
  199. uint64_t last_pass;
  200. Material() {
  201. for(int i=0;i<VS::MATERIAL_FLAG_MAX;i++)
  202. flags[i]=false;
  203. flags[VS::MATERIAL_FLAG_VISIBLE]=true;
  204. line_width=1;
  205. has_alpha=false;
  206. depth_draw_mode=VS::MATERIAL_DEPTH_DRAW_OPAQUE_ONLY;
  207. blend_mode=VS::MATERIAL_BLEND_MODE_MIX;
  208. last_pass = 0;
  209. shader_version=0;
  210. shader_cache=NULL;
  211. }
  212. };
  213. _FORCE_INLINE_ void _update_material_shader_params(Material *p_material) const;
  214. mutable RID_Owner<Material> material_owner;
  215. struct Geometry {
  216. enum Type {
  217. GEOMETRY_INVALID,
  218. GEOMETRY_SURFACE,
  219. GEOMETRY_IMMEDIATE,
  220. GEOMETRY_PARTICLES,
  221. GEOMETRY_MULTISURFACE,
  222. };
  223. Type type;
  224. RID material;
  225. bool has_alpha;
  226. bool material_owned;
  227. Geometry() { has_alpha=false; material_owned = false; }
  228. virtual ~Geometry() {};
  229. };
  230. struct GeometryOwner {
  231. virtual ~GeometryOwner() {}
  232. };
  233. class Mesh;
  234. struct Surface : public Geometry {
  235. struct ArrayData {
  236. uint32_t ofs,size,datatype,count;
  237. bool normalize;
  238. bool bind;
  239. ArrayData() { ofs=0; size=0; count=0; datatype=0; normalize=0; bind=false;}
  240. };
  241. Mesh *mesh;
  242. Array data;
  243. Array morph_data;
  244. ArrayData array[VS::ARRAY_MAX];
  245. // support for vertex array objects
  246. GLuint array_object_id;
  247. // support for vertex buffer object
  248. GLuint vertex_id; // 0 means, unconfigured
  249. GLuint index_id; // 0 means, unconfigured
  250. // no support for the above, array in localmem.
  251. uint8_t *array_local;
  252. uint8_t *index_array_local;
  253. Vector<AABB> skeleton_bone_aabb;
  254. Vector<bool> skeleton_bone_used;
  255. //bool packed;
  256. struct MorphTarget {
  257. uint32_t configured_format;
  258. uint8_t *array;
  259. };
  260. MorphTarget* morph_targets_local;
  261. int morph_target_count;
  262. AABB aabb;
  263. int array_len;
  264. int index_array_len;
  265. int max_bone;
  266. float vertex_scale;
  267. float uv_scale;
  268. float uv2_scale;
  269. bool alpha_sort;
  270. VS::PrimitiveType primitive;
  271. uint32_t format;
  272. uint32_t configured_format;
  273. int stride;
  274. int local_stride;
  275. uint32_t morph_format;
  276. bool active;
  277. Point2 uv_min;
  278. Point2 uv_max;
  279. Surface() {
  280. array_len=0;
  281. local_stride=0;
  282. morph_format=0;
  283. type=GEOMETRY_SURFACE;
  284. primitive=VS::PRIMITIVE_POINTS;
  285. index_array_len=0;
  286. vertex_scale=1.0;
  287. uv_scale=1.0;
  288. uv2_scale=1.0;
  289. alpha_sort=false;
  290. format=0;
  291. stride=0;
  292. morph_targets_local=0;
  293. morph_target_count=0;
  294. array_local = index_array_local = 0;
  295. vertex_id = index_id = 0;
  296. active=false;
  297. //packed=false;
  298. }
  299. ~Surface() {
  300. }
  301. };
  302. struct Mesh {
  303. bool active;
  304. Vector<Surface*> surfaces;
  305. int morph_target_count;
  306. VS::MorphTargetMode morph_target_mode;
  307. AABB custom_aabb;
  308. mutable uint64_t last_pass;
  309. Mesh() {
  310. morph_target_mode=VS::MORPH_MODE_NORMALIZED;
  311. morph_target_count=0;
  312. last_pass=0;
  313. active=false;
  314. }
  315. };
  316. mutable RID_Owner<Mesh> mesh_owner;
  317. Error _surface_set_arrays(Surface *p_surface, uint8_t *p_mem,uint8_t *p_index_mem,const Array& p_arrays,bool p_main);
  318. struct MultiMesh;
  319. struct MultiMeshSurface : public Geometry {
  320. Surface *surface;
  321. MultiMeshSurface() { type=GEOMETRY_MULTISURFACE; }
  322. };
  323. struct MultiMesh : public GeometryOwner {
  324. struct Element {
  325. float matrix[16];
  326. uint8_t color[4];
  327. Element() {
  328. matrix[0]=1;
  329. matrix[1]=0;
  330. matrix[2]=0;
  331. matrix[3]=0;
  332. matrix[4]=0;
  333. matrix[5]=1;
  334. matrix[6]=0;
  335. matrix[7]=0;
  336. matrix[8]=0;
  337. matrix[9]=0;
  338. matrix[10]=1;
  339. matrix[11]=0;
  340. matrix[12]=0;
  341. matrix[13]=0;
  342. matrix[14]=0;
  343. matrix[15]=1;
  344. };
  345. };
  346. AABB aabb;
  347. RID mesh;
  348. int visible;
  349. //IDirect3DVertexBuffer9* instance_buffer;
  350. Vector<Element> elements;
  351. Vector<MultiMeshSurface> cache_surfaces;
  352. mutable uint64_t last_pass;
  353. GLuint tex_id;
  354. int tw;
  355. int th;
  356. SelfList<MultiMesh> dirty_list;
  357. MultiMesh() : dirty_list(this) {
  358. tw=1;
  359. th=1;
  360. tex_id=0;
  361. last_pass=0;
  362. visible = -1;
  363. }
  364. };
  365. mutable RID_Owner<MultiMesh> multimesh_owner;
  366. mutable SelfList<MultiMesh>::List _multimesh_dirty_list;
  367. struct Immediate : public Geometry {
  368. struct Chunk {
  369. RID texture;
  370. VS::PrimitiveType primitive;
  371. Vector<Vector3> vertices;
  372. Vector<Vector3> normals;
  373. Vector<Plane> tangents;
  374. Vector<Color> colors;
  375. Vector<Vector2> uvs;
  376. Vector<Vector2> uvs2;
  377. };
  378. List<Chunk> chunks;
  379. bool building;
  380. int mask;
  381. AABB aabb;
  382. Immediate() { type=GEOMETRY_IMMEDIATE; building=false;}
  383. };
  384. mutable RID_Owner<Immediate> immediate_owner;
  385. struct Particles : public Geometry {
  386. ParticleSystemSW data; // software particle system
  387. Particles() {
  388. type=GEOMETRY_PARTICLES;
  389. }
  390. };
  391. mutable RID_Owner<Particles> particles_owner;
  392. struct ParticlesInstance : public GeometryOwner {
  393. RID particles;
  394. ParticleSystemProcessSW particles_process;
  395. Transform transform;
  396. ParticlesInstance() { }
  397. };
  398. mutable RID_Owner<ParticlesInstance> particles_instance_owner;
  399. ParticleSystemDrawInfoSW particle_draw_info;
  400. struct Skeleton {
  401. struct Bone {
  402. float mtx[4][4]; //used
  403. Bone() {
  404. for(int i=0;i<4;i++) {
  405. for(int j=0;j<4;j++) {
  406. mtx[i][j]=(i==j)?1:0;
  407. }
  408. }
  409. }
  410. _ALWAYS_INLINE_ void transform_add_mul3(const float * p_src, float* r_dst, float p_weight) const {
  411. r_dst[0]+=((mtx[0][0]*p_src[0] ) + ( mtx[1][0]*p_src[1] ) + ( mtx[2][0]*p_src[2] ) + mtx[3][0])*p_weight;
  412. r_dst[1]+=((mtx[0][1]*p_src[0] ) + ( mtx[1][1]*p_src[1] ) + ( mtx[2][1]*p_src[2] ) + mtx[3][1])*p_weight;
  413. r_dst[2]+=((mtx[0][2]*p_src[0] ) + ( mtx[1][2]*p_src[1] ) + ( mtx[2][2]*p_src[2] ) + mtx[3][2])*p_weight;
  414. }
  415. _ALWAYS_INLINE_ void transform3_add_mul3(const float * p_src, float* r_dst, float p_weight) const {
  416. r_dst[0]+=((mtx[0][0]*p_src[0] ) + ( mtx[1][0]*p_src[1] ) + ( mtx[2][0]*p_src[2] ) )*p_weight;
  417. r_dst[1]+=((mtx[0][1]*p_src[0] ) + ( mtx[1][1]*p_src[1] ) + ( mtx[2][1]*p_src[2] ) )*p_weight;
  418. r_dst[2]+=((mtx[0][2]*p_src[0] ) + ( mtx[1][2]*p_src[1] ) + ( mtx[2][2]*p_src[2] ) )*p_weight;
  419. }
  420. _ALWAYS_INLINE_ AABB transform_aabb(const AABB& p_aabb) const {
  421. float vertices[8][3]={
  422. {p_aabb.pos.x+p_aabb.size.x, p_aabb.pos.y+p_aabb.size.y, p_aabb.pos.z+p_aabb.size.z},
  423. {p_aabb.pos.x+p_aabb.size.x, p_aabb.pos.y+p_aabb.size.y, p_aabb.pos.z},
  424. {p_aabb.pos.x+p_aabb.size.x, p_aabb.pos.y, p_aabb.pos.z+p_aabb.size.z},
  425. {p_aabb.pos.x+p_aabb.size.x, p_aabb.pos.y, p_aabb.pos.z},
  426. {p_aabb.pos.x, p_aabb.pos.y+p_aabb.size.y, p_aabb.pos.z+p_aabb.size.z},
  427. {p_aabb.pos.x, p_aabb.pos.y+p_aabb.size.y, p_aabb.pos.z},
  428. {p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z+p_aabb.size.z},
  429. {p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z}
  430. };
  431. AABB ret;
  432. for (int i=0;i<8;i++) {
  433. Vector3 xv(
  434. ((mtx[0][0]*vertices[i][0] ) + ( mtx[1][0]*vertices[i][1] ) + ( mtx[2][0]*vertices[i][2] ) + mtx[3][0] ),
  435. ((mtx[0][1]*vertices[i][0] ) + ( mtx[1][1]*vertices[i][1] ) + ( mtx[2][1]*vertices[i][2] ) + mtx[3][1] ),
  436. ((mtx[0][2]*vertices[i][0] ) + ( mtx[1][2]*vertices[i][1] ) + ( mtx[2][2]*vertices[i][2] ) + mtx[3][2] )
  437. );
  438. if (i==0)
  439. ret.pos=xv;
  440. else
  441. ret.expand_to(xv);
  442. }
  443. return ret;
  444. }
  445. };
  446. GLuint tex_id;
  447. float pixel_size; //for texture
  448. Vector<Bone> bones;
  449. SelfList<Skeleton> dirty_list;
  450. Skeleton() : dirty_list(this) { tex_id=0; pixel_size=1.0; }
  451. };
  452. mutable RID_Owner<Skeleton> skeleton_owner;
  453. mutable SelfList<Skeleton>::List _skeleton_dirty_list;
  454. template<bool USE_NORMAL, bool USE_TANGENT,bool INPLACE>
  455. void _skeleton_xform(const uint8_t * p_src_array, int p_src_stride, uint8_t * p_dst_array, int p_dst_stride, int p_elements,const uint8_t *p_src_bones, const uint8_t *p_src_weights, const Skeleton::Bone *p_bone_xforms);
  456. struct Light {
  457. VS::LightType type;
  458. float vars[VS::LIGHT_PARAM_MAX];
  459. Color colors[3];
  460. bool shadow_enabled;
  461. RID projector;
  462. bool volumetric_enabled;
  463. Color volumetric_color;
  464. VS::LightOmniShadowMode omni_shadow_mode;
  465. VS::LightDirectionalShadowMode directional_shadow_mode;
  466. float directional_shadow_param[3];
  467. Light() {
  468. vars[VS::LIGHT_PARAM_SPOT_ATTENUATION]=1;
  469. vars[VS::LIGHT_PARAM_SPOT_ANGLE]=45;
  470. vars[VS::LIGHT_PARAM_ATTENUATION]=1.0;
  471. vars[VS::LIGHT_PARAM_ENERGY]=1.0;
  472. vars[VS::LIGHT_PARAM_RADIUS]=1.0;
  473. vars[VS::LIGHT_PARAM_SHADOW_DARKENING]=0.0;
  474. vars[VS::LIGHT_PARAM_SHADOW_Z_OFFSET]=0.2;
  475. vars[VS::LIGHT_PARAM_SHADOW_Z_SLOPE_SCALE]=1.4;
  476. vars[VS::LIGHT_PARAM_SHADOW_ESM_MULTIPLIER]=60.0;
  477. vars[VS::LIGHT_PARAM_SHADOW_BLUR_PASSES]=1;
  478. colors[VS::LIGHT_COLOR_DIFFUSE]=Color(1,1,1);
  479. colors[VS::LIGHT_COLOR_SPECULAR]=Color(1,1,1);
  480. shadow_enabled=false;
  481. volumetric_enabled=false;
  482. directional_shadow_param[VS::LIGHT_DIRECTIONAL_SHADOW_PARAM_PSSM_SPLIT_WEIGHT]=0.5;
  483. directional_shadow_param[VS::LIGHT_DIRECTIONAL_SHADOW_PARAM_MAX_DISTANCE]=0;
  484. directional_shadow_param[VS::LIGHT_DIRECTIONAL_SHADOW_PARAM_PSSM_ZOFFSET_SCALE]=2.0;
  485. omni_shadow_mode=VS::LIGHT_OMNI_SHADOW_DEFAULT;
  486. directional_shadow_mode=VS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL;
  487. }
  488. };
  489. struct Environment {
  490. VS::EnvironmentBG bg_mode;
  491. Variant bg_param[VS::ENV_BG_PARAM_MAX];
  492. bool fx_enabled[VS::ENV_FX_MAX];
  493. Variant fx_param[VS::ENV_FX_PARAM_MAX];
  494. Environment() {
  495. bg_mode=VS::ENV_BG_DEFAULT_COLOR;
  496. bg_param[VS::ENV_BG_PARAM_COLOR]=Color(0,0,0);
  497. bg_param[VS::ENV_BG_PARAM_TEXTURE]=RID();
  498. bg_param[VS::ENV_BG_PARAM_CUBEMAP]=RID();
  499. bg_param[VS::ENV_BG_PARAM_ENERGY]=1.0;
  500. bg_param[VS::ENV_BG_PARAM_SCALE]=1.0;
  501. bg_param[VS::ENV_BG_PARAM_GLOW]=0.0;
  502. for(int i=0;i<VS::ENV_FX_MAX;i++)
  503. fx_enabled[i]=false;
  504. fx_param[VS::ENV_FX_PARAM_GLOW_BLUR_PASSES]=1;
  505. fx_param[VS::ENV_FX_PARAM_GLOW_BLUR_SCALE]=1.0;
  506. fx_param[VS::ENV_FX_PARAM_GLOW_BLUR_STRENGTH]=1.0;
  507. fx_param[VS::ENV_FX_PARAM_GLOW_BLUR_BLEND_MODE]=0;
  508. fx_param[VS::ENV_FX_PARAM_GLOW_BLOOM]=0.0;
  509. fx_param[VS::ENV_FX_PARAM_GLOW_BLOOM_TRESHOLD]=0.5;
  510. fx_param[VS::ENV_FX_PARAM_DOF_BLUR_PASSES]=1;
  511. fx_param[VS::ENV_FX_PARAM_DOF_BLUR_BEGIN]=100.0;
  512. fx_param[VS::ENV_FX_PARAM_DOF_BLUR_RANGE]=10.0;
  513. fx_param[VS::ENV_FX_PARAM_HDR_TONEMAPPER]=VS::ENV_FX_HDR_TONE_MAPPER_LINEAR;
  514. fx_param[VS::ENV_FX_PARAM_HDR_EXPOSURE]=0.4;
  515. fx_param[VS::ENV_FX_PARAM_HDR_WHITE]=1.0;
  516. fx_param[VS::ENV_FX_PARAM_HDR_GLOW_TRESHOLD]=0.95;
  517. fx_param[VS::ENV_FX_PARAM_HDR_GLOW_SCALE]=0.2;
  518. fx_param[VS::ENV_FX_PARAM_HDR_MIN_LUMINANCE]=0.4;
  519. fx_param[VS::ENV_FX_PARAM_HDR_MAX_LUMINANCE]=8.0;
  520. fx_param[VS::ENV_FX_PARAM_HDR_EXPOSURE_ADJUST_SPEED]=0.5;
  521. fx_param[VS::ENV_FX_PARAM_FOG_BEGIN]=100.0;
  522. fx_param[VS::ENV_FX_PARAM_FOG_ATTENUATION]=1.0;
  523. fx_param[VS::ENV_FX_PARAM_FOG_BEGIN_COLOR]=Color(0,0,0);
  524. fx_param[VS::ENV_FX_PARAM_FOG_END_COLOR]=Color(0,0,0);
  525. fx_param[VS::ENV_FX_PARAM_FOG_BG]=true;
  526. fx_param[VS::ENV_FX_PARAM_BCS_BRIGHTNESS]=1.0;
  527. fx_param[VS::ENV_FX_PARAM_BCS_CONTRAST]=1.0;
  528. fx_param[VS::ENV_FX_PARAM_BCS_SATURATION]=1.0;
  529. }
  530. };
  531. mutable RID_Owner<Environment> environment_owner;
  532. struct SampledLight {
  533. int w,h;
  534. GLuint texture;
  535. float multiplier;
  536. bool is_float;
  537. };
  538. mutable RID_Owner<SampledLight> sampled_light_owner;
  539. struct ViewportData {
  540. //1x1 fbo+texture for storing previous HDR value
  541. GLuint lum_fbo;
  542. GLuint lum_color;
  543. ViewportData() { lum_fbo=0; lum_color=0; }
  544. };
  545. mutable RID_Owner<ViewportData> viewport_data_owner;
  546. struct RenderTarget {
  547. Texture *texture_ptr;
  548. RID texture;
  549. GLuint fbo;
  550. GLuint color;
  551. GLuint depth;
  552. int width,height;
  553. uint64_t last_pass;
  554. };
  555. mutable RID_Owner<RenderTarget> render_target_owner;
  556. struct ShadowBuffer;
  557. struct LightInstance {
  558. struct SplitInfo {
  559. CameraMatrix camera;
  560. Transform transform;
  561. float near;
  562. float far;
  563. };
  564. RID light;
  565. Light *base;
  566. Transform transform;
  567. CameraMatrix projection;
  568. Transform custom_transform[4];
  569. CameraMatrix custom_projection[4];
  570. Vector3 light_vector;
  571. Vector3 spot_vector;
  572. float linear_att;
  573. uint64_t shadow_pass;
  574. uint64_t last_pass;
  575. uint16_t sort_key;
  576. Vector2 dp;
  577. CameraMatrix shadow_projection[4];
  578. float shadow_split[4];
  579. ShadowBuffer* near_shadow_buffer;
  580. void clear_shadow_buffers() {
  581. clear_near_shadow_buffers();
  582. }
  583. void clear_near_shadow_buffers() {
  584. if (near_shadow_buffer) {
  585. near_shadow_buffer->owner=NULL;
  586. near_shadow_buffer=NULL;
  587. }
  588. }
  589. LightInstance() { shadow_pass=0; last_pass=0; sort_key=0; near_shadow_buffer=NULL;}
  590. };
  591. mutable RID_Owner<Light> light_owner;
  592. mutable RID_Owner<LightInstance> light_instance_owner;
  593. LightInstance *light_instances[MAX_SCENE_LIGHTS];
  594. LightInstance *directional_lights[4];
  595. int light_instance_count;
  596. int directional_light_count;
  597. int last_light_id;
  598. bool current_depth_test;
  599. bool current_depth_mask;
  600. VS::MaterialBlendMode current_blend_mode;
  601. bool use_fast_texture_filter;
  602. bool fragment_lighting;
  603. RID shadow_material;
  604. Material *shadow_mat_ptr;
  605. int max_texture_units;
  606. GLuint base_framebuffer;
  607. GLuint gui_quad_buffer;
  608. struct RenderList {
  609. enum {
  610. MAX_ELEMENTS=4096,
  611. MAX_LIGHTS=4,
  612. SORT_FLAG_SKELETON=1,
  613. SORT_FLAG_INSTANCING=2,
  614. };
  615. struct Element {
  616. float depth;
  617. const InstanceData *instance;
  618. const Skeleton *skeleton;
  619. const Geometry *geometry;
  620. const Geometry *geometry_cmp;
  621. const Material *material;
  622. const GeometryOwner *owner;
  623. bool *additive_ptr;
  624. bool additive;
  625. bool mirror;
  626. union {
  627. #ifdef BIG_ENDIAN_ENABLED
  628. struct {
  629. uint8_t sort_flags;
  630. uint8_t light_type;
  631. uint16_t light;
  632. };
  633. #else
  634. struct {
  635. uint16_t light;
  636. uint8_t light_type;
  637. uint8_t sort_flags;
  638. };
  639. #endif
  640. uint32_t sort_key;
  641. };
  642. };
  643. Element _elements[MAX_ELEMENTS];
  644. Element *elements[MAX_ELEMENTS];
  645. int element_count;
  646. void clear() {
  647. element_count=0;
  648. }
  649. struct SortZ {
  650. _FORCE_INLINE_ bool operator()(const Element* A, const Element* B ) const {
  651. return A->depth > B->depth;
  652. }
  653. };
  654. void sort_z() {
  655. SortArray<Element*,SortZ> sorter;
  656. sorter.sort(elements,element_count);
  657. }
  658. struct SortMatGeom {
  659. _FORCE_INLINE_ bool operator()(const Element* A, const Element* B ) const {
  660. // TODO move to a single uint64 (one comparison)
  661. if (A->material->shader_cache == B->material->shader_cache) {
  662. if (A->material == B->material) {
  663. return A->geometry_cmp < B->geometry_cmp;
  664. } else {
  665. return (A->material < B->material);
  666. }
  667. } else {
  668. return A->material->shader_cache < B->material->shader_cache;
  669. }
  670. }
  671. };
  672. void sort_mat_geom() {
  673. SortArray<Element*,SortMatGeom> sorter;
  674. sorter.sort(elements,element_count);
  675. }
  676. struct SortMatLight {
  677. _FORCE_INLINE_ bool operator()(const Element* A, const Element* B ) const {
  678. if (A->geometry_cmp == B->geometry_cmp) {
  679. if (A->material == B->material) {
  680. return A->light<B->light;
  681. } else {
  682. return (A->material < B->material);
  683. }
  684. } else {
  685. return (A->geometry_cmp < B->geometry_cmp);
  686. }
  687. }
  688. };
  689. void sort_mat_light() {
  690. SortArray<Element*,SortMatLight> sorter;
  691. sorter.sort(elements,element_count);
  692. }
  693. struct SortMatLightType {
  694. _FORCE_INLINE_ bool operator()(const Element* A, const Element* B ) const {
  695. if (A->light_type == B->light_type) {
  696. if (A->material->shader_cache == B->material->shader_cache) {
  697. if (A->material == B->material) {
  698. return (A->geometry_cmp < B->geometry_cmp);
  699. } else {
  700. return (A->material < B->material);
  701. }
  702. } else {
  703. return (A->material->shader_cache < B->material->shader_cache);
  704. }
  705. } else {
  706. return A->light_type < B->light_type;
  707. }
  708. }
  709. };
  710. void sort_mat_light_type() {
  711. SortArray<Element*,SortMatLightType> sorter;
  712. sorter.sort(elements,element_count);
  713. }
  714. struct SortMatLightTypeFlags {
  715. _FORCE_INLINE_ bool operator()(const Element* A, const Element* B ) const {
  716. if (A->sort_key == B->sort_key) {
  717. if (A->material->shader_cache == B->material->shader_cache) {
  718. if (A->material == B->material) {
  719. return (A->geometry_cmp < B->geometry_cmp);
  720. } else {
  721. return (A->material < B->material);
  722. }
  723. } else {
  724. return (A->material->shader_cache < B->material->shader_cache);
  725. }
  726. } else {
  727. return A->sort_key < B->sort_key; //one is null and one is not
  728. }
  729. }
  730. };
  731. void sort_mat_light_type_flags() {
  732. SortArray<Element*,SortMatLightTypeFlags> sorter;
  733. sorter.sort(elements,element_count);
  734. }
  735. _FORCE_INLINE_ Element* add_element() {
  736. if (element_count>MAX_ELEMENTS)
  737. return NULL;
  738. elements[element_count]=&_elements[element_count];
  739. return elements[element_count++];
  740. }
  741. RenderList() {
  742. element_count = 0;
  743. for (int i=0;i<MAX_ELEMENTS;i++)
  744. elements[i]=&_elements[i]; // assign elements
  745. }
  746. };
  747. RenderList opaque_render_list;
  748. RenderList alpha_render_list;
  749. RID default_material;
  750. CameraMatrix camera_projection;
  751. Transform camera_transform;
  752. Transform camera_transform_inverse;
  753. float camera_z_near;
  754. float camera_z_far;
  755. Size2 camera_vp_size;
  756. Set<String> extensions;
  757. bool texscreen_copied;
  758. bool texscreen_used;
  759. Plane camera_plane;
  760. void _add_geometry( const Geometry* p_geometry, const InstanceData *p_instance, const Geometry *p_geometry_cmp, const GeometryOwner *p_owner);
  761. void _render_list_forward(RenderList *p_render_list,const Transform& p_view_transform,const Transform& p_view_transform_inverse, const CameraMatrix& p_projection,bool p_reverse_cull=false,bool p_fragment_light=false,bool p_alpha_pass=false);
  762. //void _setup_light(LightInstance* p_instance, int p_idx);
  763. void _setup_light(uint16_t p_light);
  764. _FORCE_INLINE_ void _setup_shader_params(const Material *p_material);
  765. bool _setup_material(const Geometry *p_geometry, const Material *p_material, bool p_no_const_light, bool p_opaque_pass);
  766. void _setup_skeleton(const Skeleton *p_skeleton);
  767. Error _setup_geometry(const Geometry *p_geometry, const Material* p_material,const Skeleton *p_skeleton, const float *p_morphs);
  768. void _render(const Geometry *p_geometry,const Material *p_material, const Skeleton* p_skeleton, const GeometryOwner *p_owner,const Transform& p_xform);
  769. /***********/
  770. /* SHADOWS */
  771. /***********/
  772. struct ShadowBuffer {
  773. int size;
  774. GLuint fbo;
  775. GLuint rbo;
  776. GLuint depth;
  777. GLuint rgba; //for older devices
  778. #if 0
  779. GLuint fbo_blur;
  780. GLuint rbo_blur;
  781. GLuint blur;
  782. #endif
  783. LightInstance *owner;
  784. bool init(int p_size,bool p_use_depth);
  785. ShadowBuffer() { size=0; depth=0; owner=NULL; }
  786. };
  787. Vector<ShadowBuffer> near_shadow_buffers;
  788. ShadowBuffer blur_shadow_buffer;
  789. Vector<ShadowBuffer> far_shadow_buffers;
  790. LightInstance *shadow;
  791. int shadow_pass;
  792. float shadow_near_far_split_size_ratio;
  793. bool _allocate_shadow_buffers(LightInstance *p_instance, Vector<ShadowBuffer>& p_buffers);
  794. void _debug_draw_shadow(GLuint tex, const Rect2& p_rect);
  795. void _debug_draw_shadows_type(Vector<ShadowBuffer>& p_shadows,Point2& ofs);
  796. void _debug_shadows();
  797. void _debug_luminances();
  798. void _debug_samplers();
  799. /***********/
  800. /* FBOs */
  801. /***********/
  802. struct FrameBuffer {
  803. GLuint fbo;
  804. GLuint color;
  805. GLuint depth;
  806. int width,height;
  807. int scale;
  808. bool active;
  809. int blur_size;
  810. struct Blur {
  811. GLuint fbo;
  812. GLuint color;
  813. Blur() { fbo=0; color=0; }
  814. } blur[3];
  815. struct Luminance {
  816. int size;
  817. GLuint fbo;
  818. GLuint color;
  819. Luminance() { fbo=0; color=0; size=0;}
  820. };
  821. Vector<Luminance> luminance;
  822. GLuint sample_fbo;
  823. GLuint sample_color;
  824. FrameBuffer() {
  825. blur_size=0;
  826. }
  827. } framebuffer;
  828. void _update_framebuffer();
  829. void _process_glow_and_bloom();
  830. //void _update_blur_buffer();
  831. /*********/
  832. /* FRAME */
  833. /*********/
  834. struct _Rinfo {
  835. int texture_mem;
  836. int vertex_count;
  837. int object_count;
  838. int mat_change_count;
  839. int surface_count;
  840. int shader_change_count;
  841. int ci_draw_commands;
  842. int draw_calls;
  843. } _rinfo;
  844. RenderTarget *current_rt;
  845. bool current_rt_transparent;
  846. bool current_rt_vflip;
  847. ViewportData *current_vd;
  848. GLuint white_tex;
  849. RID canvas_tex;
  850. float canvas_opacity;
  851. _FORCE_INLINE_ Texture* _bind_canvas_texture(const RID& p_texture);
  852. VS::MaterialBlendMode canvas_blend_mode;
  853. int _setup_geometry_vinfo;
  854. bool pack_arrays;
  855. bool keep_copies;
  856. bool use_reload_hooks;
  857. bool cull_front;
  858. bool lights_use_shadow;
  859. _FORCE_INLINE_ void _set_cull(bool p_front,bool p_reverse_cull=false);
  860. _FORCE_INLINE_ Color _convert_color(const Color& p_color);
  861. void _process_glow_bloom();
  862. void _process_hdr();
  863. void _draw_tex_bg();
  864. Size2 window_size;
  865. VS::ViewportRect viewport;
  866. double last_time;
  867. double time_delta;
  868. uint64_t frame;
  869. uint64_t scene_pass;
  870. bool draw_next_frame;
  871. Environment *current_env;
  872. VS::ScenarioDebugMode current_debug;
  873. RID overdraw_material;
  874. mutable MaterialShaderGLES2 material_shader;
  875. CanvasShaderGLES2 canvas_shader;
  876. BlurShaderGLES2 blur_shader;
  877. CopyShaderGLES2 copy_shader;
  878. mutable ShaderCompilerGLES2 shader_precompiler;
  879. void _draw_primitive(int p_points, const Vector3 *p_vertices, const Vector3 *p_normals, const Color* p_colors, const Vector3 *p_uvs,const Plane *p_tangents=NULL,int p_instanced=1);
  880. _FORCE_INLINE_ void _draw_gui_primitive(int p_points, const Vector2 *p_vertices, const Color* p_colors, const Vector2 *p_uvs);
  881. _FORCE_INLINE_ void _draw_gui_primitive2(int p_points, const Vector2 *p_vertices, const Color* p_colors, const Vector2 *p_uvs, const Vector2 *p_uvs2);
  882. void _draw_textured_quad(const Rect2& p_rect, const Rect2& p_src_region, const Size2& p_tex_size,bool p_h_flip=false, bool p_v_flip=false );
  883. void _draw_quad(const Rect2& p_rect);
  884. void _copy_screen_quad();
  885. void _copy_to_texscreen();
  886. Vector3 chunk_vertex;
  887. Vector3 chunk_normal;
  888. Plane chunk_tangent;
  889. Color chunk_color;
  890. Vector2 chunk_uv;
  891. Vector2 chunk_uv2;
  892. GLuint tc0_id_cache;
  893. GLuint tc0_idx;
  894. public:
  895. /* TEXTURE API */
  896. virtual RID texture_create();
  897. virtual void texture_allocate(RID p_texture,int p_width, int p_height,Image::Format p_format,uint32_t p_flags=VS::TEXTURE_FLAGS_DEFAULT);
  898. virtual void texture_set_data(RID p_texture,const Image& p_image,VS::CubeMapSide p_cube_side=VS::CUBEMAP_LEFT);
  899. virtual Image texture_get_data(RID p_texture,VS::CubeMapSide p_cube_side=VS::CUBEMAP_LEFT) const;
  900. virtual void texture_set_flags(RID p_texture,uint32_t p_flags);
  901. virtual uint32_t texture_get_flags(RID p_texture) const;
  902. virtual Image::Format texture_get_format(RID p_texture) const;
  903. virtual uint32_t texture_get_width(RID p_texture) const;
  904. virtual uint32_t texture_get_height(RID p_texture) const;
  905. virtual bool texture_has_alpha(RID p_texture) const;
  906. virtual void texture_set_size_override(RID p_texture,int p_width, int p_height);
  907. virtual void texture_set_reload_hook(RID p_texture,ObjectID p_owner,const StringName& p_function) const;
  908. GLuint _texture_get_name(RID p_tex);
  909. /* SHADER API */
  910. virtual RID shader_create(VS::ShaderMode p_mode=VS::SHADER_MATERIAL);
  911. virtual void shader_set_mode(RID p_shader,VS::ShaderMode p_mode);
  912. virtual VS::ShaderMode shader_get_mode(RID p_shader) const;
  913. virtual void shader_set_code(RID p_shader, const String& p_vertex, const String& p_fragment,const String& p_light,int p_vertex_ofs=0,int p_fragment_ofs=0,int p_light_ofs=0);
  914. virtual String shader_get_fragment_code(RID p_shader) const;
  915. virtual String shader_get_vertex_code(RID p_shader) const;
  916. virtual String shader_get_light_code(RID p_shader) const;
  917. virtual void shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const;
  918. virtual void shader_set_default_texture_param(RID p_shader, const StringName& p_name, RID p_texture);
  919. virtual RID shader_get_default_texture_param(RID p_shader, const StringName& p_name) const;
  920. /* COMMON MATERIAL API */
  921. virtual RID material_create();
  922. virtual void material_set_shader(RID p_shader_material, RID p_shader);
  923. virtual RID material_get_shader(RID p_shader_material) const;
  924. virtual void material_set_param(RID p_material, const StringName& p_param, const Variant& p_value);
  925. virtual Variant material_get_param(RID p_material, const StringName& p_param) const;
  926. virtual void material_set_flag(RID p_material, VS::MaterialFlag p_flag,bool p_enabled);
  927. virtual bool material_get_flag(RID p_material,VS::MaterialFlag p_flag) const;
  928. virtual void material_set_depth_draw_mode(RID p_material, VS::MaterialDepthDrawMode p_mode);
  929. virtual VS::MaterialDepthDrawMode material_get_depth_draw_mode(RID p_material) const;
  930. virtual void material_set_blend_mode(RID p_material,VS::MaterialBlendMode p_mode);
  931. virtual VS::MaterialBlendMode material_get_blend_mode(RID p_material) const;
  932. virtual void material_set_line_width(RID p_material,float p_line_width);
  933. virtual float material_get_line_width(RID p_material) const;
  934. /* MESH API */
  935. virtual RID mesh_create();
  936. virtual void mesh_add_surface(RID p_mesh,VS::PrimitiveType p_primitive,const Array& p_arrays,const Array& p_blend_shapes=Array(),bool p_alpha_sort=false);
  937. virtual Array mesh_get_surface_arrays(RID p_mesh,int p_surface) const;
  938. virtual Array mesh_get_surface_morph_arrays(RID p_mesh,int p_surface) const;
  939. virtual void mesh_add_custom_surface(RID p_mesh,const Variant& p_dat);
  940. virtual void mesh_set_morph_target_count(RID p_mesh,int p_amount);
  941. virtual int mesh_get_morph_target_count(RID p_mesh) const;
  942. virtual void mesh_set_morph_target_mode(RID p_mesh,VS::MorphTargetMode p_mode);
  943. virtual VS::MorphTargetMode mesh_get_morph_target_mode(RID p_mesh) const;
  944. virtual void mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material,bool p_owned=false);
  945. virtual RID mesh_surface_get_material(RID p_mesh, int p_surface) const;
  946. virtual int mesh_surface_get_array_len(RID p_mesh, int p_surface) const;
  947. virtual int mesh_surface_get_array_index_len(RID p_mesh, int p_surface) const;
  948. virtual uint32_t mesh_surface_get_format(RID p_mesh, int p_surface) const;
  949. virtual VS::PrimitiveType mesh_surface_get_primitive_type(RID p_mesh, int p_surface) const;
  950. virtual void mesh_remove_surface(RID p_mesh,int p_index);
  951. virtual int mesh_get_surface_count(RID p_mesh) const;
  952. virtual AABB mesh_get_aabb(RID p_mesh,RID p_skeleton=RID()) const;
  953. virtual void mesh_set_custom_aabb(RID p_mesh,const AABB& p_aabb);
  954. virtual AABB mesh_get_custom_aabb(RID p_mesh) const;
  955. /* MULTIMESH API */
  956. virtual RID multimesh_create();
  957. virtual void multimesh_set_instance_count(RID p_multimesh,int p_count);
  958. virtual int multimesh_get_instance_count(RID p_multimesh) const;
  959. virtual void multimesh_set_mesh(RID p_multimesh,RID p_mesh);
  960. virtual void multimesh_set_aabb(RID p_multimesh,const AABB& p_aabb);
  961. virtual void multimesh_instance_set_transform(RID p_multimesh,int p_index,const Transform& p_transform);
  962. virtual void multimesh_instance_set_color(RID p_multimesh,int p_index,const Color& p_color);
  963. virtual RID multimesh_get_mesh(RID p_multimesh) const;
  964. virtual AABB multimesh_get_aabb(RID p_multimesh) const;;
  965. virtual Transform multimesh_instance_get_transform(RID p_multimesh,int p_index) const;
  966. virtual Color multimesh_instance_get_color(RID p_multimesh,int p_index) const;
  967. virtual void multimesh_set_visible_instances(RID p_multimesh,int p_visible);
  968. virtual int multimesh_get_visible_instances(RID p_multimesh) const;
  969. /* IMMEDIATE API */
  970. virtual RID immediate_create();
  971. virtual void immediate_begin(RID p_immediate,VS::PrimitiveType p_rimitive,RID p_texture=RID());
  972. virtual void immediate_vertex(RID p_immediate,const Vector3& p_vertex);
  973. virtual void immediate_normal(RID p_immediate,const Vector3& p_normal);
  974. virtual void immediate_tangent(RID p_immediate,const Plane& p_tangent);
  975. virtual void immediate_color(RID p_immediate,const Color& p_color);
  976. virtual void immediate_uv(RID p_immediate,const Vector2& tex_uv);
  977. virtual void immediate_uv2(RID p_immediate,const Vector2& tex_uv);
  978. virtual void immediate_end(RID p_immediate);
  979. virtual void immediate_clear(RID p_immediate);
  980. virtual AABB immediate_get_aabb(RID p_immediate) const;
  981. virtual void immediate_set_material(RID p_immediate,RID p_material);
  982. virtual RID immediate_get_material(RID p_immediate) const;
  983. /* PARTICLES API */
  984. virtual RID particles_create();
  985. virtual void particles_set_amount(RID p_particles, int p_amount);
  986. virtual int particles_get_amount(RID p_particles) const;
  987. virtual void particles_set_emitting(RID p_particles, bool p_emitting);
  988. virtual bool particles_is_emitting(RID p_particles) const;
  989. virtual void particles_set_visibility_aabb(RID p_particles, const AABB& p_visibility);
  990. virtual AABB particles_get_visibility_aabb(RID p_particles) const;
  991. virtual void particles_set_emission_half_extents(RID p_particles, const Vector3& p_half_extents);
  992. virtual Vector3 particles_get_emission_half_extents(RID p_particles) const;
  993. virtual void particles_set_emission_base_velocity(RID p_particles, const Vector3& p_base_velocity);
  994. virtual Vector3 particles_get_emission_base_velocity(RID p_particles) const;
  995. virtual void particles_set_emission_points(RID p_particles, const DVector<Vector3>& p_points);
  996. virtual DVector<Vector3> particles_get_emission_points(RID p_particles) const;
  997. virtual void particles_set_gravity_normal(RID p_particles, const Vector3& p_normal);
  998. virtual Vector3 particles_get_gravity_normal(RID p_particles) const;
  999. virtual void particles_set_variable(RID p_particles, VS::ParticleVariable p_variable,float p_value);
  1000. virtual float particles_get_variable(RID p_particles, VS::ParticleVariable p_variable) const;
  1001. virtual void particles_set_randomness(RID p_particles, VS::ParticleVariable p_variable,float p_randomness);
  1002. virtual float particles_get_randomness(RID p_particles, VS::ParticleVariable p_variable) const;
  1003. virtual void particles_set_color_phase_pos(RID p_particles, int p_phase, float p_pos);
  1004. virtual float particles_get_color_phase_pos(RID p_particles, int p_phase) const;
  1005. virtual void particles_set_color_phases(RID p_particles, int p_phases);
  1006. virtual int particles_get_color_phases(RID p_particles) const;
  1007. virtual void particles_set_color_phase_color(RID p_particles, int p_phase, const Color& p_color);
  1008. virtual Color particles_get_color_phase_color(RID p_particles, int p_phase) const;
  1009. virtual void particles_set_attractors(RID p_particles, int p_attractors);
  1010. virtual int particles_get_attractors(RID p_particles) const;
  1011. virtual void particles_set_attractor_pos(RID p_particles, int p_attractor, const Vector3& p_pos);
  1012. virtual Vector3 particles_get_attractor_pos(RID p_particles,int p_attractor) const;
  1013. virtual void particles_set_attractor_strength(RID p_particles, int p_attractor, float p_force);
  1014. virtual float particles_get_attractor_strength(RID p_particles,int p_attractor) const;
  1015. virtual void particles_set_material(RID p_particles, RID p_material,bool p_owned=false);
  1016. virtual RID particles_get_material(RID p_particles) const;
  1017. virtual AABB particles_get_aabb(RID p_particles) const;
  1018. virtual void particles_set_height_from_velocity(RID p_particles, bool p_enable);
  1019. virtual bool particles_has_height_from_velocity(RID p_particles) const;
  1020. virtual void particles_set_use_local_coordinates(RID p_particles, bool p_enable);
  1021. virtual bool particles_is_using_local_coordinates(RID p_particles) const;
  1022. /* SKELETON API */
  1023. virtual RID skeleton_create();
  1024. virtual void skeleton_resize(RID p_skeleton,int p_bones);
  1025. virtual int skeleton_get_bone_count(RID p_skeleton) const;
  1026. virtual void skeleton_bone_set_transform(RID p_skeleton,int p_bone, const Transform& p_transform);
  1027. virtual Transform skeleton_bone_get_transform(RID p_skeleton,int p_bone);
  1028. /* LIGHT API */
  1029. virtual RID light_create(VS::LightType p_type);
  1030. virtual VS::LightType light_get_type(RID p_light) const;
  1031. virtual void light_set_color(RID p_light,VS::LightColor p_type, const Color& p_color);
  1032. virtual Color light_get_color(RID p_light,VS::LightColor p_type) const;
  1033. virtual void light_set_shadow(RID p_light,bool p_enabled);
  1034. virtual bool light_has_shadow(RID p_light) const;
  1035. virtual void light_set_volumetric(RID p_light,bool p_enabled);
  1036. virtual bool light_is_volumetric(RID p_light) const;
  1037. virtual void light_set_projector(RID p_light,RID p_texture);
  1038. virtual RID light_get_projector(RID p_light) const;
  1039. virtual void light_set_var(RID p_light, VS::LightParam p_var, float p_value);
  1040. virtual float light_get_var(RID p_light, VS::LightParam p_var) const;
  1041. virtual void light_set_operator(RID p_light,VS::LightOp p_op);
  1042. virtual VS::LightOp light_get_operator(RID p_light) const;
  1043. virtual void light_omni_set_shadow_mode(RID p_light,VS::LightOmniShadowMode p_mode);
  1044. virtual VS::LightOmniShadowMode light_omni_get_shadow_mode(RID p_light) const;
  1045. virtual void light_directional_set_shadow_mode(RID p_light,VS::LightDirectionalShadowMode p_mode);
  1046. virtual VS::LightDirectionalShadowMode light_directional_get_shadow_mode(RID p_light) const;
  1047. virtual void light_directional_set_shadow_param(RID p_light,VS::LightDirectionalShadowParam p_param, float p_value);
  1048. virtual float light_directional_get_shadow_param(RID p_light,VS::LightDirectionalShadowParam p_param) const;
  1049. virtual AABB light_get_aabb(RID p_poly) const;
  1050. virtual RID light_instance_create(RID p_light);
  1051. virtual void light_instance_set_transform(RID p_light_instance,const Transform& p_transform);
  1052. virtual ShadowType light_instance_get_shadow_type(RID p_light_instance,bool p_far=false) const;
  1053. virtual int light_instance_get_shadow_passes(RID p_light_instance) const;
  1054. virtual bool light_instance_get_pssm_shadow_overlap(RID p_light_instance) const;
  1055. virtual void light_instance_set_shadow_transform(RID p_light_instance, int p_index, const CameraMatrix& p_camera, const Transform& p_transform, float p_split_near=0,float p_split_far=0);
  1056. virtual int light_instance_get_shadow_size(RID p_light_instance, int p_index=0) const;
  1057. virtual void shadow_clear_near();
  1058. virtual bool shadow_allocate_near(RID p_light);
  1059. virtual bool shadow_allocate_far(RID p_light);
  1060. /* SHADOW */
  1061. virtual RID particles_instance_create(RID p_particles);
  1062. virtual void particles_instance_set_transform(RID p_particles_instance,const Transform& p_transform);
  1063. /* VIEWPORT */
  1064. virtual RID viewport_data_create();
  1065. virtual RID render_target_create();
  1066. virtual void render_target_set_size(RID p_render_target, int p_width, int p_height);
  1067. virtual RID render_target_get_texture(RID p_render_target) const;
  1068. virtual bool render_target_renedered_in_frame(RID p_render_target);
  1069. /* RENDER API */
  1070. /* all calls (inside begin/end shadow) are always warranted to be in the following order: */
  1071. virtual void begin_frame();
  1072. virtual void set_viewport(const VS::ViewportRect& p_viewport);
  1073. virtual void set_render_target(RID p_render_target,bool p_transparent_bg=false,bool p_vflip=false);
  1074. virtual void clear_viewport(const Color& p_color);
  1075. virtual void capture_viewport(Image* r_capture);
  1076. virtual void begin_scene(RID p_viewport_data,RID p_env,VS::ScenarioDebugMode p_debug);
  1077. virtual void begin_shadow_map( RID p_light_instance, int p_shadow_pass );
  1078. virtual void set_camera(const Transform& p_world,const CameraMatrix& p_projection);
  1079. virtual void add_light( RID p_light_instance ); ///< all "add_light" calls happen before add_geometry calls
  1080. typedef Map<StringName,Variant> ParamOverrideMap;
  1081. virtual void add_mesh( const RID& p_mesh, const InstanceData *p_data);
  1082. virtual void add_multimesh( const RID& p_multimesh, const InstanceData *p_data);
  1083. virtual void add_immediate( const RID& p_immediate, const InstanceData *p_data);
  1084. virtual void add_particles( const RID& p_particle_instance, const InstanceData *p_data);
  1085. virtual void end_scene();
  1086. virtual void end_shadow_map();
  1087. virtual void end_frame();
  1088. /* CANVAS API */
  1089. virtual void canvas_begin();
  1090. virtual void canvas_disable_blending();
  1091. virtual void canvas_set_opacity(float p_opacity);
  1092. virtual void canvas_set_blend_mode(VS::MaterialBlendMode p_mode);
  1093. virtual void canvas_begin_rect(const Matrix32& p_transform);
  1094. virtual void canvas_set_clip(bool p_clip, const Rect2& p_rect);
  1095. virtual void canvas_end_rect();
  1096. virtual void canvas_draw_line(const Point2& p_from, const Point2& p_to,const Color& p_color,float p_width);
  1097. virtual void canvas_draw_rect(const Rect2& p_rect, int p_flags, const Rect2& p_source,RID p_texture,const Color& p_modulate);
  1098. virtual void canvas_draw_style_box(const Rect2& p_rect, RID p_texture,const float *p_margins, bool p_draw_center=true,const Color& p_modulate=Color(1,1,1));
  1099. virtual void canvas_draw_primitive(const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs, RID p_texture,float p_width);
  1100. virtual void canvas_draw_polygon(int p_vertex_count, const int* p_indices, const Vector2* p_vertices, const Vector2* p_uvs, const Color* p_colors,const RID& p_texture,bool p_singlecolor);
  1101. virtual void canvas_set_transform(const Matrix32& p_transform);
  1102. /* ENVIRONMENT */
  1103. virtual RID environment_create();
  1104. virtual void environment_set_background(RID p_env,VS::EnvironmentBG p_bg);
  1105. virtual VS::EnvironmentBG environment_get_background(RID p_env) const;
  1106. virtual void environment_set_background_param(RID p_env,VS::EnvironmentBGParam p_param, const Variant& p_value);
  1107. virtual Variant environment_get_background_param(RID p_env,VS::EnvironmentBGParam p_param) const;
  1108. virtual void environment_set_enable_fx(RID p_env,VS::EnvironmentFx p_effect,bool p_enabled);
  1109. virtual bool environment_is_fx_enabled(RID p_env,VS::EnvironmentFx p_effect) const;
  1110. virtual void environment_fx_set_param(RID p_env,VS::EnvironmentFxParam p_param,const Variant& p_value);
  1111. virtual Variant environment_fx_get_param(RID p_env,VS::EnvironmentFxParam p_param) const;
  1112. /* SAMPLED LIGHT */
  1113. virtual RID sampled_light_dp_create(int p_width,int p_height);
  1114. virtual void sampled_light_dp_update(RID p_sampled_light, const Color *p_data, float p_multiplier);
  1115. /*MISC*/
  1116. virtual bool is_texture(const RID& p_rid) const;
  1117. virtual bool is_material(const RID& p_rid) const;
  1118. virtual bool is_mesh(const RID& p_rid) const;
  1119. virtual bool is_immediate(const RID& p_rid) const;
  1120. virtual bool is_multimesh(const RID& p_rid) const;
  1121. virtual bool is_particles(const RID &p_beam) const;
  1122. virtual bool is_light(const RID& p_rid) const;
  1123. virtual bool is_light_instance(const RID& p_rid) const;
  1124. virtual bool is_particles_instance(const RID& p_rid) const;
  1125. virtual bool is_skeleton(const RID& p_rid) const;
  1126. virtual bool is_environment(const RID& p_rid) const;
  1127. virtual bool is_shader(const RID& p_rid) const;
  1128. virtual void free(const RID& p_rid);
  1129. virtual void init();
  1130. virtual void finish();
  1131. virtual int get_render_info(VS::RenderInfo p_info);
  1132. void set_base_framebuffer(GLuint p_id, Vector2 p_size = Vector2(0, 0));
  1133. virtual void flush_frame(); //not necesary in most cases
  1134. void set_extensions(const char *p_strings);
  1135. virtual bool needs_to_draw_next_frame() const;
  1136. void set_use_framebuffers(bool p_use);
  1137. void reload_vram();
  1138. virtual bool has_feature(VS::Features p_feature) const;
  1139. static RasterizerGLES2* get_singleton();
  1140. RasterizerGLES2(bool p_compress_arrays=false,bool p_keep_ram_copy=true,bool p_default_fragment_lighting=true,bool p_use_reload_hooks=false);
  1141. virtual ~RasterizerGLES2();
  1142. };
  1143. #endif
  1144. #endif