Skip to content

Commit

Permalink
Attempt to implement barrier for fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
WSSDude committed Dec 11, 2024
1 parent 7aca66d commit fe934d0
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 418 deletions.
1 change: 1 addition & 0 deletions src/d3d12/D3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,5 @@ struct D3D12
std::array<ImDrawData, 3> m_imguiDrawDataBuffers;
std::atomic_bool m_delayedTrapInput{false};
std::atomic_bool m_delayedTrapInputState{false};
bool m_imGuiInitialized{false};
};
31 changes: 26 additions & 5 deletions src/d3d12/D3D12_Functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ bool D3D12::ResetState(const bool acClearDownlevelBackbuffers, const bool acDest
drawData.Clear();
}

ImGui_ImplDX12_Shutdown();
ImGui_ImplWin32_Shutdown();
ImGui::GetIO().Fonts->Clear();

if (acDestroyContext)
{
ImGui_ImplDX12_Shutdown();
ImGui_ImplWin32_Shutdown();
ImGui::DestroyContext();

m_imGuiInitialized = false;
}
}

m_frameContexts.clear();
Expand Down Expand Up @@ -278,14 +283,15 @@ bool D3D12::InitializeDownlevel(ID3D12CommandQueue* apCommandQueue, ID3D12Resour
void D3D12::ReloadFonts()
{
std::lock_guard _(m_imguiLock);

auto& io = ImGui::GetIO();
if (io.Fonts->IsBuilt())
return;

// TODO - scale also by DPI
const auto [resx, resy] = m_outSize;
const auto scaleFromReference = std::min(static_cast<float>(resx) / 1920.0f, static_cast<float>(resy) / 1080.0f);

auto& io = ImGui::GetIO();
io.Fonts->Clear();

ImFontConfig config;
const auto& fontSettings = m_options.Font;
config.SizePixels = std::floorf(fontSettings.BaseSize * scaleFromReference);
Expand Down Expand Up @@ -415,12 +421,16 @@ void D3D12::ReloadFonts()
static const ImWchar icon_ranges[] = {ICON_MIN_MD, ICON_MAX_MD, 0};
auto cetIconPath = GetAbsolutePath(L"materialdesignicons.ttf", m_paths.Fonts(), false);
io.Fonts->AddFontFromFileTTF(UTF16ToUTF8(cetIconPath.native()).c_str(), config.SizePixels, &config, icon_ranges);
io.Fonts->Build();
}

bool D3D12::InitializeImGui(size_t aBuffersCounts)
{
std::lock_guard _(m_imguiLock);

if (m_imGuiInitialized)
return true;

// TODO - scale also by DPI
const auto [resx, resy] = m_outSize;
const auto scaleFromReference = std::min(static_cast<float>(resx) / 1920.0f, static_cast<float>(resy) / 1080.0f);
Expand Down Expand Up @@ -469,9 +479,13 @@ bool D3D12::InitializeImGui(size_t aBuffersCounts)
Log::Error("D3D12::InitializeImGui() - ImGui_ImplDX12_CreateDeviceObjects call failed!");
ImGui_ImplDX12_Shutdown();
ImGui_ImplWin32_Shutdown();

ImGui::GetIO().Fonts->Clear();

return false;
}

m_imGuiInitialized = true;
return true;
}

Expand All @@ -482,6 +496,13 @@ void D3D12::PrepareUpdate()

std::lock_guard _(m_imguiLock);

if (!ImGui::GetIO().Fonts->IsBuilt())
{
ReloadFonts();

ImGui_ImplDX12_CreateDeviceObjects(m_pCommandQueue.Get());
}

ImGui_ImplWin32_NewFrame(m_outSize);
ImGui::NewFrame();

Expand Down
Loading

0 comments on commit fe934d0

Please sign in to comment.