VisuTwin Canvas
C++ 3D Engine — Metal Backend
Loading...
Searching...
No Matches
textureUtils.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2025-2026 Arnis Lektauers
3//
4// Created by Arnis Lektauers on 19.09.2025.
5//
6#include "textureUtils.h"
7
8#include <algorithm>
9
10namespace visutwin::canvas
11{
12 uint32_t TextureUtils::calcLevelDimension(const uint32_t dimension, const uint32_t mipLevel)
13 {
14 return std::max(dimension >> mipLevel, 1u);
15 }
16
17 uint32_t TextureUtils::calcMipLevelsCount(uint32_t width, uint32_t height, uint32_t depth) {
18 uint32_t maxDimension = std::max({width, height, depth});
19 if (maxDimension == 0) {
20 return 1;
21 }
22
23 // Calculate log2 of the maximum dimension
24 uint32_t levels = 1;
25 while (maxDimension > 1) {
26 maxDimension >>= 1;
27 levels++;
28 }
29
30 return levels;
31 }
32}
static uint32_t calcLevelDimension(uint32_t dimension, uint32_t mipLevel)
static uint32_t calcMipLevelsCount(uint32_t width, uint32_t height, uint32_t depth=1)