Skip to content

Commit f89e972

Browse files
authored
Move __glGenObject to GL.genObject. NFC (#21302)
This function logically belongs alongside getNewId. Split out from #18874
1 parent 01d0fc4 commit f89e972

9 files changed

+46
-55
lines changed

src/library_webgl.js

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,34 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
309309
return ret;
310310
},
311311

312+
// The code path for creating textures, buffers, framebuffers and other
313+
// objects the same (and not in fast path), so we merge the functions
314+
// together.
315+
// 'createFunction' refers to the WebGL context function name to do the actual
316+
// creation, 'objectTable' points to the GL object table where to populate the
317+
// created objects, and 'functionName' carries the name of the caller for
318+
// debug information.
319+
genObject: (n, buffers, createFunction, objectTable
320+
#if GL_ASSERTIONS
321+
, functionName
322+
#endif
323+
) => {
324+
for (var i = 0; i < n; i++) {
325+
var buffer = GLctx[createFunction]();
326+
var id = buffer && GL.getNewId(objectTable);
327+
if (buffer) {
328+
buffer.name = id;
329+
objectTable[id] = buffer;
330+
} else {
331+
GL.recordError(0x502 /* GL_INVALID_OPERATION */);
332+
#if GL_ASSERTIONS
333+
err(`GL_INVALID_OPERATION in ${functionName}: GLctx.${createFunction} returned null - most likely GL context is lost!`);
334+
#endif
335+
}
336+
{{{ makeSetValue('buffers', 'i*4', 'id', 'i32') }}};
337+
}
338+
},
339+
312340
#if FULL_ES2 || LEGACY_GL_EMULATION
313341
// When user GL code wants to render from client-side memory, we need to
314342
// upload the vertex data to a temp VBO for rendering. Maintain a set of
@@ -1770,46 +1798,16 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
17701798
return GLctx.isTexture(texture);
17711799
},
17721800

