Image.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c) 2021, Stephan Unverwerth <s.unverwerth@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibSoftGPU/Image.h>
  7. namespace SoftGPU {
  8. Image::Image(ImageFormat format, unsigned width, unsigned height, unsigned depth, unsigned levels, unsigned layers)
  9. : m_format(format)
  10. , m_width(width)
  11. , m_height(height)
  12. , m_depth(depth)
  13. , m_num_layers(layers)
  14. {
  15. VERIFY(width > 0);
  16. VERIFY(height > 0);
  17. VERIFY(depth > 0);
  18. VERIFY(levels > 0);
  19. VERIFY(layers > 0);
  20. m_mipmap_sizes.append({ width, height, depth });
  21. m_mipmap_offsets.append(0);
  22. m_mipchain_size += width * height * depth * element_size(format);
  23. while (--levels && (width > 1 || height > 1 || depth > 1)) {
  24. width = max(width / 2, 1);
  25. height = max(height / 2, 1);
  26. depth = max(depth / 2, 1);
  27. m_mipmap_sizes.append({ width, height, depth });
  28. m_mipmap_offsets.append(m_mipchain_size);
  29. m_mipchain_size += width * height * depth * element_size(format);
  30. }
  31. m_num_levels = m_mipmap_sizes.size();
  32. m_data.resize(m_mipchain_size * m_num_layers);
  33. }
  34. }