1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
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);
|