5#ifndef _DIRECTX11RENDERER_H
6#define _DIRECTX11RENDERER_H
8#include <backends/imgui_impl_dx11.h>
11#include <wrl/client.h>
31 DirectX11Renderer(Window* window);
32 ~DirectX11Renderer()
override;
34 bool Initialize()
override;
35 void BeginRender()
override;
36 void EndRender()
override;
37 void Cleanup()
override;
38#ifdef SLEAK_HOT_RELOAD
40 bool ReloadShaders(
const std::vector<std::string>& stems)
override;
44 bool CreateDepthStencilBuffer(uint32_t
width, uint32_t
height);
48 virtual void Resize(uint32_t
width, uint32_t
height)
override;
51 virtual uint32_t GetFeatureCaps()
const override {
55 virtual void Draw(uint32_t vertexCount)
override;
56 virtual void Draw(uint32_t vertexCount, uint32_t firstVertex)
override;
57 virtual void DrawIndexed(uint32_t indexCount)
override;
58 virtual void DrawIndexed(uint32_t indexCount, uint32_t firstIndex,
59 int32_t baseVertex)
override;
60 virtual void DrawInstance(uint32_t instanceCount, uint32_t vertexPerInstance)
override;
61 virtual void DrawIndexedInstance(uint32_t instanceCount, uint32_t indexPerInstance)
override;
62 virtual void DrawIndexedInstance(uint32_t instanceCount,
63 uint32_t indexPerInstance,
65 int32_t baseVertex)
override;
68 virtual void SetRenderMode(RenderMode mode)
override;
69 virtual void SetRenderFace(RenderFace face)
override;
70 virtual void SetViewport(
float x,
float y,
float width,
float height,
float minDepth = 0.0f,
float maxDepth = 1.0f)
override;
72 virtual void ClearDepthStencil(
bool clearDepth,
bool clearStencil,
73 float depth, uint8_t stencil)
override;
76 virtual void BindVertexBuffer(RefPtr<BufferBase> buffer,
77 uint32_t slot = 0)
override;
78 virtual void BindIndexBuffer(RefPtr<BufferBase> buffer,
79 uint32_t slot = 0)
override;
81 uint32_t slot = 0)
override;
83 virtual BufferBase* CreateBuffer(BufferType Type, uint32_t size,
void* data)
override;
84 virtual Shader* CreateShader(
const std::string& shaderSource)
override;
85 virtual Texture* CreateTexture(
const std::string& TexturePath)
override;
90 Texture* CreateCubemapTexture(
const std::array<std::string, 6>& facePaths);
92 Texture* CreateCubemapTextureFromPanorama(
const std::string& panoramaPath);
95 virtual void SetDepthWrite(
bool enabled)
override;
96 virtual void SetDepthCompare(DepthCompare compare)
override;
97 virtual void SetCullEnabled(
bool enabled)
override;
98 virtual void BindTexture(RefPtr<Sleak::Texture> texture, uint32_t slot = 0)
override;
99 virtual void BeginSkyboxPass()
override;
100 virtual void EndSkyboxPass()
override;
101 virtual void BeginDebugLinePass()
override;
102 virtual void EndDebugLinePass()
override;
104 virtual bool CreateImGUI();
106 void ApplyMSAAChange()
override;
109 void UpdateShadowLightUBO(
const void* data, uint32_t size)
override;
111 virtual RenderContext* GetContext()
override {
return this; }
114 virtual void ConfigureRenderMode()
override;
115 virtual void ConfigureRenderFace()
override;
117 bool CreateRenderTargetView();
119 bool SetRasterState();
121 void ApplyDepthState();
123 ID3D11RasterizerState* GetRasterState(
const D3D11_RASTERIZER_DESC& desc);
125 ID3D11DepthStencilState* GetDepthState(
126 const D3D11_DEPTH_STENCIL_DESC& desc);
129 bool CreateBlendState();
130 void SetBlendState(
float r,
float g,
float b,
float a, UINT Mask);
133 void CheckMSAASupport();
135 bool CreateMSAARenderTarget();
137 bool CreateMSAADepthStencil();
142 bool bIsLayoutCreated =
false;
144 List<std::string> SupportedMSAA;
146 UINT msaaSampleCount = 1;
147 UINT msaaQualityLevel = 0;
149 IDXGISwapChain* swapChain;
151 ID3D11Device* device;
152 ID3D11DeviceContext* deviceContext;
153 ID3D11RenderTargetView* renderTargetView;
154 ID3D11InputLayout* layout;
156 ID3D11DepthStencilState* depthStencilState =
nullptr;
157 ID3D11DepthStencilView* depthStencilView;
158 ID3D11Texture2D* depthStencilBuffer;
160 ID3D11BlendState* blendState;
162 ID3D11Texture2D* msaaRenderTarget =
nullptr;
163 ID3D11RenderTargetView* msaaRenderTargetView =
nullptr;
164 ID3D11Texture2D* msaaDepthStencilBuffer =
nullptr;
165 ID3D11DepthStencilView* msaaDepthStencilView =
nullptr;
167 ID3D11Query* query =
nullptr;
169 D3D11_PRIMITIVE_TOPOLOGY topology;
170 D3D11_FILL_MODE fillMode;
171 D3D11_CULL_MODE cull;
175 D3D11_PRIMITIVE_TOPOLOGY m_savedTopology = D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
176 ID3D11DepthStencilState* m_savedDepthStencilState =
nullptr;
177 D3D11_CULL_MODE m_savedCullMode = D3D11_CULL_FRONT;
178 bool m_depthWriteEnabled =
true;
179 D3D11_COMPARISON_FUNC m_depthFunc = D3D11_COMPARISON_LESS;
182 std::vector<std::pair<D3D11_RASTERIZER_DESC,
183 Microsoft::WRL::ComPtr<ID3D11RasterizerState>>>
185 std::vector<std::pair<D3D11_DEPTH_STENCIL_DESC,
186 Microsoft::WRL::ComPtr<ID3D11DepthStencilState>>>
192 ID3D11Buffer* m_shadowCB =
nullptr;
193 bool m_shadowCBCreated =
false;
195 bool CreateShadowConstantBuffer();
196 void CleanupShadowResources();
199 ID3D11Texture2D* m_shadowDepthTex =
nullptr;
200 ID3D11DepthStencilView* m_shadowDSV =
nullptr;
201 ID3D11ShaderResourceView* m_shadowSRV =
nullptr;
202 ID3D11SamplerState* m_shadowSampler =
nullptr;
203 ID3D11RasterizerState* m_shadowRasterState =
nullptr;
204 bool m_shadowMapCreated =
false;
205 float m_lightVP[16] = {};
206 float m_pendingLightVP[16] = {};
207 bool m_hasPendingLightVP =
false;
208 ID3D11Buffer* m_shadowTransformCB =
nullptr;
210 float m_shadowWorldCache[16] = {};
211 bool m_shadowCBCacheValid =
false;
212 bool m_inShadowPass =
false;
213 void SetLightVP(
const float* mat)
override;
215 bool CreateShadowMapResources();
217 void RenderShadowPass();
220 ID3D11Buffer* m_postProcessCB =
nullptr;
221 ID3D11Texture2D* m_hdrTexture =
nullptr;
222 ID3D11RenderTargetView* m_hdrRTV =
nullptr;
223 ID3D11ShaderResourceView* m_hdrSRV =
nullptr;
224 ID3D11SamplerState* m_pointSampler =
nullptr;
225 ID3D11VertexShader* m_tonemapVS =
nullptr;
226 ID3D11PixelShader* m_tonemapPS =
nullptr;
227 bool m_tonemapResourcesCreated =
false;
229 bool CreateTonemapResources();
231 bool CompileTonemapShaders(ID3D11VertexShader** vs, ID3D11PixelShader** ps);
232#ifdef SLEAK_HOT_RELOAD
234 void ReloadTonemapShaders();
236 void CleanupTonemapResources();
238 void ExecuteTonemapPass();
Abstract interface for high-level graphics command execution and resource management.
Abstract render backend: swapchain, frame lifecycle, and post-effect toggles.
Backend-facing rendering layer shared by the four graphics backends.
Root namespace for everything the engine exposes.