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

Function main

test/browser/webgl_create_context.cpp:77–206  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

75}
76
77int main() {
78 bool first = true;
79 EmscriptenWebGLContextAttributes attrs;
80 int depth = 0;
81 int stencil = 0;
82 int antialias = 0;
83#ifndef NO_DEPTH
84 for(depth = 0; depth <= 1; ++depth)
85#endif
86#ifndef NO_STENCIL
87 for(stencil = 0; stencil <= 1; ++stencil)
88#endif
89#ifndef NO_ANTIALIAS
90 for(antialias = 0; antialias <= 1; ++antialias)
91#endif
92 {
93 emscripten_webgl_init_context_attributes(&attrs);
94 attrs.depth = depth;
95 attrs.stencil = stencil;
96 attrs.antialias = antialias;
97 printf("Requesting depth: %d, stencil: %d, antialias: %d\n", depth, stencil, antialias);
98
99 EM_ASM(
100 var canvas2 = document.createElement('canvas');
101 Module['canvas'].parentElement.appendChild(canvas2);
102 canvas2.id = 'customCanvas';
103 );
104
105 assert(emscripten_webgl_get_current_context() == 0);
106 EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context = emscripten_webgl_create_context("#customCanvas", &attrs);
107 assert(context > 0); // Must have received a valid context.
108 EMSCRIPTEN_RESULT res = emscripten_webgl_make_context_current(context);
109 assert(res == EMSCRIPTEN_RESULT_SUCCESS);
110 assert(emscripten_webgl_get_current_context() == context);
111
112 // Let's try enabling all extensions.
113 const char *extensions = (const char*)glGetString(GL_EXTENSIONS);
114 std::vector<std::string> exts = split(extensions, ' ');
115 for(size_t i = 0; i < exts.size(); ++i)
116 {
117 bool supported = emscripten_webgl_enable_extension(context, exts[i].c_str());
118 printf("%s\n", exts[i].c_str());
119 assert(supported);
120 }
121
122 int drawingBufferWidth = -1;
123 int drawingBufferHeight = -1;
124 res = emscripten_webgl_get_drawing_buffer_size(context, &drawingBufferWidth, &drawingBufferHeight);
125 assert(res == EMSCRIPTEN_RESULT_SUCCESS);
126 printf("drawingBufferWidth x Height: %dx%d\n", drawingBufferWidth, drawingBufferHeight);
127 assert(drawingBufferWidth == 300);
128 assert(drawingBufferHeight == 150);
129
130 // Try with a simple glClear() that we got a context.
131 glClearColor(1.f, 0.f, 0.f, 1.f);
132 glClear(GL_COLOR_BUFFER_BIT);
133 unsigned char pixels[4];
134 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);

Callers

nothing calls this directly

Calls 11

printfFunction · 0.85
GetIntFunction · 0.85
splitFunction · 0.70
sizeMethod · 0.65
assertFunction · 0.50
c_strMethod · 0.45
removeChildMethod · 0.45

Tested by

no test coverage detected