Split large shader files into string literals rejoined into std strings

This commit is contained in:
Marek Roszko 2022-05-12 23:16:08 -04:00
parent 6188f632b9
commit 239af40256
1 changed files with 37 additions and 2 deletions

View File

@ -1,14 +1,49 @@
file( READ ${SOURCE} SOURCE_TEXT )
file( SIZE ${SOURCE} SOURCE_FILESIZE )
set( MAX_BYTES_PER_LITERAL 16380 )
math(EXPR NUMBER_LITERALS "${SOURCE_FILESIZE}/${MAX_BYTES_PER_LITERAL}")
set( outCppTextStdString "std::string ${OUTVARNAME} = ")
set( outCppText
"
#include <string>
#include <${OUTHEADERFILE}>
namespace KIGFX {
namespace BUILTIN_SHADERS {
const char ${OUTVARNAME}[] = R\"SHADER_SOURCE(
")
MATH(EXPR LAST_LITERAL_ITER "${LITERAL_ITER}-1")
foreach(LITERAL_ITER RANGE ${NUMBER_LITERALS})
set( outCppText
"
${outCppText}
const char ${OUTVARNAME}_p${LITERAL_ITER}[] = R\"SHADER_SOURCE(
${SOURCE_TEXT}
)SHADER_SOURCE\";
" )
set( outCppTextStdString "${outCppTextStdString} std::string(${OUTVARNAME}_p${LITERAL_ITER})")
if( ${LITERAL_ITER} LESS ${LAST_LITERAL_ITER})
set( outCppTextStdString " ${outCppTextStdString} +")
endif()
endforeach()
set( outCppTextStdString "${outCppTextStdString};")
set( outCppText
"
${outCppText}
${outCppTextStdString}
}
}
" )
@ -22,7 +57,7 @@ file(
set( outHeaderText
"namespace KIGFX {
namespace BUILTIN_SHADERS {
extern const char ${OUTVARNAME}[];
extern std::string ${OUTVARNAME};
}
}"
)