@@ -45,10 +45,6 @@ void stbi_image_free(void *);
4545#include < CoreGraphics/CoreGraphics.h>
4646#endif
4747
48- #ifdef __APPLE__
49- #include < objc/message.h>
50- #endif
51-
5248#ifndef LIZARD_TEST
5349#include " embedded.h"
5450#endif
@@ -476,6 +472,8 @@ bool Overlay::init(const app::Config &cfg, std::optional<std::filesystem::path>
476472 glDeleteShader (vsId);
477473 glDeleteShader (fsId);
478474
475+ platform::clear_current_context (m_window);
476+
479477#endif
480478 m_running = true ;
481479 return true ;
@@ -728,29 +726,13 @@ void Overlay::apply_pending_config() {
728726void Overlay::shutdown () {
729727#ifndef LIZARD_TEST
730728 stop ();
731- // Release GL resources after the render loop has stopped
732- #ifdef _WIN32
733- if (m_window.device && m_window.glContext ) {
734- wglMakeCurrent ((HDC )m_window.device , (HGLRC )m_window.glContext );
735- }
736- #elif defined(__linux__)
737- if (m_window.native && m_window.glContext ) {
738- Display *dpy = glXGetCurrentDisplay ();
739- if (dpy) {
740- glXMakeCurrent (dpy, (GLXDrawable)m_window.native , (GLXContext)m_window.glContext );
741- }
742- }
743- #elif defined(__APPLE__)
744- if (m_window.glContext ) {
745- auto makeCurrent = reinterpret_cast <void (*)(id, SEL )>(objc_msgSend);
746- makeCurrent ((id)m_window.glContext , sel_getUid (" makeCurrentContext" ));
747- }
748- #endif
729+ platform::make_context_current (m_window);
749730 m_texture.reset ();
750731 m_vbo.reset ();
751732 m_instance.reset ();
752733 m_vao.reset ();
753734 m_program.reset ();
735+ platform::clear_current_context (m_window);
754736 platform::destroy_window (m_window);
755737#endif
756738}
@@ -927,12 +909,14 @@ void Overlay::render() {
927909 glBindVertexArray (m_vao.id );
928910 glBindTexture (GL_TEXTURE_2D , m_texture.id );
929911 glDrawArraysInstanced (GL_TRIANGLE_FAN , 0 , 4 , static_cast <GLsizei>(m_badges.size ()));
912+ platform::swap_buffers (m_window);
930913 platform::poll_events (m_window);
931914#endif
932915}
933916
934917void Overlay::run (std::stop_token st) {
935918#ifndef LIZARD_TEST
919+ platform::make_context_current (m_window);
936920 using clock = std::chrono::steady_clock;
937921 auto last = clock::now ();
938922 while (m_running && !st.stop_requested ()) {
@@ -958,6 +942,7 @@ void Overlay::run(std::stop_token st) {
958942 std::this_thread::sleep_for (frame - spend);
959943 }
960944 }
945+ platform::clear_current_context (m_window);
961946 stop ();
962947#else
963948 (void )st;
0 commit comments