mirror of
https://github.com/RGBCube/serenity
synced 2025-05-15 11:54:58 +00:00

Between the OpenGL client and server, a lot of data type and color conversion needs to happen. We are performing these conversions both in `LibSoftGPU` and `LibGL`, which is not ideal. Additionally, some concepts like the color, depth and stencil buffers should share their logic but have separate implementations. This is the first step towards generalizing our `LibSoftGPU` frame buffer: a generalized `Typed3DBuffer` is introduced for arbitrary 3D value storage and retrieval, and `Typed2DBuffer` wraps around it to provide in an easy-to-use 2D pixel buffer. The color, depth and stencil buffers are replaced by `Typed2DBuffer` and are now managed by the new `FrameBuffer` class. The `Image` class now uses multiple `Typed3DBuffer`s for layers and mipmap levels. Additionally, the textures are now always stored as BGRA8888, only converting between formats when reading or writing pixels. Ideally this refactor should have no functional changes, but some graphical glitches in Grim Fandango seem to be fixed and most OpenGL ports get an FPS boost on my machine. :^)
57 lines
1.9 KiB
C++
57 lines
1.9 KiB
C++
/*
|
|
* Copyright (c) 2022, Jelle Raaijmakers <jelle@gmta.nl>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Error.h>
|
|
#include <AK/NonnullRefPtr.h>
|
|
#include <AK/RefCounted.h>
|
|
#include <LibGfx/Rect.h>
|
|
#include <LibGfx/Size.h>
|
|
#include <LibSoftGPU/Buffer/Typed2DBuffer.h>
|
|
|
|
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<typename C, typename D, typename S>
|
|
class FrameBuffer final : public RefCounted<FrameBuffer<C, D, S>> {
|
|
public:
|
|
static ErrorOr<NonnullRefPtr<FrameBuffer<C, D, S>>> try_create(Gfx::IntSize const& size)
|
|
{
|
|
Gfx::IntRect rect = { 0, 0, size.width(), size.height() };
|
|
auto color_buffer = TRY(Typed2DBuffer<C>::try_create(size));
|
|
auto depth_buffer = TRY(Typed2DBuffer<D>::try_create(size));
|
|
auto stencil_buffer = TRY(Typed2DBuffer<S>::try_create(size));
|
|
return adopt_ref(*new FrameBuffer(rect, color_buffer, depth_buffer, stencil_buffer));
|
|
}
|
|
|
|
NonnullRefPtr<Typed2DBuffer<C>> color_buffer() { return m_color_buffer; }
|
|
NonnullRefPtr<Typed2DBuffer<D>> depth_buffer() { return m_depth_buffer; }
|
|
NonnullRefPtr<Typed2DBuffer<S>> stencil_buffer() { return m_stencil_buffer; }
|
|
Gfx::IntRect rect() const { return m_rect; }
|
|
|
|
private:
|
|
FrameBuffer(Gfx::IntRect rect, NonnullRefPtr<Typed2DBuffer<C>> color_buffer, NonnullRefPtr<Typed2DBuffer<D>> depth_buffer, NonnullRefPtr<Typed2DBuffer<S>> stencil_buffer)
|
|
: m_color_buffer(color_buffer)
|
|
, m_depth_buffer(depth_buffer)
|
|
, m_stencil_buffer(stencil_buffer)
|
|
, m_rect(rect)
|
|
{
|
|
}
|
|
|
|
NonnullRefPtr<Typed2DBuffer<C>> m_color_buffer;
|
|
NonnullRefPtr<Typed2DBuffer<D>> m_depth_buffer;
|
|
NonnullRefPtr<Typed2DBuffer<S>> m_stencil_buffer;
|
|
Gfx::IntRect m_rect;
|
|
};
|
|
|
|
}
|