Skip to content
Snippets Groups Projects
Commit 1a7ca10c authored by Leonie Franken's avatar Leonie Franken
Browse files

fixed wrong filepaths in cmake build, work in progress reworking...

fixed wrong filepaths in cmake build, work in progress reworking ShaderProgramm with the new Core structure
parent 6aa9928f
No related branches found
No related tags found
4 merge requests!12Resolve "Swapchain Class",!7Resolve "Shader Program Class",!5Resolve "Pipeline State Object",!4Resolve "Renderpass Class"
Pipeline #24696 failed
......@@ -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
)
......@@ -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);
}
}
......
......@@ -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();
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment