Paper-Cranes-Ltd / big2-stack

This is a middleware repository that eases up the work with BGFX, GLFW, IMGUI and GLM.
https://paper-cranes-ltd.github.io/big2-stack/
The Unlicense
41 stars 1 forks source link

Fix add_shaders_directory glob mask #2

Closed Razenpok closed 1 year ago

Razenpok commented 1 year ago

Current glob mask fails to detect files fs_texture.sc and vs_texture.sc

[!.def] matches the last symbol before .sc !(.def) matches the whole pattern

Before: broken

After: fixed

object71 commented 1 year ago

Hey, thanks for the suggestion. The build doesn't pass though since it doesn't match any shaders now. Can you tell me on what platform you get an invalid glob match as it seems to work on my windows pc and the linux build on github?

DylanLukes commented 1 year ago

After a bunch of debugging of a seemingly related issue, I'd run into this as well. Picks up vs_basic.sc but not vs_grid.sc (on account of the d).

DylanLukes commented 1 year ago

@Razenpok I don't believe CMake globbing expressions support parenthesized subpatterns like that.

I've just switched to:

    file(GLOB VERTEX_SHADER_FILES CONFIGURE_DEPENDS FOLLOW_SYMLINKS "${SHADERS_DIR}/vs_*.sc")
    file(GLOB FRAGMENT_SHADER_FILES CONFIGURE_DEPENDS FOLLOW_SYMLINKS "${SHADERS_DIR}/fs_*.sc")

This won't match uniforms.sh or varying.def.sc anyways.

I'm fine with the vs_ or fs_ prefix indicated embedding, but perhaps there's a little saner way. It might work to glob something like the above and then filter it out with list(FILTER <list> EXCLUDE REGEX <regex>) or something?

Or, glob the entire directory and then `list(FILTER <list> INCLUDE REGEX <regex>) to get actual full regex rather than globbing expressions.

object71 commented 1 year ago

Well thanks for pointing out the issue. I've fixed it in 10a36c5a9e164f2f55d737af0473d14d05881624 . Now I glob everything and you would have two ways of writing the shader filenames (since we still want to distinguish them somehow)

vs_texture.sc
texture.vert.sc
fs_texture.sc
texture.frag.sc

And there is also a wrong scenario: fs_wrong.vert which will be captured by both but you shouldn't do it anyway. If you want to have your own logic you can always rework or suggest a new cmake function. You could even use the ones provided by BGFX itself which are the ones I use anyway.