| |
| |
| |
| |
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| {{{ |
| |
| const eglDefaultDisplay = 62000; |
| |
| const eglDefaultConfig = 62002; |
| |
| const eglDefaultContext = 62004; |
| }}} |
|
|
| var LibraryEGL = { |
| $EGL__deps: ['$Browser'], |
| $EGL: { |
| |
| errorCode: 0x3000 , |
| defaultDisplayInitialized: false, |
| currentContext: 0 , |
| currentReadSurface: 0 , |
| currentDrawSurface: 0 , |
|
|
| contextAttributes: { |
| alpha: false, |
| depth: false, |
| stencil: false, |
| antialias: false |
| }, |
|
|
| stringCache: {}, |
|
|
| setErrorCode(code) { |
| EGL.errorCode = code; |
| }, |
|
|
| chooseConfig(display, attribList, config, config_size, numConfigs) { |
| if (display != {{{ eglDefaultDisplay }}}) { |
| EGL.setErrorCode(0x3008 ); |
| return 0; |
| } |
|
|
| if (attribList) { |
| |
| for (;;) { |
| var param = {{{ makeGetValue('attribList', '0', 'i32') }}}; |
| if (param == 0x3021 ) { |
| var alphaSize = {{{ makeGetValue('attribList', '4', 'i32') }}}; |
| EGL.contextAttributes.alpha = (alphaSize > 0); |
| } else if (param == 0x3025 ) { |
| var depthSize = {{{ makeGetValue('attribList', '4', 'i32') }}}; |
| EGL.contextAttributes.depth = (depthSize > 0); |
| } else if (param == 0x3026 ) { |
| var stencilSize = {{{ makeGetValue('attribList', '4', 'i32') }}}; |
| EGL.contextAttributes.stencil = (stencilSize > 0); |
| } else if (param == 0x3031 ) { |
| var samples = {{{ makeGetValue('attribList', '4', 'i32') }}}; |
| EGL.contextAttributes.antialias = (samples > 0); |
| } else if (param == 0x3032 ) { |
| var samples = {{{ makeGetValue('attribList', '4', 'i32') }}}; |
| EGL.contextAttributes.antialias = (samples == 1); |
| } else if (param == 0x3100 ) { |
| var requestedPriority = {{{ makeGetValue('attribList', '4', 'i32') }}}; |
| EGL.contextAttributes.lowLatency = (requestedPriority != 0x3103 ); |
| } else if (param == 0x3038 ) { |
| break; |
| } |
| attribList += 8; |
| } |
| } |
|
|
| if ((!config || !config_size) && !numConfigs) { |
| EGL.setErrorCode(0x300C ); |
| return 0; |
| } |
| if (numConfigs) { |
| {{{ makeSetValue('numConfigs', '0', '1', 'i32') }}}; |
| } |
| if (config && config_size > 0) { |
| {{{ makeSetValue('config', '0', eglDefaultConfig , '*') }}}; |
| } |
|
|
| EGL.setErrorCode(0x3000 ); |
| return 1; |
| }, |
| }, |
|
|
| |
| eglGetDisplay__proxy: 'sync', |
| eglGetDisplay: (nativeDisplayType) => { |
| EGL.setErrorCode(0x3000 ); |
| |
| |
| |
| if (nativeDisplayType != 0 && nativeDisplayType != 1 ) { |
| return 0; |
| } |
| return {{{ eglDefaultDisplay }}}; |
| }, |
|
|
| |
| eglInitialize__proxy: 'sync', |
| eglInitialize: (display, majorVersion, minorVersion) => { |
| if (display != {{{ eglDefaultDisplay }}}) { |
| EGL.setErrorCode(0x3008 ); |
| return 0; |
| } |
| if (majorVersion) { |
| {{{ makeSetValue('majorVersion', '0', '1', 'i32') }}}; |
| } |
| if (minorVersion) { |
| {{{ makeSetValue('minorVersion', '0', '4', 'i32') }}}; |
| } |
| EGL.defaultDisplayInitialized = true; |
| EGL.setErrorCode(0x3000 ); |
| return 1; |
| }, |
|
|
| |
| eglTerminate__proxy: 'sync', |
| eglTerminate: (display) => { |
| if (display != {{{ eglDefaultDisplay }}}) { |
| EGL.setErrorCode(0x3008 ); |
| return 0; |
| } |
| EGL.currentContext = 0; |
| EGL.currentReadSurface = 0; |
| EGL.currentDrawSurface = 0; |
| EGL.defaultDisplayInitialized = false; |
| EGL.setErrorCode(0x3000 ); |
| return 1; |
| }, |
|
|
| |
| eglGetConfigs__proxy: 'sync', |
| eglGetConfigs: (display, configs, config_size, numConfigs) => |
| EGL.chooseConfig(display, 0, configs, config_size, numConfigs), |
|
|
| |
| eglChooseConfig__proxy: 'sync', |
| eglChooseConfig: (display, attrib_list, configs, config_size, numConfigs) => |
| EGL.chooseConfig(display, attrib_list, configs, config_size, numConfigs), |
|
|
| |
| eglGetConfigAttrib__proxy: 'sync', |
| eglGetConfigAttrib: (display, config, attribute, value) => { |
| if (display != {{{ eglDefaultDisplay }}}) { |
| EGL.setErrorCode(0x3008 ); |
| return 0; |
| } |
| if (config != {{{ eglDefaultConfig }}}) { |
| EGL.setErrorCode(0x3005 ); |
| return 0; |
| } |
| if (!value) { |
| EGL.setErrorCode(0x300C ); |
| return 0; |
| } |
| EGL.setErrorCode(0x3000 ); |
| switch (attribute) { |
| case 0x3020: |
| {{{ makeSetValue('value', '0', 'EGL.contextAttributes.alpha ? 32 : 24' , 'i32') }}}; |
| return 1; |
| case 0x3021: |
| {{{ makeSetValue('value', '0', 'EGL.contextAttributes.alpha ? 8 : 0' , 'i32') }}}; |
| return 1; |
| case 0x3022: |
| {{{ makeSetValue('value', '0', '8' , 'i32') }}}; |
| return 1; |
| case 0x3023: |
| {{{ makeSetValue('value', '0', '8' , 'i32') }}}; |
| return 1; |
| case 0x3024: |
| {{{ makeSetValue('value', '0', '8' , 'i32') }}}; |
| return 1; |
| case 0x3025: |
| {{{ makeSetValue('value', '0', 'EGL.contextAttributes.depth ? 24 : 0' , 'i32') }}}; |
| return 1; |
| case 0x3026: |
| {{{ makeSetValue('value', '0', 'EGL.contextAttributes.stencil ? 8 : 0' , 'i32') }}}; |
| return 1; |
| case 0x3027: |
| |
| {{{ makeSetValue('value', '0', '0x3038' , 'i32') }}}; |
| return 1; |
| case 0x3028: |
| {{{ makeSetValue('value', '0', eglDefaultConfig, 'i32') }}}; |
| return 1; |
| case 0x3029: |
| {{{ makeSetValue('value', '0', '0' , 'i32') }}}; |
| return 1; |
| case 0x302A: |
| {{{ makeSetValue('value', '0', '4096', 'i32') }}}; |
| return 1; |
| case 0x302B: |
| {{{ makeSetValue('value', '0', '16777216' , 'i32') }}}; |
| return 1; |
| case 0x302C: |
| {{{ makeSetValue('value', '0', '4096', 'i32') }}}; |
| return 1; |
| case 0x302D: |
| {{{ makeSetValue('value', '0', '0' , 'i32') }}}; |
| return 1; |
| case 0x302E: |
| {{{ makeSetValue('value', '0', '0' , 'i32') }}}; |
| return 1; |
| case 0x302F: |
| {{{ makeSetValue('value', '0', '0x3038' , 'i32') }}}; |
| return 1; |
| case 0x3031: |
| {{{ makeSetValue('value', '0', 'EGL.contextAttributes.antialias ? 4 : 0' , 'i32') }}}; |
| return 1; |
| case 0x3032: |
| {{{ makeSetValue('value', '0', 'EGL.contextAttributes.antialias ? 1 : 0' , 'i32') }}}; |
| return 1; |
| case 0x3033: |
| {{{ makeSetValue('value', '0', '0x4' , 'i32') }}}; |
| return 1; |
| case 0x3034: |
| |
| {{{ makeSetValue('value', '0', '0x3038' , 'i32') }}}; |
| return 1; |
| case 0x3035: |
| case 0x3036: |
| case 0x3037: |
| |
| {{{ makeSetValue('value', '0', '-1' , 'i32') }}}; |
| return 1; |
| case 0x3039: |
| case 0x303A: |
| {{{ makeSetValue('value', '0', '0' , 'i32') }}}; |
| return 1; |
| case 0x303B: |
| {{{ makeSetValue('value', '0', '0', 'i32') }}}; |
| return 1; |
| case 0x303C: |
| {{{ makeSetValue('value', '0', '1' , 'i32') }}}; |
| return 1; |
| case 0x303D: |
| case 0x303E: |
| {{{ makeSetValue('value', '0', '0' , 'i32') }}}; |
| return 1; |
| case 0x303F: |
| |
| {{{ makeSetValue('value', '0', '0x308E' , 'i32') }}}; |
| return 1; |
| case 0x3040: |
| |
| {{{ makeSetValue('value', '0', '0x4' , 'i32') }}}; |
| return 1; |
| case 0x3042: |
| |
| {{{ makeSetValue('value', '0', '0' , 'i32') }}}; |
| return 1; |
| default: |
| EGL.setErrorCode(0x3004 ); |
| return 0; |
| } |
| }, |
|
|
| |
| eglCreateWindowSurface__proxy: 'sync', |
| eglCreateWindowSurface: (display, config, win, attrib_list) => { |
| if (display != {{{ eglDefaultDisplay }}}) { |
| EGL.setErrorCode(0x3008 ); |
| return 0; |
| } |
| if (config != {{{ eglDefaultConfig }}}) { |
| EGL.setErrorCode(0x3005 ); |
| return 0; |
| } |
| |
| |
| |
| |
| EGL.setErrorCode(0x3000 ); |
| return 62006; |
| }, |
|
|
| |
| eglDestroySurface__proxy: 'sync', |
| eglDestroySurface: (display, surface) => { |
| if (display != {{{ eglDefaultDisplay }}}) { |
| EGL.setErrorCode(0x3008 ); |
| return 0; |
| } |
| if (surface != 62006 ) { |
| EGL.setErrorCode(0x300D ); |
| return 1; |
| } |
| if (EGL.currentReadSurface == surface) { |
| EGL.currentReadSurface = 0; |
| } |
| if (EGL.currentDrawSurface == surface) { |
| EGL.currentDrawSurface = 0; |
| } |
| EGL.setErrorCode(0x3000 ); |
| return 1; |
| }, |
|
|
| eglCreateContext__deps: ['$GL'], |
|
|
| |
| eglCreateContext__proxy: 'sync', |
| eglCreateContext: (display, config, hmm, contextAttribs) => { |
| if (display != {{{ eglDefaultDisplay }}}) { |
| EGL.setErrorCode(0x3008 ); |
| return 0; |
| } |
|
|
| |
| |
| var glesContextVersion = 1; |
| for (;;) { |
| var param = {{{ makeGetValue('contextAttribs', '0', 'i32') }}}; |
| if (param == 0x3098 ) { |
| glesContextVersion = {{{ makeGetValue('contextAttribs', '4', 'i32') }}}; |
| } else if (param == 0x3038 ) { |
| break; |
| } else { |
| |
| EGL.setErrorCode(0x3004 ); |
| return 0; |
| } |
| contextAttribs += 8; |
| } |
| #if MAX_WEBGL_VERSION >= 2 |
| if (glesContextVersion < 2 || glesContextVersion > 3) { |
| #else |
| if (glesContextVersion != 2) { |
| #endif |
| #if GL_ASSERTIONS |
| if (glesContextVersion == 3) { |
| err('When initializing GLES3/WebGL2 via EGL, one must build with -sMAX_WEBGL_VERSION=2!'); |
| } else { |
| err(`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 ); |
| return 0; |
| } |
|
|
| EGL.contextAttributes.majorVersion = glesContextVersion - 1; |
| EGL.contextAttributes.minorVersion = 0; |
|
|
| EGL.context = GL.createContext(Browser.getCanvas(), EGL.contextAttributes); |
|
|
| if (EGL.context != 0) { |
| EGL.setErrorCode(0x3000 ); |
|
|
| |
| GL.makeContextCurrent(EGL.context); |
| Browser.useWebGL = true; |
| Browser.moduleContextCreatedCallbacks.forEach((callback) => callback()); |
|
|
| |
| GL.makeContextCurrent(null); |
| return {{{ eglDefaultContext }}}; |
| } else { |
| EGL.setErrorCode(0x3009 ); |
| return 0; |
| } |
| }, |
|
|
| eglDestroyContext__deps: ['$GL'], |
|
|
| |
| eglDestroyContext__proxy: 'sync', |
| eglDestroyContext: (display, context) => { |
| if (display != {{{ eglDefaultDisplay }}}) { |
| EGL.setErrorCode(0x3008 ); |
| return 0; |
| } |
| if (context != {{{ eglDefaultContext }}}) { |
| EGL.setErrorCode(0x3006 ); |
| return 0; |
| } |
|
|
| GL.deleteContext(EGL.context); |
| EGL.setErrorCode(0x3000 ); |
| if (EGL.currentContext == context) { |
| EGL.currentContext = 0; |
| } |
| return 1 ; |
| }, |
|
|
| |
| eglQuerySurface__proxy: 'sync', |
| eglQuerySurface: (display, surface, attribute, value) => { |
| if (display != {{{ eglDefaultDisplay }}}) { |
| EGL.setErrorCode(0x3008 ); |
| return 0; |
| } |
| if (surface != 62006 ) { |
| EGL.setErrorCode(0x300D ); |
| return 0; |
| } |
| if (!value) { |
| EGL.setErrorCode(0x300C ); |
| return 0; |
| } |
| EGL.setErrorCode(0x3000 ); |
| switch (attribute) { |
| case 0x3028: |
| {{{ makeSetValue('value', '0', eglDefaultConfig, 'i32') }}}; |
| return 1; |
| case 0x3058: |
| |
| |
| return 1; |
| case 0x3057: |
| {{{ makeSetValue('value', '0', "Browser.getCanvas().width", 'i32') }}}; |
| return 1; |
| case 0x3056: |
| {{{ makeSetValue('value', '0', "Browser.getCanvas().height", 'i32') }}}; |
| return 1; |
| case 0x3090: |
| {{{ makeSetValue('value', '0', '-1' , 'i32') }}}; |
| return 1; |
| case 0x3091: |
| {{{ makeSetValue('value', '0', '-1' , 'i32') }}}; |
| return 1; |
| case 0x3092: |
| {{{ makeSetValue('value', '0', '-1' , 'i32') }}}; |
| return 1; |
| case 0x3086: |
| |
| |
| {{{ makeSetValue('value', '0', '0x3084' , 'i32') }}}; |
| return 1; |
| case 0x3099: |
| {{{ makeSetValue('value', '0', '0x309A' , 'i32') }}}; |
| return 1; |
| case 0x3093: |
| |
| |
| {{{ makeSetValue('value', '0', '0x3095' , 'i32') }}}; |
| return 1; |
| case 0x3080: |
| case 0x3081: |
| case 0x3082: |
| case 0x3083: |
| |
| |
| |
| return 1; |
| default: |
| EGL.setErrorCode(0x3004 ); |
| return 0; |
| } |
| }, |
|
|
| |
| eglQueryContext__proxy: 'sync', |
| eglQueryContext: (display, context, attribute, value) => { |
| if (display != {{{ eglDefaultDisplay }}}) { |
| EGL.setErrorCode(0x3008 ); |
| return 0; |
| } |
| |
| if (context != {{{ eglDefaultContext }}}) { |
| EGL.setErrorCode(0x3006 ); |
| return 0; |
| } |
| if (!value) { |
| EGL.setErrorCode(0x300C ); |
| return 0; |
| } |
|
|
| EGL.setErrorCode(0x3000 ); |
| switch (attribute) { |
| case 0x3028: |
| {{{ makeSetValue('value', '0', eglDefaultConfig, 'i32') }}}; |
| return 1; |
| case 0x3097: |
| {{{ makeSetValue('value', '0', '0x30A0' , 'i32') }}}; |
| return 1; |
| case 0x3098: |
| {{{ makeSetValue('value', '0', 'EGL.contextAttributes.majorVersion + 1', 'i32') }}}; |
| return 1; |
| case 0x3086: |
| |
| |
| {{{ makeSetValue('value', '0', '0x3084' , 'i32') }}}; |
| return 1; |
| default: |
| EGL.setErrorCode(0x3004 ); |
| return 0; |
| } |
| }, |
|
|
| |
| eglGetError__proxy: 'sync', |
| eglGetError: () => EGL.errorCode, |
|
|
| |
| |
| eglQueryString__noleakcheck: true, |
| eglQueryString__deps: ['$stringToNewUTF8'], |
| eglQueryString__proxy: 'sync', |
| eglQueryString: (display, name) => { |
| if (display != {{{ eglDefaultDisplay }}}) { |
| EGL.setErrorCode(0x3008 ); |
| return 0; |
| } |
| |
| EGL.setErrorCode(0x3000 ); |
| if (EGL.stringCache[name]) return EGL.stringCache[name]; |
| var ret; |
| switch (name) { |
| case 0x3053 : ret = stringToNewUTF8("Emscripten"); break; |
| case 0x3054 : ret = stringToNewUTF8("1.4 Emscripten EGL"); break; |
| case 0x3055 : ret = stringToNewUTF8(""); break; |
| case 0x308D : ret = stringToNewUTF8("OpenGL_ES"); break; |
| default: |
| EGL.setErrorCode(0x300C ); |
| return 0; |
| } |
| EGL.stringCache[name] = ret; |
| return ret; |
| }, |
|
|
| |
| eglBindAPI__proxy: 'sync', |
| eglBindAPI: (api) => { |
| if (api == 0x30A0 ) { |
| EGL.setErrorCode(0x3000 ); |
| return 1; |
| } |
| |
| EGL.setErrorCode(0x300C ); |
| return 0; |
| }, |
|
|
| |
| eglQueryAPI__proxy: 'sync', |
| eglQueryAPI: () => { |
| EGL.setErrorCode(0x3000 ); |
| return 0x30A0; |
| }, |
|
|
| |
| eglWaitClient__proxy: 'sync', |
| eglWaitClient: () => { |
| EGL.setErrorCode(0x3000 ); |
| return 1; |
| }, |
|
|
| |
| eglWaitNative__proxy: 'sync', |
| eglWaitNative: (nativeEngineId) => { |
| EGL.setErrorCode(0x3000 ); |
| return 1; |
| }, |
|
|
|
|
| |
| eglWaitGL: 'eglWaitClient', |
|
|
| |
| eglSwapInterval__deps: ['emscripten_set_main_loop_timing'], |
| eglSwapInterval__proxy: 'sync', |
| eglSwapInterval: (display, interval) => { |
| if (display != {{{ eglDefaultDisplay }}}) { |
| EGL.setErrorCode(0x3008 ); |
| return 0; |
| } |
| if (interval == 0) _emscripten_set_main_loop_timing({{{ cDefs.EM_TIMING_SETTIMEOUT }}}, 0); |
| else _emscripten_set_main_loop_timing({{{ cDefs.EM_TIMING_RAF }}}, interval); |
|
|
| EGL.setErrorCode(0x3000 ); |
| return 1; |
| }, |
|
|
| |
| eglMakeCurrent__deps: ['$GL'], |
| eglMakeCurrent__proxy: 'sync', |
| eglMakeCurrent: (display, draw, read, context) => { |
| if (display != {{{ eglDefaultDisplay }}}) { |
| EGL.setErrorCode(0x3008 ); |
| return 0 ; |
| } |
| |
| if (context != 0 && context != {{{ eglDefaultContext }}}) { |
| EGL.setErrorCode(0x3006 ); |
| return 0; |
| } |
| if ((read != 0 && read != 62006) || (draw != 0 && draw != 62006 )) { |
| EGL.setErrorCode(0x300D ); |
| return 0; |
| } |
|
|
| GL.makeContextCurrent(context ? EGL.context : null); |
|
|
| EGL.currentContext = context; |
| EGL.currentDrawSurface = draw; |
| EGL.currentReadSurface = read; |
| EGL.setErrorCode(0x3000 ); |
| return 1 ; |
| }, |
|
|
| |
| eglGetCurrentContext__proxy: 'sync', |
| eglGetCurrentContext: () => EGL.currentContext, |
|
|
| |
| eglGetCurrentSurface__proxy: 'sync', |
| eglGetCurrentSurface: (readdraw) => { |
| if (readdraw == 0x305A ) { |
| return EGL.currentReadSurface; |
| } else if (readdraw == 0x3059 ) { |
| return EGL.currentDrawSurface; |
| } else { |
| EGL.setErrorCode(0x300C ); |
| return 0 ; |
| } |
| }, |
|
|
| |
| eglGetCurrentDisplay__proxy: 'sync', |
| eglGetCurrentDisplay: () => EGL.currentContext ? {{{ eglDefaultDisplay }}} : 0, |
|
|
| |
| eglSwapBuffers__deps: ['$GLctx'], |
| eglSwapBuffers__proxy: 'sync', |
| eglSwapBuffers: (dpy, surface) => { |
| if (!EGL.defaultDisplayInitialized) { |
| EGL.setErrorCode(0x3001 ); |
| } else if (!GLctx) { |
| EGL.setErrorCode(0x3002 ); |
| } else if (GLctx.isContextLost()) { |
| EGL.setErrorCode(0x300E ); |
| } else { |
| |
| |
| |
| |
| EGL.setErrorCode(0x3000 ); |
| return 1 ; |
| } |
| return 0 ; |
| }, |
|
|
| eglReleaseThread__proxy: 'sync', |
| eglReleaseThread: () => { |
| |
| EGL.currentContext = 0; |
| EGL.currentReadSurface = 0; |
| EGL.currentDrawSurface = 0; |
| |
| |
| |
| EGL.setErrorCode(0x3000 ); |
| return 1 ; |
| } |
| }; |
|
|
| autoAddDeps(LibraryEGL, '$EGL'); |
|
|
| addToLibrary(LibraryEGL); |
|
|