Skip to content

Commit 570aafc

Browse files
committed
correct RT setup for draw over on dx11
1 parent 67d4614 commit 570aafc

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/Core.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,15 @@ void Core::SwapchainCreate11(ID3D11Device5* device, ID3D11DeviceContext* context
4747
screenHeight_ = desc->BufferDesc.Height;
4848
firstFrame_ = true;
4949

50+
dxSwapChain = swc;
51+
pD11Device = device;
52+
pD11DeviceContext = context;
53+
5054
ImGui_ImplDX11_Init(device, context);
5155
}
5256

57+
ID3D11RenderTargetView* pD11RenderTargetView = nullptr;
58+
5359
void Core::DrawOver11()
5460
{
5561
if (firstFrame_)
@@ -58,14 +64,35 @@ void Core::DrawOver11()
5864
}
5965
else
6066
{
67+
//TODO: took this part from https://github.com/lguilhermee/Discord-DX11-Overlay-Hook/
68+
//maybe it is bad idea to recreate RTVs every frame? need to deal with this later on
69+
ID3D11Texture2D* renderTargetTexture = nullptr;
70+
if (!pD11RenderTargetView)
71+
{
72+
if (SUCCEEDED(dxSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<LPVOID*>(&renderTargetTexture))))
73+
{
74+
pD11Device->CreateRenderTargetView(renderTargetTexture, nullptr, &pD11RenderTargetView);
75+
renderTargetTexture->Release();
76+
}
77+
}
78+
6179
ImGui_ImplDX11_NewFrame();
6280
ImGui_ImplWin32_NewFrame();
6381
ImGui::NewFrame();
6482

6583
//this sends event to all other addons to draw their UI
6684
SendDrawEvent();
6785

86+
pD11DeviceContext->OMSetRenderTargets(1, &pD11RenderTargetView, nullptr);
6887
ImGui::Render();
88+
89+
// Release and free resources to setup again on the next loop.
90+
if (pD11RenderTargetView)
91+
{
92+
pD11RenderTargetView->Release();
93+
pD11RenderTargetView = nullptr;
94+
}
95+
6996
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
7097
}
7198
}

src/Core.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ namespace lib_imgui
5353
int screenHeight_ = 0;
5454
bool firstFrame_ = true;
5555

56+
IDXGISwapChain4* dxSwapChain = nullptr;
57+
ID3D11Device5* pD11Device = nullptr;
58+
ID3D11DeviceContext* pD11DeviceContext = nullptr;
59+
5660
ImGuiContext* imguiContext_ = nullptr;
5761
};
5862
}

0 commit comments

Comments
 (0)