docs/README-emscripten.md
author Sam Lantinga <slouken@libsdl.org>
Wed, 18 Oct 2017 08:52:04 -0700
changeset 11630 ad4b5d85edee
parent 10958 92d837180433
permissions -rw-r--r--
Fixed bug 3821 - Allow SDL_CreateWindow and SDL_CreateRenderer with OpenGL ES 3.0 (GLES3) for Angle (Windows)

Carlos

Angle supports GLES3 but when using these functions (SDL_CreateWindow and SDL_CreateRenderer), defaults again to GLES2.0.

A current workaround (hack) to retrieve a GLES3.0 context with Angle is:

1) set

SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);

after InitSDL AND after calling SDL_CreateWindow (before SDL_CreateRenderer)

2) Comment lines 2032-2044 in SDL_render_gles2.c, funtion GLES2_CreateRenderer

window_flags = SDL_GetWindowFlags(window);
if (!(window_flags & SDL_WINDOW_OPENGL) ||
profile_mask != SDL_GL_CONTEXT_PROFILE_ES || major != RENDERER_CONTEXT_MAJOR || minor != RENDERER_CONTEXT_MINOR) {

changed_window = SDL_TRUE;
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, RENDERER_CONTEXT_MAJOR);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, RENDERER_CONTEXT_MINOR);

if (SDL_RecreateWindow(window, window_flags | SDL_WINDOW_OPENGL) < 0) {
goto error;
}
}

This retrives a GLES3 context as confirmed using glGetString(GL_VERSION). This should be fixed by modifying a few if's.
     1 Emscripten
     2 ================================================================================
     3 
     4 Build:
     5 
     6     $ mkdir build
     7     $ cd build
     8     $ emconfigure ../configure --host=asmjs-unknown-emscripten --disable-assembly --disable-threads --disable-cpuinfo CFLAGS="-O2"
     9     $ emmake make
    10 
    11 Or with cmake:
    12 
    13     $ mkdir build
    14     $ cd build
    15     $ emcmake cmake ..
    16     $ emmake make
    17 
    18 To build one of the tests:
    19 
    20     $ cd test/
    21     $ emcc -O2 --js-opts 0 -g4 testdraw2.c -I../include ../build/.libs/libSDL2.a ../build/libSDL2_test.a -o a.html
    22 
    23 Uses GLES2 renderer or software
    24 
    25 Some other SDL2 libraries can be easily built (assuming SDL2 is installed somewhere):
    26 
    27 SDL_mixer (http://www.libsdl.org/projects/SDL_mixer/):
    28 
    29     $ EMCONFIGURE_JS=1 emconfigure ../configure
    30     build as usual...
    31 
    32 SDL_gfx (http://cms.ferzkopp.net/index.php/software/13-sdl-gfx):
    33 
    34     $ EMCONFIGURE_JS=1 emconfigure ../configure --disable-mmx
    35     build as usual...