Skip to content

Commit

Permalink
Move GLSL Resources generation to a separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
congard committed Jul 7, 2024
1 parent 16915dc commit d936bf1
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 86 deletions.
89 changes: 3 additions & 86 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,92 +65,9 @@ endif()

include(cmake/deps.cmake)

# built-in glsl modules
# TODO: move to another file
file(READ src/common/core/glsl-modules/BoneSystem.glsl GLSLModules_BoneSystem)
file(READ src/common/core/glsl-modules/NormalMapping.vs.glsl GLSLModules_NormalMapping_vs)
file(READ src/common/core/glsl-modules/NormalMapping.fs.glsl GLSLModules_NormalMapping_fs)
file(READ src/common/core/glsl-modules/SSR.glsl GLSLModules_SSR)

file(READ src/common/core/glsl-modules/fresnel.glsl GLSLModules_fresnel)

file(READ src/common/core/glsl-modules/ToneMapping/all.glsl GLSLModules_ToneMapping_all)
file(READ src/common/core/glsl-modules/ToneMapping/aces.glsl GLSLModules_ToneMapping_aces)
file(READ src/common/core/glsl-modules/ToneMapping/exposure.glsl GLSLModules_ToneMapping_exposure)
file(READ src/common/core/glsl-modules/ToneMapping/filmic.glsl GLSLModules_ToneMapping_filmic)
file(READ src/common/core/glsl-modules/ToneMapping/lottes.glsl GLSLModules_ToneMapping_lottes)
file(READ src/common/core/glsl-modules/ToneMapping/reinhard.glsl GLSLModules_ToneMapping_reinhard)
file(READ src/common/core/glsl-modules/ToneMapping/reinhard2.glsl GLSLModules_ToneMapping_reinhard2)
file(READ src/common/core/glsl-modules/ToneMapping/uchimura.glsl GLSLModules_ToneMapping_uchimura)
file(READ src/common/core/glsl-modules/ToneMapping/uncharted2.glsl GLSLModules_ToneMapping_uncharted2)
file(READ src/common/core/glsl-modules/ToneMapping/unreal.glsl GLSLModules_ToneMapping_unreal)

file(READ src/common/core/glsl-modules/Blending/all.glsl GLSLModules_Blending_all)
file(READ src/common/core/glsl-modules/Blending/add.glsl GLSLModules_Blending_add)
file(READ src/common/core/glsl-modules/Blending/average.glsl GLSLModules_Blending_average)
file(READ src/common/core/glsl-modules/Blending/color-burn.glsl GLSLModules_Blending_color_burn)
file(READ src/common/core/glsl-modules/Blending/color-dodge.glsl GLSLModules_Blending_color_dodge)
file(READ src/common/core/glsl-modules/Blending/darken.glsl GLSLModules_Blending_darken)
file(READ src/common/core/glsl-modules/Blending/difference.glsl GLSLModules_Blending_difference)
file(READ src/common/core/glsl-modules/Blending/exclusion.glsl GLSLModules_Blending_exclusion)
file(READ src/common/core/glsl-modules/Blending/glow.glsl GLSLModules_Blending_glow)
file(READ src/common/core/glsl-modules/Blending/hard-light.glsl GLSLModules_Blending_hard_light)
file(READ src/common/core/glsl-modules/Blending/hard-mix.glsl GLSLModules_Blending_hard_mix)
file(READ src/common/core/glsl-modules/Blending/lighten.glsl GLSLModules_Blending_lighten)
file(READ src/common/core/glsl-modules/Blending/linear-burn.glsl GLSLModules_Blending_linear_burn)
file(READ src/common/core/glsl-modules/Blending/linear-dodge.glsl GLSLModules_Blending_linear_dodge)
file(READ src/common/core/glsl-modules/Blending/linear-light.glsl GLSLModules_Blending_linear_light)
file(READ src/common/core/glsl-modules/Blending/multiply.glsl GLSLModules_Blending_multiply)
file(READ src/common/core/glsl-modules/Blending/negation.glsl GLSLModules_Blending_negation)
file(READ src/common/core/glsl-modules/Blending/normal.glsl GLSLModules_Blending_normal)
file(READ src/common/core/glsl-modules/Blending/overlay.glsl GLSLModules_Blending_overlay)
file(READ src/common/core/glsl-modules/Blending/phoenix.glsl GLSLModules_Blending_phoenix)
file(READ src/common/core/glsl-modules/Blending/pin-light.glsl GLSLModules_Blending_pin_light)
file(READ src/common/core/glsl-modules/Blending/reflect.glsl GLSLModules_Blending_reflect)
file(READ src/common/core/glsl-modules/Blending/screen.glsl GLSLModules_Blending_screen)
file(READ src/common/core/glsl-modules/Blending/soft-light.glsl GLSLModules_Blending_soft_light)
file(READ src/common/core/glsl-modules/Blending/subtract.glsl GLSLModules_Blending_subtract)
file(READ src/common/core/glsl-modules/Blending/vivid-light.glsl GLSLModules_Blending_vivid_light)

