shader processing
parent
cbc703b852
commit
cf48035378
|
@ -1,5 +1,5 @@
|
|||
/opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/bin/cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_MAKE_PROGRAM=/opt/netbrains/clion/clion-2022.1.3/bin/ninja/linux/ninja -DBUILD_TESTS:BOOL=ON -G Ninja -S /home/brett/Documents/code/c++/BLT -B /home/brett/Documents/code/c++/BLT/cmake-build-release
|
||||
Standard Files /home/brett/Documents/code/c++/BLT/src/blt/std/filesystem.cpp;/home/brett/Documents/code/c++/BLT/src/blt/std/format.cpp;/home/brett/Documents/code/c++/BLT/src/blt/std/logging.cpp;/home/brett/Documents/code/c++/BLT/src/blt/std/system.cpp
|
||||
Standard Files /home/brett/Documents/code/c++/BLT/src/blt/std/filesystem.cpp;/home/brett/Documents/code/c++/BLT/src/blt/std/format.cpp;/home/brett/Documents/code/c++/BLT/src/blt/std/loader.cpp;/home/brett/Documents/code/c++/BLT/src/blt/std/logging.cpp;/home/brett/Documents/code/c++/BLT/src/blt/std/system.cpp
|
||||
Profiler Files /home/brett/Documents/code/c++/BLT/src/blt/profiling/profiler.cpp
|
||||
Source: /home/brett/Documents/code/c++/BLT
|
||||
Current Source: /home/brett/Documents/code/c++/BLT
|
||||
|
|
|
@ -63,6 +63,13 @@ build CMakeFiles/BLT.dir/src/blt/std/format.cpp.o: CXX_COMPILER__BLT_Release /ho
|
|||
OBJECT_DIR = CMakeFiles/BLT.dir
|
||||
OBJECT_FILE_DIR = CMakeFiles/BLT.dir/src/blt/std
|
||||
|
||||
build CMakeFiles/BLT.dir/src/blt/std/loader.cpp.o: CXX_COMPILER__BLT_Release /home/brett/Documents/code/c++/BLT/src/blt/std/loader.cpp || cmake_object_order_depends_target_BLT
|
||||
DEP_FILE = CMakeFiles/BLT.dir/src/blt/std/loader.cpp.o.d
|
||||
FLAGS = -O3 -DNDEBUG -fdiagnostics-color=always
|
||||
INCLUDES = -I/home/brett/Documents/code/c++/BLT/include -I/home/brett/Documents/code/c++/BLT/cmake-build-release/config
|
||||
OBJECT_DIR = CMakeFiles/BLT.dir
|
||||
OBJECT_FILE_DIR = CMakeFiles/BLT.dir/src/blt/std
|
||||
|
||||
build CMakeFiles/BLT.dir/src/blt/std/logging.cpp.o: CXX_COMPILER__BLT_Release /home/brett/Documents/code/c++/BLT/src/blt/std/logging.cpp || cmake_object_order_depends_target_BLT
|
||||
DEP_FILE = CMakeFiles/BLT.dir/src/blt/std/logging.cpp.o.d
|
||||
FLAGS = -O3 -DNDEBUG -fdiagnostics-color=always
|
||||
|
@ -106,7 +113,7 @@ build CMakeFiles/BLT.dir/src/blt/nbt/nbt_block.cpp.o: CXX_COMPILER__BLT_Release
|
|||
#############################################
|
||||
# Link the static library libBLT.a
|
||||
|
||||
build libBLT.a: CXX_STATIC_LIBRARY_LINKER__BLT_Release CMakeFiles/BLT.dir/src/blt/std/filesystem.cpp.o CMakeFiles/BLT.dir/src/blt/std/format.cpp.o CMakeFiles/BLT.dir/src/blt/std/logging.cpp.o CMakeFiles/BLT.dir/src/blt/std/system.cpp.o CMakeFiles/BLT.dir/src/blt/profiling/profiler.cpp.o CMakeFiles/BLT.dir/src/blt/nbt/nbt.cpp.o CMakeFiles/BLT.dir/src/blt/nbt/nbt_block.cpp.o
|
||||
build libBLT.a: CXX_STATIC_LIBRARY_LINKER__BLT_Release CMakeFiles/BLT.dir/src/blt/std/filesystem.cpp.o CMakeFiles/BLT.dir/src/blt/std/format.cpp.o CMakeFiles/BLT.dir/src/blt/std/loader.cpp.o CMakeFiles/BLT.dir/src/blt/std/logging.cpp.o CMakeFiles/BLT.dir/src/blt/std/system.cpp.o CMakeFiles/BLT.dir/src/blt/profiling/profiler.cpp.o CMakeFiles/BLT.dir/src/blt/nbt/nbt.cpp.o CMakeFiles/BLT.dir/src/blt/nbt/nbt_block.cpp.o
|
||||
LANGUAGE_COMPILE_FLAGS = -O3 -DNDEBUG
|
||||
OBJECT_DIR = CMakeFiles/BLT.dir
|
||||
POST_BUILD = :
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Created by Brett on 08/02/23.
|
||||
* Licensed under GNU General Public License V3.0
|
||||
* See LICENSE file for license detail
|
||||
*/
|
||||
|
||||
#ifndef BLT_TESTS_LOADER_H
|
||||
#define BLT_TESTS_LOADER_H
|
||||
|
||||
#include <fstream>
|
||||
#include <ios>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
#include <blt/std/string.h>
|
||||
#include <blt/std/logging.h>
|
||||
|
||||
namespace blt::fs {
|
||||
std::vector<std::string> getLinesFromFile(const std::string& path);
|
||||
|
||||
std::vector<std::string> recursiveShaderInclude(const std::string& path);
|
||||
|
||||
std::string loadShaderFile(const std::string& path) {
|
||||
std::stringstream stringStream;
|
||||
|
||||
auto lines = recursiveShaderInclude(path);
|
||||
|
||||
for (const auto& line : lines) {
|
||||
// now process the defines, if they exist
|
||||
// if (line.starts_with("#define")) {
|
||||
// auto defineParts = String::split(line, " ");
|
||||
// // create a new define statement in the defines place but with the respective value.
|
||||
// if (defines.contains(defineParts[1])) {
|
||||
// stringStream << "#define ";
|
||||
// stringStream << defineParts[1] << " ";
|
||||
// stringStream << defines[defineParts[1]];
|
||||
// stringStream << "\n";
|
||||
// continue;
|
||||
// }
|
||||
// }
|
||||
stringStream << line;
|
||||
stringStream << "\n";
|
||||
}
|
||||
|
||||
//tlog << stringStream.str();
|
||||
return stringStream.str();
|
||||
}
|
||||
}
|
||||
|
||||
#endif //BLT_TESTS_LOADER_H
|
|
@ -116,12 +116,12 @@ namespace blt::logging {
|
|||
#define BLT_ERROR(format, ...)
|
||||
#define BLT_FATAL(format, ...)
|
||||
#else
|
||||
#define BLT_TRACE(format, ...) log_internal(format, blt::logging::TRACE, __FILE__, __LINE__, true, ##__VA_ARGS__);
|
||||
#define BLT_DEBUG(format, ...) log_internal(format, blt::logging::DEBUG, __FILE__, __LINE__, true, ##__VA_ARGS__);
|
||||
#define BLT_INFO(format, ...) log_internal(format, blt::logging::INFO, __FILE__, __LINE__, true, ##__VA_ARGS__);
|
||||
#define BLT_WARN(format, ...) log_internal(format, blt::logging::WARN, __FILE__, __LINE__, true, ##__VA_ARGS__);
|
||||
#define BLT_ERROR(format, ...) log_internal(format, blt::logging::ERROR, __FILE__, __LINE__, true, ##__VA_ARGS__);
|
||||
#define BLT_FATAL(format, ...) log_internal(format, blt::logging::FATAL, __FILE__, __LINE__, true, ##__VA_ARGS__);
|
||||
#define BLT_TRACE(format, ...) log_internal(format, blt::logging::TRACE, __FILE__, __LINE__, true, ##__VA_ARGS__)
|
||||
#define BLT_DEBUG(format, ...) log_internal(format, blt::logging::DEBUG, __FILE__, __LINE__, true, ##__VA_ARGS__)
|
||||
#define BLT_INFO(format, ...) log_internal(format, blt::logging::INFO, __FILE__, __LINE__, true, ##__VA_ARGS__)
|
||||
#define BLT_WARN(format, ...) log_internal(format, blt::logging::WARN, __FILE__, __LINE__, true, ##__VA_ARGS__)
|
||||
#define BLT_ERROR(format, ...) log_internal(format, blt::logging::ERROR, __FILE__, __LINE__, true, ##__VA_ARGS__)
|
||||
#define BLT_FATAL(format, ...) log_internal(format, blt::logging::FATAL, __FILE__, __LINE__, true, ##__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#endif //BLT_LOGGING_H
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Created by Brett on 08/02/23.
|
||||
* Licensed under GNU General Public License V3.0
|
||||
* See LICENSE file for license detail
|
||||
*/
|
||||
#include <blt/std/loader.h>
|
||||
|
||||
std::vector<std::string> blt::fs::getLinesFromFile(const std::string& path) {
|
||||
std::string shaderSource;
|
||||
std::ifstream shaderFile;
|
||||
if (!shaderFile.good())
|
||||
BLT_ERROR("Input stream not good!\n");
|
||||
// ensure ifstream objects can throw exceptions:
|
||||
shaderFile.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
||||
try {
|
||||
// open file
|
||||
shaderFile.open(path);
|
||||
std::stringstream shaderStream;
|
||||
// read file's buffer contents into streams
|
||||
shaderStream << shaderFile.rdbuf();
|
||||
// close file handlers
|
||||
shaderFile.close();
|
||||
// convert stream into std::string
|
||||
shaderSource = shaderStream.str();
|
||||
} catch (std::ifstream::failure& e) {
|
||||
BLT_FATAL("Unable to read file '%s'!\n", path.c_str());
|
||||
}
|
||||
|
||||
// split the shader into the lines, this way we can get out the #include statements.
|
||||
return string::split(shaderSource, "\n");
|
||||
}
|
||||
|
||||
std::vector<std::string> blt::fs::recursiveShaderInclude(const std::string& path) {
|
||||
std::string pathOnly = path.substr(0, path.find_last_of('/'));
|
||||
|
||||
auto mainLines = getLinesFromFile(path);
|
||||
std::unordered_map<int, std::vector<std::string>> includes;
|
||||
|
||||
for (int i = 0; i < mainLines.size(); i++) {
|
||||
auto& line = mainLines[i];
|
||||
// if the line is an include statement then we want to add lines recursively.
|
||||
if (string::starts_with(line, "#include")) {
|
||||
std::vector<std::string> include_statement = string::split(line, "<");
|
||||
|
||||
if (include_statement.size() <= 1)
|
||||
include_statement = string::split(line, "\"");
|
||||
|
||||
string::trim(line);
|
||||
if (!(string::ends_with(line, ">") || string::ends_with(line, "\""))) {
|
||||
BLT_FATAL("Shader file contains an invalid #include statement. (Missing terminator)\n");
|
||||
std::abort();
|
||||
}
|
||||
try {
|
||||
// filter out the > or " at the end of the include statement.
|
||||
std::string file;
|
||||
file = include_statement[1];
|
||||
if (string::ends_with(include_statement[1], ">"))
|
||||
file = file.substr(0, file.size() - 1);
|
||||
|
||||
BLT_TRACE("Recusing into %s/%s\n", pathOnly.c_str(), file.c_str());
|
||||
|
||||
includes.insert({i, recursiveShaderInclude((pathOnly + "/" + file))});
|
||||
} catch (std::exception& e) {
|
||||
BLT_FATAL("Shader file contains an invalid #include statement. (Missing < or \")\n");
|
||||
std::abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> returnLines;
|
||||
|
||||
// now combine all the loaded files while respecting the include's position in the file.
|
||||
for (int i = 0; i < mainLines.size(); i++) {
|
||||
if (!includes[i].empty()) {
|
||||
auto includedFileLines = includes[i];
|
||||
|
||||
for (const auto& line : includedFileLines)
|
||||
returnLines.push_back(line);
|
||||
} else
|
||||
returnLines.push_back(mainLines[i]);
|
||||
}
|
||||
return returnLines;
|
||||
}
|
|
@ -122,14 +122,15 @@ namespace blt::logging {
|
|||
if (level < BLT_LOGGING_PROPERTIES.minLevel)
|
||||
return;
|
||||
std::string outputString = System::getTimeStringLog();
|
||||
bool includeExtras = BLT_LOGGING_PROPERTIES.m_logWithData && currentLine >= 0;
|
||||
if (includeExtras) {
|
||||
outputString += "[";
|
||||
|
||||
if (BLT_LOGGING_PROPERTIES.m_logWithData && currentLine >= 0) {
|
||||
outputString += '[';
|
||||
outputString += filename(file);
|
||||
outputString += ":";
|
||||
outputString += ':';
|
||||
outputString += std::to_string(currentLine);
|
||||
outputString += "] ";
|
||||
}
|
||||
|
||||
outputString += levelNames[level];
|
||||
outputString += str;
|
||||
|
||||
|
|
Loading…
Reference in New Issue