Skip to content

Commit 129e0f0

Browse files
committed
Fix glDrawElements under CAN_ADDRESS_2GB
This is partially a workround for emscripten-core#21250
1 parent e279a10 commit 129e0f0

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,7 @@ jobs:
821821
browser_2gb.test_cubegeom
822822
browser_2gb.test_cubegeom_normal
823823
browser_2gb.test_cubegeom_normal_dap
824+
browser_2gb.test_cubegeom_normal_dap_far
824825
"
825826
test-browser-chrome-wasm64-4gb:
826827
executor: bionic

src/library_glemu.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2940,9 +2940,9 @@ var LibraryGLEmulation = {
29402940
// Detect which case we are in by using a quick heuristic by examining the
29412941
// strides of the buffers. If all the buffers have identical stride, we
29422942
// assume we have case (2), otherwise we have something more complex.
2943-
var clientStartPointer = 0x7FFFFFFF;
2943+
var clientStartPointer = {{{ POINTER_MAX }}};
29442944
var bytes = 0; // Total number of bytes taken up by a single vertex.
2945-
var minStride = 0x7FFFFFFF;
2945+
var minStride = {{{ POINTER_MAX }}};
29462946
var maxStride = 0;
29472947
var attributes = GLImmediate.liveClientAttributes;
29482948
attributes.length = 0;
@@ -3544,8 +3544,14 @@ var LibraryGLEmulation = {
35443544
GLImmediate.firstVertex = end ? start : HEAP8.length; // if we don't know the start, set an invalid value and we will calculate it later from the indices
35453545
GLImmediate.lastVertex = end ? end + 1 : 0;
35463546
start = GLImmediate.vertexPointer;
3547-
end = end ? GLImmediate.vertexPointer + (end+1)*GLImmediate.stride : undefined;
3548-
GLImmediate.vertexData = HEAPF32.subarray({{{ getHeapOffset('start', 'float') }}}, end ? {{{ getHeapOffset('end', 'float') }}} : undefined);
3547+
// TODO(sbc): Combine these two subarray calls back into a single one if
3548+
// we ever fix https://github.com/emscripten-core/emscripten/issues/21250.
3549+
if (end) {
3550+
end = GLImmediate.vertexPointer + (end +1 ) * GLImmediate.stride;
3551+
GLImmediate.vertexData = HEAPF32.subarray({{{ getHeapOffset('start', 'float') }}}, {{{ getHeapOffset('end', 'float') }}});
3552+
} else {
3553+
GLImmediate.vertexData = HEAPF32.subarray({{{ getHeapOffset('start', 'float') }}});
3554+
}
35493555
}
35503556
GLImmediate.flush(count, 0, indices);
35513557
GLImmediate.mode = -1;

src/parseTools.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ function needsQuoting(ident) {
176176
}
177177

178178
globalThis.POINTER_SIZE = MEMORY64 ? 8 : 4;
179+
globalThis.POINTER_MAX = MEMORY64 ? 'Number.MAX_SAFE_INTEGER' : '2**32';
179180
globalThis.STACK_ALIGN = 16;
180181
const POINTER_BITS = POINTER_SIZE * 8;
181182
const POINTER_TYPE = `u${POINTER_BITS}`;

0 commit comments

Comments
 (0)