file(READ src/common/core/glsl-modules/Shading/all.glsl GLSLModules_Shading_all)
file(READ src/common/core/glsl-modules/Shading/attenuation.glsl GLSLModules_Shading_attenuation)
file(READ src/common/core/glsl-modules/Shading/diffuseLambert.glsl GLSLModules_Shading_diffuseLambert)
file(READ src/common/core/glsl-modules/Shading/diffuseOrenNayar.glsl GLSLModules_Shading_diffuseOrenNayar)
file(READ src/common/core/glsl-modules/Shading/specularAnisotropic.glsl GLSLModules_Shading_specularAnisotropic)
file(READ src/common/core/glsl-modules/Shading/specularBlinnPhong.glsl GLSLModules_Shading_specularBlinnPhong)
file(READ src/common/core/glsl-modules/Shading/specularCookTorrance.glsl GLSLModules_Shading_specularCookTorrance)
file(READ src/common/core/glsl-modules/Shading/specularPhong.glsl GLSLModules_Shading_specularPhong)
file(READ src/common/core/glsl-modules/Shading/dirLightShadow.glsl GLSLModules_Shading_dirLightShadow)
file(READ src/common/core/glsl-modules/Shading/pointLightShadow.glsl GLSLModules_Shading_pointLightShadow)

file(READ src/common/core/glsl-modules/DOF/all.glsl GLSLModules_DOF_all)
file(READ src/common/core/glsl-modules/DOF/cinematicCoC.glsl GLSLModules_DOF_cinematicCoC)
file(READ src/common/core/glsl-modules/DOF/linearCoC.glsl GLSLModules_DOF_linearCoC)

file(READ src/common/core/glsl-modules/Luminance/all.glsl GLSLModules_Luminance_all)
file(READ src/common/core/glsl-modules/Luminance/luminance.glsl GLSLModules_Luminance_luminance)
file(READ src/common/core/glsl-modules/Luminance/luminanceHSP.glsl GLSLModules_Luminance_luminanceHSP)
file(READ src/common/core/glsl-modules/Luminance/luminanceW3.glsl GLSLModules_Luminance_luminanceW3)

configure_file(src/common/core/glsl-modules/GLSLModules.h.in src/common/core/glsl-modules/GLSLModules.h)

# built-in glsl shaders
file(READ src/common/core/glsl-shaders/Blur.fs.glsl GLSLShaders_Blur_fs)
file(READ src/common/core/glsl-shaders/Quad.vs.glsl GLSLShaders_Quad_vs)
file(READ src/common/core/glsl-shaders/Shadow.fs.glsl GLSLShaders_Shadow_fs)
file(READ src/common/core/glsl-shaders/Shadow.gs.glsl GLSLShaders_Shadow_gs)
file(READ src/common/core/glsl-shaders/Shadow.vs.glsl GLSLShaders_Shadow_vs)

configure_file(src/common/core/glsl-shaders/GLSLShaders.h.in src/common/core/glsl-shaders/GLSLShaders.h)

