Serenity Operating System
1/*
2 * Copyright (c) 2022, Stephan Unverwerth <s.unverwerth@serenityos.org>
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#include <AK/IntegralMath.h>
8#include <AK/Math.h>
9#include <LibGPU/Image.h>
10
11namespace GPU {
12
13Image::Image(void const* ownership_token, GPU::PixelFormat const& pixel_format, u32 width, u32 height, u32 depth, u32 max_levels)
14 : m_ownership_token { ownership_token }
15 , m_pixel_format { pixel_format }
16{
17 VERIFY(width > 0);
18 VERIFY(height > 0);
19 VERIFY(depth > 0);
20 VERIFY(max_levels > 0);
21
22 u32 number_of_levels_in_full_chain = max(max(AK::log2(width), AK::log2(height)), AK::log2(depth)) + 1;
23 m_mipmap_sizes.resize(min(max_levels, number_of_levels_in_full_chain));
24
25 for (u32 level = 0; level < m_mipmap_sizes.size(); ++level) {
26 m_mipmap_sizes[level] = { width, height, depth };
27 width = max(width / 2, 1);
28 height = max(height / 2, 1);
29 depth = max(depth / 2, 1);
30 }
31}
32
33}