5#ifndef _DIRECTX11RENDERER_H
6#define _DIRECTX11RENDERER_H
15#include <backends/imgui_impl_dx11.h>
26 DirectX11Renderer(Window* window);
27 ~DirectX11Renderer()
override;
29 bool Initialize()
override;
30 void BeginRender()
override;
31 void EndRender()
override;
32 void Cleanup()
override;
35 bool CreateDepthStencilBuffer(uint32_t
width, uint32_t
height);
39 virtual void Resize(uint32_t
width, uint32_t
height)
override;
42 virtual uint32_t GetFeatureCaps()
const override {
46 virtual void Draw(uint32_t vertexCount)
override;
47 virtual void DrawIndexed(uint32_t indexCount)
override;
48 virtual void DrawInstance(uint32_t instanceCount, uint32_t vertexPerInstance)
override;
49 virtual void DrawIndexedInstance(uint32_t instanceCount, uint32_t indexPerInstance)
override;
52 virtual void SetRenderMode(RenderMode mode)
override;
53 virtual void SetRenderFace(RenderFace face)
override;
54 virtual void SetViewport(
float x,
float y,
float width,
float height,
float minDepth = 0.0f,
float maxDepth = 1.0f)
override;
56 virtual void ClearDepthStencil(
bool clearDepth,
bool clearStencil,
57 float depth, uint8_t stencil)
override;
60 virtual void BindVertexBuffer(RefPtr<BufferBase> buffer,
61 uint32_t slot = 0)
override;
62 virtual void BindIndexBuffer(RefPtr<BufferBase> buffer,
63 uint32_t slot = 0)
override;
65 uint32_t slot = 0)
override;
67 virtual BufferBase* CreateBuffer(BufferType Type, uint32_t size,
void* data)
override;
68 virtual Shader* CreateShader(
const std::string& shaderSource)
override;
69 virtual Texture* CreateTexture(
const std::string& TexturePath)
override;
74 Texture* CreateCubemapTexture(
const std::array<std::string, 6>& facePaths);
76 Texture* CreateCubemapTextureFromPanorama(
const std::string& panoramaPath);
79 virtual void SetDepthWrite(
bool enabled)
override;
80 virtual void SetDepthCompare(DepthCompare compare)
override;
81 virtual void SetCullEnabled(
bool enabled)
override;
82 virtual void BindTexture(RefPtr<Sleak::Texture> texture, uint32_t slot = 0)
override;
83 virtual void BeginSkyboxPass()
override;
84 virtual void EndSkyboxPass()
override;
85 virtual void BeginDebugLinePass()
override;
86 virtual void EndDebugLinePass()
override;
88 virtual bool CreateImGUI();
90 void ApplyMSAAChange()
override;
93 void UpdateShadowLightUBO(
const void* data, uint32_t size)
override;
95 virtual RenderContext* GetContext()
override {
return this; }
98 virtual void ConfigureRenderMode()
override;
99 virtual void ConfigureRenderFace()
override;
101 bool CreateRenderTargetView();
103 bool SetRasterState();
106 bool CreateBlendState();
107 void SetBlendState(
float r,
float g,
float b,
float a, UINT Mask);
110 void CheckMSAASupport();
112 bool CreateMSAARenderTarget();
114 bool CreateMSAADepthStencil();
119 bool bIsLayoutCreated =
false;
121 List<std::string> SupportedMSAA;
123 UINT msaaSampleCount = 1;
124 UINT msaaQualityLevel = 0;
126 IDXGISwapChain* swapChain;
128 ID3D11Device* device;
129 ID3D11DeviceContext* deviceContext;
130 ID3D11RenderTargetView* renderTargetView;
131 ID3D11InputLayout* layout;
133 ID3D11DepthStencilState* depthStencilState;
134 ID3D11DepthStencilView* depthStencilView;
135 ID3D11Texture2D* depthStencilBuffer;
137 ID3D11BlendState* blendState;
139 ID3D11Texture2D* msaaRenderTarget =
nullptr;
140 ID3D11RenderTargetView* msaaRenderTargetView =
nullptr;
141 ID3D11Texture2D* msaaDepthStencilBuffer =
nullptr;
142 ID3D11DepthStencilView* msaaDepthStencilView =
nullptr;
146 D3D11_PRIMITIVE_TOPOLOGY topology;
147 D3D11_FILL_MODE fillMode;
148 D3D11_CULL_MODE cull;
152 D3D11_PRIMITIVE_TOPOLOGY m_savedTopology = D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
153 ID3D11DepthStencilState* m_savedDepthStencilState =
nullptr;
154 D3D11_CULL_MODE m_savedCullMode = D3D11_CULL_FRONT;
155 bool m_depthWriteEnabled =
true;
156 D3D11_COMPARISON_FUNC m_depthFunc = D3D11_COMPARISON_LESS;
161 ID3D11Buffer* m_shadowCB =
nullptr;
162 bool m_shadowCBCreated =
false;
164 bool CreateShadowConstantBuffer();
165 void CleanupShadowResources();
168 ID3D11Texture2D* m_shadowDepthTex =
nullptr;
169 ID3D11DepthStencilView* m_shadowDSV =
nullptr;
170 ID3D11ShaderResourceView* m_shadowSRV =
nullptr;
171 ID3D11SamplerState* m_shadowSampler =
nullptr;
172 ID3D11RasterizerState* m_shadowRasterState =
nullptr;
173 bool m_shadowMapCreated =
false;
174 float m_lightVP[16] = {};
175 float m_pendingLightVP[16] = {};
176 bool m_hasPendingLightVP =
false;
177 ID3D11Buffer* m_shadowTransformCB =
nullptr;
178 bool m_inShadowPass =
false;
179 void SetLightVP(
const float* mat)
override;
181 bool CreateShadowMapResources();
183 void RenderShadowPass();
186 ID3D11Buffer* m_postProcessCB =
nullptr;
187 ID3D11Texture2D* m_hdrTexture =
nullptr;
188 ID3D11RenderTargetView* m_hdrRTV =
nullptr;
189 ID3D11ShaderResourceView* m_hdrSRV =
nullptr;
190 ID3D11SamplerState* m_pointSampler =
nullptr;
191 ID3D11VertexShader* m_tonemapVS =
nullptr;
192 ID3D11PixelShader* m_tonemapPS =
nullptr;
193 bool m_tonemapResourcesCreated =
false;
195 bool CreateTonemapResources();
196 void CleanupTonemapResources();
198 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.