Skip to content

Commit 165133b

Browse files
authored
Minor library_webgl.js cleanup (#21457)
Split out from #21445
1 parent cbb7a11 commit 165133b

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

src/library_webgl.js

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
assert(MAX_WEBGL_VERSION >= 2, 'isCurrentContextWebGL2 called without webgl2 support');
1515
if (MIN_WEBGL_VERSION >= 2) return 'true';
1616
return 'GL.currentContext.version >= 2';
17-
}
17+
};
1818
null;
1919
}}}
2020

@@ -1677,14 +1677,11 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
16771677
} else if (pixels) {
16781678
var heap = heapObjectForWebGLType(type);
16791679
GLctx.texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, heap, toTypedArrayIndex(pixels, heap));
1680-
} else {
1681-
GLctx.texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, null);
1680+
return;
16821681
}
1683-
return;
16841682
}
16851683
#endif
1686-
var pixelData = null;
1687-
if (pixels) pixelData = emscriptenWebGLGetTexPixelData(type, format, width, height, pixels, 0);
1684+
var pixelData = pixels ? emscriptenWebGLGetTexPixelData(type, format, width, height, pixels, 0) : null;
16881685
GLctx.texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixelData);
16891686
},
16901687

@@ -1855,16 +1852,14 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
18551852
} else {
18561853
GLctx.bufferData(target, size, usage);
18571854
}
1858-
} else {
1859-
#endif
1860-
// N.b. here first form specifies a heap subarray, second form an integer
1861-
// size, so the ?: code here is polymorphic. It is advised to avoid
1862-
// randomly mixing both uses in calling code, to avoid any potential JS
1863-
// engine JIT issues.
1864-
GLctx.bufferData(target, data ? HEAPU8.subarray(data, data+size) : size, usage);
1865-
#if MAX_WEBGL_VERSION >= 2
1855+
return;
18661856
}
18671857
#endif
1858+
// N.b. here first form specifies a heap subarray, second form an integer
1859+
// size, so the ?: code here is polymorphic. It is advised to avoid
1860+
// randomly mixing both uses in calling code, to avoid any potential JS
1861+
// engine JIT issues.
1862+
GLctx.bufferData(target, data ? HEAPU8.subarray(data, data+size) : size, usage);
18681863
},
18691864

18701865
glBufferSubData: (target, offset, size, data) => {
@@ -3813,8 +3808,8 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
38133808
buf = GL.getTempIndexBuffer(size);
38143809
GLctx.bindBuffer(0x8893 /*GL_ELEMENT_ARRAY_BUFFER*/, buf);
38153810
GLctx.bufferSubData(0x8893 /*GL_ELEMENT_ARRAY_BUFFER*/,
3816-
0,
3817-
HEAPU8.subarray(indices, indices + size));
3811+
0,
3812+
HEAPU8.subarray(indices, indices + size));
38183813
// the index is now 0
38193814
indices = 0;
38203815
}
@@ -4159,12 +4154,13 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
41594154
return 0;
41604155
}
41614156

4162-
if (!(mapping.access & 0x10)) /* GL_MAP_FLUSH_EXPLICIT_BIT */
4157+
if (!(mapping.access & 0x10)) { /* GL_MAP_FLUSH_EXPLICIT_BIT */
41634158
if ({{{ isCurrentContextWebGL2() }}}) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
41644159
GLctx.bufferSubData(target, mapping.offset, HEAPU8, mapping.mem, mapping.length);
41654160
} else {
41664161
GLctx.bufferSubData(target, mapping.offset, HEAPU8.subarray(mapping.mem, mapping.mem+mapping.length));
41674162
}
4163+
}
41684164
_free(mapping.mem);
41694165
mapping.mem = 0;
41704166
return 1;

0 commit comments

Comments
 (0)