SDL  2.0
SDL_naclopengles.c
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2018 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_internal.h"
22 
23 #if SDL_VIDEO_DRIVER_NACL
24 
25 /* NaCl SDL video GLES 2 driver implementation */
26 
27 #include "SDL_video.h"
28 #include "SDL_naclvideo.h"
29 
30 #if SDL_LOADSO_DLOPEN
31 #include "dlfcn.h"
32 #endif
33 
34 #include "ppapi/gles2/gl2ext_ppapi.h"
35 #include "ppapi_simple/ps.h"
36 
37 /* GL functions */
38 int
39 NACL_GLES_LoadLibrary(_THIS, const char *path)
40 {
41  /* FIXME: Support dynamic linking when PNACL supports it */
42  return glInitializePPAPI(PSGetInterface) == 0;
43 }
44 
45 void *
46 NACL_GLES_GetProcAddress(_THIS, const char *proc)
47 {
48 #if SDL_LOADSO_DLOPEN
49  return dlsym( 0 /* RTLD_DEFAULT */, proc);
50 #else
51  return NULL;
52 #endif
53 }
54 
55 void
57 {
58  /* FIXME: Support dynamic linking when PNACL supports it */
59  glTerminatePPAPI();
60 }
61 
62 int
64 {
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);
69  return 0;
70 }
71 
74 {
75  SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
76  PP_Resource context, share_context = 0;
77  /* 64 seems nice. */
78  Sint32 attribs[64];
79  int i = 0;
80 
82  share_context = (PP_Resource) SDL_GL_GetCurrentContext();
83  }
84 
85  /* FIXME: Some ATTRIBS from PP_Graphics3DAttrib are not set here */
86 
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;
93  attribs[i++] = PP_GRAPHICS3DATTRIB_GREEN_SIZE;
95  attribs[i++] = PP_GRAPHICS3DATTRIB_BLUE_SIZE;
97 
98  if (_this->gl_config.alpha_size) {
99  attribs[i++] = PP_GRAPHICS3DATTRIB_ALPHA_SIZE;
101  }
102 
103  /*if (_this->gl_config.buffer_size) {
104  attribs[i++] = EGL_BUFFER_SIZE;
105  attribs[i++] = _this->gl_config.buffer_size;
106  }*/
107 
108  attribs[i++] = PP_GRAPHICS3DATTRIB_DEPTH_SIZE;
110 
112  attribs[i++] = PP_GRAPHICS3DATTRIB_STENCIL_SIZE;
114  }
115 
117  attribs[i++] = PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS;
119  }
120 
122  attribs[i++] = PP_GRAPHICS3DATTRIB_SAMPLES;
124  }
125 
126  attribs[i++] = PP_GRAPHICS3DATTRIB_NONE;
127 
128  context = driverdata->ppb_graphics->Create(driverdata->instance, share_context, attribs);
129 
130  if (context) {
131  /* We need to make the context current, otherwise nothing works */
132  SDL_GL_MakeCurrent(window, (SDL_GLContext) context);
133  }
134 
135  return (SDL_GLContext) context;
136 }
137 
138 
139 
140 int
141 NACL_GLES_SetSwapInterval(_THIS, int interval)
142 {
143  /* STUB */
144  return SDL_Unsupported();
145 }
146 
147 int
149 {
150  /* STUB */
151  return 0;
152 }
153 
154 int
156 {
157  SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
158  struct PP_CompletionCallback callback = { NULL, 0, PP_COMPLETIONCALLBACK_FLAG_NONE };
159  if (driverdata->ppb_graphics->SwapBuffers((PP_Resource) SDL_GL_GetCurrentContext(), callback ) != 0) {
160  return SDL_SetError("SwapBuffers failed");
161  }
162  return 0;
163 }
164 
165 void
167 {
168  SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
169  driverdata->ppb_core->ReleaseResource((PP_Resource) context);
170 }
171 
172 #endif /* SDL_VIDEO_DRIVER_NACL */
173 
174 /* vi: set ts=4 sw=4 expandtab: */
const GLint * attribs
const PPB_Instance * ppb_instance
Definition: SDL_naclvideo.h:46
const PPB_Graphics3D * ppb_graphics
Definition: SDL_naclvideo.h:42
static screen_context_t context
Definition: video.c:25
SDL_GLContext NACL_GLES_CreateContext(_THIS, SDL_Window *window)
static SDL_VideoDevice * _this
Definition: SDL_video.c:121
void * SDL_GLContext
An opaque handle to an OpenGL context.
Definition: SDL_video.h:175
int NACL_GLES_SwapWindow(_THIS, SDL_Window *window)
#define _THIS
static Uint32 callback(Uint32 interval, void *param)
Definition: testtimer.c:34
int NACL_GLES_GetSwapInterval(_THIS)
PP_Instance instance
Definition: SDL_naclvideo.h:57
int32_t Sint32
Definition: SDL_stdinc.h:175
int NACL_GLES_LoadLibrary(_THIS, const char *path)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
int share_with_current_context
Definition: SDL_sysvideo.h:343
#define NULL
Definition: begin_code.h:164
#define SDL_GL_GetCurrentContext
#define SDL_SetError
int NACL_GLES_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context)
#define SDL_GL_MakeCurrent
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
void NACL_GLES_DeleteContext(_THIS, SDL_GLContext context)
void NACL_GLES_UnloadLibrary(_THIS)
The type used to identify a window.
Definition: SDL_sysvideo.h:73
GLsizei const GLchar *const * path
struct SDL_VideoDevice::@34 gl_config
const PPB_Core * ppb_core
Definition: SDL_naclvideo.h:44
#define SDL_Unsupported()
Definition: SDL_error.h:53
int NACL_GLES_SetSwapInterval(_THIS, int interval)
void * NACL_GLES_GetProcAddress(_THIS, const char *proc)