2 Simple DirectMedia Layer
3 Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
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.
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:
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.
21 #include "../../SDL_internal.h"
23 #if SDL_VIDEO_DRIVER_NACL
25 /* NaCl SDL video GLES 2 driver implementation */
27 #include "SDL_video.h"
28 #include "SDL_naclvideo.h"
34 #include "ppapi/gles2/gl2ext_ppapi.h"
35 #include "ppapi_simple/ps.h"
39 NACL_GLES_LoadLibrary(_THIS, const char *path)
41 /* FIXME: Support dynamic linking when PNACL supports it */
42 return glInitializePPAPI(PSGetInterface) == 0;
46 NACL_GLES_GetProcAddress(_THIS, const char *proc)
49 return dlsym( 0 /* RTLD_DEFAULT */, proc);
56 NACL_GLES_UnloadLibrary(_THIS)
58 /* FIXME: Support dynamic linking when PNACL supports it */
63 NACL_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext sdl_context)
65 SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
66 /* FIXME: Check threading issues...otherwise use a hardcoded _this->context across all threads */
67 driverdata->ppb_instance->BindGraphics(driverdata->instance, (PP_Resource) sdl_context);
68 glSetCurrentContextPPAPI((PP_Resource) sdl_context);
73 NACL_GLES_CreateContext(_THIS, SDL_Window * window)
75 SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
76 PP_Resource context, share_context = 0;
81 if (_this->gl_config.share_with_current_context) {
82 share_context = (PP_Resource) SDL_GL_GetCurrentContext();
85 /* FIXME: Some ATTRIBS from PP_Graphics3DAttrib are not set here */
87 attribs[i++] = PP_GRAPHICS3DATTRIB_WIDTH;
88 attribs[i++] = window->w;
89 attribs[i++] = PP_GRAPHICS3DATTRIB_HEIGHT;
90 attribs[i++] = window->h;
91 attribs[i++] = PP_GRAPHICS3DATTRIB_RED_SIZE;
92 attribs[i++] = _this->gl_config.red_size;
93 attribs[i++] = PP_GRAPHICS3DATTRIB_GREEN_SIZE;
94 attribs[i++] = _this->gl_config.green_size;
95 attribs[i++] = PP_GRAPHICS3DATTRIB_BLUE_SIZE;
96 attribs[i++] = _this->gl_config.blue_size;
98 if (_this->gl_config.alpha_size) {
99 attribs[i++] = PP_GRAPHICS3DATTRIB_ALPHA_SIZE;
100 attribs[i++] = _this->gl_config.alpha_size;
103 /*if (_this->gl_config.buffer_size) {
104 attribs[i++] = EGL_BUFFER_SIZE;
105 attribs[i++] = _this->gl_config.buffer_size;
108 attribs[i++] = PP_GRAPHICS3DATTRIB_DEPTH_SIZE;
109 attribs[i++] = _this->gl_config.depth_size;
111 if (_this->gl_config.stencil_size) {
112 attribs[i++] = PP_GRAPHICS3DATTRIB_STENCIL_SIZE;
113 attribs[i++] = _this->gl_config.stencil_size;
116 if (_this->gl_config.multisamplebuffers) {
117 attribs[i++] = PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS;
118 attribs[i++] = _this->gl_config.multisamplebuffers;
121 if (_this->gl_config.multisamplesamples) {
122 attribs[i++] = PP_GRAPHICS3DATTRIB_SAMPLES;
123 attribs[i++] = _this->gl_config.multisamplesamples;
126 attribs[i++] = PP_GRAPHICS3DATTRIB_NONE;
128 context = driverdata->ppb_graphics->Create(driverdata->instance, share_context, attribs);
131 /* We need to make the context current, otherwise nothing works */
132 SDL_GL_MakeCurrent(window, (SDL_GLContext) context);
135 return (SDL_GLContext) context;
141 NACL_GLES_SetSwapInterval(_THIS, int interval)
148 NACL_GLES_GetSwapInterval(_THIS)
155 NACL_GLES_SwapWindow(_THIS, SDL_Window * window)
157 SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
158 struct PP_CompletionCallback callback = { NULL, 0, PP_COMPLETIONCALLBACK_FLAG_NONE };
159 driverdata->ppb_graphics->SwapBuffers((PP_Resource) SDL_GL_GetCurrentContext(), callback );
163 NACL_GLES_DeleteContext(_THIS, SDL_GLContext context)
165 SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
166 driverdata->ppb_core->ReleaseResource((PP_Resource) context);
169 #endif /* SDL_VIDEO_DRIVER_NACL */
171 /* vi: set ts=4 sw=4 expandtab: */