src/video/nacl/SDL_naclopengles.c
author Ryan C. Gordon <icculus@icculus.org>
Mon, 06 Apr 2015 00:10:54 -0400
changeset 9458 543298b36b28
parent 8833 ae720d61d14d
child 9619 b94b6d0bff0f
permissions -rw-r--r--
This function can be static.
gabomdq@8833
     1
/*
gabomdq@8833
     2
  Simple DirectMedia Layer
gabomdq@8833
     3
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
gabomdq@8833
     4
gabomdq@8833
     5
  This software is provided 'as-is', without any express or implied
gabomdq@8833
     6
  warranty.  In no event will the authors be held liable for any damages
gabomdq@8833
     7
  arising from the use of this software.
gabomdq@8833
     8
gabomdq@8833
     9
  Permission is granted to anyone to use this software for any purpose,
gabomdq@8833
    10
  including commercial applications, and to alter it and redistribute it
gabomdq@8833
    11
  freely, subject to the following restrictions:
gabomdq@8833
    12
gabomdq@8833
    13
  1. The origin of this software must not be misrepresented; you must not
gabomdq@8833
    14
     claim that you wrote the original software. If you use this software
gabomdq@8833
    15
     in a product, an acknowledgment in the product documentation would be
gabomdq@8833
    16
     appreciated but is not required.
gabomdq@8833
    17
  2. Altered source versions must be plainly marked as such, and must not be
gabomdq@8833
    18
     misrepresented as being the original software.
gabomdq@8833
    19
  3. This notice may not be removed or altered from any source distribution.
gabomdq@8833
    20
*/
gabomdq@8833
    21
#include "../../SDL_internal.h"
gabomdq@8833
    22
gabomdq@8833
    23
#if SDL_VIDEO_DRIVER_NACL
gabomdq@8833
    24
gabomdq@8833
    25
/* NaCl SDL video GLES 2 driver implementation */
gabomdq@8833
    26
gabomdq@8833
    27
#include "SDL_video.h"
gabomdq@8833
    28
#include "SDL_naclvideo.h"
gabomdq@8833
    29
gabomdq@8833
    30
#if SDL_LOADSO_DLOPEN
gabomdq@8833
    31
#include "dlfcn.h"
gabomdq@8833
    32
#endif
gabomdq@8833
    33
gabomdq@8833
    34
#include "ppapi/gles2/gl2ext_ppapi.h"
gabomdq@8833
    35
#include "ppapi_simple/ps.h"
gabomdq@8833
    36
gabomdq@8833
    37
/* GL functions */
gabomdq@8833
    38
int
gabomdq@8833
    39
NACL_GLES_LoadLibrary(_THIS, const char *path)
gabomdq@8833
    40
{
gabomdq@8833
    41
    /* FIXME: Support dynamic linking when PNACL supports it */
gabomdq@8833
    42
    return glInitializePPAPI(PSGetInterface) == 0;
gabomdq@8833
    43
}
gabomdq@8833
    44
gabomdq@8833
    45
void *
gabomdq@8833
    46
NACL_GLES_GetProcAddress(_THIS, const char *proc)
gabomdq@8833
    47
{
gabomdq@8833
    48
#if SDL_LOADSO_DLOPEN
gabomdq@8833
    49
    return dlsym( 0 /* RTLD_DEFAULT */, proc);
gabomdq@8833
    50
#else
gabomdq@8833
    51
    return NULL;
gabomdq@8833
    52
#endif
gabomdq@8833
    53
}
gabomdq@8833
    54
gabomdq@8833
    55
void
gabomdq@8833
    56
NACL_GLES_UnloadLibrary(_THIS)
gabomdq@8833
    57
{
gabomdq@8833
    58
    /* FIXME: Support dynamic linking when PNACL supports it */
gabomdq@8833
    59
    glTerminatePPAPI();
gabomdq@8833
    60
}
gabomdq@8833
    61
gabomdq@8833
    62
int
gabomdq@8833
    63
NACL_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext sdl_context)
gabomdq@8833
    64
{
gabomdq@8833
    65
    SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
gabomdq@8833
    66
    /* FIXME: Check threading issues...otherwise use a hardcoded _this->context across all threads */
gabomdq@8833
    67
    driverdata->ppb_instance->BindGraphics(driverdata->instance, (PP_Resource) sdl_context);
gabomdq@8833
    68
    glSetCurrentContextPPAPI((PP_Resource) sdl_context);
gabomdq@8833
    69
    return 0;
gabomdq@8833
    70
}
gabomdq@8833
    71
gabomdq@8833
    72
SDL_GLContext
gabomdq@8833
    73
