SDL_emscriptenopengles.c
Go to the documentation of this file.
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_EMSCRIPTEN && SDL_VIDEO_OPENGL_EGL
#include <emscripten/emscripten.h>
#include <GLES2/gl2.h>
#include "SDL_emscriptenvideo.h"
#include "SDL_emscriptenopengles.h"
#define LOAD_FUNC(NAME) _this->egl_data->NAME = NAME;
/* EGL implementation of SDL OpenGL support */
int
Emscripten_GLES_LoadLibrary(_THIS, const char *path) {
/*we can't load EGL dynamically*/
_this->egl_data = (struct SDL_EGL_VideoData *) SDL_calloc(1, sizeof(SDL_EGL_VideoData));
if (!_this->egl_data) {
return SDL_OutOfMemory();
}
/* Emscripten forces you to manually cast eglGetProcAddress to the real
function type; grep for "__eglMustCastToProperFunctionPointerType" in
Emscripten's egl.h for details. */
_this->egl_data->eglGetProcAddress = (void *(EGLAPIENTRY *)(const char *)) eglGetProcAddress;
LOAD_FUNC(eglGetDisplay);
LOAD_FUNC(eglInitialize);
LOAD_FUNC(eglTerminate);
LOAD_FUNC(eglChooseConfig);
LOAD_FUNC(eglGetConfigAttrib);
LOAD_FUNC(eglCreateContext);
LOAD_FUNC(eglDestroyContext);
LOAD_FUNC(eglCreateWindowSurface);
LOAD_FUNC(eglDestroySurface);
LOAD_FUNC(eglMakeCurrent);
LOAD_FUNC(eglSwapBuffers);
LOAD_FUNC(eglSwapInterval);
LOAD_FUNC(eglWaitNative);
LOAD_FUNC(eglWaitGL);
LOAD_FUNC(eglBindAPI);
_this->egl_data->egl_display = _this->egl_data->eglGetDisplay(EGL_DEFAULT_DISPLAY);
if (!_this->egl_data->egl_display) {
return SDL_SetError("Could not get EGL display");
}
if (_this->egl_data->eglInitialize(_this->egl_data->egl_display, NULL, NULL) != EGL_TRUE) {
return SDL_SetError("Could not initialize EGL");
}
if (path) {
SDL_strlcpy(_this->gl_config.driver_path, path, sizeof(_this->gl_config.driver_path) - 1);
} else {
*_this->gl_config.driver_path = '\0';
}
return 0;
}
void
Emscripten_GLES_DeleteContext(_THIS, SDL_GLContext context)
{
/*
WebGL contexts can't actually be deleted, so we need to reset it.
ES2 renderer resets state on init anyway, clearing the canvas should be enough
*/
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
SDL_EGL_DeleteContext(_this, context);
}
SDL_EGL_CreateContext_impl(Emscripten)
SDL_EGL_SwapWindow_impl(Emscripten)
SDL_EGL_MakeCurrent_impl(Emscripten)
void
Emscripten_GLES_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
{
SDL_WindowData *data;
if (window->driverdata) {
data = (SDL_WindowData *) window->driverdata;
if (w) {
*w = window->w * data->pixel_ratio;
}
if (h) {
*h = window->h * data->pixel_ratio;
}
}
}
#endif /* SDL_VIDEO_DRIVER_EMSCRIPTEN && SDL_VIDEO_OPENGL_EGL */
/* vi: set ts=4 sw=4 expandtab: */
SDL_strlcpy
#define SDL_strlcpy
Definition: SDL_dynapi_overrides.h:394
eglTerminate
EGLAPI EGLBoolean EGLAPIENTRY eglTerminate(EGLDisplay dpy)
SDL_WindowData::pixel_ratio
float pixel_ratio
Definition: SDL_emscriptenvideo.h:43
eglDestroySurface
EGLAPI EGLBoolean EGLAPIENTRY eglDestroySurface(EGLDisplay dpy, EGLSurface surface)
eglCreateWindowSurface
EGLAPI EGLSurface EGLAPIENTRY eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list)
SDL_emscriptenvideo.h
SDL_Window::w
int w
Definition: SDL_sysvideo.h:80
GL_STENCIL_BUFFER_BIT
#define GL_STENCIL_BUFFER_BIT
Definition: SDL_opengl.h:738
eglMakeCurrent
EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
h
GLfloat GLfloat GLfloat GLfloat h
Definition: SDL_opengl_glext.h:1946
context
static screen_context_t context
Definition: video.c:25
GL_DEPTH_BUFFER_BIT
#define GL_DEPTH_BUFFER_BIT
Definition: SDL_opengl.h:736
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
eglGetProcAddress
EGLAPI __eglMustCastToProperFunctionPointerType EGLAPIENTRY eglGetProcAddress(const char *procname)
eglGetConfigAttrib
EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value)
eglBindAPI
EGLAPI EGLBoolean EGLAPIENTRY eglBindAPI(EGLenum api)
EGL_TRUE
#define EGL_TRUE
Definition: egl.h:116
EGL_DEFAULT_DISPLAY
#define EGL_DEFAULT_DISPLAY
Definition: egl.h:227
SDL_WindowData
Definition: SDL_androidwindow.h:35
eglChooseConfig
EGLAPI EGLBoolean EGLAPIENTRY eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config)
_this
static SDL_VideoDevice * _this
Definition: SDL_video.c:121
eglDestroyContext
EGLAPI EGLBoolean EGLAPIENTRY eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
EGLAPIENTRY
#define EGLAPIENTRY
Definition: eglplatform.h:54
SDL_GLContext
void * SDL_GLContext
An opaque handle to an OpenGL context.
Definition: SDL_video.h:175
_THIS
#define _THIS
Definition: SDL_alsa_audio.h:31
SDL_VideoDevice::driver_path
char driver_path[256]
Definition: SDL_sysvideo.h:350
SDL_emscriptenopengles.h
gl2.h
w
GLubyte GLubyte GLubyte GLubyte w
Definition: SDL_opengl_glext.h:731
glClear
GLAPI void GLAPIENTRY glClear(GLbitfield mask)
GL_COLOR_BUFFER_BIT
#define GL_COLOR_BUFFER_BIT
Definition: SDL_opengl.h:742
SDL_Window::h
int h
Definition: SDL_sysvideo.h:80
NULL
#define NULL
Definition: begin_code.h:164
SDL_OutOfMemory
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
eglGetDisplay
EGLAPI EGLDisplay EGLAPIENTRY eglGetDisplay(EGLNativeDisplayType display_id)
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:30
eglSwapBuffers
EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
SDL_calloc
#define SDL_calloc
Definition: SDL_dynapi_overrides.h:375
window
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
SDL_Window
The type used to identify a window.
Definition: SDL_sysvideo.h:73
eglWaitGL
EGLAPI EGLBoolean EGLAPIENTRY eglWaitGL(void)
eglSwapInterval
EGLAPI EGLBoolean EGLAPIENTRY eglSwapInterval(EGLDisplay dpy, EGLint interval)
eglWaitNative
EGLAPI EGLBoolean EGLAPIENTRY eglWaitNative(EGLint engine)
path
GLsizei const GLchar *const * path
Definition: SDL_opengl_glext.h:3730
SDL_VideoDevice::gl_config
struct SDL_VideoDevice::@34 gl_config
SDL_Window::driverdata
void * driverdata
Definition: SDL_sysvideo.h:111
eglCreateContext
EGLAPI EGLContext EGLAPIENTRY eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list)
eglInitialize
EGLAPI EGLBoolean EGLAPIENTRY eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)