/* * Copyright (c) 2022, Jelle Raaijmakers * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include namespace SoftGPU { /* * The frame buffer is a 2D buffer that consists of: * - color buffer(s); (FIXME: implement multiple color buffers) * - depth buffer; * - stencil buffer; * - accumulation buffer. (FIXME: implement accumulation buffer) */ template class FrameBuffer final : public RefCounted> { public: static ErrorOr>> try_create(Gfx::IntSize const& size) { Gfx::IntRect rect = { 0, 0, size.width(), size.height() }; auto color_buffer = TRY(Typed2DBuffer::try_create(size)); auto depth_buffer = TRY(Typed2DBuffer::try_create(size)); auto stencil_buffer = TRY(Typed2DBuffer::try_create(size)); return adopt_ref(*new FrameBuffer(rect, color_buffer, depth_buffer, stencil_buffer)); } NonnullRefPtr> color_buffer() { return m_color_buffer; } NonnullRefPtr> depth_buffer() { return m_depth_buffer; } NonnullRefPtr> stencil_buffer() { return m_stencil_buffer; } Gfx::IntRect rect() const { return m_rect; } private: FrameBuffer(Gfx::IntRect rect, NonnullRefPtr> color_buffer, NonnullRefPtr> depth_buffer, NonnullRefPtr> stencil_buffer) : m_color_buffer(color_buffer) , m_depth_buffer(depth_buffer) , m_stencil_buffer(stencil_buffer) , m_rect(rect) { } NonnullRefPtr> m_color_buffer; NonnullRefPtr> m_depth_buffer; NonnullRefPtr> m_stencil_buffer; Gfx::IntRect m_rect; }; }