Skip to content

Commit

Permalink
egl: implement concatenation of client/display extensions
Browse files Browse the repository at this point in the history
Signed-off-by: Steven Noonan <[email protected]>
  • Loading branch information
tycho committed Nov 2, 2022
1 parent b15120a commit fc5c724
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions glad/generator/c/templates/egl.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
{% extends 'base_template.c' %}

{% block loader %}
static int glad_egl_get_extensions({{ template_utils.context_arg(', ') }}EGLDisplay display, const char **extensions) {
*extensions = {{ 'eglQueryString'|ctx }}(display, EGL_EXTENSIONS);
static int glad_egl_get_extensions({{ template_utils.context_arg(', ') }}EGLDisplay display, char **extensions) {
const char *clientExtensions = {{ 'eglQueryString'|ctx }}(EGL_NO_DISPLAY, EGL_EXTENSIONS);
const char *displayExtensions = (display == EGL_NO_DISPLAY) ? "" : {{ 'eglQueryString'|ctx }}(display, EGL_EXTENSIONS);

return extensions != NULL;
if (!clientExtensions) return 0;
if (!displayExtensions) return 0;

size_t clientLen = strlen(clientExtensions);
size_t displayLen = strlen(displayExtensions);

char *concat = (char *)malloc(clientLen + displayLen + 2);
if (!concat) return 0;

concat[0] = 0;
strcat(concat, clientExtensions);
if (displayLen) {
if (concat[clientLen - 1] != ' ')
strcat(concat, " ");
strcat(concat, displayExtensions);
}

*extensions = concat;

return 1;
}

static int glad_egl_has_extension(const char *extensions, const char *ext) {
Expand Down Expand Up @@ -33,7 +53,7 @@ static GLADapiproc glad_egl_get_proc_from_userptr(void *userptr, const char *nam

{% for api in feature_set.info.apis %}
static int glad_egl_find_extensions_{{ api|lower }}({{ template_utils.context_arg(', ') }}EGLDisplay display) {
const char *extensions;
char *extensions;
if (!glad_egl_get_extensions({{'context, ' if options.mx }}display, &extensions)) return 0;

{% for extension in feature_set.extensions %}
Expand All @@ -42,6 +62,8 @@ static int glad_egl_find_extensions_{{ api|lower }}({{ template_utils.context_ar
GLAD_UNUSED(glad_egl_has_extension);
{% endfor %}

free(extensions);

return 1;
}

Expand Down

0 comments on commit fc5c724

Please sign in to comment.