BsVulkanTexture.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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, VkDeviceMemory memory, 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. VkDeviceMemory mMemory;
  27. VkImageLayout mLayout;
  28. };
  29. /** Vulkan implementation of a texture. */
  30. class VulkanTextureCore : public TextureCore
  31. {
  32. public:
  33. ~VulkanTextureCore();
  34. /**
  35. * Gets the resource wrapping the Vulkan image object, on the specified device. If texture device mask doesn't
  36. * include the provided device, null is returned.
  37. */
  38. VulkanImage* getResource(UINT32 deviceIdx) const { return mImages[deviceIdx]; }
  39. /**
  40. * Returns an image view that covers all faces and mip maps of the texture. Usable only on the specified device.
  41. * If texture device mask doesn't include the provided device, null is returned.
  42. */
  43. VkImageView getView(UINT32 deviceIdx);
  44. /**
  45. * Returns an image view that covers the specified faces and mip maps of the texture. Usable only on the specified
  46. * device. If texture device mask doesn't include the provided device, null is returned.
  47. */
  48. VkImageView getView(UINT32 deviceIdx, const TextureSurface& surface);
  49. protected:
  50. friend class VulkanTextureCoreManager;
  51. VulkanTextureCore(const TEXTURE_DESC& desc, const SPtr<PixelData>& initialData, GpuDeviceFlags deviceMask);
  52. /** @copydoc CoreObjectCore::initialize() */
  53. void initialize() override;
  54. /** @copydoc TextureCore::lockImpl */
  55. PixelData lockImpl(GpuLockOptions options, UINT32 mipLevel = 0, UINT32 face = 0) override;
  56. /** @copydoc TextureCore::unlockImpl */
  57. void unlockImpl() override;
  58. /** @copydoc TextureCore::copyImpl */
  59. void copyImpl(UINT32 srcFace, UINT32 srcMipLevel, UINT32 destFace, UINT32 destMipLevel, const SPtr<TextureCore>& target) override;
  60. /** @copydoc TextureCore::readData */
  61. void readData(PixelData& dest, UINT32 mipLevel = 0, UINT32 face = 0) override;
  62. /** @copydoc TextureCore::writeData */
  63. void writeData(const PixelData& src, UINT32 mipLevel = 0, UINT32 face = 0, bool discardWholeBuffer = false) override;
  64. private:
  65. VulkanImage* mImages[BS_MAX_DEVICES];
  66. };
  67. /** @} */
  68. }