Skip to content

Commit

Permalink
Base plugin API on SDL
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-johansson committed Aug 7, 2023
1 parent d00aa97 commit ad7ffd9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ set(VULKAN_INCLUDE_DIR "$ENV{VULKAN_SDK}/include")
# Vcpkg dependencies
find_package(argparse CONFIG REQUIRED)
find_package(assimp CONFIG REQUIRED)
find_package(Boost COMPONENTS filesystem REQUIRED)
find_package(Boost REQUIRED)
find_package(EnTT CONFIG REQUIRED)
find_package(fmt CONFIG REQUIRED)
find_package(glad CONFIG REQUIRED)
Expand Down
1 change: 0 additions & 1 deletion src/private/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ target_link_libraries(${GLOW_CORE_TARGET}
PRIVATE
SDL2::SDL2
Boost::boost
Boost::filesystem
)
29 changes: 22 additions & 7 deletions src/private/core/plugins/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,21 @@

#include "glow/core/plugins/plugin.hpp"

#include <boost/dll.hpp>
#include <SDL2/SDL.h>

namespace glow {
namespace {

using SharedLibrary = boost::dll::shared_library;
struct SharedLibraryDeleter final {
void operator()(void* handle) noexcept { SDL_UnloadObject(handle); }
};

} // namespace

using SharedLibraryHandle = std::unique_ptr<void, SharedLibraryDeleter>;

struct Plugin::Data final {
SharedLibrary dll;
SharedLibraryHandle dll;
};

Plugin::Plugin()
Expand All @@ -47,22 +54,30 @@ auto Plugin::operator=(Plugin&& other) noexcept -> Plugin& = default;

void Plugin::load(const std::filesystem::path& file)
{
mData->dll = SharedLibrary {file};
mData->dll.reset(SDL_LoadObject(file.string().c_str()));
}

auto Plugin::is_rhi_plugin() const -> bool
{
return mData->dll.has("glow_rhi_init") && mData->dll.has("glow_rhi_get_name");
if (is_valid()) {
return _get_symbol("glow_rhi_init") && _get_symbol("glow_rhi_get_name");
}

return false;
}

auto Plugin::is_valid() const -> bool
{
return mData->dll.is_loaded();
return mData->dll != nullptr;
}

auto Plugin::_get_symbol(const char* name) const -> void*
{
return mData->dll.get<void*>(name);
if (is_valid()) {
return SDL_LoadFunction(mData->dll.get(), name);
}

return nullptr;
}

} // namespace glow
1 change: 0 additions & 1 deletion vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"argparse",
"assimp",
"boost-assert",
"boost-dll",
"boost-predef",
"boost-stacktrace",
"entt",
Expand Down

0 comments on commit ad7ffd9

Please sign in to comment.