src/video/android/SDL_androidgl.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 31 Dec 2012 14:57:36 -0800
changeset 6792 a15821a3471f
parent 6138 4c64952a58fb
child 6885 700f1b25f77f
permissions -rw-r--r--
Fixed bug 1616 - SDL does not use values set with SDL_GL_SetAttribute on Android

Philipp Wiesemann 2012-10-06 07:19:57 PDT

SDL does not use values set with SDL_GL_SetAttribute on Android.

I attached a patch which adds this functionality and makes it possible to set
(for example) depth buffer size or anti-aliasing in the actual application
instead of modifying the Java source (which seems currently the only way).
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
     4 
     5   This software is provided 'as-is', without any express or implied
     6   warranty.  In no event will the authors be held liable for any damages
     7   arising from the use of this software.
     8 
     9   Permission is granted to anyone to use this software for any purpose,
    10   including commercial applications, and to alter it and redistribute it
    11   freely, subject to the following restrictions:
    12 
    13   1. The origin of this software must not be misrepresented; you must not
    14      claim that you wrote the original software. If you use this software
    15      in a product, an acknowledgment in the product documentation would be
    16      appreciated but is not required.
    17   2. Altered source versions must be plainly marked as such, and must not be
    18      misrepresented as being the original software.
    19   3. This notice may not be removed or altered from any source distribution.
    20 */
    21 #include "SDL_config.h"
    22 
    23 #if SDL_VIDEO_DRIVER_ANDROID
    24 
    25 /* Android SDL video driver implementation */
    26 
    27 #include "SDL_video.h"
    28 
    29 #include "SDL_androidvideo.h"
    30 #include "../../core/android/SDL_android.h"
    31 
    32 #include <android/log.h>
    33 
    34 #include <dlfcn.h>
    35 
    36 static void* Android_GLHandle = NULL;
    37 
    38 /* GL functions */
    39 int
    40 Android_GL_LoadLibrary(_THIS, const char *path)
    41 {
    42     if (!Android_GLHandle) {
    43         Android_GLHandle = dlopen("libGLESv1_CM.so",RTLD_GLOBAL);
    44         if (!Android_GLHandle) {
    45             SDL_SetError("Could not initialize GL ES library\n");
    46             return -1;
    47         }
    48     }
    49     return 0;
    50 }
    51 
    52 void *
    53 Android_GL_GetProcAddress(_THIS, const char *proc)
    54 {
    55     /*
    56        !!! FIXME: this _should_ use eglGetProcAddress(), but it appears to be
    57        !!! FIXME:  busted on Android at the moment...
    58        !!! FIXME:  http://code.google.com/p/android/issues/detail?id=7681
    59        !!! FIXME: ...so revisit this later.  --ryan.
    60     */
    61     return dlsym(Android_GLHandle, proc);
    62 }
    63 
    64 void
    65 Android_GL_UnloadLibrary(_THIS)
    66 {
    67     if(Android_GLHandle) {
    68         dlclose(Android_GLHandle);
    69         Android_GLHandle = NULL;
    70     }
    71 }
    72 
    73 SDL_GLContext
    74 Android_GL_CreateContext(_THIS, SDL_Window * window)
    75 {
    76     if (!Android_JNI_CreateContext(_this->gl_config.major_version,
    77                                    _this->gl_config.minor_version,
    78                                    _this->gl_config.red_size,
    79                                    _this->gl_config.green_size,
    80                                    _this->gl_config.blue_size,
    81                                    _this->gl_config.alpha_size,
    82                                    _this->gl_config.buffer_size,
    83                                    _this->gl_config.depth_size,
    84                                    _this->gl_config.stencil_size,
    85                                    _this->gl_config.multisamplebuffers,
    86                                    _this->gl_config.multisamplesamples)) {
    87         SDL_SetError("Couldn't create OpenGL context - see Android log for details");
    88         return NULL;
    89     }
    90     return (SDL_GLContext)1;
    91 }
    92 
    93 int
    94 Android_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
    95 {
    96     /* There's only one context, nothing to do... */
    97     return 0;
    98 }
    99 
   100 int
   101 Android_GL_SetSwapInterval(_THIS, int interval)
   102 {
   103     __android_log_print(ANDROID_LOG_INFO, "SDL", "[STUB] GL_SetSwapInterval\n");
   104     return 0;
   105 }
   106 
   107 int
   108 Android_GL_GetSwapInterval(_THIS)
   109 {
   110     __android_log_print(ANDROID_LOG_INFO, "SDL", "[STUB] GL_GetSwapInterval\n");
   111     return 0;
   112 }
   113 
   114 void
   115 Android_GL_SwapWindow(_THIS, SDL_Window * window)
   116 {
   117     Android_JNI_SwapWindow();
   118 }
   119 
   120 void
   121 Android_GL_DeleteContext(_THIS, SDL_GLContext context)
   122 {
   123     __android_log_print(ANDROID_LOG_INFO, "SDL", "[STUB] GL_DeleteContext\n");
   124 }
   125 
   126 #endif /* SDL_VIDEO_DRIVER_ANDROID */
   127 
   128 /* vi: set ts=4 sw=4 expandtab: */