From c36d05d5aed2f8f7c6342b174692146e2d11c386 Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Mon, 22 Mar 2021 20:54:51 -0400 Subject: Refactored frontend, beginnings of general cpp layer, and beginning roadmap --- frontend/shared_cpp/WebglContext.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 frontend/shared_cpp/WebglContext.h (limited to 'frontend/shared_cpp/WebglContext.h') 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 +#include +#include +#include + +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; +}; -- cgit v1.2.1