diff options
Diffstat (limited to 'frontend/shared_cpp/WebglContext.h')
| -rw-r--r-- | frontend/shared_cpp/WebglContext.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/frontend/shared_cpp/WebglContext.h b/frontend/shared_cpp/WebglContext.h new file mode 100644 index 0000000..cf9cce2 --- /dev/null +++ b/frontend/shared_cpp/WebglContext.h @@ -0,0 +1,31 @@ +#pragma once +#include <emscripten.h> +#include <emscripten/html5.h> +#include <GLES2/gl2.h> +#include <EGL/egl.h> + +struct WebglContext { + void init(const char* query, int width = 640, int height = 480) { + emscripten_set_canvas_element_size( query, width, height); + + EmscriptenWebGLContextAttributes attrs; + emscripten_webgl_init_context_attributes(&attrs); + + attrs.enableExtensionsByDefault = 1; + attrs.majorVersion = 3; + attrs.minorVersion = 0; + + context = emscripten_webgl_create_context( "#wasm_canvas", &attrs ); + makeCurrentContext(); + }; + + void makeCurrentContext() { + emscripten_webgl_make_context_current(context); + }; + + void destroy() { + emscripten_webgl_destroy_context(context); + } + + EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context; +}; |
