cae  0.0.0
Cross-API graphics engine
Loading...
Searching...
No Matches
GLSL.hpp
Go to the documentation of this file.
1///
2/// @file GLSL.hpp
3/// @brief This file contains the GLSL class declaration
4/// @namespace cae
5///
6
7#pragma once
8
10
11#include <glslang/Public/ShaderLang.h>
12
13#include <stdexcept>
14
15namespace cae
16{
17
18 constexpr auto VERSION = 450;
19
20 ///
21 /// @class GLSL
22 /// @brief Class for the GLSL plugin
23 /// @namespace cae
24 ///
25 class GLSL final : public AShaderFrontend
26 {
27
28 public:
29 GLSL() = default;
30 ~GLSL() override = default;
31
32 GLSL(const GLSL &) = delete;
33 GLSL &operator=(const GLSL &) = delete;
34 GLSL(GLSL &&) = delete;
35 GLSL &operator=(GLSL &&) = delete;
36
37 [[nodiscard]] std::string getName() const override { return "GLSL"; }
38 [[nodiscard]] utl::PluginType getType() const override { return utl::PluginType::SHADER_FRONTEND; }
39 [[nodiscard]] utl::PluginPlatform getPlatform() const override { return utl::PluginPlatform::ALL; }
40
41 [[nodiscard]] ShaderSourceType sourceType() const override { return ShaderSourceType::GLSL; }
42
44 {
46 ir.id = desc.id;
47 ir.stage = desc.stage;
48 ir.entryPoint = "main";
49 ir.spirv = compileGLSLtoSPIRV(desc.source, desc.stage);
50 return ir;
51 }
52
53 private:
54 static EShLanguage shaderStageToESh(const ShaderStage stage)
55 {
56 switch (stage)
57 {
59 return EShLangVertex;
61 return EShLangFragment;
63 return EShLangGeometry;
65 return EShLangCompute;
66 default:
67 throw std::runtime_error("Unsupported ShaderStage");
68 }
69 }
70
71 static std::vector<uint32_t> compileGLSLtoSPIRV(const std::string &src, ShaderStage stage);
72
73 }; // class GLSL
74
75} // namespace cae
This file contains the ShaderFrontend abstract class.
Abstract class for shader frontend.
Class for the GLSL plugin.
Definition GLSL.hpp:26
~GLSL() override=default
GLSL & operator=(GLSL &&)=delete
utl::PluginType getType() const override
Get the type of the plugin.
Definition GLSL.hpp:38
GLSL(const GLSL &)=delete
std::string getName() const override
Get the name of the plugin.
Definition GLSL.hpp:37
utl::PluginPlatform getPlatform() const override
Get the handled platform of the plugin.
Definition GLSL.hpp:39
GLSL()=default
GLSL(GLSL &&)=delete
ShaderIRModule compile(const ShaderSourceDesc &desc) override
Compile shader source to intermediate representation.
Definition GLSL.hpp:43
ShaderSourceType sourceType() const override
Get the source type this frontend handles.
Definition GLSL.hpp:41
GLSL & operator=(const GLSL &)=delete
static std::vector< uint32_t > compileGLSLtoSPIRV(const std::string &src, ShaderStage stage)
Definition glsl.cpp:5
static EShLanguage shaderStageToESh(const ShaderStage stage)
Definition GLSL.hpp:54
constexpr auto VERSION
Definition GLSL.hpp:18
PluginPlatform
Definition IPlugin.hpp:33
PluginType
Definition IPlugin.hpp:22
Struct for shader intermediate representation module.
std::vector< uint32_t > spirv
Struct for shader source description.