Skip to content

Commit

Permalink
Instance: use utf8 string for application name
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathSpirit committed Sep 16, 2024
1 parent 825b720 commit 9e8a8ac
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
10 changes: 5 additions & 5 deletions includes/FastEngine/vulkan/C_instance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "FastEngine/fge_extern.hpp"
#include "volk.h"
#include "C_physicalDevice.hpp"
#include "SDL_vulkan.h"
#include "tinyutf8.h"
#include <optional>
#include <string>
#include <vector>
Expand All @@ -39,7 +39,7 @@ class FGE_API Instance
{
public:
Instance();
explicit Instance(std::string applicationName,
explicit Instance(std::string_view applicationName,
uint16_t versionMajor = 1,
uint16_t versionMinor = 0,
uint16_t versionPatch = 0);
Expand All @@ -58,13 +58,13 @@ class FGE_API Instance
* \param versionMinor The application version minor
* \param versionPatch The application version patch
*/
void create(std::string applicationName,
void create(std::string_view applicationName,
uint16_t versionMajor = 1,
uint16_t versionMinor = 0,
uint16_t versionPatch = 0);
void destroy();

[[nodiscard]] std::string const& getApplicationName() const;
[[nodiscard]] tiny_utf8::string const& getApplicationName() const;

[[nodiscard]] VkInstance get() const;

Expand All @@ -91,7 +91,7 @@ class FGE_API Instance
void enumeratePhysicalDevices();

VkInstance g_instance;
std::string g_applicationName;
tiny_utf8::string g_applicationName;

std::vector<PhysicalDevice> g_physicalDevices;
};
Expand Down
16 changes: 11 additions & 5 deletions sources/vulkan/C_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ namespace fge::vulkan
Instance::Instance() :
g_instance(VK_NULL_HANDLE)
{}
Instance::Instance(std::string applicationName, uint16_t versionMajor, uint16_t versionMinor, uint16_t versionPatch) :
Instance::Instance(std::string_view applicationName,
uint16_t versionMajor,
uint16_t versionMinor,
uint16_t versionPatch) :
g_instance(VK_NULL_HANDLE)
{
this->create(std::move(applicationName), versionMajor, versionMinor, versionPatch);
this->create(applicationName, versionMajor, versionMinor, versionPatch);
}
Instance::Instance(Instance&& r) noexcept :
g_instance(r.g_instance),
Expand All @@ -45,14 +48,17 @@ Instance::~Instance()
this->destroy();
}

void Instance::create(std::string applicationName, uint16_t versionMajor, uint16_t versionMinor, uint16_t versionPatch)
void Instance::create(std::string_view applicationName,
uint16_t versionMajor,
uint16_t versionMinor,
uint16_t versionPatch)
{
if (this->g_instance != VK_NULL_HANDLE)
{
throw fge::Exception{"instance already created !"};
}

this->g_applicationName = std::move(applicationName);
this->g_applicationName = applicationName;

VkApplicationInfo appInfo{};
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Expand Down Expand Up @@ -117,7 +123,7 @@ void Instance::destroy()
}
}

std::string const& Instance::getApplicationName() const
tiny_utf8::string const& Instance::getApplicationName() const
{
return this->g_applicationName;
}
Expand Down
2 changes: 1 addition & 1 deletion sources/vulkan/C_surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ SurfaceSDLWindow::SurfaceSDLWindow(Instance& instance,
uint32_t flags) :
SurfaceSDLWindow(instance)
{
this->create(instance.getApplicationName(), position, size, flags);
this->create(instance.getApplicationName().cpp_str_view(), position, size, flags);
}
SurfaceSDLWindow::SurfaceSDLWindow(SurfaceSDLWindow&& r) noexcept :
SurfaceWindow(std::move(r)),
Expand Down

0 comments on commit 9e8a8ac

Please sign in to comment.