Buckets:
| // Copyright 2018 The Emscripten Authors. All rights reserved. | |
| // Emscripten is available under two separate licenses, the MIT license and the | |
| // University of Illinois/NCSA Open Source License. Both these licenses can be | |
| // found in the LICENSE file. | |
| pthread_t thread; | |
| EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx; | |
| _Atomic int threadRunning = 0; | |
| void *ThreadMain(void *arg) | |
| { | |
| printf("Thread started. You should see the WebGL canvas fade from black to red.\n"); | |
| EmscriptenWebGLContextAttributes attr; | |
| emscripten_webgl_init_context_attributes(&attr); | |
| attr.explicitSwapControl = true; | |
| ctx = emscripten_webgl_create_context("#canvas", &attr); | |
| emscripten_webgl_make_context_current(ctx); | |
| double color = 0; | |
| for(int i = 0; i < 100; ++i) | |
| { | |
| color += 0.01; | |
| glClearColor(color, 0, 0, 1); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| EMSCRIPTEN_RESULT r = emscripten_webgl_commit_frame(); | |
| assert(r == EMSCRIPTEN_RESULT_SUCCESS); | |
| double now = emscripten_get_now(); | |
| while(emscripten_get_now() - now < 16) /*no-op*/; | |
| } | |
| unsigned char data[64]; | |
| glReadPixels(0, 0, 4, 4, GL_RGBA, GL_UNSIGNED_BYTE, data); | |
| assert(glGetError() == 0); | |
| printf("%d %d %d %d\n", data[0], data[1], data[2], data[3]); | |
| emscripten_webgl_make_context_current(0); | |
| emscripten_webgl_destroy_context(ctx); | |
| threadRunning = 0; | |
| printf("Thread quit\n"); | |
| pthread_exit(0); | |
| } | |
| void CreateThread() | |
| { | |
| pthread_attr_t attr; | |
| pthread_attr_init(&attr); | |
| emscripten_pthread_attr_settransferredcanvases(&attr, "#canvas"); | |
| int rc = pthread_create(&thread, &attr, ThreadMain, 0); | |
| if (rc == ENOSYS) | |
| { | |
| printf("Test Skipped! OffscreenCanvas is not supported!\n"); | |
| REPORT_RESULT(0); // for now, report a skip as success | |
| exit(1); | |
| } | |
| pthread_attr_destroy(&attr); | |
| threadRunning = 1; | |
| } | |
| void PollThreadExit(void *arg) | |
| { | |
| if (!threadRunning) | |
| { | |
| printf("Test finished.\n"); | |
| REPORT_RESULT(0); | |
| } else { | |
| emscripten_async_call(PollThreadExit, 0, 100); | |
| } | |
| } | |
| int main() | |
| { | |
| if (!emscripten_supports_offscreencanvas()) | |
| { | |
| printf("Current browser does not support OffscreenCanvas. Skipping this test.\n"); | |
| REPORT_RESULT(0); | |
| return 0; | |
| } | |
| CreateThread(); | |
| emscripten_async_call(PollThreadExit, 0, 100); | |
| return 0; | |
| } | |
Xet Storage Details
- Size:
- 2.65 kB
- Xet hash:
- 279ebf0dd648f7c26857c6afb64bc0d02a10d2873a4e98719107300ca9029538
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.