Skip to content

Commit

Permalink
Separate imgui contexts for TV and Pad windows. (#664)
Browse files Browse the repository at this point in the history
  • Loading branch information
goeiecool9999 committed Feb 18, 2023
1 parent daf3ef0 commit cbb79fd
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 184 deletions.
16 changes: 8 additions & 8 deletions src/Cafe/HW/Latte/Core/LatteOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void LatteOverlay_renderOverlay(ImVec2& position, ImVec2& pivot, sint32 directio
{
ImGui::SetNextWindowPos(position, ImGuiCond_Always, pivot);
ImGui::SetNextWindowBgAlpha(kBackgroundAlpha);
if (ImGui_BeginPadDistinct("Stats overlay", nullptr, kPopupFlags, pad))
if (ImGui::Begin("Stats overlay", nullptr, kPopupFlags))
{
if (config.overlay.fps)
ImGui::Text("FPS: %.2lf", g_state.fps);
Expand Down Expand Up @@ -141,7 +141,7 @@ void LatteOverlay_RenderNotifications(ImVec2& position, ImVec2& pivot, sint32 di
// active account
ImGui::SetNextWindowPos(position, ImGuiCond_Always, pivot);
ImGui::SetNextWindowBgAlpha(kBackgroundAlpha);
if (ImGui_BeginPadDistinct("Active account", nullptr, kPopupFlags, pad))
if (ImGui::Begin("Active account", nullptr, kPopupFlags))
{
ImGui::TextUnformatted((const char*)ICON_FA_USER);
ImGui::SameLine();
Expand Down Expand Up @@ -179,7 +179,7 @@ void LatteOverlay_RenderNotifications(ImVec2& position, ImVec2& pivot, sint32 di
{
ImGui::SetNextWindowPos(position, ImGuiCond_Always, pivot);
ImGui::SetNextWindowBgAlpha(kBackgroundAlpha);
if (ImGui_BeginPadDistinct("Controller profile names", nullptr, kPopupFlags, pad))
if (ImGui::Begin("Controller profile names", nullptr, kPopupFlags))
{
auto it = profiles.cbegin();
ImGui::TextUnformatted((const char*)ICON_FA_GAMEPAD);
Expand Down Expand Up @@ -227,7 +227,7 @@ void LatteOverlay_RenderNotifications(ImVec2& position, ImVec2& pivot, sint32 di
{
ImGui::SetNextWindowPos(position, ImGuiCond_Always, pivot);
ImGui::SetNextWindowBgAlpha(kBackgroundAlpha);
if (ImGui_BeginPadDistinct("Friends overlay", nullptr, kPopupFlags, pad))
if (ImGui::Begin("Friends overlay", nullptr, kPopupFlags))
{
const auto tick = tick_cached();
for (auto it = s_friend_list.cbegin(); it != s_friend_list.cend();)
Expand Down Expand Up @@ -274,7 +274,7 @@ void LatteOverlay_RenderNotifications(ImVec2& position, ImVec2& pivot, sint32 di

ImGui::SetNextWindowPos(position, ImGuiCond_Always, pivot);
ImGui::SetNextWindowBgAlpha(kBackgroundAlpha);
if (ImGui_BeginPadDistinct("Low battery overlay", nullptr, kPopupFlags, pad))
if (ImGui::Begin("Low battery overlay", nullptr, kPopupFlags))
{
auto it = batteries.cbegin();
ImGui::TextUnformatted((const char*)(s_blink_state ? ICON_FA_BATTERY_EMPTY : ICON_FA_BATTERY_QUARTER));
Expand Down Expand Up @@ -322,7 +322,7 @@ void LatteOverlay_RenderNotifications(ImVec2& position, ImVec2& pivot, sint32 di
{
ImGui::SetNextWindowPos(position, ImGuiCond_Always, pivot);
ImGui::SetNextWindowBgAlpha(kBackgroundAlpha);
if (ImGui_BeginPadDistinct("Compiling shaders overlay", nullptr, kPopupFlags, pad))
if (ImGui::Begin("Compiling shaders overlay", nullptr, kPopupFlags))
{
ImRotateStart();
ImGui::TextUnformatted((const char*)ICON_FA_SPINNER);
Expand Down Expand Up @@ -377,7 +377,7 @@ void LatteOverlay_RenderNotifications(ImVec2& position, ImVec2& pivot, sint32 di
{
ImGui::SetNextWindowPos(position, ImGuiCond_Always, pivot);
ImGui::SetNextWindowBgAlpha(kBackgroundAlpha);
if (ImGui_BeginPadDistinct("Compiling pipeline overlay", nullptr, kPopupFlags, pad))
if (ImGui::Begin("Compiling pipeline overlay", nullptr, kPopupFlags))
{
ImRotateStart();
ImGui::TextUnformatted((const char*)ICON_FA_SPINNER);
Expand Down Expand Up @@ -446,7 +446,7 @@ void LatteOverlay_RenderNotifications(ImVec2& position, ImVec2& pivot, sint32 di
{
ImGui::SetNextWindowPos(position, ImGuiCond_Always, pivot);
ImGui::SetNextWindowBgAlpha(kBackgroundAlpha);
if (ImGui_BeginPadDistinct("Misc notifications", nullptr, kPopupFlags, pad))
if (ImGui::Begin("Misc notifications", nullptr, kPopupFlags))
{
const auto tick = tick_cached();
for (auto it = s_misc_notifications.cbegin(); it != s_misc_notifications.cend();)
Expand Down
236 changes: 78 additions & 158 deletions src/Cafe/HW/Latte/Core/LatteShaderCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,43 @@ uint32 LatteShaderCache_getPipelineCacheExtraVersion(uint64 titleId)
return extraVersion;
}

void LatteShaderCache_drawBackgroundImage(ImTextureID texture, int width, int height)
{
// clear framebuffers and clean up
const auto kPopupFlags =
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoSavedSettings |
ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_AlwaysAutoResize;
auto& io = ImGui::GetIO();
ImGui::SetNextWindowPos({0, 0}, ImGuiCond_Always);
ImGui::SetNextWindowSize(io.DisplaySize, ImGuiCond_Always);
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {0, 0});
if (ImGui::Begin("Background texture", nullptr, kPopupFlags))
{
if (texture)
{
float imageDisplayWidth = io.DisplaySize.x;
float imageDisplayHeight = height * imageDisplayWidth / width;

float paddingLeftAndRight = 0.0f;
float paddingTopAndBottom = (io.DisplaySize.y - imageDisplayHeight) / 2.0f;
if (imageDisplayHeight > io.DisplaySize.y)
{
imageDisplayHeight = io.DisplaySize.y;
imageDisplayWidth = width * imageDisplayHeight / height;
paddingLeftAndRight = (io.DisplaySize.x - imageDisplayWidth) / 2.0f;
paddingTopAndBottom = 0.0f;
}

ImGui::GetWindowDrawList()->AddImage(texture, ImVec2(paddingLeftAndRight, paddingTopAndBottom),
ImVec2(io.DisplaySize.x - paddingLeftAndRight,
io.DisplaySize.y - paddingTopAndBottom), {0, 1}, {1, 0});
}
}
ImGui::End();
ImGui::PopStyleVar(2);
}

void LatteShaderCache_load()
{
shaderCacheScreenStats.compiledShaderCount = 0;
Expand Down Expand Up @@ -231,48 +268,36 @@ void LatteShaderCache_load()
g_shaderCacheLoaderState.loadedShaderFiles = 0;

// get game background loading image
TGAFILE TVfile{};
g_shaderCacheLoaderState.textureTVId = nullptr;

std::string tvTexPath = fmt::format("{}/meta/bootTvTex.tga", CafeSystem::GetMlcStoragePath(CafeSystem::GetForegroundTitleId()));
sint32 statusTV;
auto fscfile = fsc_open(tvTexPath.c_str(), FSC_ACCESS_FLAG::OPEN_FILE | FSC_ACCESS_FLAG::READ_PERMISSION, &statusTV);
if (fscfile)
auto loadBackgroundTexture = [](bool isTV, ImTextureID& out)
{
uint32 size = fsc_getFileSize(fscfile);
if (size > 0)
{
std::vector<uint8> tmpData(size);
fsc_readFile(fscfile, tmpData.data(), size);
const bool backgroundLoaded = LoadTGAFile(tmpData, &TVfile);
TGAFILE file{};
out = nullptr;

if (backgroundLoaded)
g_shaderCacheLoaderState.textureTVId = g_renderer->GenerateTexture(TVfile.imageData, { TVfile.imageWidth, TVfile.imageHeight });
}
std::string fileName = isTV ? "bootTvTex.tga" : "bootDRCTex.tga";

fsc_close(fscfile);
}
//get game background loading image for DRC
TGAFILE DRCfile{};
g_shaderCacheLoaderState.textureDRCId = nullptr;

std::string drcTexPath = fmt::format("{}/meta/bootDRCTex.tga", CafeSystem::GetMlcStoragePath(CafeSystem::GetForegroundTitleId()));
sint32 statusDRC;
auto fscfile2 = fsc_open(drcTexPath.c_str(), FSC_ACCESS_FLAG::OPEN_FILE | FSC_ACCESS_FLAG::READ_PERMISSION, &statusDRC);
if (fscfile2)
{
uint32 size = fsc_getFileSize(fscfile2);
if (size > 0)
std::string texPath = fmt::format("{}/meta/{}", CafeSystem::GetMlcStoragePath(CafeSystem::GetForegroundTitleId()), fileName);
sint32 status;
auto fscfile = fsc_open(texPath.c_str(), FSC_ACCESS_FLAG::OPEN_FILE | FSC_ACCESS_FLAG::READ_PERMISSION, &status);
if (fscfile)
{
std::vector<uint8> tmpData(size);
fsc_readFile(fscfile2, tmpData.data(), size);
const bool backgroundLoaded = LoadTGAFile(tmpData, &DRCfile);
uint32 size = fsc_getFileSize(fscfile);
if (size > 0)
{
std::vector<uint8> tmpData(size);
fsc_readFile(fscfile, tmpData.data(), size);
const bool backgroundLoaded = LoadTGAFile(tmpData, &file);

if (backgroundLoaded)
g_shaderCacheLoaderState.textureDRCId = g_renderer->GenerateTexture(DRCfile.imageData, { DRCfile.imageWidth, DRCfile.imageHeight });
if (backgroundLoaded)
out = g_renderer->GenerateTexture(file.imageData, { file.imageWidth, file.imageHeight });
}

fsc_close(fscfile);
}
fsc_close(fscfile2);
}
};

loadBackgroundTexture(true, g_shaderCacheLoaderState.textureTVId);
loadBackgroundTexture(false, g_shaderCacheLoaderState.textureDRCId);

sint32 numLoadedShaders = 0;
uint32 loadIndex = 0;

Expand Down Expand Up @@ -319,79 +344,22 @@ void LatteShaderCache_load()
if (g_renderer->GetType() == RendererAPI::Vulkan)
LatteShaderCache_loadVulkanPipelineCache(cacheTitleId);

// clear framebuffers and clean up
auto& io = ImGui::GetIO();
const auto kPopupFlags = ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_AlwaysAutoResize;
for (int i = 0; i < 2; ++i)
{
g_renderer->BeginFrame(true);
if (g_renderer->ImguiBegin(true))
{
ImGui::SetNextWindowPos({ 0,0 }, ImGuiCond_Always);
ImGui::SetNextWindowSize(io.DisplaySize, ImGuiCond_Always);
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, { 0,0 });
if (ImGui::Begin("Background texture", nullptr, kPopupFlags))
{
if (g_shaderCacheLoaderState.textureTVId)
{
float imageDisplayWidth = io.DisplaySize.x;
float imageDisplayHeight = 720 * imageDisplayWidth / 1280;

float paddingLeftAndRight = 0.0f;
float paddingTopAndBottom = (io.DisplaySize.y - imageDisplayHeight)/2.0f;
if (imageDisplayHeight > io.DisplaySize.y)
{
imageDisplayHeight = io.DisplaySize.y;
imageDisplayWidth = 1280 * imageDisplayHeight / 720;
paddingLeftAndRight = (io.DisplaySize.x - imageDisplayWidth)/2.0f;
paddingTopAndBottom = 0.0f;
}

ImGui::GetWindowDrawList()->AddImage(g_shaderCacheLoaderState.textureTVId, ImVec2(paddingLeftAndRight, paddingTopAndBottom), ImVec2(io.DisplaySize.x-paddingLeftAndRight, io.DisplaySize.y-paddingTopAndBottom), { 0,1 }, { 1,0 });
}
}
ImGui::End();
ImGui::PopStyleVar(2);
g_renderer->ImguiEnd();
}

g_renderer->BeginFrame(false);
if (g_renderer->ImguiBegin(false))
{
ImGui::SetNextWindowPos({ 0,0 }, ImGuiCond_Always);
ImGui::SetNextWindowSize(io.DisplaySize, ImGuiCond_Always);
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, { 0,0 });

if (ImGui::Begin("Background texture2", nullptr, kPopupFlags))
{
if (g_shaderCacheLoaderState.textureDRCId)
{
float imageDisplayWidth = io.DisplaySize.x;
float imageDisplayHeight = 480 * imageDisplayWidth / 854;

float paddingLeftAndRight = 0.0f;
float paddingTopAndBottom = (io.DisplaySize.y - imageDisplayHeight)/2.0f;
if (imageDisplayHeight > io.DisplaySize.y)
{
imageDisplayHeight = io.DisplaySize.y;
imageDisplayWidth = 854 * imageDisplayHeight / 480;
paddingLeftAndRight = (io.DisplaySize.x - imageDisplayWidth)/2.0f;
paddingTopAndBottom = 0.0f;
}

ImGui::GetWindowDrawList()->AddImage(g_shaderCacheLoaderState.textureDRCId, ImVec2(paddingLeftAndRight, paddingTopAndBottom), ImVec2(io.DisplaySize.x-paddingLeftAndRight, io.DisplaySize.y-paddingTopAndBottom), { 0,1 }, { 1,0 });
}
}
ImGui::End();
ImGui::PopStyleVar(2);
g_renderer->ImguiEnd();
}

g_renderer->SwapBuffers(true, true);
g_renderer->BeginFrame(true);
if (g_renderer->ImguiBegin(true))
{
LatteShaderCache_drawBackgroundImage(g_shaderCacheLoaderState.textureTVId, 1280, 720);
g_renderer->ImguiEnd();
}
g_renderer->BeginFrame(false);
if (g_renderer->ImguiBegin(false))
{
LatteShaderCache_drawBackgroundImage(g_shaderCacheLoaderState.textureDRCId, 854, 480);
g_renderer->ImguiEnd();
}

g_renderer->SwapBuffers(true, true);

if (g_shaderCacheLoaderState.textureTVId)
g_renderer->DeleteTexture(g_shaderCacheLoaderState.textureTVId);
if (g_shaderCacheLoaderState.textureDRCId)
Expand Down Expand Up @@ -427,35 +395,11 @@ void LatteShaderCache_ShowProgress(const std::function <bool(void)>& loadUpdateF
g_renderer->BeginFrame(true);
if (g_renderer->ImguiBegin(true))
{
// render background texture
LatteShaderCache_drawBackgroundImage(g_shaderCacheLoaderState.textureTVId, 1280, 720);

const auto progress_font = ImGui_GetFont(window_size.y / 32.0f); // = 24 by default
const auto shader_count_font = ImGui_GetFont(window_size.y / 48.0f); // = 16
// render background texture
if (g_shaderCacheLoaderState.textureTVId)
{
ImGui::SetNextWindowPos({ 0, 0 }, ImGuiCond_Always);
ImGui::SetNextWindowSize(io.DisplaySize, ImGuiCond_Always);
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, { 0, 0 });
if (ImGui::Begin("Background texture", nullptr, kPopupFlags | ImGuiWindowFlags_NoBringToFrontOnFocus))
{
float imageDisplayWidth = io.DisplaySize.x;
float imageDisplayHeight = 720 * imageDisplayWidth / 1280;

float paddingLeftAndRight = 0.0f;
float paddingTopAndBottom = (io.DisplaySize.y - imageDisplayHeight) / 2.0f;
if (imageDisplayHeight > io.DisplaySize.y)
{
imageDisplayHeight = io.DisplaySize.y;
imageDisplayWidth = 1280 * imageDisplayHeight / 720;
paddingLeftAndRight = (io.DisplaySize.x - imageDisplayWidth) / 2.0f;
paddingTopAndBottom = 0.0f;
}

ImGui::GetWindowDrawList()->AddImage(g_shaderCacheLoaderState.textureTVId, ImVec2(paddingLeftAndRight, paddingTopAndBottom), ImVec2(io.DisplaySize.x-paddingLeftAndRight, io.DisplaySize.y-paddingTopAndBottom), { 0,1 }, { 1,0 });
}
ImGui::End();
ImGui::PopStyleVar(2);
}

ImVec2 position = { window_size.x / 2.0f, window_size.y / 2.0f };
ImVec2 pivot = { 0.5f, 0.5f };
Expand Down Expand Up @@ -541,31 +485,7 @@ void LatteShaderCache_ShowProgress(const std::function <bool(void)>& loadUpdateF
g_renderer->BeginFrame(false);
if (g_renderer->ImguiBegin(false))
{
ImGui::SetNextWindowPos({ 0,0 }, ImGuiCond_Always);
ImGui::SetNextWindowSize(io.DisplaySize, ImGuiCond_Always);
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, { 0,0 });
if (ImGui::Begin("Background texture2", nullptr, kPopupFlags))
{
if (g_shaderCacheLoaderState.textureDRCId)
{
float imageDisplayWidth = io.DisplaySize.x;
float imageDisplayHeight = 480 * imageDisplayWidth / 854;

float paddingLeftAndRight = 0.0f;
float paddingTopAndBottom = (io.DisplaySize.y - imageDisplayHeight)/2.0f;
if (imageDisplayHeight > io.DisplaySize.y)
{
imageDisplayHeight = io.DisplaySize.y;
imageDisplayWidth = 854 * imageDisplayHeight / 480;
paddingLeftAndRight = (io.DisplaySize.x - imageDisplayWidth)/2.0f;
paddingTopAndBottom = 0.0f;
}
ImGui::GetWindowDrawList()->AddImage(g_shaderCacheLoaderState.textureDRCId, ImVec2(paddingLeftAndRight, paddingTopAndBottom), ImVec2(io.DisplaySize.x-paddingLeftAndRight, io.DisplaySize.y-paddingTopAndBottom), { 0,1 }, { 1,0 });
}
}
ImGui::End();
ImGui::PopStyleVar(2);
LatteShaderCache_drawBackgroundImage(g_shaderCacheLoaderState.textureDRCId, 854, 480);
g_renderer->ImguiEnd();
}

Expand Down
8 changes: 0 additions & 8 deletions src/Cafe/HW/Latte/Core/LatteThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,9 @@ int Latte_ThreadEntry()
sint32 w,h;
gui_getWindowPhysSize(w,h);

// imgui
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();
io.WantSaveIniSettings = false;
io.IniFilename = nullptr;
io.Fonts->AddFontDefault();

// renderer
g_renderer->Initialize();
RendererOutputShader::InitializeStatic();
io.DisplaySize = ImVec2((float)w, (float)h);

LatteTiming_Init();
LatteTexture_init();
Expand Down
1 change: 1 addition & 0 deletions src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ void LoadOpenGLImports()

void OpenGLRenderer::Initialize()
{
Renderer::Initialize();
auto lock = cafeLog_acquire();
forceLog_printf("------- Init OpenGL graphics backend -------");

Expand Down

0 comments on commit cbb79fd

Please sign in to comment.