Skip to content

Commit

Permalink
Added the blitz namespace to all necessary files
Browse files Browse the repository at this point in the history
  • Loading branch information
tstullich committed Oct 21, 2020
1 parent a8c4db8 commit 577d273
Show file tree
Hide file tree
Showing 18 changed files with 181 additions and 153 deletions.
18 changes: 9 additions & 9 deletions src/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// TODO Create a separate command pool for copying buffers and use VK_COMMAND_POOL_CREATE_TRANSIENT_BIT
// during command pool creation
void Buffer::copyBuffer(const BufferContext &ctx, VkBuffer src, VkBuffer dst, VkDeviceSize size) {
void blitz::Buffer::copyBuffer(const BufferContext &ctx, VkBuffer src, VkBuffer dst, VkDeviceSize size) {
VkCommandBufferAllocateInfo allocateInfo = {};
allocateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
allocateInfo.commandPool = ctx.commandPool;
Expand Down Expand Up @@ -43,13 +43,13 @@ void Buffer::copyBuffer(const BufferContext &ctx, VkBuffer src, VkBuffer dst, Vk
}


void Buffer::cleanup(VkDevice logicalDevice) {
void blitz::Buffer::cleanup(VkDevice logicalDevice) {
vkDestroyBuffer(logicalDevice, buffer, nullptr);
vkFreeMemory(logicalDevice, deviceMemory, nullptr);
}

void Buffer::allocateMemory(const BufferContext &ctx, VkDeviceSize size, VkBufferUsageFlags usage,
VkMemoryPropertyFlags properties, VkBuffer &buf, VkDeviceMemory &devMem) {
void blitz::Buffer::allocateMemory(const Buffer::BufferContext &ctx, VkDeviceSize size, VkBufferUsageFlags usage,
VkMemoryPropertyFlags properties, VkBuffer &buf, VkDeviceMemory &devMem) {
VkBufferCreateInfo bufferInfo = {};
bufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
bufferInfo.size = size;
Expand All @@ -76,7 +76,7 @@ void Buffer::allocateMemory(const BufferContext &ctx, VkDeviceSize size, VkBuffe
vkBindBufferMemory(ctx.logicalDevice, buf, devMem, 0);
}

uint32_t Buffer::pickMemoryType(VkPhysicalDevice physicalDevice, uint32_t typeFilter, VkMemoryPropertyFlags properties) {
uint32_t blitz::Buffer::pickMemoryType(VkPhysicalDevice physicalDevice, uint32_t typeFilter, VkMemoryPropertyFlags properties) {
VkPhysicalDeviceMemoryProperties memProperties;
vkGetPhysicalDeviceMemoryProperties(physicalDevice, &memProperties);

Expand All @@ -89,7 +89,7 @@ uint32_t Buffer::pickMemoryType(VkPhysicalDevice physicalDevice, uint32_t typeFi
throw std::runtime_error("Unable to find proper memory type on the GPU!");
}

void VertexBuffer::create(const BufferContext &ctx, const std::vector<Vertex> &vertices) {
void blitz::VertexBuffer::create(const BufferContext &ctx, const std::vector<Vertex> &vertices) {
VkDeviceSize bufferSize = sizeof(vertices[0]) * vertices.size();

// We use a staging buffer to transfer the host buffer data to the GPU
Expand All @@ -114,7 +114,7 @@ void VertexBuffer::create(const BufferContext &ctx, const std::vector<Vertex> &v
vkFreeMemory(ctx.logicalDevice, stagingMemory, nullptr);
}

void IndexBuffer::create(const BufferContext &ctx, const std::vector<uint32_t> &vertIndices) {
void blitz::IndexBuffer::create(const BufferContext &ctx, const std::vector<uint32_t> &vertIndices) {
VkDeviceSize bufferSize = sizeof(vertIndices[0]) * vertIndices.size();

VkBuffer stagingBuffer;
Expand All @@ -137,14 +137,14 @@ void IndexBuffer::create(const BufferContext &ctx, const std::vector<uint32_t> &
vkFreeMemory(ctx.logicalDevice, stagingMemory, nullptr);
}

void UniformBuffer::create(const BufferContext &ctx, const Camera &camera) {
void blitz::UniformBuffer::create(const BufferContext &ctx, const Camera &camera) {
VkDeviceSize bufferSize = sizeof(Camera);

allocateMemory(ctx, bufferSize, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, buffer, deviceMemory);
}

void TextureBuffer::create(const Buffer::BufferContext &ctx, const tinygltf::Image &textureImage) {
void blitz::TextureBuffer::create(const Buffer::BufferContext &ctx, const tinygltf::Image &textureImage) {
VkDeviceSize bufferSize = textureImage.image.size();

allocateMemory(ctx, bufferSize, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
Expand Down
4 changes: 3 additions & 1 deletion src/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "vertex.h"

// TODO Templatize this logic since vertex and index buffer creation is almost identical
namespace blitz {
class Buffer {
public:
struct BufferContext {
Expand Down Expand Up @@ -67,4 +68,5 @@ class TextureBuffer : public Buffer {
TextureBuffer() = default;

void create(const BufferContext &ctx, const tinygltf::Image &textureImage);
};
};
} // namespace blitz
4 changes: 3 additions & 1 deletion src/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>

namespace blitz {
struct Camera {
Camera() = default;

Expand All @@ -18,4 +19,5 @@ struct Camera {
glm::mat4 model = {};
glm::mat4 view = {};
glm::mat4 proj = {};
};
};
} // namespace blitz
2 changes: 1 addition & 1 deletion src/gltfloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "tiny_gltf.h"

tinygltf::Model GLTFLoader::load(const std::string &filePath) {
tinygltf::Model blitz::GLTFLoader::load(const std::string &filePath) {
tinygltf::Model model;
tinygltf::TinyGLTF loader;
std::string error;
Expand Down
2 changes: 2 additions & 0 deletions src/gltfloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

#include "tiny_gltf.h"

namespace blitz {
class GLTFLoader {
public:
GLTFLoader() = delete;

static tinygltf::Model load(const std::string &filePath);
};
} // namespace blitz
10 changes: 5 additions & 5 deletions src/image.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "image.h"

Image::Image(VkDevice logicalDevice, const VkImageCreateInfo &imageInfo) {
blitz::Image::Image(VkDevice logicalDevice, const VkImageCreateInfo &imageInfo) {
createImage(logicalDevice, imageInfo);
}

void Image::bindImage(VkDevice logicalDevice, uint32_t memoryTypeIndex, VkImageAspectFlagBits aspectFlags) {
void blitz::Image::bindImage(VkDevice logicalDevice, uint32_t memoryTypeIndex, VkImageAspectFlagBits aspectFlags) {
VkMemoryRequirements memRequirements;
vkGetImageMemoryRequirements(logicalDevice, image, &memRequirements);

Expand All @@ -23,13 +23,13 @@ void Image::bindImage(VkDevice logicalDevice, uint32_t memoryTypeIndex, VkImageA
createImageView(logicalDevice, aspectFlags);
}

void Image::cleanup(VkDevice logicalDevice) {
void blitz::Image::cleanup(VkDevice logicalDevice) {
vkDestroyImageView(logicalDevice, imageView, nullptr);
vkDestroyImage(logicalDevice, image, nullptr);
vkFreeMemory(logicalDevice, imageMemory, nullptr);
}

void Image::createImage(VkDevice logicalDevice, const VkImageCreateInfo &imageCreateInfo) {
void blitz::Image::createImage(VkDevice logicalDevice, const VkImageCreateInfo &imageCreateInfo) {
// Store the image format and mip levels for later use
format = imageCreateInfo.format;
mipLevels = imageCreateInfo.mipLevels;
Expand All @@ -40,7 +40,7 @@ void Image::createImage(VkDevice logicalDevice, const VkImageCreateInfo &imageCr
}
}

void Image::createImageView(VkDevice logicalDevice, VkImageAspectFlagBits aspectFlags) {
void blitz::Image::createImageView(VkDevice logicalDevice, VkImageAspectFlagBits aspectFlags) {
VkImageViewCreateInfo viewInfo = {};
viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
viewInfo.image = image;
Expand Down
4 changes: 3 additions & 1 deletion src/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <vulkan/vulkan.h>

namespace blitz {
class Image {
public:
Image() = default;
Expand Down Expand Up @@ -37,4 +38,5 @@ class Image {
VkDeviceMemory imageMemory = {};
VkExtent3D extent = {};
uint32_t mipLevels = 1;
};
};
} // namespace blitz
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "renderer.h"

int main() {
Renderer app;
blitz::Renderer app;
try {
app.run();
} catch (std::exception &e) {
Expand Down
Loading

0 comments on commit 577d273

Please sign in to comment.