Dav1dde / glad

Multi-Language Vulkan/GL/GLES/EGL/GLX/WGL Loader-Generator based on the official specs.
https://glad.dav1d.de/
Other
3.73k stars 440 forks source link

glad2: allow custom symbol prefix (instead of glad/Glad/GLAD) #198

Open nnemkin opened 5 years ago

nnemkin commented 5 years ago

Two reasons for this change:

One reason against:

Dav1dde commented 5 years ago

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.

ao2 commented 2 years ago

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
Dav1dde commented 2 years ago

Thanks for sharing!

The main reason it isn't in glad is simply it makes the already horrible templating code even worse.