From 0fefb85d0a69ce68778a08999d72d47df21e0a7f Mon Sep 17 00:00:00 2001 From: Lillian Salehi Date: Wed, 9 Oct 2024 02:53:44 -0500 Subject: [PATCH] Majorly cleaned up unnecessary includes and reformatted makefile to include shaders now. --- Makefile | 18 +++++++++++------- src/debug/vulkandebuglibs.cpp | 6 ------ src/debug/vulkandebuglibs.h | 4 +++- src/devicelibrary.cpp | 10 ---------- src/devicelibrary.h | 7 ++++++- src/entrypoint.cpp | 9 ++------- src/entrypoint.h | 2 -- src/global.h | 2 +- src/graphics/graphicspipeline.cpp | 13 ++++--------- src/graphics/graphicspipeline.h | 3 ++- src/main.cpp | 1 - src/shaders/frag.spv | Bin 572 -> 0 bytes src/shaders/{shader.frag => fragment.frag} | 0 src/shaders/vert.spv | Bin 1504 -> 0 bytes src/shaders/{shader.vert => vertex.vert} | 0 15 files changed, 29 insertions(+), 46 deletions(-) delete mode 100644 src/shaders/frag.spv rename src/shaders/{shader.frag => fragment.frag} (100%) delete mode 100644 src/shaders/vert.spv rename src/shaders/{shader.vert => vertex.vert} (100%) diff --git a/Makefile b/Makefile index d4d17b8..2de88c1 100644 --- a/Makefile +++ b/Makefile @@ -2,14 +2,13 @@ CPPFLAGS=-g LDFLAGS=-lglfw -lvulkan -ldl -lpthread -lX11 -lXxf86vm -lXrandr -lXi DEBUGFLAGS=-DDEBUG -fsanitize=address GDBFLAGS= -SRC = $(shell find . -name *.cpp) +SRC = $(shell find . -name "*.cpp") +SHDRSRC = $(shell find . -name "*.frag" -o -name "*vert") +SPV = $(SHDRSRC:%.vert=%.spv) $(SHDRSRC:%.frag=%.spv) OBJ = $(SRC:%.cpp=%.o) -VERTEX = $(src/shaders/%.vert=%.spv) -FRAGMENT = $(src/shaders/%.frag=%.spv) BIN=build/agnosiaengine - .PHONY: all all: $(BIN) @@ -28,25 +27,30 @@ debug: $(BIN) .PHONY: dep dep: - sudo pacman -S gcc glfw glm shaderc libxi libxxf86vm gdb glslc + sudo pacman -S gcc glfw glm shaderc libxi libxxf86vm gdb shaderc .PHONY: info info: @echo "make: Build executable" @echo "make dep: Make all required dependencies" @echo "make debug: Make with Debug hooked in" + @echo "make gdb: Make with GDB hooked in" @echo "make clean: Clean all files" @echo "make run: Run the executable after building" -$(BIN): $(OBJ) $(VERTEX) $(FRAGMENT) +$(BIN): $(OBJ) $(SPV) mkdir -p build g++ $(CPPFLAGS) -o $(BIN) $(OBJ) $(LDFLAGS) %.o: %.cpp g++ -c -g $< -o $@ $(LDFLAGS) -%.spv: %.vert %.frag + +%.spv: %.frag + glslc $< -o $@ +%.spv: %.vert glslc $< -o $@ .PHONY: clean clean: rm -rf build find . -name "*.o" -type f -delete + find . -name "*.spv" -type f -delete diff --git a/src/debug/vulkandebuglibs.cpp b/src/debug/vulkandebuglibs.cpp index f13d4bc..3cc31d1 100644 --- a/src/debug/vulkandebuglibs.cpp +++ b/src/debug/vulkandebuglibs.cpp @@ -1,12 +1,6 @@ #include "vulkandebuglibs.h" -#include "../global.h" using namespace Debug; -#include -#include -#include -#include - // This is our messenger object! It handles passing along debug messages to the debug callback we will also set. VkDebugUtilsMessengerEXT debugMessenger; // This is the set of "layers" to hook into. Basically, layers are used to tell the messenger what data we want, its a filter. *validation* is the general blanket layer to cover incorrect usage. diff --git a/src/debug/vulkandebuglibs.h b/src/debug/vulkandebuglibs.h index 225dc89..f8548c2 100644 --- a/src/debug/vulkandebuglibs.h +++ b/src/debug/vulkandebuglibs.h @@ -1,6 +1,8 @@ #pragma once -#include #include +#include +#include +#include "../global.h" namespace Debug { class vulkandebuglibs { diff --git a/src/devicelibrary.cpp b/src/devicelibrary.cpp index ff2eaf4..19e8e0e 100644 --- a/src/devicelibrary.cpp +++ b/src/devicelibrary.cpp @@ -1,16 +1,6 @@ #include "devicelibrary.h" #include "global.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include namespace DeviceControl { diff --git a/src/devicelibrary.h b/src/devicelibrary.h index c14c4b7..f170878 100644 --- a/src/devicelibrary.h +++ b/src/devicelibrary.h @@ -1,7 +1,12 @@ #pragma once #include "global.h" #include -#include +#include +#include +#include +#include +#include +#include namespace DeviceControl { class devicelibrary { public: diff --git a/src/entrypoint.cpp b/src/entrypoint.cpp index b53e4a6..7d28ace 100644 --- a/src/entrypoint.cpp +++ b/src/entrypoint.cpp @@ -5,7 +5,7 @@ Graphics::graphicspipeline graphicsPipeline; RenderPresent::render renderPresentation; VkInstance vulkaninstance; - +// Getters and Setters! void EntryApp::setFramebufferResized(bool setter) { framebufferResized = setter; } @@ -28,8 +28,6 @@ void initWindow() { glfwSetWindowUserPointer(Global::window, &EntryApp::getInstance()); glfwSetFramebufferSizeCallback(Global::window, framebufferResizeCallback); } - - void createInstance() { debugController.checkUnavailableValidationLayers(); // Check if there is a mistake with our Validation Layers. @@ -83,9 +81,6 @@ void cleanup() { // Similar to th renderPresentation.destroyFenceSemaphores(); graphicsPipeline.destroyCommandPool(); - deviceLibs.destroyImageViews(); - deviceLibs.destroySwapChain(); - vkDestroyDevice(Global::device, nullptr); if(Global::enableValidationLayers) { debugController.DestroyDebugUtilsMessengerEXT(vulkaninstance, nullptr); @@ -96,7 +91,7 @@ void cleanup() { // Similar to th glfwDestroyWindow(Global::window); glfwTerminate(); } - +// External Functions EntryApp& EntryApp::getInstance() { static EntryApp instance; return instance; diff --git a/src/entrypoint.h b/src/entrypoint.h index 615b12c..adc0ab7 100644 --- a/src/entrypoint.h +++ b/src/entrypoint.h @@ -19,6 +19,4 @@ class EntryApp { bool framebufferResized; bool initialized; - - }; diff --git a/src/global.h b/src/global.h index 83a9392..03e5849 100644 --- a/src/global.h +++ b/src/global.h @@ -1,9 +1,9 @@ #pragma once -#include "debug/vulkandebuglibs.h" #include #include #include #include +#include "debug/vulkandebuglibs.h" #define GLFW_INCLUDE_VULKAN #include diff --git a/src/graphics/graphicspipeline.cpp b/src/graphics/graphicspipeline.cpp index 9801d7a..b0bc62b 100644 --- a/src/graphics/graphicspipeline.cpp +++ b/src/graphics/graphicspipeline.cpp @@ -1,9 +1,5 @@ + #include "graphicspipeline.h" -#include "../devicelibrary.h" -#include -#include -#include -#include namespace Graphics { std::vector dynamicStates = { VK_DYNAMIC_STATE_VIEWPORT, @@ -57,8 +53,8 @@ namespace Graphics { void graphicspipeline::createGraphicsPipeline() { // Note to self, for some reason the working directory is not where a read file is called from, but the project folder! - auto vertShaderCode = readFile("src/shaders/vert.spv"); - auto fragShaderCode = readFile("src/shaders/frag.spv"); + auto vertShaderCode = readFile("src/shaders/vertex.spv"); + auto fragShaderCode = readFile("src/shaders/fragment.spv"); VkShaderModule vertShaderModule = createShaderModule(vertShaderCode, Global::device); VkShaderModule fragShaderModule = createShaderModule(fragShaderCode, Global::device); @@ -208,7 +204,7 @@ namespace Graphics { } void graphicspipeline::destroyRenderPass() { vkDestroyRenderPass(Global::device, renderPass, nullptr); - std::cout << "Destroyed Render Pass Safely\n" << std::endl; + if(Global::enableValidationLayers) std::cout << "Destroyed Render Pass Safely\n" << std::endl; } void graphicspipeline::createFramebuffers() { // Resize the container to hold all the framebuffers. @@ -275,7 +271,6 @@ namespace Graphics { if (vkBeginCommandBuffer(commandBuffer, &beginInfo) != VK_SUCCESS) { throw std::runtime_error("failed to begin recording command buffer!"); } - if(Global::enableValidationLayers) std::cout << "Recording command buffer...\n" << std::endl; VkRenderPassBeginInfo renderPassInfo{}; renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; diff --git a/src/graphics/graphicspipeline.h b/src/graphics/graphicspipeline.h index 953b640..258628c 100644 --- a/src/graphics/graphicspipeline.h +++ b/src/graphics/graphicspipeline.h @@ -1,6 +1,7 @@ #pragma once #include "../global.h" - +#include "../devicelibrary.h" +#include namespace Graphics { class graphicspipeline { public: diff --git a/src/main.cpp b/src/main.cpp index c1d1aff..6991f16 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,6 @@ #include "entrypoint.h" int main() { EntryApp::getInstance().initialize(); - try { EntryApp::getInstance().run(); } catch (const std::exception &e) { diff --git a/src/shaders/frag.spv b/src/shaders/frag.spv deleted file mode 100644 index da37f7ede672fe162b5322c32f5938a7836409a7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 572 zcmYk2PfNo<6vUrx)7IAhv!FMrcod2U6+zU4NG^dYet=MtD1q3NHWj@2+5A*q1n0LV z(uK*}H#=`OEEHA71Yeo8+BI6MPEqd}+{a8uKdhAl0+aGA( z6gLqLrRPob_)qk0tMXUiuge|}IP@J=^z`Vvs`?d4G32BH#;R0mT<^MFnDF)EG3?WD_tXer-10N+zk@OW-Q!$6U%CCwBbK=EWe5;z^DZB6pD_lbols z;A~j*!x>3aHS;kY(h;+8ZeOy&`7ymK{vghmXU$b^!qFcb-s$KIjvgFG49B?z%J}l= z0x|SK?oo}|e?!JvmI~dbYWN26s-mvEFI!W+9#DzNtqAiXd>L!E#+MXRzb-s0PYs+e z%-(zt{$-81PdMuF^D>sh3l;pmr?cT(i!wCuPIE=E)*Gi;5`e=TcU3Vp71u3$SQh4c z=*ctVHF^4QGps0vb2F^gd3a_3^ZuGMTo*Rxm-^|JwKs&|=o@qV%^JI$<8L*zhH;ugQp(6Q*-1WD5ekY5ZsgJ+w=n7uQ6v$J(%~2hWvAR>d7DJE${}JnT6)B z7*GDS5O0dRCFX88w^vfr+kF{*y_K4t9?H(LSvj4QYY=-~< diff --git a/src/shaders/shader.vert b/src/shaders/vertex.vert similarity index 100% rename from src/shaders/shader.vert rename to src/shaders/vertex.vert