1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 13:57:35 +00:00

LibSoftGPU: Add Image class

This serves as the storage for all image types. 1D, 2D, 3D, Cube and
image arrays.

Upon construction a full mipmap chain is generated and the image is
immutable afterwards with respect to its layout.
This commit is contained in:
Stephan Unverwerth 2021-12-18 23:48:07 +01:00 committed by Brian Gianforcaro
parent a9e27b9a0f
commit 91ccf9958f
4 changed files with 235 additions and 0 deletions

View file

@ -0,0 +1,44 @@
/*
* Copyright (c) 2021, Stephan Unverwerth <s.unverwerth@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibSoftGPU/Image.h>
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)
{
VERIFY(width > 0);
VERIFY(height > 0);
VERIFY(depth > 0);
VERIFY(levels > 0);
VERIFY(layers > 0);
m_mipmap_sizes.append({ width, height, depth });
m_mipmap_offsets.append(0);
m_mipchain_size += width * height * depth * element_size(format);
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);
}
}