From 1a7ca10c5f702dfa7de679e45aa5bac785dfa78f Mon Sep 17 00:00:00 2001
From: Leonie Franken <lfranken@uni-koblenz.de>
Date: Tue, 11 May 2021 17:56:43 +0200
Subject: [PATCH] fixed wrong filepaths in cmake build, work in progress
 reworking ShaderProgramm with the new Core structure

---
 config/Sources.cmake       |   6 +-
 src/vkcv/ShaderProgram.cpp |  24 +++++---
 src/vkcv/ShaderProgram.hpp | 113 +++++++++++++++++++++----------------
 3 files changed, 80 insertions(+), 63 deletions(-)

diff --git a/config/Sources.cmake b/config/Sources.cmake
index 5136110e..23c000fa 100644
--- a/config/Sources.cmake
+++ b/config/Sources.cmake
@@ -12,11 +12,7 @@ set(vkcv_sources
 
 		${vkcv_include}/vkcv/Window.hpp
 		${vkcv_source}/vkcv/Window.cpp
-<<<<<<< HEAD
-		${vkcv_source}/vkcv/CoreManager.hpp
-		${vkcv_source}/vkcv/CoreManager.cpp
+
 		${vkcv_source}/vkcv/ShaderProgram.hpp
 		${vkcv_source}/vkcv/ShaderProgram.cpp
-=======
->>>>>>> 74ff8e7041d7958006a434cf4d3a7fee0a3fa724
 )
