Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/test/browser/gl_in_proxy_pthread.c
7085 views
1
#include <stdio.h>
2
#include <string.h>
3
#include <pthread.h>
4
#include <GLES2/gl2.h>
5
#include <math.h>
6
#include <assert.h>
7
#include <emscripten/emscripten.h>
8
#include <emscripten/html5.h>
9
#include <emscripten/threading.h>
10
#include <bits/errno.h>
11
#include <stdlib.h>
12
13
int main()
14
{
15
if (!emscripten_supports_offscreencanvas())
16
{
17
printf("Current browser does not support OffscreenCanvas. Skipping this test.\n");
18
return 0;
19
}
20
EmscriptenWebGLContextAttributes attr;
21
emscripten_webgl_init_context_attributes(&attr);
22
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_create_context("#canvas", &attr);
23
printf("Created context with handle %u\n", (unsigned int)ctx);
24
emscripten_webgl_make_context_current(ctx);
25
26
printf("You should see the canvas fade from black to red.\n");
27
double color = 0;
28
for(int i = 0; i < 100; ++i)
29
{
30
color += 0.01;
31
glClearColor(color, 0, 0, 1);
32
glClear(GL_COLOR_BUFFER_BIT);
33
34
#if ASYNCIFY
35
emscripten_sleep(16);
36
#else
37
double now = emscripten_get_now();
38
while(emscripten_get_now() - now < 16) /*no-op*/;
39
#endif
40
}
41
42
emscripten_webgl_make_context_current(0);
43
emscripten_webgl_destroy_context(ctx);
44
printf("Thread quit\n");
45
return 0;
46
}
47
48