diff options
| author | Matthew Kosarek <mattkae@protonmail.com> | 2021-03-22 20:54:51 -0400 |
|---|---|---|
| committer | Matthew Kosarek <mattkae@protonmail.com> | 2021-03-22 20:54:51 -0400 |
| commit | c36d05d5aed2f8f7c6342b174692146e2d11c386 (patch) | |
| tree | 8e54047d7b6db7e3d21ccfad6b8c4965d42c09fa /frontend/shared_cpp/WebglContext.h | |
| parent | c29a911cd1a3f23f66478f205cace14487aadc56 (diff) | |
Refactored frontend, beginnings of general cpp layer, and beginning roadmap
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; +}; |
