2023-01-27 04:03:15 +00:00
|
|
|
// Copyright 2023 Dolphin Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
|
|
#include "VideoCommon/OnScreenUI.h"
|
|
|
|
|
2023-02-03 06:11:31 +00:00
|
|
|
#include "Common/EnumMap.h"
|
2023-01-27 04:03:15 +00:00
|
|
|
#include "Common/Profiler.h"
|
|
|
|
#include "Common/Timer.h"
|
|
|
|
|
2023-10-20 12:38:20 +00:00
|
|
|
#include "Core/AchievementManager.h"
|
2023-01-27 04:03:15 +00:00
|
|
|
#include "Core/Config/MainSettings.h"
|
|
|
|
#include "Core/Config/NetplaySettings.h"
|
|
|
|
#include "Core/Movie.h"
|
2024-01-13 12:14:48 +00:00
|
|
|
#include "Core/System.h"
|
2023-01-27 04:03:15 +00:00
|
|
|
|
2023-01-26 22:34:59 +00:00
|
|
|
#include "VideoCommon/AbstractGfx.h"
|
2023-01-27 04:03:15 +00:00
|
|
|
#include "VideoCommon/AbstractPipeline.h"
|
|
|
|
#include "VideoCommon/AbstractShader.h"
|
|
|
|
#include "VideoCommon/FramebufferShaderGen.h"
|
|
|
|
#include "VideoCommon/NetPlayChatUI.h"
|
|
|
|
#include "VideoCommon/NetPlayGolfUI.h"
|
|
|
|
#include "VideoCommon/OnScreenDisplay.h"
|
|
|
|
#include "VideoCommon/PerformanceMetrics.h"
|
|
|
|
#include "VideoCommon/Present.h"
|
|
|
|
#include "VideoCommon/Statistics.h"
|
|
|
|
#include "VideoCommon/VertexManagerBase.h"
|
|
|
|
#include "VideoCommon/VideoConfig.h"
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <mutex>
|
|
|
|
|
|
|
|
#include <imgui.h>
|
|
|
|
#include <implot.h>
|
|
|
|
|
|
|
|
namespace VideoCommon
|
|
|
|
{
|
|
|
|
bool OnScreenUI::Initialize(u32 width, u32 height, float scale)
|
|
|
|
{
|
|
|
|
std::unique_lock<std::mutex> imgui_lock(m_imgui_mutex);
|
|
|
|
|
|
|
|
if (!IMGUI_CHECKVERSION())
|
|
|
|
{
|
|
|
|
PanicAlertFmt("ImGui version check failed");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!ImGui::CreateContext())
|
|
|
|
{
|
|
|
|
PanicAlertFmt("Creating ImGui context failed");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!ImPlot::CreateContext())
|
|
|
|
{
|
|
|
|
PanicAlertFmt("Creating ImPlot context failed");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't create an ini file. TODO: Do we want this in the future?
|
|
|
|
ImGui::GetIO().IniFilename = nullptr;
|
|
|
|
SetScale(scale);
|
|
|
|
|
|
|
|
PortableVertexDeclaration vdecl = {};
|
|
|
|
vdecl.position = {ComponentFormat::Float, 2, offsetof(ImDrawVert, pos), true, false};
|
|
|
|
vdecl.texcoords[0] = {ComponentFormat::Float, 2, offsetof(ImDrawVert, uv), true, false};
|
|
|
|
vdecl.colors[0] = {ComponentFormat::UByte, 4, offsetof(ImDrawVert, col), true, false};
|
|
|
|
vdecl.stride = sizeof(ImDrawVert);
|
2023-01-26 22:34:59 +00:00
|
|
|
m_imgui_vertex_format = g_gfx->CreateNativeVertexFormat(vdecl);
|
2023-01-27 04:03:15 +00:00
|
|
|
if (!m_imgui_vertex_format)
|
|
|
|
{
|
|
|
|
PanicAlertFmt("Failed to create ImGui vertex format");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Font texture(s).
|
|
|
|
{
|
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
u8* font_tex_pixels;
|
|
|
|
int font_tex_width, font_tex_height;
|
|
|
|
io.Fonts->GetTexDataAsRGBA32(&font_tex_pixels, &font_tex_width, &font_tex_height);
|
|
|
|
|
|
|
|
TextureConfig font_tex_config(font_tex_width, font_tex_height, 1, 1, 1,
|
2023-12-10 01:00:11 +00:00
|
|
|
AbstractTextureFormat::RGBA8, 0,
|
|
|
|
AbstractTextureType::Texture_2DArray);
|
2023-01-27 04:03:15 +00:00
|
|
|
std::unique_ptr<AbstractTexture> font_tex =
|
2023-01-26 22:34:59 +00:00
|
|
|
g_gfx->CreateTexture(font_tex_config, "ImGui font texture");
|
2023-01-27 04:03:15 +00:00
|
|
|
if (!font_tex)
|
|
|
|
{
|
|
|
|
PanicAlertFmt("Failed to create ImGui texture");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
font_tex->Load(0, font_tex_width, font_tex_height, font_tex_width, font_tex_pixels,
|
|
|
|
sizeof(u32) * font_tex_width * font_tex_height);
|
|
|
|
|
|
|
|
io.Fonts->TexID = font_tex.get();
|
|
|
|
|
|
|
|
m_imgui_textures.push_back(std::move(font_tex));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!RecompileImGuiPipeline())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
m_imgui_last_frame_time = Common::Timer::NowUs();
|
|
|
|
m_ready = true;
|
|
|
|
BeginImGuiFrameUnlocked(width, height); // lock is already held
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
OnScreenUI::~OnScreenUI()
|
|
|
|
{
|
|
|
|
std::unique_lock<std::mutex> imgui_lock(m_imgui_mutex);
|
|
|
|
|
|
|
|
ImGui::EndFrame();
|
|
|
|
ImPlot::DestroyContext();
|
|
|
|
ImGui::DestroyContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OnScreenUI::RecompileImGuiPipeline()
|
|
|
|
{
|
|
|
|
if (g_presenter->GetBackbufferFormat() == AbstractTextureFormat::Undefined)
|
|
|
|
{
|
|
|
|
// No backbuffer (nogui) means no imgui rendering will happen
|
|
|
|
// Some backends don't like making pipelines with no render targets
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
Video: implement color correction to match the NTSC and PAL color spaces (and gamma) that GC and Wii targeted.
To further increase the accuracy of the post process phase, I've added (scRGB) HDR support, which is necessary
to fully display the PAL and NTSC-J color spaces, and also to improve the quality of post process texture samplings and
do them in linear space instead of gamma space (which is very important when playing at low resolutions).
For SDR, the quality is also slightly increased, at least if any post process runs, as the buffer is now
R10G10B10A2 (on Vulkan, DX11 and DX12) if supported; previously it was R8G8B8A8 but the alpha bits were wasted.
Gamma correction is arguably the most important thing as Dolphin on Windows outputted in "sRGB" (implicitly)
as that's what Windows expects by default, though sRGB gamma is very different from the gamma commonly used
by video standards dating to the pre HDR era (roughly gamma 2.35).
Additionally, the addition of HDR support (which is pretty straight forward and minimal), added support for
our own custom AutoHDR shaders, which would allow us to achieve decent looking HDR in Dolphin games without
having to use SpecialK or Windows 11 AutoHDR. Both of which don't necessarily play nice with older games
with strongly different and simpler lighting. HDR should also be supported in Linux.
Development of my own AutoHDR shader is almost complete and will come next.
This has been carefully tested and there should be no regression in any of the different features that Dolphin
offers, like multisampling, stereo rendering, other post processes, etc etc.
Fixes: https://bugs.dolphin-emu.org/issues/8941
Co-authored-by: EndlesslyFlowering <EndlesslyFlowering@protonmail.com>
Co-authored-by: Dogway <lin_ares@hotmail.com>
2023-06-10 08:48:05 +00:00
|
|
|
const bool linear_space_output =
|
|
|
|
g_presenter->GetBackbufferFormat() == AbstractTextureFormat::RGBA16F;
|
|
|
|
|
2023-01-26 22:34:59 +00:00
|
|
|
std::unique_ptr<AbstractShader> vertex_shader = g_gfx->CreateShaderFromSource(
|
2023-01-27 04:03:15 +00:00
|
|
|
ShaderStage::Vertex, FramebufferShaderGen::GenerateImGuiVertexShader(),
|
|
|
|
"ImGui vertex shader");
|
2023-01-26 22:34:59 +00:00
|
|
|
std::unique_ptr<AbstractShader> pixel_shader = g_gfx->CreateShaderFromSource(
|
Video: implement color correction to match the NTSC and PAL color spaces (and gamma) that GC and Wii targeted.
To further increase the accuracy of the post process phase, I've added (scRGB) HDR support, which is necessary
to fully display the PAL and NTSC-J color spaces, and also to improve the quality of post process texture samplings and
do them in linear space instead of gamma space (which is very important when playing at low resolutions).
For SDR, the quality is also slightly increased, at least if any post process runs, as the buffer is now
R10G10B10A2 (on Vulkan, DX11 and DX12) if supported; previously it was R8G8B8A8 but the alpha bits were wasted.
Gamma correction is arguably the most important thing as Dolphin on Windows outputted in "sRGB" (implicitly)
as that's what Windows expects by default, though sRGB gamma is very different from the gamma commonly used
by video standards dating to the pre HDR era (roughly gamma 2.35).
Additionally, the addition of HDR support (which is pretty straight forward and minimal), added support for
our own custom AutoHDR shaders, which would allow us to achieve decent looking HDR in Dolphin games without
having to use SpecialK or Windows 11 AutoHDR. Both of which don't necessarily play nice with older games
with strongly different and simpler lighting. HDR should also be supported in Linux.
Development of my own AutoHDR shader is almost complete and will come next.
This has been carefully tested and there should be no regression in any of the different features that Dolphin
offers, like multisampling, stereo rendering, other post processes, etc etc.
Fixes: https://bugs.dolphin-emu.org/issues/8941
Co-authored-by: EndlesslyFlowering <EndlesslyFlowering@protonmail.com>
Co-authored-by: Dogway <lin_ares@hotmail.com>
2023-06-10 08:48:05 +00:00
|
|
|
ShaderStage::Pixel, FramebufferShaderGen::GenerateImGuiPixelShader(linear_space_output),
|
|
|
|
"ImGui pixel shader");
|
2023-01-27 04:03:15 +00:00
|
|
|
if (!vertex_shader || !pixel_shader)
|
|
|
|
{
|
|
|
|
PanicAlertFmt("Failed to compile ImGui shaders");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// GS is used to render the UI to both eyes in stereo modes.
|
|
|
|
std::unique_ptr<AbstractShader> geometry_shader;
|
2023-01-26 22:34:59 +00:00
|
|
|
if (g_gfx->UseGeometryShaderForUI())
|
2023-01-27 04:03:15 +00:00
|
|
|
{
|
2023-01-26 22:34:59 +00:00
|
|
|
geometry_shader = g_gfx->CreateShaderFromSource(
|
2023-01-27 04:03:15 +00:00
|
|
|
ShaderStage::Geometry, FramebufferShaderGen::GeneratePassthroughGeometryShader(1, 1),
|
|
|
|
"ImGui passthrough geometry shader");
|
|
|
|
if (!geometry_shader)
|
|
|
|
{
|
|
|
|
PanicAlertFmt("Failed to compile ImGui geometry shader");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AbstractPipelineConfig pconfig = {};
|
|
|
|
pconfig.vertex_format = m_imgui_vertex_format.get();
|
|
|
|
pconfig.vertex_shader = vertex_shader.get();
|
|
|
|
pconfig.geometry_shader = geometry_shader.get();
|
|
|
|
pconfig.pixel_shader = pixel_shader.get();
|
|
|
|
pconfig.rasterization_state = RenderState::GetNoCullRasterizationState(PrimitiveType::Triangles);
|
|
|
|
pconfig.depth_state = RenderState::GetNoDepthTestingDepthState();
|
|
|
|
pconfig.blending_state = RenderState::GetNoBlendingBlendState();
|
|
|
|
pconfig.blending_state.blendenable = true;
|
|
|
|
pconfig.blending_state.srcfactor = SrcBlendFactor::SrcAlpha;
|
|
|
|
pconfig.blending_state.dstfactor = DstBlendFactor::InvSrcAlpha;
|
|
|
|
pconfig.blending_state.srcfactoralpha = SrcBlendFactor::Zero;
|
|
|
|
pconfig.blending_state.dstfactoralpha = DstBlendFactor::One;
|
|
|
|
pconfig.framebuffer_state.color_texture_format = g_presenter->GetBackbufferFormat();
|
|
|
|
pconfig.framebuffer_state.depth_texture_format = AbstractTextureFormat::Undefined;
|
|
|
|
pconfig.framebuffer_state.samples = 1;
|
|
|
|
pconfig.framebuffer_state.per_sample_shading = false;
|
|
|
|
pconfig.usage = AbstractPipelineUsage::Utility;
|
2023-01-26 22:34:59 +00:00
|
|
|
m_imgui_pipeline = g_gfx->CreatePipeline(pconfig);
|
2023-01-27 04:03:15 +00:00
|
|
|
if (!m_imgui_pipeline)
|
|
|
|
{
|
|
|
|
PanicAlertFmt("Failed to create imgui pipeline");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnScreenUI::BeginImGuiFrame(u32 width, u32 height)
|
|
|
|
{
|
|
|
|
std::unique_lock<std::mutex> imgui_lock(m_imgui_mutex);
|
|
|
|
BeginImGuiFrameUnlocked(width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnScreenUI::BeginImGuiFrameUnlocked(u32 width, u32 height)
|
|
|
|
{
|
|
|
|
m_backbuffer_width = width;
|
|
|
|
m_backbuffer_height = height;
|
|
|
|
|
|
|
|
const u64 current_time_us = Common::Timer::NowUs();
|
|
|
|
const u64 time_diff_us = current_time_us - m_imgui_last_frame_time;
|
|
|
|
const float time_diff_secs = static_cast<float>(time_diff_us / 1000000.0);
|
|
|
|
m_imgui_last_frame_time = current_time_us;
|
|
|
|
|
|
|
|
// Update I/O with window dimensions.
|
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
io.DisplaySize =
|
|
|
|
ImVec2(static_cast<float>(m_backbuffer_width), static_cast<float>(m_backbuffer_height));
|
|
|
|
io.DeltaTime = time_diff_secs;
|
|
|
|
|
|
|
|
ImGui::NewFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnScreenUI::DrawImGui()
|
|
|
|
{
|
|
|
|
ImDrawData* draw_data = ImGui::GetDrawData();
|
|
|
|
if (!draw_data)
|
|
|
|
return;
|
|
|
|
|
2023-01-26 22:34:59 +00:00
|
|
|
g_gfx->SetViewport(0.0f, 0.0f, static_cast<float>(m_backbuffer_width),
|
|
|
|
static_cast<float>(m_backbuffer_height), 0.0f, 1.0f);
|
2023-01-27 04:03:15 +00:00
|
|
|
|
|
|
|
// Uniform buffer for draws.
|
|
|
|
struct ImGuiUbo
|
|
|
|
{
|
|
|
|
float u_rcp_viewport_size_mul2[2];
|
|
|
|
float padding[2];
|
|
|
|
};
|
|
|
|
ImGuiUbo ubo = {{1.0f / m_backbuffer_width * 2.0f, 1.0f / m_backbuffer_height * 2.0f}};
|
|
|
|
|
|
|
|
// Set up common state for drawing.
|
2023-01-26 22:34:59 +00:00
|
|
|
g_gfx->SetPipeline(m_imgui_pipeline.get());
|
|
|
|
g_gfx->SetSamplerState(0, RenderState::GetPointSamplerState());
|
2023-01-27 04:03:15 +00:00
|
|
|
g_vertex_manager->UploadUtilityUniforms(&ubo, sizeof(ubo));
|
|
|
|
|
|
|
|
for (int i = 0; i < draw_data->CmdListsCount; i++)
|
|
|
|
{
|
|
|
|
const ImDrawList* cmdlist = draw_data->CmdLists[i];
|
|
|
|
if (cmdlist->VtxBuffer.empty() || cmdlist->IdxBuffer.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
u32 base_vertex, base_index;
|
|
|
|
g_vertex_manager->UploadUtilityVertices(cmdlist->VtxBuffer.Data, sizeof(ImDrawVert),
|
|
|
|
cmdlist->VtxBuffer.Size, cmdlist->IdxBuffer.Data,
|
|
|
|
cmdlist->IdxBuffer.Size, &base_vertex, &base_index);
|
|
|
|
|
|
|
|
for (const ImDrawCmd& cmd : cmdlist->CmdBuffer)
|
|
|
|
{
|
|
|
|
if (cmd.UserCallback)
|
|
|
|
{
|
|
|
|
cmd.UserCallback(cmdlist, &cmd);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-01-26 22:34:59 +00:00
|
|
|
g_gfx->SetScissorRect(g_gfx->ConvertFramebufferRectangle(
|
2023-01-27 04:03:15 +00:00
|
|
|
MathUtil::Rectangle<int>(
|
|
|
|
static_cast<int>(cmd.ClipRect.x), static_cast<int>(cmd.ClipRect.y),
|
|
|
|
static_cast<int>(cmd.ClipRect.z), static_cast<int>(cmd.ClipRect.w)),
|
2023-01-26 22:34:59 +00:00
|
|
|
g_gfx->GetCurrentFramebuffer()));
|
|
|
|
g_gfx->SetTexture(0, reinterpret_cast<const AbstractTexture*>(cmd.TextureId));
|
|
|
|
g_gfx->DrawIndexed(base_index, cmd.ElemCount, base_vertex);
|
2023-01-27 04:03:15 +00:00
|
|
|
base_index += cmd.ElemCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Some capture software (such as OBS) hooks SwapBuffers and uses glBlitFramebuffer to copy our
|
|
|
|
// back buffer just before swap. Because glBlitFramebuffer honors the scissor test, the capture
|
|
|
|
// itself will be clipped to whatever bounds were last set by ImGui, resulting in a rather useless
|
|
|
|
// capture whenever any ImGui windows are open. We'll reset the scissor rectangle to the entire
|
|
|
|
// viewport here to avoid this problem.
|
2023-01-26 22:34:59 +00:00
|
|
|
g_gfx->SetScissorRect(g_gfx->ConvertFramebufferRectangle(
|
2023-01-27 04:03:15 +00:00
|
|
|
MathUtil::Rectangle<int>(0, 0, m_backbuffer_width, m_backbuffer_height),
|
2023-01-26 22:34:59 +00:00
|
|
|
g_gfx->GetCurrentFramebuffer()));
|
2023-01-27 04:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create On-Screen-Messages
|
|
|
|
void OnScreenUI::DrawDebugText()
|
|
|
|
{
|
|
|
|
const bool show_movie_window =
|
|
|
|
Config::Get(Config::MAIN_SHOW_FRAME_COUNT) || Config::Get(Config::MAIN_SHOW_LAG) ||
|
|
|
|
Config::Get(Config::MAIN_MOVIE_SHOW_INPUT_DISPLAY) ||
|
|
|
|
Config::Get(Config::MAIN_MOVIE_SHOW_RTC) || Config::Get(Config::MAIN_MOVIE_SHOW_RERECORD);
|
|
|
|
if (show_movie_window)
|
|
|
|
{
|
|
|
|
// Position under the FPS display.
|
|
|
|
ImGui::SetNextWindowPos(
|
|
|
|
ImVec2(ImGui::GetIO().DisplaySize.x - 10.f * m_backbuffer_scale, 80.f * m_backbuffer_scale),
|
|
|
|
ImGuiCond_FirstUseEver, ImVec2(1.0f, 0.0f));
|
|
|
|
ImGui::SetNextWindowSizeConstraints(
|
|
|
|
ImVec2(150.0f * m_backbuffer_scale, 20.0f * m_backbuffer_scale),
|
|
|
|
ImGui::GetIO().DisplaySize);
|
|
|
|
if (ImGui::Begin("Movie", nullptr, ImGuiWindowFlags_NoFocusOnAppearing))
|
|
|
|
{
|
2024-01-13 12:14:48 +00:00
|
|
|
auto& movie = Core::System::GetInstance().GetMovie();
|
|
|
|
if (movie.IsPlayingInput())
|
2023-01-27 04:03:15 +00:00
|
|
|
{
|
2024-01-13 12:14:48 +00:00
|
|
|
ImGui::Text("Frame: %" PRIu64 " / %" PRIu64, movie.GetCurrentFrame(),
|
|
|
|
movie.GetTotalFrames());
|
|
|
|
ImGui::Text("Input: %" PRIu64 " / %" PRIu64, movie.GetCurrentInputCount(),
|
|
|
|
movie.GetTotalInputCount());
|
2023-01-27 04:03:15 +00:00
|
|
|
}
|
|
|
|
else if (Config::Get(Config::MAIN_SHOW_FRAME_COUNT))
|
|
|
|
{
|
2024-01-13 12:14:48 +00:00
|
|
|
ImGui::Text("Frame: %" PRIu64, movie.GetCurrentFrame());
|
2024-04-27 00:06:57 +00:00
|
|
|
if (movie.IsRecordingInput())
|
|
|
|
ImGui::Text("Input: %" PRIu64, movie.GetCurrentInputCount());
|
2023-01-27 04:03:15 +00:00
|
|
|
}
|
|
|
|
if (Config::Get(Config::MAIN_SHOW_LAG))
|
2024-01-13 12:14:48 +00:00
|
|
|
ImGui::Text("Lag: %" PRIu64 "\n", movie.GetCurrentLagCount());
|
2023-01-27 04:03:15 +00:00
|
|
|
if (Config::Get(Config::MAIN_MOVIE_SHOW_INPUT_DISPLAY))
|
2024-01-13 12:14:48 +00:00
|
|
|
ImGui::TextUnformatted(movie.GetInputDisplay().c_str());
|
2023-01-27 04:03:15 +00:00
|
|
|
if (Config::Get(Config::MAIN_MOVIE_SHOW_RTC))
|
2024-01-13 12:14:48 +00:00
|
|
|
ImGui::TextUnformatted(movie.GetRTCDisplay().c_str());
|
2023-01-27 04:03:15 +00:00
|
|
|
if (Config::Get(Config::MAIN_MOVIE_SHOW_RERECORD))
|
2024-01-13 12:14:48 +00:00
|
|
|
ImGui::TextUnformatted(movie.GetRerecords().c_str());
|
2023-01-27 04:03:15 +00:00
|
|
|
}
|
|
|
|
ImGui::End();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_ActiveConfig.bOverlayStats)
|
|
|
|
g_stats.Display();
|
|
|
|
|
|
|
|
if (g_ActiveConfig.bShowNetPlayMessages && g_netplay_chat_ui)
|
|
|
|
g_netplay_chat_ui->Display();
|
|
|
|
|
|
|
|
if (Config::Get(Config::NETPLAY_GOLF_MODE_OVERLAY) && g_netplay_golf_ui)
|
|
|
|
g_netplay_golf_ui->Display();
|
|
|
|
|
|
|
|
if (g_ActiveConfig.bOverlayProjStats)
|
|
|
|
g_stats.DisplayProj();
|
|
|
|
|
|
|
|
if (g_ActiveConfig.bOverlayScissorStats)
|
|
|
|
g_stats.DisplayScissor();
|
|
|
|
|
|
|
|
const std::string profile_output = Common::Profiler::ToString();
|
|
|
|
if (!profile_output.empty())
|
|
|
|
ImGui::TextUnformatted(profile_output.c_str());
|
|
|
|
}
|
|
|
|
|
2024-02-24 17:06:59 +00:00
|
|
|
void OnScreenUI::DrawChallengesAndLeaderboards()
|
2023-10-20 12:38:20 +00:00
|
|
|
{
|
2024-06-14 04:19:45 +00:00
|
|
|
if (!Config::Get(Config::MAIN_OSD_MESSAGES))
|
|
|
|
return;
|
2024-06-04 14:20:20 +00:00
|
|
|
#ifdef USE_RETRO_ACHIEVEMENTS
|
2024-06-13 04:03:46 +00:00
|
|
|
auto& instance = AchievementManager::GetInstance();
|
|
|
|
std::lock_guard lg{instance.GetLock()};
|
|
|
|
if (instance.AreChallengesUpdated())
|
|
|
|
{
|
|
|
|
instance.ResetChallengesUpdated();
|
|
|
|
const auto& challenges = instance.GetActiveChallenges();
|
|
|
|
m_challenge_texture_map.clear();
|
|
|
|
for (const auto& name : challenges)
|
|
|
|
{
|
|
|
|
const auto& icon = instance.GetAchievementBadge(name, false);
|
|
|
|
const u32 width = icon.width;
|
|
|
|
const u32 height = icon.height;
|
|
|
|
TextureConfig tex_config(width, height, 1, 1, 1, AbstractTextureFormat::RGBA8, 0,
|
|
|
|
AbstractTextureType::Texture_2DArray);
|
|
|
|
auto res = m_challenge_texture_map.insert_or_assign(name, g_gfx->CreateTexture(tex_config));
|
|
|
|
res.first->second->Load(0, width, height, width, icon.data.data(),
|
|
|
|
sizeof(u32) * width * height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-24 17:06:59 +00:00
|
|
|
float leaderboard_y = ImGui::GetIO().DisplaySize.y;
|
2024-06-13 04:03:46 +00:00
|
|
|
if (!m_challenge_texture_map.empty())
|
2023-10-20 12:38:20 +00:00
|
|
|
{
|
2024-06-14 04:01:21 +00:00
|
|
|
float scale = ImGui::GetIO().DisplaySize.y / 1024.0;
|
2024-06-14 03:39:46 +00:00
|
|
|
ImGui::SetNextWindowSize(ImVec2(0, 0));
|
2024-02-24 17:06:59 +00:00
|
|
|
ImGui::SetNextWindowPos(ImVec2(ImGui::GetIO().DisplaySize.x, ImGui::GetIO().DisplaySize.y), 0,
|
2024-06-14 03:39:46 +00:00
|
|
|
ImVec2(1, 1));
|
2024-02-24 17:06:59 +00:00
|
|
|
if (ImGui::Begin("Challenges", nullptr,
|
|
|
|
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoInputs |
|
|
|
|
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings |
|
|
|
|
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoNav |
|
|
|
|
ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoFocusOnAppearing))
|
2023-10-20 12:38:20 +00:00
|
|
|
{
|
2024-02-24 17:06:59 +00:00
|
|
|
for (auto& [name, texture] : m_challenge_texture_map)
|
2023-10-20 12:38:20 +00:00
|
|
|
{
|
2024-06-14 04:01:21 +00:00
|
|
|
ImGui::Image(texture.get(), ImVec2(static_cast<float>(texture->GetWidth()) * scale,
|
|
|
|
static_cast<float>(texture->GetHeight()) * scale));
|
2024-06-14 03:39:46 +00:00
|
|
|
ImGui::SameLine();
|
2023-10-20 12:38:20 +00:00
|
|
|
}
|
|
|
|
}
|
2024-06-14 03:39:46 +00:00
|
|
|
leaderboard_y -= ImGui::GetWindowHeight();
|
2024-02-24 17:06:59 +00:00
|
|
|
ImGui::End();
|
2023-10-20 12:38:20 +00:00
|
|
|
}
|
|
|
|
|
2024-06-13 04:03:46 +00:00
|
|
|
const auto& leaderboard_progress = instance.GetActiveLeaderboards();
|
2024-02-24 17:06:59 +00:00
|
|
|
if (!leaderboard_progress.empty())
|
|
|
|
{
|
|
|
|
ImGui::SetNextWindowPos(ImVec2(ImGui::GetIO().DisplaySize.x, leaderboard_y), 0,
|
|
|
|
ImVec2(1.0, 1.0));
|
|
|
|
ImGui::SetNextWindowSize(ImVec2(0.0f, 0.0f));
|
|
|
|
if (ImGui::Begin("Leaderboards", nullptr,
|
|
|
|
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoInputs |
|
|
|
|
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings |
|
|
|
|
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoNav |
|
|
|
|
ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoFocusOnAppearing))
|
|
|
|
{
|
|
|
|
for (const auto& value : leaderboard_progress)
|
2024-06-15 21:12:12 +00:00
|
|
|
ImGui::TextUnformatted(value.c_str());
|
2024-02-24 17:06:59 +00:00
|
|
|
}
|
|
|
|
ImGui::End();
|
|
|
|
}
|
2023-10-20 12:38:20 +00:00
|
|
|
#endif // USE_RETRO_ACHIEVEMENTS
|
2024-06-04 14:20:20 +00:00
|
|
|
}
|
2023-10-20 12:38:20 +00:00
|
|
|
|
2023-01-27 04:03:15 +00:00
|
|
|
void OnScreenUI::Finalize()
|
|
|
|
{
|
|
|
|
auto lock = GetImGuiLock();
|
|
|
|
|
|
|
|
g_perf_metrics.DrawImGuiStats(m_backbuffer_scale);
|
|
|
|
DrawDebugText();
|
|
|
|
OSD::DrawMessages();
|
2024-02-24 17:06:59 +00:00
|
|
|
DrawChallengesAndLeaderboards();
|
2023-01-27 04:03:15 +00:00
|
|
|
ImGui::Render();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_lock<std::mutex> OnScreenUI::GetImGuiLock()
|
|
|
|
{
|
|
|
|
return std::unique_lock<std::mutex>(m_imgui_mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnScreenUI::SetScale(float backbuffer_scale)
|
|
|
|
{
|
|
|
|
ImGui::GetIO().DisplayFramebufferScale.x = backbuffer_scale;
|
|
|
|
ImGui::GetIO().DisplayFramebufferScale.y = backbuffer_scale;
|
|
|
|
ImGui::GetIO().FontGlobalScale = backbuffer_scale;
|
2023-06-10 07:11:14 +00:00
|
|
|
// ScaleAllSizes scales in-place, so calling it twice will double-apply the scale
|
|
|
|
// Reset the style first so that the scale is applied to the base style, not an already-scaled one
|
|
|
|
ImGui::GetStyle() = {};
|
|
|
|
ImGui::GetStyle().WindowRounding = 7.0f;
|
2023-01-27 04:03:15 +00:00
|
|
|
ImGui::GetStyle().ScaleAllSizes(backbuffer_scale);
|
|
|
|
|
|
|
|
m_backbuffer_scale = backbuffer_scale;
|
|
|
|
}
|
2023-02-03 06:11:31 +00:00
|
|
|
void OnScreenUI::SetKeyMap(const DolphinKeyMap& key_map)
|
2023-01-27 04:03:15 +00:00
|
|
|
{
|
2023-02-03 06:11:31 +00:00
|
|
|
static constexpr DolphinKeyMap dolphin_to_imgui_map = {
|
|
|
|
ImGuiKey_Tab, ImGuiKey_LeftArrow, ImGuiKey_RightArrow, ImGuiKey_UpArrow,
|
|
|
|
ImGuiKey_DownArrow, ImGuiKey_PageUp, ImGuiKey_PageDown, ImGuiKey_Home,
|
|
|
|
ImGuiKey_End, ImGuiKey_Insert, ImGuiKey_Delete, ImGuiKey_Backspace,
|
2023-07-23 18:43:50 +00:00
|
|
|
ImGuiKey_Space, ImGuiKey_Enter, ImGuiKey_Escape, ImGuiKey_KeypadEnter,
|
2023-02-03 06:11:31 +00:00
|
|
|
ImGuiKey_A, ImGuiKey_C, ImGuiKey_V, ImGuiKey_X,
|
|
|
|
ImGuiKey_Y, ImGuiKey_Z,
|
|
|
|
};
|
|
|
|
|
2023-01-27 04:03:15 +00:00
|
|
|
auto lock = GetImGuiLock();
|
|
|
|
|
|
|
|
if (!ImGui::GetCurrentContext())
|
|
|
|
return;
|
|
|
|
|
2023-07-23 18:43:50 +00:00
|
|
|
m_dolphin_to_imgui_map.clear();
|
2023-02-03 06:11:31 +00:00
|
|
|
for (int dolphin_key = 0; dolphin_key <= static_cast<int>(DolphinKey::Z); dolphin_key++)
|
|
|
|
{
|
2023-07-23 18:43:50 +00:00
|
|
|
const int imgui_key = dolphin_to_imgui_map[DolphinKey(dolphin_key)];
|
2023-02-03 06:11:31 +00:00
|
|
|
if (imgui_key >= 0)
|
2023-07-23 18:43:50 +00:00
|
|
|
{
|
|
|
|
const int mapped_key = key_map[DolphinKey(dolphin_key)];
|
|
|
|
m_dolphin_to_imgui_map[mapped_key & 0x1FF] = imgui_key;
|
|
|
|
}
|
2023-02-03 06:11:31 +00:00
|
|
|
}
|
2023-01-27 04:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OnScreenUI::SetKey(u32 key, bool is_down, const char* chars)
|
|
|
|
{
|
|
|
|
auto lock = GetImGuiLock();
|
2023-07-23 18:43:50 +00:00
|
|
|
if (auto iter = m_dolphin_to_imgui_map.find(key); iter != m_dolphin_to_imgui_map.end())
|
|
|
|
ImGui::GetIO().AddKeyEvent((ImGuiKey)iter->second, is_down);
|
2023-01-27 04:03:15 +00:00
|
|
|
|
|
|
|
if (chars)
|
|
|
|
ImGui::GetIO().AddInputCharactersUTF8(chars);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnScreenUI::SetMousePos(float x, float y)
|
|
|
|
{
|
|
|
|
auto lock = GetImGuiLock();
|
|
|
|
|
2024-06-01 03:31:54 +00:00
|
|
|
ImGui::GetIO().AddMousePosEvent(x, y);
|
2023-01-27 04:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OnScreenUI::SetMousePress(u32 button_mask)
|
|
|
|
{
|
|
|
|
auto lock = GetImGuiLock();
|
|
|
|
|
|
|
|
for (size_t i = 0; i < std::size(ImGui::GetIO().MouseDown); i++)
|
2024-05-18 16:49:19 +00:00
|
|
|
{
|
|
|
|
ImGui::GetIO().AddMouseButtonEvent(static_cast<int>(i), (button_mask & (1u << i)) != 0);
|
|
|
|
}
|
2023-01-27 04:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace VideoCommon
|