Image.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright (c) 2021, Stephan Unverwerth <s.unverwerth@serenityos.org>
  3. * Copyright (c) 2022, Jelle Raaijmakers <jelle@gmta.nl>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <AK/FixedArray.h>
  9. #include <AK/RefPtr.h>
  10. #include <LibGPU/Image.h>
  11. #include <LibGPU/ImageDataLayout.h>
  12. #include <LibGPU/ImageFormat.h>
  13. #include <LibGfx/Vector3.h>
  14. #include <LibGfx/Vector4.h>
  15. #include <LibSoftGPU/Buffer/Typed3DBuffer.h>
  16. namespace SoftGPU {
  17. class Image final : public GPU::Image {
  18. public:
  19. Image(void const* ownership_token, GPU::PixelFormat const&, u32 width, u32 height, u32 depth, u32 max_levels);
  20. bool width_is_power_of_two() const { return m_width_is_power_of_two; }
  21. bool height_is_power_of_two() const { return m_height_is_power_of_two; }
  22. bool depth_is_power_of_two() const { return m_depth_is_power_of_two; }
  23. GPU::ImageDataLayout image_data_layout(u32 level, Vector3<i32> offset) const;
  24. virtual void regenerate_mipmaps() override;
  25. FloatVector4 const& texel(u32 level, int x, int y, int z) const
  26. {
  27. return *texel_pointer(level, x, y, z);
  28. }
  29. void set_texel(u32 level, int x, int y, int z, FloatVector4 const& color)
  30. {
  31. *texel_pointer(level, x, y, z) = color;
  32. }
  33. virtual void write_texels(u32 level, Vector3<i32> const& output_offset, void const* input_data, GPU::ImageDataLayout const&) override;
  34. virtual void read_texels(u32 level, Vector3<i32> const& input_offset, void* output_data, GPU::ImageDataLayout const&) const override;
  35. virtual void copy_texels(GPU::Image const& source, u32 source_level, Vector3<u32> const& source_offset, Vector3<u32> const& size, u32 destination_level, Vector3<u32> const& destination_offset) override;
  36. FloatVector4 const* texel_pointer(u32 level, int x, int y, int z) const
  37. {
  38. return m_mipmap_buffers[level]->buffer_pointer(x, y, z);
  39. }
  40. FloatVector4* texel_pointer(u32 level, int x, int y, int z)
  41. {
  42. return m_mipmap_buffers[level]->buffer_pointer(x, y, z);
  43. }
  44. private:
  45. FixedArray<RefPtr<Typed3DBuffer<FloatVector4>>> m_mipmap_buffers;
  46. bool m_width_is_power_of_two { false };
  47. bool m_height_is_power_of_two { false };
  48. bool m_depth_is_power_of_two { false };
  49. };
  50. }