Skip to content

Commit a39788f

Browse files
committed
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
1 parent 0e36f07 commit a39788f

6 files changed

Lines changed: 1029 additions & 5 deletions

File tree

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,4 @@ a license to everyone to use it as detailed in LICENSE.)
117117
* Andre Weissflog <[email protected]>
118118
* Alexandre Perrot <[email protected]>
119119
* Emerson José Silveira da Costa <[email protected]>
120+
* Jari Vetoniemi <[email protected]>

src/library_glew.js

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/*******************************************************************************
2+
* EMSCRIPTEN GLEW 1.10.0 emulation
3+
*
4+
* What it does:
5+
* - Stubs init function.
6+
* - GL Extensions support.
7+
*
8+
* Optional:
9+
* - isLinaroFork variable to enable glew-es specific error strings.
10+
* This is enabled by default, but should be disabled when upstream glew conflicts.
11+
*
12+
* Authors:
13+
* - Jari Vetoniemi <[email protected]>
14+
******************************************************************************/
15+
16+
var LibraryGLEW = {
17+
$GLEW__deps: ['glGetString'],
18+
$GLEW: {
19+
isLinaroFork: 1,
20+
extensions: null,
21+
22+
error: {
23+
0:null, // GLEW_OK || GLEW_NO_ERROR
24+
1:null, // GLEW_ERROR_NO_GL_VERSION
25+
2:null, // GLEW_ERROR_GL_VERSION_10_ONLY
26+
3:null, // GLEW_ERROR_GLX_VERSION_11_ONLY
27+
28+
4:null, // GLEW_ERROR_NOT_GLES_VERSION
29+
5:null, // GLEW_ERROR_GLES_VERSION
30+
6:null, // GLEW_ERROR_NO_EGL_VERSION
31+
7:null, // GLEW_ERROR_EGL_VERSION_10_ONLY
32+
33+
8:null, // Unknown error
34+
},
35+
36+
version: {
37+
1:null, // GLEW_VERSION
38+
2:null, // GLEW_VERSION_MAJOR
39+
3:null, // GLEW_VERSION_MINOR
40+
4:null, // GLEW_VERSION_MICRO
41+
},
42+
43+
errorStringConstantFromCode: function(error) {
44+
if (GLEW.isLinaroFork) {
45+
switch (error) {
46+
case 4:return "OpenGL ES lib expected, found OpenGL lib"; // GLEW_ERROR_NOT_GLES_VERSION
47+
case 5:return "OpenGL lib expected, found OpenGL ES lib"; // GLEW_ERROR_GLES_VERSION
48+
case 6:return "Missing EGL version"; // GLEW_ERROR_NO_EGL_VERSION
49+
case 7:return "EGL 1.1 and up are supported"; // GLEW_ERROR_EGL_VERSION_10_ONLY
50+
default:break;
51+
}
52+
}
53+
54+
switch (error) {
55+
case 0:return "No error"; // GLEW_OK || GLEW_NO_ERROR
56+
case 1:return "Missing GL version"; // GLEW_ERROR_NO_GL_VERSION
57+
case 2:return "GL 1.1 and up are supported"; // GLEW_ERROR_GL_VERSION_10_ONLY
58+
case 3:return "GLX 1.2 and up are supported"; // GLEW_ERROR_GLX_VERSION_11_ONLY
59+
default:return null;
60+
}
61+
},
62+
63+
errorString: function(error) {
64+
if (!GLEW.error[error]) {
65+
var string = GLEW.errorStringConstantFromCode(error);
66+
if (!string) {
67+
string = "Unknown error";
68+
error = 8; // prevent array from growing more than this
69+
}
70+
GLEW.error[error] = allocate(intArrayFromString(string), 'i8', ALLOC_NORMAL);
71+
}
72+
return GLEW.error[error];
73+
},
74+
75+
versionStringConstantFromCode: function(name) {
76+
switch (name) {
77+
case 1:return "1.10.0"; // GLEW_VERSION
78+
case 2:return "1"; // GLEW_VERSION_MAJOR
79+
case 3:return "10"; // GLEW_VERSION_MINOR
80+
case 4:return "0"; // GLEW_VERSION_MICRO
81+
default:return null;
82+
}
83+
},
84+
85+
versionString: function(name) {
86+
if (!GLEW.version[name]) {
87+
var string = GLEW.versionStringConstantFromCode(name);
88+
if (!string)
89+
return 0;
90+
GLEW.version[name] = allocate(intArrayFromString(string), 'i8', ALLOC_NORMAL);
91+
}
92+
return GLEW.version[name];
93+
},
94+
95+
extensionIsSupported: function(name) {
96+
if (!GLEW.extensions) {
97+
GLEW.extensions = Pointer_stringify(_glGetString(0x1F03)).split(' ');
98+
}
99+
100+
if (GLEW.extensions.indexOf(name) != -1)
101+
return 1;
102+
103+
// extensions from GLEmulations do not come unprefixed
104+
// so, try with prefix
105+
return (GLEW.extensions.indexOf("GL_" + name) != -1);
106+
},
107+
},
108+
109+
glewInit: function() { return 0; },
110+
111+
glewIsSupported: function(name) {
112+
var exts = Pointer_stringify(name).split(' ');
113+
for (i in exts) {
114+
if (!GLEW.extensionIsSupported(exts[i]))
115+
return 0;
116+
}
117+
return 1;
118+
},
119+
120+
glewGetExtension: function(name) {
121+
return GLEW.extensionIsSupported(Pointer_stringify(name));
122+
},
123+
124+
glewGetErrorString: function(error) {
125+
return GLEW.errorString(error);
126+
},
127+
128+
glewGetString: function(name) {
129+
return GLEW.versionString(name);
130+
},
131+
132+
};
133+
134+
autoAddDeps(LibraryGLEW, '$GLEW');
135+
mergeInto(LibraryManager.library, LibraryGLEW);

src/modules.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ var LibraryManager = {
424424
load: function() {
425425
if (this.library) return;
426426

427-
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);
427+
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);
428428
for (var i = 0; i < libraries.length; i++) {
429429
eval(processMacros(preprocess(read(libraries[i]))));
430430
}

0 commit comments

Comments
 (0)