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