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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107 | // Create and Allocate a Buffer
static int CreateBuffer(uint64_t size, VkBufferUsageFlagBits usage, VkBuffer* pBuffer, VkDeviceMemory* pDevMemory)
{
// Setup The Buffer information
VkBufferCreateInfo bufferInfo = {};
bufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
bufferInfo.usage = usage;
bufferInfo.size = size;
bufferInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
// Create a Buffer
VkBuffer buffer;
VkResult res = vkCreateBuffer(_VkSystem.device, &bufferInfo, 0, &buffer);
if (res != VK_SUCCESS)
return 1;
// Get the Memory Requirements for the buffer
VkMemoryRequirements memoryReq;
vkGetBufferMemoryRequirements(_VkSystem.device, buffer, &memoryReq);
uint32_t typeIndex = FindMemoryType(memoryReq.memoryTypeBits, (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT));
if (typeIndex == -1)
DebugBreak();
// Setup Memory Allocation Information
VkMemoryAllocateInfo allocInfo = {};
allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
allocInfo.allocationSize = memoryReq.size;
allocInfo.memoryTypeIndex = typeIndex;
// Allocate device memory
VkDeviceMemory devMemory = {};
res = vkAllocateMemory(_VkSystem.device, &allocInfo, 0, &devMemory);
if (res != VK_SUCCESS)
return 1;
// Bind the Buffer to our Device Memory
res = vkBindBufferMemory(_VkSystem.device, buffer, devMemory, 0);
if (res != VK_SUCCESS)
return 1;
*pBuffer = buffer;
*pDevMemory = devMemory;
return res;
}
----------------------
#version 450
// vertices
layout(location=0)in vec2 pos;
// offset (position basically)
//layout(location=1)in vec2 offset;
#if 0
// uv
layout(location=2)in vec2 uvIn;
layout(location=5)out vec2 uv;
// texIdx
layout(location=3)in float texIdx;
layout(location=6)out float texIdxOut;
// size
layout(location=4)in vec2 size;
#endif
layout (set=0, binding = 0) uniform Block
{
// camera
vec2 camera;
// resolution (for scaling from pixels to NDC)
//vec2 pixelsToNdc;
};
vec2 positions[3] = vec2[](
vec2(0.0,-0.5),
vec2(0.5,0.5),
vec2(-0.5,0.5)
);
void main()
{
#if 0
texIdxOut = texIdx;
// set UV
uv = uvIn;
// set size of the object (square only)
vec2 newPos = (pos.xy*(vec2(64,64)*0.5));
//make 0,0 be the Top Left of the object drawn
newPos.xy -= vec2(-64,64)*0.5;
// offset position
newPos += vec2(offset.x,offset.y);
// offset camera
newPos += camera;
// scale to the resolution (so positions can be in pixels)
newPos *= pixelsToNdc;
// make (0,0) Top Left
newPos -= vec2(1,-1);
gl_Position = vec4(newPos,1.0,1.0);
#endif
vec2 test = pos + camera;
gl_Position = vec4(test,1,1);
}
|