aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJukka Jylänki <jujjyl@gmail.com>2013-11-13 13:29:45 +0200
committerJukka Jylänki <jujjyl@gmail.com>2013-11-13 14:04:14 +0200
commit9df84e4fdc2ea1580402a54a791257345d7b079d (patch)
tree4a3f1eac4831ba30fa999c42b7f97f5a76c8c815
parent73da7f6eb78aa704b80a272d7eeb9c3f0aa9982b (diff)
Add concepts of current context, and current draw and read surfaces on that context. Implement functions eglGetCurrentSurface(), eglGetCurrentDisplay() and eglGetCurrentContext(). Allow passing EGL_NO_SURFACE and EGL_NO_CONTEXT to eglMakeCurrent. Fixes #1793 and #1775.
-rw-r--r--src/library_egl.js70
1 files changed, 53 insertions, 17 deletions
diff --git a/src/library_egl.js b/src/library_egl.js
index 95abe821..73d5e544 100644
--- a/src/library_egl.js
+++ b/src/library_egl.js
@@ -10,6 +10,10 @@ var LibraryEGL = {
$EGL: {
// This variable tracks the success status of the most recently invoked EGL function call.
errorCode: 0x3000 /* EGL_SUCCESS */,
+ defaultDisplayInitialized: false,
+ currentContext: 0 /* EGL_NO_CONTEXT */,
+ currentReadSurface: 0 /* EGL_NO_SURFACE */,
+ currentDrawSurface: 0 /* EGL_NO_SURFACE */,
stringCache: {},
@@ -65,6 +69,7 @@ var LibraryEGL = {
if (minorVersion) {
{{{ makeSetValue('minorVersion', '0', '4', 'i32') }}}; // Advertise EGL Minor version: '4'
}
+ EGL.defaultDisplayInitialized = true;
EGL.setErrorCode(0x3000 /* EGL_SUCCESS */);
return 1;
}
@@ -80,18 +85,10 @@ var LibraryEGL = {
EGL.setErrorCode(0x3008 /* EGL_BAD_DISPLAY */);
return 0;
}
- // TODO: Tear down EGL here. Currently a no-op since we don't need to actually do anything here for the browser.
- EGL.setErrorCode(0x3000 /* EGL_SUCCESS */);
- return 1;
- },
-
-// EGLAPI EGLBoolean EGLAPIENTRY eglTerminate(EGLDisplay dpy);
- eglTerminate: function(display) {
- if (display != 62000 /* Magic ID for Emscripten 'default display' */) {
- EGL.setErrorCode(0x3008 /* EGL_BAD_DISPLAY */);
- return 0;
- }
- // TODO: Tear down EGL here. Currently a no-op since we don't need to actually do anything here for the browser.
+ EGL.currentContext = 0;
+ EGL.currentReadSurface = 0;
+ EGL.currentDrawSurface = 0;
+ EGL.defaultDisplayInitialized = false;
EGL.setErrorCode(0x3000 /* EGL_SUCCESS */);
return 1;
},
@@ -248,6 +245,12 @@ var LibraryEGL = {
EGL.setErrorCode(0x300D /* EGL_BAD_SURFACE */);
return 1;
}
+ if (EGL.currentReadSurface == surface) {
+ EGL.currentReadSurface = 0;
+ }
+ if (EGL.currentDrawSurface == surface) {
+ EGL.currentDrawSurface = 0;
+ }
EGL.setErrorCode(0x3000 /* EGL_SUCCESS */);
return 1; /* Magic ID for Emscripten 'default surface' */
},
@@ -265,6 +268,7 @@ var LibraryEGL = {
EGL.windowID = _glutCreateWindow();
if (EGL.windowID != 0) {
EGL.setErrorCode(0x3000 /* EGL_SUCCESS */);
+ // Note: This function only creates a context, but it shall not make it active.
return 62004; // Magic ID for Emscripten EGLContext
} else {
EGL.setErrorCode(0x3009 /* EGL_BAD_MATCH */); // By the EGL 1.4 spec, an implementation that does not support GLES2 (WebGL in this case), this error code is set.
@@ -280,10 +284,17 @@ var LibraryEGL = {
EGL.setErrorCode(0x3008 /* EGL_BAD_DISPLAY */);
return 0;
}
+ if (context != 62004 /* Magic ID for Emscripten EGLContext */) {
+ EGL.setErrorCode(0x3006 /* EGL_BAD_CONTEXT */);
+ return 0;
+ }
_glutDestroyWindow(EGL.windowID);
EGL.setErrorCode(0x3000 /* EGL_SUCCESS */);
- return 62004; // Magic ID for Emscripten EGLContext
+ if (EGL.currentContext == context) {
+ EGL.currentContext = 0;
+ }
+ return 1 /* EGL_TRUE */;
},
// EGLAPI EGLBoolean EGLAPIENTRY eglDestroyContext(EGLDisplay dpy, EGLContext ctx);
@@ -477,21 +488,46 @@ var LibraryEGL = {
eglMakeCurrent: function(display, draw, read, context) {
if (display != 62000 /* Magic ID for Emscripten 'default display' */) {
EGL.setErrorCode(0x3008 /* EGL_BAD_DISPLAY */);
- return 0;
+ return 0 /* EGL_FALSE */;
}
//\todo An EGL_NOT_INITIALIZED error is generated if EGL is not initialized for dpy.
- if (context != 62004 /* Magic ID for Emscripten EGLContext */) {
+ if (context != 0 && context != 62004 /* Magic ID for Emscripten EGLContext */) {
EGL.setErrorCode(0x3006 /* EGL_BAD_CONTEXT */);
return 0;
}
- if (read != 62006 || draw != 62006 /* Magic ID for Emscripten 'default surface' */) {
+ if ((read != 0 && read != 62006) || (draw != 0 && draw != 62006 /* Magic ID for Emscripten 'default surface' */)) {
EGL.setErrorCode(0x300D /* EGL_BAD_SURFACE */);
return 0;
}
+ EGL.currentContext = context;
+ EGL.currentDrawSurface = draw;
+ EGL.currentReadSurface = read;
EGL.setErrorCode(0x3000 /* EGL_SUCCESS */);
- return 1;
+ return 1 /* EGL_TRUE */;
+ },
+
+ // EGLAPI EGLContext EGLAPIENTRY eglGetCurrentContext(void);
+ eglGetCurrentContext: function() {
+ return EGL.currentContext;
},
+ // EGLAPI EGLSurface EGLAPIENTRY eglGetCurrentSurface(EGLint readdraw);
+ eglGetCurrentSurface: function(readdraw) {
+ if (readdraw == 0x305A /* EGL_READ */) {
+ return EGL.currentReadSurface;
+ } else if (readdraw == 0x3059 /* EGL_DRAW */) {
+ return EGL.currentDrawSurface;
+ } else {
+ EGL.setErrorCode(0x300C /* EGL_BAD_PARAMETER */);
+ return 0 /* EGL_NO_SURFACE */;
+ }
+ },
+
+ // EGLAPI EGLDisplay EGLAPIENTRY eglGetCurrentDisplay(void);
+ eglGetCurrentDisplay: function() {
+ return EGL.currentContext ? 62000 /* Magic ID for Emscripten 'default display' */ : 0;
+ },
+
// EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffers(EGLDisplay dpy, EGLSurface surface);
eglSwapBuffers: function() {
EGL.setErrorCode(0x3000 /* EGL_SUCCESS */);