ShaderProgram.hpp 1.75 KB
Newer Older
1
2
#pragma once
/**
3
 * @authors Simeon Hermann, Leonie Franken
4
5
6
7
 * @file src/vkcv/ShaderProgram.hpp
 * @brief ShaderProgram class to handle and prepare the shader stages for a graphics pipeline
 */

Artur Wasmut's avatar
Artur Wasmut committed
8
#include <unordered_map>
9
10
#include <fstream>
#include <iostream>
Artur Wasmut's avatar
Artur Wasmut committed
11
#include <filesystem>
12
13
14
15
#include <vulkan/vulkan.hpp>

namespace vkcv {

Artur Wasmut's avatar
Artur Wasmut committed
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
    enum class ShaderStage
    {
        VERTEX,
        TESS_CONTROL,
        TESS_EVAL,
        GEOMETRY,
        FRAGMENT,
        COMPUTE
    };

    struct Shader
    {
        std::vector<char> shaderCode;
        ShaderStage shaderStage;
    };

	class ShaderProgram
	{
34
    public:
Artur Wasmut's avatar
Artur Wasmut committed
35
36
        ShaderProgram() noexcept; // ctor
        ~ShaderProgram() = default; // dtor
37
38
39
40
41
42
43
44

        /**
        * 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")
        */
Artur Wasmut's avatar
Artur Wasmut committed
45
        bool addShader(ShaderStage shaderStage, const std::filesystem::path &shaderPath);
46
47

        /**
Artur Wasmut's avatar
Artur Wasmut committed
48
        * Returns the shader program's shader of the specified shader.
49
        * Needed for the transfer to the pipeline.
Artur Wasmut's avatar
Artur Wasmut committed
50
        * @return Shader object consisting of buffer with shader code and shader stage enum
51
        */
Artur Wasmut's avatar
Artur Wasmut committed
52
        const Shader &getShader(ShaderStage shaderStage) const;
53

Artur Wasmut's avatar
Artur Wasmut committed
54
        bool existsShader(ShaderStage shaderStage) const;
55

56
	private:
Artur Wasmut's avatar
Artur Wasmut committed
57
        std::unordered_map<ShaderStage, Shader> m_Shaders;
58
59
60

	};
}