Skip to content
Permalink
Browse files

Merge pull request #7478 from stenzek/imgui

Replace raster font with dear imgui
  • Loading branch information...
spycrab committed Jan 25, 2019
2 parents e060b13 + 774480b commit 6962d5bc5217562b0200a47968e013e9c820feeb
Showing with 1,148 additions and 2,067 deletions.
  1. +10 −1 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java
  2. +2 −2 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/Java_GCAdapter.java
  3. +1 −1 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/Java_WiimoteAdapter.java
  4. +51 −6 Source/Android/jni/MainAndroid.cpp
  5. +3 −0 Source/Core/Common/WindowSystemInfo.h
  6. +1 −0 Source/Core/DolphinQt/CMakeLists.txt
  7. +3 −0 Source/Core/DolphinQt/DolphinQt.vcxproj
  8. +69 −21 Source/Core/DolphinQt/HotkeyScheduler.cpp
  9. +1 −0 Source/Core/DolphinQt/MainWindow.cpp
  10. +87 −0 Source/Core/DolphinQt/RenderWidget.cpp
  11. +2 −0 Source/Core/DolphinQt/RenderWidget.h
  12. +0 −390 Source/Core/VideoBackends/D3D/D3DUtil.cpp
  13. +0 −2 Source/Core/VideoBackends/D3D/D3DUtil.h
  14. +4 −0 Source/Core/VideoBackends/D3D/FramebufferManager.cpp
  15. +51 −93 Source/Core/VideoBackends/D3D/Render.cpp
  16. +5 −9 Source/Core/VideoBackends/D3D/Render.h
  17. +5 −3 Source/Core/VideoBackends/D3D/main.cpp
  18. +1 −11 Source/Core/VideoBackends/Null/Render.cpp
  19. +0 −3 Source/Core/VideoBackends/Null/Render.h
  20. +0 −1 Source/Core/VideoBackends/OGL/CMakeLists.txt
  21. +0 −2 Source/Core/VideoBackends/OGL/OGL.vcxproj
  22. +0 −9 Source/Core/VideoBackends/OGL/OGL.vcxproj.filters
  23. +0 −5 Source/Core/VideoBackends/OGL/PostProcessing.cpp
  24. +0 −291 Source/Core/VideoBackends/OGL/RasterFont.cpp
  25. +0 −30 Source/Core/VideoBackends/OGL/RasterFont.h
  26. +65 −157 Source/Core/VideoBackends/OGL/Render.cpp
  27. +8 −13 Source/Core/VideoBackends/OGL/Render.h
  28. +1 −1 Source/Core/VideoBackends/OGL/main.cpp
  29. +2 −13 Source/Core/VideoBackends/Software/SWOGLWindow.cpp
  30. +1 −12 Source/Core/VideoBackends/Software/SWOGLWindow.h
  31. +2 −14 Source/Core/VideoBackends/Software/SWRenderer.cpp
  32. +1 −2 Source/Core/VideoBackends/Software/SWRenderer.h
  33. +0 −1 Source/Core/VideoBackends/Vulkan/CMakeLists.txt
  34. +9 −0 Source/Core/VideoBackends/Vulkan/ObjectCache.cpp
  35. +2 −0 Source/Core/VideoBackends/Vulkan/ObjectCache.h
  36. +1 −8 Source/Core/VideoBackends/Vulkan/PostProcessing.cpp
  37. +1 −2 Source/Core/VideoBackends/Vulkan/PostProcessing.h
  38. +0 −421 Source/Core/VideoBackends/Vulkan/RasterFont.cpp
  39. +0 −41 Source/Core/VideoBackends/Vulkan/RasterFont.h
  40. +48 −143 Source/Core/VideoBackends/Vulkan/Renderer.cpp
  41. +5 −16 Source/Core/VideoBackends/Vulkan/Renderer.h
  42. +3 −1 Source/Core/VideoBackends/Vulkan/StateTracker.cpp
  43. +3 −2 Source/Core/VideoBackends/Vulkan/StateTracker.h
  44. +0 −14 Source/Core/VideoBackends/Vulkan/TextureCache.cpp
  45. +0 −3 Source/Core/VideoBackends/Vulkan/TextureCache.h
  46. +1 −1 Source/Core/VideoBackends/Vulkan/VKTexture.cpp
  47. +0 −2 Source/Core/VideoBackends/Vulkan/Vulkan.vcxproj
  48. +13 −1 Source/Core/VideoBackends/Vulkan/main.cpp
  49. +1 −1 Source/Core/VideoCommon/AsyncShaderCompiler.cpp
  50. +1 −0 Source/Core/VideoCommon/CMakeLists.txt
  51. +65 −35 Source/Core/VideoCommon/OnScreenDisplay.cpp
  52. +0 −22 Source/Core/VideoCommon/OnScreenDisplay.h
  53. +409 −148 Source/Core/VideoCommon/RenderBase.cpp
  54. +64 −22 Source/Core/VideoCommon/RenderBase.h
  55. +28 −0 Source/Core/VideoCommon/RenderState.cpp
  56. +4 −0 Source/Core/VideoCommon/RenderState.h
  57. +22 −4 Source/Core/VideoCommon/ShaderCache.cpp
  58. +86 −77 Source/Core/VideoCommon/Statistics.cpp
  59. +2 −3 Source/Core/VideoCommon/Statistics.h
  60. +0 −6 Source/Core/VideoCommon/VideoBackendBase.cpp
  61. +4 −1 Source/Core/VideoCommon/VideoCommon.vcxproj
