icculus@9278
|
1 |
/*
|
icculus@9278
|
2 |
Simple DirectMedia Layer
|
icculus@9278
|
3 |
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
|
icculus@9278
|
4 |
|
icculus@9278
|
5 |
This software is provided 'as-is', without any express or implied
|
icculus@9278
|
6 |
warranty. In no event will the authors be held liable for any damages
|
icculus@9278
|
7 |
arising from the use of this software.
|
icculus@9278
|
8 |
|
icculus@9278
|
9 |
Permission is granted to anyone to use this software for any purpose,
|
icculus@9278
|
10 |
including commercial applications, and to alter it and redistribute it
|
icculus@9278
|
11 |
freely, subject to the following restrictions:
|
icculus@9278
|
12 |
|
icculus@9278
|
13 |
1. The origin of this software must not be misrepresented; you must not
|
icculus@9278
|
14 |
claim that you wrote the original software. If you use this software
|
icculus@9278
|
15 |
in a product, an acknowledgment in the product documentation would be
|
icculus@9278
|
16 |
appreciated but is not required.
|
icculus@9278
|
17 |
2. Altered source versions must be plainly marked as such, and must not be
|
icculus@9278
|
18 |
misrepresented as being the original software.
|
icculus@9278
|
19 |
3. This notice may not be removed or altered from any source distribution.
|
icculus@9278
|
20 |
*/
|
icculus@9278
|
21 |
#include "../../SDL_internal.h"
|
icculus@9278
|
22 |
|
icculus@9278
|
23 |
#if SDL_VIDEO_DRIVER_EMSCRIPTEN && SDL_VIDEO_OPENGL_EGL
|
icculus@9278
|
24 |
|
icculus@9278
|
25 |
#include <emscripten/emscripten.h>
|
icculus@9278
|
26 |
#include <GLES2/gl2.h>
|
icculus@9278
|
27 |
|
icculus@9278
|
28 |
#include "SDL_emscriptenvideo.h"
|
icculus@9278
|
29 |
#include "SDL_emscriptenopengles.h"
|
icculus@9278
|
30 |
|
icculus@9278
|
31 |
#define LOAD_FUNC(NAME) _this->egl_data->NAME = NAME;
|
icculus@9278
|
32 |
|
icculus@9278
|
33 |
/* EGL implementation of SDL OpenGL support */
|
icculus@9278
|
34 |
|
icculus@9278
|
35 |
int
|
icculus@9278
|
36 |
Emscripten_GLES_LoadLibrary(_THIS, const char *path) {
|
icculus@9278
|
37 |
/*we can't load EGL dynamically*/
|
icculus@9278
|
38 |
_this->egl_data = (struct SDL_EGL_VideoData *) SDL_calloc(1, sizeof(SDL_EGL_VideoData));
|
icculus@9278
|
39 |
if (!_this->egl_data) {
|
icculus@9278
|
40 |
return SDL_OutOfMemory();
|
icculus@9278
|
41 |
}
|
icculus@9278
|
42 |
|
icculus@9278
|
43 |
LOAD_FUNC(eglGetDisplay);
|
icculus@9278
|
44 |
LOAD_FUNC(eglInitialize);
|
icculus@9278
|
45 |
LOAD_FUNC(eglTerminate);
|
icculus@9278
|
46 |
LOAD_FUNC(eglGetProcAddress);
|
icculus@9278
|
47 |
LOAD_FUNC(eglChooseConfig);
|
icculus@9278
|
48 |
LOAD_FUNC(eglGetConfigAttrib);
|
icculus@9278
|
49 |
LOAD_FUNC(eglCreateContext);
|
icculus@9278
|
50 |
LOAD_FUNC(eglDestroyContext);
|
icculus@9278
|
51 |
LOAD_FUNC(eglCreateWindowSurface);
|
icculus@9278
|
52 |
LOAD_FUNC(eglDestroySurface);
|
icculus@9278
|
53 |
LOAD_FUNC(eglMakeCurrent);
|
icculus@9278
|
54 |
LOAD_FUNC(eglSwapBuffers);
|
icculus@9278
|
55 |
LOAD_FUNC(eglSwapInterval);
|
icculus@9278
|
56 |
LOAD_FUNC(eglWaitNative);
|
icculus@9278
|
57 |
LOAD_FUNC(eglWaitGL);
|
icculus@9278
|
58 |
LOAD_FUNC(eglBindAPI);
|
icculus@9278
|
59 |
|
icculus@9278
|
60 |
_this->egl_data->egl_display = _this->egl_data->eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
icculus@9278
|
61 |
if (!_this->egl_data->egl_display) {
|
icculus@9278
|
62 |
return SDL_SetError("Could not get EGL display");
|
icculus@9278
|
63 |
}
|
icculus@9278
|
64 |
|
icculus@9278
|
65 |
if (_this->egl_data->eglInitialize(_this->egl_data->egl_display, NULL, NULL) != EGL_TRUE) {
|
icculus@9278
|
66 |
return SDL_SetError("Could not initialize EGL");
|
icculus@9278
|
67 |
}
|
icculus@9278
|
68 |
|
icculus@9278
|
69 |
_this->gl_config.driver_loaded = 1;
|
icculus@9278
|
70 |
|
icculus@9278
|
71 |
if (path) {
|
icculus@9278
|
72 |
SDL_strlcpy(_this->gl_config.driver_path, path, sizeof(_this->gl_config.driver_path) - 1);
|
icculus@9278
|
73 |
} else {
|
icculus@9278
|
74 |
*_this->gl_config.driver_path = '\0';
|
icculus@9278
|
75 |
}
|
icculus@9278
|
76 |
|
icculus@9278
|
77 |
return 0;
|
icculus@9278
|
78 |
}
|
icculus@9278
|
79 |
|
icculus@9278
|
80 |
void
|
icculus@9278
|
81 |
Emscripten_GLES_DeleteContext(_THIS, SDL_GLContext context)
|
icculus@9278
|
82 |
{
|
icculus@9278
|
83 |
/*
|
icculus@9278
|
84 |
WebGL contexts can't actually be deleted, so we need to reset it.
|
icculus@9278
|
85 |
ES2 renderer resets state on init anyway, clearing the canvas should be enough
|
icculus@9278
|
86 |
*/
|
icculus@9278
|
87 |
|
icculus@9278
|
88 |
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
icculus@9278
|
89 |
|
icculus@9278
|
90 |
SDL_EGL_DeleteContext(_this, context);
|
icculus@9278
|
91 |
}
|
icculus@9278
|
92 |
|
icculus@9278
|
93 |
SDL_EGL_CreateContext_impl(Emscripten)
|
icculus@9278
|
94 |
SDL_EGL_SwapWindow_impl(Emscripten)
|
icculus@9278
|
95 |
SDL_EGL_MakeCurrent_impl(Emscripten)
|
icculus@9278
|
96 |
|
icculus@9278
|
97 |
void
|
icculus@9278
|
98 |
Emscripten_GLES_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
|
icculus@9278
|
99 |
{
|
icculus@9278
|
100 |
SDL_WindowData *data;
|
icculus@9278
|
101 |
if (window->driverdata) {
|
icculus@9278
|
102 |
data = (SDL_WindowData *) window->driverdata;
|
icculus@9278
|
103 |
|
icculus@9278
|
104 |
if (w) {
|
icculus@9278
|
105 |
*w = window->w * data->pixel_ratio;
|
icculus@9278
|
106 |
}
|
icculus@9278
|
107 |
|
icculus@9278
|
108 |
if (h) {
|
icculus@9278
|
109 |
*h = window->h * data->pixel_ratio;
|
icculus@9278
|
110 |
}
|
icculus@9278
|
111 |
}
|
icculus@9278
|
112 |
}
|
icculus@9278
|
113 |
|
icculus@9278
|
114 |
#endif /* SDL_VIDEO_DRIVER_EMSCRIPTEN && SDL_VIDEO_OPENGL_EGL */
|
icculus@9278
|
115 |
|
icculus@9278
|
116 |
/* vi: set ts=4 sw=4 expandtab: */
|
icculus@9278
|
117 |
|