Image.cpp 957 B

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