coral_texture.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #pragma once
  2. #include <memory>
  3. #include "vk_types.h"
  4. #include "coral_device.h"
  5. namespace coral_3d
  6. {
  7. class coral_texture final
  8. {
  9. public:
  10. coral_texture(coral_device& device, AllocatedImage image, uint32_t mip_levels, VkFormat format);
  11. ~coral_texture();
  12. static std::unique_ptr<coral_texture> create_texture_from_file(coral_device& device, const std::string& file_path, VkFormat format);
  13. AllocatedImage image() const { return image_; }
  14. VkImageView image_view() const { return image_view_; }
  15. VkSampler sampler() const { return sampler_; }
  16. VkDescriptorImageInfo get_descriptor_info() const
  17. {
  18. VkDescriptorImageInfo descriptor_info{};
  19. descriptor_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
  20. descriptor_info.imageView = image_view_;
  21. descriptor_info.sampler = sampler_;
  22. return descriptor_info;
  23. }
  24. private:
  25. struct Builder
  26. {
  27. AllocatedImage image;
  28. uint32_t mip_levels;
  29. bool load_image_from_file(coral_device& device, const std::string& file_name, VkFormat format);
  30. void generate_mipmaps(coral_device& device, uint32_t width, uint32_t height);
  31. };
  32. void create_image_view(VkFormat format);
  33. void create_texture_sampler();
  34. coral_device& device_;
  35. AllocatedImage image_;
  36. VkImageView image_view_;
  37. VkSampler sampler_;
  38. // MIP MAPS
  39. uint32_t mip_levels_;
  40. };
  41. }