NACL_GLES_CreateContext(_THIS, SDL_Window * window)
gabomdq@8833
    74
{
gabomdq@8833
    75
    SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
gabomdq@8833
    76
    PP_Resource context, share_context = 0;
gabomdq@8833
    77
    /* 64 seems nice. */
gabomdq@8833
    78
    Sint32 attribs[64];
gabomdq@8833
    79
    int i = 0;
gabomdq@8833
    80
    
gabomdq@8833
    81
    if (_this->gl_config.share_with_current_context) {
gabomdq@8833
    82
        share_context = (PP_Resource) SDL_GL_GetCurrentContext();
gabomdq@8833
    83
    }
gabomdq@8833
    84
gabomdq@8833
    85
    /* FIXME: Some ATTRIBS from PP_Graphics3DAttrib are not set here */
gabomdq@8833
    86
    
gabomdq@8833
    87
    attribs[i++] = PP_GRAPHICS3DATTRIB_WIDTH;
gabomdq@8833
    88
    attribs[i++] = window->w;
gabomdq@8833
    89
    attribs[i++] = PP_GRAPHICS3DATTRIB_HEIGHT;
gabomdq@8833
    90
    attribs[i++] = window->h;
gabomdq@8833
    91
    attribs[i++] = PP_GRAPHICS3DATTRIB_RED_SIZE;
gabomdq@8833
    92
    attribs[i++] = _this->gl_config.red_size;
gabomdq@8833
    93
    attribs[i++] = PP_GRAPHICS3DATTRIB_GREEN_SIZE;
gabomdq@8833
    94
    attribs[i++] = _this->gl_config.green_size;
gabomdq@8833
    95
    attribs[i++] = PP_GRAPHICS3DATTRIB_BLUE_SIZE;
gabomdq@8833
    96
    attribs[i++] = _this->gl_config.blue_size;
gabomdq@8833
    97
    
gabomdq@8833
    98
    if (_this->gl_config.alpha_size) {
gabomdq@8833
    99
        attribs[i++] = PP_GRAPHICS3DATTRIB_ALPHA_SIZE;
gabomdq@8833
   100
        attribs[i++] = _this->gl_config.alpha_size;
gabomdq@8833
   101
    }
gabomdq@8833
   102
    
gabomdq@8833
   103
    /*if (_this->gl_config.buffer_size) {
gabomdq@8833
   104
        attribs[i++] = EGL_BUFFER_SIZE;
gabomdq@8833
   105
        attribs[i++] = _this->gl_config.buffer_size;
gabomdq@8833
   106
    }*/
gabomdq@8833
   107
    
gabomdq@8833
   108
    attribs[i++] = PP_GRAPHICS3DATTRIB_DEPTH_SIZE;
gabomdq@8833
   109
    attribs[i++] = _this->gl_config.depth_size;
gabomdq@8833
   110
    
gabomdq@8833
   111
    if (_this->gl_config.stencil_size) {
gabomdq@8833
   112
        attribs[i++] = PP_GRAPHICS3DATTRIB_STENCIL_SIZE;
gabomdq@8833
   113
        attribs[i++] = _this->gl_config.stencil_size;
gabomdq@8833
   114
    }
gabomdq@8833
   115
    
gabomdq@8833
   116
    if (_this->gl_config.multisamplebuffers) {
gabomdq@8833
   117
        attribs[i++] = PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS;
gabomdq@8833
   118
        attribs[i++] = _this->gl_config.multisamplebuffers;
gabomdq@8833
   119
    }
gabomdq@8833
   120
    
gabomdq@8833
   121
    if (_this->gl_config.multisamplesamples) {
gabomdq@8833
   122
        attribs[i++] = PP_GRAPHICS3DATTRIB_SAMPLES;
gabomdq@8833
   123
        attribs[i++] = _this->gl_config.multisamplesamples;
gabomdq@8833
   124
    }
gabomdq@8833
   125
       
gabomdq@8833
   126
    attribs[i++] = PP_GRAPHICS3DATTRIB_NONE;
gabomdq@8833
   127
    
gabomdq@8833
   128
    context = driverdata->ppb_graphics->Create(driverdata->instance, share_context, attribs);
gabomdq@8833
   129
gabomdq@8833
   130
    if (context) {
gabomdq@8833
   131
        /* We need to make the context current, otherwise nothing works */
gabomdq@8833
   132
        SDL_GL_MakeCurrent(window, (SDL_GLContext) context);
gabomdq@8833
   133
    }
gabomdq@8833
   134
    
gabomdq@8833
   135
    return (SDL_GLContext) context;
gabomdq@8833
   136
}
gabomdq@8833
   137
gabomdq@8833
   138
gabomdq@8833
   139
gabomdq@8833
   140
int
gabomdq@8833
   141
NACL_GLES_SetSwapInterval(_THIS, int interval)
gabomdq@8833
   142
{
gabomdq@8833
   143
    /* STUB */
gabomdq@8833
   144
    return 0;
gabomdq@8833
   145
}
gabomdq@8833
   146
gabomdq@8833
   147
int
gabomdq@8833
   148
NACL_GLES_GetSwapInterval(_THIS)
gabomdq@8833
   149
{
gabomdq@8833
   150
    /* STUB */
gabomdq@8833
   151
    return 0;
gabomdq@8833
   152
}
gabomdq@8833
   153
gabomdq@8833
   154
void
gabomdq@8833
   155
NACL_GLES_SwapWindow(_THIS, SDL_Window * window)
gabomdq@8833
   156
{
gabomdq@8833
   157
    SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
gabomdq@8833
   158
    struct PP_CompletionCallback callback = { NULL, 0, PP_COMPLETIONCALLBACK_FLAG_NONE };
gabomdq@8833
   159
    driverdata->ppb_graphics->SwapBuffers((PP_Resource) SDL_GL_GetCurrentContext(), callback );
gabomdq@8833
   160
}
gabomdq@8833
   161
gabomdq@8833
   162
void
gabomdq@8833
   163
NACL_GLES_DeleteContext(_THIS, SDL_GLContext context)
gabomdq@8833
   164
{
gabomdq@8833
   165
    SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
gabomdq@8833
   166
    driverdata->ppb_core->ReleaseResource((PP_Resource) context);
gabomdq@8833
   167
}
gabomdq@8833
   168
gabomdq@8833
   169
#endif /* SDL_VIDEO_DRIVER_NACL */
gabomdq@8833
   170
gabomdq@8833
   171
/* vi: set ts=4 sw=4 expandtab: */