Path: blob/main/test/browser/gl_in_proxy_pthread.c
7085 views
#include <stdio.h>1#include <string.h>2#include <pthread.h>3#include <GLES2/gl2.h>4#include <math.h>5#include <assert.h>6#include <emscripten/emscripten.h>7#include <emscripten/html5.h>8#include <emscripten/threading.h>9#include <bits/errno.h>10#include <stdlib.h>1112int main()13{14if (!emscripten_supports_offscreencanvas())15{16printf("Current browser does not support OffscreenCanvas. Skipping this test.\n");17return 0;18}19EmscriptenWebGLContextAttributes attr;20emscripten_webgl_init_context_attributes(&attr);21EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_create_context("#canvas", &attr);22printf("Created context with handle %u\n", (unsigned int)ctx);23emscripten_webgl_make_context_current(ctx);2425printf("You should see the canvas fade from black to red.\n");26double color = 0;27for(int i = 0; i < 100; ++i)28{29color += 0.01;30glClearColor(color, 0, 0, 1);31glClear(GL_COLOR_BUFFER_BIT);3233#if ASYNCIFY34emscripten_sleep(16);35#else36double now = emscripten_get_now();37while(emscripten_get_now() - now < 16) /*no-op*/;38#endif39}4041emscripten_webgl_make_context_current(0);42emscripten_webgl_destroy_context(ctx);43printf("Thread quit\n");44return 0;45}464748