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

RFC: Add epoxy_set_resolver_failure_handler() #131

Merged
merged 1 commit into from
Sep 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions include/epoxy/gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ EPOXY_PUBLIC bool epoxy_has_gl_extension(const char *extension);
EPOXY_PUBLIC bool epoxy_is_desktop_gl(void);
EPOXY_PUBLIC int epoxy_gl_version(void);

/*
* the type of the stub function that the failure handler must return;
* this function will be called on subsequent calls to the same bogus
* function name
*/
typedef void (*epoxy_resolver_stub_t)(void);

/* the type of the failure handler itself */
typedef epoxy_resolver_stub_t
(*epoxy_resolver_failure_handler_t)(const char *name);

EPOXY_PUBLIC epoxy_resolver_failure_handler_t
epoxy_set_resolver_failure_handler(epoxy_resolver_failure_handler_t handler);

EPOXY_END_DECLS

#endif /* EPOXY_GL_H */
18 changes: 18 additions & 0 deletions src/dispatch_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -845,3 +845,21 @@ WRAPPER(epoxy_glEnd)(void)

PFNGLBEGINPROC epoxy_glBegin = epoxy_glBegin_wrapped;
PFNGLENDPROC epoxy_glEnd = epoxy_glEnd_wrapped;

epoxy_resolver_failure_handler_t epoxy_resolver_failure_handler;

epoxy_resolver_failure_handler_t
epoxy_set_resolver_failure_handler(epoxy_resolver_failure_handler_t handler)
{
#ifdef _WIN32
return InterlockedExchangePointer(&epoxy_resolver_failure_handler,
handler);
#else
epoxy_resolver_failure_handler_t old;
pthread_mutex_lock(&api.mutex);
old = epoxy_resolver_failure_handler;
epoxy_resolver_failure_handler = handler;
pthread_mutex_unlock(&api.mutex);
return old;
#endif
}
2 changes: 2 additions & 0 deletions src/dispatch_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ bool epoxy_extension_in_string(const char *extension_list, const char *ext);
extern void UNWRAPPED_PROTO(glBegin_unwrapped)(GLenum primtype);
extern void UNWRAPPED_PROTO(glEnd_unwrapped)(void);

extern epoxy_resolver_failure_handler_t epoxy_resolver_failure_handler;

#if USING_DISPATCH_TABLE
void gl_init_dispatch_table(void);
void gl_switch_to_dispatch_table(void);
Expand Down
4 changes: 4 additions & 0 deletions src/gen_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,10 @@ def write_provider_resolver(self):
self.outln(' }')
self.outln('')

self.outln(' if (epoxy_resolver_failure_handler)')
self.outln(' return epoxy_resolver_failure_handler(name);')
self.outln('')

# If the function isn't provided by any known extension, print
# something useful for the poor application developer before
# aborting. (In non-epoxy GL usage, the app developer would
Expand Down