MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / ThreadMain

Function ThreadMain

test/browser/gl_only_in_pthread.c:24–58  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22_Atomic int threadRunning = 0;
23
24void *ThreadMain(void *arg)
25{
26 printf("Thread started. You should see the WebGL canvas fade from black to red.\n");
27 EmscriptenWebGLContextAttributes attr;
28 emscripten_webgl_init_context_attributes(&attr);
29 attr.explicitSwapControl = true;
30 ctx = emscripten_webgl_create_context("#canvas", &attr);
31 emscripten_webgl_make_context_current(ctx);
32
33 double color = 0;
34 for(int i = 0; i < 100; ++i)
35 {
36 color += 0.01;
37 glClearColor(color, 0, 0, 1);
38 glClear(GL_COLOR_BUFFER_BIT);
39 EMSCRIPTEN_RESULT r = emscripten_webgl_commit_frame();
40 assert(r == EMSCRIPTEN_RESULT_SUCCESS);
41
42 double now = emscripten_get_now();
43 while(emscripten_get_now() - now < 16) /*no-op*/;
44 }
45
46#if 0 // TODO: this doesn't work yet for some reason
47 unsigned char data[64];
48 glReadPixels(0, 0, 4, 4, GL_RGBA, GL_UNSIGNED_BYTE, data);
49 assert(glGetError() == 0);
50 printf("%d %d %d %d\n", data[0], data[1], data[2], data[3]);
51#endif
52
53 emscripten_webgl_make_context_current(0);
54 emscripten_webgl_destroy_context(ctx);
55 threadRunning = 0;
56 printf("Thread quit\n");
57 pthread_exit(0);
58}
59
60void CreateThread()
61{

Callers

nothing calls this directly

Calls 7

printfFunction · 0.85
assertFunction · 0.50
emscripten_get_nowFunction · 0.50

Tested by

no test coverage detected