# painter shaders
file(READ src/common/core/painter/painter.vs.glsl Painter_painter_vs)
file(READ src/common/core/painter/fill.fs.glsl Painter_fill_fs)
file(READ src/common/core/painter/circle-fill.fs.glsl Painter_circle_fill_fs)
file(READ src/common/core/painter/roundRect-fill.fs.glsl Painter_round_rect_fill_fs)
file(READ src/common/core/painter/text-fill.fs.glsl Painter_text_fill_fs)

configure_file(src/common/core/painter/PainterShaders.h.in src/common/core/painter/PainterShaders.h)
# pack built-in glsl resources
include(cmake/GLSLResources.cmake)
glsl_pack_all()

# lua
function(build_lua_interp out_binary)
Expand Down
138 changes: 138 additions & 0 deletions cmake/GLSLResources.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# Reads files to variables.
# BASEDIR: The directory files located in
# PAIRS: [file0 out-var0 file1 out-var1 ...]
macro(_glsl_read)
cmake_parse_arguments(
ARG # prefix of output variables
"" # list of names of the boolean arguments (only defined ones will be true)
"BASEDIR" # list of names of mono-valued arguments
"PAIRS" # list of names of multi-valued arguments (output variables are lists)
${ARGN} # arguments of the function to parse, here we take the all original ones
)

if (NOT ARG_BASEDIR)
set(ARG_BASEDIR "")
else()
set(ARG_BASEDIR "${ARG_BASEDIR}/")
endif()

list(LENGTH ARG_PAIRS PAIRS_LEN)

MATH(EXPR RANGE_END "${PAIRS_LEN}-1")

foreach(i RANGE 0 ${RANGE_END} 2)
list(GET ARG_PAIRS ${i} file)

MATH(EXPR i "${i}+1")
list(GET ARG_PAIRS ${i} varname)

file(READ "${ARG_BASEDIR}${file}" "${varname}")
endforeach()
endmacro()

# built-in glsl modules
function(glsl_pack_modules)
set(MDIR "src/common/core/glsl-modules")

