Skip to content

Commit c3f9ac2

Browse files
authored
Minor cleanups to GL passthrough function handling. NFC (#19023)
1 parent 058fa51 commit c3f9ac2

File tree

2 files changed

+32
-33
lines changed

2 files changed

+32
-33
lines changed

src/library_webgl.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4172,18 +4172,18 @@ var LibraryGL = {
41724172
glFrontFace__sig: 'vi',
41734173
};
41744174

4175-
// Simple pass-through functions. Starred ones have return values. [X] ones have X in the C name but not in the JS name
4176-
var glFuncs = [[0, 'finish flush'],
4177-
[1, 'clearDepth clearDepth[f] depthFunc enable disable frontFace cullFace clear lineWidth clearStencil stencilMask checkFramebufferStatus* generateMipmap activeTexture blendEquation isEnabled*'],
4178-
[2, 'blendFunc blendEquationSeparate depthRange depthRange[f] stencilMaskSeparate hint polygonOffset vertexAttrib1f'],
4179-
[3, 'texParameteri texParameterf vertexAttrib2f stencilFunc stencilOp'],
4180-
[4, 'viewport clearColor scissor vertexAttrib3f renderbufferStorage blendFuncSeparate blendColor stencilFuncSeparate stencilOpSeparate'],
4181-
[5, 'vertexAttrib4f'],
4182-
[6, ''],
4183-
[7, ''],
4184-
[8, 'copyTexImage2D copyTexSubImage2D'],
4185-
[9, ''],
4186-
[10, '']];
4175+
// Simple pass-through functions.
4176+
// - Starred ones have return values.
4177+
// - [X] ones have X in the C name but not in the JS name
4178+
var glPassthroughFuncs = [
4179+
[0, 'finish flush'],
4180+
[1, 'clearDepth clearDepth[f] depthFunc enable disable frontFace cullFace clear lineWidth clearStencil stencilMask checkFramebufferStatus* generateMipmap activeTexture blendEquation isEnabled*'],
4181+
[2, 'blendFunc blendEquationSeparate depthRange depthRange[f] stencilMaskSeparate hint polygonOffset vertexAttrib1f'],
4182+
[3, 'texParameteri texParameterf vertexAttrib2f stencilFunc stencilOp'],
4183+
[4, 'viewport clearColor scissor vertexAttrib3f renderbufferStorage blendFuncSeparate blendColor stencilFuncSeparate stencilOpSeparate'],
4184+
[5, 'vertexAttrib4f'],
4185+
[8, 'copyTexImage2D copyTexSubImage2D'],
4186+
];
41874187

41884188
function createGLPassthroughFunctions(lib, funcs) {
41894189
funcs.forEach((data) => {
@@ -4194,11 +4194,10 @@ function createGLPassthroughFunctions(lib, funcs) {
41944194
const returnStub = '(function(' + args + ') { return GLctx[\'NAME\'](' + args + ') })';
41954195
const sigEnd = range(num).map(() => 'i').join('');
41964196
names.split(' ').forEach((name) => {
4197-
if (name.length == 0) return;
41984197
let stub = plainStub;
41994198
let sig;
4200-
if (name[name.length-1] == '*') {
4201-
name = name.substr(0, name.length-1);
4199+
if (name.endsWith('*')) {
4200+
name = name.slice(0, -1);
42024201
stub = returnStub;
42034202
sig = 'i' + sigEnd;
42044203
} else {
@@ -4207,7 +4206,7 @@ function createGLPassthroughFunctions(lib, funcs) {
42074206
let cName = name;
42084207
if (name.includes('[')) {
42094208
cName = name.replace('[', '').replace(']', '');
4210-
name = cName.substr(0, cName.length-1);
4209+
name = cName.slice(0, -1);
42114210
}
42124211
cName = 'gl' + cName[0].toUpperCase() + cName.substr(1);
42134212
assert(!(cName in lib), "Cannot reimplement the existing function " + cName);
@@ -4217,7 +4216,7 @@ function createGLPassthroughFunctions(lib, funcs) {
42174216
});
42184217
}
42194218

4220-
createGLPassthroughFunctions(LibraryGL, glFuncs);
4219+
createGLPassthroughFunctions(LibraryGL, glPassthroughFuncs);
42214220

42224221
autoAddDeps(LibraryGL, '$GL');
42234222

src/library_webgl2.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,28 +1116,28 @@ var LibraryWebGL2 = {
11161116
glClearBufferfi__sig: 'viifi',
11171117
};
11181118

1119-
// Simple pass-through functions. Starred ones have return values. [X] ones have X in the C name but not in the JS name
1120-
var webgl2Funcs = [[0, 'endTransformFeedback pauseTransformFeedback resumeTransformFeedback'],
1121-
[1, 'beginTransformFeedback readBuffer endQuery'],
1122-
[2, ''],
1123-
[3, ''],
1124-
[4, 'clearBufferfi'],
1125-
[5, 'vertexAttribI4i vertexAttribI4ui copyBufferSubData texStorage2D renderbufferStorageMultisample'],
1126-
[6, 'texStorage3D'],
1127-
[7, ''],
1128-
[8, ''],
1129-
[9, 'copyTexSubImage3D'],
1130-
[10, 'blitFramebuffer']];
1131-
11321119
#if MAX_WEBGL_VERSION >= 2
11331120

1134-
// If user passes -sMAX_WEBGL_VERSION >= 2 -sSTRICT but not -lGL (to link in WebGL 1), then WebGL2 library should not
1135-
// be linked in as well.
1121+
// Simple pass-through functions.
1122+
// - Starred ones have return values.
1123+
// - [X] ones have X in the C name but not in the JS name
1124+
var webgl2PassthroughFuncs = [
1125+
[0, 'endTransformFeedback pauseTransformFeedback resumeTransformFeedback'],
1126+
[1, 'beginTransformFeedback readBuffer endQuery'],
1127+
[4, 'clearBufferfi'],
1128+
[5, 'vertexAttribI4i vertexAttribI4ui copyBufferSubData texStorage2D renderbufferStorageMultisample'],
1129+
[6, 'texStorage3D'],
1130+
[9, 'copyTexSubImage3D'],
1131+
[10, 'blitFramebuffer']
1132+
];
1133+
1134+
// If user passes -sMAX_WEBGL_VERSION >= 2 -sSTRICT but not -lGL (to link in
1135+
// WebGL 1), then WebGL2 library should not be linked in as well.
11361136
if (typeof createGLPassthroughFunctions == 'undefined') {
11371137
throw 'In order to use WebGL 2 in strict mode with -sMAX_WEBGL_VERSION=2, you need to link in WebGL support with -lGL!';
11381138
}
11391139

1140-
createGLPassthroughFunctions(LibraryWebGL2, webgl2Funcs);
1140+
createGLPassthroughFunctions(LibraryWebGL2, webgl2PassthroughFuncs);
11411141

11421142
recordGLProcAddressGet(LibraryWebGL2);
11431143

0 commit comments

Comments
 (0)