GLContext.cpp 798 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 <LibGfx/Bitmap.h>
  10. __attribute__((visibility("hidden"))) GL::GLContext* g_gl_context;
  11. namespace GL {
  12. GLContext::~GLContext()
  13. {
  14. if (g_gl_context == this)
  15. make_context_current(nullptr);
  16. }
  17. OwnPtr<GLContext> create_context(Gfx::Bitmap& bitmap)
  18. {
  19. auto context = adopt_own(*new SoftwareGLContext(bitmap));
  20. if (!g_gl_context)
  21. g_gl_context = context;
  22. return context;
  23. }
  24. void make_context_current(GLContext* context)
  25. {
  26. g_gl_context = context;
  27. }
  28. void present_context(GLContext* context)
  29. {
  30. context->present();
  31. }
  32. }