Skip to content

Commit

Permalink
Renderer: Use imgui for drawing debug text and OSD
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Jan 25, 2019
1 parent d1868d9 commit 600d1fc
Show file tree
Hide file tree
Showing 13 changed files with 270 additions and 326 deletions.
4 changes: 1 addition & 3 deletions Source/Android/jni/MainAndroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,9 +595,6 @@ static void Run(const std::vector<std::string>& paths, bool first_open,
ASSERT(!paths.empty());
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Running : %s", paths[0].c_str());

// Install our callbacks
OSD::AddCallback(OSD::CallbackType::Shutdown, ButtonManager::Shutdown);

RegisterMsgAlertHandler(&MsgAlert);
Common::AndroidSetReportHandler(&ReportSend);
DolphinAnalytics::AndroidSetGetValFunc(&GetAnalyticValue);
Expand Down Expand Up @@ -639,6 +636,7 @@ static void Run(const std::vector<std::string>& paths, bool first_open,
}

Core::Shutdown();
ButtonManager::Shutdown();
UICommon::Shutdown();
guard.unlock();

Expand Down
90 changes: 69 additions & 21 deletions Source/Core/DolphinQt/HotkeyScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "DolphinQt/HotkeyScheduler.h"

#include <algorithm>
#include <cmath>
#include <thread>

#include <QCoreApplication>
Expand All @@ -26,6 +27,7 @@

#include "InputCommon/ControllerInterface/ControllerInterface.h"

#include "VideoCommon/OnScreenDisplay.h"
#include "VideoCommon/RenderBase.h"
#include "VideoCommon/VertexShaderManager.h"
#include "VideoCommon/VideoConfig.h"
Expand Down Expand Up @@ -286,78 +288,118 @@ void HotkeyScheduler::Run()
else if (IsHotkey(HK_NEXT_GAME_WIIMOTE_PROFILE_4))
m_profile_cycler.NextWiimoteProfileForGame(3);

const auto show_msg = [](OSDMessage message) {
if (g_renderer)
g_renderer->ShowOSDMessage(message);
auto ShowVolume = []() {
OSD::AddMessage(std::string("Volume: ") +
(SConfig::GetInstance().m_IsMuted ?
"Muted" :
std::to_string(SConfig::GetInstance().m_Volume)) +
"%");
};

// Volume
if (IsHotkey(HK_VOLUME_DOWN))
{
show_msg(OSDMessage::VolumeChanged);
settings.DecreaseVolume(3);
ShowVolume();
}

if (IsHotkey(HK_VOLUME_UP))
{
show_msg(OSDMessage::VolumeChanged);
settings.IncreaseVolume(3);
ShowVolume();
}

if (IsHotkey(HK_VOLUME_TOGGLE_MUTE))
{
show_msg(OSDMessage::VolumeChanged);
AudioCommon::ToggleMuteVolume();
ShowVolume();
}

// Graphics
const auto efb_scale = Config::Get(Config::GFX_EFB_SCALE);
auto ShowEFBScale = []() {
switch (Config::Get(Config::GFX_EFB_SCALE))
{
case EFB_SCALE_AUTO_INTEGRAL:
OSD::AddMessage("Internal Resolution: Auto (integral)");
break;
case 1:
OSD::AddMessage("Internal Resolution: Native");
break;
default:
OSD::AddMessage("Internal Resolution: %dx", g_Config.iEFBScale);
break;
}
};

if (IsHotkey(HK_INCREASE_IR))
{
show_msg(OSDMessage::IRChanged);
Config::SetCurrent(Config::GFX_EFB_SCALE, efb_scale + 1);
ShowEFBScale();
}
if (IsHotkey(HK_DECREASE_IR))
{
show_msg(OSDMessage::IRChanged);
if (efb_scale > EFB_SCALE_AUTO_INTEGRAL)
{
Config::SetCurrent(Config::GFX_EFB_SCALE, efb_scale - 1);
ShowEFBScale();
}
}

if (IsHotkey(HK_TOGGLE_CROP))
Config::SetCurrent(Config::GFX_CROP, !Config::Get(Config::GFX_CROP));

if (IsHotkey(HK_TOGGLE_AR))
{
show_msg(OSDMessage::ARToggled);
const int aspect_ratio = (static_cast<int>(Config::Get(Config::GFX_ASPECT_RATIO)) + 1) & 3;
Config::SetCurrent(Config::GFX_ASPECT_RATIO, static_cast<AspectMode>(aspect_ratio));
switch (static_cast<AspectMode>(aspect_ratio))
{
case AspectMode::Stretch:
OSD::AddMessage("Stretch");
break;
case AspectMode::Analog:
OSD::AddMessage("Force 4:3");
break;
case AspectMode::AnalogWide:
OSD::AddMessage("Force 16:9");
break;
case AspectMode::Auto:
default:
OSD::AddMessage("Auto");
break;
}
}
if (IsHotkey(HK_TOGGLE_EFBCOPIES))
{
show_msg(OSDMessage::EFBCopyToggled);
Config::SetCurrent(Config::GFX_HACK_SKIP_EFB_COPY_TO_RAM,
!Config::Get(Config::GFX_HACK_SKIP_EFB_COPY_TO_RAM));
const bool new_value = !Config::Get(Config::GFX_HACK_SKIP_EFB_COPY_TO_RAM);
Config::SetCurrent(Config::GFX_HACK_SKIP_EFB_COPY_TO_RAM, new_value);
OSD::AddMessage(StringFromFormat("Copy EFB: %s", new_value ? "to Texture" : "to RAM"));
}

auto ShowXFBCopies = []() {
OSD::AddMessage(StringFromFormat(
"Copy XFB: %s%s", Config::Get(Config::GFX_HACK_IMMEDIATE_XFB) ? " (Immediate)" : "",
Config::Get(Config::GFX_HACK_SKIP_XFB_COPY_TO_RAM) ? "to Texture" : "to RAM"));
};

if (IsHotkey(HK_TOGGLE_XFBCOPIES))
{
show_msg(OSDMessage::XFBChanged);
Config::SetCurrent(Config::GFX_HACK_SKIP_XFB_COPY_TO_RAM,
!Config::Get(Config::GFX_HACK_SKIP_XFB_COPY_TO_RAM));
ShowXFBCopies();
}
if (IsHotkey(HK_TOGGLE_IMMEDIATE_XFB))
{
show_msg(OSDMessage::XFBChanged);

Config::SetCurrent(Config::GFX_HACK_IMMEDIATE_XFB,
!Config::Get(Config::GFX_HACK_IMMEDIATE_XFB));
ShowXFBCopies();
}
if (IsHotkey(HK_TOGGLE_FOG))
{
show_msg(OSDMessage::FogToggled);
Config::SetCurrent(Config::GFX_DISABLE_FOG, !Config::Get(Config::GFX_DISABLE_FOG));
const bool new_value = !Config::Get(Config::GFX_DISABLE_FOG);
Config::SetCurrent(Config::GFX_DISABLE_FOG, new_value);
OSD::AddMessage(StringFromFormat("Fog: %s", new_value ? "Enabled" : "Disabled"));
}

if (IsHotkey(HK_TOGGLE_DUMPTEXTURES))
Expand All @@ -368,22 +410,28 @@ void HotkeyScheduler::Run()

Core::SetIsThrottlerTempDisabled(IsHotkey(HK_TOGGLE_THROTTLE, true));

auto ShowEmulationSpeed = []() {
OSD::AddMessage(
SConfig::GetInstance().m_EmulationSpeed <= 0 ?
"Speed Limit: Unlimited" :
StringFromFormat("Speed Limit: %li%%",
std::lround(SConfig::GetInstance().m_EmulationSpeed * 100.f)));
};

if (IsHotkey(HK_DECREASE_EMULATION_SPEED))
{
show_msg(OSDMessage::SpeedChanged);

auto speed = SConfig::GetInstance().m_EmulationSpeed - 0.1;
speed = (speed <= 0 || (speed >= 0.95 && speed <= 1.05)) ? 1.0 : speed;
SConfig::GetInstance().m_EmulationSpeed = speed;
ShowEmulationSpeed();
}

if (IsHotkey(HK_INCREASE_EMULATION_SPEED))
{
show_msg(OSDMessage::SpeedChanged);

auto speed = SConfig::GetInstance().m_EmulationSpeed + 0.1;
speed = (speed >= 0.95 && speed <= 1.05) ? 1.0 : speed;
SConfig::GetInstance().m_EmulationSpeed = speed;
ShowEmulationSpeed();
}

// Slot Saving / Loading
Expand Down
4 changes: 0 additions & 4 deletions Source/Core/VideoBackends/D3D/Render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,10 +595,6 @@ void Renderer::SwapImpl(AbstractTexture* texture, const EFBRectangle& xfb_region
D3D11_VIEWPORT vp = CD3D11_VIEWPORT(0.0f, 0.0f, static_cast<float>(m_backbuffer_width),
static_cast<float>(m_backbuffer_height));
D3D::context->RSSetViewports(1, &vp);

Renderer::DrawDebugText();

OSD::DrawMessages();
DrawImGui();

g_texture_cache->Cleanup(frameCount);
Expand Down
7 changes: 0 additions & 7 deletions Source/Core/VideoBackends/OGL/Render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1424,9 +1424,6 @@ void Renderer::SwapImpl(AbstractTexture* texture, const EFBRectangle& xfb_region

ResetAPIState();

// Do our OSD callbacks
OSD::DoCallbacks(OSD::CallbackType::OnFrame);

// Check if we need to render to a new surface.
CheckForSurfaceChange();
CheckForSurfaceResize();
Expand All @@ -1451,10 +1448,6 @@ void Renderer::SwapImpl(AbstractTexture* texture, const EFBRectangle& xfb_region

// Render OSD messages.
glViewport(0, 0, m_backbuffer_width, m_backbuffer_height);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
DrawDebugText();
OSD::DrawMessages();
DrawImGui();

// Swap the back and front buffers, presenting the image.
Expand Down
5 changes: 0 additions & 5 deletions Source/Core/VideoBackends/Software/SWRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,8 @@ std::unique_ptr<AbstractPipeline> SWRenderer::CreatePipeline(const AbstractPipel
// Called on the GPU thread
void SWRenderer::SwapImpl(AbstractTexture* texture, const EFBRectangle& xfb_region, u64 ticks)
{
OSD::DoCallbacks(OSD::CallbackType::OnFrame);

if (!IsHeadless())
{
DrawDebugText();
m_window->ShowImage(texture, xfb_region);
}

UpdateActiveConfig();
}
Expand Down
3 changes: 0 additions & 3 deletions Source/Core/VideoBackends/Vulkan/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,9 +704,6 @@ void Renderer::DrawScreen(VKTexture* xfb_texture, const EFBRectangle& xfb_region
// Draw OSD
SetViewport(0.0f, 0.0f, static_cast<float>(backbuffer->GetWidth()),
static_cast<float>(backbuffer->GetHeight()), 0.0f, 1.0f);
DrawDebugText();
OSD::DoCallbacks(OSD::CallbackType::OnFrame);
OSD::DrawMessages();
StateTracker::GetInstance()->SetPendingRebind();
DrawImGui();

Expand Down
Loading

0 comments on commit 600d1fc

Please sign in to comment.