1
0

finish buggy dx11 code

This commit is contained in:
2026-01-04 23:11:58 +08:00
parent a66d3dee8b
commit 7b234ec405
12 changed files with 432 additions and 219 deletions

View File

@@ -1,18 +1,67 @@
#include "dll_loader.hpp"
#include <basalt_char.hpp>
#include <stdexcept>
#include <filesystem>
#if defined(BASALT_OS_WINDOWS)
#include <windows.h>
#else
#include <unistd.h>
#endif
namespace Basalt::Presenter {
DllLoader::DllLoader(DllKind kind, const std::basic_string_view<BSCHAR> filename) {
// TODO:
// Add current executable location supports.
// Add sub directories supports.
// Fix file name terminal error.
static std::filesystem::path get_executable() {
#if defined(BASALT_OS_WINDOWS)
m_Handle = LoadLibraryW(filename.data());
wchar_t buffer[MAX_PATH];
DWORD hr = GetModuleFileNameW(NULL, buffer, MAX_PATH);
if (hr == 0) {
throw std::runtime_error("Failed to get executable path");
} else {
return std::filesystem::path(buffer);
}
#else
m_Handle = dlopen(filename.data(), RTLD_LAZY);
char buffer[PATH_MAX];
ssize_t len = readlink("/proc/self/exe", buffer, sizeof(buffer) - 1);
if (len != -1) {
buffer[len] = '\0';
return std::filesystem::path(buffer);
} else {
throw std::runtime_error("Failed to get executable path");
}
#endif
}
DllLoader::DllLoader(DllKind kind, const std::basic_string_view<BSCHAR> filename) {
// Build DLL full path
auto dll_path = get_executable().parent_path();
dll_path /= BSTEXT("plugin");
switch (kind) {
case DllKind::Engine:
dll_path /= BSTEXT("engine");
break;
case DllKind::Deliver:
dll_path /= BSTEXT("deliver");
break;
case DllKind::ObjectLoader:
dll_path /= BSTEXT("object_loader");
break;
case DllKind::AnimeLoader:
dll_path /= BSTEXT("anime_loader");
break;
}
dll_path /= filename;
#if defined(BASALT_OS_WINDOWS)
dll_path.replace_extension(BSTEXT(".dll"));
#endif
// Load DLL
#if defined(BASALT_OS_WINDOWS)
m_Handle = LoadLibraryW(dll_path.wstring().c_str());
#else
m_Handle = dlopen(dll_path.string().c_str(), RTLD_LAZY);
#endif
// Check loaded DLL
if (!m_Handle) throw std::runtime_error("Can not load given dynamic library.");
}