diff options
-rw-r--r-- | src/library_egl.js | 20 | ||||
-rw-r--r-- | tests/test_egl.c | 11 |
2 files changed, 30 insertions, 1 deletions
diff --git a/src/library_egl.js b/src/library_egl.js index 73d5e544..11cf8951 100644 --- a/src/library_egl.js +++ b/src/library_egl.js @@ -264,6 +264,26 @@ var LibraryEGL = { return 0; } + // EGL 1.4 spec says default EGL_CONTEXT_CLIENT_VERSION is GLES1, but this is not supported by Emscripten. + // So user must pass EGL_CONTEXT_CLIENT_VERSION == 2 to initialize EGL. + var glesContextVersion = 1; + for(;;) { + var param = {{{ makeGetValue('contextAttribs', '0', 'i32') }}}; + if (!param) break; + var value = {{{ makeGetValue('contextAttribs', '4', 'i32') }}}; + if (param == 0x3098 /*EGL_CONTEXT_CLIENT_VERSION*/) { + glesContextVersion = value; + } + contextAttribs += 8; + } + if (glesContextVersion != 2) { +#if GL_ASSERTIONS + Module.printErr('When initializing GLES2/WebGL1 via EGL, one must pass EGL_CONTEXT_CLIENT_VERSION = 2 to GL context attributes! GLES version ' + glesContextVersion + ' is not supported!'); +#endif + EGL.setErrorCode(0x3005 /* EGL_BAD_CONFIG */); + return 0; /* EGL_NO_CONTEXT */ + } + _glutInitDisplayMode(0x92 /* GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE */); EGL.windowID = _glutCreateWindow(); if (EGL.windowID != 0) { diff --git a/tests/test_egl.c b/tests/test_egl.c index 5864a797..d66949d0 100644 --- a/tests/test_egl.c +++ b/tests/test_egl.c @@ -37,12 +37,21 @@ int main(int argc, char *argv[]) assert(eglGetError() == EGL_SUCCESS); assert(surface != 0); + // WebGL maps to GLES2. GLES1 is not supported. + EGLint contextAttribsOld[] = + { + EGL_CONTEXT_CLIENT_VERSION, 1, + EGL_NONE + }; + EGLContext context = eglCreateContext(display, config, NULL, contextAttribsOld); + assert(eglGetError() != EGL_SUCCESS); + EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; - EGLContext context = eglCreateContext(display, config, NULL, contextAttribs); + context = eglCreateContext(display, config, NULL, contextAttribs); assert(eglGetError() == EGL_SUCCESS); assert(context != 0); |