-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBindable.h
More file actions
76 lines (65 loc) · 1.61 KB
/
Bindable.h
File metadata and controls
76 lines (65 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#pragma once
#include "pch.h"
struct Sampler
{
static VkSampler Create(VkSamplerAddressMode mode, uint mip);
};
struct Bindable
{
VkDescriptorType type;
union DescriptorInfo
{
VkDescriptorImageInfo image;
VkDescriptorBufferInfo buffer;
} info;
DescriptorInfo& GetDescriptorInfo()
{
return info;
}
};
template<class T>
concept Bindable_T = std::is_base_of_v<Bindable, T>;
struct Buffer : Bindable
{
uint64 memory;
void* ptr;
VkBuffer& handle() { return info.buffer.buffer; }
static Buffer* Create(VkBufferUsageFlags usage, uint size, DeviceMemoryTypeIndex mem);
static Buffer* Create(VkBufferUsageFlags usage, uint size);
static Buffer* Create(VkBufferUsageFlags usage, uint size, void* src);
void Free();
template<class T> T* Get() { return (T*)ptr; }
};
struct Image : Bindable
{
uint64 memory;
VkImage handle;
VkImageView& view() { return info.image.imageView; }
VkSampler& sampler() { return info.image.sampler; }
VkImageLayout& layout() { return info.image.imageLayout; }
static Image* Create(VkFormat format, VkImageUsageFlags usage, VkExtent2D extent, uint mip, uint ms, VkImageAspectFlags aspect);
void Free();
};
struct Texture : Image
{
static Texture* Create(const char* path, VkFormat format);
void Free();
};
enum PBRSlot
{
PBR_ALBEDO = 0,
PBR_NORMAL = 1,
PBR_METALIC = 2,
};
struct Material
{
Texture* textures[3] = {
Texture::Create("white.png", VK_FORMAT_R8G8B8A8_SRGB),
Texture::Create("normal.png", VK_FORMAT_R8G8B8A8_UNORM) ,
Texture::Create("white.png", VK_FORMAT_R8G8B8A8_UNORM)
};
void SetTexture(Texture* tex, PBRSlot slot)
{
if(tex) textures[slot] = tex;
}
};