diff --git a/examples/directx11_example/imgui_impl_dx11.cpp b/examples/directx11_example/imgui_impl_dx11.cpp index 5f209bc0..33afb7ea 100644 --- a/examples/directx11_example/imgui_impl_dx11.cpp +++ b/examples/directx11_example/imgui_impl_dx11.cpp @@ -35,6 +35,7 @@ static ID3D11ShaderResourceView*g_pFontTextureView = NULL; static ID3D11RasterizerState* g_pRasterizerState = NULL; static ID3D11BlendState* g_pBlendState = NULL; static int g_VertexBufferSize = 5000, g_IndexBufferSize = 10000; +static ID3D11DepthStencilState* g_pDSState = NULL; struct VERTEX_CONSTANT_BUFFER { @@ -138,6 +139,8 @@ void ImGui_ImplDX11_RenderDrawLists(ImDrawData* draw_data) UINT IndexBufferOffset, VertexBufferStride, VertexBufferOffset; DXGI_FORMAT IndexBufferFormat; ID3D11InputLayout* InputLayout; + ID3D11DepthStencilState* DepthStencilState; + UINT StencilRef; }; BACKUP_DX11_STATE old; old.ScissorRectsCount = old.ViewportsCount = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; @@ -155,6 +158,7 @@ void ImGui_ImplDX11_RenderDrawLists(ImDrawData* draw_data) ctx->IAGetIndexBuffer(&old.IndexBuffer, &old.IndexBufferFormat, &old.IndexBufferOffset); ctx->IAGetVertexBuffers(0, 1, &old.VertexBuffer, &old.VertexBufferStride, &old.VertexBufferOffset); ctx->IAGetInputLayout(&old.InputLayout); + ctx->OMGetDepthStencilState(&old.DepthStencilState, &old.StencilRef); // Setup viewport D3D11_VIEWPORT vp; @@ -182,6 +186,7 @@ void ImGui_ImplDX11_RenderDrawLists(ImDrawData* draw_data) const float blend_factor[4] = { 0.f, 0.f, 0.f, 0.f }; ctx->OMSetBlendState(g_pBlendState, blend_factor, 0xffffffff); ctx->RSSetState(g_pRasterizerState); + ctx->OMSetDepthStencilState( g_pDSState, 1 ); // Render command lists int vtx_offset = 0; @@ -224,6 +229,7 @@ void ImGui_ImplDX11_RenderDrawLists(ImDrawData* draw_data) ctx->IASetIndexBuffer(old.IndexBuffer, old.IndexBufferFormat, old.IndexBufferOffset); if (old.IndexBuffer) old.IndexBuffer->Release(); ctx->IASetVertexBuffers(0, 1, &old.VertexBuffer, &old.VertexBufferStride, &old.VertexBufferOffset); if (old.VertexBuffer) old.VertexBuffer->Release(); ctx->IASetInputLayout(old.InputLayout); if (old.InputLayout) old.InputLayout->Release(); + ctx->OMSetDepthStencilState(old.DepthStencilState, old.StencilRef); } IMGUI_API LRESULT ImGui_ImplDX11_WndProcHandler(HWND, UINT msg, WPARAM wParam, LPARAM lParam) @@ -448,6 +454,18 @@ bool ImGui_ImplDX11_CreateDeviceObjects() g_pd3dDevice->CreateRasterizerState(&desc, &g_pRasterizerState); } + + // Create Depth-Stencil State + { + D3D11_DEPTH_STENCIL_DESC desc; + ZeroMemory(&desc, sizeof(desc)); + desc.StencilEnable = false; + desc.DepthEnable = true; + desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL; + desc.DepthFunc = D3D11_COMPARISON_ALWAYS; + g_pd3dDevice->CreateDepthStencilState( &desc, &g_pDSState ); + } + ImGui_ImplDX11_CreateFontsTexture(); return true; @@ -471,6 +489,7 @@ void ImGui_ImplDX11_InvalidateDeviceObjects() if (g_pInputLayout) { g_pInputLayout->Release(); g_pInputLayout = NULL; } if (g_pVertexShader) { g_pVertexShader->Release(); g_pVertexShader = NULL; } if (g_pVertexShaderBlob) { g_pVertexShaderBlob->Release(); g_pVertexShaderBlob = NULL; } + if (g_pDSState) { g_pDSState->Release(); g_pDSState = NULL; } } bool ImGui_ImplDX11_Init(void* hwnd, ID3D11Device* device, ID3D11DeviceContext* device_context)