diff --git a/src/vkcv/ShaderProgram.cpp b/src/vkcv/ShaderProgram.cpp
index 70a12a3c..917e192c 100644
--- a/src/vkcv/ShaderProgram.cpp
+++ b/src/vkcv/ShaderProgram.cpp
@@ -13,9 +13,11 @@ std::vector<const char*> validationLayers = {
 
 namespace vkcv {
 
-	ShaderProgram::ShaderProgram(vkcv::Context& context)
-		: m_context(context) 
-	{}
+	ShaderProgram::ShaderProgram(){
+	    ShaderStages m_shaderStages{};
+	    m_shaderStages.shaderCode = std::vector<std::vector<char>> ();
+	    m_shaderStages.shaderStageFlag = std::vector<vk::ShaderStageFlagBits> ();
+	}
 
 	std::vector<char> ShaderProgram::readFile(const std::string& filepath) {
 		std::ifstream file(filepath, std::ios::ate | std::ios::binary);
@@ -49,20 +51,24 @@ namespace vkcv {
 	ShaderProgram::~ShaderProgram() {
 	}
 
-	ShaderProgram ShaderProgram::create(vkcv::Context& context) {
-		return ShaderProgram(context);
+	ShaderProgram ShaderProgram::create() {
+		return ShaderProgram();
 	}
 
+	//TODO: Enum übergeben statt ShaderStageFlagBits
 	void ShaderProgram::addShader(vk::ShaderStageFlagBits shaderStage, const std::string& filepath) {
 		if (containsShaderStage(shaderStage)) {
 			throw std::runtime_error("Shader program already contains this particular shader stage.");
 		}
 		else {
 			auto shaderCode = readFile(filepath);
-			vk::ShaderModule shaderModule = createShaderModule(shaderCode);
-			vk::PipelineShaderStageCreateInfo shaderInfo = createShaderStage(shaderModule, shaderStage);
-			m_shaderStagesList.push_back(shaderInfo);
-			m_context.getDevice().destroyShaderModule(shaderModule, nullptr);
+			//vk::ShaderModule shaderModule = createShaderModule(shaderCode);
+			//vk::PipelineShaderStageCreateInfo shaderInfo = createShaderStage(shaderModule, shaderStage);
+			//m_shaderStagesList.push_back(shaderInfo);
+			//m_context.getDevice().destroyShaderModule(shaderModule, nullptr);
+			m_shaderStages.shaderCode.push_back(shaderCode);
+			m_shaderStages.shaderStageFlag.push_back(shaderStage);
+
 		}
 	}
 
diff --git a/src/vkcv/ShaderProgram.hpp b/src/vkcv/ShaderProgram.hpp
index ea7fe3c4..107b6d17 100644
--- a/src/vkcv/ShaderProgram.hpp
+++ b/src/vkcv/ShaderProgram.hpp
@@ -15,10 +15,74 @@
 namespace vkcv {
 
 	class ShaderProgram final {
+    public:
+
+        enum ShaderStage {VERTEX, FRAGMENT, COMPUTE};
+
+
+        /**
+        * destructor of ShaderProgram, does nothing so far
+        */
+        ~ShaderProgram();
+
+        /**
+        * Creates a shader program.
+        * So far it only calls the constructor.
+        * @param[in] context of the app
+        */
+        static ShaderProgram create();
+
+        /**
+        * Adds a shader into the shader program.
+        * The shader is only added if the shader program does not contain the particular shader stage already.
+        * Contains: (1) reading of the code, (2) creation of a shader module, (3) creation of a shader stage, (4) adding to the shader stage list, (5) destroying of the shader module
+        * @param[in] flag that signals the respective shaderStage (e.g. VK_SHADER_STAGE_VERTEX_BIT)
+        * @param[in] relative path to the shader code (e.g. "../../../../../shaders/vert.spv")
+        */
+        void addShader(vk::ShaderStageFlagBits shaderStage, const std::string& filepath);
+
+        /**
+        * Tests if the shader program contains a certain shader stage.
+        * @param[in] flag that signals the respective shader stage (e.g. VK_SHADER_STAGE_VERTEX_BIT)
+        * @return boolean that is true if the shader program contains the shader stage
+        */
+        bool containsShaderStage(vk::ShaderStageFlagBits shaderStage);
+
+        /**
+        * Deletes the given shader stage in the shader program.
+        * @param[in] flag that signals the respective shader stage (e.g. VK_SHADER_STAGE_VERTEX_BIT)
+        * @return boolean that is false if the shader stage was not found in the shader program
+        */
+        bool deleteShaderStage(vk::ShaderStageFlagBits shaderStage);
+
+        /**
+        * Returns a list with all the shader stages in the shader program.
+        * Needed for the transfer to the pipeline.
+        * @return vector list with all shader stage info structs
+        */
+        std::vector<vk::PipelineShaderStageCreateInfo> getShaderStages();
+
+        /**
+        * Returns the number of shader stages in the shader program.
+        * Needed for the transfer to the pipeline.
+        * @return integer with the number of stages
+        */
+        int getShaderStagesCount();
+
+
+
 	private:
 
+	    struct ShaderStages {
+            std::vector<std::vector<char>> shaderCode;
+            std::vector<vk::ShaderStageFlagBits> shaderStageFlag;
+	    };
+
 		vkcv::Context& m_context;
 		std::vector<vk::PipelineShaderStageCreateInfo> m_shaderStagesList;
+
+		ShaderStages m_shaderStages;
+
 		/**
 		* Constructor of ShaderProgram requires a context for the logical device. 
 		* @param context of the app
@@ -52,56 +116,7 @@ namespace vkcv {
 		vk::PipelineShaderStageCreateInfo createShaderStage(vk::ShaderModule& shaderModule, vk::ShaderStageFlagBits shaderStage);
 
 
-	public:
-
-		/**
-		* destructor of ShaderProgram, does nothing so far
-		*/
-		~ShaderProgram();
-
-		/**
-		* Creates a shader program.
-		* So far it only calls the constructor.
-		* @param[in] context of the app
-		*/
-		static ShaderProgram create(vkcv::Context& context);
-
-		/**
-		* Adds a shader into the shader program.
-		* The shader is only added if the shader program does not contain the particular shader stage already.
-		* Contains: (1) reading of the code, (2) creation of a shader module, (3) creation of a shader stage, (4) adding to the shader stage list, (5) destroying of the shader module
-		* @param[in] flag that signals the respective shaderStage (e.g. VK_SHADER_STAGE_VERTEX_BIT)
-		* @param[in] relative path to the shader code (e.g. "../../../../../shaders/vert.spv")
-		*/
-		void addShader(vk::ShaderStageFlagBits shaderStage, const std::string& filepath);
-
-		/**
-		* Tests if the shader program contains a certain shader stage.
-		* @param[in] flag that signals the respective shader stage (e.g. VK_SHADER_STAGE_VERTEX_BIT)
-		* @return boolean that is true if the shader program contains the shader stage
-		*/
-		bool containsShaderStage(vk::ShaderStageFlagBits shaderStage);
 
-		/**
-		* Deletes the given shader stage in the shader program.
-		* @param[in] flag that signals the respective shader stage (e.g. VK_SHADER_STAGE_VERTEX_BIT)
-		* @return boolean that is false if the shader stage was not found in the shader program
-		*/
-		bool deleteShaderStage(vk::ShaderStageFlagBits shaderStage);
-
-		/**
-		* Returns a list with all the shader stages in the shader program.
-		* Needed for the transfer to the pipeline.
-		* @return vector list with all shader stage info structs
-		*/
-		std::vector<vk::PipelineShaderStageCreateInfo> getShaderStages();
-
-		/**
-		* Returns the number of shader stages in the shader program.
-		* Needed for the transfer to the pipeline.
-		* @return integer with the number of stages
-		*/
-		int getShaderStagesCount();
 
 
 	};
-- 
GitLab