SleakEngine 1.0.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
DirectX12Shader.hpp
Go to the documentation of this file.
1#ifndef _DIRECTX12_SHADER_H_
2#define _DIRECTX12_SHADER_H_
3
4#include <d3d12.h>
5#include <d3dcompiler.h>
6#include <wrl/client.h>
7
8#include <stdexcept>
9#include <string>
10#include <vector>
11
12#include "../Common/Shader.hpp"
13
14namespace Sleak {
15namespace RenderEngine {
16
17/// D3D12 vertex+pixel shader pair; the pipeline state object itself is owned per-shader.
18class DirectX12Shader : public Shader {
19public:
20 DirectX12Shader(ID3D12Device* device);
21 ~DirectX12Shader() override;
22
23 /// Compiles the combined-path convention (vs_main/ps_main entry points) from a single HLSL file.
24 bool compile(const std::string& shaderPath) override;
25 /// Compiles separate vertex and pixel shader HLSL files.
26 bool compile(const std::string& vertPath,
27 const std::string& fragPath) override;
28 /// Binds the shader's cached PSO to the current command list.
29 void bind() override;
30
31 ID3DBlob* getVertexShaderBlob() const;
32 ID3DBlob* getPixelShaderBlob() const;
33
34 // Per-shader PSO
35 void SetPipelineState(Microsoft::WRL::ComPtr<ID3D12PipelineState> pso);
36 ID3D12PipelineState* GetPipelineState() const;
37 void SetCommandList(ID3D12GraphicsCommandList* cmdList);
38
39private:
40 /// Compiles one HLSL entry point/profile via D3DCompileFromFile into bytecode.
41 bool compileShader(const std::string& filePath,
42 const std::string& entryPoint,
43 const std::string& profile,
44 Microsoft::WRL::ComPtr<ID3DBlob>& blob);
45
46 Microsoft::WRL::ComPtr<ID3D12Device> m_device;
47
48 Microsoft::WRL::ComPtr<ID3DBlob> m_vertexShaderBlob;
49 Microsoft::WRL::ComPtr<ID3DBlob> m_pixelShaderBlob;
50 Microsoft::WRL::ComPtr<ID3D12PipelineState> m_pipelineState;
51 ID3D12GraphicsCommandList* m_commandList = nullptr;
52};
53
54} // namespace RenderEngine
55} // namespace Sleak
56#endif // _DIRECTX12_SHADER_H_
void bind() override
Binds the shader's cached PSO to the current command list.
void SetCommandList(ID3D12GraphicsCommandList *cmdList)
void SetPipelineState(Microsoft::WRL::ComPtr< ID3D12PipelineState > pso)
ID3D12PipelineState * GetPipelineState() const
bool compile(const std::string &shaderPath) override
Compiles the combined-path convention (vs_main/ps_main entry points) from a single HLSL file.
Backend-agnostic compiled shader program.
Definition Shader.hpp:11
Backend-facing rendering layer shared by the four graphics backends.
Root namespace for everything the engine exposes.
Definition Camera.hpp:10