Skip to content

Commit

Permalink
Finished Episode 8. Added dynamic viewports. Updated Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
Sargates committed Mar 2, 2024
1 parent f9d4c78 commit 72c5cd9
Show file tree
Hide file tree
Showing 13 changed files with 240 additions and 103 deletions.
17 changes: 17 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Copyright 2024- Nick Glenn
Copyright 2020- Brendan Galea

Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the “Software”), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies
or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16 changes: 13 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ SRC_DIR := src
SRC_FILES := $(call rwildcard,$(SRC_DIR)/,*.cpp)
# Directory to store `.o` files
OBJ_DIR := obj

# These two lines compile all object files from updated `.cpp` files, I do not understand this
OBJ_FILES := $(patsubst $(SRC_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(filter $(SRC_DIR)/%.cpp,$(SRC_FILES))) \
$(patsubst %.cpp,$(OBJ_DIR)/%.o,$(filter-out $(SRC_DIR)/%.cpp,$(SRC_FILES)))
INCLUDE_DIR := include
HEADER_FILES := $(call rwildcard,$(INCLUDE_DIR)/,*.hpp)

# Rule for compiling source files
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(HEADER_FILES)
@echo -n "$@ "
@mkdir -p $(@D)
@$(CXX) -c $< -o $@ $(CXXFLAGS)

Expand All @@ -27,12 +30,14 @@ SHADER_FRAG_FILES := $(call rwildcard,$(SHADER_DIR)/,*.frag)
SHADER_VERT_SPIRV_FILES := $(patsubst $(SHADER_DIR)/%.vert,$(SHADER_OUT_DIR)/%.vert.spv,$(filter $(SHADER_DIR)/%.vert,$(SHADER_VERT_FILES))) \
$(patsubst %.vert,$(SHADER_OUT_DIR)/%.vert.spv,$(filter-out $(SHADER_DIR)/%.vert,$(SHADER_VERT_FILES)))
$(SHADER_OUT_DIR)/%.vert.spv: $(SHADER_DIR)/%.vert
@echo "Compiling Vertex Shaders"
@mkdir -p $(@D)
@$(GLSLC) -c $< -o $@

SHADER_FRAG_SPIRV_FILES := $(patsubst $(SHADER_DIR)/%.frag,$(SHADER_OUT_DIR)/%.frag.spv,$(filter $(SHADER_DIR)/%.frag,$(SHADER_FRAG_FILES))) \
$(patsubst %.frag,$(SHADER_OUT_DIR)/%.frag.spv,$(filter-out $(SHADER_DIR)/%.frag,$(SHADER_FRAG_FILES)))
$(SHADER_OUT_DIR)/%.frag.spv: $(SHADER_DIR)/%.frag
@echo "Compiling Fragment Shaders"
@mkdir -p $(@D)
@$(GLSLC) -c $< -o $@

Expand All @@ -43,6 +48,9 @@ PROGRAM := main


program: $(OBJ_FILES)
@echo ""
@echo "Object Files Compiled!"
@echo "Compiling Executable..."
$(CXX) $^ -o $(PROGRAM) $(CXXFLAGS)


Expand All @@ -53,9 +61,10 @@ windows:
--no-print-directory
@echo "Shaders Compiled!"

@echo -n "Compiling Object Files: "
@$(MAKE) program \
CXX="x86_64-w64-mingw32-g++" \
CXXFLAGS="-I include -L lib/x86_64-w64-mingw32 -lopengl32 -lglfw3dll -lvulkan -std=c++20 -static-libgcc -static-libstdc++" \
CXXFLAGS="-I include -L lib/x86_64-w64-mingw32 -lopengl32 -lglfw3dll -lvulkan -std=c++20" \
--no-print-directory

linux:
Expand All @@ -65,6 +74,7 @@ linux:
--no-print-directory
@echo "Shaders Compiled!"

@echo -n "Compiling Object Files: "
@$(MAKE) program \
CXX="g++" \
CXXFLAGS="-I include -L lib/x86_64-linux-gnu -lglfw3 -lvulkan -lGL -std=c++20" \
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Vulkan-Engine-cpp
This is a game engine prototype I'm creating by following [this tutorial](https://www.youtube.com/playlist?list=PL8327DO66nu9qYVKLDmdLW_84-yE4auCR)



5 changes: 4 additions & 1 deletion include/first_app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ namespace lve {
void createPipelineLayout();
void createPipeline();
void createCommandBuffers();
void freeCommandBuffers();
void drawFrame();
void recreateSwapChain();
void recordCommandBuffer(int imageIndex);

LveWindow lveWindow{WIDTH, HEIGHT, "Hello Vulkan!"};
LveDevice lveDevice{lveWindow};
LveSwapChain lveSwapChain{lveDevice, lveWindow.getExtent()};
std::unique_ptr<LveSwapChain> lveSwapChain; // {lveDevice, lveWindow.getExtent()}
std::unique_ptr<LvePipeline> lvePipeline;
VkPipelineLayout pipelineLayout;
std::vector<VkCommandBuffer> commandBuffers;
Expand Down
2 changes: 2 additions & 0 deletions include/glm/detail/setup.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma once

#ifndef GLM_SETUP_INCLUDED

#include <cassert>
Expand Down
2 changes: 1 addition & 1 deletion include/glm/glm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@
/// at once by including <glm/ext.hpp>. Otherwise, each extension needs to be
/// included a specific file.
///
#pragma once

#include "detail/_fixes.hpp"

#include "detail/setup.hpp"

#pragma once

#include <cmath>
#include <climits>
Expand Down
18 changes: 13 additions & 5 deletions include/lve_pipeline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@
namespace lve {

struct PipelineConfigInfo {
VkViewport viewport;
VkRect2D scissor;
PipelineConfigInfo() = default; // Idk why, this line is required or it doesn't compile. Video doesn't use this -- idk
PipelineConfigInfo(const PipelineConfigInfo&) = delete;
PipelineConfigInfo &operator=(const PipelineConfigInfo&) = delete;

VkPipelineViewportStateCreateInfo viewportInfo;
VkPipelineInputAssemblyStateCreateInfo inputAssemblyInfo;
VkPipelineRasterizationStateCreateInfo rasterizationInfo;
VkPipelineMultisampleStateCreateInfo multisampleInfo;
VkPipelineColorBlendAttachmentState colorBlendAttachment;
VkPipelineColorBlendStateCreateInfo colorBlendInfo;
VkPipelineDepthStencilStateCreateInfo depthSencilInfo;
VkPipelineDepthStencilStateCreateInfo depthStencilInfo;
std::vector<VkDynamicState> dynamicStateEnables;
VkPipelineDynamicStateCreateInfo dynamicStateInfo;
VkPipelineLayout pipelineLayout = nullptr;
VkRenderPass renderPass = nullptr;
uint32_t subpass = 0;
Expand All @@ -31,11 +36,14 @@ namespace lve {
LvePipeline& operator=(const LvePipeline&) = delete;

void bind(VkCommandBuffer commandBuffer);
static PipelineConfigInfo defaultPipelineConfigInfo(uint32_t width, uint32_t height);
static void defaultPipelineConfigInfo(PipelineConfigInfo& configInfo);

private:
static std::vector<char> readFile(const std::string& filepath);
void createGraphicsPipeline(const std::string& vertFilePath, const std::string& fragFilePath, const PipelineConfigInfo& configInfo);
void createGraphicsPipeline(
const std::string& vertFilePath,
const std::string& fragFilePath,
const PipelineConfigInfo& configInfo);
void createShaderModule(const std::vector<char>& code, VkShaderModule* shaderModule);

LveDevice& lveDevice;
Expand Down
4 changes: 4 additions & 0 deletions include/lve_swap_chain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <vulkan/vulkan.h>

// std lib headers
#include <memory>
#include <string>
#include <vector>

Expand All @@ -16,6 +17,7 @@ namespace lve {
static constexpr int MAX_FRAMES_IN_FLIGHT = 2;

LveSwapChain(LveDevice &deviceRef, VkExtent2D windowExtent);
LveSwapChain(LveDevice &deviceRef, VkExtent2D windowExtent, std::shared_ptr<LveSwapChain> previous);
~LveSwapChain();

LveSwapChain(const LveSwapChain &) = delete;
Expand All @@ -39,6 +41,7 @@ namespace lve {
VkResult submitCommandBuffers(const VkCommandBuffer *buffers, uint32_t *imageIndex);

private:
void init();
void createSwapChain();
void createImageViews();
void createDepthResources();
Expand Down Expand Up @@ -69,6 +72,7 @@ namespace lve {
VkExtent2D windowExtent;

VkSwapchainKHR swapChain;
std::shared_ptr<LveSwapChain> oldSwapChain;

std::vector<VkSemaphore> imageAvailableSemaphores;
std::vector<VkSemaphore> renderFinishedSemaphores;
Expand Down
9 changes: 6 additions & 3 deletions include/lve_window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ namespace lve {


bool shouldClose() { return glfwWindowShouldClose(window); }

VkExtent2D getExtent() { return {static_cast<uint32_t>(width), static_cast<uint32_t>(height)}; };

bool wasWindowResized() { return frameBufferResized; }
void resetWindowResizedFlag() { frameBufferResized = false; }

void createWindowSurface(VkInstance instance, VkSurfaceKHR* surface);
GLFWwindow* getWindow();
private:
static void frameBufferResizedCallback(GLFWwindow* window, int width, int height);
void initWindow();
const int width, height;
int width, height;
bool frameBufferResized = false;
std::string windowName;

GLFWwindow* window;
Expand Down
Loading

0 comments on commit 72c5cd9

Please sign in to comment.