#pragma once #include "../dxvk_device.h" #include "dxvk_hud_font.h" namespace dxvk::hud { /** * \brief HUD coordinates * * Coordinates relative to the top-left * corner of the swap image, in pixels. */ struct HudPos { float x; float y; }; /** * \brief Texture coordinates * * Absolute texture coordinates that are used * to pick letters in the font texture. */ struct HudTexCoord { uint32_t u; uint32_t v; }; /** * \brief Color * * SRGB color with alpha channel. The text * will use this color for the most part. */ struct HudColor { float r; float g; float b; float a; }; /** * \brief Vertex */ struct HudVertex { HudPos position; HudTexCoord texcoord; HudColor color; }; /** * \brief Text renderer for the HUD * * Can be used by the presentation backend to * display performance and driver information. */ class HudRenderer { constexpr static VkDeviceSize MaxVertexCount = 1 << 16; public: HudRenderer( const Rc& device); ~HudRenderer(); void beginFrame( const Rc& context); void drawText( const Rc& context, float size, HudPos pos, HudColor color, const std::string& text); void drawLines( const Rc& context, size_t vertexCount, const HudVertex* vertexData); private: enum class Mode { RenderNone, RenderText, RenderLines, }; std::array m_charMap; Mode m_mode; Rc m_vertShader; Rc m_textShader; Rc m_lineShader; Rc m_fontImage; Rc m_fontView; Rc m_fontSampler; Rc m_vertexBuffer; size_t m_vertexIndex = 0; void setRenderMode( const Rc& context, Mode mode); Rc createVertexShader( const Rc& device); Rc createTextShader( const Rc& device); Rc createLineShader( const Rc& device); Rc createFontImage( const Rc& device); Rc createFontView( const Rc& device); Rc createFontSampler( const Rc& device); Rc createVertexBuffer( const Rc& device); void initFontTexture( const Rc& device); void initCharMap(); }; }