18
18
19
19
#if defined(__EMSCRIPTEN_PTHREADS__ ) && defined(__EMSCRIPTEN_OFFSCREEN_FRAMEBUFFER__ )
20
20
21
- pthread_key_t currentActiveWebGLContext ;
21
+ static pthread_key_t currentActiveWebGLContext ;
22
22
pthread_key_t currentThreadOwnsItsWebGLContext ;
23
23
static pthread_once_t tlsInit = PTHREAD_ONCE_INIT ;
24
24
@@ -27,6 +27,10 @@ static void InitWebGLTls() {
27
27
pthread_key_create (& currentThreadOwnsItsWebGLContext , NULL );
28
28
}
29
29
30
+ static pthread_t GetCurrentTargetThread () {
31
+ return * (void * * )(pthread_getspecific (currentActiveWebGLContext ) + 4 );
32
+ }
33
+
30
34
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE emscripten_webgl_create_context (const char * target , const EmscriptenWebGLContextAttributes * attributes ) {
31
35
GL_FUNCTION_TRACE ();
32
36
if (!attributes ) {
@@ -111,7 +115,7 @@ void glBufferData(GLenum target, GLsizeiptr size, const void *data, GLenum usage
111
115
if (size < 256 * 1024 ) { // run small buffer sizes asynchronously by copying - large buffers run synchronously
112
116
void * ptr = memdup (data , size );
113
117
if (ptr || !data ) { // glBufferData(data=0) can always be handled asynchronously
114
- emscripten_dispatch_to_thread (* ( void * * )( pthread_getspecific ( currentActiveWebGLContext ) + 4 ), EM_FUNC_SIG_VIIII , & emscripten_glBufferData , ptr , target , size , ptr , usage );
118
+ emscripten_dispatch_to_thread (GetCurrentTargetThread ( ), EM_FUNC_SIG_VIIII , & emscripten_glBufferData , ptr , target , size , ptr , usage );
115
119
return ;
116
120
}
117
121
// Fall through on allocation failure and run synchronously.
@@ -130,7 +134,7 @@ void glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void
130
134
if (size < 256 * 1024 ) { // run small buffer sizes asynchronously by copying - large buffers run synchronously
131
135
void * ptr = memdup (data , size );
132
136
if (ptr || !data ) {
133
- emscripten_dispatch_to_thread (* ( void * * )( pthread_getspecific ( currentActiveWebGLContext ) + 4 ), EM_FUNC_SIG_VIIII , & emscripten_glBufferSubData , ptr , target , offset , size , ptr );
137
+ emscripten_dispatch_to_thread (GetCurrentTargetThread ( ), EM_FUNC_SIG_VIIII , & emscripten_glBufferSubData , ptr , target , offset , size , ptr );
134
138
return ;
135
139
}
136
140
// Fall through on allocation failure and run synchronously.
@@ -266,7 +270,7 @@ void glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei widt
266
270
if (!pixels || (sz >= 0 && sz < 256 * 1024 )) { // run small buffer sizes asynchronously by copying - large buffers run synchronously
267
271
void * ptr = memdup (pixels , sz );
268
272
if (ptr || !pixels ) {
269
- emscripten_dispatch_to_thread (* ( void * * )( pthread_getspecific ( currentActiveWebGLContext ) + 4 ), EM_FUNC_SIG_VIIIIIIIII , & emscripten_glTexImage2D , ptr , target , level , internalformat , width , height , border , format , type , ptr );
273
+ emscripten_dispatch_to_thread (GetCurrentTargetThread ( ), EM_FUNC_SIG_VIIIIIIIII , & emscripten_glTexImage2D , ptr , target , level , internalformat , width , height , border , format , type , ptr );
270
274
return ;
271
275
}
272
276
// Fall through on allocation failure and run synchronously.
@@ -291,7 +295,7 @@ void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, G
291
295
if (!pixels || (sz >= 0 && sz < 256 * 1024 )) { // run small buffer sizes asynchronously by copying - large buffers run synchronously
292
296
void * ptr = memdup (pixels , sz );
293
297
if (ptr || !pixels ) {
294
- emscripten_dispatch_to_thread (* ( void * * )( pthread_getspecific ( currentActiveWebGLContext ) + 4 ), EM_FUNC_SIG_VIIIIIIIII , & emscripten_glTexSubImage2D , ptr , target , level , xoffset , yoffset , width , height , format , type , ptr );
298
+ emscripten_dispatch_to_thread (GetCurrentTargetThread ( ), EM_FUNC_SIG_VIIIIIIIII , & emscripten_glTexSubImage2D , ptr , target , level , xoffset , yoffset , width , height , format , type , ptr );
295
299
return ;
296
300
}
297
301
// Fall through on allocation failure and run synchronously.
@@ -313,7 +317,7 @@ void glUniform1fv(GLint location, GLsizei count, const GLfloat *value) {
313
317
if (sz < 256 * 1024 ) { // run small buffer sizes asynchronously by copying - large buffers run synchronously
314
318
void * ptr = memdup (value , sz );
315
319
if (ptr ) {
316
- emscripten_dispatch_to_thread (* ( void * * )( pthread_getspecific ( currentActiveWebGLContext ) + 4 ), EM_FUNC_SIG_VIII , & emscripten_glUniform1fv , ptr , location , count , (GLfloat * )ptr );
320
+ emscripten_dispatch_to_thread (GetCurrentTargetThread ( ), EM_FUNC_SIG_VIII , & emscripten_glUniform1fv , ptr , location , count , (GLfloat * )ptr );
317
321
return ;
318
322
}
319
323
// Fall through on allocation failure and run synchronously.
@@ -335,7 +339,7 @@ void glUniform1iv(GLint location, GLsizei count, const GLint *value) {
335
339
if (sz < 256 * 1024 ) { // run small buffer sizes asynchronously by copying - large buffers run synchronously
336
340
void * ptr = memdup (value , sz );
337
341
if (ptr ) {
338
- emscripten_dispatch_to_thread (* ( void * * )( pthread_getspecific ( currentActiveWebGLContext ) + 4 ), EM_FUNC_SIG_VIII , & emscripten_glUniform1iv , ptr , location , count , (GLint * )ptr );
342
+ emscripten_dispatch_to_thread (GetCurrentTargetThread ( ), EM_FUNC_SIG_VIII , & emscripten_glUniform1iv , ptr , location , count , (GLint * )ptr );
339
343
return ;
340
344
}
341
345
// Fall through on allocation failure and run synchronously.
@@ -356,7 +360,7 @@ void glUniform2fv(GLint location, GLsizei count, const GLfloat *value) {
356
360
if (sz < 256 * 1024 ) { // run small buffer sizes asynchronously by copying - large buffers run synchronously
357
361
void * ptr = memdup (value , sz );
358
362
if (ptr ) {
359
- emscripten_dispatch_to_thread (* ( void * * )( pthread_getspecific ( currentActiveWebGLContext ) + 4 ), EM_FUNC_SIG_VIII , & emscripten_glUniform2fv , ptr , location , count , (GLfloat * )ptr );
363
+ emscripten_dispatch_to_thread (GetCurrentTargetThread ( ), EM_FUNC_SIG_VIII , & emscripten_glUniform2fv , ptr , location , count , (GLfloat * )ptr );
360
364
return ;
361
365
}
362
366
// Fall through on allocation failure and run synchronously.
@@ -378,7 +382,7 @@ void glUniform2iv(GLint location, GLsizei count, const GLint *value) {
378
382
if (sz < 256 * 1024 ) { // run small buffer sizes asynchronously by copying - large buffers run synchronously
379
383
void * ptr = memdup (value , sz );
380
384
if (ptr ) {
381
- emscripten_dispatch_to_thread (* ( void * * )( pthread_getspecific ( currentActiveWebGLContext ) + 4 ), EM_FUNC_SIG_VIII , & emscripten_glUniform2iv , ptr , location , count , (GLint * )ptr );
385
+ emscripten_dispatch_to_thread (GetCurrentTargetThread ( ), EM_FUNC_SIG_VIII , & emscripten_glUniform2iv , ptr , location , count , (GLint * )ptr );
382
386
return ;
383
387
}
384
388
// Fall through on allocation failure and run synchronously.
@@ -399,7 +403,7 @@ void glUniform3fv(GLint location, GLsizei count, const GLfloat *value) {
399
403
if (sz < 256 * 1024 ) { // run small buffer sizes asynchronously by copying - large buffers run synchronously
400
404
void * ptr = memdup (value , sz );
401
405
if (ptr ) {
402
- emscripten_dispatch_to_thread (* ( void * * )( pthread_getspecific ( currentActiveWebGLContext ) + 4 ), EM_FUNC_SIG_VIII , & emscripten_glUniform3fv , ptr , location , count , (GLfloat * )ptr );
406
+ emscripten_dispatch_to_thread (GetCurrentTargetThread ( ), EM_FUNC_SIG_VIII , & emscripten_glUniform3fv , ptr , location , count , (GLfloat * )ptr );
403
407
return ;
404
408
}
405
409
// Fall through on allocation failure and run synchronously.
@@ -421,7 +425,7 @@ void glUniform3iv(GLint location, GLsizei count, const GLint *value) {
421
425
if (sz < 256 * 1024 ) { // run small buffer sizes asynchronously by copying - large buffers run synchronously
422
426
void * ptr = memdup (value , sz );
423
427
if (ptr ) {
424
- emscripten_dispatch_to_thread (* ( void * * )( pthread_getspecific ( currentActiveWebGLContext ) + 4 ), EM_FUNC_SIG_VIII , & emscripten_glUniform3iv , ptr , location , count , (GLint * )ptr );
428
+ emscripten_dispatch_to_thread (GetCurrentTargetThread ( ), EM_FUNC_SIG_VIII , & emscripten_glUniform3iv , ptr , location , count , (GLint * )ptr );
425
429
return ;
426
430
}
427
431
// Fall through on allocation failure and run synchronously.
@@ -442,7 +446,7 @@ void glUniform4fv(GLint location, GLsizei count, const GLfloat *value) {
442
446
if (sz < 256 * 1024 ) { // run small buffer sizes asynchronously by copying - large buffers run synchronously
443
447
void * ptr = memdup (value , sz );
444
448
if (ptr ) {
445
- emscripten_dispatch_to_thread (* ( void * * )( pthread_getspecific ( currentActiveWebGLContext ) + 4 ), EM_FUNC_SIG_VIII , & emscripten_glUniform4fv , ptr , location , count , (GLfloat * )ptr );
449
+ emscripten_dispatch_to_thread (GetCurrentTargetThread ( ), EM_FUNC_SIG_VIII , & emscripten_glUniform4fv , ptr , location , count , (GLfloat * )ptr );
446
450
return ;
447
451
}
448
452
// Fall through on allocation failure and run synchronously.
@@ -464,7 +468,7 @@ void glUniform4iv(GLint location, GLsizei count, const GLint *value) {
464
468
if (sz < 256 * 1024 ) { // run small buffer sizes asynchronously by copying - large buffers run synchronously
465
469
void * ptr = memdup (value , sz );
466
470
if (ptr ) {
467
- emscripten_dispatch_to_thread (* ( void * * )( pthread_getspecific ( currentActiveWebGLContext ) + 4 ), EM_FUNC_SIG_VIII , & emscripten_glUniform4iv , ptr , location , count , (GLint * )ptr );
471
+ emscripten_dispatch_to_thread (GetCurrentTargetThread ( ), EM_FUNC_SIG_VIII , & emscripten_glUniform4iv , ptr , location , count , (GLint * )ptr );
468
472
return ;
469
473
}
470
474
// Fall through on allocation failure and run synchronously.
@@ -483,7 +487,7 @@ void glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, cons
483
487
if (sz < 256 * 1024 ) { // run small buffer sizes asynchronously by copying - large buffers run synchronously
484
488
void * ptr = memdup (value , sz );
485
489
if (ptr ) {
486
- emscripten_dispatch_to_thread (* ( void * * )( pthread_getspecific ( currentActiveWebGLContext ) + 4 ), EM_FUNC_SIG_VIIII , & emscripten_glUniformMatrix2fv , ptr , location , count , transpose , (GLfloat * )ptr );
490
+ emscripten_dispatch_to_thread (GetCurrentTargetThread ( ), EM_FUNC_SIG_VIIII , & emscripten_glUniformMatrix2fv , ptr , location , count , transpose , (GLfloat * )ptr );
487
491
return ;
488
492
}
489
493
// Fall through on allocation failure and run synchronously.
@@ -502,7 +506,7 @@ void glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, cons
502
506
if (sz < 256 * 1024 ) { // run small buffer sizes asynchronously by copying - large buffers run synchronously
503
507
void * ptr = memdup (value , sz );
504
508
if (ptr ) {
505
- emscripten_dispatch_to_thread (* ( void * * )( pthread_getspecific ( currentActiveWebGLContext ) + 4 ), EM_FUNC_SIG_VIIII , & emscripten_glUniformMatrix3fv , ptr , location , count , transpose , (GLfloat * )ptr );
509
+ emscripten_dispatch_to_thread (GetCurrentTargetThread ( ), EM_FUNC_SIG_VIIII , & emscripten_glUniformMatrix3fv , ptr , location , count , transpose , (GLfloat * )ptr );
506
510
return ;
507
511
}
508
512
// Fall through on allocation failure and run synchronously.
@@ -521,7 +525,7 @@ void glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, cons
521
525
if (sz < 256 * 1024 ) { // run small buffer sizes asynchronously by copying - large buffers run synchronously
522
526
void * ptr = memdup (value , sz );
523
527
if (ptr ) {
524
- emscripten_dispatch_to_thread (* ( void * * )( pthread_getspecific ( currentActiveWebGLContext ) + 4 ), EM_FUNC_SIG_VIIII , & emscripten_glUniformMatrix4fv , ptr , location , count , transpose , (GLfloat * )ptr );
528
+ emscripten_dispatch_to_thread (GetCurrentTargetThread ( ), EM_FUNC_SIG_VIIII , & emscripten_glUniformMatrix4fv , ptr , location , count , transpose , (GLfloat * )ptr );
525
529
return ;
526
530
}
527
531
// Fall through on allocation failure and run synchronously.
0 commit comments