Graphics v0.0.0
A simple abstraction layer for the modern graphics APIs.
载入中...
搜索中...
未找到
Shader.h
1// Copyright 2022 ShenMian
2// License(Apache-2.0)
3
4#pragma once
5
6#include <filesystem>
7#include <memory>
8#include <string>
9#include <unordered_map>
10#include <vector>
11
19class Shader
20{
21public:
25 enum class Stage
26 {
27 Vertex,
28 Fragment,
29 Pixel = Fragment,
30 Geometry,
31 Compute
32 };
33
34 struct Descriptor;
35
41 [[nodiscard]] static std::shared_ptr<Shader> create(const Descriptor& desc);
42
46 const std::string& get_name() const noexcept;
47
51 const std::string& get_entry_point() const noexcept;
52
56 Stage get_stage() const noexcept;
57
58protected:
59 Shader(const Descriptor& desc);
60 virtual ~Shader() = default;
61
65 std::vector<uint32_t> get_code(std::filesystem::path path);
66
76 void compile(const std::filesystem::path& sourcePath, const std::filesystem::path& targetPath, Stage stage);
77
83 void parse(const std::vector<uint32_t>& buf);
84
85 std::string name_;
86 std::string entry_point_;
87 Stage stage_;
88};
89
91{
92 Stage stage;
93 std::filesystem::path path;
94};
95
着色器阶段.
Definition: Shader.h:20
Stage get_stage() const noexcept
获取阶段.
Definition: Shader.cpp:153
void parse(const std::vector< uint32_t > &buf)
将 GLSL 编译为 SPIR-V.
Definition: Shader.cpp:233
Stage
着色器阶段.
Definition: Shader.h:26
@ Pixel
像素着色器.
@ Fragment
片段着色器.
@ Compute
计算着色器.
@ Vertex
顶点着色器.
@ Geometry
几何着色器.
static std::shared_ptr< Shader > create(const Descriptor &desc)
创建着色器阶段.
Definition: Shader.cpp:125
const std::string & get_entry_point() const noexcept
获取入口点名称.
Definition: Shader.cpp:148
std::vector< uint32_t > get_code(std::filesystem::path path)
获取 SPIR-V 代码, 若未编译则先进行编译.
Definition: Shader.cpp:162
void compile(const std::filesystem::path &sourcePath, const std::filesystem::path &targetPath, Stage stage)
将 GLSL 编译为 SPIR-V.
Definition: Shader.cpp:192
const std::string & get_name() const noexcept
获取名称.
Definition: Shader.cpp:143
Definition: Shader.h:91
std::filesystem::path path
GLSL 源码文件或 SPIR-V 文件路径.
Definition: Shader.h:93