Skip to content

Commit cbb79fd

Browse files
Separate imgui contexts for TV and Pad windows. (#664)
1 parent daf3ef0 commit cbb79fd

File tree

8 files changed

+131
-184
lines changed

8 files changed

+131
-184
lines changed

src/Cafe/HW/Latte/Core/LatteOverlay.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void LatteOverlay_renderOverlay(ImVec2& position, ImVec2& pivot, sint32 directio
8080
{
8181
ImGui::SetNextWindowPos(position, ImGuiCond_Always, pivot);
8282
ImGui::SetNextWindowBgAlpha(kBackgroundAlpha);
83-
if (ImGui_BeginPadDistinct("Stats overlay", nullptr, kPopupFlags, pad))
83+
if (ImGui::Begin("Stats overlay", nullptr, kPopupFlags))
8484
{
8585
if (config.overlay.fps)
8686
ImGui::Text("FPS: %.2lf", g_state.fps);
@@ -141,7 +141,7 @@ void LatteOverlay_RenderNotifications(ImVec2& position, ImVec2& pivot, sint32 di
141141
// active account
142142
ImGui::SetNextWindowPos(position, ImGuiCond_Always, pivot);
143143
ImGui::SetNextWindowBgAlpha(kBackgroundAlpha);
144-
if (ImGui_BeginPadDistinct("Active account", nullptr, kPopupFlags, pad))
144+
if (ImGui::Begin("Active account", nullptr, kPopupFlags))
145145
{
146146
ImGui::TextUnformatted((const char*)ICON_FA_USER);
147147
ImGui::SameLine();
@@ -179,7 +179,7 @@ void LatteOverlay_RenderNotifications(ImVec2& position, ImVec2& pivot, sint32 di
179179
{
180180
ImGui::SetNextWindowPos(position, ImGuiCond_Always, pivot);
181181
ImGui::SetNextWindowBgAlpha(kBackgroundAlpha);
182-
if (ImGui_BeginPadDistinct("Controller profile names", nullptr, kPopupFlags, pad))
182+
if (ImGui::Begin("Controller profile names", nullptr, kPopupFlags))
183183
{
184184
auto it = profiles.cbegin();
185185
ImGui::TextUnformatted((const char*)ICON_FA_GAMEPAD);
@@ -227,7 +227,7 @@ void LatteOverlay_RenderNotifications(ImVec2& position, ImVec2& pivot, sint32 di
227227
{
228228
ImGui::SetNextWindowPos(position, ImGuiCond_Always, pivot);
229229
ImGui::SetNextWindowBgAlpha(kBackgroundAlpha);
230-
if (ImGui_BeginPadDistinct("Friends overlay", nullptr, kPopupFlags, pad))
230+
if (ImGui::Begin("Friends overlay", nullptr, kPopupFlags))
231231
{
232232
const auto tick = tick_cached();
233233
for (auto it = s_friend_list.cbegin(); it != s_friend_list.cend();)
@@ -274,7 +274,7 @@ void LatteOverlay_RenderNotifications(ImVec2& position, ImVec2& pivot, sint32 di
274274

275275
ImGui::SetNextWindowPos(position, ImGuiCond_Always, pivot);
276276
ImGui::SetNextWindowBgAlpha(kBackgroundAlpha);
277-
if (ImGui_BeginPadDistinct("Low battery overlay", nullptr, kPopupFlags, pad))
277+
if (ImGui::Begin("Low battery overlay", nullptr, kPopupFlags))
278278
{
279279
auto it = batteries.cbegin();
280280
ImGui::TextUnformatted((const char*)(s_blink_state ? ICON_FA_BATTERY_EMPTY : ICON_FA_BATTERY_QUARTER));
@@ -322,7 +322,7 @@ void LatteOverlay_RenderNotifications(ImVec2& position, ImVec2& pivot, sint32 di
322322
{
323323
ImGui::SetNextWindowPos(position, ImGuiCond_Always, pivot);
324324
ImGui::SetNextWindowBgAlpha(kBackgroundAlpha);
325-
if (ImGui_BeginPadDistinct("Compiling shaders overlay", nullptr, kPopupFlags, pad))
325+
if (ImGui::Begin("Compiling shaders overlay", nullptr, kPopupFlags))
326326
{
327327
ImRotateStart();
328328
ImGui::TextUnformatted((const char*)ICON_FA_SPINNER);
@@ -377,7 +377,7 @@ void LatteOverlay_RenderNotifications(ImVec2& position, ImVec2& pivot, sint32 di
377377
{
378378
ImGui::SetNextWindowPos(position, ImGuiCond_Always, pivot);
379379
ImGui::SetNextWindowBgAlpha(kBackgroundAlpha);
380-
if (ImGui_BeginPadDistinct("Compiling pipeline overlay", nullptr, kPopupFlags, pad))
380+
if (ImGui::Begin("Compiling pipeline overlay", nullptr, kPopupFlags))
381381
{
382382
ImRotateStart();
383383
ImGui::TextUnformatted((const char*)ICON_FA_SPINNER);
@@ -446,7 +446,7 @@ void LatteOverlay_RenderNotifications(ImVec2& position, ImVec2& pivot, sint32 di
446446
{
447447
ImGui::SetNextWindowPos(position, ImGuiCond_Always, pivot);
448448
ImGui::SetNextWindowBgAlpha(kBackgroundAlpha);
449-
if (ImGui_BeginPadDistinct("Misc notifications", nullptr, kPopupFlags, pad))
449+
if (ImGui::Begin("Misc notifications", nullptr, kPopupFlags))
450450
{
451451
const auto tick = tick_cached();
452452
for (auto it = s_misc_notifications.cbegin(); it != s_misc_notifications.cend();)

src/Cafe/HW/Latte/Core/LatteShaderCache.cpp

+78-158
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,43 @@ uint32 LatteShaderCache_getPipelineCacheExtraVersion(uint64 titleId)
178178
return extraVersion;
179179
}
180180

181+
void LatteShaderCache_drawBackgroundImage(ImTextureID texture, int width, int height)
182+
{
183+
// clear framebuffers and clean up
184+
const auto kPopupFlags =
185+
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoSavedSettings |
186+
ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_AlwaysAutoResize;
187+
auto& io = ImGui::GetIO();
188+
ImGui::SetNextWindowPos({0, 0}, ImGuiCond_Always);
189+
ImGui::SetNextWindowSize(io.DisplaySize, ImGuiCond_Always);
190+
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0);
191+
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {0, 0});
192+
if (ImGui::Begin("Background texture", nullptr, kPopupFlags))
193+
{
194+
if (texture)
195+
{
196+
float imageDisplayWidth = io.DisplaySize.x;
197+
float imageDisplayHeight = height * imageDisplayWidth / width;
198+
199+
float paddingLeftAndRight = 0.0f;
200+
float paddingTopAndBottom = (io.DisplaySize.y - imageDisplayHeight) / 2.0f;
201+
if (imageDisplayHeight > io.DisplaySize.y)
202+
{
203+
imageDisplayHeight = io.DisplaySize.y;
204+
imageDisplayWidth = width * imageDisplayHeight / height;
205+
paddingLeftAndRight = (io.DisplaySize.x - imageDisplayWidth) / 2.0f;
206+
paddingTopAndBottom = 0.0f;
207+
}
208+
209+
ImGui::GetWindowDrawList()->AddImage(texture, ImVec2(paddingLeftAndRight, paddingTopAndBottom),
210+
ImVec2(io.DisplaySize.x - paddingLeftAndRight,
211+
io.DisplaySize.y - paddingTopAndBottom), {0, 1}, {1, 0});
212+
}
213+
}
214+
ImGui::End();
215+
ImGui::PopStyleVar(2);
216+
}
217+
181218
void LatteShaderCache_load()
182219
{
183220
shaderCacheScreenStats.compiledShaderCount = 0;
@@ -231,48 +268,36 @@ void LatteShaderCache_load()
231268
g_shaderCacheLoaderState.loadedShaderFiles = 0;
232269

233270
// get game background loading image
234-
TGAFILE TVfile{};
235-
g_shaderCacheLoaderState.textureTVId = nullptr;
236-
237-
std::string tvTexPath = fmt::format("{}/meta/bootTvTex.tga", CafeSystem::GetMlcStoragePath(CafeSystem::GetForegroundTitleId()));
238-
sint32 statusTV;
239-
auto fscfile = fsc_open(tvTexPath.c_str(), FSC_ACCESS_FLAG::OPEN_FILE | FSC_ACCESS_FLAG::READ_PERMISSION, &statusTV);
240-
if (fscfile)
271+
auto loadBackgroundTexture = [](bool isTV, ImTextureID& out)
241272
{
242-
uint32 size = fsc_getFileSize(fscfile);
243-
if (size > 0)
244-
{
245-
std::vector<uint8> tmpData(size);
246-
fsc_readFile(fscfile, tmpData.data(), size);
247-
const bool backgroundLoaded = LoadTGAFile(tmpData, &TVfile);
273+
TGAFILE file{};
274+
out = nullptr;
248275

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

253-
fsc_close(fscfile);
254-
}
255-
//get game background loading image for DRC
256-
TGAFILE DRCfile{};
257-
g_shaderCacheLoaderState.textureDRCId = nullptr;
258-
259-
std::string drcTexPath = fmt::format("{}/meta/bootDRCTex.tga", CafeSystem::GetMlcStoragePath(CafeSystem::GetForegroundTitleId()));
260-
sint32 statusDRC;
261-
auto fscfile2 = fsc_open(drcTexPath.c_str(), FSC_ACCESS_FLAG::OPEN_FILE | FSC_ACCESS_FLAG::READ_PERMISSION, &statusDRC);
262-
if (fscfile2)
263-
{
264-
uint32 size = fsc_getFileSize(fscfile2);
265-
if (size > 0)
278+
std::string texPath = fmt::format("{}/meta/{}", CafeSystem::GetMlcStoragePath(CafeSystem::GetForegroundTitleId()), fileName);
279+
sint32 status;
280+
auto fscfile = fsc_open(texPath.c_str(), FSC_ACCESS_FLAG::OPEN_FILE | FSC_ACCESS_FLAG::READ_PERMISSION, &status);
281+
if (fscfile)
266282
{
267-
std::vector<uint8> tmpData(size);
268-
fsc_readFile(fscfile2, tmpData.data(), size);
269-
const bool backgroundLoaded = LoadTGAFile(tmpData, &DRCfile);
283+
uint32 size = fsc_getFileSize(fscfile);
284+
if (size > 0)
285+
{
286+
std::vector<uint8> tmpData(size);
287+
fsc_readFile(fscfile, tmpData.data(), size);
288+
const bool backgroundLoaded = LoadTGAFile(tmpData, &file);
270289

271-
if (backgroundLoaded)
272-
g_shaderCacheLoaderState.textureDRCId = g_renderer->GenerateTexture(DRCfile.imageData, { DRCfile.imageWidth, DRCfile.imageHeight });
290+
if (backgroundLoaded)
291+
out = g_renderer->GenerateTexture(file.imageData, { file.imageWidth, file.imageHeight });
292+
}
293+
294+
fsc_close(fscfile);
273295
}
274-
fsc_close(fscfile2);
275-
}
296+
};
297+
298+
loadBackgroundTexture(true, g_shaderCacheLoaderState.textureTVId);
299+
loadBackgroundTexture(false, g_shaderCacheLoaderState.textureDRCId);
300+
276301
sint32 numLoadedShaders = 0;
277302
uint32 loadIndex = 0;
278303

@@ -319,79 +344,22 @@ void LatteShaderCache_load()
319344
if (g_renderer->GetType() == RendererAPI::Vulkan)
320345
LatteShaderCache_loadVulkanPipelineCache(cacheTitleId);
321346

322-
// clear framebuffers and clean up
323-
auto& io = ImGui::GetIO();
324-
const auto kPopupFlags = ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_AlwaysAutoResize;
325-
for (int i = 0; i < 2; ++i)
326-
{
327-
g_renderer->BeginFrame(true);
328-
if (g_renderer->ImguiBegin(true))
329-
{
330-
ImGui::SetNextWindowPos({ 0,0 }, ImGuiCond_Always);
331-
ImGui::SetNextWindowSize(io.DisplaySize, ImGuiCond_Always);
332-
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0);
333-
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, { 0,0 });
334-
if (ImGui::Begin("Background texture", nullptr, kPopupFlags))
335-
{
336-
if (g_shaderCacheLoaderState.textureTVId)
337-
{
338-
float imageDisplayWidth = io.DisplaySize.x;
339-
float imageDisplayHeight = 720 * imageDisplayWidth / 1280;
340-
341-
float paddingLeftAndRight = 0.0f;
342-
float paddingTopAndBottom = (io.DisplaySize.y - imageDisplayHeight)/2.0f;
343-
if (imageDisplayHeight > io.DisplaySize.y)
344-
{
345-
imageDisplayHeight = io.DisplaySize.y;
346-
imageDisplayWidth = 1280 * imageDisplayHeight / 720;
347-
paddingLeftAndRight = (io.DisplaySize.x - imageDisplayWidth)/2.0f;
348-
paddingTopAndBottom = 0.0f;
349-
}
350-
351-
ImGui::GetWindowDrawList()->AddImage(g_shaderCacheLoaderState.textureTVId, ImVec2(paddingLeftAndRight, paddingTopAndBottom), ImVec2(io.DisplaySize.x-paddingLeftAndRight, io.DisplaySize.y-paddingTopAndBottom), { 0,1 }, { 1,0 });
352-
}
353-
}
354-
ImGui::End();
355-
ImGui::PopStyleVar(2);
356-
g_renderer->ImguiEnd();
357-
}
358347

359-
g_renderer->BeginFrame(false);
360-
if (g_renderer->ImguiBegin(false))
361-
{
362-
ImGui::SetNextWindowPos({ 0,0 }, ImGuiCond_Always);
363-
ImGui::SetNextWindowSize(io.DisplaySize, ImGuiCond_Always);
364-
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0);
365-
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, { 0,0 });
366-
367-
if (ImGui::Begin("Background texture2", nullptr, kPopupFlags))
368-
{
369-
if (g_shaderCacheLoaderState.textureDRCId)
370-
{
371-
float imageDisplayWidth = io.DisplaySize.x;
372-
float imageDisplayHeight = 480 * imageDisplayWidth / 854;
373-
374-
float paddingLeftAndRight = 0.0f;
375-
float paddingTopAndBottom = (io.DisplaySize.y - imageDisplayHeight)/2.0f;
376-
if (imageDisplayHeight > io.DisplaySize.y)
377-
{
378-
imageDisplayHeight = io.DisplaySize.y;
379-
imageDisplayWidth = 854 * imageDisplayHeight / 480;
380-
paddingLeftAndRight = (io.DisplaySize.x - imageDisplayWidth)/2.0f;
381-
paddingTopAndBottom = 0.0f;
382-
}
383-
384-
ImGui::GetWindowDrawList()->AddImage(g_shaderCacheLoaderState.textureDRCId, ImVec2(paddingLeftAndRight, paddingTopAndBottom), ImVec2(io.DisplaySize.x-paddingLeftAndRight, io.DisplaySize.y-paddingTopAndBottom), { 0,1 }, { 1,0 });
385-
}
386-
}
387-
ImGui::End();
388-
ImGui::PopStyleVar(2);
389-
g_renderer->ImguiEnd();
390-
}
391-
392-
g_renderer->SwapBuffers(true, true);
348+
g_renderer->BeginFrame(true);
349+
if (g_renderer->ImguiBegin(true))
350+
{
351+
LatteShaderCache_drawBackgroundImage(g_shaderCacheLoaderState.textureTVId, 1280, 720);
352+
g_renderer->ImguiEnd();
353+
}
354+
g_renderer->BeginFrame(false);
355+
if (g_renderer->ImguiBegin(false))
356+
{
357+
LatteShaderCache_drawBackgroundImage(g_shaderCacheLoaderState.textureDRCId, 854, 480);
358+
g_renderer->ImguiEnd();
393359
}
394360

361+
g_renderer->SwapBuffers(true, true);
362+
395363
if (g_shaderCacheLoaderState.textureTVId)
396364
g_renderer->DeleteTexture(g_shaderCacheLoaderState.textureTVId);
397365
if (g_shaderCacheLoaderState.textureDRCId)
@@ -427,35 +395,11 @@ void LatteShaderCache_ShowProgress(const std::function <bool(void)>& loadUpdateF
427395
g_renderer->BeginFrame(true);
428396
if (g_renderer->ImguiBegin(true))
429397
{
398+
// render background texture
399+
LatteShaderCache_drawBackgroundImage(g_shaderCacheLoaderState.textureTVId, 1280, 720);
400+
430401
const auto progress_font = ImGui_GetFont(window_size.y / 32.0f); // = 24 by default
431402
const auto shader_count_font = ImGui_GetFont(window_size.y / 48.0f); // = 16
432-
// render background texture
433-
if (g_shaderCacheLoaderState.textureTVId)
434-
{
435-
ImGui::SetNextWindowPos({ 0, 0 }, ImGuiCond_Always);
436-
ImGui::SetNextWindowSize(io.DisplaySize, ImGuiCond_Always);
437-
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0);
438-
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, { 0, 0 });
439-
if (ImGui::Begin("Background texture", nullptr, kPopupFlags | ImGuiWindowFlags_NoBringToFrontOnFocus))
440-
{
441-
float imageDisplayWidth = io.DisplaySize.x;
442-
float imageDisplayHeight = 720 * imageDisplayWidth / 1280;
443-
444-
float paddingLeftAndRight = 0.0f;
445-
float paddingTopAndBottom = (io.DisplaySize.y - imageDisplayHeight) / 2.0f;
446-
if (imageDisplayHeight > io.DisplaySize.y)
447-
{
448-
imageDisplayHeight = io.DisplaySize.y;
449-
imageDisplayWidth = 1280 * imageDisplayHeight / 720;
450-
paddingLeftAndRight = (io.DisplaySize.x - imageDisplayWidth) / 2.0f;
451-
paddingTopAndBottom = 0.0f;
452-
}
453-
454-
ImGui::GetWindowDrawList()->AddImage(g_shaderCacheLoaderState.textureTVId, ImVec2(paddingLeftAndRight, paddingTopAndBottom), ImVec2(io.DisplaySize.x-paddingLeftAndRight, io.DisplaySize.y-paddingTopAndBottom), { 0,1 }, { 1,0 });
455-
}
456-
ImGui::End();
457-
ImGui::PopStyleVar(2);
458-
}
459403

460404
ImVec2 position = { window_size.x / 2.0f, window_size.y / 2.0f };
461405
ImVec2 pivot = { 0.5f, 0.5f };
@@ -541,31 +485,7 @@ void LatteShaderCache_ShowProgress(const std::function <bool(void)>& loadUpdateF
541485
g_renderer->BeginFrame(false);
542486
if (g_renderer->ImguiBegin(false))
543487
{
544-
ImGui::SetNextWindowPos({ 0,0 }, ImGuiCond_Always);
545-
ImGui::SetNextWindowSize(io.DisplaySize, ImGuiCond_Always);
546-
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0);
547-
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, { 0,0 });
548-
if (ImGui::Begin("Background texture2", nullptr, kPopupFlags))
549-
{
550-
if (g_shaderCacheLoaderState.textureDRCId)
551-
{
552-
float imageDisplayWidth = io.DisplaySize.x;
553-
float imageDisplayHeight = 480 * imageDisplayWidth / 854;
554-
555-
float paddingLeftAndRight = 0.0f;
556-
float paddingTopAndBottom = (io.DisplaySize.y - imageDisplayHeight)/2.0f;
557-
if (imageDisplayHeight > io.DisplaySize.y)
558-
{
559-
imageDisplayHeight = io.DisplaySize.y;
560-
imageDisplayWidth = 854 * imageDisplayHeight / 480;
561-
paddingLeftAndRight = (io.DisplaySize.x - imageDisplayWidth)/2.0f;
562-
paddingTopAndBottom = 0.0f;
563-
}
564-
ImGui::GetWindowDrawList()->AddImage(g_shaderCacheLoaderState.textureDRCId, ImVec2(paddingLeftAndRight, paddingTopAndBottom), ImVec2(io.DisplaySize.x-paddingLeftAndRight, io.DisplaySize.y-paddingTopAndBottom), { 0,1 }, { 1,0 });
565-
}
566-
}
567-
ImGui::End();
568-
ImGui::PopStyleVar(2);
488+
LatteShaderCache_drawBackgroundImage(g_shaderCacheLoaderState.textureDRCId, 854, 480);
569489
g_renderer->ImguiEnd();
570490
}
571491

src/Cafe/HW/Latte/Core/LatteThread.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,9 @@ int Latte_ThreadEntry()
119119
sint32 w,h;
120120
gui_getWindowPhysSize(w,h);
121121

122-
// imgui
123-
ImGui::CreateContext();
124-
ImGuiIO& io = ImGui::GetIO();
125-
io.WantSaveIniSettings = false;
126-
io.IniFilename = nullptr;
127-
io.Fonts->AddFontDefault();
128-
129122
// renderer
130123
g_renderer->Initialize();
131124
RendererOutputShader::InitializeStatic();
132-
io.DisplaySize = ImVec2((float)w, (float)h);
133125

134126
LatteTiming_Init();
135127
LatteTexture_init();

src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ void LoadOpenGLImports()
252252

253253
void OpenGLRenderer::Initialize()
254254
{
255+
Renderer::Initialize();
255256
auto lock = cafeLog_acquire();
256257
forceLog_printf("------- Init OpenGL graphics backend -------");
257258

0 commit comments

Comments
 (0)