From e7139fe0d1c8bafdf1dca3fce4fa2a9e4a31fcdc Mon Sep 17 00:00:00 2001
From: dankcushions <chris.bransden@gmail.com>
Date: Mon, 30 Nov 2020 14:08:26 +0000
Subject: [PATCH] OES_copy_image support

---
 src/core/gpu_hw_opengl.cpp | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/core/gpu_hw_opengl.cpp b/src/core/gpu_hw_opengl.cpp
index 27830a6e1..bc22de507 100644
--- a/src/core/gpu_hw_opengl.cpp
+++ b/src/core/gpu_hw_opengl.cpp
@@ -208,8 +208,8 @@ void GPU_HW_OpenGL::SetCapabilities(HostDisplay* host_display)
   glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, reinterpret_cast<GLint*>(&m_uniform_buffer_alignment));
   Log_InfoPrintf("Uniform buffer offset alignment: %u", m_uniform_buffer_alignment);
 
-  if (!GLAD_GL_VERSION_4_3 && !GLAD_GL_EXT_copy_image)
-    Log_WarningPrintf("GL_EXT_copy_image missing, this may affect performance.");
+  if (!GLAD_GL_VERSION_4_3 && !GLAD_GL_EXT_copy_image && !GLAD_GL_ES_VERSION_3_2 && !GLAD_GL_OES_copy_image)
+    Log_WarningPrintf("GL_EXT/OES_copy_image missing, this may affect performance.");
 
 #ifdef __APPLE__
   // Partial texture buffer uploads appear to be broken in macOS's OpenGL driver.
@@ -1000,6 +1000,11 @@ void GPU_HW_OpenGL::CopyVRAM(u32 src_x, u32 src_y, u32 dst_x, u32 dst_y, u32 wid
     glCopyImageSubDataEXT(m_vram_texture.GetGLId(), m_vram_texture.GetGLTarget(), 0, src_x, src_y, 0,
                           m_vram_texture.GetGLId(), m_vram_texture.GetGLTarget(), 0, dst_x, dst_y, 0, width, height, 1);
   }
+  else if (GLAD_GL_OES_copy_image)
+  {
+    glCopyImageSubDataOES(m_vram_texture.GetGLId(), m_vram_texture.GetGLTarget(), 0, src_x, src_y, 0,
+                          m_vram_texture.GetGLId(), m_vram_texture.GetGLTarget(), 0, dst_x, dst_y, 0, width, height, 1);
+  }
   else
   {
     glDisable(GL_SCISSOR_TEST);
@@ -1029,6 +1034,11 @@ void GPU_HW_OpenGL::UpdateVRAMReadTexture()
     glCopyImageSubDataEXT(m_vram_texture.GetGLId(), m_vram_texture.GetGLTarget(), 0, x, y, 0,
                           m_vram_read_texture.GetGLId(), m_vram_texture.GetGLTarget(), 0, x, y, 0, width, height, 1);
   }
+  else if (!multisampled && GLAD_GL_OES_copy_image)
+  {
+    glCopyImageSubDataOES(m_vram_texture.GetGLId(), m_vram_texture.GetGLTarget(), 0, x, y, 0,
+                          m_vram_read_texture.GetGLId(), m_vram_texture.GetGLTarget(), 0, x, y, 0, width, height, 1);
+  }
   else
   {
     m_vram_read_texture.BindFramebuffer(GL_DRAW_FRAMEBUFFER);