jGL
Loading...
Searching...
No Matches
vkShader.h
Go to the documentation of this file.
1#ifndef VKSHADER
2#define VKSHADER
3
4#include <vulkan/vulkan.h>
5#include <shaderc/shaderc.hpp>
6
7#include <jGL/shader.h>
8
9#include <fstream>
10#include <string>
11#include <cstring>
12#include <vector>
13#include <iostream>
14
15namespace jGL::Vulkan
16{
17
18 class vkShader : public Shader
19 {
20
21 /*
22
23 Shaderc macro definitions
24 // Like -DMY_DEFINE=1
25 options.AddMacroDefinition("MY_DEFINE", "1");
26
27 */
28
29 public:
30
31 vkShader(const VkDevice & d, const char * vs, const char * fs)
32 : Shader(vs, fs), device(d)
33 {
34
35 compile();
36
37 createShaderModules(device);
38
39 }
40
41 ~vkShader();
42
43 std::vector<VkPipelineShaderStageCreateInfo> shaderStage() const;
44
45 void use(){}
46
47 private:
48
49 const VkDevice & device;
50
51 VkShaderModule vertexModule, fragmentModule;
52
53 std::vector<uint32_t> vertexSource, fragmentSource;
54
55 void compile();
56
57 std::vector<char> readSPIRV(const std::string & filename);
58 void createShaderModules(const VkDevice & device);
59
60 // Returns GLSL vkShader source text after preprocessing.
61 std::string preprocessShader
62 (
63 const std::string& source_name,
64 shaderc_shader_kind kind,
65 const std::string& source,
66 shaderc::CompileOptions options
67 );
68
69 // Compiles a vkShader to SPIR-V assembly. Returns the assembly text
70 // as a string.
71 std::string compileToAssembly
72 (
73 const std::string& source_name,
74 shaderc_shader_kind kind,
75 const std::string& source,
76 shaderc::CompileOptions options,
77 bool optimize = false
78 );
79
80
81 // Compiles a vkShader to a SPIR-V binary. Returns the binary as
82 // a vector of 32-bit words.
83 std::vector<uint32_t> compileSPIRV
84 (
85 const std::string& source_name,
86 shaderc_shader_kind kind,
87 const std::string& source,
88 shaderc::CompileOptions options,
89 bool optimize = false
90 );
91 };
92}
93
94#endif /* VKSHADER */
Definition vkShader.h:19
~vkShader()
Definition vkShader.cpp:6
void use()
Use the shader.
Definition vkShader.h:45
vkShader(const VkDevice &d, const char *vs, const char *fs)
Definition vkShader.h:31
std::vector< VkPipelineShaderStageCreateInfo > shaderStage() const
Definition vkShader.cpp:92
Definition buffer.h:10
Generic shader program with vertex and fragment shader.
Definition shader.h:44