mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:38:11 +00:00
LibSoftGPU: Generalize pixel buffers and standardize on BGRA8888
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. :^)
This commit is contained in:
parent
72ec2c21f4
commit
db0616c67a
14 changed files with 339 additions and 316 deletions
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Stephan Unverwerth <s.unverwerth@serenityos.org>
|
||||
* Copyright (c) 2022, Jelle Raaijmakers <jelle@gmta.nl>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -8,17 +9,14 @@
|
|||
|
||||
namespace SoftGPU {
|
||||
|
||||
Image::Image(ImageFormat format, unsigned width, unsigned height, unsigned depth, unsigned levels, unsigned layers)
|
||||
: m_format(format)
|
||||
, m_width(width)
|
||||
, m_height(height)
|
||||
, m_depth(depth)
|
||||
, m_num_layers(layers)
|
||||
Image::Image(unsigned width, unsigned height, unsigned depth, unsigned max_levels, unsigned layers)
|
||||
: m_num_layers(layers)
|
||||
, m_mipmap_buffers(FixedArray<RefPtr<Typed3DBuffer<ColorType>>>::must_create_but_fixme_should_propagate_errors(layers * max_levels))
|
||||
{
|
||||
VERIFY(width > 0);
|
||||
VERIFY(height > 0);
|
||||
VERIFY(depth > 0);
|
||||
VERIFY(levels > 0);
|
||||
VERIFY(max_levels > 0);
|
||||
VERIFY(layers > 0);
|
||||
|
||||
if ((width & (width - 1)) == 0)
|
||||
|
@ -30,24 +28,20 @@ Image::Image(ImageFormat format, unsigned width, unsigned height, unsigned depth
|
|||
if ((depth & (depth - 1)) == 0)
|
||||
m_depth_is_power_of_two = true;
|
||||
|
||||
m_mipmap_sizes.append({ width, height, depth });
|
||||
m_mipmap_offsets.append(0);
|
||||
unsigned level;
|
||||
for (level = 0; level < max_levels; ++level) {
|
||||
for (unsigned layer = 0; layer < layers; ++layer)
|
||||
m_mipmap_buffers[layer * layers + level] = MUST(Typed3DBuffer<ColorType>::try_create(width, height, depth));
|
||||
|
||||
m_mipchain_size += width * height * depth * element_size(format);
|
||||
if (width <= 1 && height <= 1 && depth <= 1)
|
||||
break;
|
||||
|
||||
while (--levels && (width > 1 || height > 1 || depth > 1)) {
|
||||
width = max(width / 2, 1);
|
||||
height = max(height / 2, 1);
|
||||
depth = max(depth / 2, 1);
|
||||
m_mipmap_sizes.append({ width, height, depth });
|
||||
m_mipmap_offsets.append(m_mipchain_size);
|
||||
|
||||
m_mipchain_size += width * height * depth * element_size(format);
|
||||
}
|
||||
|
||||
m_num_levels = m_mipmap_sizes.size();
|
||||
|
||||
m_data.resize(m_mipchain_size * m_num_layers);
|
||||
m_num_levels = level + 1;
|
||||
}
|
||||
|
||||
void Image::write_texels(unsigned layer, unsigned level, Vector3<unsigned> const& offset, Vector3<unsigned> const& size, void const* data, ImageDataLayout const& layout)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue