diff options
author | Jari Vetoniemi <mailroxas@gmail.com> | 2014-01-14 17:04:58 +0200 |
---|---|---|
committer | Jari Vetoniemi <mailroxas@gmail.com> | 2014-01-14 17:04:58 +0200 |
commit | a39788f5020f726cbe6cfcc49de9cc669f445237 (patch) | |
tree | 221e61708bbbd3fcf95c1d964f48a3bb3333698e /src | |
parent | 0e36f078d4a9666303340506638726d316096e07 (diff) |
Add GLEW 1.10.0 emulation
Includes library_glew.js that stubs the init functions, but also provides the
other functions.
GL/glew.h is now changed to work with GLEW_EXT_foo_bar constants,
some missing constants that are in GLEW 1.10.0 are also provided.
Otherwise it still uses SDL_opengl.h to provide function definitions and
other constants.
Linaro's GLEW (glew-oes) is also supported to some degree to make it
easier to get ES1 and ES2 software using it running.
What it lacks:
- Some constants and function declarations that are in GLEW 1.10.0
might be missing.
- The real glew-es fork also includes normal GL constants and
function pointers, this does not.
Tests ran:
- tests/runner.py browser
Real world example using this code (and upcomming glfw3 port) can be found here:
http://cloudef.eu/glhck
http://cloudef.eu/glhck/qb.html
Diffstat (limited to 'src')
-rw-r--r-- | src/library_glew.js | 135 | ||||
-rw-r--r-- | src/modules.js | 2 |
2 files changed, 136 insertions, 1 deletions
diff --git a/src/library_glew.js b/src/library_glew.js new file mode 100644 index 00000000..f7da5f82 --- /dev/null +++ b/src/library_glew.js @@ -0,0 +1,135 @@ +/******************************************************************************* + * EMSCRIPTEN GLEW 1.10.0 emulation + * + * What it does: + * - Stubs init function. + * - GL Extensions support. + * + * Optional: + * - isLinaroFork variable to enable glew-es specific error strings. + * This is enabled by default, but should be disabled when upstream glew conflicts. + * + * Authors: + * - Jari Vetoniemi <mailroxas@gmail.com> + ******************************************************************************/ + +var LibraryGLEW = { + $GLEW__deps: ['glGetString'], + $GLEW: { + isLinaroFork: 1, + extensions: null, + + error: { + 0:null, // GLEW_OK || GLEW_NO_ERROR + 1:null, // GLEW_ERROR_NO_GL_VERSION + 2:null, // GLEW_ERROR_GL_VERSION_10_ONLY + 3:null, // GLEW_ERROR_GLX_VERSION_11_ONLY + + 4:null, // GLEW_ERROR_NOT_GLES_VERSION + 5:null, // GLEW_ERROR_GLES_VERSION + 6:null, // GLEW_ERROR_NO_EGL_VERSION + 7:null, // GLEW_ERROR_EGL_VERSION_10_ONLY + + 8:null, // Unknown error + }, + + version: { + 1:null, // GLEW_VERSION + 2:null, // GLEW_VERSION_MAJOR + 3:null, // GLEW_VERSION_MINOR + 4:null, // GLEW_VERSION_MICRO + }, + + errorStringConstantFromCode: function(error) { + if (GLEW.isLinaroFork) { + switch (error) { + case 4:return "OpenGL ES lib expected, found OpenGL lib"; // GLEW_ERROR_NOT_GLES_VERSION + case 5:return "OpenGL lib expected, found OpenGL ES lib"; // GLEW_ERROR_GLES_VERSION + case 6:return "Missing EGL version"; // GLEW_ERROR_NO_EGL_VERSION + case 7:return "EGL 1.1 and up are supported"; // GLEW_ERROR_EGL_VERSION_10_ONLY + default:break; + } + } + + switch (error) { + case 0:return "No error"; // GLEW_OK || GLEW_NO_ERROR + case 1:return "Missing GL version"; // GLEW_ERROR_NO_GL_VERSION + case 2:return "GL 1.1 and up are supported"; // GLEW_ERROR_GL_VERSION_10_ONLY + case 3:return "GLX 1.2 and up are supported"; // GLEW_ERROR_GLX_VERSION_11_ONLY + default:return null; + } + }, + + errorString: function(error) { + if (!GLEW.error[error]) { + var string = GLEW.errorStringConstantFromCode(error); + if (!string) { + string = "Unknown error"; + error = 8; // prevent array from growing more than this + } + GLEW.error[error] = allocate(intArrayFromString(string), 'i8', ALLOC_NORMAL); + } + return GLEW.error[error]; + }, + + versionStringConstantFromCode: function(name) { + switch (name) { + case 1:return "1.10.0"; // GLEW_VERSION + case 2:return "1"; // GLEW_VERSION_MAJOR + case 3:return "10"; // GLEW_VERSION_MINOR + case 4:return "0"; // GLEW_VERSION_MICRO + default:return null; + } + }, + + versionString: function(name) { + if (!GLEW.version[name]) { + var string = GLEW.versionStringConstantFromCode(name); + if (!string) + return 0; + GLEW.version[name] = allocate(intArrayFromString(string), 'i8', ALLOC_NORMAL); + } + return GLEW.version[name]; + }, + + extensionIsSupported: function(name) { + if (!GLEW.extensions) { + GLEW.extensions = Pointer_stringify(_glGetString(0x1F03)).split(' '); + } + + if (GLEW.extensions.indexOf(name) != -1) + return 1; + + // extensions from GLEmulations do not come unprefixed + // so, try with prefix + return (GLEW.extensions.indexOf("GL_" + name) != -1); + }, + }, + + glewInit: function() { return 0; }, + + glewIsSupported: function(name) { + var exts = Pointer_stringify(name).split(' '); + for (i in exts) { + if (!GLEW.extensionIsSupported(exts[i])) + return 0; + } + return 1; + }, + + glewGetExtension: function(name) { + return GLEW.extensionIsSupported(Pointer_stringify(name)); + }, + + glewGetErrorString: function(error) { + return GLEW.errorString(error); + }, + + glewGetString: function(name) { + return GLEW.versionString(name); + }, + +}; + +autoAddDeps(LibraryGLEW, '$GLEW'); +mergeInto(LibraryManager.library, LibraryGLEW); diff --git a/src/modules.js b/src/modules.js index c0b98f6f..ad467ba7 100644 --- a/src/modules.js +++ b/src/modules.js @@ -424,7 +424,7 @@ var LibraryManager = { load: function() { if (this.library) return; - var libraries = ['library.js', 'library_path.js', 'library_fs.js', 'library_idbfs.js', 'library_memfs.js', 'library_nodefs.js', 'library_sockfs.js', 'library_tty.js', 'library_browser.js', 'library_sdl.js', 'library_gl.js', 'library_glut.js', 'library_xlib.js', 'library_egl.js', 'library_gc.js', 'library_jansson.js', 'library_openal.js', 'library_glfw.js', 'library_uuid.js'].concat(additionalLibraries); + var libraries = ['library.js', 'library_path.js', 'library_fs.js', 'library_idbfs.js', 'library_memfs.js', 'library_nodefs.js', 'library_sockfs.js', 'library_tty.js', 'library_browser.js', 'library_sdl.js', 'library_gl.js', 'library_glut.js', 'library_xlib.js', 'library_egl.js', 'library_gc.js', 'library_jansson.js', 'library_openal.js', 'library_glfw.js', 'library_uuid.js', 'library_glew.js'].concat(additionalLibraries); for (var i = 0; i < libraries.length; i++) { eval(processMacros(preprocess(read(libraries[i])))); } |