Vulkan icon indicating copy to clipboard operation
Vulkan copied to clipboard

Using getAssetPath() for all data accessing

Open wumo opened this issue 4 years ago • 5 comments

https://github.com/SaschaWillems/Vulkan/blob/e1e348ac7a5b468aadc958bfd998497d6570cb49/base/VulkanUIOverlay.cpp#L75

Currently VulkanUIOverlay references the "Roboto-Medium.ttf" by relative path to the compiled binary which can results in the following error:

image

I suggest using getAssetPath() for all data file accessing which is defined in: https://github.com/SaschaWillems/Vulkan/blob/e1e348ac7a5b468aadc958bfd998497d6570cb49/base/vulkanexamplebase.cpp#L106

wumo avatar Nov 02 '19 08:11 wumo

The getAssetPath is an Absolute Path. And it is defined in your cmake.

engineer1109 avatar Nov 11 '19 06:11 engineer1109

@engineer1109 Right. Absolute path is needed because the compiled binary is located in ${CMAKE_CURRENT_BINARY_DIR}/bin which can be anywhere.

wumo avatar Nov 11 '19 06:11 wumo

See #470 and #477

eero-t avatar Jan 24 '20 09:01 eero-t

I suggest to write a smart file checker function for both relative and absolute path.

#ifndef VULKAN_BASICENGINE_FILESYSTEM_H  
#define VULKAN_BASICENGINE_FILESYSTEM_H  
#include <string>  
#include <iostream>  
#include <experimental/filesystem>  
class FS{  
public:
    static std::string getAssetPath(std::string p){
        using namespace std::experimental::filesystem;
        path pa=path(std::string("../data/"+p).c_str());   //for vs2015 compatibility
        path pb=path(std::string(PROJECT_ABSOLUTE_PATH+("/data/"+p)).c_str());
//        std::cout<<pa.c_str()<<std::endl;
//        std::cout<<pb.c_str()<<std::endl;
        if(exists(pa)){
            return std::string("../data/"+p);
        }
        else if(exists(pb)){
            return std::string(PROJECT_ABSOLUTE_PATH+("/data/"+p));
        }
        else {
            std::cout<<"Error!Could not find this file:"<<p<<std::endl;
            exit(1);
        }
    }
};
#endif // VULKAN_BASICENGINE_FILESYSTEM_H  

Look my project

https://github.com/engineer1109/LearnVulkan/blob/master/include/basicengine/vulkan_basicengine_filesystem.h

engineer1109 avatar Feb 04 '20 15:02 engineer1109

I have slightly reworked this and centralized the code for asset path handling. Loading font is now done using the getAssetPath function.

SaschaWillems avatar Feb 17 '20 20:02 SaschaWillems