rasterizer_canvas_base_gles3.cpp 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273
  1. /**************************************************************************/
  2. /* rasterizer_canvas_base_gles3.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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. #include "rasterizer_canvas_base_gles3.h"
  31. #include "core/os/os.h"
  32. #include "core/project_settings.h"
  33. #include "drivers/gles_common/rasterizer_asserts.h"
  34. #include "rasterizer_scene_gles3.h"
  35. #include "servers/visual/visual_server_raster.h"
  36. #ifndef GLES_OVER_GL
  37. #define glClearDepth glClearDepthf
  38. #endif
  39. static _FORCE_INLINE_ void store_transform2d(const Transform2D &p_mtx, float *p_array) {
  40. p_array[0] = p_mtx.elements[0][0];
  41. p_array[1] = p_mtx.elements[0][1];
  42. p_array[2] = 0;
  43. p_array[3] = 0;
  44. p_array[4] = p_mtx.elements[1][0];
  45. p_array[5] = p_mtx.elements[1][1];
  46. p_array[6] = 0;
  47. p_array[7] = 0;
  48. p_array[8] = 0;
  49. p_array[9] = 0;
  50. p_array[10] = 1;
  51. p_array[11] = 0;
  52. p_array[12] = p_mtx.elements[2][0];
  53. p_array[13] = p_mtx.elements[2][1];
  54. p_array[14] = 0;
  55. p_array[15] = 1;
  56. }
  57. static _FORCE_INLINE_ void store_transform(const Transform &p_mtx, float *p_array) {
  58. p_array[0] = p_mtx.basis.elements[0][0];
  59. p_array[1] = p_mtx.basis.elements[1][0];
  60. p_array[2] = p_mtx.basis.elements[2][0];
  61. p_array[3] = 0;
  62. p_array[4] = p_mtx.basis.elements[0][1];
  63. p_array[5] = p_mtx.basis.elements[1][1];
  64. p_array[6] = p_mtx.basis.elements[2][1];
  65. p_array[7] = 0;
  66. p_array[8] = p_mtx.basis.elements[0][2];
  67. p_array[9] = p_mtx.basis.elements[1][2];
  68. p_array[10] = p_mtx.basis.elements[2][2];
  69. p_array[11] = 0;
  70. p_array[12] = p_mtx.origin.x;
  71. p_array[13] = p_mtx.origin.y;
  72. p_array[14] = p_mtx.origin.z;
  73. p_array[15] = 1;
  74. }
  75. static _FORCE_INLINE_ void store_camera(const CameraMatrix &p_mtx, float *p_array) {
  76. for (int i = 0; i < 4; i++) {
  77. for (int j = 0; j < 4; j++) {
  78. p_array[i * 4 + j] = p_mtx.matrix[i][j];
  79. }
  80. }
  81. }
  82. RID RasterizerCanvasBaseGLES3::light_internal_create() {
  83. LightInternal *li = memnew(LightInternal);
  84. glGenBuffers(1, &li->ubo);
  85. glBindBuffer(GL_UNIFORM_BUFFER, li->ubo);
  86. glBufferData(GL_UNIFORM_BUFFER, sizeof(LightInternal::UBOData), nullptr, GL_DYNAMIC_DRAW);
  87. glBindBuffer(GL_UNIFORM_BUFFER, 0);
  88. return light_internal_owner.make_rid(li);
  89. }
  90. void RasterizerCanvasBaseGLES3::light_internal_update(RID p_rid, Light *p_light) {
  91. LightInternal *li = light_internal_owner.getornull(p_rid);
  92. ERR_FAIL_COND(!li);
  93. store_transform2d(p_light->light_shader_xform, li->ubo_data.light_matrix);
  94. store_transform2d(p_light->xform_cache.affine_inverse(), li->ubo_data.local_matrix);
  95. store_camera(p_light->shadow_matrix_cache, li->ubo_data.shadow_matrix);
  96. for (int i = 0; i < 4; i++) {
  97. li->ubo_data.color[i] = p_light->color[i] * p_light->energy;
  98. li->ubo_data.shadow_color[i] = p_light->shadow_color[i];
  99. }
  100. li->ubo_data.light_pos[0] = p_light->light_shader_pos.x;
  101. li->ubo_data.light_pos[1] = p_light->light_shader_pos.y;
  102. li->ubo_data.shadowpixel_size = (1.0 / p_light->shadow_buffer_size) * (1.0 + p_light->shadow_smooth);
  103. li->ubo_data.light_outside_alpha = p_light->mode == VS::CANVAS_LIGHT_MODE_MASK ? 1.0 : 0.0;
  104. li->ubo_data.light_height = p_light->height;
  105. if (p_light->radius_cache == 0) {
  106. li->ubo_data.shadow_gradient = 0;
  107. } else {
  108. li->ubo_data.shadow_gradient = p_light->shadow_gradient_length / (p_light->radius_cache * 1.1);
  109. }
  110. li->ubo_data.shadow_distance_mult = (p_light->radius_cache * 1.1);
  111. glBindBuffer(GL_UNIFORM_BUFFER, li->ubo);
  112. glBufferData(GL_UNIFORM_BUFFER, sizeof(LightInternal::UBOData), &li->ubo_data, GL_DYNAMIC_DRAW);
  113. glBindBuffer(GL_UNIFORM_BUFFER, 0);
  114. }
  115. void RasterizerCanvasBaseGLES3::light_internal_free(RID p_rid) {
  116. LightInternal *li = light_internal_owner.getornull(p_rid);
  117. ERR_FAIL_COND(!li);
  118. glDeleteBuffers(1, &li->ubo);
  119. light_internal_owner.free(p_rid);
  120. memdelete(li);
  121. }
  122. void RasterizerCanvasBaseGLES3::canvas_begin() {
  123. if (storage->frame.current_rt && storage->frame.clear_request) {
  124. // a clear request may be pending, so do it
  125. bool transparent = storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT];
  126. glClearColor(storage->frame.clear_request_color.r,
  127. storage->frame.clear_request_color.g,
  128. storage->frame.clear_request_color.b,
  129. transparent ? storage->frame.clear_request_color.a : 1.0);
  130. glClear(GL_COLOR_BUFFER_BIT);
  131. storage->frame.clear_request = false;
  132. glColorMask(1, 1, 1, transparent ? 1 : 0);
  133. }
  134. reset_canvas();
  135. state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_TEXTURE_RECT, true);
  136. state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_LIGHTING, false);
  137. state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_SHADOWS, false);
  138. state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_NEAREST, false);
  139. state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF3, false);
  140. state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF5, false);
  141. state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF7, false);
  142. state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF9, false);
  143. state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF13, false);
  144. state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_DISTANCE_FIELD, false);
  145. state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_NINEPATCH, false);
  146. state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_ATTRIB_LIGHT_ANGLE, false);
  147. state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_ATTRIB_MODULATE, false);
  148. state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_ATTRIB_LARGE_VERTEX, false);
  149. state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_SKELETON, false);
  150. state.canvas_shader.set_custom_shader(0);
  151. state.canvas_shader.bind();
  152. state.canvas_shader.set_uniform(CanvasShaderGLES3::FINAL_MODULATE, Color(1, 1, 1, 1));
  153. state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX, Transform2D());
  154. state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX, Transform2D());
  155. if (storage->frame.current_rt) {
  156. state.canvas_shader.set_uniform(CanvasShaderGLES3::SCREEN_PIXEL_SIZE, Vector2(1.0 / storage->frame.current_rt->width, 1.0 / storage->frame.current_rt->height));
  157. } else {
  158. state.canvas_shader.set_uniform(CanvasShaderGLES3::SCREEN_PIXEL_SIZE, Vector2(1.0, 1.0));
  159. }
  160. //state.canvas_shader.set_uniform(CanvasShaderGLES3::PROJECTION_MATRIX,state.vp);
  161. //state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX,Transform());
  162. //state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX,Transform());
  163. glBindBufferBase(GL_UNIFORM_BUFFER, 0, state.canvas_item_ubo);
  164. glBindVertexArray(data.canvas_quad_array);
  165. state.using_texture_rect = true;
  166. state.using_ninepatch = false;
  167. state.using_light_angle = false;
  168. state.using_modulate = false;
  169. state.using_large_vertex = false;
  170. state.using_skeleton = false;
  171. }
  172. void RasterizerCanvasBaseGLES3::canvas_end() {
  173. glBindVertexArray(0);
  174. glBindBufferBase(GL_UNIFORM_BUFFER, 0, 0);
  175. glColorMask(1, 1, 1, 1);
  176. glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1);
  177. state.using_texture_rect = false;
  178. state.using_ninepatch = false;
  179. state.using_light_angle = false;
  180. }
  181. RasterizerStorageGLES3::Texture *RasterizerCanvasBaseGLES3::_bind_canvas_texture(const RID &p_texture, const RID &p_normal_map, bool p_force) {
  182. RasterizerStorageGLES3::Texture *tex_return = nullptr;
  183. if (p_texture == state.current_tex && !p_force) {
  184. tex_return = state.current_tex_ptr;
  185. } else if (p_texture.is_valid()) {
  186. RasterizerStorageGLES3::Texture *texture = storage->texture_owner.getornull(p_texture);
  187. if (!texture) {
  188. state.current_tex = RID();
  189. state.current_tex_ptr = nullptr;
  190. glActiveTexture(GL_TEXTURE0);
  191. glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex);
  192. } else {
  193. if (texture->redraw_if_visible) { //check before proxy, because this is usually used with proxies
  194. VisualServerRaster::redraw_request(false);
  195. }
  196. texture = texture->get_ptr();
  197. if (texture->render_target) {
  198. texture->render_target->used_in_frame = true;
  199. }
  200. glActiveTexture(GL_TEXTURE0);
  201. glBindTexture(GL_TEXTURE_2D, texture->tex_id);
  202. state.current_tex = p_texture;
  203. state.current_tex_ptr = texture;
  204. tex_return = texture;
  205. }
  206. } else {
  207. glActiveTexture(GL_TEXTURE0);
  208. glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex);
  209. state.current_tex = RID();
  210. state.current_tex_ptr = nullptr;
  211. }
  212. if (p_normal_map == state.current_normal && !p_force) {
  213. //do none
  214. state.canvas_shader.set_uniform(CanvasShaderGLES3::USE_DEFAULT_NORMAL, state.current_normal.is_valid());
  215. } else if (p_normal_map.is_valid()) {
  216. RasterizerStorageGLES3::Texture *normal_map = storage->texture_owner.getornull(p_normal_map);
  217. if (!normal_map) {
  218. state.current_normal = RID();
  219. glActiveTexture(GL_TEXTURE1);
  220. glBindTexture(GL_TEXTURE_2D, storage->resources.normal_tex);
  221. state.canvas_shader.set_uniform(CanvasShaderGLES3::USE_DEFAULT_NORMAL, false);
  222. } else {
  223. if (normal_map->redraw_if_visible) { //check before proxy, because this is usually used with proxies
  224. VisualServerRaster::redraw_request(false);
  225. }
  226. normal_map = normal_map->get_ptr();
  227. glActiveTexture(GL_TEXTURE1);
  228. glBindTexture(GL_TEXTURE_2D, normal_map->tex_id);
  229. state.current_normal = p_normal_map;
  230. state.canvas_shader.set_uniform(CanvasShaderGLES3::USE_DEFAULT_NORMAL, true);
  231. }
  232. } else {
  233. state.current_normal = RID();
  234. glActiveTexture(GL_TEXTURE1);
  235. glBindTexture(GL_TEXTURE_2D, storage->resources.normal_tex);
  236. state.canvas_shader.set_uniform(CanvasShaderGLES3::USE_DEFAULT_NORMAL, false);
  237. }
  238. return tex_return;
  239. }
  240. void RasterizerCanvasBaseGLES3::_set_texture_rect_mode(bool p_enable, bool p_ninepatch, bool p_light_angle, bool p_modulate, bool p_large_vertex) {
  241. // this state check could be done individually
  242. if (state.using_texture_rect == p_enable && state.using_ninepatch == p_ninepatch && state.using_light_angle == p_light_angle && state.using_modulate == p_modulate && state.using_large_vertex == p_large_vertex) {
  243. return;
  244. }
  245. if (p_enable) {
  246. glBindVertexArray(data.canvas_quad_array);
  247. } else {
  248. glBindVertexArray(0);
  249. glBindBuffer(GL_ARRAY_BUFFER, 0);
  250. glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
  251. }
  252. state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_NINEPATCH, p_ninepatch && p_enable);
  253. state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_TEXTURE_RECT, p_enable);
  254. state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_ATTRIB_LIGHT_ANGLE, p_light_angle);
  255. state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_ATTRIB_MODULATE, p_modulate);
  256. state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_ATTRIB_LARGE_VERTEX, p_large_vertex);
  257. state.canvas_shader.bind();
  258. state.canvas_shader.set_uniform(CanvasShaderGLES3::FINAL_MODULATE, state.canvas_item_modulate);
  259. state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX, state.final_transform);
  260. state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX, state.extra_matrix);
  261. if (state.using_skeleton) {
  262. state.canvas_shader.set_uniform(CanvasShaderGLES3::SKELETON_TRANSFORM, state.skeleton_transform);
  263. state.canvas_shader.set_uniform(CanvasShaderGLES3::SKELETON_TRANSFORM_INVERSE, state.skeleton_transform_inverse);
  264. }
  265. if (storage->frame.current_rt) {
  266. state.canvas_shader.set_uniform(CanvasShaderGLES3::SCREEN_PIXEL_SIZE, Vector2(1.0 / storage->frame.current_rt->width, 1.0 / storage->frame.current_rt->height));
  267. } else {
  268. state.canvas_shader.set_uniform(CanvasShaderGLES3::SCREEN_PIXEL_SIZE, Vector2(1.0, 1.0));
  269. }
  270. state.using_texture_rect = p_enable;
  271. state.using_ninepatch = p_ninepatch;
  272. state.using_light_angle = p_light_angle;
  273. state.using_modulate = p_modulate;
  274. state.using_large_vertex = p_large_vertex;
  275. }
  276. void RasterizerCanvasBaseGLES3::_draw_polygon(const int *p_indices, int p_index_count, int p_vertex_count, const Vector2 *p_vertices, const Vector2 *p_uvs, const Color *p_colors, bool p_singlecolor, const int *p_bones, const float *p_weights) {
  277. glBindVertexArray(data.polygon_buffer_pointer_array);
  278. glBindBuffer(GL_ARRAY_BUFFER, data.polygon_buffer);
  279. uint32_t buffer_ofs = 0;
  280. uint32_t buffer_ofs_after = buffer_ofs + (sizeof(Vector2) * p_vertex_count);
  281. #ifdef DEBUG_ENABLED
  282. ERR_FAIL_COND(buffer_ofs_after > data.polygon_buffer_size);
  283. #endif
  284. storage->buffer_orphan_and_upload(data.polygon_buffer_size, buffer_ofs, sizeof(Vector2) * p_vertex_count, p_vertices, GL_ARRAY_BUFFER, _buffer_upload_usage_flag);
  285. glEnableVertexAttribArray(VS::ARRAY_VERTEX);
  286. glVertexAttribPointer(VS::ARRAY_VERTEX, 2, GL_FLOAT, false, sizeof(Vector2), CAST_INT_TO_UCHAR_PTR(buffer_ofs));
  287. buffer_ofs = buffer_ofs_after;
  288. //color
  289. if (p_singlecolor) {
  290. glDisableVertexAttribArray(VS::ARRAY_COLOR);
  291. Color m = *p_colors;
  292. glVertexAttrib4f(VS::ARRAY_COLOR, m.r, m.g, m.b, m.a);
  293. } else if (!p_colors) {
  294. glDisableVertexAttribArray(VS::ARRAY_COLOR);
  295. glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1);
  296. } else {
  297. RAST_FAIL_COND(!storage->safe_buffer_sub_data(data.polygon_buffer_size, GL_ARRAY_BUFFER, buffer_ofs, sizeof(Color) * p_vertex_count, p_colors, buffer_ofs_after));
  298. glEnableVertexAttribArray(VS::ARRAY_COLOR);
  299. glVertexAttribPointer(VS::ARRAY_COLOR, 4, GL_FLOAT, false, sizeof(Color), CAST_INT_TO_UCHAR_PTR(buffer_ofs));
  300. buffer_ofs = buffer_ofs_after;
  301. }
  302. if (p_uvs) {
  303. RAST_FAIL_COND(!storage->safe_buffer_sub_data(data.polygon_buffer_size, GL_ARRAY_BUFFER, buffer_ofs, sizeof(Vector2) * p_vertex_count, p_uvs, buffer_ofs_after));
  304. glEnableVertexAttribArray(VS::ARRAY_TEX_UV);
  305. glVertexAttribPointer(VS::ARRAY_TEX_UV, 2, GL_FLOAT, false, sizeof(Vector2), CAST_INT_TO_UCHAR_PTR(buffer_ofs));
  306. buffer_ofs = buffer_ofs_after;
  307. } else {
  308. glDisableVertexAttribArray(VS::ARRAY_TEX_UV);
  309. }
  310. if (p_bones && p_weights) {
  311. RAST_FAIL_COND(!storage->safe_buffer_sub_data(data.polygon_buffer_size, GL_ARRAY_BUFFER, buffer_ofs, sizeof(int) * 4 * p_vertex_count, p_bones, buffer_ofs_after));
  312. glEnableVertexAttribArray(VS::ARRAY_BONES);
  313. //glVertexAttribPointer(VS::ARRAY_BONES, 4, GL_UNSIGNED_INT, false, sizeof(int) * 4, ((uint8_t *)0) + buffer_ofs);
  314. glVertexAttribIPointer(VS::ARRAY_BONES, 4, GL_UNSIGNED_INT, sizeof(int) * 4, CAST_INT_TO_UCHAR_PTR(buffer_ofs));
  315. buffer_ofs = buffer_ofs_after;
  316. RAST_FAIL_COND(!storage->safe_buffer_sub_data(data.polygon_buffer_size, GL_ARRAY_BUFFER, buffer_ofs, sizeof(float) * 4 * p_vertex_count, p_weights, buffer_ofs_after));
  317. glEnableVertexAttribArray(VS::ARRAY_WEIGHTS);
  318. glVertexAttribPointer(VS::ARRAY_WEIGHTS, 4, GL_FLOAT, false, sizeof(float) * 4, CAST_INT_TO_UCHAR_PTR(buffer_ofs));
  319. buffer_ofs = buffer_ofs_after;
  320. } else if (state.using_skeleton) {
  321. glVertexAttribI4ui(VS::ARRAY_BONES, 0, 0, 0, 0);
  322. glVertexAttrib4f(VS::ARRAY_WEIGHTS, 0, 0, 0, 0);
  323. }
  324. #ifdef DEBUG_ENABLED
  325. ERR_FAIL_COND((sizeof(int) * p_index_count) > data.polygon_index_buffer_size);
  326. #endif
  327. //bind the indices buffer.
  328. glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, data.polygon_index_buffer);
  329. storage->buffer_orphan_and_upload(data.polygon_index_buffer_size, 0, sizeof(int) * p_index_count, p_indices, GL_ELEMENT_ARRAY_BUFFER, _buffer_upload_usage_flag);
  330. //draw the triangles.
  331. glDrawElements(GL_TRIANGLES, p_index_count, GL_UNSIGNED_INT, nullptr);
  332. storage->info.render._2d_draw_call_count++;
  333. if (p_bones && p_weights) {
  334. //not used so often, so disable when used
  335. glDisableVertexAttribArray(VS::ARRAY_BONES);
  336. glDisableVertexAttribArray(VS::ARRAY_WEIGHTS);
  337. }
  338. glBindVertexArray(0);
  339. glBindBuffer(GL_ARRAY_BUFFER, 0);
  340. }
  341. void RasterizerCanvasBaseGLES3::_draw_generic(GLuint p_primitive, int p_vertex_count, const Vector2 *p_vertices, const Vector2 *p_uvs, const Color *p_colors, bool p_singlecolor) {
  342. glBindVertexArray(data.polygon_buffer_pointer_array);
  343. glBindBuffer(GL_ARRAY_BUFFER, data.polygon_buffer);
  344. //vertex
  345. uint32_t buffer_ofs = 0;
  346. uint32_t buffer_ofs_after = buffer_ofs + (sizeof(Vector2) * p_vertex_count);
  347. #ifdef DEBUG_ENABLED
  348. ERR_FAIL_COND(buffer_ofs_after > data.polygon_buffer_size);
  349. #endif
  350. storage->buffer_orphan_and_upload(data.polygon_buffer_size, buffer_ofs, sizeof(Vector2) * p_vertex_count, p_vertices, GL_ARRAY_BUFFER, _buffer_upload_usage_flag);
  351. glEnableVertexAttribArray(VS::ARRAY_VERTEX);
  352. glVertexAttribPointer(VS::ARRAY_VERTEX, 2, GL_FLOAT, false, sizeof(Vector2), CAST_INT_TO_UCHAR_PTR(buffer_ofs));
  353. buffer_ofs = buffer_ofs_after;
  354. //color
  355. if (p_singlecolor) {
  356. glDisableVertexAttribArray(VS::ARRAY_COLOR);
  357. Color m = *p_colors;
  358. glVertexAttrib4f(VS::ARRAY_COLOR, m.r, m.g, m.b, m.a);
  359. } else if (!p_colors) {
  360. glDisableVertexAttribArray(VS::ARRAY_COLOR);
  361. glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1);
  362. } else {
  363. RAST_FAIL_COND(!storage->safe_buffer_sub_data(data.polygon_buffer_size, GL_ARRAY_BUFFER, buffer_ofs, sizeof(Color) * p_vertex_count, p_colors, buffer_ofs_after));
  364. glEnableVertexAttribArray(VS::ARRAY_COLOR);
  365. glVertexAttribPointer(VS::ARRAY_COLOR, 4, GL_FLOAT, false, sizeof(Color), CAST_INT_TO_UCHAR_PTR(buffer_ofs));
  366. buffer_ofs = buffer_ofs_after;
  367. }
  368. if (p_uvs) {
  369. RAST_FAIL_COND(!storage->safe_buffer_sub_data(data.polygon_buffer_size, GL_ARRAY_BUFFER, buffer_ofs, sizeof(Vector2) * p_vertex_count, p_uvs, buffer_ofs_after));
  370. glEnableVertexAttribArray(VS::ARRAY_TEX_UV);
  371. glVertexAttribPointer(VS::ARRAY_TEX_UV, 2, GL_FLOAT, false, sizeof(Vector2), CAST_INT_TO_UCHAR_PTR(buffer_ofs));
  372. buffer_ofs = buffer_ofs_after;
  373. } else {
  374. glDisableVertexAttribArray(VS::ARRAY_TEX_UV);
  375. }
  376. glDrawArrays(p_primitive, 0, p_vertex_count);
  377. storage->info.render._2d_draw_call_count++;
  378. glBindVertexArray(0);
  379. glBindBuffer(GL_ARRAY_BUFFER, 0);
  380. }
  381. void RasterizerCanvasBaseGLES3::_draw_generic_indices(GLuint p_primitive, const int *p_indices, int p_index_count, int p_vertex_count, const Vector2 *p_vertices, const Vector2 *p_uvs, const Color *p_colors, bool p_singlecolor) {
  382. glBindVertexArray(data.polygon_buffer_pointer_array);
  383. glBindBuffer(GL_ARRAY_BUFFER, data.polygon_buffer);
  384. //vertex
  385. uint32_t buffer_ofs = 0;
  386. uint32_t buffer_ofs_after = buffer_ofs + (sizeof(Vector2) * p_vertex_count);
  387. #ifdef DEBUG_ENABLED
  388. ERR_FAIL_COND(buffer_ofs_after > data.polygon_buffer_size);
  389. #endif
  390. storage->buffer_orphan_and_upload(data.polygon_buffer_size, buffer_ofs, sizeof(Vector2) * p_vertex_count, p_vertices, GL_ARRAY_BUFFER, _buffer_upload_usage_flag);
  391. glEnableVertexAttribArray(VS::ARRAY_VERTEX);
  392. glVertexAttribPointer(VS::ARRAY_VERTEX, 2, GL_FLOAT, false, sizeof(Vector2), CAST_INT_TO_UCHAR_PTR(buffer_ofs));
  393. buffer_ofs = buffer_ofs_after;
  394. //color
  395. if (p_singlecolor) {
  396. glDisableVertexAttribArray(VS::ARRAY_COLOR);
  397. Color m = *p_colors;
  398. glVertexAttrib4f(VS::ARRAY_COLOR, m.r, m.g, m.b, m.a);
  399. } else if (!p_colors) {
  400. glDisableVertexAttribArray(VS::ARRAY_COLOR);
  401. glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1);
  402. } else {
  403. RAST_FAIL_COND(!storage->safe_buffer_sub_data(data.polygon_buffer_size, GL_ARRAY_BUFFER, buffer_ofs, sizeof(Color) * p_vertex_count, p_colors, buffer_ofs_after));
  404. glEnableVertexAttribArray(VS::ARRAY_COLOR);
  405. glVertexAttribPointer(VS::ARRAY_COLOR, 4, GL_FLOAT, false, sizeof(Color), CAST_INT_TO_UCHAR_PTR(buffer_ofs));
  406. buffer_ofs = buffer_ofs_after;
  407. }
  408. if (p_uvs) {
  409. RAST_FAIL_COND(!storage->safe_buffer_sub_data(data.polygon_buffer_size, GL_ARRAY_BUFFER, buffer_ofs, sizeof(Vector2) * p_vertex_count, p_uvs, buffer_ofs_after));
  410. glEnableVertexAttribArray(VS::ARRAY_TEX_UV);
  411. glVertexAttribPointer(VS::ARRAY_TEX_UV, 2, GL_FLOAT, false, sizeof(Vector2), CAST_INT_TO_UCHAR_PTR(buffer_ofs));
  412. buffer_ofs = buffer_ofs_after;
  413. } else {
  414. glDisableVertexAttribArray(VS::ARRAY_TEX_UV);
  415. }
  416. #ifdef RASTERIZER_EXTRA_CHECKS
  417. // very slow, do not enable in normal use
  418. for (int n = 0; n < p_index_count; n++) {
  419. RAST_DEV_DEBUG_ASSERT(p_indices[n] < p_vertex_count);
  420. }
  421. #endif
  422. #ifdef DEBUG_ENABLED
  423. ERR_FAIL_COND((sizeof(int) * p_index_count) > data.polygon_index_buffer_size);
  424. #endif
  425. //bind the indices buffer.
  426. glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, data.polygon_index_buffer);
  427. storage->buffer_orphan_and_upload(data.polygon_index_buffer_size, 0, sizeof(int) * p_index_count, p_indices, GL_ELEMENT_ARRAY_BUFFER, _buffer_upload_usage_flag);
  428. //draw the triangles.
  429. glDrawElements(p_primitive, p_index_count, GL_UNSIGNED_INT, nullptr);
  430. storage->info.render._2d_draw_call_count++;
  431. glBindVertexArray(0);
  432. glBindBuffer(GL_ARRAY_BUFFER, 0);
  433. }
  434. void RasterizerCanvasBaseGLES3::_draw_gui_primitive(int p_points, const Vector2 *p_vertices, const Color *p_colors, const Vector2 *p_uvs, const float *p_light_angles) {
  435. static const GLenum prim[5] = { GL_POINTS, GL_POINTS, GL_LINES, GL_TRIANGLES, GL_TRIANGLE_FAN };
  436. //#define GLES_USE_PRIMITIVE_BUFFER
  437. int version = 0;
  438. int color_ofs = 0;
  439. int uv_ofs = 0;
  440. int light_angle_ofs = 0;
  441. int stride = 2;
  442. if (p_colors) { //color
  443. version |= 1;
  444. color_ofs = stride;
  445. stride += 4;
  446. }
  447. if (p_uvs) { //uv
  448. version |= 2;
  449. uv_ofs = stride;
  450. stride += 2;
  451. }
  452. if (p_light_angles) { //light_angles
  453. version |= 4;
  454. light_angle_ofs = stride;
  455. stride += 1;
  456. }
  457. DEV_ASSERT(p_points <= 4);
  458. float b[(2 + 2 + 4 + 1) * 4];
  459. for (int i = 0; i < p_points; i++) {
  460. b[stride * i + 0] = p_vertices[i].x;
  461. b[stride * i + 1] = p_vertices[i].y;
  462. }
  463. if (p_colors) {
  464. for (int i = 0; i < p_points; i++) {
  465. b[stride * i + color_ofs + 0] = p_colors[i].r;
  466. b[stride * i + color_ofs + 1] = p_colors[i].g;
  467. b[stride * i + color_ofs + 2] = p_colors[i].b;
  468. b[stride * i + color_ofs + 3] = p_colors[i].a;
  469. }
  470. }
  471. if (p_uvs) {
  472. for (int i = 0; i < p_points; i++) {
  473. b[stride * i + uv_ofs + 0] = p_uvs[i].x;
  474. b[stride * i + uv_ofs + 1] = p_uvs[i].y;
  475. }
  476. }
  477. if (p_light_angles) {
  478. for (int i = 0; i < p_points; i++) {
  479. b[stride * i + light_angle_ofs] = p_light_angles[i];
  480. }
  481. }
  482. glBindBuffer(GL_ARRAY_BUFFER, data.polygon_buffer);
  483. storage->buffer_orphan_and_upload(data.polygon_buffer_size, 0, p_points * stride * sizeof(float), &b[0], GL_ARRAY_BUFFER, _buffer_upload_usage_flag);
  484. glBindVertexArray(data.polygon_buffer_quad_arrays[version]);
  485. glDrawArrays(prim[p_points], 0, p_points);
  486. glBindVertexArray(0);
  487. glBindBuffer(GL_ARRAY_BUFFER, 0);
  488. storage->info.render._2d_draw_call_count++;
  489. }
  490. void RasterizerCanvasBaseGLES3::render_rect_nvidia_workaround(const Item::CommandRect *p_rect, const RasterizerStorageGLES3::Texture *p_texture) {
  491. if (p_texture) {
  492. bool send_light_angles = false;
  493. // only need to use light angles when normal mapping
  494. // otherwise we can use the default shader
  495. if (state.current_normal != RID()) {
  496. send_light_angles = true;
  497. }
  498. // we don't want to use texture rect, and we want to send light angles if we are using normal mapping
  499. _set_texture_rect_mode(false, false, send_light_angles);
  500. bool untile = false;
  501. if (p_rect->flags & CANVAS_RECT_TILE && !(p_texture->flags & VS::TEXTURE_FLAG_REPEAT)) {
  502. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  503. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  504. untile = true;
  505. }
  506. Size2 texpixel_size(1.0 / p_texture->width, 1.0 / p_texture->height);
  507. state.canvas_shader.set_uniform(CanvasShaderGLES3::CLIP_RECT_UV, p_rect->flags & CANVAS_RECT_CLIP_UV);
  508. Vector2 points[4] = {
  509. p_rect->rect.position,
  510. p_rect->rect.position + Vector2(p_rect->rect.size.x, 0.0),
  511. p_rect->rect.position + p_rect->rect.size,
  512. p_rect->rect.position + Vector2(0.0, p_rect->rect.size.y),
  513. };
  514. if (p_rect->rect.size.x < 0) {
  515. SWAP(points[0], points[1]);
  516. SWAP(points[2], points[3]);
  517. }
  518. if (p_rect->rect.size.y < 0) {
  519. SWAP(points[0], points[3]);
  520. SWAP(points[1], points[2]);
  521. }
  522. Rect2 src_rect = (p_rect->flags & CANVAS_RECT_REGION) ? Rect2(p_rect->source.position * texpixel_size, p_rect->source.size * texpixel_size) : Rect2(0, 0, 1, 1);
  523. Vector2 uvs[4] = {
  524. src_rect.position,
  525. src_rect.position + Vector2(src_rect.size.x, 0.0),
  526. src_rect.position + src_rect.size,
  527. src_rect.position + Vector2(0.0, src_rect.size.y),
  528. };
  529. // for encoding in light angle
  530. bool flip_h = false;
  531. bool flip_v = false;
  532. if (p_rect->flags & CANVAS_RECT_TRANSPOSE) {
  533. SWAP(uvs[1], uvs[3]);
  534. }
  535. if (p_rect->flags & CANVAS_RECT_FLIP_H) {
  536. SWAP(uvs[0], uvs[1]);
  537. SWAP(uvs[2], uvs[3]);
  538. flip_h = true;
  539. flip_v = !flip_v;
  540. }
  541. if (p_rect->flags & CANVAS_RECT_FLIP_V) {
  542. SWAP(uvs[0], uvs[3]);
  543. SWAP(uvs[1], uvs[2]);
  544. flip_v = !flip_v;
  545. }
  546. if (send_light_angles) {
  547. // for single rects, there is no need to fully utilize the light angle,
  548. // we only need it to encode flips (horz and vert). But the shader can be reused with
  549. // batching in which case the angle encodes the transform as well as
  550. // the flips.
  551. // Note transpose is NYI. I don't think it worked either with the non-nvidia method.
  552. // if horizontal flip, angle is 180
  553. float angle = 0.0f;
  554. if (flip_h) {
  555. angle = Math_PI;
  556. }
  557. // add 1 (to take care of zero floating point error with sign)
  558. angle += 1.0f;
  559. // flip if necessary
  560. if (flip_v) {
  561. angle *= -1.0f;
  562. }
  563. // light angle must be sent for each vert, instead as a single uniform in the uniform draw method
  564. // this has the benefit of enabling batching with light angles.
  565. float light_angles[4] = { angle, angle, angle, angle };
  566. _draw_gui_primitive(4, points, nullptr, uvs, light_angles);
  567. } else {
  568. _draw_gui_primitive(4, points, nullptr, uvs);
  569. }
  570. if (untile) {
  571. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  572. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  573. }
  574. } else {
  575. _set_texture_rect_mode(false);
  576. state.canvas_shader.set_uniform(CanvasShaderGLES3::CLIP_RECT_UV, false);
  577. Vector2 points[4] = {
  578. p_rect->rect.position,
  579. p_rect->rect.position + Vector2(p_rect->rect.size.x, 0.0),
  580. p_rect->rect.position + p_rect->rect.size,
  581. p_rect->rect.position + Vector2(0.0, p_rect->rect.size.y),
  582. };
  583. _draw_gui_primitive(4, points, nullptr, nullptr);
  584. }
  585. }
  586. void RasterizerCanvasBaseGLES3::_copy_texscreen(const Rect2 &p_rect) {
  587. ERR_FAIL_COND_MSG(storage->frame.current_rt->effects.mip_maps[0].sizes.size() == 0, "Can't use screen texture copying in a render target configured without copy buffers. To resolve this, change the viewport's Usage property to \"2D\" or \"3D\" instead of \"2D Without Sampling\" or \"3D Without Effects\" respectively.");
  588. glDisable(GL_BLEND);
  589. state.canvas_texscreen_used = true;
  590. //blur diffuse into effect mipmaps using separatable convolution
  591. //storage->shaders.copy.set_conditional(CopyShaderGLES3::GAUSSIAN_HORIZONTAL,true);
  592. Vector2 wh(storage->frame.current_rt->width, storage->frame.current_rt->height);
  593. Color blur_section(p_rect.position.x / wh.x, p_rect.position.y / wh.y, p_rect.size.x / wh.x, p_rect.size.y / wh.y);
  594. if (p_rect != Rect2()) {
  595. scene_render->state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::USE_BLUR_SECTION, true);
  596. storage->shaders.copy.set_conditional(CopyShaderGLES3::USE_COPY_SECTION, true);
  597. }
  598. glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->effects.mip_maps[0].sizes[0].fbo);
  599. glActiveTexture(GL_TEXTURE0);
  600. glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->color);
  601. storage->shaders.copy.bind();
  602. storage->shaders.copy.set_uniform(CopyShaderGLES3::COPY_SECTION, blur_section);
  603. scene_render->_copy_screen();
  604. for (int i = 0; i < storage->frame.current_rt->effects.mip_maps[1].sizes.size(); i++) {
  605. int vp_w = storage->frame.current_rt->effects.mip_maps[1].sizes[i].width;
  606. int vp_h = storage->frame.current_rt->effects.mip_maps[1].sizes[i].height;
  607. glViewport(0, 0, vp_w, vp_h);
  608. //horizontal pass
  609. scene_render->state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GAUSSIAN_HORIZONTAL, true);
  610. scene_render->state.effect_blur_shader.bind();
  611. scene_render->state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::PIXEL_SIZE, Vector2(1.0 / vp_w, 1.0 / vp_h));
  612. scene_render->state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::LOD, float(i));
  613. scene_render->state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::BLUR_SECTION, blur_section);
  614. glActiveTexture(GL_TEXTURE0);
  615. glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.mip_maps[0].color); //previous level, since mipmaps[0] starts one level bigger
  616. glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->effects.mip_maps[1].sizes[i].fbo);
  617. scene_render->_copy_screen();
  618. scene_render->state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GAUSSIAN_HORIZONTAL, false);
  619. //vertical pass
  620. scene_render->state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GAUSSIAN_VERTICAL, true);
  621. scene_render->state.effect_blur_shader.bind();
  622. scene_render->state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::PIXEL_SIZE, Vector2(1.0 / vp_w, 1.0 / vp_h));
  623. scene_render->state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::LOD, float(i));
  624. scene_render->state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::BLUR_SECTION, blur_section);
  625. glActiveTexture(GL_TEXTURE0);
  626. glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.mip_maps[1].color);
  627. glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->effects.mip_maps[0].sizes[i + 1].fbo); //next level, since mipmaps[0] starts one level bigger
  628. scene_render->_copy_screen();
  629. scene_render->state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GAUSSIAN_VERTICAL, false);
  630. }
  631. scene_render->state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::USE_BLUR_SECTION, false);
  632. storage->shaders.copy.set_conditional(CopyShaderGLES3::USE_COPY_SECTION, false);
  633. glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->fbo); //back to front
  634. glViewport(0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height);
  635. // back to canvas, force rebind
  636. state.using_texture_rect = true;
  637. _set_texture_rect_mode(false);
  638. _bind_canvas_texture(state.current_tex, state.current_normal, true);
  639. glEnable(GL_BLEND);
  640. }
  641. void RasterizerCanvasBaseGLES3::canvas_debug_viewport_shadows(Light *p_lights_with_shadow) {
  642. Light *light = p_lights_with_shadow;
  643. canvas_begin(); //reset
  644. glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1);
  645. int h = 10;
  646. int w = storage->frame.current_rt->width;
  647. int ofs = h;
  648. glDisable(GL_BLEND);
  649. while (light) {
  650. if (light->shadow_buffer.is_valid()) {
  651. RasterizerStorageGLES3::CanvasLightShadow *sb = storage->canvas_light_shadow_owner.get(light->shadow_buffer);
  652. if (sb) {
  653. glBindTexture(GL_TEXTURE_2D, sb->distance);
  654. draw_generic_textured_rect(Rect2(h, ofs, w - h * 2, h), Rect2(0, 0, 1, 1));
  655. ofs += h * 2;
  656. }
  657. }
  658. light = light->shadows_next_ptr;
  659. }
  660. canvas_end();
  661. }
  662. void RasterizerCanvasBaseGLES3::canvas_light_shadow_buffer_update(RID p_buffer, const Transform2D &p_light_xform, int p_light_mask, float p_near, float p_far, LightOccluderInstance *p_occluders, CameraMatrix *p_xform_cache) {
  663. RasterizerStorageGLES3::CanvasLightShadow *cls = storage->canvas_light_shadow_owner.get(p_buffer);
  664. ERR_FAIL_COND(!cls);
  665. glDisable(GL_BLEND);
  666. glDisable(GL_SCISSOR_TEST);
  667. glDisable(GL_DITHER);
  668. glDisable(GL_CULL_FACE);
  669. glDepthFunc(GL_LEQUAL);
  670. glEnable(GL_DEPTH_TEST);
  671. glDepthMask(true);
  672. glBindFramebuffer(GL_FRAMEBUFFER, cls->fbo);
  673. state.canvas_shadow_shader.bind();
  674. glViewport(0, 0, cls->size, cls->height);
  675. glClearDepth(1.0f);
  676. glClearColor(1, 1, 1, 1);
  677. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  678. VS::CanvasOccluderPolygonCullMode cull = VS::CANVAS_OCCLUDER_POLYGON_CULL_DISABLED;
  679. for (int i = 0; i < 4; i++) {
  680. //make sure it remains orthogonal, makes easy to read angle later
  681. Transform light;
  682. light.origin[0] = p_light_xform[2][0];
  683. light.origin[1] = p_light_xform[2][1];
  684. light.basis[0][0] = p_light_xform[0][0];
  685. light.basis[0][1] = p_light_xform[1][0];
  686. light.basis[1][0] = p_light_xform[0][1];
  687. light.basis[1][1] = p_light_xform[1][1];
  688. //light.basis.scale(Vector3(to_light.elements[0].length(),to_light.elements[1].length(),1));
  689. //p_near=1;
  690. CameraMatrix projection;
  691. {
  692. real_t fov = 90;
  693. real_t nearp = p_near;
  694. real_t farp = p_far;
  695. real_t aspect = 1.0;
  696. real_t ymax = nearp * Math::tan(Math::deg2rad(fov * 0.5));
  697. real_t ymin = -ymax;
  698. real_t xmin = ymin * aspect;
  699. real_t xmax = ymax * aspect;
  700. projection.set_frustum(xmin, xmax, ymin, ymax, nearp, farp);
  701. }
  702. Vector3 cam_target = Basis(Vector3(0, 0, Math_PI * 2 * (i / 4.0))).xform(Vector3(0, 1, 0));
  703. projection = projection * CameraMatrix(Transform().looking_at(cam_target, Vector3(0, 0, -1)).affine_inverse());
  704. state.canvas_shadow_shader.set_uniform(CanvasShadowShaderGLES3::PROJECTION_MATRIX, projection);
  705. state.canvas_shadow_shader.set_uniform(CanvasShadowShaderGLES3::LIGHT_MATRIX, light);
  706. state.canvas_shadow_shader.set_uniform(CanvasShadowShaderGLES3::DISTANCE_NORM, 1.0 / p_far);
  707. if (i == 0) {
  708. *p_xform_cache = projection;
  709. }
  710. glViewport(0, (cls->height / 4) * i, cls->size, cls->height / 4);
  711. LightOccluderInstance *instance = p_occluders;
  712. while (instance) {
  713. RasterizerStorageGLES3::CanvasOccluder *cc = storage->canvas_occluder_owner.getornull(instance->polygon_buffer);
  714. if (!cc || cc->len == 0 || !(p_light_mask & instance->light_mask)) {
  715. instance = instance->next;
  716. continue;
  717. }
  718. state.canvas_shadow_shader.set_uniform(CanvasShadowShaderGLES3::WORLD_MATRIX, instance->xform_cache);
  719. VS::CanvasOccluderPolygonCullMode transformed_cull_cache = instance->cull_cache;
  720. if (transformed_cull_cache != VS::CANVAS_OCCLUDER_POLYGON_CULL_DISABLED &&
  721. (p_light_xform.basis_determinant() * instance->xform_cache.basis_determinant()) < 0) {
  722. transformed_cull_cache = (transformed_cull_cache == VS::CANVAS_OCCLUDER_POLYGON_CULL_CLOCKWISE)
  723. ? VS::CANVAS_OCCLUDER_POLYGON_CULL_COUNTER_CLOCKWISE
  724. : VS::CANVAS_OCCLUDER_POLYGON_CULL_CLOCKWISE;
  725. }
  726. if (cull != transformed_cull_cache) {
  727. cull = transformed_cull_cache;
  728. switch (cull) {
  729. case VS::CANVAS_OCCLUDER_POLYGON_CULL_DISABLED: {
  730. glDisable(GL_CULL_FACE);
  731. } break;
  732. case VS::CANVAS_OCCLUDER_POLYGON_CULL_CLOCKWISE: {
  733. glEnable(GL_CULL_FACE);
  734. glCullFace(GL_FRONT);
  735. } break;
  736. case VS::CANVAS_OCCLUDER_POLYGON_CULL_COUNTER_CLOCKWISE: {
  737. glEnable(GL_CULL_FACE);
  738. glCullFace(GL_BACK);
  739. } break;
  740. }
  741. }
  742. glBindVertexArray(cc->array_id);
  743. glDrawElements(GL_TRIANGLES, cc->len * 3, GL_UNSIGNED_SHORT, nullptr);
  744. instance = instance->next;
  745. }
  746. }
  747. glBindVertexArray(0);
  748. }
  749. void RasterizerCanvasBaseGLES3::reset_canvas() {
  750. if (storage->frame.current_rt) {
  751. glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->fbo);
  752. glColorMask(1, 1, 1, 1); //don't touch alpha
  753. }
  754. glBindVertexArray(0);
  755. glDisable(GL_CULL_FACE);
  756. glDisable(GL_DEPTH_TEST);
  757. glDisable(GL_SCISSOR_TEST);
  758. glDisable(GL_DITHER);
  759. glEnable(GL_BLEND);
  760. glBlendEquation(GL_FUNC_ADD);
  761. if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) {
  762. glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
  763. } else {
  764. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  765. }
  766. //glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
  767. //glLineWidth(1.0);
  768. glBindBuffer(GL_ARRAY_BUFFER, 0);
  769. glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
  770. //use for reading from screen
  771. if (storage->frame.current_rt && !storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_NO_SAMPLING]) {
  772. glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 3);
  773. glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.mip_maps[0].color);
  774. }
  775. glActiveTexture(GL_TEXTURE0);
  776. glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex);
  777. glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1);
  778. Transform canvas_transform;
  779. if (storage->frame.current_rt) {
  780. float csy = 1.0;
  781. if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_VFLIP]) {
  782. csy = -1.0;
  783. }
  784. canvas_transform.translate(-(storage->frame.current_rt->width / 2.0f), -(storage->frame.current_rt->height / 2.0f), 0.0f);
  785. canvas_transform.scale(Vector3(2.0f / storage->frame.current_rt->width, csy * -2.0f / storage->frame.current_rt->height, 1.0f));
  786. } else {
  787. Vector2 ssize = OS::get_singleton()->get_window_size();
  788. canvas_transform.translate(-(ssize.width / 2.0f), -(ssize.height / 2.0f), 0.0f);
  789. canvas_transform.scale(Vector3(2.0f / ssize.width, -2.0f / ssize.height, 1.0f));
  790. }
  791. state.vp = canvas_transform;
  792. store_transform(canvas_transform, state.canvas_item_ubo_data.projection_matrix);
  793. state.canvas_item_ubo_data.time = storage->frame.time[0];
  794. glBindBuffer(GL_UNIFORM_BUFFER, state.canvas_item_ubo);
  795. glBufferData(GL_UNIFORM_BUFFER, sizeof(CanvasItemUBO), &state.canvas_item_ubo_data, GL_DYNAMIC_DRAW);
  796. glBindBuffer(GL_UNIFORM_BUFFER, 0);
  797. state.canvas_texscreen_used = false;
  798. }
  799. void RasterizerCanvasBaseGLES3::draw_generic_textured_rect(const Rect2 &p_rect, const Rect2 &p_src) {
  800. state.canvas_shader.set_uniform(CanvasShaderGLES3::DST_RECT, Color(p_rect.position.x, p_rect.position.y, p_rect.size.x, p_rect.size.y));
  801. state.canvas_shader.set_uniform(CanvasShaderGLES3::SRC_RECT, Color(p_src.position.x, p_src.position.y, p_src.size.x, p_src.size.y));
  802. state.canvas_shader.set_uniform(CanvasShaderGLES3::CLIP_RECT_UV, false);
  803. glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
  804. }
  805. void RasterizerCanvasBaseGLES3::draw_lens_distortion_rect(const Rect2 &p_rect, float p_k1, float p_k2, const Vector2 &p_eye_center, float p_oversample) {
  806. Vector2 half_size;
  807. if (storage->frame.current_rt) {
  808. half_size = Vector2(storage->frame.current_rt->width, storage->frame.current_rt->height);
  809. } else {
  810. half_size = OS::get_singleton()->get_window_size();
  811. }
  812. half_size *= 0.5;
  813. Vector2 offset((p_rect.position.x - half_size.x) / half_size.x, (p_rect.position.y - half_size.y) / half_size.y);
  814. Vector2 scale(p_rect.size.x / half_size.x, p_rect.size.y / half_size.y);
  815. float aspect_ratio = p_rect.size.x / p_rect.size.y;
  816. // setup our lens shader
  817. state.lens_shader.bind();
  818. state.lens_shader.set_uniform(LensDistortedShaderGLES3::OFFSET, offset);
  819. state.lens_shader.set_uniform(LensDistortedShaderGLES3::SCALE, scale);
  820. state.lens_shader.set_uniform(LensDistortedShaderGLES3::K1, p_k1);
  821. state.lens_shader.set_uniform(LensDistortedShaderGLES3::K2, p_k2);
  822. state.lens_shader.set_uniform(LensDistortedShaderGLES3::EYE_CENTER, p_eye_center);
  823. state.lens_shader.set_uniform(LensDistortedShaderGLES3::UPSCALE, p_oversample);
  824. state.lens_shader.set_uniform(LensDistortedShaderGLES3::ASPECT_RATIO, aspect_ratio);
  825. glBindBufferBase(GL_UNIFORM_BUFFER, 0, state.canvas_item_ubo);
  826. glBindVertexArray(data.canvas_quad_array);
  827. // and draw
  828. glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
  829. glBindVertexArray(0);
  830. glBindBufferBase(GL_UNIFORM_BUFFER, 0, 0);
  831. }
  832. void RasterizerCanvasBaseGLES3::draw_window_margins(int *black_margin, RID *black_image) {
  833. Vector2 window_size = OS::get_singleton()->get_window_size();
  834. int window_h = window_size.height;
  835. int window_w = window_size.width;
  836. glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo);
  837. glViewport(0, 0, window_size.width, window_size.height);
  838. canvas_begin();
  839. if (black_image[MARGIN_LEFT].is_valid()) {
  840. _bind_canvas_texture(black_image[MARGIN_LEFT], RID(), true);
  841. Size2 sz(storage->texture_get_width(black_image[MARGIN_LEFT]), storage->texture_get_height(black_image[MARGIN_LEFT]));
  842. draw_generic_textured_rect(Rect2(0, 0, black_margin[MARGIN_LEFT], window_h),
  843. Rect2(0, 0, (float)black_margin[MARGIN_LEFT] / sz.x, (float)(window_h) / sz.y));
  844. } else if (black_margin[MARGIN_LEFT]) {
  845. glActiveTexture(GL_TEXTURE0);
  846. glBindTexture(GL_TEXTURE_2D, storage->resources.black_tex);
  847. draw_generic_textured_rect(Rect2(0, 0, black_margin[MARGIN_LEFT], window_h), Rect2(0, 0, 1, 1));
  848. }
  849. if (black_image[MARGIN_RIGHT].is_valid()) {
  850. _bind_canvas_texture(black_image[MARGIN_RIGHT], RID(), true);
  851. Size2 sz(storage->texture_get_width(black_image[MARGIN_RIGHT]), storage->texture_get_height(black_image[MARGIN_RIGHT]));
  852. draw_generic_textured_rect(Rect2(window_w - black_margin[MARGIN_RIGHT], 0, black_margin[MARGIN_RIGHT], window_h),
  853. Rect2(0, 0, (float)black_margin[MARGIN_RIGHT] / sz.x, (float)window_h / sz.y));
  854. } else if (black_margin[MARGIN_RIGHT]) {
  855. glActiveTexture(GL_TEXTURE0);
  856. glBindTexture(GL_TEXTURE_2D, storage->resources.black_tex);
  857. draw_generic_textured_rect(Rect2(window_w - black_margin[MARGIN_RIGHT], 0, black_margin[MARGIN_RIGHT], window_h), Rect2(0, 0, 1, 1));
  858. }
  859. if (black_image[MARGIN_TOP].is_valid()) {
  860. _bind_canvas_texture(black_image[MARGIN_TOP], RID(), true);
  861. Size2 sz(storage->texture_get_width(black_image[MARGIN_TOP]), storage->texture_get_height(black_image[MARGIN_TOP]));
  862. draw_generic_textured_rect(Rect2(0, 0, window_w, black_margin[MARGIN_TOP]),
  863. Rect2(0, 0, (float)window_w / sz.x, (float)black_margin[MARGIN_TOP] / sz.y));
  864. } else if (black_margin[MARGIN_TOP]) {
  865. glActiveTexture(GL_TEXTURE0);
  866. glBindTexture(GL_TEXTURE_2D, storage->resources.black_tex);
  867. draw_generic_textured_rect(Rect2(0, 0, window_w, black_margin[MARGIN_TOP]), Rect2(0, 0, 1, 1));
  868. }
  869. if (black_image[MARGIN_BOTTOM].is_valid()) {
  870. _bind_canvas_texture(black_image[MARGIN_BOTTOM], RID(), true);
  871. Size2 sz(storage->texture_get_width(black_image[MARGIN_BOTTOM]), storage->texture_get_height(black_image[MARGIN_BOTTOM]));
  872. draw_generic_textured_rect(Rect2(0, window_h - black_margin[MARGIN_BOTTOM], window_w, black_margin[MARGIN_BOTTOM]),
  873. Rect2(0, 0, (float)window_w / sz.x, (float)black_margin[MARGIN_BOTTOM] / sz.y));
  874. } else if (black_margin[MARGIN_BOTTOM]) {
  875. glActiveTexture(GL_TEXTURE0);
  876. glBindTexture(GL_TEXTURE_2D, storage->resources.black_tex);
  877. draw_generic_textured_rect(Rect2(0, window_h - black_margin[MARGIN_BOTTOM], window_w, black_margin[MARGIN_BOTTOM]), Rect2(0, 0, 1, 1));
  878. }
  879. }
  880. void RasterizerCanvasBaseGLES3::initialize() {
  881. int flag_stream_mode = GLOBAL_GET("rendering/2d/opengl/legacy_stream");
  882. switch (flag_stream_mode) {
  883. default: {
  884. _buffer_upload_usage_flag = GL_STREAM_DRAW;
  885. } break;
  886. case 1: {
  887. _buffer_upload_usage_flag = GL_DYNAMIC_DRAW;
  888. } break;
  889. case 2: {
  890. _buffer_upload_usage_flag = GL_STREAM_DRAW;
  891. } break;
  892. }
  893. {
  894. //quad buffers
  895. glGenBuffers(1, &data.canvas_quad_vertices);
  896. glBindBuffer(GL_ARRAY_BUFFER, data.canvas_quad_vertices);
  897. {
  898. const float qv[8] = {
  899. 0, 0,
  900. 0, 1,
  901. 1, 1,
  902. 1, 0
  903. };
  904. glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 8, qv, GL_STATIC_DRAW);
  905. }
  906. glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind
  907. glGenVertexArrays(1, &data.canvas_quad_array);
  908. glBindVertexArray(data.canvas_quad_array);
  909. glBindBuffer(GL_ARRAY_BUFFER, data.canvas_quad_vertices);
  910. glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, nullptr);
  911. glEnableVertexAttribArray(0);
  912. glBindVertexArray(0);
  913. glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind
  914. }
  915. {
  916. //particle quad buffers
  917. glGenBuffers(1, &data.particle_quad_vertices);
  918. glBindBuffer(GL_ARRAY_BUFFER, data.particle_quad_vertices);
  919. {
  920. //quad of size 1, with pivot on the center for particles, then regular UVS. Color is general plus fetched from particle
  921. const float qv[16] = {
  922. -0.5, -0.5,
  923. 0.0, 0.0,
  924. -0.5, 0.5,
  925. 0.0, 1.0,
  926. 0.5, 0.5,
  927. 1.0, 1.0,
  928. 0.5, -0.5,
  929. 1.0, 0.0
  930. };
  931. glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 16, qv, GL_STATIC_DRAW);
  932. }
  933. glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind
  934. glGenVertexArrays(1, &data.particle_quad_array);
  935. glBindVertexArray(data.particle_quad_array);
  936. glBindBuffer(GL_ARRAY_BUFFER, data.particle_quad_vertices);
  937. glEnableVertexAttribArray(VS::ARRAY_VERTEX);
  938. glVertexAttribPointer(VS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, nullptr);
  939. glEnableVertexAttribArray(VS::ARRAY_TEX_UV);
  940. glVertexAttribPointer(VS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, CAST_INT_TO_UCHAR_PTR(8));
  941. glBindVertexArray(0);
  942. glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind
  943. }
  944. {
  945. uint32_t poly_size = GLOBAL_DEF_RST("rendering/limits/buffers/canvas_polygon_buffer_size_kb", 128);
  946. ProjectSettings::get_singleton()->set_custom_property_info("rendering/limits/buffers/canvas_polygon_buffer_size_kb", PropertyInfo(Variant::INT, "rendering/limits/buffers/canvas_polygon_buffer_size_kb", PROPERTY_HINT_RANGE, "0,256,1,or_greater"));
  947. poly_size = MAX(poly_size, 2); // minimum 2k, may still see anomalies in editor
  948. poly_size *= 1024; //kb
  949. glGenBuffers(1, &data.polygon_buffer);
  950. glBindBuffer(GL_ARRAY_BUFFER, data.polygon_buffer);
  951. glBufferData(GL_ARRAY_BUFFER, poly_size, nullptr, GL_DYNAMIC_DRAW); //allocate max size
  952. glBindBuffer(GL_ARRAY_BUFFER, 0);
  953. data.polygon_buffer_size = poly_size;
  954. //quad arrays
  955. for (int i = 0; i < Data::NUM_QUAD_ARRAY_VARIATIONS; i++) {
  956. glGenVertexArrays(1, &data.polygon_buffer_quad_arrays[i]);
  957. glBindVertexArray(data.polygon_buffer_quad_arrays[i]);
  958. glBindBuffer(GL_ARRAY_BUFFER, data.polygon_buffer);
  959. int uv_ofs = 0;
  960. int color_ofs = 0;
  961. int light_angle_ofs = 0;
  962. int stride = 2 * 4;
  963. if (i & 1) { //color
  964. color_ofs = stride;
  965. stride += 4 * 4;
  966. }
  967. if (i & 2) { //uv
  968. uv_ofs = stride;
  969. stride += 2 * 4;
  970. }
  971. if (i & 4) { //light_angle
  972. light_angle_ofs = stride;
  973. stride += 1 * 4;
  974. }
  975. glEnableVertexAttribArray(VS::ARRAY_VERTEX);
  976. glVertexAttribPointer(VS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, stride, nullptr);
  977. if (i & 1) {
  978. glEnableVertexAttribArray(VS::ARRAY_COLOR);
  979. glVertexAttribPointer(VS::ARRAY_COLOR, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(color_ofs));
  980. }
  981. if (i & 2) {
  982. glEnableVertexAttribArray(VS::ARRAY_TEX_UV);
  983. glVertexAttribPointer(VS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(uv_ofs));
  984. }
  985. if (i & 4) {
  986. // reusing tangent for light_angle
  987. glEnableVertexAttribArray(VS::ARRAY_TANGENT);
  988. glVertexAttribPointer(VS::ARRAY_TANGENT, 1, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(light_angle_ofs));
  989. }
  990. glBindVertexArray(0);
  991. }
  992. glGenVertexArrays(1, &data.polygon_buffer_pointer_array);
  993. uint32_t index_size = GLOBAL_DEF_RST("rendering/limits/buffers/canvas_polygon_index_buffer_size_kb", 128);
  994. ProjectSettings::get_singleton()->set_custom_property_info("rendering/limits/buffers/canvas_polygon_index_buffer_size_kb", PropertyInfo(Variant::INT, "rendering/limits/buffers/canvas_polygon_index_buffer_size_kb", PROPERTY_HINT_RANGE, "0,256,1,or_greater"));
  995. index_size = MAX(index_size, 2);
  996. index_size *= 1024; //kb
  997. glGenBuffers(1, &data.polygon_index_buffer);
  998. glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, data.polygon_index_buffer);
  999. glBufferData(GL_ELEMENT_ARRAY_BUFFER, index_size, nullptr, GL_DYNAMIC_DRAW); //allocate max size
  1000. glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
  1001. data.polygon_index_buffer_size = index_size;
  1002. }
  1003. store_transform(Transform(), state.canvas_item_ubo_data.projection_matrix);
  1004. glGenBuffers(1, &state.canvas_item_ubo);
  1005. glBindBuffer(GL_UNIFORM_BUFFER, state.canvas_item_ubo);
  1006. glBufferData(GL_UNIFORM_BUFFER, sizeof(CanvasItemUBO), &state.canvas_item_ubo_data, GL_DYNAMIC_DRAW);
  1007. glBindBuffer(GL_UNIFORM_BUFFER, 0);
  1008. state.canvas_shader.init();
  1009. state.canvas_shader.set_base_material_tex_index(2);
  1010. state.canvas_shadow_shader.init();
  1011. state.lens_shader.init();
  1012. state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_RGBA_SHADOWS, storage->config.use_rgba_2d_shadows);
  1013. state.canvas_shadow_shader.set_conditional(CanvasShadowShaderGLES3::USE_RGBA_SHADOWS, storage->config.use_rgba_2d_shadows);
  1014. state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_PIXEL_SNAP, GLOBAL_DEF("rendering/2d/snapping/use_gpu_pixel_snap", false));
  1015. }
  1016. void RasterizerCanvasBaseGLES3::finalize() {
  1017. glDeleteBuffers(1, &data.canvas_quad_vertices);
  1018. glDeleteVertexArrays(1, &data.canvas_quad_array);
  1019. glDeleteBuffers(1, &data.canvas_quad_vertices);
  1020. glDeleteVertexArrays(1, &data.canvas_quad_array);
  1021. glDeleteVertexArrays(1, &data.polygon_buffer_pointer_array);
  1022. }
  1023. RasterizerCanvasBaseGLES3::RasterizerCanvasBaseGLES3() {
  1024. }