1773-
// The code path for creating textures, buffers, framebuffers and other
1774-
// objects is so identical to each other (and not in fast path), that merge
1775-
// the functions together to only have one generated copy of this.
1776-
// 'createFunction' refers to the WebGL context function name to do the actual
1777-
// creation, 'objectTable' points to the GL object table where to populate the
1778-
// created objects, and 'functionName' carries the name of the caller for
1779-
// debug information.
1780-
$__glGenObject: (n, buffers, createFunction, objectTable
1781-
#if GL_ASSERTIONS
1782-
, functionName
1783-
#endif
1784-
) => {
1785-
for (var i = 0; i < n; i++) {
1786-
var buffer = GLctx[createFunction]();
1787-
var id = buffer && GL.getNewId(objectTable);
1788-
if (buffer) {
1789-
buffer.name = id;
1790-
objectTable[id] = buffer;
1791-
} else {
1792-
GL.recordError(0x502 /* GL_INVALID_OPERATION */);
1793-
#if GL_ASSERTIONS
1794-
err(`GL_INVALID_OPERATION in ${functionName}: GLctx.${createFunction} returned null - most likely GL context is lost!`);
1795-
#endif
1796-
}
1797-
{{{ makeSetValue('buffers', 'i*4', 'id', 'i32') }}};
1798-
}
1799-
},
1800-
1801-
glGenBuffers__deps: ['$__glGenObject'],
18021801
glGenBuffers: (n, buffers) => {
1803-
__glGenObject(n, buffers, 'createBuffer', GL.buffers
1802+
GL.genObject(n, buffers, 'createBuffer', GL.buffers
18041803
#if GL_ASSERTIONS
18051804
, 'glGenBuffers'
18061805
#endif
18071806
);
18081807
},
18091808

1810-
glGenTextures__deps: ['$__glGenObject'],
18111809
glGenTextures: (n, textures) => {
1812-
__glGenObject(n, textures, 'createTexture', GL.textures
1810+
GL.genObject(n, textures, 'createTexture', GL.textures
18131811
#if GL_ASSERTIONS
18141812
, 'glGenTextures'
18151813
#endif
@@ -2055,9 +2053,8 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
20552053
return GLctx.isBuffer(b);
20562054
},
20572055

2058-
glGenRenderbuffers__deps: ['$__glGenObject'],
20592056
glGenRenderbuffers: (n, renderbuffers) => {
2060-
__glGenObject(n, renderbuffers, 'createRenderbuffer', GL.renderbuffers
2057+
GL.genObject(n, renderbuffers, 'createRenderbuffer', GL.renderbuffers
20612058
#if GL_ASSERTIONS
20622059
, 'glGenRenderbuffers'
20632060
#endif
@@ -3627,9 +3624,8 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
36273624

36283625
},
36293626

3630-
glGenFramebuffers__deps: ['$__glGenObject'],
36313627
glGenFramebuffers: (n, ids) => {
3632-
__glGenObject(n, ids, 'createFramebuffer', GL.framebuffers
3628+
GL.genObject(n, ids, 'createFramebuffer', GL.framebuffers
36333629
#if GL_ASSERTIONS
36343630
, 'glGenFramebuffers'
36353631
#endif
@@ -3678,19 +3674,17 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
36783674
return GLctx.isFramebuffer(fb);
36793675
},
36803676

3681-
glGenVertexArrays__deps: ['$__glGenObject'
36823677
#if LEGACY_GL_EMULATION
3683-
, '$emulGlGenVertexArrays'
3678+
glGenVertexArrays__deps: ['$emulGlGenVertexArrays'],
36843679
#endif
3685-
],
36863680
glGenVertexArrays: (n, arrays) => {
36873681
#if LEGACY_GL_EMULATION
36883682
emulGlGenVertexArrays(n, arrays);
36893683
#else
36903684
#if GL_ASSERTIONS
36913685
assert(GLctx.createVertexArray, 'Must have WebGL2 or OES_vertex_array_object to use vao');
36923686
#endif
3693-
__glGenObject(n, arrays, 'createVertexArray', GL.vaos
3687+
GL.genObject(n, arrays, 'createVertexArray', GL.vaos
36943688
#if GL_ASSERTIONS
36953689
, 'glGenVertexArrays'
36963690
#endif

src/library_webgl2.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,8 @@ var LibraryWebGL2 = {
172172
},
173173

174174
// Queries
175-
glGenQueries__deps: ['$__glGenObject'],
176175
glGenQueries: (n, ids) => {
177-
__glGenObject(n, ids, 'createQuery', GL.queries
176+
GL.genObject(n, ids, 'createQuery', GL.queries
178177
#if GL_ASSERTIONS
179178
, 'glGenQueries'
180179
#endif
@@ -246,9 +245,8 @@ var LibraryWebGL2 = {
246245
},
247246

248247
// Sampler objects
249-
glGenSamplers__deps: ['$__glGenObject'],
250248
glGenSamplers: (n, samplers) => {
251-
__glGenObject(n, samplers, 'createSampler', GL.samplers
249+
GL.genObject(n, samplers, 'createSampler', GL.samplers
252250
#if GL_ASSERTIONS
253251
, 'glGenSamplers'
254252
#endif
@@ -340,9 +338,8 @@ var LibraryWebGL2 = {
340338
},
341339

342340
// Transform Feedback
343-
glGenTransformFeedbacks__deps: ['$__glGenObject'],
344341
glGenTransformFeedbacks: (n, ids) => {
345-
__glGenObject(n, ids, 'createTransformFeedback', GL.transformFeedbacks
342+
GL.genObject(n, ids, 'createTransformFeedback', GL.transformFeedbacks
346343
#if GL_ASSERTIONS
347344
, 'glGenTransformFeedbacks'
348345
#endif

test/code_size/hello_webgl2_wasm2js.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"a.html": 567,
33
"a.html.gz": 379,
44
"a.js": 17795,
5-
"a.js.gz": 7978,
5+
"a.js.gz": 7979,
66
"a.mem": 3123,
77
"a.mem.gz": 2693,
88
"total": 21485,
9-
"total_gz": 11050
9+
"total_gz": 11051
1010
}

test/code_size/hello_webgl_wasm2js.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"a.html": 567,
33
"a.html.gz": 379,
44
"a.js": 17267,
5-
"a.js.gz": 7813,
5+
"a.js.gz": 7812,
66
"a.mem": 3123,
77
"a.mem.gz": 2693,
88
"total": 20957,
9-
"total_gz": 10885
9+
"total_gz": 10884
1010
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8355
1+
8348
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
22908
1+
22894
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7176
1+
7169
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
19532
1+
19518
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
58114
1+
58095

0 commit comments

Comments
 (0)