Add printable Enum

This commit is contained in:
Thraix
2023-05-01 18:23:22 +02:00
parent ca7286807a
commit ad69293faa
17 changed files with 122 additions and 76 deletions
@@ -126,7 +126,7 @@ namespace Copium
void Pipeline::InitializePipeline(const PipelineCreator& creator)
{
Shader shader{Shader::Type::GlslFile, creator.vertexShader, creator.fragmentShader};
Shader shader{ShaderReadType::GlslFile, creator.vertexShader, creator.fragmentShader};
VkPipelineVertexInputStateCreateInfo vertexInputCreateInfo{};
vertexInputCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
+6 -6
View File
@@ -6,28 +6,28 @@
namespace Copium
{
Shader::Shader(Type type, const std::string& vertexInput, const std::string& fragmentInput)
Shader::Shader(ShaderReadType type, const std::string& vertexInput, const std::string& fragmentInput)
{
switch (type)
{
case Type::GlslCode:
case ShaderReadType::GlslCode:
vertShaderModule = InitializeShaderModuleFromGlslCode(vertexInput, shaderc_vertex_shader);
fragShaderModule = InitializeShaderModuleFromGlslCode(fragmentInput, shaderc_fragment_shader);
break;
case Type::GlslFile:
case ShaderReadType::GlslFile:
vertShaderModule = InitializeShaderModuleFromGlslFile(vertexInput, shaderc_vertex_shader);
fragShaderModule = InitializeShaderModuleFromGlslFile(fragmentInput, shaderc_fragment_shader);
break;
case Type::SpvCode:
case ShaderReadType::SpvCode:
vertShaderModule = InitializeShaderModule(vertexInput);
fragShaderModule = InitializeShaderModule(fragmentInput);
break;
case Type::SpvFile:
case ShaderReadType::SpvFile:
vertShaderModule = InitializeShaderModule(FileSystem::ReadFile(vertexInput));
fragShaderModule = InitializeShaderModule(FileSystem::ReadFile(fragmentInput));
break;
default:
CP_ASSERT(false, "Unreachable switch case %d", (int)type);
CP_ASSERT(false, "Unreachable switch case: %s", ToString(type).c_str());
}
shaderStages.resize(2);
+5 -7
View File
@@ -1,27 +1,25 @@
#pragma once
#include "copium/util/Common.h"
#include "copium/util/Enum.h"
#include <shaderc/shaderc.hpp>
#include <vulkan/vulkan.hpp>
#define CP_SHADER_READ_TYPE_ENUMS GlslFile, GlslCode, SpvFile, SpvCode
CP_ENUM_CREATOR(Copium, ShaderReadType, CP_SHADER_READ_TYPE_ENUMS);
namespace Copium
{
class Shader final
{
CP_DELETE_COPY_AND_MOVE_CTOR(Shader);
public:
enum class Type
{
GlslFile, GlslCode, SpvFile, SpvCode
};
private:
VkShaderModule vertShaderModule;
VkShaderModule fragShaderModule;
std::vector<VkPipelineShaderStageCreateInfo> shaderStages;
public:
Shader(Type type, const std::string& vertexInput, const std::string& fragmentInput);
Shader(ShaderReadType type, const std::string& vertexInput, const std::string& fragmentInput);
~Shader();
const std::vector<VkPipelineShaderStageCreateInfo> GetShaderStages() const;
@@ -79,7 +79,7 @@ namespace Copium
case UniformType::Float:
return 4; // float
default:
CP_ABORT("Unhandled switch case");
CP_ABORT("Unhandled switch case: %s", ToString(type).c_str());
}
}
@@ -102,7 +102,7 @@ namespace Copium
case UniformType::Float:
return 16; // alignas(16) glm::vec2
default:
CP_ABORT("Unhandled switch case");
CP_ABORT("Unhandled switch case", ToString(type).c_str());
}
}
}
@@ -1,25 +1,21 @@
#pragma once
#include "copium/util/Enum.h"
#include <string>
#include <vector>
#define CP_BINDING_TYPE_ENUMS Sampler2D, UniformBuffer
#define CP_SHADER_TYPE_ENUMS Vertex, Fragment
#define CP_UNIFORM_TYPE_ENUMS Mat3, Mat4, Vec2, Vec3, Vec4, Float, Int
CP_ENUM_CREATOR(Copium, BindingType, CP_BINDING_TYPE_ENUMS);
CP_ENUM_CREATOR(Copium, ShaderType, CP_SHADER_TYPE_ENUMS);
CP_ENUM_CREATOR(Copium, UniformType, CP_UNIFORM_TYPE_ENUMS);
namespace Copium
{
enum class BindingType
{
Sampler2D, UniformBuffer
};
enum class ShaderType
{
Vertex, Fragment
};
enum class UniformType
{
Mat3, Mat4, Vec2, Vec3, Vec4, Float, Int
};
struct ShaderBinding
{
std::string name;