SWTexture.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright 2017 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <memory>
  5. #include <vector>
  6. #include "Common/CommonTypes.h"
  7. #include "VideoCommon/AbstractFramebuffer.h"
  8. #include "VideoCommon/AbstractStagingTexture.h"
  9. #include "VideoCommon/AbstractTexture.h"
  10. namespace SW
  11. {
  12. class SWTexture final : public AbstractTexture
  13. {
  14. public:
  15. explicit SWTexture(const TextureConfig& tex_config);
  16. ~SWTexture() = default;
  17. void CopyRectangleFromTexture(const AbstractTexture* src,
  18. const MathUtil::Rectangle<int>& src_rect, u32 src_layer,
  19. u32 src_level, const MathUtil::Rectangle<int>& dst_rect,
  20. u32 dst_layer, u32 dst_level) override;
  21. void ResolveFromTexture(const AbstractTexture* src, const MathUtil::Rectangle<int>& rect,
  22. u32 layer, u32 level) override;
  23. void Load(u32 level, u32 width, u32 height, u32 row_length, const u8* buffer, size_t buffer_size,
  24. u32 layer) override;
  25. const u8* GetData(u32 layer, u32 level) const;
  26. u8* GetData(u32 layer, u32 level);
  27. private:
  28. std::vector<std::vector<std::vector<u8>>> m_data;
  29. };
  30. class SWStagingTexture final : public AbstractStagingTexture
  31. {
  32. public:
  33. explicit SWStagingTexture(StagingTextureType type, const TextureConfig& config);
  34. ~SWStagingTexture();
  35. void CopyFromTexture(const AbstractTexture* src, const MathUtil::Rectangle<int>& src_rect,
  36. u32 src_layer, u32 src_level,
  37. const MathUtil::Rectangle<int>& dst_rect) override;
  38. void CopyToTexture(const MathUtil::Rectangle<int>& src_rect, AbstractTexture* dst,
  39. const MathUtil::Rectangle<int>& dst_rect, u32 dst_layer,
  40. u32 dst_level) override;
  41. bool Map() override;
  42. void Unmap() override;
  43. void Flush() override;
  44. void SetMapStride(size_t stride) { m_map_stride = stride; }
  45. private:
  46. std::vector<u8> m_data;
  47. };
  48. class SWFramebuffer final : public AbstractFramebuffer
  49. {
  50. public:
  51. explicit SWFramebuffer(AbstractTexture* color_attachment, AbstractTexture* depth_attachment,
  52. std::vector<AbstractTexture*> additional_color_attachments,
  53. AbstractTextureFormat color_format, AbstractTextureFormat depth_format,
  54. u32 width, u32 height, u32 layers, u32 samples);
  55. ~SWFramebuffer() override = default;
  56. static std::unique_ptr<SWFramebuffer>
  57. Create(SWTexture* color_attachment, SWTexture* depth_attachment,
  58. std::vector<AbstractTexture*> additional_color_attachments);
  59. };
  60. } // namespace SW