Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11
authorSam Lantinga <slouken@libsdl.org>
Sun, 08 Jan 2012 02:23:37 -0500
changeset 6188e82023802002
parent 6187 6b1932e5a36b
child 6189 b5a665fbaedc
Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11

Scott Percival 2011-07-03 06:41:51 PDT

This submission is aimed at making life easier for OpenGL ES capable devices
running a X11 stack (e.g. Maemo, Meego, TrimSlice, other ARM SoC boards not
running Android). SDL's Pandora support already has the neccesary GLES-to-X11
glue code, however it's all ghetto'd off in Makefile.pandora and not very
flexible.

The patch:
- adds an awesome --enable-video-opengles option to configure
- re-modifies the opengles and opengles2 SDL_renderers to use function pointers
- no idea why this was removed?
- for SDL_Renderers, links in libGLESv1_CM, libGLES_CM (for PowerVR fans) or
libGLESv2 at runtime
- links in libEGL.so at runtime - the old code made an assumption that
eglFunctions could be pulled from the active GLES library, PowerVR for one
doesn't let you do that with their libGLESv2
- allows you to pick which of GLES v1 or v2 to load via
SDL_GL_CONTEXT_MAJOR_VERSION

So far I've tested this on a Nokia N900 (OMAP 3430/SGX 530 running Maemo 5) and
a Toshiba AC100 (Tegra 2 running Ubuntu 10.10). I haven't tested it on... well,
everything that isn't those two, such as a Pandora, iOS or Android device. The
Pandora specific code should be kept intact (fingers crossed), and nothing
painfully drastic has been added to the SDL_renderers. The library loading
sequence in SDL_x11opengles has been updated to accomodate both NVIDIA's
propensity to let developers get away with murder and PowerVR's alternative of
punishing every missed step.

The test apps work okay with GLES or GLES2 as the renderer. For some reason
alpha blending doesn't seem to work on the Tegra 2; last week NVIDIA pushed out
a new set of X11 GLES drivers, so I'll try and investigate once I upgrade
those. Also, this patch adds things to configure.in, include/SDL_config.h.in
and test/configure.in. I didn't know what the policy was re. committing
generated spaghetti from autotools, so ./autogen.sh has to be run again. Sorry.

