mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-01-18 02:52:10 +01:00
[hud] Added configurable HUD
HUD elements can be enabled individually using a comma-separated list. Supported options include: - fps: Displays the framerate - devinfo: Displays device info Passing "1" has the same effect as "fps,devinfo".
This commit is contained in:
parent
8aa8610221
commit
3ed03f7a3d
@ -4,8 +4,11 @@
|
||||
|
||||
namespace dxvk::hud {
|
||||
|
||||
Hud::Hud(const Rc<DxvkDevice>& device)
|
||||
: m_device (device),
|
||||
Hud::Hud(
|
||||
const Rc<DxvkDevice>& device,
|
||||
const HudConfig& config)
|
||||
: m_config (config),
|
||||
m_device (device),
|
||||
m_context (m_device->createContext()),
|
||||
m_textRenderer (m_device, m_context),
|
||||
m_uniformBuffer (createUniformBuffer()),
|
||||
@ -37,13 +40,13 @@ namespace dxvk::hud {
|
||||
|
||||
|
||||
Rc<Hud> Hud::createHud(const Rc<DxvkDevice>& device) {
|
||||
const std::string hudConfig = env::getEnvVar(L"DXVK_HUD");
|
||||
HudConfig config(env::getEnvVar(L"DXVK_HUD"));
|
||||
|
||||
if (hudConfig.size() == 0 || hudConfig == "0")
|
||||
if (config.elements.isClear())
|
||||
return nullptr;
|
||||
|
||||
// TODO implement configuration options for the HUD
|
||||
return new Hud(device);
|
||||
return new Hud(device, config);
|
||||
}
|
||||
|
||||
|
||||
@ -65,10 +68,16 @@ namespace dxvk::hud {
|
||||
m_textRenderer.beginFrame(m_context);
|
||||
|
||||
HudPos position = { 8.0f, 24.0f };
|
||||
position = m_hudDeviceInfo.renderText(
|
||||
m_context, m_textRenderer, position);
|
||||
position = m_hudFps.renderText(
|
||||
m_context, m_textRenderer, position);
|
||||
|
||||
if (m_config.elements.test(HudElement::DeviceInfo)) {
|
||||
position = m_hudDeviceInfo.renderText(
|
||||
m_context, m_textRenderer, position);
|
||||
}
|
||||
|
||||
if (m_config.elements.test(HudElement::Framerate)) {
|
||||
position = m_hudFps.renderText(
|
||||
m_context, m_textRenderer, position);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -4,12 +4,17 @@
|
||||
|
||||
#include "../util/util_env.h"
|
||||
|
||||
#include "dxvk_hud_config.h"
|
||||
#include "dxvk_hud_devinfo.h"
|
||||
#include "dxvk_hud_fps.h"
|
||||
#include "dxvk_hud_text.h"
|
||||
|
||||
namespace dxvk::hud {
|
||||
|
||||
/**
|
||||
* \brief HUD uniform data
|
||||
* Shader data for the HUD.
|
||||
*/
|
||||
struct HudUniformData {
|
||||
VkExtent2D surfaceSize;
|
||||
};
|
||||
@ -24,8 +29,9 @@ namespace dxvk::hud {
|
||||
|
||||
public:
|
||||
|
||||
explicit Hud(
|
||||
const Rc<DxvkDevice>& device);
|
||||
Hud(
|
||||
const Rc<DxvkDevice>& device,
|
||||
const HudConfig& config);
|
||||
|
||||
~Hud();
|
||||
|
||||
@ -62,6 +68,8 @@ namespace dxvk::hud {
|
||||
|
||||
private:
|
||||
|
||||
const HudConfig m_config;
|
||||
|
||||
const Rc<DxvkDevice> m_device;
|
||||
const Rc<DxvkContext> m_context;
|
||||
|
||||
|
45
src/dxvk/hud/dxvk_hud_config.cpp
Normal file
45
src/dxvk/hud/dxvk_hud_config.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
#include "dxvk_hud_config.h"
|
||||
|
||||
namespace dxvk {
|
||||
|
||||
const std::unordered_map<std::string, HudElement> g_hudElements = {{
|
||||
{ "devinfo", HudElement::DeviceInfo },
|
||||
{ "fps", HudElement::Framerate },
|
||||
}};
|
||||
|
||||
|
||||
HudConfig::HudConfig() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
HudConfig::HudConfig(const std::string& configStr) {
|
||||
if (configStr == "1") {
|
||||
this->elements.set(
|
||||
HudElement::DeviceInfo,
|
||||
HudElement::Framerate);
|
||||
} else {
|
||||
std::string::size_type pos = 0;
|
||||
std::string::size_type end = 0;
|
||||
|
||||
while (pos < configStr.size()) {
|
||||
end = configStr.find(',', pos);
|
||||
|
||||
if (end == std::string::npos)
|
||||
end = configStr.size();
|
||||
|
||||
std::string configPart = configStr.substr(pos, end - pos);
|
||||
|
||||
auto element = g_hudElements.find(configPart);
|
||||
|
||||
if (element != g_hudElements.cend()) {
|
||||
this->elements.set(element->second);
|
||||
Logger::debug(str::format("Hud: Enabled ", configPart));
|
||||
}
|
||||
|
||||
pos = end + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
40
src/dxvk/hud/dxvk_hud_config.h
Normal file
40
src/dxvk/hud/dxvk_hud_config.h
Normal file
@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include "../dxvk_include.h"
|
||||
|
||||
namespace dxvk {
|
||||
|
||||
/**
|
||||
* \brief HUD element
|
||||
*
|
||||
* These flags can be used to enable
|
||||
* or disable HUD elements on demand.
|
||||
*/
|
||||
enum class HudElement {
|
||||
DeviceInfo = 0,
|
||||
Framerate = 1,
|
||||
};
|
||||
|
||||
using HudElements = Flags<HudElement>;
|
||||
|
||||
|
||||
/**
|
||||
* \brief HUD configuration
|
||||
*/
|
||||
struct HudConfig {
|
||||
HudConfig();
|
||||
HudConfig(const std::string& configStr);
|
||||
|
||||
HudElements elements;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* \brief Gets HUD configuration from config strnig
|
||||
*
|
||||
* \param [in] configStr Configuration string
|
||||
* \returns HUD configuration struct
|
||||
*/
|
||||
HudConfig parseHudConfigStr(const std::string& configStr);
|
||||
|
||||
}
|
@ -48,6 +48,7 @@ dxvk_src = files([
|
||||
'dxvk_util.cpp',
|
||||
|
||||
'hud/dxvk_hud.cpp',
|
||||
'hud/dxvk_hud_config.cpp',
|
||||
'hud/dxvk_hud_devinfo.cpp',
|
||||
'hud/dxvk_hud_font.cpp',
|
||||
'hud/dxvk_hud_fps.cpp',
|
||||
|
Loading…
x
Reference in New Issue
Block a user