@@ -21,7 +21,16 @@
*/
public final class NativeLibrary
{
public static WeakReference<EmulationActivity> sEmulationActivity = new WeakReference<>(null);
private static WeakReference<EmulationActivity> sEmulationActivity = new WeakReference<>(null);

/**
* Returns the current instance of EmulationActivity.
* There should only ever be one EmulationActivity instantiated.
*/
public static EmulationActivity getEmulationActivity()
{
return sEmulationActivity.get();
}

/**
* Button type for use in onTouchEvent
@@ -31,7 +31,7 @@

private static void RequestPermission()
{
Context context = NativeLibrary.sEmulationActivity.get();
Context context = NativeLibrary.getEmulationActivity();
if (context != null)
{
HashMap<String, UsbDevice> devices = manager.getDeviceList();
@@ -141,7 +141,7 @@ public static boolean OpenAdapter()
}
}

final Activity emulationActivity = NativeLibrary.sEmulationActivity.get();
final Activity emulationActivity = NativeLibrary.getEmulationActivity();
if (emulationActivity != null)
{
emulationActivity.runOnUiThread(() -> Toast.makeText(emulationActivity,
@@ -34,7 +34,7 @@

private static void RequestPermission()
{
Context context = NativeLibrary.sEmulationActivity.get();
Context context = NativeLibrary.getEmulationActivity();
if (context != null)
{
HashMap<String, UsbDevice> devices = manager.getDeviceList();
@@ -52,6 +52,7 @@
#include "VideoCommon/RenderBase.h"
#include "VideoCommon/VideoBackendBase.h"

#include "../../Core/Common/WindowSystemInfo.h"
#include "jni/AndroidCommon/AndroidCommon.h"
#include "jni/AndroidCommon/IDCache.h"
#include "jni/ButtonManager.h"
@@ -589,15 +590,57 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ReloadWiimot
Wiimote::LoadConfig();
}

static void Run(const std::vector<std::string>& paths, bool first_open,
// Returns the scale factor for imgui rendering.
// Based on the scaledDensity of the device's display metrics.
static float GetRenderSurfaceScale(JNIEnv* env)
{
// NativeLibrary emulation_activity = NativeLibrary.getEmulationActivity();
jclass native_library_class = env->FindClass("org/dolphinemu/dolphinemu/NativeLibrary");
jmethodID get_emulation_activity_method =
env->GetStaticMethodID(native_library_class, "getEmulationActivity",
"()Lorg/dolphinemu/dolphinemu/activities/EmulationActivity;");
jobject emulation_activity =
env->CallStaticObjectMethod(native_library_class, get_emulation_activity_method);

// WindowManager window_manager = emulation_activity.getWindowManager();
jmethodID get_window_manager_method =
env->GetMethodID(env->GetObjectClass(emulation_activity), "getWindowManager",
"()Landroid/view/WindowManager;");
jobject window_manager = env->CallObjectMethod(emulation_activity, get_window_manager_method);

// Display display = window_manager.getDisplay();
jmethodID get_display_method = env->GetMethodID(env->GetObjectClass(window_manager),
"getDefaultDisplay", "()Landroid/view/Display;");
jobject display = env->CallObjectMethod(window_manager, get_display_method);

// DisplayMetrics metrics = new DisplayMetrics();
jclass display_metrics_class = env->FindClass("android/util/DisplayMetrics");
jmethodID display_metrics_constructor = env->GetMethodID(display_metrics_class, "<init>", "()V");
jobject metrics = env->NewObject(display_metrics_class, display_metrics_constructor);

// display.getMetrics(metrics);
jmethodID get_metrics_method = env->GetMethodID(env->GetObjectClass(display), "getMetrics",
"(Landroid/util/DisplayMetrics;)V");
env->CallVoidMethod(display, get_metrics_method, metrics);

// float scaled_density = metrics.scaledDensity;
jfieldID scaled_density_field =
env->GetFieldID(env->GetObjectClass(metrics), "scaledDensity", "F");
float scaled_density = env->GetFloatField(metrics, scaled_density_field);
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Using %f for render surface scale.",
scaled_density);

// cleanup
env->DeleteLocalRef(metrics);
return scaled_density;
}

static void Run(JNIEnv* env, const std::vector<std::string>& paths, bool first_open,
std::optional<std::string> savestate_path = {}, bool delete_savestate = false)
{
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);
@@ -617,6 +660,7 @@ static void Run(const std::vector<std::string>& paths, bool first_open,
std::unique_ptr<BootParameters> boot = BootParameters::GenerateFromFile(paths, savestate_path);
boot->delete_savestate = delete_savestate;
WindowSystemInfo wsi(WindowSystemType::Android, nullptr, s_surf);
wsi.render_surface_scale = GetRenderSurfaceScale(env);
if (BootManager::BootCore(std::move(boot), wsi))
{
ButtonManager::Init(SConfig::GetInstance().GetGameID());
@@ -639,6 +683,7 @@ static void Run(const std::vector<std::string>& paths, bool first_open,
}

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

@@ -652,14 +697,14 @@ static void Run(const std::vector<std::string>& paths, bool first_open,
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run___3Ljava_lang_String_2Z(
JNIEnv* env, jobject obj, jobjectArray jPaths, jboolean jfirstOpen)
{
Run(JStringArrayToVector(env, jPaths), jfirstOpen);
Run(env, JStringArrayToVector(env, jPaths), jfirstOpen);
}

JNIEXPORT void JNICALL
Java_org_dolphinemu_dolphinemu_NativeLibrary_Run___3Ljava_lang_String_2Ljava_lang_String_2Z(
JNIEnv* env, jobject obj, jobjectArray jPaths, jstring jSavestate, jboolean jDeleteSavestate)
{
Run(JStringArrayToVector(env, jPaths), false, GetJString(env, jSavestate), jDeleteSavestate);
Run(env, JStringArrayToVector(env, jPaths), false, GetJString(env, jSavestate), jDeleteSavestate);
}

JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ChangeDisc(JNIEnv* env,
@@ -32,4 +32,7 @@ struct WindowSystemInfo
// on the platform. e.g. HWND for Windows, Window for X11. If the surface is
// set to nullptr, the video backend will run in headless mode.
void* render_surface = nullptr;

// Scale of the render surface. For hidpi systems, this will be >1.
float render_surface_scale = 1.0f;
};
@@ -143,6 +143,7 @@ PRIVATE
core
Qt5::Widgets
uicommon
imgui
)

if(WIN32)
@@ -463,6 +463,9 @@
<ProjectReference Include="$(CoreDir)VideoBackends\Vulkan\Vulkan.vcxproj">
<Project>{29f29a19-f141-45ad-9679-5a2923b49da3}</Project>
</ProjectReference>
<ProjectReference Include="..\..\..\Externals\imgui\imgui.vcxproj">
<Project>{4c3b2264-ea73-4a7b-9cfe-65b0fd635ebb}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
@@ -5,6 +5,7 @@
#include "DolphinQt/HotkeyScheduler.h"

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

#include <QCoreApplication>
@@ -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"
@@ -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))
@@ -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
@@ -164,6 +164,7 @@ static WindowSystemInfo GetWindowSystemInfo(QWindow* window)
else
wsi.render_surface = window ? reinterpret_cast<void*>(window->winId()) : nullptr;
#endif
wsi.render_surface_scale = window ? static_cast<float>(window->devicePixelRatio()) : 1.0f;

return wsi;
}

0 comments on commit 6962d5b

Please sign in to comment.
You can’t perform that action at this time.