FrameBuffer.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (c) 2022, Jelle Raaijmakers <jelle@gmta.nl>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Error.h>
  8. #include <AK/NonnullRefPtr.h>
  9. #include <AK/RefCounted.h>
  10. #include <LibGfx/Rect.h>
  11. #include <LibGfx/Size.h>
  12. #include <LibSoftGPU/Buffer/Typed2DBuffer.h>
  13. namespace SoftGPU {
  14. /*
  15. * The frame buffer is a 2D buffer that consists of:
  16. * - color buffer(s); (FIXME: implement multiple color buffers)
  17. * - depth buffer;
  18. * - stencil buffer;
  19. * - accumulation buffer. (FIXME: implement accumulation buffer)
  20. */
  21. template<typename C, typename D, typename S>
  22. class FrameBuffer final : public RefCounted<FrameBuffer<C, D, S>> {
  23. public:
  24. static ErrorOr<NonnullRefPtr<FrameBuffer<C, D, S>>> try_create(Gfx::IntSize size)
  25. {
  26. Gfx::IntRect rect = { 0, 0, size.width(), size.height() };
  27. auto color_buffer = TRY(Typed2DBuffer<C>::try_create(size));
  28. auto depth_buffer = TRY(Typed2DBuffer<D>::try_create(size));
  29. auto stencil_buffer = TRY(Typed2DBuffer<S>::try_create(size));
  30. return adopt_ref(*new FrameBuffer(rect, color_buffer, depth_buffer, stencil_buffer));
  31. }
  32. NonnullRefPtr<Typed2DBuffer<C>> color_buffer() { return m_color_buffer; }
  33. NonnullRefPtr<Typed2DBuffer<D>> depth_buffer() { return m_depth_buffer; }
  34. NonnullRefPtr<Typed2DBuffer<S>> stencil_buffer() { return m_stencil_buffer; }
  35. Gfx::IntRect rect() const { return m_rect; }
  36. private:
  37. FrameBuffer(Gfx::IntRect rect, NonnullRefPtr<Typed2DBuffer<C>> color_buffer, NonnullRefPtr<Typed2DBuffer<D>> depth_buffer, NonnullRefPtr<Typed2DBuffer<S>> stencil_buffer)
  38. : m_color_buffer(color_buffer)
  39. , m_depth_buffer(depth_buffer)
  40. , m_stencil_buffer(stencil_buffer)
  41. , m_rect(rect)
  42. {
  43. }
  44. NonnullRefPtr<Typed2DBuffer<C>> m_color_buffer;
  45. NonnullRefPtr<Typed2DBuffer<D>> m_depth_buffer;
  46. NonnullRefPtr<Typed2DBuffer<S>> m_stencil_buffer;
  47. Gfx::IntRect m_rect;
  48. };
  49. }