SleakEngine 0.1.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 {
16class DirectX12Renderer;
17
18/// D3D12 vertex+pixel shader pair; the pipeline state object itself is owned per-shader.
19class DirectX12Shader : public Shader {
20public:
21 DirectX12Shader(ID3D12Device* device);
22 ~DirectX12Shader() override;
23
24 /// Compiles the combined-path convention (vs_main/ps_main entry points) from a single HLSL file.
25 bool compile(const std::string& shaderPath) override;
26 /// Compiles separate vertex and pixel shader HLSL files.
27 bool compile(const std::string& vertPath,
28 const std::string& fragPath) override;
29 /// Binds the shader's cached PSO to the current command list.
30 void bind() override;
31
32 ID3DBlob* getVertexShaderBlob() const;
33 ID3DBlob* getPixelShaderBlob() const;
34
35 // Per-shader PSO
36 void SetPipelineState(Microsoft::WRL::ComPtr<ID3D12PipelineState> pso);
37 ID3D12PipelineState* GetPipelineState() const;
38 void SetCommandList(ID3D12GraphicsCommandList* cmdList);
39 /// Routes bind() through the renderer so pass-specific PSOs are respected.
40 void SetRenderer(DirectX12Renderer* renderer);
41
42 private:
43 /// Compiles one HLSL entry point/profile via D3DCompileFromFile into bytecode.
44 bool compileShader(const std::string& filePath,
45 const std::string& entryPoint,
46 const std::string& profile,
47 Microsoft::WRL::ComPtr<ID3DBlob>& blob);
48
49 Microsoft::WRL::ComPtr<ID3D12Device> m_device;
50
51 Microsoft::WRL::ComPtr<ID3DBlob> m_vertexShaderBlob;
52 Microsoft::WRL::ComPtr<ID3DBlob> m_pixelShaderBlob;
53 Microsoft::WRL::ComPtr<ID3D12PipelineState> m_pipelineState;
54 ID3D12GraphicsCommandList* m_commandList = nullptr;
55 DirectX12Renderer* m_renderer = nullptr;
56};
57
58} // namespace RenderEngine
59} // namespace Sleak
60#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.
void SetRenderer(DirectX12Renderer *renderer)
Routes bind() through the renderer so pass-specific PSOs are respected.
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