rasterizer_gles3.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. /**************************************************************************/
  2. /* rasterizer_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_gles3.h"
  31. #include "storage/utilities.h"
  32. #ifdef GLES3_ENABLED
  33. #include "core/config/project_settings.h"
  34. #include "core/io/dir_access.h"
  35. #include "core/os/os.h"
  36. #include "storage/texture_storage.h"
  37. #define _EXT_DEBUG_OUTPUT_SYNCHRONOUS_ARB 0x8242
  38. #define _EXT_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_ARB 0x8243
  39. #define _EXT_DEBUG_CALLBACK_FUNCTION_ARB 0x8244
  40. #define _EXT_DEBUG_CALLBACK_USER_PARAM_ARB 0x8245
  41. #define _EXT_DEBUG_SOURCE_API_ARB 0x8246
  42. #define _EXT_DEBUG_SOURCE_WINDOW_SYSTEM_ARB 0x8247
  43. #define _EXT_DEBUG_SOURCE_SHADER_COMPILER_ARB 0x8248
  44. #define _EXT_DEBUG_SOURCE_THIRD_PARTY_ARB 0x8249
  45. #define _EXT_DEBUG_SOURCE_APPLICATION_ARB 0x824A
  46. #define _EXT_DEBUG_SOURCE_OTHER_ARB 0x824B
  47. #define _EXT_DEBUG_TYPE_ERROR_ARB 0x824C
  48. #define _EXT_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB 0x824D
  49. #define _EXT_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB 0x824E
  50. #define _EXT_DEBUG_TYPE_PORTABILITY_ARB 0x824F
  51. #define _EXT_DEBUG_TYPE_PERFORMANCE_ARB 0x8250
  52. #define _EXT_DEBUG_TYPE_OTHER_ARB 0x8251
  53. #define _EXT_MAX_DEBUG_MESSAGE_LENGTH_ARB 0x9143
  54. #define _EXT_MAX_DEBUG_LOGGED_MESSAGES_ARB 0x9144
  55. #define _EXT_DEBUG_LOGGED_MESSAGES_ARB 0x9145
  56. #define _EXT_DEBUG_SEVERITY_HIGH_ARB 0x9146
  57. #define _EXT_DEBUG_SEVERITY_MEDIUM_ARB 0x9147
  58. #define _EXT_DEBUG_SEVERITY_LOW_ARB 0x9148
  59. #define _EXT_DEBUG_OUTPUT 0x92E0
  60. #ifndef GLAPIENTRY
  61. #if defined(WINDOWS_ENABLED)
  62. #define GLAPIENTRY APIENTRY
  63. #else
  64. #define GLAPIENTRY
  65. #endif
  66. #endif
  67. #if !defined(IOS_ENABLED) && !defined(WEB_ENABLED)
  68. // We include EGL below to get debug callback on GLES2 platforms,
  69. // but EGL is not available on iOS.
  70. #define CAN_DEBUG
  71. #endif
  72. #include "platform_gl.h"
  73. #if defined(MINGW_ENABLED) || defined(_MSC_VER)
  74. #define strcpy strcpy_s
  75. #endif
  76. bool RasterizerGLES3::gles_over_gl = true;
  77. void RasterizerGLES3::begin_frame(double frame_step) {
  78. frame++;
  79. delta = frame_step;
  80. time_total += frame_step;
  81. double time_roll_over = GLOBAL_GET("rendering/limits/time/time_rollover_secs");
  82. time_total = Math::fmod(time_total, time_roll_over);
  83. canvas->set_time(time_total);
  84. scene->set_time(time_total, frame_step);
  85. GLES3::Utilities *utils = GLES3::Utilities::get_singleton();
  86. utils->_capture_timestamps_begin();
  87. //scene->iteration();
  88. }
  89. void RasterizerGLES3::end_frame(bool p_swap_buffers) {
  90. if (p_swap_buffers) {
  91. DisplayServer::get_singleton()->swap_buffers();
  92. } else {
  93. glFinish();
  94. }
  95. }
  96. void RasterizerGLES3::clear_depth(float p_depth) {
  97. #ifdef GL_API_ENABLED
  98. if (is_gles_over_gl()) {
  99. glClearDepth(p_depth);
  100. }
  101. #endif // GL_API_ENABLED
  102. #ifdef GLES_API_ENABLED
  103. if (!is_gles_over_gl()) {
  104. glClearDepthf(p_depth);
  105. }
  106. #endif // GLES_API_ENABLED
  107. }
  108. #ifdef CAN_DEBUG
  109. static void GLAPIENTRY _gl_debug_print(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const GLvoid *userParam) {
  110. if (type == _EXT_DEBUG_TYPE_OTHER_ARB) {
  111. return;
  112. }
  113. if (type == _EXT_DEBUG_TYPE_PERFORMANCE_ARB) {
  114. return; //these are ultimately annoying, so removing for now
  115. }
  116. char debSource[256], debType[256], debSev[256];
  117. if (source == _EXT_DEBUG_SOURCE_API_ARB) {
  118. strcpy(debSource, "OpenGL");
  119. } else if (source == _EXT_DEBUG_SOURCE_WINDOW_SYSTEM_ARB) {
  120. strcpy(debSource, "Windows");
  121. } else if (source == _EXT_DEBUG_SOURCE_SHADER_COMPILER_ARB) {
  122. strcpy(debSource, "Shader Compiler");
  123. } else if (source == _EXT_DEBUG_SOURCE_THIRD_PARTY_ARB) {
  124. strcpy(debSource, "Third Party");
  125. } else if (source == _EXT_DEBUG_SOURCE_APPLICATION_ARB) {
  126. strcpy(debSource, "Application");
  127. } else if (source == _EXT_DEBUG_SOURCE_OTHER_ARB) {
  128. strcpy(debSource, "Other");
  129. }
  130. if (type == _EXT_DEBUG_TYPE_ERROR_ARB) {
  131. strcpy(debType, "Error");
  132. } else if (type == _EXT_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB) {
  133. strcpy(debType, "Deprecated behavior");
  134. } else if (type == _EXT_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB) {
  135. strcpy(debType, "Undefined behavior");
  136. } else if (type == _EXT_DEBUG_TYPE_PORTABILITY_ARB) {
  137. strcpy(debType, "Portability");
  138. } else if (type == _EXT_DEBUG_TYPE_PERFORMANCE_ARB) {
  139. strcpy(debType, "Performance");
  140. } else if (type == _EXT_DEBUG_TYPE_OTHER_ARB) {
  141. strcpy(debType, "Other");
  142. }
  143. if (severity == _EXT_DEBUG_SEVERITY_HIGH_ARB) {
  144. strcpy(debSev, "High");
  145. } else if (severity == _EXT_DEBUG_SEVERITY_MEDIUM_ARB) {
  146. strcpy(debSev, "Medium");
  147. } else if (severity == _EXT_DEBUG_SEVERITY_LOW_ARB) {
  148. strcpy(debSev, "Low");
  149. }
  150. String output = String() + "GL ERROR: Source: " + debSource + "\tType: " + debType + "\tID: " + itos(id) + "\tSeverity: " + debSev + "\tMessage: " + message;
  151. ERR_PRINT(output);
  152. }
  153. #endif
  154. typedef void(GLAPIENTRY *DEBUGPROCARB)(GLenum source,
  155. GLenum type,
  156. GLuint id,
  157. GLenum severity,
  158. GLsizei length,
  159. const char *message,
  160. const void *userParam);
  161. typedef void(GLAPIENTRY *DebugMessageCallbackARB)(DEBUGPROCARB callback, const void *userParam);
  162. void RasterizerGLES3::initialize() {
  163. print_line(vformat("OpenGL API %s - Compatibility - Using Device: %s - %s", RS::get_singleton()->get_video_adapter_api_version(), RS::get_singleton()->get_video_adapter_vendor(), RS::get_singleton()->get_video_adapter_name()));
  164. }
  165. void RasterizerGLES3::finalize() {
  166. memdelete(scene);
  167. memdelete(canvas);
  168. memdelete(gi);
  169. memdelete(fog);
  170. memdelete(copy_effects);
  171. memdelete(light_storage);
  172. memdelete(particles_storage);
  173. memdelete(mesh_storage);
  174. memdelete(material_storage);
  175. memdelete(texture_storage);
  176. memdelete(utilities);
  177. memdelete(config);
  178. }
  179. RasterizerGLES3 *RasterizerGLES3::singleton = nullptr;
  180. #ifdef EGL_ENABLED
  181. void *_egl_load_function_wrapper(const char *p_name) {
  182. return (void *)eglGetProcAddress(p_name);
  183. }
  184. #endif
  185. RasterizerGLES3::RasterizerGLES3() {
  186. singleton = this;
  187. #ifdef GLAD_ENABLED
  188. bool glad_loaded = false;
  189. #ifdef EGL_ENABLED
  190. // There should be a more flexible system for getting the GL pointer, as
  191. // different DisplayServers can have different ways. We can just use the GLAD
  192. // version global to see if it loaded for now though, otherwise we fall back to
  193. // the generic loader below.
  194. #if defined(EGL_STATIC)
  195. bool has_egl = true;
  196. #else
  197. bool has_egl = (eglGetProcAddress != nullptr);
  198. #endif
  199. if (gles_over_gl) {
  200. if (has_egl && !glad_loaded && gladLoadGL((GLADloadfunc)&_egl_load_function_wrapper)) {
  201. glad_loaded = true;
  202. }
  203. } else {
  204. if (has_egl && !glad_loaded && gladLoadGLES2((GLADloadfunc)&_egl_load_function_wrapper)) {
  205. glad_loaded = true;
  206. }
  207. }
  208. #endif // EGL_ENABLED
  209. if (gles_over_gl) {
  210. if (!glad_loaded && gladLoaderLoadGL()) {
  211. glad_loaded = true;
  212. }
  213. } else {
  214. if (!glad_loaded && gladLoaderLoadGLES2()) {
  215. glad_loaded = true;
  216. }
  217. }
  218. // FIXME this is an early return from a constructor. Any other code using this instance will crash or the finalizer will crash, because none of
  219. // the members of this instance are initialized, so this just makes debugging harder. It should either crash here intentionally,
  220. // or we need to actually test for this situation before constructing this.
  221. ERR_FAIL_COND_MSG(!glad_loaded, "Error initializing GLAD.");
  222. if (gles_over_gl) {
  223. if (OS::get_singleton()->is_stdout_verbose()) {
  224. if (GLAD_GL_ARB_debug_output) {
  225. glEnable(_EXT_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
  226. glDebugMessageCallbackARB((GLDEBUGPROCARB)_gl_debug_print, nullptr);
  227. glEnable(_EXT_DEBUG_OUTPUT);
  228. } else {
  229. print_line("OpenGL debugging not supported!");
  230. }
  231. }
  232. }
  233. #endif // GLAD_ENABLED
  234. // For debugging
  235. #ifdef CAN_DEBUG
  236. #ifdef GL_API_ENABLED
  237. if (gles_over_gl) {
  238. if (OS::get_singleton()->is_stdout_verbose() && GLAD_GL_ARB_debug_output) {
  239. glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_ERROR_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, nullptr, GL_TRUE);
  240. glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, nullptr, GL_TRUE);
  241. glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, nullptr, GL_TRUE);
  242. glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_PORTABILITY_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, nullptr, GL_TRUE);
  243. glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_PERFORMANCE_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, nullptr, GL_TRUE);
  244. glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_OTHER_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, nullptr, GL_TRUE);
  245. }
  246. }
  247. #endif // GL_API_ENABLED
  248. #ifdef GLES_API_ENABLED
  249. if (!gles_over_gl) {
  250. if (OS::get_singleton()->is_stdout_verbose()) {
  251. DebugMessageCallbackARB callback = (DebugMessageCallbackARB)eglGetProcAddress("glDebugMessageCallback");
  252. if (!callback) {
  253. callback = (DebugMessageCallbackARB)eglGetProcAddress("glDebugMessageCallbackKHR");
  254. }
  255. if (callback) {
  256. print_line("godot: ENABLING GL DEBUG");
  257. glEnable(_EXT_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
  258. callback((DEBUGPROCARB)_gl_debug_print, NULL);
  259. glEnable(_EXT_DEBUG_OUTPUT);
  260. }
  261. }
  262. }
  263. #endif // GLES_API_ENABLED
  264. #endif // CAN_DEBUG
  265. {
  266. String shader_cache_dir = Engine::get_singleton()->get_shader_cache_path();
  267. if (shader_cache_dir.is_empty()) {
  268. shader_cache_dir = "user://";
  269. }
  270. Ref<DirAccess> da = DirAccess::open(shader_cache_dir);
  271. if (da.is_null()) {
  272. ERR_PRINT("Can't create shader cache folder, no shader caching will happen: " + shader_cache_dir);
  273. } else {
  274. Error err = da->change_dir("shader_cache");
  275. if (err != OK) {
  276. err = da->make_dir("shader_cache");
  277. }
  278. if (err != OK) {
  279. ERR_PRINT("Can't create shader cache folder, no shader caching will happen: " + shader_cache_dir);
  280. } else {
  281. shader_cache_dir = shader_cache_dir.path_join("shader_cache");
  282. bool shader_cache_enabled = GLOBAL_GET("rendering/shader_compiler/shader_cache/enabled");
  283. if (!Engine::get_singleton()->is_editor_hint() && !shader_cache_enabled) {
  284. shader_cache_dir = String(); //disable only if not editor
  285. }
  286. if (!shader_cache_dir.is_empty()) {
  287. ShaderGLES3::set_shader_cache_dir(shader_cache_dir);
  288. }
  289. }
  290. }
  291. }
  292. // OpenGL needs to be initialized before initializing the Rasterizers
  293. config = memnew(GLES3::Config);
  294. utilities = memnew(GLES3::Utilities);
  295. texture_storage = memnew(GLES3::TextureStorage);
  296. material_storage = memnew(GLES3::MaterialStorage);
  297. mesh_storage = memnew(GLES3::MeshStorage);
  298. particles_storage = memnew(GLES3::ParticlesStorage);
  299. light_storage = memnew(GLES3::LightStorage);
  300. copy_effects = memnew(GLES3::CopyEffects);
  301. gi = memnew(GLES3::GI);
  302. fog = memnew(GLES3::Fog);
  303. canvas = memnew(RasterizerCanvasGLES3());
  304. scene = memnew(RasterizerSceneGLES3());
  305. }
  306. RasterizerGLES3::~RasterizerGLES3() {
  307. }
  308. void RasterizerGLES3::prepare_for_blitting_render_targets() {
  309. // This is a hack, but this function is called one time after all viewports have been updated.
  310. // So it marks the end of the frame for all viewports
  311. // In the OpenGL renderer we have to call end_frame for each viewport so we can swap the
  312. // buffers for each window before proceeding to the next.
  313. // This allows us to only increment the frame after all viewports are done.
  314. GLES3::Utilities *utils = GLES3::Utilities::get_singleton();
  315. utils->capture_timestamps_end();
  316. }
  317. void RasterizerGLES3::_blit_render_target_to_screen(RID p_render_target, DisplayServer::WindowID p_screen, const Rect2 &p_screen_rect, uint32_t p_layer, bool p_first) {
  318. GLES3::RenderTarget *rt = GLES3::TextureStorage::get_singleton()->get_render_target(p_render_target);
  319. ERR_FAIL_NULL(rt);
  320. // We normally render to the render target upside down, so flip Y when blitting to the screen.
  321. bool flip_y = true;
  322. if (rt->overridden.color.is_valid()) {
  323. // If we've overridden the render target's color texture, that means we
  324. // didn't render upside down, so we don't need to flip it.
  325. // We're probably rendering directly to an XR device.
  326. flip_y = false;
  327. }
  328. GLuint read_fbo = 0;
  329. glGenFramebuffers(1, &read_fbo);
  330. glBindFramebuffer(GL_READ_FRAMEBUFFER, read_fbo);
  331. if (rt->view_count > 1) {
  332. glFramebufferTextureLayer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, rt->color, 0, p_layer);
  333. } else {
  334. glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rt->color, 0);
  335. }
  336. glReadBuffer(GL_COLOR_ATTACHMENT0);
  337. glBindFramebuffer(GL_DRAW_FRAMEBUFFER, GLES3::TextureStorage::system_fbo);
  338. if (p_first) {
  339. Size2i win_size = DisplayServer::get_singleton()->window_get_size();
  340. if (p_screen_rect.position != Vector2() || p_screen_rect.size != rt->size) {
  341. // Viewport doesn't cover entire window so clear window to black before blitting.
  342. glViewport(0, 0, win_size.width, win_size.height);
  343. glClearColor(0.0, 0.0, 0.0, 1.0);
  344. glClear(GL_COLOR_BUFFER_BIT);
  345. }
  346. }
  347. Vector2i screen_rect_end = p_screen_rect.get_end();
  348. glBlitFramebuffer(0, 0, rt->size.x, rt->size.y,
  349. p_screen_rect.position.x, flip_y ? screen_rect_end.y : p_screen_rect.position.y, screen_rect_end.x, flip_y ? p_screen_rect.position.y : screen_rect_end.y,
  350. GL_COLOR_BUFFER_BIT, GL_NEAREST);
  351. if (read_fbo != 0) {
  352. glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
  353. glDeleteFramebuffers(1, &read_fbo);
  354. }
  355. }
  356. // is this p_screen useless in a multi window environment?
  357. void RasterizerGLES3::blit_render_targets_to_screen(DisplayServer::WindowID p_screen, const BlitToScreen *p_render_targets, int p_amount) {
  358. for (int i = 0; i < p_amount; i++) {
  359. const BlitToScreen &blit = p_render_targets[i];
  360. RID rid_rt = blit.render_target;
  361. Rect2 dst_rect = blit.dst_rect;
  362. _blit_render_target_to_screen(rid_rt, p_screen, dst_rect, blit.multi_view.use_layer ? blit.multi_view.layer : 0, i == 0);
  363. }
  364. }
  365. void RasterizerGLES3::set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter) {
  366. if (p_image.is_null() || p_image->is_empty()) {
  367. return;
  368. }
  369. Size2i win_size = DisplayServer::get_singleton()->window_get_size();
  370. glBindFramebuffer(GL_FRAMEBUFFER, 0);
  371. glViewport(0, 0, win_size.width, win_size.height);
  372. glEnable(GL_BLEND);
  373. glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE);
  374. glDepthMask(GL_FALSE);
  375. glClearColor(p_color.r, p_color.g, p_color.b, 1.0);
  376. glClear(GL_COLOR_BUFFER_BIT);
  377. RID texture = texture_storage->texture_allocate();
  378. texture_storage->texture_2d_initialize(texture, p_image);
  379. Rect2 imgrect(0, 0, p_image->get_width(), p_image->get_height());
  380. Rect2 screenrect;
  381. if (p_scale) {
  382. if (win_size.width > win_size.height) {
  383. //scale horizontally
  384. screenrect.size.y = win_size.height;
  385. screenrect.size.x = imgrect.size.x * win_size.height / imgrect.size.y;
  386. screenrect.position.x = (win_size.width - screenrect.size.x) / 2;
  387. } else {
  388. //scale vertically
  389. screenrect.size.x = win_size.width;
  390. screenrect.size.y = imgrect.size.y * win_size.width / imgrect.size.x;
  391. screenrect.position.y = (win_size.height - screenrect.size.y) / 2;
  392. }
  393. } else {
  394. screenrect = imgrect;
  395. screenrect.position += ((Size2(win_size.width, win_size.height) - screenrect.size) / 2.0).floor();
  396. }
  397. // Flip Y.
  398. screenrect.position.y = win_size.y - screenrect.position.y;
  399. screenrect.size.y = -screenrect.size.y;
  400. // Normalize texture coordinates to window size.
  401. screenrect.position /= win_size;
  402. screenrect.size /= win_size;
  403. GLES3::Texture *t = texture_storage->get_texture(texture);
  404. t->gl_set_filter(p_use_filter ? RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR : RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST);
  405. glActiveTexture(GL_TEXTURE0);
  406. glBindTexture(GL_TEXTURE_2D, t->tex_id);
  407. copy_effects->copy_to_rect(screenrect);
  408. glBindTexture(GL_TEXTURE_2D, 0);
  409. end_frame(true);
  410. texture_storage->texture_free(texture);
  411. }
  412. #endif // GLES3_ENABLED