configure_graphics.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // Copyright 2016 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <QColorDialog>
  5. #include <QComboBox>
  6. #ifdef HAS_VULKAN
  7. #include <QVulkanInstance>
  8. #endif
  9. #include "common/common_types.h"
  10. #include "common/logging/log.h"
  11. #include "core/core.h"
  12. #include "core/settings.h"
  13. #include "ui_configure_graphics.h"
  14. #include "yuzu/configuration/configure_graphics.h"
  15. #ifdef HAS_VULKAN
  16. #include "video_core/renderer_vulkan/renderer_vulkan.h"
  17. #endif
  18. ConfigureGraphics::ConfigureGraphics(QWidget* parent)
  19. : QWidget(parent), ui(new Ui::ConfigureGraphics) {
  20. vulkan_device = Settings::values.vulkan_device;
  21. RetrieveVulkanDevices();
  22. ui->setupUi(this);
  23. SetConfiguration();
  24. connect(ui->api, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
  25. [this] { UpdateDeviceComboBox(); });
  26. connect(ui->device, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this,
  27. [this](int device) { UpdateDeviceSelection(device); });
  28. connect(ui->bg_button, &QPushButton::clicked, this, [this] {
  29. const QColor new_bg_color = QColorDialog::getColor(bg_color);
  30. if (!new_bg_color.isValid()) {
  31. return;
  32. }
  33. UpdateBackgroundColorButton(new_bg_color);
  34. });
  35. }
  36. void ConfigureGraphics::UpdateDeviceSelection(int device) {
  37. if (device == -1) {
  38. return;
  39. }
  40. if (GetCurrentGraphicsBackend() == Settings::RendererBackend::Vulkan) {
  41. vulkan_device = device;
  42. }
  43. }
  44. ConfigureGraphics::~ConfigureGraphics() = default;
  45. void ConfigureGraphics::SetConfiguration() {
  46. const bool runtime_lock = !Core::System::GetInstance().IsPoweredOn();
  47. ui->api->setEnabled(runtime_lock);
  48. ui->api->setCurrentIndex(static_cast<int>(Settings::values.renderer_backend));
  49. ui->aspect_ratio_combobox->setCurrentIndex(Settings::values.aspect_ratio);
  50. ui->use_disk_shader_cache->setEnabled(runtime_lock);
  51. ui->use_disk_shader_cache->setChecked(Settings::values.use_disk_shader_cache);
  52. ui->use_asynchronous_gpu_emulation->setEnabled(runtime_lock);
  53. ui->use_asynchronous_gpu_emulation->setChecked(Settings::values.use_asynchronous_gpu_emulation);
  54. UpdateBackgroundColorButton(QColor::fromRgbF(Settings::values.bg_red, Settings::values.bg_green,
  55. Settings::values.bg_blue));
  56. UpdateDeviceComboBox();
  57. }
  58. void ConfigureGraphics::ApplyConfiguration() {
  59. Settings::values.renderer_backend = GetCurrentGraphicsBackend();
  60. Settings::values.vulkan_device = vulkan_device;
  61. Settings::values.aspect_ratio = ui->aspect_ratio_combobox->currentIndex();
  62. Settings::values.use_disk_shader_cache = ui->use_disk_shader_cache->isChecked();
  63. Settings::values.use_asynchronous_gpu_emulation =
  64. ui->use_asynchronous_gpu_emulation->isChecked();
  65. Settings::values.bg_red = static_cast<float>(bg_color.redF());
  66. Settings::values.bg_green = static_cast<float>(bg_color.greenF());
  67. Settings::values.bg_blue = static_cast<float>(bg_color.blueF());
  68. }
  69. void ConfigureGraphics::changeEvent(QEvent* event) {
  70. if (event->type() == QEvent::LanguageChange) {
  71. RetranslateUI();
  72. }
  73. QWidget::changeEvent(event);
  74. }
  75. void ConfigureGraphics::RetranslateUI() {
  76. ui->retranslateUi(this);
  77. }
  78. void ConfigureGraphics::UpdateBackgroundColorButton(QColor color) {
  79. bg_color = color;
  80. QPixmap pixmap(ui->bg_button->size());
  81. pixmap.fill(bg_color);
  82. const QIcon color_icon(pixmap);
  83. ui->bg_button->setIcon(color_icon);
  84. }
  85. void ConfigureGraphics::UpdateDeviceComboBox() {
  86. ui->device->clear();
  87. bool enabled = false;
  88. switch (GetCurrentGraphicsBackend()) {
  89. case Settings::RendererBackend::OpenGL:
  90. ui->device->addItem(tr("OpenGL Graphics Device"));
  91. enabled = false;
  92. break;
  93. case Settings::RendererBackend::Vulkan:
  94. for (const auto device : vulkan_devices) {
  95. ui->device->addItem(device);
  96. }
  97. ui->device->setCurrentIndex(vulkan_device);
  98. enabled = !vulkan_devices.empty();
  99. break;
  100. }
  101. ui->device->setEnabled(enabled && !Core::System::GetInstance().IsPoweredOn());
  102. }
  103. void ConfigureGraphics::RetrieveVulkanDevices() {
  104. #ifdef HAS_VULKAN
  105. vulkan_devices.clear();
  106. for (auto& name : Vulkan::RendererVulkan::EnumerateDevices()) {
  107. vulkan_devices.push_back(QString::fromStdString(name));
  108. }
  109. #endif
  110. }
  111. Settings::RendererBackend ConfigureGraphics::GetCurrentGraphicsBackend() const {
  112. return static_cast<Settings::RendererBackend>(ui->api->currentIndex());
  113. }