Canvas.h 905 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (c) 2023, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/RefCounted.h>
  8. #include <LibAccelGfx/GL.h>
  9. #include <LibGfx/Rect.h>
  10. namespace AccelGfx {
  11. class Canvas : public RefCounted<Canvas> {
  12. public:
  13. static NonnullRefPtr<Canvas> create(Gfx::IntSize const& size)
  14. {
  15. return adopt_ref(*new Canvas(size));
  16. }
  17. Gfx::IntSize const& size() const { return m_size; }
  18. GL::Framebuffer const& framebuffer() const { return m_framebuffer; }
  19. void bind()
  20. {
  21. GL::bind_framebuffer(m_framebuffer);
  22. }
  23. virtual ~Canvas()
  24. {
  25. GL::delete_framebuffer(m_framebuffer);
  26. }
  27. private:
  28. Canvas(Gfx::IntSize const& size)
  29. : m_size(size)
  30. , m_framebuffer(GL::create_framebuffer(size))
  31. {
  32. }
  33. Gfx::IntSize m_size;
  34. GL::Framebuffer m_framebuffer;
  35. };
  36. }