src/video/android/SDL_androidgl.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 31 Oct 2011 05:56:58 -0400
changeset 6044 35448a5ea044
parent 5992 f4b73deb9d26
child 6138 4c64952a58fb
permissions -rw-r--r--
Lots of fixes importing SDL source wholesale into a new iOS project
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2011 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         SDL_SetError("Couldn't create OpenGL context - see Android log for details");
    79         return NULL;
    80     }
    81     return (SDL_GLContext)1;
    82 }
    83 
    84 int
    85 Android_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
    86 {
    87     /* There's only one context, nothing to do... */
    88     return 0;
    89 }
    90 
    91 int
    92 Android_GL_SetSwapInterval(_THIS, int interval)
    93 {
    94     __android_log_print(ANDROID_LOG_INFO, "SDL", "[STUB] GL_SetSwapInterval\n");
    95     return 0;
    96 }
    97 
    98 int
    99 Android_GL_GetSwapInterval(_THIS)
   100 {
   101     __android_log_print(ANDROID_LOG_INFO, "SDL", "[STUB] GL_GetSwapInterval\n");
   102     return 0;
   103 }
   104 
   105 void
   106 Android_GL_SwapWindow(_THIS, SDL_Window * window)
   107 {
   108     Android_JNI_SwapWindow();
   109 }
   110 
   111 void
   112 Android_GL_DeleteContext(_THIS, SDL_GLContext context)
   113 {
   114     __android_log_print(ANDROID_LOG_INFO, "SDL", "[STUB] GL_DeleteContext\n");
   115 }
   116 
   117 #endif /* SDL_VIDEO_DRIVER_ANDROID */
   118 
   119 /* vi: set ts=4 sw=4 expandtab: */