summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--assetFactory/assimp.cpp7
-rw-r--r--assetFactory/object.cpp3
-rw-r--r--gfx/gl/program.cpp3
-rw-r--r--gfx/gl/shader.cpp3
-rw-r--r--gfx/image.cpp6
-rw-r--r--lib/persistence.h3
-rw-r--r--test/test-text.cpp8
-rw-r--r--ui/font.cpp79
-rw-r--r--ui/window.cpp3
9 files changed, 62 insertions, 53 deletions
diff --git a/assetFactory/assimp.cpp b/assetFactory/assimp.cpp
index f72e50a..1e11eda 100644
--- a/assetFactory/assimp.cpp
+++ b/assetFactory/assimp.cpp
@@ -1,12 +1,11 @@
#include "assimp.h"
#include "assetFactory.h"
#include "collections.h"
-#include "ptr.h"
#include "resource.h"
#include <assimp/cimport.h>
#include <assimp/postprocess.h>
#include <assimp/scene.h>
-#include <future>
+#include <format>
#include <stb/stb_image.h>
template<typename T>
@@ -39,7 +38,7 @@ public:
const aiNode * node;
CreatedFaces
- createMesh(ModelFactoryMesh & mesh, Scale3D) const
+ createMesh(ModelFactoryMesh & mesh, Scale3D) const override
{
CreatedFaces faces;
addMesh(faces, mesh, node);
@@ -103,7 +102,7 @@ AssImp::postLoad()
SceneCPtr scene {
aiImportFile(Resource::mapPath(path).c_str(), aiProcess_RemoveRedundantMaterials), &aiReleaseImport};
if (!scene) {
- throw std::runtime_error("Failed to load asset library: " + path);
+ throw std::runtime_error(std::format("Failed to load asset library: {}", path));
}
if (auto mf = Persistence::ParseBase::getShared<AssetFactory>("assetFactory")) {
const auto root = AIRANGE(scene->mRootNode, Children);
diff --git a/assetFactory/object.cpp b/assetFactory/object.cpp
index f48dcf6..f87a487 100644
--- a/assetFactory/object.cpp
+++ b/assetFactory/object.cpp
@@ -1,5 +1,6 @@
#include "object.h"
#include <algorithm>
+#include <format>
Object::Object(std::string i) : id {std::move(i)} { }
@@ -10,7 +11,7 @@ Object::createMesh(ModelFactoryMesh & mesh, Scale3D levelOfDetailFactor) const
for (const auto & use : uses) {
auto useFaces = use->createMesh(mesh, levelOfDetailFactor);
std::transform(useFaces.begin(), useFaces.end(), std::inserter(faces, faces.end()), [this](auto && face) {
- return std::make_pair(id + ":" + face.first, std::move(face.second));
+ return std::make_pair(std::format("{}:{}", id, face.first), std::move(face.second));
});
}
return faces;
diff --git a/gfx/gl/program.cpp b/gfx/gl/program.cpp
index 0b60eaa..7287fde 100644
--- a/gfx/gl/program.cpp
+++ b/gfx/gl/program.cpp
@@ -1,5 +1,6 @@
#include "program.h"
#include "shader.h"
+#include <format>
#include <glm/gtc/type_ptr.hpp>
#include <glm/gtx/transform.hpp>
#include <location.h>
@@ -30,6 +31,6 @@ Program::RequiredUniformLocation::RequiredUniformLocation(GLuint program, const
UniformLocation {program, name}
{
if (location < 0) {
- throw std::logic_error(std::string {"Required uniform does not exist: "} + name);
+ throw std::logic_error {std::format("Required uniform does not exist: {}", name)};
}
}
diff --git a/gfx/gl/shader.cpp b/gfx/gl/shader.cpp
index 0f75817..0bc127a 100644
--- a/gfx/gl/shader.cpp
+++ b/gfx/gl/shader.cpp
@@ -1,6 +1,7 @@
#include "shader.h"
#include <algorithm>
#include <array>
+#include <format>
#include <stdexcept>
#include <string>
@@ -70,6 +71,6 @@ Shader::CheckShaderError(GLuint shader, GLuint flag, bool isProgram, std::string
glGetShaderInfoLog(shader, error.size(), nullptr, error.data());
}
- throw std::runtime_error {std::string {errorMessage} + ": '" + std::string {error.data(), error.size()} + "'"};
+ throw std::runtime_error {std::format("{}: '{}'", errorMessage, error.data())};
}
}
diff --git a/gfx/image.cpp b/gfx/image.cpp
index fb86cb6..3b63054 100644
--- a/gfx/image.cpp
+++ b/gfx/image.cpp
@@ -1,5 +1,6 @@
#include "image.h"
#include <cstddef>
+#include <format>
#include <stb/stb_image.h>
#include <stdexcept>
@@ -13,7 +14,7 @@ Image::Image(const char * fileName, int flags) : width {}, height {}, numCompone
numComponents = static_cast<unsigned int>(nc);
if (!bytes) {
- throw std::runtime_error {std::string {"Unable to load image: "} + fileName};
+ throw std::runtime_error {std::format("Unable to load image: {}", fileName)};
}
data = {bytes, static_cast<size_t>(width * height * numComponents)};
@@ -29,7 +30,8 @@ Image::Image(std::span<unsigned char> buffer, int flags)
numComponents = static_cast<unsigned int>(nc);
if (!bytes) {
- throw std::runtime_error {"Unable to load image from memory buffer "};
+ throw std::runtime_error {std::format("Unable to load image from memory buffer @ {} ({} bytes)",
+ static_cast<void *>(buffer.data()), buffer.size_bytes())};
}
data = {bytes, static_cast<size_t>(width * height * numComponents)};
diff --git a/lib/persistence.h b/lib/persistence.h
index 3c95a00..e385b20 100644
--- a/lib/persistence.h
+++ b/lib/persistence.h
@@ -1,6 +1,7 @@
#pragma once
#include <charconv>
+#include <format>
#include <functional>
#include <glm/glm.hpp>
#include <iosfwd>
@@ -571,7 +572,7 @@ namespace Persistence {
make_default_as_needed(this->v);
PersistenceSelect ps {mbr};
if (this->v->persist(ps)) {
- throw std::runtime_error("cannot find member: " + mbr);
+ throw std::runtime_error {std::format("Cannot find member: {}", mbr)};
}
return std::move(ps.sel);
}
diff --git a/test/test-text.cpp b/test/test-text.cpp
index f652670..f185cf5 100644
--- a/test/test-text.cpp
+++ b/test/test-text.cpp
@@ -70,10 +70,10 @@ using CharDataTest = std::tuple<decltype(get_codepoint(nullptr)), Font::CharData
BOOST_DATA_TEST_CASE(initialize_chardata_A,
boost::unit_test::data::make<CharDataTest>({
- {'A', {0, {34, 35}, {627, 0}, {-1, 35}, 32}},
- {'I', {0, {6, 35}, {862, 0}, {4, 35}, 13}},
- {'j', {0, {11, 45}, {1656, 0}, {-3, 35}, 11}},
- {'o', {0, {24, 27}, {1748, 0}, {1, 27}, 27}},
+ {'A', {0, {34, 35}, {712, 0}, {-1, 35}, 32}},
+ {'I', {0, {6, 35}, {947, 0}, {4, 35}, 13}},
+ {'j', {0, {11, 45}, {1741, 0}, {-3, 35}, 11}},
+ {'o', {0, {24, 27}, {1833, 0}, {1, 27}, 27}},
}),
character, expected)
{
diff --git a/ui/font.cpp b/ui/font.cpp
index b6669b0..ebd29d0 100644
--- a/ui/font.cpp
+++ b/ui/font.cpp
@@ -1,6 +1,7 @@
#include "font.h"
#include <algorithm>
#include <cctype>
+#include <format>
#include <ft2build.h>
#include FT_FREETYPE_H
#include "gl_traits.h"
@@ -15,49 +16,51 @@
// IWYU pragma: no_forward_declare FT_LibraryRec_
-std::string
-FT_Error_StringSafe(FT_Error err)
-{
- if (const auto errstr = FT_Error_String(err)) {
- return {errstr};
+namespace {
+ std::string
+ FT_Error_StringSafe(FT_Error err)
+ {
+ if (const auto errstr = FT_Error_String(err)) {
+ return {errstr};
+ }
+ return std::format("Unknown FT error: {}", err);
}
- return std::to_string(err);
-}
-template<auto Func, typename... Args>
-void
-FT_Check(Args &&... args)
-{
- if (const auto err = Func(std::forward<Args>(args)...)) {
- throw std::runtime_error {std::string {"FreeType error: "} + FT_Error_StringSafe(err)};
+ template<auto Func, typename... Args>
+ void
+ FT_Check(Args &&... args)
+ {
+ if (const auto err = Func(std::forward<Args>(args)...)) {
+ throw std::runtime_error {std::format("FreeType error: {}", FT_Error_StringSafe(err))};
+ }
}
-}
-const std::string BASIC_CHARS = []() {
- std::string chars;
- for (char c {}; c >= 0; c++) {
- if (isgraph(c)) {
- chars += c;
+ const std::string BASIC_CHARS = []() {
+ std::string chars {"£€²³"};
+ for (char c {}; c >= 0; c++) {
+ if (isgraph(c)) {
+ chars += c;
+ }
}
- }
- return chars + "£€²³";
-}();
-
-using FT = glRef<FT_Library,
- []() {
- FT_Library ft {};
- FT_Check<FT_Init_FreeType>(&ft);
- return ft;
- },
- FT_Done_FreeType>;
-
-using Face = glRef<FT_Face,
- [](FT_Library ft, const char * const name) {
- FT_Face face {};
- FT_Check<FT_New_Face>(ft, name, 0, &face);
- return face;
- },
- FT_Done_Face>;
+ return chars;
+ }();
+
+ using FT = glRef<FT_Library,
+ []() {
+ FT_Library ft {};
+ FT_Check<FT_Init_FreeType>(&ft);
+ return ft;
+ },
+ FT_Done_FreeType>;
+
+ using Face = glRef<FT_Face,
+ [](FT_Library ft, const char * const name) {
+ FT_Face face {};
+ FT_Check<FT_New_Face>(ft, name, 0, &face);
+ return face;
+ },
+ FT_Done_Face>;
+}
Font::Font(std::filesystem::path p, unsigned s) : path {std::move(p)}, size {getTextureSize(s)}
{
diff --git a/ui/window.cpp b/ui/window.cpp
index 6855aa0..dd488d7 100644
--- a/ui/window.cpp
+++ b/ui/window.cpp
@@ -1,5 +1,6 @@
#include "window.h"
#include "uiComponent.h"
+#include <format>
#include <glad/gl.h>
#include <glm/glm.hpp>
#include <stdexcept>
@@ -9,7 +10,7 @@ Window::GLInitHelper::GLInitHelper()
[[maybe_unused]] static auto init = []() {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
if (const auto version = gladLoadGL(reinterpret_cast<GLADloadfunc>(SDL_GL_GetProcAddress)); version < 30003) {
- throw std::runtime_error {"Insufficient OpenGL version: " + std::to_string(version)};
+ throw std::runtime_error {std::format("Insufficient OpenGL version: {}", version)};
}
else {
return version;