I think that's about everything, let me know if there's anything I've
overlooked.
configure
configure.in
include/SDL_config.h.in
src/render/opengles/SDL_glesfuncs.h
src/render/opengles/SDL_render_gles.c
src/render/opengles2/SDL_gles2funcs.h
src/render/opengles2/SDL_render_gles2.c
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/x11/SDL_x11opengles.c
src/video/x11/SDL_x11opengles.h
src/video/x11/SDL_x11video.c
src/video/x11/SDL_x11window.c
test/configure
test/configure.in
     1.1 --- a/configure	Sun Jan 08 01:15:20 2012 -0500
     1.2 +++ b/configure	Sun Jan 08 02:23:37 2012 -0500
     1.3 @@ -1562,6 +1562,7 @@
     1.4                            [default=yes]
     1.5    --enable-video-dummy    use dummy video driver [default=yes]
     1.6    --enable-video-opengl   include OpenGL support [default=yes]
     1.7 +  --enable-video-opengles include OpenGL ES support [default=yes]
     1.8    --enable-input-events   use Linux 2.4 unified input interface
     1.9                            [default=yes]
    1.10    --enable-input-tslib    use the Touchscreen library for input
    1.11 @@ -3772,13 +3773,13 @@
    1.12  else
    1.13    lt_cv_nm_interface="BSD nm"
    1.14    echo "int some_variable = 0;" > conftest.$ac_ext
    1.15 -  (eval echo "\"\$as_me:3775: $ac_compile\"" >&5)
    1.16 +  (eval echo "\"\$as_me:3776: $ac_compile\"" >&5)
    1.17    (eval "$ac_compile" 2>conftest.err)
    1.18    cat conftest.err >&5
    1.19 -  (eval echo "\"\$as_me:3778: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
    1.20 +  (eval echo "\"\$as_me:3779: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
    1.21    (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out)
    1.22    cat conftest.err >&5
    1.23 -  (eval echo "\"\$as_me:3781: output\"" >&5)
    1.24 +  (eval echo "\"\$as_me:3782: output\"" >&5)
    1.25    cat conftest.out >&5
    1.26    if $GREP 'External.*some_variable' conftest.out > /dev/null; then
    1.27      lt_cv_nm_interface="MS dumpbin"
    1.28 @@ -5005,7 +5006,7 @@
    1.29    ;;
    1.30  *-*-irix6*)
    1.31    # Find out which ABI we are using.
    1.32 -  echo '#line 5008 "configure"' > conftest.$ac_ext
    1.33 +  echo '#line 5009 "configure"' > conftest.$ac_ext
    1.34    if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
    1.35    (eval $ac_compile) 2>&5
    1.36    ac_status=$?
    1.37 @@ -7166,11 +7167,11 @@
    1.38     -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    1.39     -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    1.40     -e 's:$: $lt_compiler_flag:'`
    1.41 -   (eval echo "\"\$as_me:7169: $lt_compile\"" >&5)
    1.42 +   (eval echo "\"\$as_me:7170: $lt_compile\"" >&5)
    1.43     (eval "$lt_compile" 2>conftest.err)
    1.44     ac_status=$?
    1.45     cat conftest.err >&5
    1.46 -   echo "$as_me:7173: \$? = $ac_status" >&5
    1.47 +   echo "$as_me:7174: \$? = $ac_status" >&5
    1.48     if (exit $ac_status) && test -s "$ac_outfile"; then
    1.49       # The compiler can only warn and ignore the option if not recognized
    1.50       # So say no if there are warnings other than the usual output.
    1.51 @@ -7505,11 +7506,11 @@
    1.52     -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    1.53     -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    1.54     -e 's:$: $lt_compiler_flag:'`
    1.55 -   (eval echo "\"\$as_me:7508: $lt_compile\"" >&5)
    1.56 +   (eval echo "\"\$as_me:7509: $lt_compile\"" >&5)
    1.57     (eval "$lt_compile" 2>conftest.err)
    1.58     ac_status=$?
    1.59     cat conftest.err >&5
    1.60 -   echo "$as_me:7512: \$? = $ac_status" >&5
    1.61 +   echo "$as_me:7513: \$? = $ac_status" >&5
    1.62     if (exit $ac_status) && test -s "$ac_outfile"; then
    1.63       # The compiler can only warn and ignore the option if not recognized
    1.64       # So say no if there are warnings other than the usual output.
    1.65 @@ -7610,11 +7611,11 @@
    1.66     -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    1.67     -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    1.68     -e 's:$: $lt_compiler_flag:'`
    1.69 -   (eval echo "\"\$as_me:7613: $lt_compile\"" >&5)
    1.70 +   (eval echo "\"\$as_me:7614: $lt_compile\"" >&5)
    1.71     (eval "$lt_compile" 2>out/conftest.err)
    1.72     ac_status=$?
    1.73     cat out/conftest.err >&5
    1.74 -   echo "$as_me:7617: \$? = $ac_status" >&5
    1.75 +   echo "$as_me:7618: \$? = $ac_status" >&5
    1.76     if (exit $ac_status) && test -s out/conftest2.$ac_objext
    1.77     then
    1.78       # The compiler can only warn and ignore the option if not recognized
    1.79 @@ -7665,11 +7666,11 @@
    1.80     -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    1.81     -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    1.82     -e 's:$: $lt_compiler_flag:'`
    1.83 -   (eval echo "\"\$as_me:7668: $lt_compile\"" >&5)
    1.84 +   (eval echo "\"\$as_me:7669: $lt_compile\"" >&5)
    1.85     (eval "$lt_compile" 2>out/conftest.err)
    1.86     ac_status=$?
    1.87     cat out/conftest.err >&5
    1.88 -   echo "$as_me:7672: \$? = $ac_status" >&5
    1.89 +   echo "$as_me:7673: \$? = $ac_status" >&5
    1.90     if (exit $ac_status) && test -s out/conftest2.$ac_objext
    1.91     then
    1.92       # The compiler can only warn and ignore the option if not recognized
    1.93 @@ -10423,7 +10424,7 @@
    1.94    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
    1.95    lt_status=$lt_dlunknown
    1.96    cat > conftest.$ac_ext <<_LT_EOF
    1.97 -#line 10426 "configure"
    1.98 +#line 10427 "configure"
    1.99  #include "confdefs.h"
   1.100  
   1.101  #if HAVE_DLFCN_H
   1.102 @@ -10519,7 +10520,7 @@
   1.103    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   1.104    lt_status=$lt_dlunknown
   1.105    cat > conftest.$ac_ext <<_LT_EOF
   1.106 -#line 10522 "configure"
   1.107 +#line 10523 "configure"
   1.108  #include "confdefs.h"
   1.109  
   1.110  #if HAVE_DLFCN_H
   1.111 @@ -14201,11 +14202,11 @@
   1.112     -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
   1.113     -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
   1.114     -e 's:$: $lt_compiler_flag:'`
   1.115 -   (eval echo "\"\$as_me:14204: $lt_compile\"" >&5)
   1.116 +   (eval echo "\"\$as_me:14205: $lt_compile\"" >&5)
   1.117     (eval "$lt_compile" 2>conftest.err)
   1.118     ac_status=$?
   1.119     cat conftest.err >&5
   1.120 -   echo "$as_me:14208: \$? = $ac_status" >&5
   1.121 +   echo "$as_me:14209: \$? = $ac_status" >&5
   1.122     if (exit $ac_status) && test -s "$ac_outfile"; then
   1.123       # The compiler can only warn and ignore the option if not recognized
   1.124       # So say no if there are warnings other than the usual output.
   1.125 @@ -14300,11 +14301,11 @@
   1.126     -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
   1.127     -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
   1.128     -e 's:$: $lt_compiler_flag:'`
   1.129 -   (eval echo "\"\$as_me:14303: $lt_compile\"" >&5)
   1.130 +   (eval echo "\"\$as_me:14304: $lt_compile\"" >&5)
   1.131     (eval "$lt_compile" 2>out/conftest.err)
   1.132     ac_status=$?
   1.133     cat out/conftest.err >&5
   1.134 -   echo "$as_me:14307: \$? = $ac_status" >&5
   1.135 +   echo "$as_me:14308: \$? = $ac_status" >&5
   1.136     if (exit $ac_status) && test -s out/conftest2.$ac_objext
   1.137     then
   1.138       # The compiler can only warn and ignore the option if not recognized
   1.139 @@ -14352,11 +14353,11 @@
   1.140     -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
   1.141     -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
   1.142     -e 's:$: $lt_compiler_flag:'`
   1.143 -   (eval echo "\"\$as_me:14355: $lt_compile\"" >&5)
   1.144 +   (eval echo "\"\$as_me:14356: $lt_compile\"" >&5)
   1.145     (eval "$lt_compile" 2>out/conftest.err)
   1.146     ac_status=$?
   1.147     cat out/conftest.err >&5
   1.148 -   echo "$as_me:14359: \$? = $ac_status" >&5
   1.149 +   echo "$as_me:14360: \$? = $ac_status" >&5
   1.150     if (exit $ac_status) && test -s out/conftest2.$ac_objext
   1.151     then
   1.152       # The compiler can only warn and ignore the option if not recognized
   1.153 @@ -23752,6 +23753,201 @@
   1.154      fi
   1.155  }
   1.156  
   1.157 +# Check whether --enable-video-opengles was given.
   1.158 +if test "${enable_video_opengles+set}" = set; then
   1.159 +  enableval=$enable_video_opengles;
   1.160 +else
   1.161 +  enable_video_opengles=yes
   1.162 +fi
   1.163 +
   1.164 +
   1.165 +CheckOpenGLESX11()
   1.166 +{
   1.167 +    if test x$enable_video = xyes -a x$enable_video_opengles = xyes; then
   1.168 +        { echo "$as_me:$LINENO: checking for OpenGL ES (EGL) support" >&5
   1.169 +echo $ECHO_N "checking for OpenGL ES (EGL) support... $ECHO_C" >&6; }
   1.170 +        video_opengles=no
   1.171 +        cat >conftest.$ac_ext <<_ACEOF
   1.172 +/* confdefs.h.  */
   1.173 +_ACEOF
   1.174 +cat confdefs.h >>conftest.$ac_ext
   1.175 +cat >>conftest.$ac_ext <<_ACEOF
   1.176 +/* end confdefs.h.  */
   1.177 +
   1.178 +         #include <EGL/egl.h>
   1.179 +
   1.180 +int
   1.181 +main ()
   1.182 +{
   1.183 +
   1.184 +
   1.185 +  ;
   1.186 +  return 0;
   1.187 +}
   1.188 +_ACEOF
   1.189 +rm -f conftest.$ac_objext
   1.190 +if { (ac_try="$ac_compile"
   1.191 +case "(($ac_try" in
   1.192 +  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
   1.193 +  *) ac_try_echo=$ac_try;;
   1.194 +esac
   1.195 +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
   1.196 +  (eval "$ac_compile") 2>conftest.er1
   1.197 +  ac_status=$?
   1.198 +  grep -v '^ *+' conftest.er1 >conftest.err
   1.199 +  rm -f conftest.er1
   1.200 +  cat conftest.err >&5
   1.201 +  echo "$as_me:$LINENO: \$? = $ac_status" >&5
   1.202 +  (exit $ac_status); } && {
   1.203 +	 test -z "$ac_c_werror_flag" ||
   1.204 +	 test ! -s conftest.err
   1.205 +       } && test -s conftest.$ac_objext; then
   1.206 +
   1.207 +        video_opengles=yes
   1.208 +
   1.209 +else
   1.210 +  echo "$as_me: failed program was:" >&5
   1.211 +sed 's/^/| /' conftest.$ac_ext >&5
   1.212 +
   1.213 +
   1.214 +fi
   1.215 +
   1.216 +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
   1.217 +        { echo "$as_me:$LINENO: result: $video_opengles" >&5
   1.218 +echo "${ECHO_T}$video_opengles" >&6; }
   1.219 +        if test x$video_opengles = xyes; then
   1.220 +            { echo "$as_me:$LINENO: checking for OpenGL ES v1 headers" >&5
   1.221 +echo $ECHO_N "checking for OpenGL ES v1 headers... $ECHO_C" >&6; }
   1.222 +            video_opengles_v1=no
   1.223 +            cat >conftest.$ac_ext <<_ACEOF
   1.224 +/* confdefs.h.  */
   1.225 +_ACEOF
   1.226 +cat confdefs.h >>conftest.$ac_ext
   1.227 +cat >>conftest.$ac_ext <<_ACEOF
   1.228 +/* end confdefs.h.  */
   1.229 +
   1.230 +             #include <GLES/gl.h>
   1.231 +             #include <GLES/glext.h>
   1.232 +
   1.233 +int
   1.234 +main ()
   1.235 +{
   1.236 +
   1.237 +
   1.238 +  ;
   1.239 +  return 0;
   1.240 +}
   1.241 +_ACEOF
   1.242 +rm -f conftest.$ac_objext
   1.243 +if { (ac_try="$ac_compile"
   1.244 +case "(($ac_try" in
   1.245 +  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
   1.246 +  *) ac_try_echo=$ac_try;;
   1.247 +esac
   1.248 +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
   1.249 +  (eval "$ac_compile") 2>conftest.er1
   1.250 +  ac_status=$?
   1.251 +  grep -v '^ *+' conftest.er1 >conftest.err
   1.252 +  rm -f conftest.er1
   1.253 +  cat conftest.err >&5
   1.254 +  echo "$as_me:$LINENO: \$? = $ac_status" >&5
   1.255 +  (exit $ac_status); } && {
   1.256 +	 test -z "$ac_c_werror_flag" ||
   1.257 +	 test ! -s conftest.err
   1.258 +       } && test -s conftest.$ac_objext; then
   1.259 +
   1.260 +            video_opengles_v1=yes
   1.261 +
   1.262 +else
   1.263 +  echo "$as_me: failed program was:" >&5
   1.264 +sed 's/^/| /' conftest.$ac_ext >&5
   1.265 +
   1.266 +
   1.267 +fi
   1.268 +
   1.269 +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
   1.270 +            { echo "$as_me:$LINENO: result: $video_opengles_v1" >&5
   1.271 +echo "${ECHO_T}$video_opengles_v1" >&6; }
   1.272 +            if test x$video_opengles_v1 = xyes; then
   1.273 +
   1.274 +cat >>confdefs.h <<\_ACEOF
   1.275 +#define SDL_VIDEO_OPENGL_ES 1
   1.276 +_ACEOF
   1.277 +
   1.278 +
   1.279 +cat >>confdefs.h <<\_ACEOF
   1.280 +#define SDL_VIDEO_RENDER_OGL_ES 1
   1.281 +_ACEOF
   1.282 +
   1.283 +            fi
   1.284 +            { echo "$as_me:$LINENO: checking for OpenGL ES v2 headers" >&5
   1.285 +echo $ECHO_N "checking for OpenGL ES v2 headers... $ECHO_C" >&6; }
   1.286 +            video_opengles_v2=no
   1.287 +            cat >conftest.$ac_ext <<_ACEOF
   1.288 +/* confdefs.h.  */
   1.289 +_ACEOF
   1.290 +cat confdefs.h >>conftest.$ac_ext
   1.291 +cat >>conftest.$ac_ext <<_ACEOF
   1.292 +/* end confdefs.h.  */
   1.293 +
   1.294 +             #include <GLES2/gl2.h>
   1.295 +             #include <GLES2/gl2ext.h>
   1.296 +
   1.297 +int
   1.298 +main ()
   1.299 +{
   1.300 +
   1.301 +
   1.302 +  ;
   1.303 +  return 0;
   1.304 +}
   1.305 +_ACEOF
   1.306 +rm -f conftest.$ac_objext
   1.307 +if { (ac_try="$ac_compile"
   1.308 +case "(($ac_try" in
   1.309 +  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
   1.310 +  *) ac_try_echo=$ac_try;;
   1.311 +esac
   1.312 +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
   1.313 +  (eval "$ac_compile") 2>conftest.er1
   1.314 +  ac_status=$?
   1.315 +  grep -v '^ *+' conftest.er1 >conftest.err
   1.316 +  rm -f conftest.er1
   1.317 +  cat conftest.err >&5
   1.318 +  echo "$as_me:$LINENO: \$? = $ac_status" >&5
   1.319 +  (exit $ac_status); } && {
   1.320 +	 test -z "$ac_c_werror_flag" ||
   1.321 +	 test ! -s conftest.err
   1.322 +       } && test -s conftest.$ac_objext; then
   1.323 +
   1.324 +            video_opengles_v2=yes
   1.325 +
   1.326 +else
   1.327 +  echo "$as_me: failed program was:" >&5
   1.328 +sed 's/^/| /' conftest.$ac_ext >&5
   1.329 +
   1.330 +
   1.331 +fi
   1.332 +
   1.333 +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
   1.334 +            { echo "$as_me:$LINENO: result: $video_opengles_v2" >&5
   1.335 +echo "${ECHO_T}$video_opengles_v2" >&6; }
   1.336 +            if test x$video_opengles_v2 = xyes; then
   1.337 +
   1.338 +cat >>confdefs.h <<\_ACEOF
   1.339 +#define SDL_VIDEO_OPENGL_ES2 1
   1.340 +_ACEOF
   1.341 +
   1.342 +
   1.343 +cat >>confdefs.h <<\_ACEOF
   1.344 +#define SDL_VIDEO_RENDER_OGL_ES2 1
   1.345 +_ACEOF
   1.346 +
   1.347 +            fi
   1.348 +        fi
   1.349 +    fi
   1.350 +}
   1.351 +
   1.352  CheckWINDOWSGL()
   1.353  {
   1.354      if test x$enable_video = xyes -a x$enable_video_opengl = xyes; then
   1.355 @@ -27000,6 +27196,7 @@
   1.356          CheckDirectFB
   1.357          CheckFusionSound
   1.358          CheckOpenGLX11
   1.359 +        CheckOpenGLESX11
   1.360          CheckInputEvents
   1.361          CheckTslib
   1.362          CheckUSBHID
     2.1 --- a/configure.in	Sun Jan 08 01:15:20 2012 -0500
     2.2 +++ b/configure.in	Sun Jan 08 02:23:37 2012 -0500
     2.3 @@ -1474,6 +1474,57 @@
     2.4      fi
     2.5  }
     2.6  
     2.7 +dnl Check to see if OpenGL ES support is desired
     2.8 +AC_ARG_ENABLE(video-opengles,
     2.9 +AC_HELP_STRING([--enable-video-opengles], [include OpenGL ES support [[default=yes]]]),
    2.10 +              , enable_video_opengles=yes)
    2.11 +
    2.12 +dnl Find OpenGL ES
    2.13 +CheckOpenGLESX11()
    2.14 +{
    2.15 +    if test x$enable_video = xyes -a x$enable_video_opengles = xyes; then
    2.16 +        AC_MSG_CHECKING(for OpenGL ES (EGL) support)
    2.17 +        video_opengles=no
    2.18 +        AC_TRY_COMPILE([
    2.19 +         #include <EGL/egl.h>
    2.20 +        ],[
    2.21 +        ],[
    2.22 +        video_opengles=yes
    2.23 +        ])
    2.24 +        AC_MSG_RESULT($video_opengles)
    2.25 +        if test x$video_opengles = xyes; then
    2.26 +            AC_MSG_CHECKING(for OpenGL ES v1 headers)
    2.27 +            video_opengles_v1=no
    2.28 +            AC_TRY_COMPILE([
    2.29 +             #include <GLES/gl.h>
    2.30 +             #include <GLES/glext.h>
    2.31 +            ],[
    2.32 +            ],[
    2.33 +            video_opengles_v1=yes
    2.34 +            ])
    2.35 +            AC_MSG_RESULT($video_opengles_v1)
    2.36 +            if test x$video_opengles_v1 = xyes; then
    2.37 +                AC_DEFINE(SDL_VIDEO_OPENGL_ES, 1, [ ])
    2.38 +                AC_DEFINE(SDL_VIDEO_RENDER_OGL_ES, 1, [ ])
    2.39 +            fi
    2.40 +            AC_MSG_CHECKING(for OpenGL ES v2 headers)
    2.41 +            video_opengles_v2=no
    2.42 +            AC_TRY_COMPILE([
    2.43 +             #include <GLES2/gl2.h>
    2.44 +             #include <GLES2/gl2ext.h>
    2.45 +            ],[
    2.46 +            ],[
    2.47 +            video_opengles_v2=yes
    2.48 +            ])
    2.49 +            AC_MSG_RESULT($video_opengles_v2)
    2.50 +            if test x$video_opengles_v2 = xyes; then
    2.51 +                AC_DEFINE(SDL_VIDEO_OPENGL_ES2, 1, [ ])
    2.52 +                AC_DEFINE(SDL_VIDEO_RENDER_OGL_ES2, 1, [ ])
    2.53 +            fi
    2.54 +        fi
    2.55 +    fi
    2.56 +}
    2.57 +
    2.58  dnl Check for Windows OpenGL
    2.59  CheckWINDOWSGL()
    2.60  {
    2.61 @@ -2043,6 +2094,7 @@
    2.62          CheckDirectFB
    2.63          CheckFusionSound
    2.64          CheckOpenGLX11
    2.65 +        CheckOpenGLESX11
    2.66          CheckInputEvents
    2.67          CheckTslib
    2.68          CheckUSBHID
     3.1 --- a/include/SDL_config.h.in	Sun Jan 08 01:15:20 2012 -0500
     3.2 +++ b/include/SDL_config.h.in	Sun Jan 08 02:23:37 2012 -0500
     3.3 @@ -271,6 +271,7 @@
     3.4  #undef SDL_VIDEO_RENDER_D3D
     3.5  #undef SDL_VIDEO_RENDER_OGL
     3.6  #undef SDL_VIDEO_RENDER_OGL_ES
     3.7 +#undef SDL_VIDEO_RENDER_OGL_ES2
     3.8  #undef SDL_VIDEO_RENDER_DIRECTFB
     3.9  
    3.10  /* Enable OpenGL support */
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/render/opengles/SDL_glesfuncs.h	Sun Jan 08 02:23:37 2012 -0500
     4.3 @@ -0,0 +1,30 @@
     4.4 +SDL_PROC(void, glBindTexture, (GLenum, GLuint))
     4.5 +SDL_PROC(void, glBlendFunc, (GLenum, GLenum))
     4.6 +SDL_PROC(void, glClear, (GLbitfield))
     4.7 +SDL_PROC(void, glClearColor, (GLclampf, GLclampf, GLclampf, GLclampf))
     4.8 +SDL_PROC(void, glColor4f, (GLfloat, GLfloat, GLfloat, GLfloat))
     4.9 +SDL_PROC(void, glDeleteTextures, (GLsizei, const GLuint *))
    4.10 +SDL_PROC(void, glDisable, (GLenum))
    4.11 +SDL_PROC(void, glDisableClientState, (GLenum array))
    4.12 +SDL_PROC(void, glDrawArrays, (GLenum, GLint, GLsizei))
    4.13 +SDL_PROC(void, glDrawTexiOES, (GLint, GLint, GLint, GLint, GLint))
    4.14 +SDL_PROC(void, glEnable, (GLenum))
    4.15 +SDL_PROC(void, glEnableClientState, (GLenum))
    4.16 +SDL_PROC(void, glGenTextures, (GLsizei, GLuint *))
    4.17 +SDL_PROC(GLenum, glGetError, (void))
    4.18 +SDL_PROC(void, glGetIntegerv, (GLenum, GLint *))
    4.19 +SDL_PROC(void, glLoadIdentity, (void))
    4.20 +SDL_PROC(void, glMatrixMode, (GLenum))
    4.21 +SDL_PROC(void, glOrthof, (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat))
    4.22 +SDL_PROC(void, glPixelStorei, (GLenum, GLint))
    4.23 +SDL_PROC(void, glReadPixels, (GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoid*))
    4.24 +SDL_PROC(void, glTexCoordPointer, (GLint, GLenum, GLsizei, const GLvoid *))
    4.25 +SDL_PROC(void, glTexEnvf, (GLenum, GLenum, GLfloat))
    4.26 +SDL_PROC(void, glTexImage2D, (GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid *))
    4.27 +SDL_PROC(void, glTexParameteri, (GLenum, GLenum, GLint))
    4.28 +SDL_PROC(void, glTexParameteriv, (GLenum, GLenum, const GLint *))
    4.29 +SDL_PROC(void, glTexSubImage2D, (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *))
    4.30 +SDL_PROC(void, glVertexPointer, (GLint, GLenum, GLsizei, const GLvoid *))
    4.31 +SDL_PROC(void, glViewport, (GLint, GLint, GLsizei, GLsizei))
    4.32 +
    4.33 +/* vi: set ts=4 sw=4 expandtab: */
     5.1 --- a/src/render/opengles/SDL_render_gles.c	Sun Jan 08 01:15:20 2012 -0500
     5.2 +++ b/src/render/opengles/SDL_render_gles.c	Sun Jan 08 02:23:37 2012 -0500
     5.3 @@ -40,6 +40,9 @@
     5.4  
     5.5  /* OpenGL ES 1.1 renderer implementation, based on the OpenGL renderer */
     5.6  
     5.7 +/* Used to re-create the window with OpenGL capability */
     5.8 +extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
     5.9 +
    5.10  static const float inv255f = 1.0f / 255.0f;
    5.11  
    5.12  static SDL_Renderer *GLES_CreateRenderer(SDL_Window * window, Uint32 flags);
    5.13 @@ -92,6 +95,10 @@
    5.14          SDL_bool tex_coords;
    5.15      } current;
    5.16  
    5.17 +#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
    5.18 +#include "SDL_glesfuncs.h"
    5.19 +#undef SDL_PROC
    5.20 +
    5.21      SDL_bool useDrawTexture;
    5.22      SDL_bool GL_OES_draw_texture_supported;
    5.23  } GLES_RenderData;
    5.24 @@ -142,6 +149,26 @@
    5.25      SDL_SetError("%s: %s", prefix, error);
    5.26  }
    5.27  
    5.28 +static int GLES_LoadFunctions(GLES_RenderData * data)
    5.29 +{
    5.30 +#ifdef __SDL_NOGETPROCADDR__
    5.31 +#define SDL_PROC(ret,func,params) data->func=func;
    5.32 +#else
    5.33 +#define SDL_PROC(ret,func,params) \
    5.34 +    do { \
    5.35 +        data->func = SDL_GL_GetProcAddress(#func); \
    5.36 +        if ( ! data->func ) { \
    5.37 +            SDL_SetError("Couldn't load GLES function %s: %s\n", #func, SDL_GetError()); \
    5.38 +            return -1; \
    5.39 +        } \
    5.40 +    } while ( 0 );  
    5.41 +#endif /* _SDL_NOGETPROCADDR_ */
    5.42 +
    5.43 +#include "SDL_glesfuncs.h"
    5.44 +#undef SDL_PROC
    5.45 +    return 0;
    5.46 +}
    5.47 +
    5.48  static SDL_GLContext SDL_CurrentContext = NULL;
    5.49  
    5.50  static int
    5.51 @@ -176,14 +203,14 @@
    5.52      data->current.blendMode = -1;
    5.53      data->current.tex_coords = SDL_FALSE;
    5.54  
    5.55 -    glDisable(GL_DEPTH_TEST);
    5.56 -    glDisable(GL_CULL_FACE);
    5.57 +    data->glDisable(GL_DEPTH_TEST);
    5.58 +    data->glDisable(GL_CULL_FACE);
    5.59  
    5.60 -    glMatrixMode(GL_MODELVIEW);
    5.61 -    glLoadIdentity();
    5.62 +    data->glMatrixMode(GL_MODELVIEW);
    5.63 +    data->glLoadIdentity();
    5.64  
    5.65 -    glEnableClientState(GL_VERTEX_ARRAY);
    5.66 -    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    5.67 +    data->glEnableClientState(GL_VERTEX_ARRAY);
    5.68 +    data->glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    5.69  }
    5.70  
    5.71  SDL_Renderer *
    5.72 @@ -193,6 +220,19 @@
    5.73      SDL_Renderer *renderer;
    5.74      GLES_RenderData *data;
    5.75      GLint value;
    5.76 +    Uint32 windowFlags;
    5.77 +    
    5.78 +    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
    5.79 +    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
    5.80 +    
    5.81 +    windowFlags = SDL_GetWindowFlags(window);
    5.82 +    if (!(windowFlags & SDL_WINDOW_OPENGL)) {
    5.83 +        if (SDL_RecreateWindow(window, windowFlags | SDL_WINDOW_OPENGL) < 0) {
    5.84 +            /* Uh oh, better try to put it back... */
    5.85 +            SDL_RecreateWindow(window, windowFlags);
    5.86 +            return NULL;
    5.87 +        }
    5.88 +    }
    5.89  
    5.90      renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
    5.91      if (!renderer) {
    5.92 @@ -227,9 +267,6 @@
    5.93      renderer->driverdata = data;
    5.94      renderer->window = window;
    5.95  
    5.96 -    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
    5.97 -    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
    5.98 -
    5.99      data->context = SDL_GL_CreateContext(window);
   5.100      if (!data->context) {
   5.101          GLES_DestroyRenderer(renderer);
   5.102 @@ -240,6 +277,11 @@
   5.103          return NULL;
   5.104      }
   5.105  
   5.106 +    if (GLES_LoadFunctions(data) < 0) {
   5.107 +        GLES_DestroyRenderer(renderer);
   5.108 +        return NULL;
   5.109 +    }
   5.110 +
   5.111      if (flags & SDL_RENDERER_PRESENTVSYNC) {
   5.112          SDL_GL_SetSwapInterval(1);
   5.113      } else {
   5.114 @@ -262,9 +304,9 @@
   5.115      }
   5.116  #endif
   5.117  
   5.118 -    glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
   5.119 +    data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
   5.120      renderer->info.max_texture_width = value;
   5.121 -    glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
   5.122 +    data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
   5.123      renderer->info.max_texture_height = value;
   5.124  
   5.125      /* Set up parameters for rendering */
   5.126 @@ -313,6 +355,7 @@
   5.127  static int
   5.128  GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   5.129  {
   5.130 +    GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata;
   5.131      GLES_TextureData *data;
   5.132      GLint internalFormat;
   5.133      GLenum format, type;
   5.134 @@ -351,9 +394,9 @@
   5.135  
   5.136      texture->driverdata = data;
   5.137  
   5.138 -    glGetError();
   5.139 -    glEnable(GL_TEXTURE_2D);
   5.140 -    glGenTextures(1, &data->texture);
   5.141 +    renderdata->glGetError();
   5.142 +    renderdata->glEnable(GL_TEXTURE_2D);
   5.143 +    renderdata->glGenTextures(1, &data->texture);
   5.144  
   5.145      data->type = GL_TEXTURE_2D;
   5.146      /* no NPOV textures allowed in OpenGL ES (yet) */
   5.147 @@ -365,17 +408,17 @@
   5.148      data->format = format;
   5.149      data->formattype = type;
   5.150      scaleMode = GetScaleQuality();
   5.151 -    glBindTexture(data->type, data->texture);
   5.152 -    glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER, scaleMode);
   5.153 -    glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER, scaleMode);
   5.154 -    glTexParameteri(data->type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
   5.155 -    glTexParameteri(data->type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
   5.156 +    renderdata->glBindTexture(data->type, data->texture);
   5.157 +    renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER, scaleMode);
   5.158 +    renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER, scaleMode);
   5.159 +    renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
   5.160 +    renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
   5.161  
   5.162 -    glTexImage2D(data->type, 0, internalFormat, texture_w,
   5.163 +    renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
   5.164                               texture_h, 0, format, type, NULL);
   5.165 -    glDisable(GL_TEXTURE_2D);
   5.166 +    renderdata->glDisable(GL_TEXTURE_2D);
   5.167  
   5.168 -    result = glGetError();
   5.169 +    result = renderdata->glGetError();
   5.170      if (result != GL_NO_ERROR) {
   5.171          GLES_SetError("glTexImage2D()", result);
   5.172          return -1;
   5.173 @@ -387,6 +430,7 @@
   5.174  GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   5.175                     const SDL_Rect * rect, const void *pixels, int pitch)
   5.176  {
   5.177 +    GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata;
   5.178      GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
   5.179      Uint8 *blob = NULL;
   5.180      Uint8 *src;
   5.181 @@ -421,11 +465,11 @@
   5.182      }
   5.183  
   5.184      /* Create a texture subimage with the supplied data */
   5.185 -    glGetError();
   5.186 -    glEnable(data->type);
   5.187 -    glBindTexture(data->type, data->texture);
   5.188 -    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
   5.189 -    glTexSubImage2D(data->type,
   5.190 +    renderdata->glGetError();
   5.191 +    renderdata->glEnable(data->type);
   5.192 +    renderdata->glBindTexture(data->type, data->texture);
   5.193 +    renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
   5.194 +    renderdata->glTexSubImage2D(data->type,
   5.195                      0,
   5.196                      rect->x,
   5.197                      rect->y,
   5.198 @@ -438,7 +482,7 @@
   5.199          SDL_free(blob);
   5.200      }
   5.201  
   5.202 -    if (glGetError() != GL_NO_ERROR)
   5.203 +    if (renderdata->glGetError() != GL_NO_ERROR)
   5.204      {
   5.205          SDL_SetError("Failed to update texture");
   5.206          return -1;
   5.207 @@ -483,12 +527,12 @@
   5.208          return 0;
   5.209      }
   5.210  
   5.211 -    glViewport(renderer->viewport.x, renderer->viewport.y,
   5.212 +    data->glViewport(renderer->viewport.x, renderer->viewport.y,
   5.213                 renderer->viewport.w, renderer->viewport.h);
   5.214  
   5.215 -    glMatrixMode(GL_PROJECTION);
   5.216 -    glLoadIdentity();
   5.217 -    glOrthof((GLfloat) 0,
   5.218 +    data->glMatrixMode(GL_PROJECTION);
   5.219 +    data->glLoadIdentity();
   5.220 +    data->glOrthof((GLfloat) 0,
   5.221               (GLfloat) renderer->viewport.w,
   5.222               (GLfloat) renderer->viewport.h,
   5.223               (GLfloat) 0, 0.0, 1.0);
   5.224 @@ -501,7 +545,7 @@
   5.225      Uint32 color = ((a << 24) | (r << 16) | (g << 8) | b);
   5.226  
   5.227      if (color != data->current.color) {
   5.228 -        glColor4f((GLfloat) r * inv255f,
   5.229 +        data->glColor4f((GLfloat) r * inv255f,
   5.230                          (GLfloat) g * inv255f,
   5.231                          (GLfloat) b * inv255f,
   5.232                          (GLfloat) a * inv255f);
   5.233 @@ -515,23 +559,23 @@
   5.234      if (blendMode != data->current.blendMode) {
   5.235          switch (blendMode) {
   5.236          case SDL_BLENDMODE_NONE:
   5.237 -            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
   5.238 -            glDisable(GL_BLEND);
   5.239 +            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
   5.240 +            data->glDisable(GL_BLEND);
   5.241              break;
   5.242          case SDL_BLENDMODE_BLEND:
   5.243 -            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
   5.244 -            glEnable(GL_BLEND);
   5.245 -            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   5.246 +            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
   5.247 +            data->glEnable(GL_BLEND);
   5.248 +            data->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   5.249              break;
   5.250          case SDL_BLENDMODE_ADD:
   5.251 -            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
   5.252 -            glEnable(GL_BLEND);
   5.253 -            glBlendFunc(GL_SRC_ALPHA, GL_ONE);
   5.254 +            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
   5.255 +            data->glEnable(GL_BLEND);
   5.256 +            data->glBlendFunc(GL_SRC_ALPHA, GL_ONE);
   5.257              break;
   5.258          case SDL_BLENDMODE_MOD:
   5.259 -            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
   5.260 -            glEnable(GL_BLEND);
   5.261 -            glBlendFunc(GL_ZERO, GL_SRC_COLOR);
   5.262 +            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
   5.263 +            data->glEnable(GL_BLEND);
   5.264 +            data->glBlendFunc(GL_ZERO, GL_SRC_COLOR);
   5.265              break;
   5.266          }
   5.267          data->current.blendMode = blendMode;
   5.268 @@ -543,9 +587,9 @@
   5.269  {
   5.270      if (enabled != data->current.tex_coords) {
   5.271          if (enabled) {
   5.272 -            glEnableClientState(GL_TEXTURE_COORD_ARRAY);
   5.273 +            data->glEnableClientState(GL_TEXTURE_COORD_ARRAY);
   5.274          } else {
   5.275 -            glDisableClientState(GL_TEXTURE_COORD_ARRAY);
   5.276 +            data->glDisableClientState(GL_TEXTURE_COORD_ARRAY);
   5.277          }
   5.278          data->current.tex_coords = enabled;
   5.279      }
   5.280 @@ -571,14 +615,16 @@
   5.281  static int
   5.282  GLES_RenderClear(SDL_Renderer * renderer)
   5.283  {
   5.284 +    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
   5.285 +
   5.286      GLES_ActivateRenderer(renderer);
   5.287  
   5.288 -    glClearColor((GLfloat) renderer->r * inv255f,
   5.289 +    data->glClearColor((GLfloat) renderer->r * inv255f,
   5.290                   (GLfloat) renderer->g * inv255f,
   5.291                   (GLfloat) renderer->b * inv255f,
   5.292                   (GLfloat) renderer->a * inv255f);
   5.293  
   5.294 -    glClear(GL_COLOR_BUFFER_BIT);
   5.295 +    data->glClear(GL_COLOR_BUFFER_BIT);
   5.296  
   5.297      return 0;
   5.298  }
   5.299 @@ -587,6 +633,7 @@
   5.300  GLES_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points,
   5.301                        int count)
   5.302  {
   5.303 +    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
   5.304      int i;
   5.305      GLshort *vertices;
   5.306  
   5.307 @@ -597,8 +644,8 @@
   5.308          vertices[2*i+0] = (GLshort)points[i].x;
   5.309          vertices[2*i+1] = (GLshort)points[i].y;
   5.310      }
   5.311 -    glVertexPointer(2, GL_SHORT, 0, vertices);
   5.312 -    glDrawArrays(GL_POINTS, 0, count);
   5.313 +    data->glVertexPointer(2, GL_SHORT, 0, vertices);
   5.314 +    data->glDrawArrays(GL_POINTS, 0, count);
   5.315      SDL_stack_free(vertices);
   5.316  
   5.317      return 0;
   5.318 @@ -608,6 +655,7 @@
   5.319  GLES_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points,
   5.320                       int count)
   5.321  {
   5.322 +    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
   5.323      int i;
   5.324      GLshort *vertices;
   5.325  
   5.326 @@ -618,16 +666,16 @@
   5.327          vertices[2*i+0] = (GLshort)points[i].x;
   5.328          vertices[2*i+1] = (GLshort)points[i].y;
   5.329      }
   5.330 -    glVertexPointer(2, GL_SHORT, 0, vertices);
   5.331 +    data->glVertexPointer(2, GL_SHORT, 0, vertices);
   5.332      if (count > 2 && 
   5.333          points[0].x == points[count-1].x && points[0].y == points[count-1].y) {
   5.334          /* GL_LINE_LOOP takes care of the final segment */
   5.335          --count;
   5.336 -        glDrawArrays(GL_LINE_LOOP, 0, count);
   5.337 +        data->glDrawArrays(GL_LINE_LOOP, 0, count);
   5.338      } else {
   5.339 -        glDrawArrays(GL_LINE_STRIP, 0, count);
   5.340 +        data->glDrawArrays(GL_LINE_STRIP, 0, count);
   5.341          /* We need to close the endpoint of the line */
   5.342 -        glDrawArrays(GL_POINTS, count-1, 1);
   5.343 +        data->glDrawArrays(GL_POINTS, count-1, 1);
   5.344      }
   5.345      SDL_stack_free(vertices);
   5.346  
   5.347 @@ -638,6 +686,7 @@
   5.348  GLES_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect * rects,
   5.349                       int count)
   5.350  {
   5.351 +    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
   5.352      int i;
   5.353  
   5.354      GLES_SetDrawingState(renderer);
   5.355 @@ -658,8 +707,8 @@
   5.356          vertices[6] = maxx;
   5.357          vertices[7] = maxy;
   5.358  
   5.359 -        glVertexPointer(2, GL_SHORT, 0, vertices);
   5.360 -        glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
   5.361 +        data->glVertexPointer(2, GL_SHORT, 0, vertices);
   5.362 +        data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
   5.363      }
   5.364  
   5.365      return 0;
   5.366 @@ -677,9 +726,9 @@
   5.367  
   5.368      GLES_ActivateRenderer(renderer);
   5.369  
   5.370 -    glEnable(GL_TEXTURE_2D);
   5.371 +    data->glEnable(GL_TEXTURE_2D);
   5.372  
   5.373 -    glBindTexture(texturedata->type, texturedata->texture);
   5.374 +    data->glBindTexture(texturedata->type, texturedata->texture);
   5.375  
   5.376      if (texture->modMode) {
   5.377          GLES_SetColor(data, texture->r, texture->g, texture->b, texture->a);
   5.378 @@ -702,9 +751,9 @@
   5.379          cropRect[1] = srcrect->y + srcrect->h;
   5.380          cropRect[2] = srcrect->w;
   5.381          cropRect[3] = -srcrect->h;
   5.382 -        glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES,
   5.383 +        data->glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES,
   5.384                                 cropRect);
   5.385 -        glDrawTexiOES(renderer->viewport.x + dstrect->x,
   5.386 +        data->glDrawTexiOES(renderer->viewport.x + dstrect->x,
   5.387  	              h - (renderer->viewport.y + dstrect->y) - dstrect->h, 0,
   5.388                              dstrect->w, dstrect->h);
   5.389      } else {
   5.390 @@ -744,11 +793,11 @@
   5.391          texCoords[6] = maxu;
   5.392          texCoords[7] = maxv;
   5.393  
   5.394 -        glVertexPointer(2, GL_SHORT, 0, vertices);
   5.395 -        glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
   5.396 -        glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
   5.397 +        data->glVertexPointer(2, GL_SHORT, 0, vertices);
   5.398 +        data->glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
   5.399 +        data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
   5.400      }
   5.401 -    glDisable(GL_TEXTURE_2D);
   5.402 +    data->glDisable(GL_TEXTURE_2D);
   5.403  
   5.404      return 0;
   5.405  }
   5.406 @@ -757,6 +806,7 @@
   5.407  GLES_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
   5.408                      Uint32 pixel_format, void * pixels, int pitch)
   5.409  {
   5.410 +    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
   5.411      SDL_Window *window = renderer->window;
   5.412      Uint32 temp_format = SDL_PIXELFORMAT_ABGR8888;
   5.413      void *temp_pixels;
   5.414 @@ -776,9 +826,9 @@
   5.415  
   5.416      SDL_GetWindowSize(window, &w, &h);
   5.417  
   5.418 -    glPixelStorei(GL_PACK_ALIGNMENT, 1);
   5.419 +    data->glPixelStorei(GL_PACK_ALIGNMENT, 1);
   5.420  
   5.421 -    glReadPixels(rect->x, (h-rect->y)-rect->h, rect->w, rect->h,
   5.422 +    data->glReadPixels(rect->x, (h-rect->y)-rect->h, rect->w, rect->h,
   5.423                         GL_RGBA, GL_UNSIGNED_BYTE, temp_pixels);
   5.424  
   5.425      /* Flip the rows to be top-down */
   5.426 @@ -815,6 +865,8 @@
   5.427  static void
   5.428  GLES_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   5.429  {
   5.430 +    GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata;
   5.431 +
   5.432      GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
   5.433  
   5.434      GLES_ActivateRenderer(renderer);
   5.435 @@ -823,7 +875,7 @@
   5.436          return;
   5.437      }
   5.438      if (data->texture) {
   5.439 -        glDeleteTextures(1, &data->texture);
   5.440 +        renderdata->glDeleteTextures(1, &data->texture);
   5.441      }
   5.442      if (data->pixels) {
   5.443          SDL_free(data->pixels);
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/render/opengles2/SDL_gles2funcs.h	Sun Jan 08 02:23:37 2012 -0500
     6.3 @@ -0,0 +1,42 @@
     6.4 +SDL_PROC(void, glActiveTexture, (GLenum))
     6.5 +SDL_PROC(void, glAttachShader, (GLuint, GLuint))
     6.6 +SDL_PROC(void, glBindAttribLocation, (GLuint, GLuint, const char *))
     6.7 +SDL_PROC(void, glBindTexture, (GLenum, GLuint))
     6.8 +SDL_PROC(void, glBlendFunc, (GLenum, GLenum))
     6.9 +SDL_PROC(void, glClear, (GLbitfield))
    6.10 +SDL_PROC(void, glClearColor, (GLclampf, GLclampf, GLclampf, GLclampf))
    6.11 +SDL_PROC(void, glCompileShader, (GLuint))
    6.12 +SDL_PROC(GLuint, glCreateProgram, (void))
    6.13 +SDL_PROC(GLuint, glCreateShader, (GLenum))
    6.14 +SDL_PROC(void, glDeleteProgram, (GLuint))
    6.15 +SDL_PROC(void, glDeleteShader, (GLuint))
    6.16 +SDL_PROC(void, glDeleteTextures, (GLsizei, const GLuint *))
    6.17 +SDL_PROC(void, glDisable, (GLenum))
    6.18 +SDL_PROC(void, glDisableVertexAttribArray, (GLuint))
    6.19 +SDL_PROC(void, glDrawArrays, (GLenum, GLint, GLsizei))
    6.20 +SDL_PROC(void, glEnable, (GLenum))
    6.21 +SDL_PROC(void, glEnableVertexAttribArray, (GLuint))
    6.22 +SDL_PROC(void, glFinish, (void))
    6.23 +SDL_PROC(void, glGenTextures, (GLsizei, GLuint *))
    6.24 +SDL_PROC(void, glGetBooleanv, (GLenum, GLboolean *))
    6.25 +SDL_PROC(const GLubyte *, glGetString, (GLenum))
    6.26 +SDL_PROC(GLenum, glGetError, (void))
    6.27 +SDL_PROC(void, glGetIntegerv, (GLenum, GLint *))
    6.28 +SDL_PROC(void, glGetProgramiv, (GLuint, GLenum, GLint *))
    6.29 +SDL_PROC(void, glGetShaderInfoLog, (GLuint, GLsizei, GLsizei *, char *))
    6.30 +SDL_PROC(void, glGetShaderiv, (GLuint, GLenum, GLint *))
    6.31 +SDL_PROC(GLint, glGetUniformLocation, (GLuint, const char *))
    6.32 +SDL_PROC(void, glLinkProgram, (GLuint))
    6.33 +SDL_PROC(void, glPixelStorei, (GLenum, GLint))
    6.34 +SDL_PROC(void, glReadPixels, (GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoid*))
    6.35 +SDL_PROC(void, glShaderBinary, (GLsizei, const GLuint *, GLenum, const void *, GLsizei))
    6.36 +SDL_PROC(void, glShaderSource, (GLuint, GLsizei, const char **, const GLint *))
    6.37 +SDL_PROC(void, glTexImage2D, (GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, const void *))
    6.38 +SDL_PROC(void, glTexParameteri, (GLenum, GLenum, GLint))
    6.39 +SDL_PROC(void, glTexSubImage2D, (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *))
    6.40 +SDL_PROC(void, glUniform1i, (GLint, GLint))
    6.41 +SDL_PROC(void, glUniform4f, (GLint, GLfloat, GLfloat, GLfloat, GLfloat))
    6.42 +SDL_PROC(void, glUniformMatrix4fv, (GLint, GLsizei, GLboolean, const GLfloat *))
    6.43 +SDL_PROC(void, glUseProgram, (GLuint))
    6.44 +SDL_PROC(void, glVertexAttribPointer, (GLuint, GLint, GLenum, GLboolean, GLsizei, const void *))
    6.45 +SDL_PROC(void, glViewport, (GLint, GLint, GLsizei, GLsizei))
     7.1 --- a/src/render/opengles2/SDL_render_gles2.c	Sun Jan 08 01:15:20 2012 -0500
     7.2 +++ b/src/render/opengles2/SDL_render_gles2.c	Sun Jan 08 02:23:37 2012 -0500
     7.3 @@ -27,6 +27,9 @@
     7.4  #include "../SDL_sysrender.h"
     7.5  #include "SDL_shaders_gles2.h"
     7.6  
     7.7 +/* Used to re-create the window with OpenGL capability */
     7.8 +extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
     7.9 +
    7.10  /*************************************************************************************************
    7.11   * Bootstrap data                                                                                *
    7.12   *************************************************************************************************/
    7.13 @@ -128,6 +131,10 @@
    7.14          SDL_bool tex_coords;
    7.15      } current;
    7.16  
    7.17 +#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
    7.18 +#include "SDL_gles2funcs.h"
    7.19 +#undef SDL_PROC
    7.20 +
    7.21      int shader_format_count;
    7.22      GLenum *shader_formats;
    7.23      GLES2_ShaderCache shader_cache;
    7.24 @@ -149,6 +156,26 @@
    7.25  
    7.26  static SDL_GLContext SDL_CurrentContext = NULL;
    7.27  
    7.28 +static int GLES2_LoadFunctions(GLES2_DriverContext * data)
    7.29 +{
    7.30 +#ifdef __SDL_NOGETPROCADDR__
    7.31 +#define SDL_PROC(ret,func,params) data->func=func;
    7.32 +#else
    7.33 +#define SDL_PROC(ret,func,params) \
    7.34 +    do { \
    7.35 +        data->func = SDL_GL_GetProcAddress(#func); \
    7.36 +        if ( ! data->func ) { \
    7.37 +            SDL_SetError("Couldn't load GLES2 function %s: %s\n", #func, SDL_GetError()); \
    7.38 +            return -1; \
    7.39 +        } \
    7.40 +    } while ( 0 );  
    7.41 +#endif /* _SDL_NOGETPROCADDR_ */
    7.42 +
    7.43 +#include "SDL_gles2funcs.h"
    7.44 +#undef SDL_PROC
    7.45 +    return 0;
    7.46 +}
    7.47 +
    7.48  static int
    7.49  GLES2_ActivateRenderer(SDL_Renderer * renderer)
    7.50  {
    7.51 @@ -171,6 +198,8 @@
    7.52  static void
    7.53  GLES2_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
    7.54  {
    7.55 +    GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
    7.56 +    
    7.57      if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) {
    7.58          /* Rebind the context to the window area */
    7.59          SDL_CurrentContext = NULL;
    7.60 @@ -178,7 +207,7 @@
    7.61  
    7.62      if (event->event == SDL_WINDOWEVENT_MINIMIZED) {
    7.63          /* According to Apple documentation, we need to finish drawing NOW! */
    7.64 -        glFinish();
    7.65 +        rdata->glFinish();
    7.66      }
    7.67  }
    7.68  
    7.69 @@ -192,7 +221,7 @@
    7.70          return 0;
    7.71      }
    7.72  
    7.73 -    glViewport(renderer->viewport.x, renderer->viewport.y,
    7.74 +    rdata->glViewport(renderer->viewport.x, renderer->viewport.y,
    7.75                 renderer->viewport.w, renderer->viewport.h);
    7.76      return 0;
    7.77  }
    7.78 @@ -212,7 +241,7 @@
    7.79              entry = rdata->shader_cache.head;
    7.80              while (entry)
    7.81              {
    7.82 -                glDeleteShader(entry->id);
    7.83 +                rdata->glDeleteShader(entry->id);
    7.84                  next = entry->next;
    7.85                  SDL_free(entry);
    7.86                  entry = next;
    7.87 @@ -223,7 +252,7 @@
    7.88              GLES2_ProgramCacheEntry *next;
    7.89              entry = rdata->program_cache.head;
    7.90              while (entry) {
    7.91 -                glDeleteProgram(entry->id);
    7.92 +                rdata->glDeleteProgram(entry->id);
    7.93                  next = entry->next;
    7.94                  SDL_free(entry);
    7.95                  entry = next;
    7.96 @@ -267,6 +296,7 @@
    7.97  static int
    7.98  GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
    7.99  {
   7.100 +    GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
   7.101      GLES2_TextureData *tdata;
   7.102      GLenum format;
   7.103      GLenum type;
   7.104 @@ -316,19 +346,19 @@
   7.105      }
   7.106  
   7.107      /* Allocate the texture */
   7.108 -    glGetError();
   7.109 -    glGenTextures(1, &tdata->texture);
   7.110 -    glActiveTexture(GL_TEXTURE0);
   7.111 -    glBindTexture(tdata->texture_type, tdata->texture);
   7.112 -    glTexParameteri(tdata->texture_type, GL_TEXTURE_MIN_FILTER, scaleMode);
   7.113 -    glTexParameteri(tdata->texture_type, GL_TEXTURE_MAG_FILTER, scaleMode);
   7.114 -    glTexParameteri(tdata->texture_type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
   7.115 -    glTexParameteri(tdata->texture_type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
   7.116 -    glTexImage2D(tdata->texture_type, 0, format, texture->w, texture->h, 0, format, type, NULL);
   7.117 -    if (glGetError() != GL_NO_ERROR)
   7.118 +    rdata->glGetError();
   7.119 +    rdata->glGenTextures(1, &tdata->texture);
   7.120 +    rdata->glActiveTexture(GL_TEXTURE0);
   7.121 +    rdata->glBindTexture(tdata->texture_type, tdata->texture);
   7.122 +    rdata->glTexParameteri(tdata->texture_type, GL_TEXTURE_MIN_FILTER, scaleMode);
   7.123 +    rdata->glTexParameteri(tdata->texture_type, GL_TEXTURE_MAG_FILTER, scaleMode);
   7.124 +    rdata->glTexParameteri(tdata->texture_type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
   7.125 +    rdata->glTexParameteri(tdata->texture_type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
   7.126 +    rdata->glTexImage2D(tdata->texture_type, 0, format, texture->w, texture->h, 0, format, type, NULL);
   7.127 +    if (rdata->glGetError() != GL_NO_ERROR)
   7.128      {
   7.129          SDL_SetError("Texture creation failed");
   7.130 -        glDeleteTextures(1, &tdata->texture);
   7.131 +        rdata->glDeleteTextures(1, &tdata->texture);
   7.132          SDL_free(tdata);
   7.133          return -1;
   7.134      }
   7.135 @@ -339,6 +369,7 @@
   7.136  static void
   7.137  GLES2_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture)
   7.138  {
   7.139 +    GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
   7.140      GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata;
   7.141  
   7.142      GLES2_ActivateRenderer(renderer);
   7.143 @@ -346,7 +377,7 @@
   7.144      /* Destroy the texture */
   7.145      if (tdata)
   7.146      {
   7.147 -        glDeleteTextures(1, &tdata->texture);
   7.148 +        rdata->glDeleteTextures(1, &tdata->texture);
   7.149          SDL_free(tdata->pixel_data);
   7.150          SDL_free(tdata);
   7.151          texture->driverdata = NULL;
   7.152 @@ -386,6 +417,7 @@
   7.153  GLES2_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect,
   7.154                      const void *pixels, int pitch)
   7.155  {
   7.156 +    GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
   7.157      GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata;
   7.158      Uint8 *blob = NULL;
   7.159      Uint8 *src;
   7.160 @@ -393,7 +425,7 @@
   7.161      int y;
   7.162  
   7.163      GLES2_ActivateRenderer(renderer);
   7.164 -
   7.165 +    
   7.166      /* Bail out if we're supposed to update an empty rectangle */
   7.167      if (rect->w <= 0 || rect->h <= 0)
   7.168          return 0;
   7.169 @@ -420,11 +452,11 @@
   7.170      }
   7.171  
   7.172      /* Create a texture subimage with the supplied data */
   7.173 -    glGetError();
   7.174 -    glActiveTexture(GL_TEXTURE0);
   7.175 -    glBindTexture(tdata->texture_type, tdata->texture);
   7.176 -    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
   7.177 -    glTexSubImage2D(tdata->texture_type,
   7.178 +    rdata->glGetError();
   7.179 +    rdata->glActiveTexture(GL_TEXTURE0);
   7.180 +    rdata->glBindTexture(tdata->texture_type, tdata->texture);
   7.181 +    rdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
   7.182 +    rdata->glTexSubImage2D(tdata->texture_type,
   7.183                      0,
   7.184                      rect->x,
   7.185                      rect->y,
   7.186 @@ -437,7 +469,7 @@
   7.187          SDL_free(blob);
   7.188      }
   7.189  
   7.190 -    if (glGetError() != GL_NO_ERROR)
   7.191 +    if (rdata->glGetError() != GL_NO_ERROR)
   7.192      {
   7.193          SDL_SetError("Failed to update texture");
   7.194          return -1;
   7.195 @@ -505,33 +537,33 @@
   7.196      entry->blend_mode = blendMode;
   7.197      
   7.198      /* Create the program and link it */
   7.199 -    glGetError();
   7.200 -    entry->id = glCreateProgram();
   7.201 -    glAttachShader(entry->id, vertex->id);
   7.202 -    glAttachShader(entry->id, fragment->id);
   7.203 -    glBindAttribLocation(entry->id, GLES2_ATTRIBUTE_POSITION, "a_position");
   7.204 -    glBindAttribLocation(entry->id, GLES2_ATTRIBUTE_TEXCOORD, "a_texCoord");
   7.205 -    glLinkProgram(entry->id);
   7.206 -    glGetProgramiv(entry->id, GL_LINK_STATUS, &linkSuccessful);
   7.207 -    if (glGetError() != GL_NO_ERROR || !linkSuccessful)
   7.208 +    rdata->glGetError();
   7.209 +    entry->id = rdata->glCreateProgram();
   7.210 +    rdata->glAttachShader(entry->id, vertex->id);
   7.211 +    rdata->glAttachShader(entry->id, fragment->id);
   7.212 +    rdata->glBindAttribLocation(entry->id, GLES2_ATTRIBUTE_POSITION, "a_position");
   7.213 +    rdata->glBindAttribLocation(entry->id, GLES2_ATTRIBUTE_TEXCOORD, "a_texCoord");
   7.214 +    rdata->glLinkProgram(entry->id);
   7.215 +    rdata->glGetProgramiv(entry->id, GL_LINK_STATUS, &linkSuccessful);
   7.216 +    if (rdata->glGetError() != GL_NO_ERROR || !linkSuccessful)
   7.217      {
   7.218          SDL_SetError("Failed to link shader program");
   7.219 -        glDeleteProgram(entry->id);
   7.220 +        rdata->glDeleteProgram(entry->id);
   7.221          SDL_free(entry);
   7.222          return NULL;
   7.223      }
   7.224      
   7.225      /* Predetermine locations of uniform variables */
   7.226      entry->uniform_locations[GLES2_UNIFORM_PROJECTION] =
   7.227 -        glGetUniformLocation(entry->id, "u_projection");
   7.228 +        rdata->glGetUniformLocation(entry->id, "u_projection");
   7.229      entry->uniform_locations[GLES2_UNIFORM_TEXTURE] =
   7.230 -        glGetUniformLocation(entry->id, "u_texture");
   7.231 +        rdata->glGetUniformLocation(entry->id, "u_texture");
   7.232      entry->uniform_locations[GLES2_UNIFORM_MODULATION] =
   7.233 -        glGetUniformLocation(entry->id, "u_modulation");
   7.234 +        rdata->glGetUniformLocation(entry->id, "u_modulation");
   7.235      entry->uniform_locations[GLES2_UNIFORM_COLOR] =
   7.236 -        glGetUniformLocation(entry->id, "u_color");
   7.237 +        rdata->glGetUniformLocation(entry->id, "u_color");
   7.238      entry->uniform_locations[GLES2_UNIFORM_COLORTABLE] =
   7.239 -        glGetUniformLocation(entry->id, "u_colorTable");
   7.240 +        rdata->glGetUniformLocation(entry->id, "u_colorTable");
   7.241  
   7.242      /* Cache the linked program */
   7.243      if (rdata->program_cache.head)
   7.244 @@ -559,7 +591,7 @@
   7.245          shaderEntry = rdata->program_cache.tail->fragment_shader;
   7.246          if (--shaderEntry->references <= 0)
   7.247              GLES2_EvictShader(renderer, shaderEntry);
   7.248 -        glDeleteProgram(rdata->program_cache.tail->id);
   7.249 +        rdata->glDeleteProgram(rdata->program_cache.tail->id);
   7.250          rdata->program_cache.tail = rdata->program_cache.tail->prev;
   7.251          SDL_free(rdata->program_cache.tail->next);
   7.252          rdata->program_cache.tail->next = NULL;
   7.253 @@ -628,29 +660,29 @@
   7.254      entry->instance = instance;
   7.255  
   7.256      /* Compile or load the selected shader instance */
   7.257 -    glGetError();
   7.258 -    entry->id = glCreateShader(instance->type);
   7.259 +    rdata->glGetError();
   7.260 +    entry->id = rdata->glCreateShader(instance->type);
   7.261      if (instance->format == (GLenum)-1)
   7.262      {
   7.263 -        glShaderSource(entry->id, 1, (const char **)&instance->data, NULL);
   7.264 -        glCompileShader(entry->id);
   7.265 -        glGetShaderiv(entry->id, GL_COMPILE_STATUS, &compileSuccessful);
   7.266 +        rdata->glShaderSource(entry->id, 1, (const char **)&instance->data, NULL);
   7.267 +        rdata->glCompileShader(entry->id);
   7.268 +        rdata->glGetShaderiv(entry->id, GL_COMPILE_STATUS, &compileSuccessful);
   7.269      }
   7.270      else
   7.271      {
   7.272 -        glShaderBinary(1, &entry->id, instance->format, instance->data, instance->length);
   7.273 +        rdata->glShaderBinary(1, &entry->id, instance->format, instance->data, instance->length);
   7.274          compileSuccessful = GL_TRUE;
   7.275      }
   7.276 -    if (glGetError() != GL_NO_ERROR || !compileSuccessful)
   7.277 +    if (rdata->glGetError() != GL_NO_ERROR || !compileSuccessful)
   7.278      {
   7.279          char *info = NULL;
   7.280          int length = 0;
   7.281  
   7.282 -        glGetShaderiv(entry->id, GL_INFO_LOG_LENGTH, &length);
   7.283 +        rdata->glGetShaderiv(entry->id, GL_INFO_LOG_LENGTH, &length);
   7.284          if (length > 0) {
   7.285              info = SDL_stack_alloc(char, length);
   7.286              if (info) {
   7.287 -                glGetShaderInfoLog(entry->id, length, &length, info);
   7.288 +                rdata->glGetShaderInfoLog(entry->id, length, &length, info);
   7.289              }
   7.290          }
   7.291          if (info) {
   7.292 @@ -659,7 +691,7 @@
   7.293          } else {
   7.294              SDL_SetError("Failed to load the shader");
   7.295          }
   7.296 -        glDeleteShader(entry->id);
   7.297 +        rdata->glDeleteShader(entry->id);
   7.298          SDL_free(entry);
   7.299          return NULL;
   7.300      }
   7.301 @@ -690,7 +722,7 @@
   7.302      --rdata->shader_cache.count;
   7.303  
   7.304      /* Deallocate the shader */
   7.305 -    glDeleteShader(entry->id);
   7.306 +    rdata->glDeleteShader(entry->id);
   7.307      SDL_free(entry);
   7.308  }
   7.309  
   7.310 @@ -746,9 +778,9 @@
   7.311          goto fault;
   7.312  
   7.313      /* Select that program in OpenGL */
   7.314 -    glGetError();
   7.315 -    glUseProgram(program->id);
   7.316 -    if (glGetError() != GL_NO_ERROR)
   7.317 +    rdata->glGetError();
   7.318 +    rdata->glUseProgram(program->id);
   7.319 +    if (rdata->glGetError() != GL_NO_ERROR)
   7.320      {
   7.321          SDL_SetError("Failed to select program");
   7.322          goto fault;
   7.323 @@ -799,9 +831,9 @@
   7.324  
   7.325      /* Set the projection matrix */
   7.326      locProjection = rdata->current_program->uniform_locations[GLES2_UNIFORM_PROJECTION];
   7.327 -    glGetError();
   7.328 -    glUniformMatrix4fv(locProjection, 1, GL_FALSE, (GLfloat *)projection);
   7.329 -    if (glGetError() != GL_NO_ERROR)
   7.330 +    rdata->glGetError();
   7.331 +    rdata->glUniformMatrix4fv(locProjection, 1, GL_FALSE, (GLfloat *)projection);
   7.332 +    if (rdata->glGetError() != GL_NO_ERROR)
   7.333      {
   7.334          SDL_SetError("Failed to set orthographic projection");
   7.335          return -1;
   7.336 @@ -829,14 +861,16 @@
   7.337  static int
   7.338  GLES2_RenderClear(SDL_Renderer * renderer)
   7.339  {
   7.340 +    GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
   7.341 +
   7.342      GLES2_ActivateRenderer(renderer);
   7.343 -
   7.344 -    glClearColor((GLfloat) renderer->r * inv255f,
   7.345 +    
   7.346 +    rdata->glClearColor((GLfloat) renderer->r * inv255f,
   7.347                   (GLfloat) renderer->g * inv255f,
   7.348                   (GLfloat) renderer->b * inv255f,
   7.349                   (GLfloat) renderer->a * inv255f);
   7.350  
   7.351 -    glClear(GL_COLOR_BUFFER_BIT);
   7.352 +    rdata->glClear(GL_COLOR_BUFFER_BIT);
   7.353  
   7.354      return 0;
   7.355  }
   7.356 @@ -848,19 +882,19 @@
   7.357          switch (blendMode) {
   7.358          default:
   7.359          case SDL_BLENDMODE_NONE:
   7.360 -            glDisable(GL_BLEND);
   7.361 +            rdata->glDisable(GL_BLEND);
   7.362              break;
   7.363          case SDL_BLENDMODE_BLEND:
   7.364 -            glEnable(GL_BLEND);
   7.365 -            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   7.366 +            rdata->glEnable(GL_BLEND);
   7.367 +            rdata->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   7.368              break;
   7.369          case SDL_BLENDMODE_ADD:
   7.370 -            glEnable(GL_BLEND);
   7.371 -            glBlendFunc(GL_SRC_ALPHA, GL_ONE);
   7.372 +            rdata->glEnable(GL_BLEND);
   7.373 +            rdata->glBlendFunc(GL_SRC_ALPHA, GL_ONE);
   7.374              break;
   7.375          case SDL_BLENDMODE_MOD:
   7.376 -            glEnable(GL_BLEND);
   7.377 -            glBlendFunc(GL_ZERO, GL_SRC_COLOR);
   7.378 +            rdata->glEnable(GL_BLEND);
   7.379 +            rdata->glBlendFunc(GL_ZERO, GL_SRC_COLOR);
   7.380              break;
   7.381          }
   7.382          rdata->current.blendMode = blendMode;
   7.383 @@ -872,9 +906,9 @@
   7.384  {
   7.385      if (enabled != rdata->current.tex_coords) {
   7.386          if (enabled) {
   7.387 -            glEnableVertexAttribArray(GLES2_ATTRIBUTE_TEXCOORD);
   7.388 +            rdata->glEnableVertexAttribArray(GLES2_ATTRIBUTE_TEXCOORD);
   7.389          } else {
   7.390 -            glDisableVertexAttribArray(GLES2_ATTRIBUTE_TEXCOORD);
   7.391 +            rdata->glDisableVertexAttribArray(GLES2_ATTRIBUTE_TEXCOORD);
   7.392          }
   7.393          rdata->current.tex_coords = enabled;
   7.394      }
   7.395 @@ -887,7 +921,7 @@
   7.396      int blendMode = renderer->blendMode;
   7.397      GLuint locColor;
   7.398  
   7.399 -    glGetError();
   7.400 +    rdata->glGetError();
   7.401  
   7.402      GLES2_ActivateRenderer(renderer);
   7.403  
   7.404 @@ -901,7 +935,7 @@
   7.405  
   7.406      /* Select the color to draw with */
   7.407      locColor = rdata->current_program->uniform_locations[GLES2_UNIFORM_COLOR];
   7.408 -    glUniform4f(locColor,
   7.409 +    rdata->glUniform4f(locColor,
   7.410                  renderer->r * inv255f,
   7.411                  renderer->g * inv255f,
   7.412                  renderer->b * inv255f,
   7.413 @@ -912,6 +946,7 @@
   7.414  static int
   7.415  GLES2_RenderDrawPoints(SDL_Renderer *renderer, const SDL_Point *points, int count)
   7.416  {
   7.417 +    GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
   7.418      GLfloat *vertices;
   7.419      int idx;
   7.420  
   7.421 @@ -929,11 +964,11 @@
   7.422          vertices[idx * 2] = x;
   7.423          vertices[(idx * 2) + 1] = y;
   7.424      }
   7.425 -    glGetError();
   7.426 -    glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
   7.427 -    glDrawArrays(GL_POINTS, 0, count);
   7.428 +    rdata->glGetError();
   7.429 +    rdata->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
   7.430 +    rdata->glDrawArrays(GL_POINTS, 0, count);
   7.431      SDL_stack_free(vertices);
   7.432 -    if (glGetError() != GL_NO_ERROR)
   7.433 +    if (rdata->glGetError() != GL_NO_ERROR)
   7.434      {
   7.435          SDL_SetError("Failed to render lines");
   7.436          return -1;
   7.437 @@ -944,6 +979,7 @@
   7.438  static int
   7.439  GLES2_RenderDrawLines(SDL_Renderer *renderer, const SDL_Point *points, int count)
   7.440  {
   7.441 +    GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
   7.442      GLfloat *vertices;
   7.443      int idx;
   7.444  
   7.445 @@ -961,17 +997,17 @@
   7.446          vertices[idx * 2] = x;
   7.447          vertices[(idx * 2) + 1] = y;
   7.448      }
   7.449 -    glGetError();
   7.450 -    glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
   7.451 -    glDrawArrays(GL_LINE_STRIP, 0, count);
   7.452 +    rdata->glGetError();
   7.453 +    rdata->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
   7.454 +    rdata->glDrawArrays(GL_LINE_STRIP, 0, count);
   7.455  
   7.456      /* We need to close the endpoint of the line */
   7.457      if (count == 2 ||
   7.458          points[0].x != points[count-1].x || points[0].y != points[count-1].y) {
   7.459 -        glDrawArrays(GL_POINTS, count-1, 1);
   7.460 +        rdata->glDrawArrays(GL_POINTS, count-1, 1);
   7.461      }
   7.462      SDL_stack_free(vertices);
   7.463 -    if (glGetError() != GL_NO_ERROR)
   7.464 +    if (rdata->glGetError() != GL_NO_ERROR)
   7.465      {
   7.466          SDL_SetError("Failed to render lines");
   7.467          return -1;
   7.468 @@ -982,6 +1018,7 @@
   7.469  static int
   7.470  GLES2_RenderFillRects(SDL_Renderer *renderer, const SDL_Rect *rects, int count)
   7.471  {
   7.472 +    GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
   7.473      GLfloat vertices[8];
   7.474      int idx;
   7.475  
   7.476 @@ -990,7 +1027,7 @@
   7.477      }
   7.478  
   7.479      /* Emit a line loop for each rectangle */
   7.480 -    glGetError();
   7.481 +    rdata->glGetError();
   7.482      for (idx = 0; idx < count; ++idx) {
   7.483          const SDL_Rect *rect = &rects[idx];
   7.484  
   7.485 @@ -1007,10 +1044,10 @@
   7.486          vertices[5] = yMax;
   7.487          vertices[6] = xMax;
   7.488          vertices[7] = yMax;
   7.489 -        glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
   7.490 -        glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
   7.491 +        rdata->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
   7.492 +        rdata->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
   7.493      }
   7.494 -    if (glGetError() != GL_NO_ERROR)
   7.495 +    if (rdata->glGetError() != GL_NO_ERROR)
   7.496      {
   7.497          SDL_SetError("Failed to render lines");
   7.498          return -1;
   7.499 @@ -1055,14 +1092,14 @@
   7.500  
   7.501      /* Select the target texture */
   7.502      locTexture = rdata->current_program->uniform_locations[GLES2_UNIFORM_TEXTURE];
   7.503 -    glGetError();
   7.504 -    glActiveTexture(GL_TEXTURE0);
   7.505 -    glBindTexture(tdata->texture_type, tdata->texture);
   7.506 -    glUniform1i(locTexture, 0);
   7.507 +    rdata->glGetError();
   7.508 +    rdata->glActiveTexture(GL_TEXTURE0);
   7.509 +    rdata->glBindTexture(tdata->texture_type, tdata->texture);
   7.510 +    rdata->glUniform1i(locTexture, 0);
   7.511  
   7.512      /* Configure color modulation */
   7.513      locModulation = rdata->current_program->uniform_locations[GLES2_UNIFORM_MODULATION];
   7.514 -    glUniform4f(locModulation,
   7.515 +    rdata->glUniform4f(locModulation,
   7.516                  texture->r * inv255f,
   7.517                  texture->g * inv255f,
   7.518                  texture->b * inv255f,
   7.519 @@ -1082,7 +1119,7 @@
   7.520      vertices[5] = (GLfloat)(dstrect->y + dstrect->h);
   7.521      vertices[6] = (GLfloat)(dstrect->x + dstrect->w);
   7.522      vertices[7] = (GLfloat)(dstrect->y + dstrect->h);
   7.523 -    glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
   7.524 +    rdata->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
   7.525      texCoords[0] = srcrect->x / (GLfloat)texture->w;
   7.526      texCoords[1] = srcrect->y / (GLfloat)texture->h;
   7.527      texCoords[2] = (srcrect->x + srcrect->w) / (GLfloat)texture->w;
   7.528 @@ -1091,9 +1128,9 @@
   7.529      texCoords[5] = (srcrect->y + srcrect->h) / (GLfloat)texture->h;
   7.530      texCoords[6] = (srcrect->x + srcrect->w) / (GLfloat)texture->w;
   7.531      texCoords[7] = (srcrect->y + srcrect->h) / (GLfloat)texture->h;
   7.532 -    glVertexAttribPointer(GLES2_ATTRIBUTE_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 0, texCoords);
   7.533 -    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
   7.534 -    if (glGetError() != GL_NO_ERROR)
   7.535 +    rdata->glVertexAttribPointer(GLES2_ATTRIBUTE_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 0, texCoords);
   7.536 +    rdata->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
   7.537 +    if (rdata->glGetError() != GL_NO_ERROR)
   7.538      {
   7.539          SDL_SetError("Failed to render texture");
   7.540          return -1;
   7.541 @@ -1105,6 +1142,7 @@
   7.542  GLES2_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
   7.543                      Uint32 pixel_format, void * pixels, int pitch)
   7.544  {
   7.545 +    GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
   7.546      SDL_Window *window = renderer->window;
   7.547      Uint32 temp_format = SDL_PIXELFORMAT_ABGR8888;
   7.548      void *temp_pixels;
   7.549 @@ -1124,9 +1162,9 @@
   7.550  
   7.551      SDL_GetWindowSize(window, &w, &h);
   7.552  
   7.553 -    glPixelStorei(GL_PACK_ALIGNMENT, 1);
   7.554 +    rdata->glPixelStorei(GL_PACK_ALIGNMENT, 1);
   7.555  
   7.556 -    glReadPixels(rect->x, (h-rect->y)-rect->h, rect->w, rect->h,
   7.557 +    rdata->glReadPixels(rect->x, (h-rect->y)-rect->h, rect->w, rect->h,
   7.558                         GL_RGBA, GL_UNSIGNED_BYTE, temp_pixels);
   7.559  
   7.560      /* Flip the rows to be top-down */
   7.561 @@ -1181,8 +1219,8 @@
   7.562      rdata->current.blendMode = -1;
   7.563      rdata->current.tex_coords = SDL_FALSE;
   7.564  
   7.565 -    glEnableVertexAttribArray(GLES2_ATTRIBUTE_POSITION);
   7.566 -    glDisableVertexAttribArray(GLES2_ATTRIBUTE_TEXCOORD);
   7.567 +    rdata->glEnableVertexAttribArray(GLES2_ATTRIBUTE_POSITION);
   7.568 +    rdata->glDisableVertexAttribArray(GLES2_ATTRIBUTE_TEXCOORD);
   7.569  }
   7.570  
   7.571  static SDL_Renderer *
   7.572 @@ -1194,6 +1232,19 @@
   7.573  #ifndef ZUNE_HD
   7.574      GLboolean hasCompiler;
   7.575  #endif
   7.576 +    Uint32 windowFlags;
   7.577 +    
   7.578 +    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
   7.579 +    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
   7.580 +    
   7.581 +    windowFlags = SDL_GetWindowFlags(window);
   7.582 +    if (!(windowFlags & SDL_WINDOW_OPENGL)) {
   7.583 +        if (SDL_RecreateWindow(window, windowFlags | SDL_WINDOW_OPENGL) < 0) {
   7.584 +            /* Uh oh, better try to put it back... */
   7.585 +            SDL_RecreateWindow(window, windowFlags);
   7.586 +            return NULL;
   7.587 +        }
   7.588 +    }
   7.589  
   7.590      /* Create the renderer struct */
   7.591      renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(SDL_Renderer));
   7.592 @@ -1214,9 +1265,6 @@
   7.593      renderer->window = window;
   7.594  
   7.595      /* Create an OpenGL ES 2.0 context */
   7.596 -    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
   7.597 -    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
   7.598 -
   7.599      rdata->context = SDL_GL_CreateContext(window);
   7.600      if (!rdata->context)
   7.601      {
   7.602 @@ -1228,6 +1276,11 @@
   7.603          return NULL;
   7.604      }
   7.605  
   7.606 +    if (GLES2_LoadFunctions(rdata) < 0) {
   7.607 +        GLES2_DestroyRenderer(renderer);
   7.608 +        return NULL;
   7.609 +    }
   7.610 +
   7.611      if (flags & SDL_RENDERER_PRESENTVSYNC) {
   7.612          SDL_GL_SetSwapInterval(1);
   7.613      } else {
   7.614 @@ -1239,12 +1292,12 @@
   7.615  
   7.616      /* Determine supported shader formats */
   7.617      /* HACK: glGetInteger is broken on the Zune HD's compositor, so we just hardcode this */
   7.618 -    glGetError();
   7.619 +    rdata->glGetError();
   7.620  #ifdef ZUNE_HD
   7.621      nFormats = 1;
   7.622  #else /* !ZUNE_HD */
   7.623 -    glGetIntegerv(GL_NUM_SHADER_BINARY_FORMATS, &nFormats);
   7.624 -    glGetBooleanv(GL_SHADER_COMPILER, &hasCompiler);
   7.625 +    rdata->glGetIntegerv(GL_NUM_SHADER_BINARY_FORMATS, &nFormats);
   7.626 +    rdata->glGetBooleanv(GL_SHADER_COMPILER, &hasCompiler);
   7.627      if (hasCompiler)
   7.628          ++nFormats;
   7.629  #endif /* ZUNE_HD */
   7.630 @@ -1259,8 +1312,8 @@
   7.631  #ifdef ZUNE_HD
   7.632      rdata->shader_formats[0] = GL_NVIDIA_PLATFORM_BINARY_NV;
   7.633  #else /* !ZUNE_HD */
   7.634 -    glGetIntegerv(GL_SHADER_BINARY_FORMATS, (GLint *)rdata->shader_formats);
   7.635 -    if (glGetError() != GL_NO_ERROR)
   7.636 +    rdata->glGetIntegerv(GL_SHADER_BINARY_FORMATS, (GLint *)rdata->shader_formats);
   7.637 +    if (rdata->glGetError() != GL_NO_ERROR)
   7.638      {
   7.639          GLES2_DestroyRenderer(renderer);
   7.640          SDL_SetError("Failed to query supported shader formats");
     8.1 --- a/src/video/SDL_sysvideo.h	Sun Jan 08 01:15:20 2012 -0500
     8.2 +++ b/src/video/SDL_sysvideo.h	Sun Jan 08 02:23:37 2012 -0500
     8.3 @@ -286,7 +286,7 @@
     8.4      void *driverdata;
     8.5      struct SDL_GLDriverData *gl_data;
     8.6  
     8.7 -#if SDL_VIDEO_DRIVER_PANDORA
     8.8 +#if SDL_VIDEO_OPENGL_ES
     8.9      struct SDL_PrivateGLESData *gles_data;
    8.10  #endif
    8.11  
     9.1 --- a/src/video/SDL_video.c	Sun Jan 08 01:15:20 2012 -0500
     9.2 +++ b/src/video/SDL_video.c	Sun Jan 08 02:23:37 2012 -0500
     9.3 @@ -189,6 +189,9 @@
     9.4          }
     9.5          return hasAcceleratedOpenGL;
     9.6      }
     9.7 +#elif SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
     9.8 +    /* Let's be optimistic about this! */
     9.9 +    return SDL_TRUE;
    9.10  #else
    9.11      return SDL_FALSE;
    9.12  #endif
    9.13 @@ -1138,7 +1141,7 @@
    9.14      }
    9.15  
    9.16      /* Some platforms have OpenGL enabled by default */
    9.17 -#if (SDL_VIDEO_OPENGL && __MACOSX__) || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
    9.18 +#if (SDL_VIDEO_OPENGL && __MACOSX__) || __IPHONEOS__ || __ANDROID__
    9.19      flags |= SDL_WINDOW_OPENGL;
    9.20  #endif
    9.21      if (flags & SDL_WINDOW_OPENGL) {
    10.1 --- a/src/video/x11/SDL_x11opengles.c	Sun Jan 08 01:15:20 2012 -0500
    10.2 +++ b/src/video/x11/SDL_x11opengles.c	Sun Jan 08 02:23:37 2012 -0500
    10.3 @@ -25,7 +25,10 @@
    10.4  #include "SDL_x11video.h"
    10.5  #include "SDL_x11opengles.h"
    10.6  
    10.7 -#define DEFAULT_OPENGL	"/usr/lib/libGLES_CM.so"
    10.8 +#define DEFAULT_EGL "/usr/lib/libEGL.so"
    10.9 +#define DEFAULT_OGL_ES2 "/usr/lib/libGLESv2.so"
   10.10 +#define DEFAULT_OGL_ES_PVR "/usr/lib/libGLES_CM.so"
   10.11 +#define DEFAULT_OGL_ES "/usr/lib/libGLESv1_CM.so"
   10.12  
   10.13  #define LOAD_FUNC(NAME) \
   10.14  	*((void**)&_this->gles_data->NAME) = dlsym(handle, #NAME); \
   10.15 @@ -44,13 +47,15 @@
   10.16      void *handle;
   10.17      void *retval;
   10.18  
   10.19 -    handle = _this->gl_config.dll_handle;
   10.20 +    handle = _this->gles_data->egl_dll_handle;
   10.21      if (_this->gles_data->eglGetProcAddress) {
   10.22          retval = _this->gles_data->eglGetProcAddress(proc);
   10.23          if (retval) {
   10.24              return retval;
   10.25          }
   10.26      }
   10.27 +    
   10.28 +    handle = _this->gl_config.dll_handle;
   10.29  #if defined(__OpenBSD__) && !defined(__ELF__)
   10.30  #undef dlsym(x,y);
   10.31  #endif
   10.32 @@ -70,6 +75,7 @@
   10.33          _this->gles_data->eglTerminate(_this->gles_data->egl_display);
   10.34  
   10.35          dlclose(_this->gl_config.dll_handle);
   10.36 +        dlclose(_this->gles_data->egl_dll_handle);
   10.37  
   10.38          _this->gles_data->eglGetProcAddress = NULL;
   10.39          _this->gles_data->eglChooseConfig = NULL;
   10.40 @@ -111,7 +117,7 @@
   10.41          dlclose(handle);
   10.42          path = getenv("SDL_VIDEO_GL_DRIVER");
   10.43          if (path == NULL) {
   10.44 -            path = DEFAULT_OPENGL;
   10.45 +            path = DEFAULT_EGL;
   10.46          }
   10.47          handle = dlopen(path, dlopen_flags);
   10.48      }
   10.49 @@ -153,6 +159,29 @@
   10.50          return -1;
   10.51      }
   10.52  
   10.53 +    _this->gles_data->egl_dll_handle = handle;
   10.54 +
   10.55 +    path = getenv("SDL_VIDEO_GL_DRIVER");
   10.56 +    handle = dlopen(path, dlopen_flags);
   10.57 +    if ((path == NULL) | (handle == NULL)) {
   10.58 +        if (_this->gl_config.major_version > 1) {
   10.59 +            path = DEFAULT_OGL_ES2;
   10.60 +            handle = dlopen(path, dlopen_flags);
   10.61 +        } else {
   10.62 +            path = DEFAULT_OGL_ES;
   10.63 +            handle = dlopen(path, dlopen_flags);
   10.64 +            if (handle == NULL) {
   10.65 +                path = DEFAULT_OGL_ES_PVR;
   10.66 +                handle = dlopen(path, dlopen_flags);
   10.67 +            }
   10.68 +        }
   10.69 +    }
   10.70 +
   10.71 +    if (handle == NULL) {
   10.72 +        SDL_SetError("Could not initialize OpenGL ES library");
   10.73 +        return -1;
   10.74 +    }
   10.75 +
   10.76      _this->gl_config.dll_handle = handle;
   10.77      _this->gl_config.driver_loaded = 1;
   10.78  
   10.79 @@ -218,6 +247,13 @@
   10.80          attribs[i++] = _this->gl_config.multisamplesamples;
   10.81      }
   10.82  
   10.83 +    attribs[i++] = EGL_RENDERABLE_TYPE;
   10.84 +    if (_this->gl_config.major_version == 2) {
   10.85 +        attribs[i++] = EGL_OPENGL_ES2_BIT;
   10.86 +    } else {
   10.87 +        attribs[i++] = EGL_OPENGL_ES_BIT;
   10.88 +    }
   10.89 +
   10.90      attribs[i++] = EGL_NONE;
   10.91  
   10.92      if (_this->gles_data->eglChooseConfig(_this->gles_data->egl_display,
   10.93 @@ -260,17 +296,25 @@
   10.94  SDL_GLContext
   10.95  X11_GLES_CreateContext(_THIS, SDL_Window * window)
   10.96  {
   10.97 -    int retval;
   10.98 +    EGLint context_attrib_list[] = {
   10.99 +        EGL_CONTEXT_CLIENT_VERSION,
  10.100 +        1,
  10.101 +        EGL_NONE
  10.102 +    };
  10.103 +
  10.104      SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
  10.105      Display *display = data->videodata->display;
  10.106  
  10.107      XSync(display, False);
  10.108  
  10.109 +    if (_this->gl_config.major_version) {
  10.110 +        context_attrib_list[1] = _this->gl_config.major_version;
  10.111 +    }
  10.112  
  10.113      _this->gles_data->egl_context =
  10.114          _this->gles_data->eglCreateContext(_this->gles_data->egl_display,
  10.115                                             _this->gles_data->egl_config,
  10.116 -                                           EGL_NO_CONTEXT, NULL);
  10.117 +                                           EGL_NO_CONTEXT, context_attrib_list);
  10.118      XSync(display, False);
  10.119  
  10.120      if (_this->gles_data->egl_context == EGL_NO_CONTEXT) {
  10.121 @@ -280,12 +324,12 @@
  10.122  
  10.123      _this->gles_data->egl_active = 1;
  10.124  
  10.125 -    if (_this->gles_data->egl_active)
  10.126 -        retval = 1;
  10.127 -    else
  10.128 -        retval = 0;
  10.129 +    if (X11_GLES_MakeCurrent(_this, window, context) < 0) {
  10.130 +        X11_GLES_DeleteContext(_this, context);
  10.131 +        return NULL;
  10.132 +    }
  10.133  
  10.134 -    return (retval);
  10.135 +    return (SDL_GLContext)(1);
  10.136  }
  10.137  
  10.138  int
    11.1 --- a/src/video/x11/SDL_x11opengles.h	Sun Jan 08 01:15:20 2012 -0500
    11.2 +++ b/src/video/x11/SDL_x11opengles.h	Sun Jan 08 02:23:37 2012 -0500
    11.3 @@ -32,6 +32,7 @@
    11.4  {
    11.5      int egl_active;             /* to stop switching drivers while we have a valid context */
    11.6      XVisualInfo *egl_visualinfo;
    11.7 +    void *egl_dll_handle;
    11.8      EGLDisplay egl_display;
    11.9      EGLContext egl_context;     /* Current GLES context */
   11.10      EGLSurface egl_surface;
    12.1 --- a/src/video/x11/SDL_x11video.c	Sun Jan 08 01:15:20 2012 -0500
    12.2 +++ b/src/video/x11/SDL_x11video.c	Sun Jan 08 02:23:37 2012 -0500
    12.3 @@ -34,7 +34,7 @@
    12.4  #include "SDL_x11shape.h"
    12.5  #include "SDL_x11touch.h" 
    12.6  
    12.7 -#if SDL_VIDEO_DRIVER_PANDORA
    12.8 +#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
    12.9  #include "SDL_x11opengles.h"
   12.10  #endif
   12.11  
   12.12 @@ -110,7 +110,7 @@
   12.13      }
   12.14      SDL_free(data->windowlist);
   12.15      SDL_free(device->driverdata);
   12.16 -#if SDL_VIDEO_DRIVER_PANDORA
   12.17 +#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
   12.18      SDL_free(device->gles_data);
   12.19  #endif
   12.20      SDL_free(device);
   12.21 @@ -143,7 +143,7 @@
   12.22      }
   12.23      device->driverdata = data;
   12.24  
   12.25 -#if SDL_VIDEO_DRIVER_PANDORA
   12.26 +#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
   12.27      device->gles_data = (struct SDL_PrivateGLESData *) SDL_calloc(1, sizeof(SDL_PrivateGLESData));
   12.28      if (!device->gles_data) {
   12.29          SDL_OutOfMemory();
   12.30 @@ -226,7 +226,7 @@
   12.31      device->GL_SwapWindow = X11_GL_SwapWindow;
   12.32      device->GL_DeleteContext = X11_GL_DeleteContext;
   12.33  #endif
   12.34 -#if SDL_VIDEO_DRIVER_PANDORA
   12.35 +#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
   12.36      device->GL_LoadLibrary = X11_GLES_LoadLibrary;
   12.37      device->GL_GetProcAddress = X11_GLES_GetProcAddress;
   12.38      device->GL_UnloadLibrary = X11_GLES_UnloadLibrary;
    13.1 --- a/src/video/x11/SDL_x11window.c	Sun Jan 08 01:15:20 2012 -0500
    13.2 +++ b/src/video/x11/SDL_x11window.c	Sun Jan 08 02:23:37 2012 -0500
    13.3 @@ -31,7 +31,7 @@
    13.4  #include "SDL_x11mouse.h"
    13.5  #include "SDL_x11shape.h"
    13.6  
    13.7 -#ifdef SDL_VIDEO_DRIVER_PANDORA
    13.8 +#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
    13.9  #include "SDL_x11opengles.h"
   13.10  #endif
   13.11  
   13.12 @@ -289,7 +289,7 @@
   13.13          XFree(vinfo);
   13.14      } else
   13.15  #endif
   13.16 -#ifdef SDL_VIDEO_DRIVER_PANDORA
   13.17 +#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
   13.18      if (window->flags & SDL_WINDOW_OPENGL) {
   13.19          XVisualInfo *vinfo;
   13.20  
   13.21 @@ -401,17 +401,19 @@
   13.22          SDL_SetError("Couldn't create window");
   13.23          return -1;
   13.24      }
   13.25 -#if SDL_VIDEO_DRIVER_PANDORA
   13.26 -    /* Create the GLES window surface */
   13.27 -    _this->gles_data->egl_surface =
   13.28 -        _this->gles_data->eglCreateWindowSurface(_this->gles_data->
   13.29 +#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
   13.30 +    if (window->flags & SDL_WINDOW_OPENGL) {
   13.31 +        /* Create the GLES window surface */
   13.32 +        _this->gles_data->egl_surface =
   13.33 +            _this->gles_data->eglCreateWindowSurface(_this->gles_data->
   13.34                                                   egl_display,
   13.35                                                   _this->gles_data->egl_config,
   13.36                                                   (NativeWindowType) w, NULL);
   13.37  
   13.38 -    if (_this->gles_data->egl_surface == EGL_NO_SURFACE) {
   13.39 -        SDL_SetError("Could not create GLES window surface");
   13.40 -        return -1;
   13.41 +        if (_this->gles_data->egl_surface == EGL_NO_SURFACE) {
   13.42 +            SDL_SetError("Could not create GLES window surface");
   13.43 +            return -1;
   13.44 +        }
   13.45      }
   13.46  #endif
   13.47  
    14.1 --- a/test/configure	Sun Jan 08 01:15:20 2012 -0500
    14.2 +++ b/test/configure	Sun Jan 08 02:23:37 2012 -0500
    14.3 @@ -3764,12 +3764,10 @@
    14.4  cat >>conftest.$ac_ext <<_ACEOF
    14.5  /* end confdefs.h.  */
    14.6  
    14.7 - #if defined (__QNXNTO__)
    14.8 -    #include <GLES/gl.h>
    14.9 - #elif defined (__IPHONEOS__)
   14.10 + #if defined (__IPHONEOS__)
   14.11      #include <OpenGLES/ES1/gl.h>
   14.12   #else
   14.13 -    #error "No OpenGL ES support"
   14.14 +    #include <GLES/gl.h>
   14.15   #endif /* __QNXNTO__ */
   14.16  
   14.17  int
   14.18 @@ -3812,12 +3810,13 @@
   14.19  { echo "$as_me:$LINENO: result: $have_opengles" >&5
   14.20  echo "${ECHO_T}$have_opengles" >&6; }
   14.21  
   14.22 -if test x$have_opengl = xyes; then
   14.23 +GLLIB=""
   14.24 +if test x$have_opengles = xyes; then
   14.25 +    CFLAGS="$CFLAGS -DHAVE_OPENGLES"
   14.26 +    GLLIB="$XPATH -lGLESv1_CM"
   14.27 +elif test x$have_opengl = xyes; then
   14.28      CFLAGS="$CFLAGS -DHAVE_OPENGL"
   14.29      GLLIB="$XPATH $SYS_GL_LIBS"
   14.30 -elif test x$have_opengles = xyes; then
   14.31 -    CFLAGS="$CFLAGS -DHAVE_OPENGLES"
   14.32 -    GLLIB="$XPATH $SYS_GL_LIBS"
   14.33  else
   14.34      GLLIB=""
   14.35  fi
    15.1 --- a/test/configure.in	Sun Jan 08 01:15:20 2012 -0500
    15.2 +++ b/test/configure.in	Sun Jan 08 02:23:37 2012 -0500
    15.3 @@ -103,12 +103,10 @@
    15.4  AC_MSG_CHECKING(for OpenGL ES support)
    15.5  have_opengles=no
    15.6  AC_TRY_COMPILE([
    15.7 - #if defined (__QNXNTO__)
    15.8 -    #include <GLES/gl.h>
    15.9 - #elif defined (__IPHONEOS__)
   15.10 + #if defined (__IPHONEOS__)
   15.11      #include <OpenGLES/ES1/gl.h>
   15.12   #else
   15.13 -    #error "No OpenGL ES support"
   15.14 +    #include <GLES/gl.h>
   15.15   #endif /* __QNXNTO__ */
   15.16  ],[
   15.17  ],[
   15.18 @@ -116,12 +114,13 @@
   15.19  ])
   15.20  AC_MSG_RESULT($have_opengles)
   15.21  
   15.22 -if test x$have_opengl = xyes; then
   15.23 +GLLIB=""
   15.24 +if test x$have_opengles = xyes; then
   15.25 +    CFLAGS="$CFLAGS -DHAVE_OPENGLES"
   15.26 +    GLLIB="$XPATH -lGLESv1_CM"
   15.27 +elif test x$have_opengl = xyes; then
   15.28      CFLAGS="$CFLAGS -DHAVE_OPENGL"
   15.29      GLLIB="$XPATH $SYS_GL_LIBS"
   15.30 -elif test x$have_opengles = xyes; then
   15.31 -    CFLAGS="$CFLAGS -DHAVE_OPENGLES"
   15.32 -    GLLIB="$XPATH $SYS_GL_LIBS"
   15.33  else
   15.34      GLLIB=""
   15.35  fi