GLContext.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (c) 2021, Jesse Buhagiar <jooster669@gmail.com>
  3. * Copyright (c) 2021, Stephan Unverwerth <s.unverwerth@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include "GLContext.h"
  8. #include "SoftwareGLContext.h"
  9. #include <AK/Debug.h>
  10. #include <LibGfx/Bitmap.h>
  11. __attribute__((visibility("hidden"))) GL::GLContext* g_gl_context;
  12. namespace GL {
  13. GLContext::~GLContext()
  14. {
  15. dbgln_if(GL_DEBUG, "GLContext::~GLContext() {:p}", this);
  16. if (g_gl_context == this)
  17. make_context_current(nullptr);
  18. }
  19. NonnullOwnPtr<GLContext> create_context(Gfx::Bitmap& bitmap)
  20. {
  21. auto context = make<SoftwareGLContext>(bitmap);
  22. dbgln_if(GL_DEBUG, "GL::create_context({}) -> {:p}", bitmap.size(), context.ptr());
  23. if (!g_gl_context)
  24. make_context_current(context);
  25. return context;
  26. }
  27. void make_context_current(GLContext* context)
  28. {
  29. if (g_gl_context == context)
  30. return;
  31. dbgln_if(GL_DEBUG, "GL::make_context_current({:p})", context);
  32. g_gl_context = context;
  33. }
  34. void present_context(GLContext* context)
  35. {
  36. context->present();
  37. }
  38. }