SleakEngine 1.0.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
VulkanShader.hpp
Go to the documentation of this file.
1#ifndef _VULKANSHADER_H_
2#define _VULKANSHADER_H_
3
4#include <vector>
6#include "vulkan/vulkan_core.h"
7
8namespace Sleak {
9 namespace RenderEngine {
10
11/// Vulkan vertex+fragment shader pair, loaded from precompiled SPIR-V modules.
12class ENGINE_API VulkanShader : public Shader {
13public:
14 VulkanShader(VkDevice dev) : device(dev) {}
16
17 /// Loads the combined-path convention's .vert.spv/.frag.spv pair.
18 virtual bool compile(const std::string& shaderPath) override;
19 /// Loads separate vertex and fragment SPIR-V modules.
20 virtual bool compile(const std::string& vert, const std::string& frag) override;
21 /// Loads only the vertex stage (used for depth-only/shadow pipelines with no fragment shader).
22 bool compileVertexOnly(const std::string& vertPath);
23 /// Reads a .spv file and creates a VkShaderModule from it.
24 VkShaderModule LoadSPIRV(const char* path);
25 /// No-op: Vulkan binds shader stages via pipeline creation, not a runtime bind call.
26 virtual void bind() override;
27
28 inline VkShaderModule GetVertexShader() { return vertShader; }
29 inline VkShaderModule GetFragmentShader() { return fragShader; }
30
31 inline VkPipelineShaderStageCreateInfo GetVertexInfo() { return vertexInfo;}
32 inline VkPipelineShaderStageCreateInfo GetFragInfo() { return fragmentInfo;}
33
34private:
35 VkDevice device = nullptr;
36 VkShaderModule vertShader = nullptr;
37 VkShaderModule fragShader = nullptr;
38
39 VkPipelineShaderStageCreateInfo vertexInfo{};
40 VkPipelineShaderStageCreateInfo fragmentInfo{};
41
42 /// Wraps compiled SPIR-V bytecode in a VkShaderModule.
43 VkShaderModule createShaderModule(const std::vector<char>& code);
44 /// Reads a binary file's full contents (used for .spv loading).
45 std::vector<char> ReadFile(const std::string& path);
46
47};
48
49 }
50}
51
52#endif
Backend-agnostic compiled shader program.
Definition Shader.hpp:11
Vulkan vertex+fragment shader pair, loaded from precompiled SPIR-V modules.
VkPipelineShaderStageCreateInfo GetFragInfo()
VkPipelineShaderStageCreateInfo GetVertexInfo()
Backend-facing rendering layer shared by the four graphics backends.
Root namespace for everything the engine exposes.
Definition Camera.hpp:10