Skip to content

Commit

Permalink
c: include loader based on API not specification, renamed callback API.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dav1dde committed Dec 20, 2017
1 parent b6c8ee9 commit 7dd9706
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 101 deletions.
1 change: 0 additions & 1 deletion example/c/simple.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <glad/glad.h>
#include <glad/glad_loader.h>
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
Expand Down
4 changes: 2 additions & 2 deletions glad/lang/c/templates/base_template.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ void _post_call_{{ feature_set.api }}_callback_default(const char *name, void *f
{% endblock %}

static GLADcallback _pre_call_{{ feature_set.api }}_callback = _pre_call_{{ feature_set.api }}_callback_default;
void glad_set_{{ feature_set.api }}_pre_callback(GLADcallback cb) {
void gladSet{{ feature_set.api }}PreCallback(GLADcallback cb) {
_pre_call_{{ feature_set.api }}_callback = cb;
}
static GLADcallback _post_call_{{ feature_set.api }}_callback = _post_call_{{ feature_set.api }}_callback_default;
void glad_set_{{ feature_set.api }}_post_callback(GLADcallback cb) {
void gladSet{{ feature_set.api }}PostCallback(GLADcallback cb) {
_post_call_{{ feature_set.api }}_callback = cb;
}
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion glad/lang/c/templates/base_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ GLAPI void glad_set_{{ feature_set.api }}_post_callback(GLADcallback cb);
{% endblock %}

{% block loader_impl %}
{% include 'loader/' + spec.name + '.h' %}
{% include 'loader/' + feature_set.api + '.h' %}
{% endblock %}

#ifdef __cplusplus
Expand Down
79 changes: 0 additions & 79 deletions glad/lang/c/templates/loader/gles.c

This file was deleted.

18 changes: 0 additions & 18 deletions glad/lang/c/templates/loader/gles.h

This file was deleted.

48 changes: 48 additions & 0 deletions glad/lang/c/templates/loader/gles1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#ifdef GLAD_GLES1

typedef void* (APIENTRYP GLAD_GLES1_PFNGETPROCADDRESSPROC_PRIVATE)(const char*);
struct _glad_gles1_userptr {
void *handle;
GLAD_GLES1_PFNGETPROCADDRESSPROC_PRIVATE get_proc_address_ptr;
};


static void* glad_gles1_get_proc(const char* name, void *vuserptr) {
struct _glad_gles1_userptr userptr = *(struct _glad_gles1_userptr) vuserptr;
void* result = NULL;

/* dlsym first, since some implementations don't return function pointers for core functions */
result = (void*) glad_dlsym_handle(userptr.handle, name);
if (result == NULL) {
result = (void*) userptr.get_proc_address_ptr(name);
}

return result;
}

int gladLoadGLES1InternalLoader() {
#ifdef __APPLE__
static const char *NAMES[] = {"libGLESv1_CM.dylib"};
#elif defined _WIN32
static const char *NAMES[] = {"GLESv1_CM.dll", "libGLESv1_CM", "libGLES_CM.dll"};
#else
static const char *NAMES[] = {"ibGLESv1_CM.so.1", "ibGLESv1_CM.so", "libGLES_CM.so.1"};
#endif

int version = 0;
void *handle;
struct _glad_gles1_userptr userptr;

handle = glad_get_dlopen_handle(NAMES, sizeof(NAMES) / sizeof(NAMES[0]));
if (handle) {
userptr.handle = handle;
userptr.get_proc_address_ptr = eglGetProcAddress;

version = gladLoadGLES2((GLADloadproc) glad_gles1_get_proc, &userptr);

glad_close_dlopen_handle(handle);
}

return version;
}
#endif /* GLAD_GLES1 */
8 changes: 8 additions & 0 deletions glad/lang/c/templates/loader/gles1.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifdef GLAD_GLES1
#ifndef __egl_h_
#error "gles1 loader requires egl.h, include egl.h (<glad/egl.h>) before including the loader."
#endif

GLAPI int gladLoadGLES1InternalLoader();

#endif /* GLAD_GLES1 */
49 changes: 49 additions & 0 deletions glad/lang/c/templates/loader/gles2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#ifdef GLAD_GLES2

typedef void* (APIENTRYP GLAD_GLES2_PFNGETPROCADDRESSPROC_PRIVATE)(const char*);
struct _glad_gles2_userptr {
void *handle;
GLAD_GLES2_PFNGETPROCADDRESSPROC_PRIVATE get_proc_address_ptr;
};


static void* glad_gles2_get_proc(const char* name, void *vuserptr) {
struct _glad_gles2_userptr userptr = *(struct _glad_gles2_userptr) vuserptr;
void* result = NULL;

/* dlsym first, since some implementations don't return function pointers for core functions */
result = (void*) glad_dlsym_handle(userptr.handle, name);
if (result == NULL) {
result = (void*) userptr.get_proc_address_ptr(name);
}

return result;
}


int gladLoadGLES2InternalLoader() {
#ifdef __APPLE__
static const char *NAMES[] = {"libGLESv2.dylib"};
#elif defined _WIN32
static const char *NAMES[] = {"GLESv2.dll", "libGLESv2.dll"};
#else
static const char *NAMES[] = {"libGLESv2.so.2", "libGLESv2.so"};
#endif

int version = 0;
void *handle;
struct _glad_gles_userptr userptr;

handle = glad_get_dlopen_handle(NAMES, sizeof(NAMES) / sizeof(NAMES[0]));
if (handle) {
userptr.handle = handle;
userptr.get_proc_address_ptr = eglGetProcAddress;

version = gladLoadGLES2((GLADloadproc) glad_gles2_get_proc, &userptr);

glad_close_dlopen_handle(handle);
}

return version;
}
#endif /* GLAD_GLES2 */
9 changes: 9 additions & 0 deletions glad/lang/c/templates/loader/gles2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifdef GLAD_GLES2
#ifndef __egl_h_
#error "gles2 loader requires egl.h, include egl.h (<glad/egl.h>) before including the loader."
#endif

GLAPI int gladLoadGLES2InternalLoader();

#endif /* GLAD_GLES2 */

Empty file.
Empty file.

0 comments on commit 7dd9706

Please sign in to comment.