Archived
1
Fork 0

Fix resource path handling on macOS

This commit is contained in:
redstrate 2021-09-13 17:19:59 -04:00
parent 45977b4ac1
commit f213d3d548
3 changed files with 24 additions and 8 deletions

View file

@ -8,7 +8,7 @@
#include "path.hpp" #include "path.hpp"
void app_main(prism::engine* engine) { void app_main(prism::engine* engine) {
prism::set_domain_path(prism::domain::app, "data"); prism::set_domain_path(prism::domain::app, "{resource_dir}/data");
prism::set_domain_path(prism::domain::internal, "{resource_dir}/shaders"); prism::set_domain_path(prism::domain::internal, "{resource_dir}/shaders");
platform::open_window("Example", {-1, -1, 1280, 720}, WindowFlags::Resizable); platform::open_window("Example", {-1, -1, 1280, 720}, WindowFlags::Resizable);
@ -30,8 +30,8 @@ void ExampleApp::initialize_render() {
auto sphere_obj = scene->add_object(); auto sphere_obj = scene->add_object();
auto& sphere_render = scene->add<Renderable>(sphere_obj); auto& sphere_render = scene->add<Renderable>(sphere_obj);
sphere_render.mesh = assetm->get<Mesh>(prism::path("data/models/sphere.model")); sphere_render.mesh = assetm->get<Mesh>(prism::path(prism::app_domain / "models/sphere.model"));
sphere_render.materials = { assetm->get<Material>(prism::path("data/materials/Material.material")) }; sphere_render.materials = { assetm->get<Material>(prism::path(prism::app_domain / "materials/Material.material")) };
auto probe_obj = scene->add_object(); auto probe_obj = scene->add_object();
scene->add<EnvironmentProbe>(probe_obj); scene->add<EnvironmentProbe>(probe_obj);

View file

@ -15,8 +15,12 @@ add_platform(
function(add_platform_commands target) function(add_platform_commands target)
if(NOT SKIP_DATA) if(NOT SKIP_DATA)
if(ENABLE_MACOS)
add_custom_command(TARGET ${target} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/data $<TARGET_FILE_DIR:${target}>/../Resources/data)
else()
add_custom_command(TARGET ${target} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/data $<TARGET_FILE_DIR:${target}>/data) add_custom_command(TARGET ${target} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/data $<TARGET_FILE_DIR:${target}>/data)
endif() endif()
endif()
# we HAVE to create this dummy target to convince CMake to properly copy over shader files. # we HAVE to create this dummy target to convince CMake to properly copy over shader files.
# before you ask, we have used POST_BUILD before but that only runs if the TARGET specified is built. # before you ask, we have used POST_BUILD before but that only runs if the TARGET specified is built.
@ -27,10 +31,18 @@ function(add_platform_commands target)
add_custom_target(${DUMMY_NAME} ALL DEPENDS ${CMAKE_BINARY_DIR}/dummy) add_custom_target(${DUMMY_NAME} ALL DEPENDS ${CMAKE_BINARY_DIR}/dummy)
if(ENABLE_MACOS)
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/dummy
COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${target}>/../Resources/shaders
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_BINARY_DIR}/shaders $<TARGET_FILE_DIR:${target}>/../Resources/shaders
)
else()
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/dummy add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/dummy
COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${target}>/shaders COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${target}>/shaders
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_BINARY_DIR}/shaders $<TARGET_FILE_DIR:${target}>/shaders COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_BINARY_DIR}/shaders $<TARGET_FILE_DIR:${target}>/shaders
) )
endif()
add_dependencies(${target} ${DUMMY_NAME}) add_dependencies(${target} ${DUMMY_NAME})
endfunction() endfunction()

View file

@ -3,7 +3,11 @@
#include "string_utils.hpp" #include "string_utils.hpp"
void prism::set_domain_path(const prism::domain domain, const prism::path path) { void prism::set_domain_path(const prism::domain domain, const prism::path path) {
#ifdef PLATFORM_MACOS
domain_data[(int)domain] = replace_substring(path.string(), "{resource_dir}/", "../Resources/");
#else
domain_data[(int)domain] = replace_substring(path.string(), "{resource_dir}/", ""); domain_data[(int)domain] = replace_substring(path.string(), "{resource_dir}/", "");
#endif
} }
prism::path prism::get_writeable_directory() { prism::path prism::get_writeable_directory() {