[opengl] Don't flip render target when blitting it to screen if it wasn't rendered upside down

This commit is contained in:
David Snopek 2022-12-04 14:09:52 -06:00
parent 7bffdca41c
commit 5af751bfb7

View file

@ -285,6 +285,15 @@ void RasterizerGLES3::_blit_render_target_to_screen(RID p_render_target, Display
ERR_FAIL_COND(!rt);
// We normally render to the render target upside down, so flip Y when blitting to the screen.
bool flip_y = true;
if (rt->overridden.color.is_valid()) {
// If we've overridden the render target's color texture, that means we
// didn't render upside down, so we don't need to flip it.
// We're probably rendering directly to an XR device.
flip_y = false;
}
GLuint read_fbo = 0;
if (rt->view_count > 1) {
glGenFramebuffers(1, &read_fbo);
@ -296,10 +305,9 @@ void RasterizerGLES3::_blit_render_target_to_screen(RID p_render_target, Display
glReadBuffer(GL_COLOR_ATTACHMENT0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, GLES3::TextureStorage::system_fbo);
// Flip content upside down to correct for coordinates.
Vector2i screen_rect_end = p_screen_rect.get_end();
glBlitFramebuffer(0, 0, rt->size.x, rt->size.y,
p_screen_rect.position.x, screen_rect_end.y, screen_rect_end.x, p_screen_rect.position.y,
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,
GL_COLOR_BUFFER_BIT, GL_NEAREST);
if (read_fbo != 0) {