AbstractTexture.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2017 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <cstddef>
  5. #include <string>
  6. #include "Common/CommonTypes.h"
  7. #include "Common/MathUtil.h"
  8. #include "VideoCommon/TextureConfig.h"
  9. class AbstractTexture
  10. {
  11. public:
  12. explicit AbstractTexture(const TextureConfig& c);
  13. virtual ~AbstractTexture() = default;
  14. virtual void CopyRectangleFromTexture(const AbstractTexture* src,
  15. const MathUtil::Rectangle<int>& src_rect, u32 src_layer,
  16. u32 src_level, const MathUtil::Rectangle<int>& dst_rect,
  17. u32 dst_layer, u32 dst_level) = 0;
  18. virtual void ResolveFromTexture(const AbstractTexture* src, const MathUtil::Rectangle<int>& rect,
  19. u32 layer, u32 level) = 0;
  20. virtual void Load(u32 level, u32 width, u32 height, u32 row_length, const u8* buffer,
  21. size_t buffer_size, u32 layer = 0) = 0;
  22. // Hints to the backend that we have finished rendering to this texture, and it will be used
  23. // as a shader resource and sampled. For Vulkan, this transitions the image layout.
  24. virtual void FinishedRendering();
  25. u32 GetWidth() const { return m_config.width; }
  26. u32 GetHeight() const { return m_config.height; }
  27. u32 GetLevels() const { return m_config.levels; }
  28. u32 GetLayers() const { return m_config.layers; }
  29. u32 GetSamples() const { return m_config.samples; }
  30. AbstractTextureFormat GetFormat() const { return m_config.format; }
  31. MathUtil::Rectangle<int> GetRect() const { return m_config.GetRect(); }
  32. MathUtil::Rectangle<int> GetMipRect(u32 level) const { return m_config.GetMipRect(level); }
  33. bool IsMultisampled() const { return m_config.IsMultisampled(); }
  34. bool Save(const std::string& filename, unsigned int level, int compression = 6) const;
  35. static bool IsCompressedFormat(AbstractTextureFormat format);
  36. static bool IsDepthFormat(AbstractTextureFormat format);
  37. static bool IsStencilFormat(AbstractTextureFormat format);
  38. static bool IsCompatibleDepthAndColorFormats(AbstractTextureFormat depth_format,
  39. AbstractTextureFormat color_format);
  40. static u32 CalculateStrideForFormat(AbstractTextureFormat format, u32 row_length);
  41. static u32 GetTexelSizeForFormat(AbstractTextureFormat format);
  42. static u32 GetBlockSizeForFormat(AbstractTextureFormat format);
  43. const TextureConfig& GetConfig() const;
  44. protected:
  45. const TextureConfig m_config;
  46. };