Skip to content

Commit 3bca209

Browse files
authored
Minor formatting cleanup in src/library_glemu.js. NFC (#21249)
1 parent 7514cc2 commit 3bca209

File tree

1 file changed

+107
-91
lines changed

1 file changed

+107
-91
lines changed

src/library_glemu.js

Lines changed: 107 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,11 @@ var LibraryGLEmulation = {
144144
},
145145

146146
init() {
147-
// Do not activate immediate/emulation code (e.g. replace glDrawElements) when in FULL_ES2 mode.
148-
// We do not need full emulation, we instead emulate client-side arrays etc. in FULL_ES2 code in
149-
// a straightforward manner, and avoid not having a bound buffer be ambiguous between es2 emulation
150-
// code and legacy gl emulation code.
147+
// Do not activate immediate/emulation code (e.g. replace glDrawElements)
148+
// when in FULL_ES2 mode. We do not need full emulation, we instead
149+
// emulate client-side arrays etc. in FULL_ES2 code in a straightforward
150+
// manner, and avoid not having a bound buffer be ambiguous between es2
151+
// emulation code and legacy gl emulation code.
151152
#if FULL_ES2
152153
return;
153154
#endif
@@ -2898,35 +2899,47 @@ var LibraryGLEmulation = {
28982899
// count: number of elements we will draw
28992900
// beginEnd: whether we are drawing the results of a begin/end block
29002901
prepareClientAttributes(count, beginEnd) {
2901-
// If no client attributes were modified since we were last called, do nothing. Note that this
2902-
// does not work for glBegin/End, where we generate renderer components dynamically and then
2903-
// disable them ourselves, but it does help with glDrawElements/Arrays.
2902+
// If no client attributes were modified since we were last called, do
2903+
// nothing. Note that this does not work for glBegin/End, where we
2904+
// generate renderer components dynamically and then disable them
2905+
// ourselves, but it does help with glDrawElements/Arrays.
29042906
if (!GLImmediate.modifiedClientAttributes) {
29052907
#if GL_ASSERTIONS
29062908
if ((GLImmediate.stride & 3) != 0) {
2907-
warnOnce('Warning: Rendering from client side vertex arrays where stride (' + GLImmediate.stride + ') is not a multiple of four! This is not currently supported!');
2909+
warnOnce(`Warning: Rendering from client side vertex arrays where stride (${GLImmediate.stride}) is not a multiple of four! This is not currently supported!`);
29082910
}
29092911
#endif
29102912
GLImmediate.vertexCounter = (GLImmediate.stride * count) / 4; // XXX assuming float
29112913
return;
29122914
}
29132915
GLImmediate.modifiedClientAttributes = false;
29142916

2915-
// The role of prepareClientAttributes is to examine the set of client-side vertex attribute buffers
2916-
// that user code has submitted, and to prepare them to be uploaded to a VBO in GPU memory
2917-
// (since WebGL does not support client-side rendering, i.e. rendering from vertex data in CPU memory)
2918-
// User can submit vertex data generally in three different configurations:
2919-
// 1. Fully planar: all attributes are in their own separate tightly-packed arrays in CPU memory.
2920-
// 2. Fully interleaved: all attributes share a single array where data is interleaved something like (pos,uv,normal), (pos,uv,normal), ...
2921-
// 3. Complex hybrid: Multiple separate arrays that either are sparsely strided, and/or partially interleave vertex attributes.
2922-
2923-
// For simplicity, we support the case (2) as the fast case. For (1) and (3), we do a memory copy of the
2924-
// vertex data here to prepare a relayouted buffer that is of the structure in case (2). The reason
2925-
// for this is that it allows the emulation code to get away with using just one VBO buffer for rendering,
2926-
// and not have to maintain multiple ones. Therefore cases (1) and (3) will be very slow, and case (2) is fast.
2927-
2928-
// Detect which case we are in by using a quick heuristic by examining the strides of the buffers. If all the buffers have identical
2929-
// stride, we assume we have case (2), otherwise we have something more complex.
2917+
// The role of prepareClientAttributes is to examine the set of
2918+
// client-side vertex attribute buffers that user code has submitted, and
2919+
// to prepare them to be uploaded to a VBO in GPU memory (since WebGL does
2920+
// not support client-side rendering, i.e. rendering from vertex data in
2921+
// CPU memory). User can submit vertex data generally in three different
2922+
// configurations:
2923+
// 1. Fully planar: all attributes are in their own separate
2924+
// tightly-packed arrays in CPU memory.
2925+
// 2. Fully interleaved: all attributes share a single array where data is
2926+
// interleaved something like (pos,uv,normal),
2927+
// (pos,uv,normal), ...
2928+
// 3. Complex hybrid: Multiple separate arrays that either are sparsely
2929+
// strided, and/or partially interleaves vertex
2930+
// attributes.
2931+
2932+
// For simplicity, we support the case (2) as the fast case. For (1) and
2933+
// (3), we do a memory copy of the vertex data here to prepare a
2934+
// relayouted buffer that is of the structure in case (2). The reason
2935+
// for this is that it allows the emulation code to get away with using
2936+
// just one VBO buffer for rendering, and not have to maintain multiple
2937+
// ones. Therefore cases (1) and (3) will be very slow, and case (2) is
2938+
// fast.
2939+
2940+
// Detect which case we are in by using a quick heuristic by examining the
2941+
// strides of the buffers. If all the buffers have identical stride, we
2942+
// assume we have case (2), otherwise we have something more complex.
29302943
var clientStartPointer = 0x7FFFFFFF;
29312944
var bytes = 0; // Total number of bytes taken up by a single vertex.
29322945
var minStride = 0x7FFFFFFF;
@@ -2946,9 +2959,11 @@ var LibraryGLEmulation = {
29462959
}
29472960

29482961
if ((minStride != maxStride || maxStride < bytes) && !beginEnd) {
2949-
// We are in cases (1) or (3): slow path, shuffle the data around into a single interleaved vertex buffer.
2950-
// The immediate-mode glBegin()/glEnd() vertex submission gets automatically generated in appropriate layout,
2951-
// so never need to come down this path if that was used.
2962+
// We are in cases (1) or (3): slow path, shuffle the data around into a
2963+
// single interleaved vertex buffer.
2964+
// The immediate-mode glBegin()/glEnd() vertex submission gets
2965+
// automatically generated in appropriate layout, so never need to come
2966+
// down this path if that was used.
29522967
#if GL_ASSERTIONS
29532968
warnOnce('Rendering from planar client-side vertex arrays. This is a very slow emulation path! Use interleaved vertex arrays for best performance.');
29542969
#endif
@@ -3002,7 +3017,7 @@ var LibraryGLEmulation = {
30023017
if (!beginEnd) {
30033018
#if GL_ASSERTIONS
30043019
if ((GLImmediate.stride & 3) != 0) {
3005-
warnOnce('Warning: Rendering from client side vertex arrays where stride (' + GLImmediate.stride + ') is not a multiple of four! This is not currently supported!');
3020+
warnOnce(`Warning: Rendering from client side vertex arrays where stride (${GLImmediate.stride}) is not a multiple of four! This is not currently supported!`);
30063021
}
30073022
#endif
30083023
GLImmediate.vertexCounter = (GLImmediate.stride * count) / 4; // XXX assuming float
@@ -3053,13 +3068,14 @@ var LibraryGLEmulation = {
30533068
}
30543069
} else if (GLImmediate.mode > 6) { // above GL_TRIANGLE_FAN are the non-GL ES modes
30553070
if (GLImmediate.mode != 7) throw 'unsupported immediate mode ' + GLImmediate.mode; // GL_QUADS
3056-
// GLImmediate.firstVertex is the first vertex we want. Quad indexes are in the pattern
3057-
// 0 1 2, 0 2 3, 4 5 6, 4 6 7, so we need to look at index firstVertex * 1.5 to see it.
3058-
// Then since indexes are 2 bytes each, that means 3
3071+
// GLImmediate.firstVertex is the first vertex we want. Quad indexes are
3072+
// in the pattern 0 1 2, 0 2 3, 4 5 6, 4 6 7, so we need to look at
3073+
// index firstVertex * 1.5 to see it. Then since indexes are 2 bytes
3074+
// each, that means 3
30593075
#if ASSERTIONS
30603076
assert(GLImmediate.firstVertex % 4 == 0);
30613077
#endif
3062-
ptr = GLImmediate.firstVertex*3;
3078+
ptr = GLImmediate.firstVertex * 3;
30633079
var numQuads = numVertexes / 4;
30643080
numIndexes = numQuads * 6; // 0 1 2, 0 2 3 pattern
30653081
#if ASSERTIONS
@@ -3173,19 +3189,19 @@ var LibraryGLEmulation = {
31733189
},
31743190

31753191
glVertex2fv__deps: ['glVertex2f'],
3176-
glVertex2fv: (p) => {
3177-
_glVertex2f({{{ makeGetValue('p', '0', 'float') }}}, {{{ makeGetValue('p', '4', 'float') }}});
3178-
},
3192+
glVertex2fv: (p) => _glVertex2f({{{ makeGetValue('p', '0', 'float') }}},
3193+
{{{ makeGetValue('p', '4', 'float') }}}),
31793194

31803195
glVertex3fv__deps: ['glVertex3f'],
3181-
glVertex3fv: (p) => {
3182-
_glVertex3f({{{ makeGetValue('p', '0', 'float') }}}, {{{ makeGetValue('p', '4', 'float') }}}, {{{ makeGetValue('p', '8', 'float') }}});
3183-
},
3196+
glVertex3fv: (p) => _glVertex3f({{{ makeGetValue('p', '0', 'float') }}},
3197+
{{{ makeGetValue('p', '4', 'float') }}},
3198+
{{{ makeGetValue('p', '8', 'float') }}}),
31843199

31853200
glVertex4fv__deps: ['glVertex4f'],
3186-
glVertex4fv: (p) => {
3187-
_glVertex4f({{{ makeGetValue('p', '0', 'float') }}}, {{{ makeGetValue('p', '4', 'float') }}}, {{{ makeGetValue('p', '8', 'float') }}}, {{{ makeGetValue('p', '12', 'float') }}});
3188-
},
3201+
glVertex4fv: (p) => _glVertex4f({{{ makeGetValue('p', '0', 'float') }}},
3202+
{{{ makeGetValue('p', '4', 'float') }}},
3203+
{{{ makeGetValue('p', '8', 'float') }}},
3204+
{{{ makeGetValue('p', '12', 'float') }}}),
31893205

31903206
glVertex2i: 'glVertex2f',
31913207

@@ -3204,9 +3220,8 @@ var LibraryGLEmulation = {
32043220
glTexCoord2f: 'glTexCoord2i',
32053221

32063222
glTexCoord2fv__deps: ['glTexCoord2i'],
3207-
glTexCoord2fv: (v) => {
3208-
_glTexCoord2i({{{ makeGetValue('v', '0', 'float') }}}, {{{ makeGetValue('v', '4', 'float') }}});
3209-
},
3223+
glTexCoord2fv: (v) =>
3224+
_glTexCoord2i({{{ makeGetValue('v', '0', 'float') }}}, {{{ makeGetValue('v', '4', 'float') }}}),
32103225

32113226
glTexCoord4f: () => { throw 'glTexCoord4f: TODO' },
32123227

@@ -3239,60 +3254,59 @@ var LibraryGLEmulation = {
32393254
glColor4d: 'glColor4f',
32403255

32413256
glColor4ub__deps: ['glColor4f'],
3242-
glColor4ub: (r, g, b, a) => {
3243-
_glColor4f((r&255)/255, (g&255)/255, (b&255)/255, (a&255)/255);
3244-
},
3257+
glColor4ub: (r, g, b, a) => _glColor4f((r&255)/255, (g&255)/255, (b&255)/255, (a&255)/255),
3258+
32453259
glColor4us__deps: ['glColor4f'],
3246-
glColor4us: (r, g, b, a) => {
3247-
_glColor4f((r&65535)/65535, (g&65535)/65535, (b&65535)/65535, (a&65535)/65535);
3248-
},
3260+
glColor4us: (r, g, b, a) => _glColor4f((r&65535)/65535, (g&65535)/65535, (b&65535)/65535, (a&65535)/65535),
3261+
32493262
glColor4ui__deps: ['glColor4f'],
3250-
glColor4ui: (r, g, b, a) => {
3251-
_glColor4f((r>>>0)/4294967295, (g>>>0)/4294967295, (b>>>0)/4294967295, (a>>>0)/4294967295);
3252-
},
3263+
glColor4ui: (r, g, b, a) => _glColor4f((r>>>0)/4294967295, (g>>>0)/4294967295, (b>>>0)/4294967295, (a>>>0)/4294967295),
3264+
32533265
glColor3f__deps: ['glColor4f'],
3254-
glColor3f: (r, g, b) => {
3255-
_glColor4f(r, g, b, 1);
3256-
},
3266+
glColor3f: (r, g, b) => _glColor4f(r, g, b, 1),
3267+
32573268
glColor3d: 'glColor3f',
3269+
32583270
glColor3ub__deps: ['glColor4ub'],
3259-
glColor3ub: (r, g, b) => {
3260-
_glColor4ub(r, g, b, 255);
3261-
},
3271+
glColor3ub: (r, g, b) => _glColor4ub(r, g, b, 255),
3272+
32623273
glColor3us__deps: ['glColor4us'],
3263-
glColor3us: (r, g, b) => {
3264-
_glColor4us(r, g, b, 65535);
3265-
},
3274+
glColor3us: (r, g, b) => _glColor4us(r, g, b, 65535),
3275+
32663276
glColor3ui__deps: ['glColor4ui'],
3267-
glColor3ui: (r, g, b) => {
3268-
_glColor4ui(r, g, b, 4294967295);
3269-
},
3277+
glColor3ui: (r, g, b) => _glColor4ui(r, g, b, 4294967295),
32703278

32713279
glColor3ubv__deps: ['glColor3ub'],
3272-
glColor3ubv: (p) => {
3273-
_glColor3ub({{{ makeGetValue('p', '0', 'i8') }}}, {{{ makeGetValue('p', '1', 'i8') }}}, {{{ makeGetValue('p', '2', 'i8') }}});
3274-
},
3280+
glColor3ubv: (p) => _glColor3ub({{{ makeGetValue('p', '0', 'i8') }}},
3281+
{{{ makeGetValue('p', '1', 'i8') }}},
3282+
{{{ makeGetValue('p', '2', 'i8') }}}),
3283+
32753284
glColor3usv__deps: ['glColor3us'],
3276-
glColor3usv: (p) => {
3277-
_glColor3us({{{ makeGetValue('p', '0', 'i16') }}}, {{{ makeGetValue('p', '2', 'i16') }}}, {{{ makeGetValue('p', '4', 'i16') }}});
3278-
},
3285+
glColor3usv: (p) => _glColor3us({{{ makeGetValue('p', '0', 'i16') }}},
3286+
{{{ makeGetValue('p', '2', 'i16') }}},
3287+
{{{ makeGetValue('p', '4', 'i16') }}}),
3288+
32793289
glColor3uiv__deps: ['glColor3ui'],
3280-
glColor3uiv: (p) => {
3281-
_glColor3ui({{{ makeGetValue('p', '0', 'i32') }}}, {{{ makeGetValue('p', '4', 'i32') }}}, {{{ makeGetValue('p', '8', 'i32') }}});
3282-
},
3290+
glColor3uiv: (p) => _glColor3ui({{{ makeGetValue('p', '0', 'i32') }}},
3291+
{{{ makeGetValue('p', '4', 'i32') }}},
3292+
{{{ makeGetValue('p', '8', 'i32') }}}),
3293+
32833294
glColor3fv__deps: ['glColor3f'],
3284-
glColor3fv: (p) => {
3285-
_glColor3f({{{ makeGetValue('p', '0', 'float') }}}, {{{ makeGetValue('p', '4', 'float') }}}, {{{ makeGetValue('p', '8', 'float') }}});
3286-
},
3295+
glColor3fv: (p) => _glColor3f({{{ makeGetValue('p', '0', 'float') }}},
3296+
{{{ makeGetValue('p', '4', 'float') }}},
3297+
{{{ makeGetValue('p', '8', 'float') }}}),
3298+
32873299
glColor4fv__deps: ['glColor4f'],
3288-
glColor4fv: (p) => {
3289-
_glColor4f({{{ makeGetValue('p', '0', 'float') }}}, {{{ makeGetValue('p', '4', 'float') }}}, {{{ makeGetValue('p', '8', 'float') }}}, {{{ makeGetValue('p', '12', 'float') }}});
3290-
},
3300+
glColor4fv: (p) => _glColor4f({{{ makeGetValue('p', '0', 'float') }}},
3301+
{{{ makeGetValue('p', '4', 'float') }}},
3302+
{{{ makeGetValue('p', '8', 'float') }}},
3303+
{{{ makeGetValue('p', '12', 'float') }}}),
32913304

32923305
glColor4ubv__deps: ['glColor4ub'],
3293-
glColor4ubv: (p) => {
3294-
_glColor4ub({{{ makeGetValue('p', '0', 'i8') }}}, {{{ makeGetValue('p', '1', 'i8') }}}, {{{ makeGetValue('p', '2', 'i8') }}}, {{{ makeGetValue('p', '3', 'i8') }}});
3295-
},
3306+
glColor4ubv: (p) => _glColor4ub({{{ makeGetValue('p', '0', 'i8') }}},
3307+
{{{ makeGetValue('p', '1', 'i8') }}},
3308+
{{{ makeGetValue('p', '2', 'i8') }}},
3309+
{{{ makeGetValue('p', '3', 'i8') }}}),
32963310

32973311
glFogf: (pname, param) => { // partial support, TODO
32983312
switch (pname) {
@@ -3493,9 +3507,9 @@ var LibraryGLEmulation = {
34933507
GLImmediate.clientActiveTexture = texture - 0x84C0; // GL_TEXTURE0
34943508
},
34953509

3496-
// Replace some functions with immediate-mode aware versions. If there are no client
3497-
// attributes enabled, and we use webgl-friendly modes (no GL_QUADS), then no need
3498-
// for emulation
3510+
// Replace some functions with immediate-mode aware versions. If there are no
3511+
// client attributes enabled, and we use webgl-friendly modes (no GL_QUADS),
3512+
// then no need for emulation
34993513
glDrawArrays: (mode, first, count) => {
35003514
if (GLImmediate.totalEnabledClientAttributes == 0 && mode <= 6) {
35013515
GLctx.drawArrays(mode, first, count);
@@ -3512,7 +3526,8 @@ var LibraryGLEmulation = {
35123526
GLImmediate.mode = -1;
35133527
},
35143528

3515-
glDrawElements: (mode, count, type, indices, start, end) => { // start, end are given if we come from glDrawRangeElements
3529+
// start, end are given if we come from glDrawRangeElements
3530+
glDrawElements: (mode, count, type, indices, start, end) => {
35163531
if (GLImmediate.totalEnabledClientAttributes == 0 && mode <= 6 && GLctx.currentElementArrayBufferBinding) {
35173532
GLctx.drawElements(mode, count, type, indices);
35183533
return;
@@ -3534,7 +3549,8 @@ var LibraryGLEmulation = {
35343549
GLImmediate.mode = -1;
35353550
},
35363551

3537-
// Vertex array object (VAO) support. TODO: when the WebGL extension is popular, use that and remove this code and GL.vaos
3552+
// Vertex array object (VAO) support. TODO: when the WebGL extension is
3553+
// popular, use that and remove this code and GL.vaos
35383554
$emulGlGenVertexArrays__deps: ['$GLEmulation'],
35393555
$emulGlGenVertexArrays: (n, vaos) => {
35403556
for (var i = 0; i < n; i++) {
@@ -3606,7 +3622,7 @@ var LibraryGLEmulation = {
36063622
GLImmediate.useTextureMatrix = true;
36073623
GLImmediate.currentMatrix = 2/*t*/ + GLImmediate.TexEnvJIT.getActiveTexture();
36083624
} else {
3609-
throw "Wrong mode " + mode + " passed to glMatrixMode";
3625+
throw `Wrong mode ${mode} passed to glMatrixMode`;
36103626
}
36113627
},
36123628

@@ -3833,9 +3849,9 @@ var LibraryGLEmulation = {
38333849

38343850
glTexGeni: (coord, pname, param) => { throw 'glTexGeni: TODO' },
38353851
glTexGenfv: (coord, pname, param) => { throw 'glTexGenfv: TODO' },
3836-
glTexEnvi: (target, pname, params) => { warnOnce('glTexEnvi: TODO') },
3837-
glTexEnvf: (target, pname, params) => { warnOnce('glTexEnvf: TODO') },
3838-
glTexEnvfv: (target, pname, params) => { warnOnce('glTexEnvfv: TODO') },
3852+
glTexEnvi: (target, pname, params) => warnOnce('glTexEnvi: TODO'),
3853+
glTexEnvf: (target, pname, params) => warnOnce('glTexEnvf: TODO'),
3854+
glTexEnvfv: (target, pname, params) => warnOnce('glTexEnvfv: TODO'),
38393855

38403856
glGetTexEnviv: (target, pname, param) => { throw 'GL emulation not initialized!'; },
38413857
glGetTexEnvfv: (target, pname, param) => { throw 'GL emulation not initialized!'; },

0 commit comments

Comments
 (0)