From 8af6bfb8b09f70552f2775db4a029a94968c6db4 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 3 Dec 2019 04:17:23 -0500 Subject: [PATCH] VideoCommon/ShaderGenCommon: Add function for writing fmt-based strings Begins the conversion of the shader generators over to using fmt formatting specifiers. This also has a benefit over the older StringFromFormat-based API in that all formatted data is appended to the existing buffer rather than creating a completely separate string and then appending it to the internal string buffer. --- Source/Core/VideoCommon/ShaderGenCommon.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Source/Core/VideoCommon/ShaderGenCommon.h b/Source/Core/VideoCommon/ShaderGenCommon.h index 12fa76fb72..889a446df8 100644 --- a/Source/Core/VideoCommon/ShaderGenCommon.h +++ b/Source/Core/VideoCommon/ShaderGenCommon.h @@ -6,11 +6,14 @@ #include #include +#include #include #include #include #include +#include + #include "Common/CommonTypes.h" #include "Common/StringUtil.h" #include "VideoCommon/VideoCommon.h" @@ -101,6 +104,8 @@ class ShaderCode : public ShaderGeneratorInterface public: ShaderCode() { m_buffer.reserve(16384); } const std::string& GetBuffer() const { return m_buffer; } + + // Deprecated: Writes format strings using traditional printf format strings. void Write(const char* fmt, ...) #ifdef __GNUC__ __attribute__((format(printf, 2, 3))) @@ -112,6 +117,13 @@ public: va_end(arglist); } + // Writes format strings using fmtlib format strings. + template + void WriteFmt(std::string_view format, Args&&... args) + { + fmt::format_to(std::back_inserter(m_buffer), format, std::forward(args)...); + } + protected: std::string m_buffer; };