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.
This commit is contained in:
parent
15fc71cfcf
commit
8af6bfb8b0
|
@ -6,11 +6,14 @@
|
||||||
|
|
||||||
#include <cstdarg>
|
#include <cstdarg>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <iterator>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <fmt/format.h>
|
||||||
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
#include "Common/StringUtil.h"
|
#include "Common/StringUtil.h"
|
||||||
#include "VideoCommon/VideoCommon.h"
|
#include "VideoCommon/VideoCommon.h"
|
||||||
|
@ -101,6 +104,8 @@ class ShaderCode : public ShaderGeneratorInterface
|
||||||
public:
|
public:
|
||||||
ShaderCode() { m_buffer.reserve(16384); }
|
ShaderCode() { m_buffer.reserve(16384); }
|
||||||
const std::string& GetBuffer() const { return m_buffer; }
|
const std::string& GetBuffer() const { return m_buffer; }
|
||||||
|
|
||||||
|
// Deprecated: Writes format strings using traditional printf format strings.
|
||||||
void Write(const char* fmt, ...)
|
void Write(const char* fmt, ...)
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
__attribute__((format(printf, 2, 3)))
|
__attribute__((format(printf, 2, 3)))
|
||||||
|
@ -112,6 +117,13 @@ public:
|
||||||
va_end(arglist);
|
va_end(arglist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Writes format strings using fmtlib format strings.
|
||||||
|
template <typename... Args>
|
||||||
|
void WriteFmt(std::string_view format, Args&&... args)
|
||||||
|
{
|
||||||
|
fmt::format_to(std::back_inserter(m_buffer), format, std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string m_buffer;
|
std::string m_buffer;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue