VulkanTexture2D.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #pragma once
  2. #include <vulkan/vulkan.h>
  3. #include "GraphicsDevice/ITexture2D.h"
  4. #include "IUnityGraphicsVulkan.h"
  5. namespace unity
  6. {
  7. namespace webrtc
  8. {
  9. class VulkanTexture2D : public ITexture2D
  10. {
  11. public:
  12. VulkanTexture2D(const uint32_t w, const uint32_t h);
  13. virtual ~VulkanTexture2D() override;
  14. bool Init(const VkPhysicalDevice physicalDevice, const VkDevice device, const VkCommandPool commandPool);
  15. bool InitCpuRead(const VkPhysicalDevice physicalDevice, const VkDevice device, const VkCommandPool commandPool);
  16. void Shutdown();
  17. inline virtual void* GetNativeTexturePtrV() override;
  18. inline virtual const void* GetNativeTexturePtrV() const override;
  19. inline virtual void* GetEncodeTexturePtrV() override;
  20. inline virtual const void* GetEncodeTexturePtrV() const override;
  21. inline VkImage GetImage() const;
  22. inline VkDeviceMemory GetTextureImageMemory() const;
  23. inline VkDeviceSize GetTextureImageMemorySize() const;
  24. inline VkFormat GetTextureFormat() const;
  25. VkFence GetFence() const { return m_fence; }
  26. VkCommandBuffer GetCommandBuffer() const { return m_commandBuffer; }
  27. private:
  28. VkImage m_textureImage;
  29. VkDeviceMemory m_textureImageMemory;
  30. VkDeviceSize m_textureImageMemorySize;
  31. VkPhysicalDevice m_physicalDevice;
  32. VkDevice m_device;
  33. VkCommandPool m_commandPool;
  34. VkFence m_fence;
  35. VkCommandBuffer m_commandBuffer;
  36. VkFormat m_textureFormat;
  37. UnityVulkanImage m_unityVulkanImage;
  38. const VkAllocationCallbacks* m_allocator = nullptr;
  39. };
  40. //---------------------------------------------------------------------------------------------------------------------
  41. void* VulkanTexture2D::GetNativeTexturePtrV() { return &m_unityVulkanImage; }
  42. const void* VulkanTexture2D::GetNativeTexturePtrV() const { return &m_unityVulkanImage; };
  43. void* VulkanTexture2D::GetEncodeTexturePtrV() { return nullptr; }
  44. const void* VulkanTexture2D::GetEncodeTexturePtrV() const { return nullptr; }
  45. VkImage VulkanTexture2D::GetImage() const { return m_textureImage; }
  46. VkDeviceMemory VulkanTexture2D::GetTextureImageMemory() const { return m_textureImageMemory; }
  47. VkDeviceSize VulkanTexture2D::GetTextureImageMemorySize() const { return m_textureImageMemorySize; }
  48. VkFormat VulkanTexture2D::GetTextureFormat() const { return m_textureFormat; }
  49. } // end namespace unity
  50. } // end namespace webrtc