_glsl_read(BASEDIR "${MDIR}" PAIRS
"BoneSystem.glsl" GLSLModules_BoneSystem
"NormalMapping.vs.glsl" GLSLModules_NormalMapping_vs
"NormalMapping.fs.glsl" GLSLModules_NormalMapping_fs
"SSR.glsl" GLSLModules_SSR

"fresnel.glsl" GLSLModules_fresnel

"ToneMapping/all.glsl" GLSLModules_ToneMapping_all
"ToneMapping/aces.glsl" GLSLModules_ToneMapping_aces
"ToneMapping/exposure.glsl" GLSLModules_ToneMapping_exposure
"ToneMapping/filmic.glsl" GLSLModules_ToneMapping_filmic
"ToneMapping/lottes.glsl" GLSLModules_ToneMapping_lottes
"ToneMapping/reinhard.glsl" GLSLModules_ToneMapping_reinhard
"ToneMapping/reinhard2.glsl" GLSLModules_ToneMapping_reinhard2
"ToneMapping/uchimura.glsl" GLSLModules_ToneMapping_uchimura
"ToneMapping/uncharted2.glsl" GLSLModules_ToneMapping_uncharted2
"ToneMapping/unreal.glsl" GLSLModules_ToneMapping_unreal

"Blending/all.glsl" GLSLModules_Blending_all
"Blending/add.glsl" GLSLModules_Blending_add
"Blending/average.glsl" GLSLModules_Blending_average
"Blending/color-burn.glsl" GLSLModules_Blending_color_burn
"Blending/color-dodge.glsl" GLSLModules_Blending_color_dodge
"Blending/darken.glsl" GLSLModules_Blending_darken
"Blending/difference.glsl" GLSLModules_Blending_difference
"Blending/exclusion.glsl" GLSLModules_Blending_exclusion
"Blending/glow.glsl" GLSLModules_Blending_glow
"Blending/hard-light.glsl" GLSLModules_Blending_hard_light
"Blending/hard-mix.glsl" GLSLModules_Blending_hard_mix
"Blending/lighten.glsl" GLSLModules_Blending_lighten
"Blending/linear-burn.glsl" GLSLModules_Blending_linear_burn
"Blending/linear-dodge.glsl" GLSLModules_Blending_linear_dodge
"Blending/linear-light.glsl" GLSLModules_Blending_linear_light
"Blending/multiply.glsl" GLSLModules_Blending_multiply
"Blending/negation.glsl" GLSLModules_Blending_negation
"Blending/normal.glsl" GLSLModules_Blending_normal
"Blending/overlay.glsl" GLSLModules_Blending_overlay
"Blending/phoenix.glsl" GLSLModules_Blending_phoenix
"Blending/pin-light.glsl" GLSLModules_Blending_pin_light
"Blending/reflect.glsl" GLSLModules_Blending_reflect
"Blending/screen.glsl" GLSLModules_Blending_screen
"Blending/soft-light.glsl" GLSLModules_Blending_soft_light
"Blending/subtract.glsl" GLSLModules_Blending_subtract
"Blending/vivid-light.glsl" GLSLModules_Blending_vivid_light

"Shading/all.glsl" GLSLModules_Shading_all
"Shading/attenuation.glsl" GLSLModules_Shading_attenuation
"Shading/diffuseLambert.glsl" GLSLModules_Shading_diffuseLambert
"Shading/diffuseOrenNayar.glsl" GLSLModules_Shading_diffuseOrenNayar
"Shading/specularAnisotropic.glsl" GLSLModules_Shading_specularAnisotropic
"Shading/specularBlinnPhong.glsl" GLSLModules_Shading_specularBlinnPhong
"Shading/specularCookTorrance.glsl" GLSLModules_Shading_specularCookTorrance
"Shading/specularPhong.glsl" GLSLModules_Shading_specularPhong
"Shading/dirLightShadow.glsl" GLSLModules_Shading_dirLightShadow
"Shading/pointLightShadow.glsl" GLSLModules_Shading_pointLightShadow

"DOF/all.glsl" GLSLModules_DOF_all
"DOF/cinematicCoC.glsl" GLSLModules_DOF_cinematicCoC
"DOF/linearCoC.glsl" GLSLModules_DOF_linearCoC

"Luminance/all.glsl" GLSLModules_Luminance_all
"Luminance/luminance.glsl" GLSLModules_Luminance_luminance
"Luminance/luminanceHSP.glsl" GLSLModules_Luminance_luminanceHSP
"Luminance/luminanceW3.glsl" GLSLModules_Luminance_luminanceW3)

configure_file("${MDIR}/GLSLModules.h.in" "${MDIR}/GLSLModules.h")
endfunction()

# built-in glsl shaders
function(glsl_pack_shaders)
set(SDIR "src/common/core/glsl-shaders")

_glsl_read(BASEDIR "${SDIR}" PAIRS
"Blur.fs.glsl" GLSLShaders_Blur_fs
"Quad.vs.glsl" GLSLShaders_Quad_vs
"Shadow.fs.glsl" GLSLShaders_Shadow_fs
"Shadow.gs.glsl" GLSLShaders_Shadow_gs
"Shadow.vs.glsl" GLSLShaders_Shadow_vs)

configure_file("${SDIR}/GLSLShaders.h.in" "${SDIR}/GLSLShaders.h")
endfunction()

# painter-related shaders
function(glsl_pack_painter_shaders)
set(PDIR "src/common/core/painter")

_glsl_read(BASEDIR "${PDIR}" PAIRS
"painter.vs.glsl" Painter_painter_vs
"fill.fs.glsl" Painter_fill_fs
"circle-fill.fs.glsl" Painter_circle_fill_fs
"roundRect-fill.fs.glsl" Painter_round_rect_fill_fs
"text-fill.fs.glsl" Painter_text_fill_fs)

configure_file("${PDIR}/PainterShaders.h.in" "${PDIR}/PainterShaders.h")
endfunction()

function(glsl_pack_all)
glsl_pack_modules()
glsl_pack_shaders()
glsl_pack_painter_shaders()
endfunction()

0 comments on commit d936bf1

Please sign in to comment.