BsVulkanTexture.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsVulkanPrerequisites.h"
  5. #include "BsVulkanResource.h"
  6. #include "BsTexture.h"
  7. namespace BansheeEngine
  8. {
  9. /** @addtogroup Vulkan
  10. * @{
  11. */
  12. /** Wrapper around a Vulkan image object that manages its usage and lifetime. */
  13. class VulkanImage : public VulkanResource
  14. {
  15. public:
  16. VulkanImage(VulkanResourceManager* owner, VkImage image, VkImageLayout layout);
  17. ~VulkanImage();
  18. /** Returns the internal handle to the Vulkan object. */
  19. VkImage getHandle() const { return mImage; }
  20. /** Returns the layout the image is currently in. */
  21. VkImageLayout getLayout() const { return mLayout; }
  22. /** Notifies the resource that the current image layout has changed. */
  23. void setLayout(VkImageLayout layout) { mLayout = layout; }
  24. private:
  25. VkImage mImage;
  26. VkImageLayout mLayout;
  27. };
  28. /** Vulkan implementation of a texture. */
  29. class VulkanTextureCore : public TextureCore
  30. {
  31. public:
  32. ~VulkanTextureCore();
  33. /**
  34. * Gets the resource wrapping the Vulkan image object, on the specified device. If texture device mask doesn't
  35. * include the provided device, null is returned.
  36. */
  37. VulkanImage* getResource(UINT32 deviceIdx) const { return mImages[deviceIdx]; }
  38. /**
  39. * Returns an image view that covers all faces and mip maps of the texture. Usable only on the specified device.
  40. * If texture device mask doesn't include the provided device, null is returned.
  41. */
  42. VkImageView getView(UINT32 deviceIdx);
  43. /**
  44. * Returns an image view that covers the specified faces and mip maps of the texture. Usable only on the specified
  45. * device. If texture device mask doesn't include the provided device, null is returned.
  46. */
  47. VkImageView getView(UINT32 deviceIdx, const TextureSurface& surface);
  48. protected:
  49. friend class VulkanTextureCoreManager;
  50. VulkanTextureCore(const TEXTURE_DESC& desc, const SPtr<PixelData>& initialData, GpuDeviceFlags deviceMask);
  51. /** @copydoc CoreObjectCore::initialize() */
  52. void initialize() override;
  53. /** @copydoc TextureCore::lockImpl */
  54. PixelData lockImpl(GpuLockOptions options, UINT32 mipLevel = 0, UINT32 face = 0) override;
  55. /** @copydoc TextureCore::unlockImpl */
  56. void unlockImpl() override;
  57. /** @copydoc TextureCore::copyImpl */
  58. void copyImpl(UINT32 srcFace, UINT32 srcMipLevel, UINT32 destFace, UINT32 destMipLevel, const SPtr<TextureCore>& target) override;
  59. /** @copydoc TextureCore::readData */
  60. void readData(PixelData& dest, UINT32 mipLevel = 0, UINT32 face = 0) override;
  61. /** @copydoc TextureCore::writeData */
  62. void writeData(const PixelData& src, UINT32 mipLevel = 0, UINT32 face = 0, bool discardWholeBuffer = false) override;
  63. private:
  64. VulkanImage* mImages[BS_MAX_DEVICES];
  65. };
  66. /** @} */
  67. }