ALL: moved shader sources out of data into src
parent
788fab9c0b
commit
1cabb0c2da
|
@ -108,6 +108,10 @@ configure_file(src/engine-config.h.in engine-config.h @ONLY)
|
|||
message(STATUS "Generate config.h in ${CMAKE_CURRENT_BINARY_DIR}")
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
# These includes are needed to let the include for IMPLICIT_DEPENDS for shaders work
|
||||
include_directories(src/modules/video/shaders)
|
||||
include_directories(src/modules/compute/shaders)
|
||||
|
||||
include_directories(src/modules)
|
||||
|
||||
add_subdirectory(contrib/libs)
|
||||
|
|
|
@ -58,22 +58,16 @@ macro(generate_shaders TARGET)
|
|||
file(WRITE ${CMAKE_BINARY_DIR}/GenerateShaderHeader${TARGET}.cmake "configure_file(\${SRC} \${DST} @ONLY)")
|
||||
foreach (_file ${files})
|
||||
set(_shaders)
|
||||
set(_lastdir)
|
||||
foreach (shader_dir "${TARGET}" shared)
|
||||
set(_dir ${ROOT_DIR}/${GAME_BASE_DIR}/${shader_dir}/shaders)
|
||||
if (EXISTS ${_dir}/${_file}.frag AND EXISTS ${_dir}/${_file}.vert)
|
||||
list(APPEND _shaders ${_dir}/${_file}.frag ${_dir}/${_file}.vert)
|
||||
set(_lastdir ${_dir})
|
||||
endif()
|
||||
set(_dir ${CMAKE_CURRENT_SOURCE_DIR}/shaders)
|
||||
if (EXISTS ${_dir}/${_file}.frag AND EXISTS ${_dir}/${_file}.vert)
|
||||
list(APPEND _shaders ${_dir}/${_file}.frag ${_dir}/${_file}.vert)
|
||||
if (EXISTS ${_dir}/${_file}.geom)
|
||||
list(APPEND _shaders ${_dir}/${_file}.geom)
|
||||
set(_lastdir ${_dir})
|
||||
endif()
|
||||
if (EXISTS ${_dir}/${_file}.comp)
|
||||
list(APPEND _shaders ${_dir}/${_file}.comp)
|
||||
set(_lastdir ${_dir})
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
if (EXISTS ${_dir}/${_file}.comp)
|
||||
list(APPEND _shaders ${_dir}/${_file}.comp)
|
||||
endif()
|
||||
if (_shaders)
|
||||
convert_to_camel_case(${_file} _f)
|
||||
set(_shaderfile "${_f}Shader.h")
|
||||
|
@ -82,11 +76,15 @@ macro(generate_shaders TARGET)
|
|||
OUTPUT ${_shader}.in
|
||||
IMPLICIT_DEPENDS C ${_shaders}
|
||||
COMMENT "Validate ${_file} and generate ${_shaderfile}"
|
||||
COMMAND ${CMAKE_BINARY_DIR}/shadertool --glslang ${CMAKE_BINARY_DIR}/glslangValidator -I ${CMAKE_CURRENT_SOURCE_DIR} --postfix .in --shader ${_lastdir}/${_file} --shadertemplate ${_template} --buffertemplate ${_template_ub} --sourcedir ${GEN_DIR}
|
||||
COMMAND ${CMAKE_BINARY_DIR}/shadertool --glslang ${CMAKE_BINARY_DIR}/glslangValidator -I ${_dir} -I ${PROJECT_SOURCE_DIR}/src/modules/video/shaders --postfix .in --shader ${_dir}/${_file} --shadertemplate ${_template} --buffertemplate ${_template_ub} --sourcedir ${GEN_DIR}
|
||||
DEPENDS shadertool ${_shaders} ${_template} ${_template_ub}
|
||||
)
|
||||
list(APPEND _headers ${_shader})
|
||||
add_custom_command(OUTPUT ${_shader} COMMAND ${CMAKE_COMMAND} -D SRC=${_shader}.in -D DST=${_shader} -P ${CMAKE_BINARY_DIR}/GenerateShaderHeader${TARGET}.cmake DEPENDS ${_shader}.in)
|
||||
add_custom_command(
|
||||
OUTPUT ${_shader}
|
||||
COMMAND ${CMAKE_COMMAND} -D SRC=${_shader}.in -D DST=${_shader} -P ${CMAKE_BINARY_DIR}/GenerateShaderHeader${TARGET}.cmake
|
||||
DEPENDS ${_shader}.in
|
||||
)
|
||||
else()
|
||||
message(FATAL_ERROR "Could not find any shader files for ${_file} and target '${TARGET}'")
|
||||
endif()
|
||||
|
@ -122,14 +120,10 @@ macro(generate_compute_shaders TARGET)
|
|||
file(WRITE ${CMAKE_BINARY_DIR}/GenerateComputeShaderHeader${TARGET}.cmake "configure_file(\${SRC} \${DST} @ONLY)")
|
||||
foreach (_file ${files})
|
||||
set(_shaders)
|
||||
set(_lastdir)
|
||||
foreach (shader_dir "${TARGET}" shared)
|
||||
set(_dir ${ROOT_DIR}/${GAME_BASE_DIR}/${shader_dir}/shaders)
|
||||
if (EXISTS ${_dir}/${_file}.cl)
|
||||
list(APPEND _shaders ${_dir}/${_file}.cl)
|
||||
set(_lastdir ${_dir})
|
||||
endif()
|
||||
endforeach()
|
||||
set(_dir ${CMAKE_CURRENT_SOURCE_DIR}/shaders)
|
||||
if (EXISTS ${_dir}/${_file}.cl)
|
||||
list(APPEND _shaders ${_dir}/${_file}.cl)
|
||||
endif()
|
||||
if (_shaders)
|
||||
convert_to_camel_case(${_file} _f)
|
||||
set(_shaderfile "${_f}Shader.h")
|
||||
|
@ -138,11 +132,16 @@ macro(generate_compute_shaders TARGET)
|
|||
OUTPUT ${_shader}.in
|
||||
IMPLICIT_DEPENDS C ${_shaders}
|
||||
COMMENT "Validate ${_file} and generate ${_shaderfile}"
|
||||
COMMAND ${CMAKE_BINARY_DIR}/computeshadertool --shader ${_lastdir}/${_file} -I ${CMAKE_CURRENT_SOURCE_DIR} --postfix .in --shadertemplate ${_template} --sourcedir ${GEN_DIR}
|
||||
COMMAND ${CMAKE_BINARY_DIR}/computeshadertool --shader ${_dir}/${_file} -I ${_dir} -I ${PROJECT_SOURCE_DIR}/src/modules/compute/shaders --postfix .in --shadertemplate ${_template} --sourcedir ${GEN_DIR}
|
||||
DEPENDS computeshadertool ${_shaders} ${_template}
|
||||
VERBATIM
|
||||
)
|
||||
list(APPEND _headers ${_shader})
|
||||
add_custom_command(OUTPUT ${_shader} COMMAND ${CMAKE_COMMAND} -D SRC=${_shader}.in -D DST=${_shader} -P ${CMAKE_BINARY_DIR}/GenerateComputeShaderHeader${TARGET}.cmake DEPENDS ${_shader}.in)
|
||||
add_custom_command(
|
||||
OUTPUT ${_shader}
|
||||
COMMAND ${CMAKE_COMMAND} -D SRC=${_shader}.in -D DST=${_shader} -P ${CMAKE_BINARY_DIR}/GenerateComputeShaderHeader${TARGET}.cmake
|
||||
DEPENDS ${_shader}.in
|
||||
)
|
||||
else()
|
||||
message(FATAL_ERROR "Could not find any shader files for ${_file} and target '${TARGET}'")
|
||||
endif()
|
||||
|
|
|
@ -334,6 +334,9 @@ AppState App::onInit() {
|
|||
// already handled
|
||||
continue;
|
||||
}
|
||||
if (Command::getCommand(command) == nullptr) {
|
||||
continue;
|
||||
}
|
||||
std::string args;
|
||||
args.reserve(256);
|
||||
for (++i; i < _argc;) {
|
||||
|
|
|
@ -2,6 +2,8 @@ set(SRCS
|
|||
Simplex.h
|
||||
Noise.h Noise.cpp
|
||||
PoissonDiskDistribution.h PoissonDiskDistribution.cpp
|
||||
|
||||
shaders/noise.cl
|
||||
)
|
||||
# TODO: maybe provide two noise modules, one noisefast (for e.g. client only stuff) and one noise-slow for stuff that must be cross plattform
|
||||
|
||||
|
|
|
@ -8,9 +8,18 @@ set(SRCS
|
|||
ShapeRenderer.cpp ShapeRenderer.h
|
||||
TextureRenderer.cpp TextureRenderer.h
|
||||
)
|
||||
|
||||
set(SRCS_SHADERS
|
||||
shaders/color_instanced.vert shaders/color_instanced.frag
|
||||
shaders/color.vert shaders/color.frag
|
||||
shaders/mesh.vert shaders/mesh.frag
|
||||
shaders/shadowmap_instanced.vert shaders/shadowmap_instanced.frag
|
||||
shaders/shadowmap_render.vert shaders/shadowmap_render.frag
|
||||
shaders/shadowmap.vert shaders/shadowmap.frag
|
||||
shaders/texture.vert shaders/texture.frag
|
||||
)
|
||||
#set_source_files_properties(${SRCS_SHADERS} PROPERTIES LANGUAGE C)
|
||||
set(LIB render)
|
||||
add_library(${LIB} ${SRCS})
|
||||
add_library(${LIB} ${SRCS} ${SRCS_SHADERS})
|
||||
generate_shaders(${LIB} mesh shadowmap shadowmap_instanced shadowmap_render color color_instanced texture)
|
||||
engine_target_link_libraries(TARGET ${LIB} DEPENDENCIES video noise)
|
||||
set_target_properties(${LIB} PROPERTIES FOLDER ${LIB})
|
||||
|
|
|
@ -36,12 +36,17 @@ set(SRCS
|
|||
ScopedPolygonMode.h
|
||||
StencilConfig.h StencilConfig.cpp
|
||||
)
|
||||
set(SRCS_SHADERS
|
||||
shaders/_fog.vert shaders/_fog.frag
|
||||
shaders/_fullscreen.vert
|
||||
shaders/_shadowmap.vert shaders/_shadowmap.frag
|
||||
)
|
||||
#set_source_files_properties(${SRCS_SHADERS} PROPERTIES LANGUAGE C)
|
||||
set(LIB video)
|
||||
find_package(OpenGL)
|
||||
add_library(${LIB} ${SRCS})
|
||||
add_library(${LIB} ${SRCS} ${SRCS_SHADERS})
|
||||
engine_target_link_libraries(TARGET ${LIB} DEPENDENCIES core math image util assimp zlib)
|
||||
set_target_properties(${LIB} PROPERTIES FOLDER ${LIB})
|
||||
target_include_directories(${LIB} PUBLIC ${OPENGL_INCLUDE_DIRS})
|
||||
|
||||
gtest_suite_files(tests
|
||||
tests/AbstractGLTest.h
|
||||
|
|
|
@ -96,6 +96,9 @@ void Shader::shutdown() {
|
|||
}
|
||||
|
||||
bool Shader::load(const std::string& name, const std::string& buffer, ShaderType shaderType) {
|
||||
if (buffer.empty()) {
|
||||
return false;
|
||||
}
|
||||
_name = name;
|
||||
const std::string& source = getSource(shaderType, buffer);
|
||||
|
||||
|
@ -123,7 +126,6 @@ bool Shader::loadFromFile(const std::string& filename, ShaderType shaderType) {
|
|||
}
|
||||
|
||||
bool Shader::loadProgram(const std::string& filename) {
|
||||
video::checkError();
|
||||
const bool vertex = loadFromFile(filename + VERTEX_POSTFIX, ShaderType::Vertex);
|
||||
if (!vertex) {
|
||||
const bool compute = loadFromFile(filename + COMPUTE_POSTFIX, ShaderType::Compute);
|
||||
|
@ -140,7 +142,6 @@ bool Shader::loadProgram(const std::string& filename) {
|
|||
loadFromFile(filename + GEOMETRY_POSTFIX, ShaderType::Geometry);
|
||||
}
|
||||
_name = filename;
|
||||
video::checkError();
|
||||
return init();
|
||||
}
|
||||
|
||||
|
@ -150,7 +151,6 @@ bool Shader::reload() {
|
|||
}
|
||||
|
||||
bool Shader::init() {
|
||||
video::checkError();
|
||||
createProgramFromShaders();
|
||||
const bool success = _program != InvalidId;
|
||||
_initialized = success;
|
||||
|
|
|
@ -6,9 +6,14 @@ set(SRCS
|
|||
ShaderAttribute.h
|
||||
WorldRenderer.h WorldRenderer.cpp
|
||||
)
|
||||
set(SRCS_SHADERS
|
||||
shaders/water.vert shaders/water.frag
|
||||
shaders/world_instanced.vert shaders/world_instanced.frag
|
||||
shaders/world.vert shaders/world.frag
|
||||
)
|
||||
|
||||
set(LIB voxelrender)
|
||||
add_library(${LIB} ${SRCS})
|
||||
add_library(${LIB} ${SRCS} ${SRCS_SHADERS})
|
||||
generate_shaders(${LIB} world water world_instanced)
|
||||
engine_target_link_libraries(TARGET ${LIB} DEPENDENCIES frontend render voxel)
|
||||
set_target_properties(${LIB} PROPERTIES FOLDER ${LIB})
|
||||
|
|
|
@ -3,5 +3,5 @@ set(SRCS
|
|||
TestTemplate.h TestTemplate.cpp
|
||||
)
|
||||
engine_add_executable(TARGET ${PROJECT_NAME} SRCS ${SRCS} WINDOWED NOINSTALL)
|
||||
engine_target_link_libraries(TARGET ${PROJECT_NAME} DEPENDENCIES testcore imgui)
|
||||
engine_target_link_libraries(TARGET ${PROJECT_NAME} DEPENDENCIES testcore)
|
||||
#generate_shaders(${PROJECT_NAME} testtemplate)
|
||||
|
|
|
@ -14,6 +14,10 @@
|
|||
|
||||
namespace $namespace$ {
|
||||
|
||||
namespace priv$name$ {
|
||||
static const char* ShaderBuffer = R"($shaderbuffer$)";
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Compute shader wrapper for @c $filename$
|
||||
* @ingroup Compute
|
||||
|
@ -43,7 +47,7 @@ $structs$
|
|||
if (!init()) {
|
||||
return false;
|
||||
}
|
||||
if (!loadProgram("$filename$")) {
|
||||
if (!load("$filename$", priv$name$::ShaderBuffer)) {
|
||||
return false;
|
||||
}
|
||||
$createkernels$
|
||||
|
|
|
@ -99,7 +99,7 @@ core::AppState ComputeShaderTool::onRunning() {
|
|||
return core::AppState::Cleanup;
|
||||
}
|
||||
const std::string& templateShader = filesystem()->load(_shaderTemplateFile);
|
||||
if (!computeshadertool::generateSrc(filesystem(), templateShader, _name, _namespaceSrc, _shaderDirectory, _sourceDirectory, _kernels, _structs, _constants, _postfix)) {
|
||||
if (!computeshadertool::generateSrc(filesystem(), templateShader, _name, _namespaceSrc, _shaderDirectory, _sourceDirectory, _kernels, _structs, _constants, _postfix, computeBuffer)) {
|
||||
_exitCode = 100;
|
||||
return core::AppState::Cleanup;
|
||||
}
|
||||
|
|
|
@ -216,7 +216,8 @@ bool generateSrc(const io::FilesystemPtr& filesystem,
|
|||
const std::vector<Kernel>& _kernels,
|
||||
const std::vector<Struct>& _structs,
|
||||
const std::map<std::string, std::string>& _constants,
|
||||
const std::string& postfix) {
|
||||
const std::string& postfix,
|
||||
const std::string& shaderBuffer) {
|
||||
const std::string name = _name + "Shader";
|
||||
|
||||
std::vector<std::string> shaderNameParts;
|
||||
|
@ -279,6 +280,7 @@ bool generateSrc(const io::FilesystemPtr& filesystem,
|
|||
src = core::string::replaceAll(src, "$shutdown$", shutdown.str());
|
||||
src = core::string::replaceAll(src, "$structs$", structs.str());
|
||||
src = core::string::replaceAll(src, "$createkernels$", createKernels.str());
|
||||
src = core::string::replaceAll(src, "$shaderbuffer$", shaderBuffer);
|
||||
const std::string targetFile = sourceDirectory + filename + ".h" + postfix;
|
||||
Log::info("Generate shader bindings for %s at %s", _name.c_str(), targetFile.c_str());
|
||||
if (!filesystem->syswrite(targetFile, src)) {
|
||||
|
|
|
@ -21,6 +21,7 @@ extern bool generateSrc(const io::FilesystemPtr& filesystem,
|
|||
const std::vector<Kernel>& kernels,
|
||||
const std::vector<Struct>& structs,
|
||||
const std::map<std::string, std::string>& constants,
|
||||
const std::string& postfix);
|
||||
const std::string& postfix,
|
||||
const std::string& shaderBuffer);
|
||||
|
||||
}
|
||||
|
|
|
@ -32,7 +32,8 @@ static const char *convertToTexUnit(int unit) {
|
|||
}
|
||||
|
||||
bool generateSrc(const std::string& templateShader, const std::string& templateUniformBuffer, const ShaderStruct& shaderStruct,
|
||||
const io::FilesystemPtr& filesystem, const std::string& namespaceSrc, const std::string& sourceDirectory, const std::string& shaderDirectory, const std::string& postfix) {
|
||||
const io::FilesystemPtr& filesystem, const std::string& namespaceSrc, const std::string& sourceDirectory, const std::string& shaderDirectory, const std::string& postfix,
|
||||
const std::string& vertexBuffer, const std::string& geometryBuffer, const std::string& fragmentBuffer, const std::string& computeBuffer) {
|
||||
std::string src(templateShader);
|
||||
const std::string& name = shaderStruct.name + "Shader";
|
||||
|
||||
|
@ -430,6 +431,11 @@ bool generateSrc(const std::string& templateShader, const std::string& templateU
|
|||
src = core::string::replaceAll(src, "$methods$", methods.str());
|
||||
src = core::string::replaceAll(src, "$includes$", includes.str());
|
||||
|
||||
src = core::string::replaceAll(src, "$vertexshaderbuffer$", vertexBuffer);
|
||||
src = core::string::replaceAll(src, "$computeshaderbuffer$", computeBuffer);
|
||||
src = core::string::replaceAll(src, "$fragmentshaderbuffer$", fragmentBuffer);
|
||||
src = core::string::replaceAll(src, "$geometryshaderbuffer$", geometryBuffer);
|
||||
|
||||
const std::string targetFile = sourceDirectory + filename + ".h" + postfix;
|
||||
Log::debug("Generate shader bindings for %s at %s", shaderStruct.name.c_str(), targetFile.c_str());
|
||||
if (!filesystem->syswrite(targetFile, src)) {
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
namespace shadertool {
|
||||
|
||||
extern bool generateSrc(const std::string& templateShader, const std::string& templateUniformBuffer, const ShaderStruct& shaderStruct,
|
||||
const io::FilesystemPtr& filesystem, const std::string& namespaceSrc, const std::string& sourceDirectory, const std::string& shaderDirectory, const std::string& postfix);
|
||||
const io::FilesystemPtr& filesystem, const std::string& namespaceSrc, const std::string& sourceDirectory, const std::string& shaderDirectory, const std::string& postfix,
|
||||
const std::string& vertexBuffer, const std::string& geometryBuffer, const std::string& fragmentBuffer, const std::string& computeBuffer);
|
||||
|
||||
}
|
||||
|
|
|
@ -14,6 +14,15 @@ $includes$
|
|||
|
||||
namespace $namespace$ {
|
||||
|
||||
namespace priv$name$ {
|
||||
|
||||
static const char* VertexShaderBuffer = R"($vertexshaderbuffer$)";
|
||||
static const char* ComputeShaderBuffer = R"($computeshaderbuffer$)";
|
||||
static const char* FragmentShaderBuffer = R"($fragmentshaderbuffer$)";
|
||||
static const char* GeometryShaderBuffer = R"($geometryshaderbuffer$)";
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup Video
|
||||
* @brief Shader wrapper for $filename$
|
||||
|
@ -39,7 +48,22 @@ public:
|
|||
if (_initialized) {
|
||||
return true;
|
||||
}
|
||||
if (!loadProgram("$filename$")) {
|
||||
const bool vertex = load("$filename$", priv$name$::VertexShaderBuffer, video::ShaderType::Vertex);
|
||||
if (!vertex) {
|
||||
const bool compute = load("$filename$", priv$name$::ComputeShaderBuffer, video::ShaderType::Compute);
|
||||
if (!compute) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
const bool fragment = load("$filename$", priv$name$::FragmentShaderBuffer, video::ShaderType::Fragment);
|
||||
if (!fragment) {
|
||||
return false;
|
||||
}
|
||||
// optional
|
||||
load("$filename$", priv$name$::GeometryShaderBuffer, video::ShaderType::Geometry);
|
||||
}
|
||||
_name = "$filename$";
|
||||
if (!init()) {
|
||||
return false;
|
||||
}
|
||||
$attributes$
|
||||
|
|
|
@ -169,7 +169,8 @@ core::AppState ShaderTool::onRunning() {
|
|||
}
|
||||
|
||||
if (!shadertool::generateSrc(templateShader, templateUniformBuffer, _shaderStruct,
|
||||
filesystem(), _namespaceSrc, _sourceDirectory, _shaderDirectory, _postfix)) {
|
||||
filesystem(), _namespaceSrc, _sourceDirectory, _shaderDirectory, _postfix,
|
||||
"", "", "", computeBuffer)) {
|
||||
Log::error("Failed to generate shader source for %s", _shaderfile.c_str());
|
||||
_exitCode = 1;
|
||||
return core::AppState::Cleanup;
|
||||
|
@ -230,7 +231,8 @@ core::AppState ShaderTool::onRunning() {
|
|||
}
|
||||
|
||||
if (!shadertool::generateSrc(templateShader, templateUniformBuffer, _shaderStruct,
|
||||
filesystem(), _namespaceSrc, _sourceDirectory, _shaderDirectory, _postfix)) {
|
||||
filesystem(), _namespaceSrc, _sourceDirectory, _shaderDirectory, _postfix,
|
||||
vertexBuffer, geometryBuffer, fragmentBuffer, computeBuffer)) {
|
||||
Log::error("Failed to generate shader source for %s", _shaderfile.c_str());
|
||||
_exitCode = 1;
|
||||
return core::AppState::Cleanup;
|
||||
|
|
Loading…
Reference in New Issue