src/video/android/SDL_androidgl.c
author Ryan C. Gordon <icculus@icculus.org>
Sun, 31 Mar 2013 12:48:50 -0400
changeset 7037 3fedf1f25b94
parent 6885 700f1b25f77f
child 7567 52da75545aaa
permissions -rw-r--r--
Make SDL_SetError and friends unconditionally return -1.

This lets us change things like this...

if (Failed) {
SDL_SetError("We failed");
return -1;
}

...into this...

if (Failed) {
return SDL_SetError("We failed");
}


Fixes Bugzilla #1778.
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2013 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             return SDL_SetError("Could not initialize GL ES library\n");
    46         }
    47     }
    48     return 0;
    49 }
    50 
    51 void *
    52 Android_GL_GetProcAddress(_THIS, const char *proc)
    53 {
    54     /*
    55        !!! FIXME: this _should_ use eglGetProcAddress(), but it appears to be
    56        !!! FIXME:  busted on Android at the moment...
    57        !!! FIXME:  http://code.google.com/p/android/issues/detail?id=7681
    58        !!! FIXME: ...so revisit this later.  --ryan.
    59     */
    60     return dlsym(Android_GLHandle, proc);
    61 }
    62 
    63 void
    64 Android_GL_UnloadLibrary(_THIS)
    65 {
    66     if(Android_GLHandle) {
    67         dlclose(Android_GLHandle);
    68         Android_GLHandle = NULL;
    69     }
    70 }
    71 
    72 SDL_GLContext
    73 Android_GL_CreateContext(_THIS, SDL_Window * window)
    74 {
    75     if (!Android_JNI_CreateContext(_this->gl_config.major_version,
    76                                    _this->gl_config.minor_version,
    77                                    _this->gl_config.red_size,
    78                                    _this->gl_config.green_size,
    79                                    _this->gl_config.blue_size,
    80                                    _this->gl_config.alpha_size,
    81                                    _this->gl_config.buffer_size,
    82                                    _this->gl_config.depth_size,
    83                                    _this->gl_config.stencil_size,
    84                                    _this->gl_config.multisamplebuffers,
    85                                    _this->gl_config.multisamplesamples)) {
    86         SDL_SetError("Couldn't create OpenGL context - see Android log for details");
    87         return NULL;
    88     }
    89     return (SDL_GLContext)1;
    90 }
    91 
    92 int
    93 Android_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
    94 {
    95     /* There's only one context, nothing to do... */
    96     return 0;
    97 }
    98 
    99 int
   100 Android_GL_SetSwapInterval(_THIS, int interval)
   101 {
   102     __android_log_print(ANDROID_LOG_INFO, "SDL", "[STUB] GL_SetSwapInterval\n");
   103     return 0;
   104 }
   105 
   106 int
   107 Android_GL_GetSwapInterval(_THIS)
   108 {
   109     __android_log_print(ANDROID_LOG_INFO, "SDL", "[STUB] GL_GetSwapInterval\n");
   110     return 0;
   111 }
   112 
   113 void
   114 Android_GL_SwapWindow(_THIS, SDL_Window * window)
   115 {
   116     Android_JNI_SwapWindow();
   117 }
   118 
   119 void
   120 Android_GL_DeleteContext(_THIS, SDL_GLContext context)
   121 {
   122     __android_log_print(ANDROID_LOG_INFO, "SDL", "[STUB] GL_DeleteContext\n");
   123 }
   124 
   125 #endif /* SDL_VIDEO_DRIVER_ANDROID */
   126 
   127 /* vi: set ts=4 sw=4 expandtab: */