Foray Library
rapid prototyping framework for crossplatform development of vulkan hardware ray tracing applications
Loading...
Searching...
No Matches
foray_texturemanager.hpp
Go to the documentation of this file.
1#pragma once
2#include "../../core/foray_managedimage.hpp"
3#include "../../core/foray_samplercollection.hpp"
4#include "../foray_component.hpp"
5#include <unordered_map>
6
7namespace foray::scene::gcomp {
10 {
11 public:
12 void Destroy();
13
14 virtual ~TextureManager() { Destroy(); }
15
16 struct Texture
17 {
18 public:
19 inline Texture() : mImage(), mSampler() { mSampler.SetManagedImage(&mImage); }
20 virtual ~Texture() = default;
21
22 FORAY_GETTER_CR(Image)
23 FORAY_GETTER_MR(Image)
24
25 inline VkDescriptorImageInfo GetDescriptorImageInfo(VkImageLayout layout = VkImageLayout::VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) const
26 {
28 }
29
30 FORAY_PROPERTY_R(Sampler)
31
32 protected:
35 };
36
37 FORAY_GETTER_CR(Textures)
38 FORAY_GETTER_MR(Textures)
39
40 std::vector<VkDescriptorImageInfo> GetDescriptorInfos(VkImageLayout layout = VkImageLayout::VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
41
42 inline Texture& PrepareTexture(int32_t texId)
43 {
44 Assert(!mTextures.contains(texId));
45 return mTextures[texId];
46 }
47
48 protected:
49 std::unordered_map<int32_t, Texture> mTextures;
50 };
51} // namespace foray::scene
Wraps an image + sampler combination.
Definition foray_samplercollection.hpp:61
VkDescriptorImageInfo GetVkDescriptorInfo(VkImageLayout layout=VkImageLayout::VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) const
Build descriptor image info.
Definition foray_samplercollection.hpp:85
Wraps allocation and lifetime functionality of VkImage.
Definition foray_managedimage.hpp:13
Definition foray_component.hpp:95
Manages textures and samplers.
Definition foray_texturemanager.hpp:10
std::vector< VkDescriptorImageInfo > GetDescriptorInfos(VkImageLayout layout=VkImageLayout::VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL)
std::unordered_map< int32_t, Texture > mTextures
Definition foray_texturemanager.hpp:49
Texture & PrepareTexture(int32_t texId)
Definition foray_texturemanager.hpp:42
virtual ~TextureManager()
Definition foray_texturemanager.hpp:14
#define FORAY_GETTER_CR(member)
Return constant reference.
Definition foray_basics.hpp:60
#define FORAY_GETTER_MR(member)
Return mutable reference.
Definition foray_basics.hpp:54
#define FORAY_PROPERTY_R(member)
Getter+Setter shorthand for reference types.
Definition foray_basics.hpp:86
Definition foray_scene_declares.hpp:16
void Assert(bool condition, const source_location location=source_location::current())
Asserts condition. Throws a generic error message if conditition is false.
Definition foray_exception.hpp:52
Definition foray_env.hpp:92
Definition foray_texturemanager.hpp:17
VkDescriptorImageInfo GetDescriptorImageInfo(VkImageLayout layout=VkImageLayout::VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) const
Definition foray_texturemanager.hpp:25
Texture()
Definition foray_texturemanager.hpp:19
core::ManagedImage mImage
Definition foray_texturemanager.hpp:33
core::CombinedImageSampler mSampler
Definition foray_texturemanager.hpp:34