Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nnemkin opened this issue Feb 5, 2019 · 3 comments
Open

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

nnemkin opened this issue Feb 5, 2019 · 3 comments

Comments

@nnemkin
Copy link

nnemkin commented Feb 5, 2019

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.

@Dav1dde
Copy link
Owner

Dav1dde commented Feb 5, 2019

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.

@Dav1dde Dav1dde changed the title glad2: allow custom symbol pefix (instead of glad/Glad/GLAD) glad2: allow custom symbol prefix (instead of glad/Glad/GLAD) Jul 6, 2019
@ao2
Copy link

ao2 commented Feb 8, 2022

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
Copy link
Owner

Dav1dde commented Feb 8, 2022

Thanks for sharing!

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants