-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build Triangle for all supported platforms
- Loading branch information
Showing
15 changed files
with
110 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,32 @@ | ||
function(compile_shaders target shaders output) | ||
function(compile_shaders target base_dir output_subdir shaders output_var) | ||
if (CMAKE_CROSSCOMPILING AND IOS_OR_TVOS) | ||
set(shader_compiler_cli "${CMAKE_BINARY_DIR}/macOS/bin/ShaderCompilerCLI") | ||
else() | ||
set(shader_compiler_cli "$<TARGET_FILE:ShaderCompilerCLI>") | ||
endif() | ||
set(output_dir "${CMAKE_BINARY_DIR}/gen/${target}/") | ||
set(output_dir "${CMAKE_BINARY_DIR}/bin/${output_subdir}/") | ||
foreach(full_shader_path ${shaders}) | ||
get_filename_component(shader_name ${full_shader_path} NAME_WE) | ||
cmake_path(RELATIVE_PATH full_shader_path BASE_DIRECTORY "${base_dir}" OUTPUT_VARIABLE shader_name) | ||
get_filename_component(shader_folder ${shader_name} DIRECTORY) | ||
set(spirv ${output_dir}/${shader_name}.spirv) | ||
set(dxil ${output_dir}/${shader_name}.dxil) | ||
get_property(entrypoint SOURCE ${full_shader_path} PROPERTY SHADER_ENTRYPOINT) | ||
get_property(type SOURCE ${full_shader_path} PROPERTY SHADER_TYPE) | ||
get_property(model SOURCE ${full_shader_path} PROPERTY SHADER_MODEL) | ||
add_custom_command(OUTPUT ${spirv} ${dxil} | ||
COMMAND ${CMAKE_COMMAND} -E echo ${shader_name} ${full_shader_path} ${entrypoint} ${type} ${model} ${output_dir} | ||
COMMAND ${CMAKE_COMMAND} -E make_directory ${output_dir} | ||
COMMAND ${CMAKE_COMMAND} -E make_directory ${output_dir}/${shader_folder} | ||
COMMAND ${shader_compiler_cli} ${shader_name} ${full_shader_path} ${entrypoint} ${type} ${model} ${output_dir} | ||
DEPENDS ShaderCompilerCLI | ||
MAIN_DEPENDENCY "${full_shader_path}" | ||
) | ||
set_source_files_properties(${spirv} ${dxil} PROPERTIES | ||
MACOSX_PACKAGE_LOCATION "Resources/${output_subdir}/${shader_folder}" | ||
) | ||
source_group("Shader Files" FILES "${full_shader_path}") | ||
source_group("Shader Blobs" FILES ${spirv} ${dxil}) | ||
set(compiled_shaders ${compiled_shaders} ${spirv}) | ||
set(compiled_shaders ${compiled_shaders} ${dxil}) | ||
endforeach() | ||
set(${output} ${compiled_shaders} PARENT_SCOPE) | ||
set(${output_var} ${compiled_shaders} PARENT_SCOPE) | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "Utilities/Common.h" | ||
|
||
#include "Utilities/SystemUtils.h" | ||
|
||
#include <filesystem> | ||
#include <fstream> | ||
#include <iterator> | ||
|
||
#if defined(__APPLE__) | ||
#import <Foundation/Foundation.h> | ||
#endif | ||
|
||
uint64_t Align(uint64_t size, uint64_t alignment) | ||
{ | ||
return (size + (alignment - 1)) & ~(alignment - 1); | ||
} | ||
|
||
std::vector<uint8_t> ReadBinaryFile(const std::string& filepath) | ||
{ | ||
std::ifstream file(filepath, std::ios::binary); | ||
file.unsetf(std::ios::skipws); | ||
|
||
std::streampos filesize; | ||
file.seekg(0, std::ios::end); | ||
filesize = file.tellg(); | ||
file.seekg(0, std::ios::beg); | ||
|
||
std::vector<uint8_t> data; | ||
data.reserve(filesize); | ||
data.insert(data.begin(), std::istream_iterator<uint8_t>(file), std::istream_iterator<uint8_t>()); | ||
return data; | ||
} | ||
|
||
std::string GetAssertPath(const std::string& filepath) | ||
{ | ||
#if defined(__APPLE__) | ||
auto path = std::filesystem::path(filepath); | ||
auto resource = [[NSBundle mainBundle] pathForResource:[NSString stringWithUTF8String:path.stem().c_str()] | ||
ofType:[NSString stringWithUTF8String:path.extension().c_str()] | ||
inDirectory:[NSString stringWithUTF8String:path.parent_path().c_str()]]; | ||
if (resource) { | ||
return [resource UTF8String]; | ||
} | ||
#endif | ||
return GetExecutableDir() + "\\" + filepath; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,9 @@ | ||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <fstream> | ||
#include <iterator> | ||
#include <string> | ||
#include <vector> | ||
|
||
inline uint64_t Align(uint64_t size, uint64_t alignment) | ||
{ | ||
return (size + (alignment - 1)) & ~(alignment - 1); | ||
} | ||
|
||
inline std::vector<uint8_t> ReadBinaryFile(const std::string& filename) | ||
{ | ||
std::ifstream file(filename, std::ios::binary); | ||
file.unsetf(std::ios::skipws); | ||
|
||
std::streampos filesize; | ||
file.seekg(0, std::ios::end); | ||
filesize = file.tellg(); | ||
file.seekg(0, std::ios::beg); | ||
|
||
std::vector<uint8_t> data; | ||
data.reserve(filesize); | ||
data.insert(data.begin(), std::istream_iterator<uint8_t>(file), std::istream_iterator<uint8_t>()); | ||
return data; | ||
} | ||
uint64_t Align(uint64_t size, uint64_t alignment); | ||
std::vector<uint8_t> ReadBinaryFile(const std::string& filepath); | ||
std::string GetAssertPath(const std::string& filepath); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters