From 34231f5ba0f47050fe2c6d50d0810903c262c7f1 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Wed, 23 Nov 2022 18:50:02 +0300
Subject: [PATCH] reverted opengles removal.
---
.gitignore | 1 +
CMakeLists.txt | 13 +-
Makefile.in | 1 +
VisualC-GDK/SDL/SDL.vcxproj | 1 +
VisualC-GDK/SDL/SDL.vcxproj.filters | 3 +
VisualC/SDL/SDL.vcxproj | 1 +
VisualC/SDL/SDL.vcxproj.filters | 3 +
cmake/sdlchecks.cmake | 9 +
configure | 54 +
configure.ac | 21 +
docs/doxyfile | 1 +
include/SDL_config.h.cmake | 2 +
include/SDL_config.h.in | 2 +
include/SDL_config_android.h | 2 +
include/SDL_config_emscripten.h | 1 +
include/SDL_config_iphoneos.h | 2 +
include/SDL_opengles.h | 39 +
src/render/SDL_render.c | 3 +
src/render/SDL_sysrender.h | 1 +
src/render/opengles/SDL_glesfuncs.h | 62 ++
src/render/opengles/SDL_render_gles.c | 1218 +++++++++++++++++++++
src/video/SDL_sysvideo.h | 2 +-
src/video/SDL_video.c | 18 +-
src/video/uikit/SDL_uikitevents.m | 2 +-
src/video/uikit/SDL_uikitopengles.h | 4 +-
src/video/uikit/SDL_uikitopengles.m | 2 +-
src/video/uikit/SDL_uikitopenglview.h | 4 +-
src/video/uikit/SDL_uikitopenglview.m | 2 +-
src/video/uikit/SDL_uikitvideo.m | 2 +-
src/video/uikit/SDL_uikitviewcontroller.m | 2 +-
src/video/uikit/SDL_uikitwindow.m | 2 +-
src/video/x11/SDL_x11window.c | 2 +-
test/CMakeLists.txt | 1 +
test/Makefile.in | 4 +
test/configure | 35 +
test/configure.ac | 18 +
test/testgles.c | 355 ++++++
37 files changed, 1877 insertions(+), 18 deletions(-)
create mode 100644 include/SDL_opengles.h
create mode 100644 src/render/opengles/SDL_glesfuncs.h
create mode 100644 src/render/opengles/SDL_render_gles.c
create mode 100644 test/testgles.c
diff --git a/.gitignore b/.gitignore
index c3d7b1e9a6ed..099b15322da0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -118,6 +118,7 @@ test/testgamecontroller
test/testgeometry
test/testgesture
test/testgl2
+test/testgles
test/testgles2
test/testhaptic
test/testhittesting
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8b72faf17ff2..1386072d66df 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1290,6 +1290,8 @@ if(ANDROID)
if(SDL_OPENGLES)
set(SDL_VIDEO_OPENGL_EGL 1)
set(HAVE_OPENGLES TRUE)
+ set(SDL_VIDEO_OPENGL_ES 1)
+ set(SDL_VIDEO_RENDER_OGL_ES 1)
set(SDL_VIDEO_OPENGL_ES2 1)
set(SDL_VIDEO_RENDER_OGL_ES2 1)
@@ -2091,7 +2093,11 @@ elseif(APPLE)
endif()
if(SDL_OPENGLES)
- if(NOT (IOS OR TVOS))
+ if(IOS OR TVOS)
+ set(SDL_FRAMEWORK_OPENGLES 1)
+ set(SDL_VIDEO_OPENGL_ES 1)
+ set(SDL_VIDEO_RENDER_OGL_ES 1)
+ else()
set(SDL_VIDEO_OPENGL_EGL 1)
endif()
set(SDL_VIDEO_OPENGL_ES2 1)
@@ -2180,6 +2186,9 @@ elseif(APPLE)
list(APPEND EXTRA_LDFLAGS "-Wl,-weak_framework,Metal")
endif()
endif()
+ if(SDL_FRAMEWORK_OPENGLES)
+ list(APPEND EXTRA_LDFLAGS "-Wl,-framework,OpenGLES")
+ endif()
if(SDL_FRAMEWORK_QUARTZCORE)
if(IOS OR TVOS)
list(APPEND EXTRA_LDFLAGS "-Wl,-framework,QuartzCore")
@@ -2402,6 +2411,8 @@ elseif(VITA)
check_include_file(gl4esinit.h HAVE_GL4ES_H)
set(SDL_VIDEO_OPENGL_EGL 1)
set(HAVE_OPENGLES TRUE)
+ set(SDL_VIDEO_OPENGL_ES 1)
+ set(SDL_VIDEO_RENDER_OGL_ES 1)
set(SDL_VIDEO_OPENGL_ES2 1)
set(SDL_VIDEO_RENDER_OGL_ES2 1)
diff --git a/Makefile.in b/Makefile.in
index 5ff6e8beb463..96dfed9ace7d 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -100,6 +100,7 @@ HDRS = \
SDL_name.h \
SDL_opengl.h \
SDL_opengl_glext.h \
+ SDL_opengles.h \
SDL_opengles2_gl2ext.h \
SDL_opengles2_gl2.h \
SDL_opengles2_gl2platform.h \
diff --git a/VisualC-GDK/SDL/SDL.vcxproj b/VisualC-GDK/SDL/SDL.vcxproj
index 5e5179772f12..cc02748da41f 100644
--- a/VisualC-GDK/SDL/SDL.vcxproj
+++ b/VisualC-GDK/SDL/SDL.vcxproj
@@ -329,6 +329,7 @@
<ClInclude Include="..\..\include\SDL_name.h" />
<ClInclude Include="..\..\include\SDL_opengl.h" />
<ClInclude Include="..\..\include\SDL_opengl_glext.h" />
+ <ClInclude Include="..\..\include\SDL_opengles.h" />
<ClInclude Include="..\..\include\SDL_opengles2.h" />
<ClInclude Include="..\..\include\SDL_opengles2_gl2.h" />
<ClInclude Include="..\..\include\SDL_opengles2_gl2ext.h" />
diff --git a/VisualC-GDK/SDL/SDL.vcxproj.filters b/VisualC-GDK/SDL/SDL.vcxproj.filters
index e45001412c5d..c8a757b1ea83 100644
--- a/VisualC-GDK/SDL/SDL.vcxproj.filters
+++ b/VisualC-GDK/SDL/SDL.vcxproj.filters
@@ -282,6 +282,9 @@
<ClInclude Include="..\..\include\SDL_opengl_glext.h">
<Filter>API Headers</Filter>
</ClInclude>
+ <ClInclude Include="..\..\include\SDL_opengles.h">
+ <Filter>API Headers</Filter>
+ </ClInclude>
<ClInclude Include="..\..\include\SDL_opengles2.h">
<Filter>API Headers</Filter>
</ClInclude>
diff --git a/VisualC/SDL/SDL.vcxproj b/VisualC/SDL/SDL.vcxproj
index 821777883ab8..d1adc6b98e1f 100644
--- a/VisualC/SDL/SDL.vcxproj
+++ b/VisualC/SDL/SDL.vcxproj
@@ -253,6 +253,7 @@
<ClInclude Include="..\..\include\SDL_name.h" />
<ClInclude Include="..\..\include\SDL_opengl.h" />
<ClInclude Include="..\..\include\SDL_opengl_glext.h" />
+ <ClInclude Include="..\..\include\SDL_opengles.h" />
<ClInclude Include="..\..\include\SDL_opengles2.h" />
<ClInclude Include="..\..\include\SDL_opengles2_gl2.h" />
<ClInclude Include="..\..\include\SDL_opengles2_gl2ext.h" />
diff --git a/VisualC/SDL/SDL.vcxproj.filters b/VisualC/SDL/SDL.vcxproj.filters
index 9385a7fbbf5a..d5cb6a87ba78 100644
--- a/VisualC/SDL/SDL.vcxproj.filters
+++ b/VisualC/SDL/SDL.vcxproj.filters
@@ -282,6 +282,9 @@
<ClInclude Include="..\..\include\SDL_opengl_glext.h">
<Filter>API Headers</Filter>
</ClInclude>
+ <ClInclude Include="..\..\include\SDL_opengles.h">
+ <Filter>API Headers</Filter>
+ </ClInclude>
<ClInclude Include="..\..\include\SDL_opengles2.h">
<Filter>API Headers</Filter>
</ClInclude>
diff --git a/cmake/sdlchecks.cmake b/cmake/sdlchecks.cmake
index c6a679f7eddd..01fbbc396c85 100644
--- a/cmake/sdlchecks.cmake
+++ b/cmake/sdlchecks.cmake
@@ -700,6 +700,15 @@ endmacro()
# - nada
macro(CheckOpenGLES)
if(SDL_OPENGLES)
+ check_c_source_compiles("
+ #include <GLES/gl.h>
+ #include <GLES/glext.h>
+ int main (int argc, char** argv) { return 0; }" HAVE_OPENGLES_V1)
+ if(HAVE_OPENGLES_V1)
+ set(HAVE_OPENGLES TRUE)
+ set(SDL_VIDEO_OPENGL_ES 1)
+ set(SDL_VIDEO_RENDER_OGL_ES 1)
+ endif()
check_c_source_compiles("
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
diff --git a/configure b/configure
index 0bf207ced960..1e59e861eac0 100755
--- a/configure
+++ b/configure
@@ -911,6 +911,7 @@ enable_video_dummy
enable_video_offscreen
enable_video_opengl
enable_video_opengles
+enable_video_opengles1
enable_video_opengles2
enable_video_vulkan
enable_libudev
@@ -1705,6 +1706,8 @@ Optional Features:
use offscreen video driver [default=yes]
--enable-video-opengl include OpenGL support [default=yes]
--enable-video-opengles include OpenGL ES support [default=yes]
+ --enable-video-opengles1
+ include OpenGL ES 1.1 support [default=yes]
--enable-video-opengles2
include OpenGL ES 2.0 support [default=yes]
--enable-video-vulkan include Vulkan support [default=yes]
@@ -24665,6 +24668,14 @@ else $as_nop
enable_video_opengles=yes
fi
+# Check whether --enable-video-opengles1 was given.
+if test ${enable_video_opengles1+y}
+then :
+ enableval=$enable_video_opengles1;
+else $as_nop
+ enable_video_opengles1=yes
+fi
+
# Check whether --enable-video-opengles2 was given.
if test ${enable_video_opengles2+y}
then :
@@ -24755,6 +24766,42 @@ printf "%s\n" "#define SDL_VIDEO_RENDER_OGL 1" >>confdefs.h
CheckOpenGLES()
{
if test x$enable_video = xyes -a x$enable_video_opengles = xyes; then
+ if test x$enable_video_opengles1 = xyes; then
+ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for OpenGL ES v1 headers" >&5
+printf %s "checking for OpenGL ES v1 headers... " >&6; }
+ video_opengles_v1=no
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+ #include <GLES/gl.h>
+ #include <GLES/glext.h>
+
+int
+main (void)
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"
+then :
+ video_opengles_v1=yes
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
+ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $video_opengles_v1" >&5
+printf "%s\n" "$video_opengles_v1" >&6; }
+ if test x$video_opengles_v1 = xyes; then
+
+printf "%s\n" "#define SDL_VIDEO_OPENGL_ES 1" >>confdefs.h
+
+
+printf "%s\n" "#define SDL_VIDEO_RENDER_OGL_ES 1" >>confdefs.h
+
+ SUMMARY_video="${SUMMARY_video} opengl_es1"
+ fi
+ fi
+
if test x$enable_video_opengles2 = xyes; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for OpenGL ES v2 headers" >&5
printf %s "checking for OpenGL ES v2 headers... " >&6; }
@@ -27930,6 +27977,12 @@ printf "%s\n" "#define SDL_VIDEO_DRIVER_UIKIT 1" >>confdefs.h
printf "%s\n" "#define SDL_VIDEO_OPENGL_ES2 1" >>confdefs.h
+printf "%s\n" "#define SDL_VIDEO_OPENGL_ES 1" >>confdefs.h
+
+
+printf "%s\n" "#define SDL_VIDEO_RENDER_OGL_ES 1" >>confdefs.h
+
+
printf "%s\n" "#define SDL_VIDEO_RENDER_OGL_ES2 1" >>confdefs.h
SOURCES="$SOURCES $srcdir/src/video/uikit/*.m"
@@ -27947,6 +28000,7 @@ printf "%s\n" "#define SDL_VIDEO_RENDER_OGL_ES2 1" >>confdefs.h
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,CoreMotion"
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,Foundation"
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,GameController"
+ EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,OpenGLES"
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,QuartzCore"
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,UIKit"
diff --git a/configure.ac b/configure.ac
index 208ec49c2b4c..f8e71411dda0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2211,6 +2211,9 @@ dnl Check to see if OpenGL ES support is desired
AC_ARG_ENABLE(video-opengles,
[AS_HELP_STRING([--enable-video-opengles], [include OpenGL ES support [default=yes]])],
, enable_video_opengles=yes)
+AC_ARG_ENABLE(video-opengles1,
+[AS_HELP_STRING([--enable-video-opengles1], [include OpenGL ES 1.1 support [default=yes]])],
+ , enable_video_opengles1=yes)
AC_ARG_ENABLE(video-opengles2,
[AS_HELP_STRING([--enable-video-opengles2], [include OpenGL ES 2.0 support [default=yes]])],
, enable_video_opengles2=yes)
@@ -2259,6 +2262,21 @@ dnl Find OpenGL ES
CheckOpenGLES()
{
if test x$enable_video = xyes -a x$enable_video_opengles = xyes; then
+ if test x$enable_video_opengles1 = xyes; then
+ AC_MSG_CHECKING(for OpenGL ES v1 headers)
+ video_opengles_v1=no
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+ #include <GLES/gl.h>
+ #include <GLES/glext.h>
+ ]],[])], [video_opengles_v1=yes],[])
+ AC_MSG_RESULT($video_opengles_v1)
+ if test x$video_opengles_v1 = xyes; then
+ AC_DEFINE(SDL_VIDEO_OPENGL_ES, 1, [ ])
+ AC_DEFINE(SDL_VIDEO_RENDER_OGL_ES, 1, [ ])
+ SUMMARY_video="${SUMMARY_video} opengl_es1"
+ fi
+ fi
+
if test x$enable_video_opengles2 = xyes; then
AC_MSG_CHECKING(for OpenGL ES v2 headers)
video_opengles_v2=no
@@ -3966,6 +3984,8 @@ dnl BeOS support removed after SDL 2.0.1. Haiku still works. --ryan.
# The iOS platform requires special setup.
AC_DEFINE(SDL_VIDEO_DRIVER_UIKIT, 1, [ ])
AC_DEFINE(SDL_VIDEO_OPENGL_ES2, 1, [ ])
+ AC_DEFINE(SDL_VIDEO_OPENGL_ES, 1, [ ])
+ AC_DEFINE(SDL_VIDEO_RENDER_OGL_ES, 1, [ ])
AC_DEFINE(SDL_VIDEO_RENDER_OGL_ES2, 1, [ ])
SOURCES="$SOURCES $srcdir/src/video/uikit/*.m"
SUMMARY_video="${SUMMARY_video} uikit"
@@ -3982,6 +4002,7 @@ dnl BeOS support removed after SDL 2.0.1. Haiku still works. --ryan.
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,CoreMotion"
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,Foundation"
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,GameController"
+ EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,OpenGLES"
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,QuartzCore"
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,UIKit"
diff --git a/docs/doxyfile b/docs/doxyfile
index fa7d2d4837d5..a9d837c320aa 100644
--- a/docs/doxyfile
+++ b/docs/doxyfile
@@ -637,6 +637,7 @@ EXCLUDE = ../include/SDL_opengles2_gl2ext.h \
../include/SDL_opengl_glext.h \
../include/SDL_opengles2_gl2.h \
../include/SDL_opengles2.h \
+ ../include/SDL_opengles.h \
../include/SDL_opengl.h \
../include/SDL_egl.h \
./release_checklist.md \
diff --git a/include/SDL_config.h.cmake b/include/SDL_config.h.cmake
index fef07118ae66..c52ca543739e 100644
--- a/include/SDL_config.h.cmake
+++ b/include/SDL_config.h.cmake
@@ -434,6 +434,7 @@
#cmakedefine SDL_VIDEO_RENDER_D3D11 @SDL_VIDEO_RENDER_D3D11@
#cmakedefine SDL_VIDEO_RENDER_D3D12 @SDL_VIDEO_RENDER_D3D12@
#cmakedefine SDL_VIDEO_RENDER_OGL @SDL_VIDEO_RENDER_OGL@
+#cmakedefine SDL_VIDEO_RENDER_OGL_ES @SDL_VIDEO_RENDER_OGL_ES@
#cmakedefine SDL_VIDEO_RENDER_OGL_ES2 @SDL_VIDEO_RENDER_OGL_ES2@
#cmakedefine SDL_VIDEO_RENDER_METAL @SDL_VIDEO_RENDER_METAL@
#cmakedefine SDL_VIDEO_RENDER_VITA_GXM @SDL_VIDEO_RENDER_VITA_GXM@
@@ -442,6 +443,7 @@
/* Enable OpenGL support */
#cmakedefine SDL_VIDEO_OPENGL @SDL_VIDEO_OPENGL@
+#cmakedefine SDL_VIDEO_OPENGL_ES @SDL_VIDEO_OPENGL_ES@
#cmakedefine SDL_VIDEO_OPENGL_ES2 @SDL_VIDEO_OPENGL_ES2@
#cmakedefine SDL_VIDEO_OPENGL_BGL @SDL_VIDEO_OPENGL_BGL@
#cmakedefine SDL_VIDEO_OPENGL_CGL @SDL_VIDEO_OPENGL_CGL@
diff --git a/include/SDL_config.h.in b/include/SDL_config.h.in
index 0bf7b6fc6061..fe2a2559402b 100644
--- a/include/SDL_config.h.in
+++ b/include/SDL_config.h.in
@@ -395,11 +395,13 @@
#undef SDL_VIDEO_RENDER_D3D11
#undef SDL_VIDEO_RENDER_D3D12
#undef SDL_VIDEO_RENDER_OGL
+#undef SDL_VIDEO_RENDER_OGL_ES
#undef SDL_VIDEO_RENDER_OGL_ES2
#undef SDL_VIDEO_RENDER_METAL
/* Enable OpenGL support */
#undef SDL_VIDEO_OPENGL
+#undef SDL_VIDEO_OPENGL_ES
#undef SDL_VIDEO_OPENGL_ES2
#undef SDL_VIDEO_OPENGL_BGL
#undef SDL_VIDEO_OPENGL_CGL
diff --git a/include/SDL_config_android.h b/include/SDL_config_android.h
index 6707c26d19f3..64918ae0b8a5 100644
--- a/include/SDL_config_android.h
+++ b/include/SDL_config_android.h
@@ -171,8 +171,10 @@
#define SDL_VIDEO_DRIVER_ANDROID 1
/* Enable OpenGL ES */
+#define SDL_VIDEO_OPENGL_ES 1
#define SDL_VIDEO_OPENGL_ES2 1
#define SDL_VIDEO_OPENGL_EGL 1
+#define SDL_VIDEO_RENDER_OGL_ES 1
#define SDL_VIDEO_RENDER_OGL_ES2 1
/* Enable Vulkan support */
diff --git a/include/SDL_config_emscripten.h b/include/SDL_config_emscripten.h
index ea41fc96021f..989e1243a7bb 100644
--- a/include/SDL_config_emscripten.h
+++ b/include/SDL_config_emscripten.h
@@ -199,6 +199,7 @@
/* Enable OpenGL support */
/* #undef SDL_VIDEO_OPENGL */
+/* #undef SDL_VIDEO_OPENGL_ES */
#define SDL_VIDEO_OPENGL_ES2 1
/* #undef SDL_VIDEO_OPENGL_BGL */
/* #undef SDL_VIDEO_OPENGL_CGL */
diff --git a/include/SDL_config_iphoneos.h b/include/SDL_config_iphoneos.h
index 57099b814c31..6db16eb4ccfb 100644
--- a/include/SDL_config_iphoneos.h
+++ b/include/SDL_config_iphoneos.h
@@ -176,6 +176,8 @@
/* Enable OpenGL ES */
#if !TARGET_OS_MACCATALYST
#define SDL_VIDEO_OPENGL_ES2 1
+#define SDL_VIDEO_OPENGL_ES 1
+#define SDL_VIDEO_RENDER_OGL_ES 1
#define SDL_VIDEO_RENDER_OGL_ES2 1
#endif
diff --git a/include/SDL_opengles.h b/include/SDL_opengles.h
new file mode 100644
index 000000000000..8511b9607f11
--- /dev/null
+++ b/include/SDL_opengles.h
@@ -0,0 +1,39 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_opengles.h
+ *
+ * This is a simple file to encapsulate the OpenGL ES 1.X API headers.
+ */
+#include "SDL_config.h"
+
+#ifdef __IPHONEOS__
+#include <OpenGLES/ES1/gl.h>
+#include <OpenGLES/ES1/glext.h>
+#else
+#include <GLES/gl.h>
+#include <GLES/glext.h>
+#endif
+
+#ifndef APIENTRY
+#define APIENTRY
+#endif
diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c
index 39fa911ea259..d103e958ed95 100644
--- a/src/render/SDL_render.c
+++ b/src/render/SDL_render.c
@@ -109,6 +109,9 @@ static const SDL_RenderDriver *render_drivers[] = {
#if SDL_VIDEO_RENDER_OGL_ES2
&GLES2_RenderDriver,
#endif
+#if SDL_VIDEO_RENDER_OGL_ES
+ &GLES_RenderDriver,
+#endif
#if SDL_VIDEO_RENDER_PS2 && !SDL_RENDER_DISABLED
&PS2_RenderDriver,
#endif
diff --git a/src/render/SDL_sysrender.h b/src/render/SDL_sysrender.h
index 49c682aec7fb..d9b6651c4128 100644
--- a/src/render/SDL_sysrender.h
+++ b/src/render/SDL_sysrender.h
@@ -299,6 +299,7 @@ extern SDL_RenderDriver D3D11_RenderDriver;
extern SDL_RenderDriver D3D12_RenderDriver;
extern SDL_RenderDriver GL_RenderDriver;
extern SDL_RenderDriver GLES2_RenderDriver;
+extern SDL_RenderDriver GLES_RenderDriver;
extern SDL_RenderDriver METAL_RenderDriver;
extern SDL_RenderDriver PS2_RenderDriver;
extern SDL_RenderDriver PSP_RenderDriver;
diff --git a/src/render/opengles/SDL_glesfuncs.h b/src/render/opengles/SDL_glesfuncs.h
new file mode 100644
index 000000000000..40a656455460
--- /dev/null
+++ b/src/render/opengles/SDL_glesfuncs.h
@@ -0,0 +1,62 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+SDL_PROC(void, glBindTexture, (GLenum, GLuint))
+SDL_PROC(void, glBlendFunc, (GLenum, GLenum))
+SDL_PROC_OES(void, glBlendEquationOES, (GLenum))
+SDL_PROC_OES(void, glBlendEquationSeparateOES, (GLenum, GLenum))
+SDL_PROC_OES(void, glBlendFuncSeparateOES, (GLenum, GLenum, GLenum, GLenum))
+SDL_PROC(void, glClear, (GLbitfield))
+SDL_PROC(void, glClearColor, (GLclampf, GLclampf, GLclampf, GLclampf))
+SDL_PROC(void, glColor4f, (GLfloat, GLfloat, GLfloat, GLfloat))
+SDL_PROC(void, glColorPointer, (GLint, GLenum, GLsizei, const GLvoid *))
+SDL_PROC(void, glDeleteTextures, (GLsizei, const GLuint *))
+SDL_PROC(void, glDisable, (GLenum))
+SDL_PROC(void, glDisableClientState, (GLenum array))
+SDL_PROC(void, glDrawArrays, (GLenum, GLint, GLsizei))
+SDL_PROC_OES(void, glDrawTexfOES, (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat))
+SDL_PROC(void, glEnable, (GLenum))
+SDL_PROC(void, glEnableClientState, (GLenum))
+SDL_PROC(void, glFinish, (void))
+SDL_PROC_OES(void, glGenFramebuffersOES, (GLsizei, GLuint *))
+SDL_PROC(void, glGenTextures, (GLsizei, GLuint *))
+SDL_PROC(GLenum, glGetError, (void))
+SDL_PROC(void, glGetIntegerv, (GLenum, GLint *))
+SDL_PROC(void, glLoadIdentity, (void))
+SDL_PROC(void, glMatrixMode, (GLenum))
+SDL_PROC(void, glOrthof, (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat))
+SDL_PROC(void, glPixelStorei, (GLenum, GLint))
+SDL_PROC(void, glReadPixels, (GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoid*))
+SDL_PROC(void, glScissor, (GLint, GLint, GLsizei, GLsizei))
+SDL_PROC(void, glTexCoordPointer, (GLint, GLenum, GLsizei, const GLvoid *))
+SDL_PROC(void, glTexEnvf, (GLenum, GLenum, GLfloat))
+SDL_PROC(void, glTexImage2D, (GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid *))
+SDL_PROC(void, glTexParameteri, (GLenum, GLenum, GLint))
+SDL_PROC(void, glTexParameteriv, (GLenum, GLenum, const GLint *))
+SDL_PROC(void, glTexSubImage2D, (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *))
+SDL_PROC(void, glVertexPointer, (GLint, GLenum, GLsizei, const GLvoid *))
+SDL_PROC(void, glViewport, (GLint, GLint, GLsizei, GLsizei))
+SDL_PROC_OES(void, glBindFramebufferOES, (GLenum, GLuint))
+SDL_PROC_OES(void, glFramebufferTexture2DOES, (GLenum, GLenum, GLenum, GLuint, GLint))
+SDL_PROC_OES(GLenum, glCheckFramebufferStatusOES, (GLenum))
+SDL_PROC_OES(void, glDeleteFramebuffersOES, (GLsizei, const GLuint*))
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/render/opengles/SDL_render_gles.c b/src/render/opengles/SDL_render_gles.c
new file mode 100644
index 000000000000..8e918c665517
--- /dev/null
+++ b/src/render/opengles/SDL_render_gles.c
@@ -0,0 +1,1218 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_RENDER_OGL_ES && !SDL_RENDER_DISABLED
+
+#include "SDL_hints.h"
+#include "../../video/SDL_sysvideo.h" /* For SDL_GL_SwapWindowWithResult */
+#include "SDL_opengles.h"
+#include "../SDL_sysrender.h"
+#include "../../SDL_utils_c.h"
+
+/* To prevent unnecessary window recreation,
+ * these should match the defaults selected in SDL_GL_ResetAttributes
+ */
+
+#define RENDERER_CONTEXT_MAJOR 1
+#define RENDERER_CONTEXT_MINOR 1
+
+/* OpenGL ES 1.1 renderer implementation, based on the OpenGL renderer */
+
+/* Used to re-create the window with OpenGL ES capability */
+extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
+
+static const float inv255f = 1.0f / 255.0f;
+
+typedef struct GLES_FBOList GLES_FBOList;
+
+struct GLES_FBOList
+{
+ Uint32 w, h;
+ GLuint FBO;
+ GLES_FBOList *next;
+};
+
+typedef struct
+{
+ SDL_Rect viewport;
+ SDL_bool viewport_dirty;
+ SDL_Texture *texture;
+ SDL_Texture *target;
+ int drawablew;
+ int drawableh;
+ SDL_BlendMode blend;
+ SDL_bool cliprect_enabled_dirty;
+ SDL_bool cliprect_enabled;
+ SDL_bool cliprect_dirty;
+ SDL_Rect cliprect;
+ SDL_bool texturing;
+ Uint32 color;
+ Uint32 clear_color;
+} GLES_DrawStateCache;
+
+typedef struct
+{
+ SDL_GLContext context;
+
+#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
+#define SDL_PROC_OES SDL_PROC
+#include "SDL_glesfuncs.h"
+#undef SDL_PROC
+#undef SDL_PROC_OES
+ SDL_bool GL_OES_framebuffer_object_supported;
+ GLES_FBOList *framebuffers;
+ GLuint window_framebuffer;
+
+ SDL_bool GL_OES_blend_func_separate_supported;
+ SDL_bool GL_OES_blend_equation_separate_supported;
+ SDL_bool GL_OES_blend_subtract_supported;
+
+ GLES_DrawStateCache drawstate;
+} GLES_RenderData;
+
+typedef struct
+{
+ GLuint texture;
+ GLenum type;
+ GLfloat texw;
+ GLfloat texh;
+ GLenum format;
+ GLenum formattype;
+ void *pixels;
+ int pitch;
+ GLES_FBOList *fbo;
+} GLES_TextureData;
+
+static int
+GLES_SetError(const char *prefix, GLenum result)
+{
+ const char *error;
+
+ switch (result) {
+ case GL_NO_ERROR:
+ error = "GL_NO_ERROR";
+ break;
+ case GL_INVALID_ENUM:
+ error = "GL_INVALID_ENUM";
+ break;
+ case GL_INVALID_VALUE:
+ error = "GL_INVALID_VALUE";
+ break;
+ case GL_INVALID_OPERATION:
+ error = "GL_INVALID_OPERATION";
+ break;
+ case GL_STACK_OVERFLOW:
+ error = "GL_STACK_OVERFLOW";
+ break;
+ case GL_STACK_UNDERFLOW:
+ error = "GL_STACK_UNDERFLOW";
+ break;
+ case GL_OUT_OF_MEMORY:
+ error = "GL_OUT_OF_MEMORY";
+ break;
+ default:
+ error = "UNKNOWN";
+ break;
+ }
+ return SDL_SetError("%s: %s", prefix, error);
+}
+
+static int GLES_LoadFunctions(GLES_RenderData * data)
+{
+#if SDL_VIDEO_DRIVER_UIKIT
+#define __SDL_NOGETPROCADDR__
+#elif SDL_VIDEO_DRIVER_ANDROID
+#define __SDL_NOGETPROCADDR__
+#endif
+
+#ifdef __SDL_NOGETPROCADDR__
+#define SDL_PROC(ret,func,params) data->func=func;
+#define SDL_PROC_OES(ret,func,params) data->func=func;
+#else
+#define SDL_PROC(ret,func,params) \
+ do { \
+ data->func = SDL_GL_GetProcAddress(#func); \
+ if ( ! data->func ) { \
+ return SDL_SetError("Couldn't load GLES function %s: %s", #func, SDL_GetError()); \
+ } \
+ } while ( 0 );
+#define SDL_PROC_OES(ret,func,params) \
+ do { \
+ data->func = SDL_GL_GetProcAddress(#func); \
+ } while ( 0 );
+#endif /* __SDL_NOGETPROCADDR__ */
+
+#include "SDL_glesfuncs.h"
+#undef SDL_PROC
+#undef SDL_PROC_OES
+ return 0;
+}
+
+static GLES_FBOList *
+GLES_GetFBO(GLES_RenderData *data, Uint32 w, Uint32 h)
+{
+ GLES_FBOList *result = data->framebuffers;
+ while ((result) && ((result->w != w) || (result->h != h)) ) {
+ result = result->next;
+ }
+ if (result == NULL) {
+ result = SDL_malloc(sizeof(GLES_FBOList));
+ result->w = w;
+ result->h = h;
+ data->glGenFramebuffersOES(1, &result->FBO);
+ result->next = data->framebuffers;
+ data->framebuffers = result;
+ }
+ return result;
+}
+
+
+static int
+GLES_ActivateRenderer(SDL_Renderer * renderer)
+{
+ GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
+
+ if (SDL_GL_GetCurrentContext() != data->context) {
+ if (SDL_GL_MakeCurrent(renderer->window, data->context) < 0) {
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+static void
+GLES_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
+{
+ GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
+
+ if (event->event == SDL_WINDOWEVENT_MINIMIZED) {
+ /* According to Apple documentation, we need to finish drawing NOW! */
+ data->glFinish();
+ }
+}
+
+static int
+GLES_GetOutputSize(SDL_Renderer * renderer, int *w, int *h)
+{
+ SDL_GL_GetDrawableSize(renderer->window, w, h);
+ return 0;
+}
+
+static GLenum GetBlendFunc(SDL_BlendFactor factor)
+{
+ switch (factor) {
+ case SDL_BLENDFACTOR_ZERO:
+ return GL_ZERO;
+ case SDL_BLENDFACTOR_ONE:
+ return GL_ONE;
+ case SDL_BLENDFACTOR_SRC_COLOR:
+ return GL_SRC_COLOR;
+ case SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR:
+ return GL_ONE_MINUS_SRC_COLOR;
+ case SDL_BLENDFACTOR_SRC_ALPHA:
+ return GL_SRC_ALPHA;
+ case SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA:
+ return GL_ONE_MINUS_SRC_ALPHA;
+ case SDL_BLENDFACTOR_DST_COLOR:
+ return GL_DST_COLOR;
+ case SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR:
+ return GL_ONE_MINUS_DST_COLOR;
+ case SDL_BLENDFACTOR_DST_ALPHA:
+ return GL_DST_ALPHA;
+ case SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA:
+ return GL_ONE_MINUS_DST_ALPHA;
+ default:
+ return GL_INVALID_ENUM;
+ }
+}
+
+static GLenum GetBlendEquation(SDL_BlendOperation operation)
+{
+ switch (operation) {
+ case SDL_BLENDOPERATION_ADD:
+ return GL_FUNC_ADD_OES;
+ case SDL_BLENDOPERATION_SUBTRACT:
+ return GL_FUNC_SUBTRACT_OES;
+ case SDL_BLENDOPERATION_REV_SUBTRACT:
+ return GL_FUNC_REVERSE_SUBTRACT_OES;
+ default:
+ return GL_INVALID_ENUM;
+ }
+}
+
+static SDL_bool
+GLES_SupportsBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode)
+{
+ GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
+ SDL_BlendFactor srcColorFactor = SDL_GetBlendModeSrcColorFactor(blendMode);
+ SDL_BlendFactor srcAlphaFactor = SDL_GetBlendModeSrcAlphaFactor(blendMode);
+ SDL_BlendOperation colorOperation = SDL_GetBlendModeColorOperation(blendMode);
+ SDL_BlendFactor dstColorFactor = SDL_GetBlendModeDstColorFactor(blendMode);
+ SDL_BlendFactor dstAlphaFactor = SDL_GetBlendModeDstAlphaFactor(blendMode);
+ SDL_BlendOperation alphaOperation = SDL_GetBlendModeAlphaOperation(blendMode);
+
+ if (GetBlendFunc(srcColorFactor) == GL_INVALID_ENUM ||
+ GetBlendFunc(srcAlphaFactor) == GL_INVALID_ENUM ||
+ GetBlendEquation(colorOperation) == GL_INVALID_ENUM ||
+ GetBlendFunc(dstColorFactor) == GL_INVALID_ENUM ||
+ GetBlendFunc(dstAlphaFactor) == GL_INVALID_ENUM ||
+ GetBlendEquation(alphaOperation) == GL_INVALID_ENUM) {
+ return SDL_FALSE;
+ }
+ if ((srcColorFactor != srcAlphaFactor || dstColorFactor != dstAlphaFactor) && !data->GL_OES_blend_func_separate_supported) {
+ return SDL_FALSE;
+ }
+ if (colorOperation != alphaOperation && !data->GL_OES_blend_equation_separate_supported) {
+ return SDL_FALSE;
+ }
+ if (colorOperation != SDL_BLENDOPERATION_ADD && !data->GL_OES_blend
(Patch may be truncated, please check the link at the top of this post.)