Skip to content

Commit b64da55

Browse files
committed
Add header comment blocks to and small code tweaks
1 parent 2362a09 commit b64da55

17 files changed

+89
-24
lines changed

src/Buffer.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ Buffer::Buffer(const VkDevice device,
2929
vkGetPhysicalDeviceMemoryProperties(physicalDevice, &supportedMemoryProperties);
3030

3131
const VkMemoryPropertyFlags typeFilter = memoryRequirements.memoryTypeBits;
32-
uint32_t memoryTypeIndex = 0u;
32+
uint32_t suitableMemoryTypeIndex = 0u;
3333
bool memoryTypeFound = false;
34-
for (uint32_t i = 0u; i < supportedMemoryProperties.memoryTypeCount; ++i)
34+
for (uint32_t memoryTypeIndex = 0u; memoryTypeIndex < supportedMemoryProperties.memoryTypeCount; ++memoryTypeIndex)
3535
{
36-
const VkMemoryPropertyFlags propertyFlags = supportedMemoryProperties.memoryTypes[i].propertyFlags;
37-
if (typeFilter & (1 << i) && (propertyFlags & memoryProperties) == memoryProperties)
36+
const VkMemoryPropertyFlags propertyFlags = supportedMemoryProperties.memoryTypes[memoryTypeIndex].propertyFlags;
37+
if (typeFilter & (1 << memoryTypeIndex) && (propertyFlags & memoryProperties) == memoryProperties)
3838
{
39-
memoryTypeIndex = i;
39+
suitableMemoryTypeIndex = memoryTypeIndex;
4040
memoryTypeFound = true;
4141
break;
4242
}
@@ -51,7 +51,7 @@ Buffer::Buffer(const VkDevice device,
5151

5252
VkMemoryAllocateInfo memoryAllocateInfo{ VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO };
5353
memoryAllocateInfo.allocationSize = memoryRequirements.size;
54-
memoryAllocateInfo.memoryTypeIndex = memoryTypeIndex;
54+
memoryAllocateInfo.memoryTypeIndex = suitableMemoryTypeIndex;
5555
if (vkAllocateMemory(device, &memoryAllocateInfo, nullptr, &deviceMemory) != VK_SUCCESS)
5656
{
5757
std::stringstream s;

src/Buffer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
#include <vulkan/vulkan.h>
44

5+
/*
6+
* The buffer class is used to store Vulkan data buffers, namely the uniform buffer and the vertex/index buffer. It is
7+
* unrelated to Vulkan image buffers used for the depth buffer for example. Note that is good for performance to keep
8+
* Vulkan buffers mapped until destruction. This class offers functionality to do so, but doesn't enfore the principle.
9+
*/
510
class Buffer final
611
{
712
public:

src/Context.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,9 @@ Context::Context()
285285
return;
286286
}
287287

288-
for (uint32_t i = 0u; i < requiredExtensionCount; ++i)
288+
for (uint32_t extensionIndex = 0u; extensionIndex < requiredExtensionCount; ++extensionIndex)
289289
{
290-
vulkanInstanceExtensions.push_back(buffer[i]);
290+
vulkanInstanceExtensions.push_back(buffer[extensionIndex]);
291291
}
292292
}
293293

src/Context.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
33
#include <vulkan/vulkan.h>
44

55
#define XR_USE_GRAPHICS_API_VULKAN
6-
#include <openxr/openxr.h>
76
#include <openxr/openxr_platform.h>
87

8+
/*
9+
* The context class handles the initial loading of both OpenXR and Vulkan base functionality such as instances, OpenXR
10+
* sessions, Vulkan devices and queues, and so on. It also loads debug utility messengers for both OpenXR and Vulkan if
11+
* the preprocessor macro DEBUG is defined. This enables console output that is crucial to finding potential issues in
12+
* OpenXR or Vulkan.
13+
*/
914
class Context final
1015
{
1116
public:

src/Controllers.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
#include <vector>
88

9+
/*
10+
* The controllers class handles OpenXR controller support. It represents the controller system as a whole, not an
11+
* individual controller. This is more convenient due to the OpenXR API. It allows the application to retrieve the
12+
* current transform of a controller, which is then used to accuretely pose the hand models in the scene.
13+
*/
914
class Controllers final
1015
{
1116
public:
@@ -20,10 +25,10 @@ class Controllers final
2025
private:
2126
bool valid = true;
2227

23-
XrSession session;
28+
XrSession session = nullptr;
2429
std::vector<XrPath> paths;
25-
XrActionSet actionSet;
26-
XrAction action;
30+
XrActionSet actionSet = nullptr;
31+
XrAction action = nullptr;
2732
std::vector<XrSpace> spaces;
2833
std::vector<glm::mat4> transforms;
2934
};

src/Headset.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "RenderTarget.h"
55
#include "Util.h"
66

7+
#include <glm/mat4x4.hpp>
8+
79
#include <array>
810
#include <sstream>
911

@@ -226,14 +228,14 @@ Headset::Headset(const Context* context) : context(context)
226228

227229
const VkMemoryPropertyFlags memoryProperties = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
228230
const VkMemoryPropertyFlags typeFilter = memoryRequirements.memoryTypeBits;
229-
uint32_t memoryTypeIndex = 0u;
231+
uint32_t suitableMemoryTypeIndex = 0u;
230232
bool memoryTypeFound = false;
231-
for (uint32_t i = 0u; i < supportedMemoryProperties.memoryTypeCount; ++i)
233+
for (uint32_t memoryTypeIndex = 0u; memoryTypeIndex < supportedMemoryProperties.memoryTypeCount; ++memoryTypeIndex)
232234
{
233-
const VkMemoryPropertyFlags propertyFlags = supportedMemoryProperties.memoryTypes[i].propertyFlags;
234-
if (typeFilter & (1 << i) && (propertyFlags & memoryProperties) == memoryProperties)
235+
const VkMemoryPropertyFlags propertyFlags = supportedMemoryProperties.memoryTypes[memoryTypeIndex].propertyFlags;
236+
if (typeFilter & (1 << memoryTypeIndex) && (propertyFlags & memoryProperties) == memoryProperties)
235237
{
236-
memoryTypeIndex = i;
238+
suitableMemoryTypeIndex = memoryTypeIndex;
237239
memoryTypeFound = true;
238240
break;
239241
}
@@ -248,7 +250,7 @@ Headset::Headset(const Context* context) : context(context)
248250

249251
VkMemoryAllocateInfo memoryAllocateInfo{ VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO };
250252
memoryAllocateInfo.allocationSize = memoryRequirements.size;
251-
memoryAllocateInfo.memoryTypeIndex = memoryTypeIndex;
253+
memoryAllocateInfo.memoryTypeIndex = suitableMemoryTypeIndex;
252254
if (vkAllocateMemory(device, &memoryAllocateInfo, nullptr, &depthMemory) != VK_SUCCESS)
253255
{
254256
std::stringstream s;

src/Headset.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include <glm/mat4x4.hpp>
3+
#include <glm/fwd.hpp>
44

55
#include <openxr/openxr.h>
66

@@ -11,6 +11,12 @@
1111
class Context;
1212
class RenderTarget;
1313

14+
/*
15+
* The headset class facilitates rendering into the device. It holds functionality to begin and end rendering a frame,
16+
* to find out when the user has quit the application through the headset's operating system, as opposed to the mirror
17+
* view window, and to retrieve the current orientation of the device. It relies on both OpenXR and Vulkan to provide
18+
* these features.
19+
*/
1420
class Headset final
1521
{
1622
public:

src/MeshData.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ bool MeshData::loadModel(const std::string& filename,
2323

2424
for (const tinyobj::shape_t& shape : shapes)
2525
{
26-
for (size_t i = 0u; i < shape.mesh.indices.size(); ++i)
26+
for (const tinyobj::index_t& index : shape.mesh.indices)
2727
{
28-
const tinyobj::index_t index = shape.mesh.indices.at(i);
29-
3028
Vertex vertex;
3129

3230
vertex.position = { attrib.vertices[3 * index.vertex_index + 0], attrib.vertices[3 * index.vertex_index + 1],

src/MeshData.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,23 @@
77

88
struct Model;
99

10+
/*
11+
* The vertex struct provides the vertex definition used for all geometry in the project.
12+
*/
1013
struct Vertex final
1114
{
1215
glm::vec3 position;
1316
glm::vec3 normal;
1417
glm::vec3 color;
1518
};
1619

20+
/*
21+
* The mesh data class consists of a vertex and index collection for geometric data. It is not intended to stay alive in
22+
* memory after loading is done. It's purpose is rather to serve as a container for geometry data read in from OBJ model
23+
* files until that gets uploaded to a Vulkan vertex/index buffer on the GPU. Note that the models in the mesh data
24+
* class should be unique, a model that is rendered several times only needs to be loaded once. As many model structs as
25+
* required can then be derived from the same data.
26+
*/
1727
class MeshData final
1828
{
1929
public:

src/MirrorView.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include <glfw/glfw3.h>
1010

11+
#include <glm/common.hpp>
12+
1113
#include <sstream>
1214

1315
namespace

0 commit comments

Comments
 (0)