glad
glad copied to clipboard
glad2: allow custom symbol prefix (instead of glad/Glad/GLAD)
Two reasons for this change:
- Prevent symbol collisions when linking statically.
- Better integrate into the host project.
One reason against:
- Templates become very messy. Example (note the
GLAD
/Glad
/glad
prefix vars):
{{ GLAD }}_API_CALL int {{ glad }}Load{{ api|api }}{{ 'Context' if options.mx }}UserPtr({{ template_utils.context_arg(',') }} {{ GLAD }}userptrloadfunc load, void *userptr);
{{ GLAD }}_API_CALL int {{ glad }}Load{{ api|api }}{{ 'Context' if options.mx }}({{ template_utils.context_arg(',') }} {{ GLAD }}loadfunc load);
If you think it's worthwhile, I'll prepare a PR.
I think this is pretty useful but for the exact reason of not cluttering the templates even more (it's already pretty bad) I don't think this is how we should do it.
Since I was/am pretty careful with the prefixes, I think simply having a postprocessing step that replaces all glad
occurences is better (basically sed -i -e s/glad/foo/ -e s/Glad/Foo/
).
An entry point for such a feature could be here: post_generate, similar to _add_additional_headers (edit files instead of adding more).
If you want to prepare a PR for this, I am happy to review and merge it.
It would be great if adding a custom symbol prefix was made available in glad directly, and via the web interface.
For the time being I am using this script:
#!/bin/sh
set -e
set -x
PREFIX="Custom"
LOWERCASE=$(printf "$PREFIX" | tr '[:upper:]' '[:lower]')
UPPERCASE=$(printf "$PREFIX" | tr '[:lower:]' '[:upper:]')
# the negative match on '_' in the regexes below is to be able to run the
# script multiple times avoiding to add the custom prefix each time.
#
# https://xkcd.com/208/ I guess
sed \
-e "s/^GLAD_/${UPPERCASE}_GLAD_/g" \
-e "s/\\([^_]\\)GLAD_/\\1${UPPERCASE}_GLAD_/g" \
-e "s/\\([^_]\\)glad_/\\1${LOWERCASE}_glad_/g" \
-e "/${UPPERCASE}GLAD/! s/GLAD\\([a-z]\\)/${UPPERCASE}GLAD\\1/g" \
-e "s/\\([^_]\\)glad\\([A-Z]\\)/\\1${LOWERCASE}Glad\\2/g" \
-i include/glad/egl.h include/glad/gl.h src/gl.c src/egl.c
Thanks for sharing!
The main reason it isn't in glad is simply it makes the already horrible templating code even worse.