mirror of
https://github.com/JoeyDeVries/LearnOpenGL.git
synced 2026-01-30 20:13:22 +08:00
Support for out-of-source builds.
Uses environment variable to tell the program where to find resource files. Sharder sources are still search for in the current workind directory.
This commit is contained in:
49
includes/learnopengl/filesystem.h
Normal file
49
includes/learnopengl/filesystem.h
Normal file
@@ -0,0 +1,49 @@
|
||||
#ifndef FILESYSTEM_H
|
||||
#define FILESYSTEM_H
|
||||
|
||||
#include <string>
|
||||
|
||||
class FileSystem
|
||||
{
|
||||
private:
|
||||
typedef std::string (*Builder) (const std::string& path);
|
||||
|
||||
public:
|
||||
static std::string getPath(const std::string& path)
|
||||
{
|
||||
static std::string(*pathBuilder)(std::string const &) = getPathBuilder();
|
||||
return (*pathBuilder)(path);
|
||||
}
|
||||
|
||||
private:
|
||||
static std::string const & getRoot()
|
||||
{
|
||||
static char const * givenRoot {getenv("LOGL_ROOT_PATH")};
|
||||
static std::string root {givenRoot != nullptr ? givenRoot : ""};
|
||||
return root;
|
||||
}
|
||||
|
||||
//static std::string(*foo (std::string const &)) getPathBuilder()
|
||||
static Builder getPathBuilder()
|
||||
{
|
||||
if (getRoot() != "")
|
||||
return &FileSystem::getPathRelativeRoot;
|
||||
else
|
||||
return &FileSystem::getPathRelativeBinary;
|
||||
}
|
||||
|
||||
static std::string getPathRelativeRoot(const std::string& path)
|
||||
{
|
||||
return getRoot() + std::string("/") + path;
|
||||
}
|
||||
|
||||
static std::string getPathRelativeBinary(const std::string& path)
|
||||
{
|
||||
return "../../../" + path;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
// FILESYSTEM_H
|
||||
#endif
|
||||
Reference in New Issue
Block a user