diff --git a/Userland/Libraries/LibGL/GLContext.cpp b/Userland/Libraries/LibGL/GLContext.cpp index 4c8f7dc977..f49d90e4b7 100644 --- a/Userland/Libraries/LibGL/GLContext.cpp +++ b/Userland/Libraries/LibGL/GLContext.cpp @@ -7,6 +7,7 @@ #include "GLContext.h" #include "SoftwareGLContext.h" +#include #include __attribute__((visibility("hidden"))) GL::GLContext* g_gl_context; @@ -15,22 +16,28 @@ namespace GL { GLContext::~GLContext() { + dbgln_if(GL_DEBUG, "GLContext::~GLContext() {:p}", this); if (g_gl_context == this) make_context_current(nullptr); } -OwnPtr create_context(Gfx::Bitmap& bitmap) +NonnullOwnPtr create_context(Gfx::Bitmap& bitmap) { - auto context = adopt_own(*new SoftwareGLContext(bitmap)); + auto context = make(bitmap); + dbgln_if(GL_DEBUG, "GL::create_context({}) -> {:p}", bitmap.size(), context.ptr()); if (!g_gl_context) - g_gl_context = context; + make_context_current(context); return context; } void make_context_current(GLContext* context) { + if (g_gl_context == context) + return; + + dbgln_if(GL_DEBUG, "GL::make_context_current({:p})", context); g_gl_context = context; } diff --git a/Userland/Libraries/LibGL/GLContext.h b/Userland/Libraries/LibGL/GLContext.h index 896b005e7a..bf189197d9 100644 --- a/Userland/Libraries/LibGL/GLContext.h +++ b/Userland/Libraries/LibGL/GLContext.h @@ -120,7 +120,7 @@ public: virtual void present() = 0; }; -OwnPtr create_context(Gfx::Bitmap&); +NonnullOwnPtr create_context(Gfx::Bitmap&); void make_context_current(GLContext*); void present_context(GLContext*);