Skip to content

Commit f2353a2

Browse files
committed
Added semaphore and fence wrappers
1 parent aaad74f commit f2353a2

File tree

4 files changed

+159
-0
lines changed

4 files changed

+159
-0
lines changed

examples/resources/meshes/box.obj

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# 3ds Max Wavefront OBJ Exporter v0.99 - (c)2007 guruware
2+
# File Created: 17.03.2023 20:06:14
3+
4+
#
5+
# object Box001
6+
#
7+
8+
v -0.5000 -0.5000 0.5000
9+
v 0.5000 -0.5000 0.5000
10+
v -0.5000 -0.5000 -0.5000
11+
v 0.5000 -0.5000 -0.5000
12+
v -0.5000 0.5000 0.5000
13+
v 0.5000 0.5000 0.5000
14+
v -0.5000 0.5000 -0.5000
15+
v 0.5000 0.5000 -0.5000
16+
# 8 vertices
17+
18+
vn 0.0000 -1.0000 -0.0000
19+
vn 0.0000 -1.0000 -0.0000
20+
vn 0.0000 -1.0000 -0.0000
21+
vn 0.0000 -1.0000 -0.0000
22+
vn 0.0000 1.0000 -0.0000
23+
vn 0.0000 1.0000 -0.0000
24+
vn 0.0000 1.0000 -0.0000
25+
vn 0.0000 1.0000 -0.0000
26+
vn 0.0000 0.0000 1.0000
27+
vn 0.0000 0.0000 1.0000
28+
vn 0.0000 0.0000 1.0000
29+
vn 0.0000 0.0000 1.0000
30+
vn 1.0000 0.0000 -0.0000
31+
vn 1.0000 0.0000 -0.0000
32+
vn 1.0000 0.0000 -0.0000
33+
vn 1.0000 0.0000 -0.0000
34+
vn 0.0000 0.0000 -1.0000
35+
vn 0.0000 0.0000 -1.0000
36+
vn 0.0000 0.0000 -1.0000
37+
vn 0.0000 0.0000 -1.0000
38+
vn -1.0000 0.0000 -0.0000
39+
vn -1.0000 0.0000 -0.0000
40+
vn -1.0000 0.0000 -0.0000
41+
vn -1.0000 0.0000 -0.0000
42+
# 24 vertex normals
43+
44+
vt 1.0000 0.0000 0.0000
45+
vt 1.0000 1.0000 0.0000
46+
vt 0.0000 1.0000 0.0000
47+
vt 0.0000 0.0000 0.0000
48+
# 4 texture coords
49+
50+
o Box001
51+
g Box001
52+
f 3/2/1 4/3/2 2/4/3 1/1/4
53+
f 6/1/5 8/2/6 7/3/7 5/4/8
54+
f 2/1/9 6/2/10 5/3/11 1/4/12
55+
f 4/1/13 8/2/14 6/3/15 2/4/16
56+
f 3/1/17 7/2/18 8/3/19 4/4/20
57+
f 1/1/21 5/2/22 7/3/23 3/4/24
58+
# 6 polygons
59+
7.77 MB
Loading
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
This file is part of Vulkan-Engine, a simple to use Vulkan based 3D library
3+
4+
MIT License
5+
6+
Copyright (c) 2023 Antonio Espinosa Garcia
7+
8+
*/
9+
////////////////////////////////////////////
10+
// SEMAPHORE AND FENCES
11+
///////////////////////////////////////////
12+
#ifndef SEMAPHORE_H
13+
#define SEMAPHORE_H
14+
15+
#include <engine/graphics/utilities/initializers.h>
16+
17+
VULKAN_ENGINE_NAMESPACE_BEGIN
18+
19+
namespace Graphics {
20+
21+
class Semaphore
22+
{
23+
VkSemaphore m_handle = VK_NULL_HANDLE;
24+
VkDevice m_device = VK_NULL_HANDLE;
25+
26+
public:
27+
Semaphore() {
28+
}
29+
~Semaphore() {
30+
cleanup();
31+
}
32+
33+
inline VkSemaphore get_handle() const {
34+
return m_handle;
35+
}
36+
37+
void init(VkDevice device);
38+
void cleanup();
39+
};
40+
41+
class Fence
42+
{
43+
VkFence m_handle = VK_NULL_HANDLE;
44+
VkDevice m_device = VK_NULL_HANDLE;
45+
46+
public:
47+
Fence() {
48+
}
49+
~Fence() {
50+
cleanup();
51+
}
52+
53+
inline VkFence get_handle() const {
54+
return m_handle;
55+
}
56+
57+
void init(VkDevice device);
58+
void cleanup();
59+
void reset();
60+
};
61+
62+
} // namespace Graphics
63+
64+
VULKAN_ENGINE_NAMESPACE_END
65+
#endif

src/graphics/semaphore.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <engine/graphics/semaphore.h>
2+
3+
VULKAN_ENGINE_NAMESPACE_BEGIN
4+
namespace Graphics {
5+
6+
void Semaphore::init(VkDevice device) {
7+
m_device = device;
8+
VkSemaphoreCreateInfo semaphoreCreateInfo = Init::semaphore_create_info();
9+
VK_CHECK(vkCreateSemaphore(device, &semaphoreCreateInfo, nullptr, &m_handle));
10+
}
11+
void Semaphore::cleanup() {
12+
if (m_handle != VK_NULL_HANDLE)
13+
{
14+
vkDestroySemaphore(m_device, m_handle, nullptr);
15+
m_handle = VK_NULL_HANDLE;
16+
}
17+
}
18+
void Fence::init(VkDevice device) {
19+
m_device = device;
20+
VkFenceCreateInfo fenceCreateInfo = Init::fence_create_info(VK_FENCE_CREATE_SIGNALED_BIT);
21+
VK_CHECK(vkCreateFence(device, &fenceCreateInfo, nullptr, &m_handle));
22+
}
23+
void Fence::cleanup() {
24+
if (m_handle != VK_NULL_HANDLE)
25+
{
26+
vkDestroyFence(m_device, m_handle, nullptr);
27+
m_handle = VK_NULL_HANDLE;
28+
}
29+
}
30+
void Fence::reset() {
31+
if (m_handle != VK_NULL_HANDLE)
32+
VK_CHECK(vkResetFences(m_device, 1, &m_handle));
33+
}
34+
} // namespace Graphics
35+
VULKAN_ENGINE_NAMESPACE_END

0 commit comments

Comments
 (0)