Browse Source

Platform: actually properly destroy the WebGL context after.

And expose it to the users.
pull/300/head
Vladimír Vondruš 7 years ago
parent
commit
ac0d6987ad
  1. 14
      src/Magnum/Platform/EmscriptenApplication.cpp
  2. 12
      src/Magnum/Platform/EmscriptenApplication.h

14
src/Magnum/Platform/EmscriptenApplication.cpp

@ -208,7 +208,11 @@ EmscriptenApplication::EmscriptenApplication(const Arguments& arguments, NoCreat
}
EmscriptenApplication::~EmscriptenApplication() {
emscripten_webgl_make_context_current(0);
#ifdef MAGNUM_TARGET_GL
_context.reset();
emscripten_webgl_destroy_context(_glContext);
#endif
}
void EmscriptenApplication::create() {
@ -335,9 +339,8 @@ bool EmscriptenApplication::tryCreate(const Configuration& configuration, const
const Vector2i scaledCanvasSize = canvasSize*_dpiScaling*_devicePixelRatio;
emscripten_set_canvas_element_size("#canvas", scaledCanvasSize.x(), scaledCanvasSize.y());
/* Create surface and context */
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context =
emscripten_webgl_create_context("#canvas", &attrs);
/* Create WebGL context */
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context = emscripten_webgl_create_context("#canvas", &attrs);
if(!context) {
/* When context creation fails, `context` is a negative integer
matching EMSCRIPTEN_RESULT_* defines */
@ -347,8 +350,7 @@ bool EmscriptenApplication::tryCreate(const Configuration& configuration, const
}
/* Make the context current */
CORRADE_INTERNAL_ASSERT_OUTPUT(
emscripten_webgl_make_context_current(context) == EMSCRIPTEN_RESULT_SUCCESS);
CORRADE_INTERNAL_ASSERT_OUTPUT(emscripten_webgl_make_context_current(_glContext = context) == EMSCRIPTEN_RESULT_SUCCESS);
setupCallbacks(!!(configuration.windowFlags() & Configuration::WindowFlag::Resizable));

12
src/Magnum/Platform/EmscriptenApplication.h

@ -49,6 +49,7 @@ struct EmscriptenKeyboardEvent;
struct EmscriptenMouseEvent;
struct EmscriptenWheelEvent;
struct EmscriptenUiEvent;
typedef int EMSCRIPTEN_WEBGL_CONTEXT_HANDLE;
#endif
namespace Magnum { namespace Platform {
@ -309,6 +310,16 @@ class EmscriptenApplication {
*/
void exit(int exitCode = 0);
#ifdef MAGNUM_TARGET_GL
/**
* @brief Underlying WebGL context
*
* Use in case you need to call Emscripten functionality directly.
* Returns @cpp 0 @ce in case the context was not created yet.
*/
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE glContext() { return _glContext; }
#endif
protected:
/* Nobody will need to have (and delete) EmscriptenApplication*, thus
this is faster than public pure virtual destructor */
@ -574,6 +585,7 @@ class EmscriptenApplication {
Flags _flags;
#ifdef MAGNUM_TARGET_GL
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE _glContext{};
Containers::Pointer<Platform::GLContext> _context;
#endif

Loading…
Cancel
Save