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