rasterizer_gles2.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. /*************************************************************************/
  2. /* rasterizer_gles2.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "rasterizer_gles2.h"
  31. #include "core/os/os.h"
  32. #include "core/project_settings.h"
  33. #include "drivers/gl_context/context_gl.h"
  34. #define _EXT_DEBUG_OUTPUT_SYNCHRONOUS_ARB 0x8242
  35. #define _EXT_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_ARB 0x8243
  36. #define _EXT_DEBUG_CALLBACK_FUNCTION_ARB 0x8244
  37. #define _EXT_DEBUG_CALLBACK_USER_PARAM_ARB 0x8245
  38. #define _EXT_DEBUG_SOURCE_API_ARB 0x8246
  39. #define _EXT_DEBUG_SOURCE_WINDOW_SYSTEM_ARB 0x8247
  40. #define _EXT_DEBUG_SOURCE_SHADER_COMPILER_ARB 0x8248
  41. #define _EXT_DEBUG_SOURCE_THIRD_PARTY_ARB 0x8249
  42. #define _EXT_DEBUG_SOURCE_APPLICATION_ARB 0x824A
  43. #define _EXT_DEBUG_SOURCE_OTHER_ARB 0x824B
  44. #define _EXT_DEBUG_TYPE_ERROR_ARB 0x824C
  45. #define _EXT_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB 0x824D
  46. #define _EXT_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB 0x824E
  47. #define _EXT_DEBUG_TYPE_PORTABILITY_ARB 0x824F
  48. #define _EXT_DEBUG_TYPE_PERFORMANCE_ARB 0x8250
  49. #define _EXT_DEBUG_TYPE_OTHER_ARB 0x8251
  50. #define _EXT_MAX_DEBUG_MESSAGE_LENGTH_ARB 0x9143
  51. #define _EXT_MAX_DEBUG_LOGGED_MESSAGES_ARB 0x9144
  52. #define _EXT_DEBUG_LOGGED_MESSAGES_ARB 0x9145
  53. #define _EXT_DEBUG_SEVERITY_HIGH_ARB 0x9146
  54. #define _EXT_DEBUG_SEVERITY_MEDIUM_ARB 0x9147
  55. #define _EXT_DEBUG_SEVERITY_LOW_ARB 0x9148
  56. #define _EXT_DEBUG_OUTPUT 0x92E0
  57. #ifndef GLAPIENTRY
  58. #if defined(WINDOWS_ENABLED) && !defined(UWP_ENABLED)
  59. #define GLAPIENTRY APIENTRY
  60. #else
  61. #define GLAPIENTRY
  62. #endif
  63. #endif
  64. #ifndef IPHONE_ENABLED
  65. // We include EGL below to get debug callback on GLES2 platforms,
  66. // but EGL is not available on iOS.
  67. #define CAN_DEBUG
  68. #endif
  69. #if !defined(GLES_OVER_GL) && defined(CAN_DEBUG)
  70. #include <GLES2/gl2.h>
  71. #include <GLES2/gl2ext.h>
  72. #include <GLES2/gl2platform.h>
  73. #include <EGL/egl.h>
  74. #include <EGL/eglext.h>
  75. #endif
  76. #if defined(MINGW_ENABLED) || defined(_MSC_VER)
  77. #define strcpy strcpy_s
  78. #endif
  79. #ifdef CAN_DEBUG
  80. static void GLAPIENTRY _gl_debug_print(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const GLvoid *userParam) {
  81. if (type == _EXT_DEBUG_TYPE_OTHER_ARB)
  82. return;
  83. if (type == _EXT_DEBUG_TYPE_PERFORMANCE_ARB)
  84. return; //these are ultimately annoying, so removing for now
  85. char debSource[256], debType[256], debSev[256];
  86. if (source == _EXT_DEBUG_SOURCE_API_ARB)
  87. strcpy(debSource, "OpenGL");
  88. else if (source == _EXT_DEBUG_SOURCE_WINDOW_SYSTEM_ARB)
  89. strcpy(debSource, "Windows");
  90. else if (source == _EXT_DEBUG_SOURCE_SHADER_COMPILER_ARB)
  91. strcpy(debSource, "Shader Compiler");
  92. else if (source == _EXT_DEBUG_SOURCE_THIRD_PARTY_ARB)
  93. strcpy(debSource, "Third Party");
  94. else if (source == _EXT_DEBUG_SOURCE_APPLICATION_ARB)
  95. strcpy(debSource, "Application");
  96. else if (source == _EXT_DEBUG_SOURCE_OTHER_ARB)
  97. strcpy(debSource, "Other");
  98. if (type == _EXT_DEBUG_TYPE_ERROR_ARB)
  99. strcpy(debType, "Error");
  100. else if (type == _EXT_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB)
  101. strcpy(debType, "Deprecated behavior");
  102. else if (type == _EXT_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB)
  103. strcpy(debType, "Undefined behavior");
  104. else if (type == _EXT_DEBUG_TYPE_PORTABILITY_ARB)
  105. strcpy(debType, "Portability");
  106. else if (type == _EXT_DEBUG_TYPE_PERFORMANCE_ARB)
  107. strcpy(debType, "Performance");
  108. else if (type == _EXT_DEBUG_TYPE_OTHER_ARB)
  109. strcpy(debType, "Other");
  110. if (severity == _EXT_DEBUG_SEVERITY_HIGH_ARB)
  111. strcpy(debSev, "High");
  112. else if (severity == _EXT_DEBUG_SEVERITY_MEDIUM_ARB)
  113. strcpy(debSev, "Medium");
  114. else if (severity == _EXT_DEBUG_SEVERITY_LOW_ARB)
  115. strcpy(debSev, "Low");
  116. String output = String() + "GL ERROR: Source: " + debSource + "\tType: " + debType + "\tID: " + itos(id) + "\tSeverity: " + debSev + "\tMessage: " + message;
  117. ERR_PRINTS(output);
  118. }
  119. #endif // CAN_DEBUG
  120. typedef void (*DEBUGPROCARB)(GLenum source,
  121. GLenum type,
  122. GLuint id,
  123. GLenum severity,
  124. GLsizei length,
  125. const char *message,
  126. const void *userParam);
  127. typedef void (*DebugMessageCallbackARB)(DEBUGPROCARB callback, const void *userParam);
  128. RasterizerStorage *RasterizerGLES2::get_storage() {
  129. return storage;
  130. }
  131. RasterizerCanvas *RasterizerGLES2::get_canvas() {
  132. return canvas;
  133. }
  134. RasterizerScene *RasterizerGLES2::get_scene() {
  135. return scene;
  136. }
  137. Error RasterizerGLES2::is_viable() {
  138. #ifdef GLAD_ENABLED
  139. if (!gladLoadGL()) {
  140. ERR_PRINT("Error initializing GLAD");
  141. return ERR_UNAVAILABLE;
  142. }
  143. // GLVersion seems to be used for both GL and GL ES, so we need different version checks for them
  144. #ifdef OPENGL_ENABLED // OpenGL 2.1 Profile required
  145. if (GLVersion.major < 2 || (GLVersion.major == 2 && GLVersion.minor < 1)) {
  146. #else // OpenGL ES 2.0
  147. if (GLVersion.major < 2) {
  148. #endif
  149. return ERR_UNAVAILABLE;
  150. }
  151. #ifdef GLES_OVER_GL
  152. //Test GL_ARB_framebuffer_object extension
  153. if (!GLAD_GL_ARB_framebuffer_object) {
  154. //Try older GL_EXT_framebuffer_object extension
  155. if (GLAD_GL_EXT_framebuffer_object) {
  156. glIsRenderbuffer = glIsRenderbufferEXT;
  157. glBindRenderbuffer = glBindRenderbufferEXT;
  158. glDeleteRenderbuffers = glDeleteRenderbuffersEXT;
  159. glGenRenderbuffers = glGenRenderbuffersEXT;
  160. glRenderbufferStorage = glRenderbufferStorageEXT;
  161. glGetRenderbufferParameteriv = glGetRenderbufferParameterivEXT;
  162. glIsFramebuffer = glIsFramebufferEXT;
  163. glBindFramebuffer = glBindFramebufferEXT;
  164. glDeleteFramebuffers = glDeleteFramebuffersEXT;
  165. glGenFramebuffers = glGenFramebuffersEXT;
  166. glCheckFramebufferStatus = glCheckFramebufferStatusEXT;
  167. glFramebufferTexture1D = glFramebufferTexture1DEXT;
  168. glFramebufferTexture2D = glFramebufferTexture2DEXT;
  169. glFramebufferTexture3D = glFramebufferTexture3DEXT;
  170. glFramebufferRenderbuffer = glFramebufferRenderbufferEXT;
  171. glGetFramebufferAttachmentParameteriv = glGetFramebufferAttachmentParameterivEXT;
  172. glGenerateMipmap = glGenerateMipmapEXT;
  173. } else {
  174. return ERR_UNAVAILABLE;
  175. }
  176. }
  177. #endif // GLES_OVER_GL
  178. #endif // GLAD_ENABLED
  179. return OK;
  180. }
  181. void RasterizerGLES2::initialize() {
  182. print_verbose("Using GLES2 video driver");
  183. #ifdef GLAD_ENABLED
  184. if (OS::get_singleton()->is_stdout_verbose()) {
  185. if (GLAD_GL_ARB_debug_output) {
  186. glEnable(_EXT_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
  187. glDebugMessageCallbackARB(_gl_debug_print, NULL);
  188. glEnable(_EXT_DEBUG_OUTPUT);
  189. } else {
  190. print_line("OpenGL debugging not supported!");
  191. }
  192. }
  193. #endif // GLAD_ENABLED
  194. // For debugging
  195. #ifdef CAN_DEBUG
  196. #ifdef GLES_OVER_GL
  197. if (OS::get_singleton()->is_stdout_verbose() && GLAD_GL_ARB_debug_output) {
  198. glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_ERROR_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, NULL, GL_TRUE);
  199. glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, NULL, GL_TRUE);
  200. glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, NULL, GL_TRUE);
  201. glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_PORTABILITY_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, NULL, GL_TRUE);
  202. glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_PERFORMANCE_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, NULL, GL_TRUE);
  203. glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_OTHER_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, NULL, GL_TRUE);
  204. /* glDebugMessageInsertARB(
  205. GL_DEBUG_SOURCE_API_ARB,
  206. GL_DEBUG_TYPE_OTHER_ARB, 1,
  207. GL_DEBUG_SEVERITY_HIGH_ARB, 5, "hello");
  208. */
  209. }
  210. #else
  211. if (OS::get_singleton()->is_stdout_verbose()) {
  212. DebugMessageCallbackARB callback = (DebugMessageCallbackARB)eglGetProcAddress("glDebugMessageCallback");
  213. if (!callback) {
  214. callback = (DebugMessageCallbackARB)eglGetProcAddress("glDebugMessageCallbackKHR");
  215. }
  216. if (callback) {
  217. print_line("godot: ENABLING GL DEBUG");
  218. glEnable(_EXT_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
  219. callback(_gl_debug_print, NULL);
  220. glEnable(_EXT_DEBUG_OUTPUT);
  221. }
  222. }
  223. #endif // GLES_OVER_GL
  224. #endif // CAN_DEBUG
  225. const GLubyte *renderer = glGetString(GL_RENDERER);
  226. print_line("OpenGL ES 2.0 Renderer: " + String((const char *)renderer));
  227. storage->initialize();
  228. canvas->initialize();
  229. scene->initialize();
  230. }
  231. void RasterizerGLES2::begin_frame(double frame_step) {
  232. time_total += frame_step;
  233. if (frame_step == 0) {
  234. //to avoid hiccups
  235. frame_step = 0.001;
  236. }
  237. // double time_roll_over = GLOBAL_GET("rendering/limits/time/time_rollover_secs");
  238. // if (time_total > time_roll_over)
  239. // time_total = 0; //roll over every day (should be customz
  240. storage->frame.time[0] = time_total;
  241. storage->frame.time[1] = Math::fmod(time_total, 3600);
  242. storage->frame.time[2] = Math::fmod(time_total, 900);
  243. storage->frame.time[3] = Math::fmod(time_total, 60);
  244. storage->frame.count++;
  245. storage->frame.delta = frame_step;
  246. storage->update_dirty_resources();
  247. storage->info.render_final = storage->info.render;
  248. storage->info.render.reset();
  249. scene->iteration();
  250. }
  251. void RasterizerGLES2::set_current_render_target(RID p_render_target) {
  252. if (!p_render_target.is_valid() && storage->frame.current_rt && storage->frame.clear_request) {
  253. // pending clear request. Do that first.
  254. glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->fbo);
  255. glClearColor(storage->frame.clear_request_color.r,
  256. storage->frame.clear_request_color.g,
  257. storage->frame.clear_request_color.b,
  258. storage->frame.clear_request_color.a);
  259. glClear(GL_COLOR_BUFFER_BIT);
  260. }
  261. if (p_render_target.is_valid()) {
  262. RasterizerStorageGLES2::RenderTarget *rt = storage->render_target_owner.getornull(p_render_target);
  263. storage->frame.current_rt = rt;
  264. ERR_FAIL_COND(!rt);
  265. storage->frame.clear_request = false;
  266. glViewport(0, 0, rt->width, rt->height);
  267. } else {
  268. storage->frame.current_rt = NULL;
  269. storage->frame.clear_request = false;
  270. glViewport(0, 0, OS::get_singleton()->get_window_size().width, OS::get_singleton()->get_window_size().height);
  271. glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES2::system_fbo);
  272. }
  273. }
  274. void RasterizerGLES2::restore_render_target() {
  275. ERR_FAIL_COND(storage->frame.current_rt == NULL);
  276. RasterizerStorageGLES2::RenderTarget *rt = storage->frame.current_rt;
  277. glBindFramebuffer(GL_FRAMEBUFFER, rt->fbo);
  278. glViewport(0, 0, rt->width, rt->height);
  279. }
  280. void RasterizerGLES2::clear_render_target(const Color &p_color) {
  281. ERR_FAIL_COND(!storage->frame.current_rt);
  282. storage->frame.clear_request = true;
  283. storage->frame.clear_request_color = p_color;
  284. }
  285. void RasterizerGLES2::set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale) {
  286. if (p_image.is_null() || p_image->empty())
  287. return;
  288. int window_w = OS::get_singleton()->get_video_mode(0).width;
  289. int window_h = OS::get_singleton()->get_video_mode(0).height;
  290. glBindFramebuffer(GL_FRAMEBUFFER, 0);
  291. glViewport(0, 0, window_w, window_h);
  292. glDisable(GL_BLEND);
  293. glDepthMask(GL_FALSE);
  294. if (OS::get_singleton()->get_window_per_pixel_transparency_enabled()) {
  295. glClearColor(0.0, 0.0, 0.0, 0.0);
  296. } else {
  297. glClearColor(p_color.r, p_color.g, p_color.b, 1.0);
  298. }
  299. glClear(GL_COLOR_BUFFER_BIT);
  300. canvas->canvas_begin();
  301. RID texture = storage->texture_create();
  302. storage->texture_allocate(texture, p_image->get_width(), p_image->get_height(), 0, p_image->get_format(), VS::TEXTURE_TYPE_2D, VS::TEXTURE_FLAG_FILTER);
  303. storage->texture_set_data(texture, p_image);
  304. Rect2 imgrect(0, 0, p_image->get_width(), p_image->get_height());
  305. Rect2 screenrect;
  306. if (p_scale) {
  307. if (window_w > window_h) {
  308. //scale horizontally
  309. screenrect.size.y = window_h;
  310. screenrect.size.x = imgrect.size.x * window_h / imgrect.size.y;
  311. screenrect.position.x = (window_w - screenrect.size.x) / 2;
  312. } else {
  313. //scale vertically
  314. screenrect.size.x = window_w;
  315. screenrect.size.y = imgrect.size.y * window_w / imgrect.size.x;
  316. screenrect.position.y = (window_h - screenrect.size.y) / 2;
  317. }
  318. } else {
  319. screenrect = imgrect;
  320. screenrect.position += ((Size2(window_w, window_h) - screenrect.size) / 2.0).floor();
  321. }
  322. RasterizerStorageGLES2::Texture *t = storage->texture_owner.get(texture);
  323. glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 1);
  324. glBindTexture(GL_TEXTURE_2D, t->tex_id);
  325. canvas->draw_generic_textured_rect(screenrect, Rect2(0, 0, 1, 1));
  326. glBindTexture(GL_TEXTURE_2D, 0);
  327. canvas->canvas_end();
  328. storage->free(texture);
  329. end_frame(true);
  330. }
  331. void RasterizerGLES2::blit_render_target_to_screen(RID p_render_target, const Rect2 &p_screen_rect, int p_screen) {
  332. ERR_FAIL_COND(storage->frame.current_rt);
  333. RasterizerStorageGLES2::RenderTarget *rt = storage->render_target_owner.getornull(p_render_target);
  334. ERR_FAIL_COND(!rt);
  335. canvas->state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_TEXTURE_RECT, true);
  336. canvas->state.canvas_shader.set_custom_shader(0);
  337. canvas->state.canvas_shader.bind();
  338. canvas->canvas_begin();
  339. glDisable(GL_BLEND);
  340. glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES2::system_fbo);
  341. glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 1);
  342. glBindTexture(GL_TEXTURE_2D, rt->color);
  343. // TODO normals
  344. canvas->draw_generic_textured_rect(p_screen_rect, Rect2(0, 0, 1, -1));
  345. glBindTexture(GL_TEXTURE_2D, 0);
  346. canvas->canvas_end();
  347. }
  348. void RasterizerGLES2::output_lens_distorted_to_screen(RID p_render_target, const Rect2 &p_screen_rect, float p_k1, float p_k2, const Vector2 &p_eye_center, float p_oversample) {
  349. ERR_FAIL_COND(storage->frame.current_rt);
  350. RasterizerStorageGLES2::RenderTarget *rt = storage->render_target_owner.getornull(p_render_target);
  351. ERR_FAIL_COND(!rt);
  352. glDisable(GL_BLEND);
  353. // render to our framebuffer
  354. glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES2::system_fbo);
  355. // output our texture
  356. glActiveTexture(GL_TEXTURE0);
  357. glBindTexture(GL_TEXTURE_2D, rt->color);
  358. canvas->draw_lens_distortion_rect(p_screen_rect, p_k1, p_k2, p_eye_center, p_oversample);
  359. glBindTexture(GL_TEXTURE_2D, 0);
  360. }
  361. void RasterizerGLES2::end_frame(bool p_swap_buffers) {
  362. if (OS::get_singleton()->is_layered_allowed()) {
  363. if (OS::get_singleton()->get_window_per_pixel_transparency_enabled()) {
  364. #if (defined WINDOWS_ENABLED) && !(defined UWP_ENABLED)
  365. Size2 wndsize = OS::get_singleton()->get_layered_buffer_size();
  366. uint8_t *data = OS::get_singleton()->get_layered_buffer_data();
  367. if (data) {
  368. glReadPixels(0, 0, wndsize.x, wndsize.y, GL_BGRA, GL_UNSIGNED_BYTE, data);
  369. OS::get_singleton()->swap_layered_buffer();
  370. return;
  371. }
  372. #endif
  373. } else {
  374. //clear alpha
  375. glColorMask(false, false, false, true);
  376. glClearColor(0, 0, 0, 1);
  377. glClear(GL_COLOR_BUFFER_BIT);
  378. glColorMask(true, true, true, true);
  379. }
  380. }
  381. if (p_swap_buffers)
  382. OS::get_singleton()->swap_buffers();
  383. else
  384. glFinish();
  385. }
  386. void RasterizerGLES2::finalize() {
  387. }
  388. Rasterizer *RasterizerGLES2::_create_current() {
  389. return memnew(RasterizerGLES2);
  390. }
  391. void RasterizerGLES2::make_current() {
  392. _create_func = _create_current;
  393. }
  394. void RasterizerGLES2::register_config() {
  395. }
  396. RasterizerGLES2::RasterizerGLES2() {
  397. storage = memnew(RasterizerStorageGLES2);
  398. canvas = memnew(RasterizerCanvasGLES2);
  399. scene = memnew(RasterizerSceneGLES2);
  400. canvas->storage = storage;
  401. canvas->scene_render = scene;
  402. storage->canvas = canvas;
  403. scene->storage = storage;
  404. storage->scene = scene;
  405. time_total = 0;
  406. }
  407. RasterizerGLES2::~RasterizerGLES2() {
  408. memdelete(storage);
  409. memdelete(canvas);
  410. }