Subversion Repositories eduke32

Rev

Rev 6948 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6656 pogokeen 1
/*
2
 
7752 pogokeen 3
    WGL loader generated by glad 0.1.30 on Thu Jul  4 02:04:37 2019.
6656 pogokeen 4
 
5
    Language/Generator: C/C++
6
    Specification: wgl
7
    APIs: wgl=1.0
8
    Profile: -
9
    Extensions:
10
        WGL_ARB_create_context,
11
        WGL_ARB_create_context_profile,
12
        WGL_ARB_extensions_string,
13
        WGL_ARB_pixel_format,
14
        WGL_EXT_extensions_string,
15
        WGL_EXT_swap_control
16
    Loader: True
17
    Local files: False
18
    Omit khrplatform: False
7752 pogokeen 19
    Reproducible: False
6656 pogokeen 20
 
21
    Commandline:
22
        --api="wgl=1.0" --generator="c" --spec="wgl" --extensions="WGL_ARB_create_context,WGL_ARB_create_context_profile,WGL_ARB_extensions_string,WGL_ARB_pixel_format,WGL_EXT_extensions_string,WGL_EXT_swap_control"
23
    Online:
7752 pogokeen 24
        https://glad.dav1d.de/#language=c&specification=wgl&loader=on&api=wgl%3D1.0&extensions=WGL_ARB_create_context&extensions=WGL_ARB_create_context_profile&extensions=WGL_ARB_extensions_string&extensions=WGL_ARB_pixel_format&extensions=WGL_EXT_extensions_string&extensions=WGL_EXT_swap_control
6656 pogokeen 25
*/
26
 
27
#include <stdio.h>
28
#include <stdlib.h>
29
#include <string.h>
30
#include <glad/glad_wgl.h>
31
 
32
static void* get_proc(const char *namez);
33
 
6948 hendricks2 34
#if defined(_WIN32) || defined(__CYGWIN__)
6656 pogokeen 35
#include <windows.h>
36
static HMODULE libGL;
37
 
38
typedef void* (APIENTRYP PFNWGLGETPROCADDRESSPROC_PRIVATE)(const char*);
39
static PFNWGLGETPROCADDRESSPROC_PRIVATE gladGetProcAddressPtr;
40
 
6948 hendricks2 41
#ifdef _MSC_VER
42
#ifdef __has_include
43
  #if __has_include(<winapifamily.h>)
44
    #define HAVE_WINAPIFAMILY 1
45
  #endif
46
#elif _MSC_VER >= 1700 && !_USING_V110_SDK71_
47
  #define HAVE_WINAPIFAMILY 1
48
#endif
49
#endif
50
 
51
#ifdef HAVE_WINAPIFAMILY
52
  #include <winapifamily.h>
53
  #if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
54
    #define IS_UWP 1
55
  #endif
56
#endif
57
 
6656 pogokeen 58
static
59
int open_gl(void) {
6948 hendricks2 60
#ifndef IS_UWP
6656 pogokeen 61
    libGL = LoadLibraryW(L"opengl32.dll");
62
    if(libGL != NULL) {
6948 hendricks2 63
        void (* tmp)(void);
64
        tmp = (void(*)(void)) GetProcAddress(libGL, "wglGetProcAddress");
65
        gladGetProcAddressPtr = (PFNWGLGETPROCADDRESSPROC_PRIVATE) tmp;
6656 pogokeen 66
        return gladGetProcAddressPtr != NULL;
67
    }
6948 hendricks2 68
#endif
6656 pogokeen 69
 
70
    return 0;
71
}
72
 
73
static
74
void close_gl(void) {
75
    if(libGL != NULL) {
6780 hendricks2 76
        FreeLibrary((HMODULE) libGL);
6948 hendricks2 77
        libGL = NULL;
6656 pogokeen 78
    }
79
}
80
#else
81
#include <dlfcn.h>
82
static void* libGL;
83
 
7752 pogokeen 84
#if !defined(__APPLE__) && !defined(__HAIKU__)
6656 pogokeen 85
typedef void* (APIENTRYP PFNGLXGETPROCADDRESSPROC_PRIVATE)(const char*);
86
static PFNGLXGETPROCADDRESSPROC_PRIVATE gladGetProcAddressPtr;
87
#endif
88
 
89
static
90
int open_gl(void) {
91
#ifdef __APPLE__
92
    static const char *NAMES[] = {
93
        "../Frameworks/OpenGL.framework/OpenGL",
94
        "/Library/Frameworks/OpenGL.framework/OpenGL",
95
        "/System/Library/Frameworks/OpenGL.framework/OpenGL",
96
        "/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL"
97
    };
98
#else
99
    static const char *NAMES[] = {"libGL.so.1", "libGL.so"};
100
#endif
101
 
102
    unsigned int index = 0;
103
    for(index = 0; index < (sizeof(NAMES) / sizeof(NAMES[0])); index++) {
104
        libGL = dlopen(NAMES[index], RTLD_NOW | RTLD_GLOBAL);
105
 
106
        if(libGL != NULL) {
7752 pogokeen 107
#if defined(__APPLE__) || defined(__HAIKU__)
6656 pogokeen 108
            return 1;
109
#else
110
            gladGetProcAddressPtr = (PFNGLXGETPROCADDRESSPROC_PRIVATE)dlsym(libGL,
111
                "glXGetProcAddressARB");
112
            return gladGetProcAddressPtr != NULL;
113
#endif
114
        }
115
    }
116
 
117
    return 0;
118
}
119
 
120
static
121
void close_gl(void) {
122
    if(libGL != NULL) {
123
        dlclose(libGL);
124
        libGL = NULL;
125
    }
126
}
127
#endif
128
 
129
static
130
void* get_proc(const char *namez) {
131
    void* result = NULL;
132
    if(libGL == NULL) return NULL;
133
 
7752 pogokeen 134
#if !defined(__APPLE__) && !defined(__HAIKU__)
6656 pogokeen 135
    if(gladGetProcAddressPtr != NULL) {
136
        result = gladGetProcAddressPtr(namez);
137
    }
138
#endif
139
    if(result == NULL) {
6948 hendricks2 140
#if defined(_WIN32) || defined(__CYGWIN__)
6780 hendricks2 141
        result = (void*)GetProcAddress((HMODULE) libGL, namez);
6656 pogokeen 142
#else
143
        result = dlsym(libGL, namez);
144
#endif
145
    }
146
 
147
    return result;
148
}
149
 
150
int gladLoadWGL(HDC hdc) {
151
    int status = 0;
152
 
153
    if(open_gl()) {
154
        status = gladLoadWGLLoader((GLADloadproc)get_proc, hdc);
155
        close_gl();
156
    }
157
 
158
    return status;
159
}
160
 
161
static HDC GLADWGLhdc = (HDC)INVALID_HANDLE_VALUE;
162
 
163
static int get_exts(void) {
164
    return 1;
165
}
166
 
167
static void free_exts(void) {
168
    return;
169
}
170
 
171
static int has_ext(const char *ext) {
172
    const char *terminator;
173
    const char *loc;
174
    const char *extensions;
175
 
176
    if(wglGetExtensionsStringEXT == NULL && wglGetExtensionsStringARB == NULL)
177
        return 0;
178
 
179
    if(wglGetExtensionsStringARB == NULL || GLADWGLhdc == INVALID_HANDLE_VALUE)
180
        extensions = wglGetExtensionsStringEXT();
181
    else
182
        extensions = wglGetExtensionsStringARB(GLADWGLhdc);
183
 
184
    if(extensions == NULL || ext == NULL)
185
        return 0;
186
 
187
    while(1) {
188
        loc = strstr(extensions, ext);
189
        if(loc == NULL)
190
            break;
191
 
192
        terminator = loc + strlen(ext);
193
        if((loc == extensions || *(loc - 1) == ' ') &&
194
            (*terminator == ' ' || *terminator == '\0'))
195
        {
196
            return 1;
197
        }
198
        extensions = terminator;
199
    }
200
 
201
    return 0;
202
}
7752 pogokeen 203
int GLAD_WGL_VERSION_1_0 = 0;
204
int GLAD_WGL_ARB_create_context = 0;
205
int GLAD_WGL_ARB_create_context_profile = 0;
206
int GLAD_WGL_ARB_extensions_string = 0;
207
int GLAD_WGL_ARB_pixel_format = 0;
208
int GLAD_WGL_EXT_extensions_string = 0;
209
int GLAD_WGL_EXT_swap_control = 0;
210
PFNWGLCREATECONTEXTATTRIBSARBPROC glad_wglCreateContextAttribsARB = NULL;
211
PFNWGLGETEXTENSIONSSTRINGARBPROC glad_wglGetExtensionsStringARB = NULL;
212
PFNWGLGETPIXELFORMATATTRIBIVARBPROC glad_wglGetPixelFormatAttribivARB = NULL;
213
PFNWGLGETPIXELFORMATATTRIBFVARBPROC glad_wglGetPixelFormatAttribfvARB = NULL;
214
PFNWGLCHOOSEPIXELFORMATARBPROC glad_wglChoosePixelFormatARB = NULL;
215
PFNWGLGETEXTENSIONSSTRINGEXTPROC glad_wglGetExtensionsStringEXT = NULL;
216
PFNWGLSWAPINTERVALEXTPROC glad_wglSwapIntervalEXT = NULL;
217
PFNWGLGETSWAPINTERVALEXTPROC glad_wglGetSwapIntervalEXT = NULL;
6656 pogokeen 218
static void load_WGL_ARB_create_context(GLADloadproc load) {
219
        if(!GLAD_WGL_ARB_create_context) return;
220
        glad_wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)load("wglCreateContextAttribsARB");
221
}
222
static void load_WGL_ARB_extensions_string(GLADloadproc load) {
223
        if(!GLAD_WGL_ARB_extensions_string) return;
224
        glad_wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)load("wglGetExtensionsStringARB");
225
}
226
static void load_WGL_ARB_pixel_format(GLADloadproc load) {
227
        if(!GLAD_WGL_ARB_pixel_format) return;
228
        glad_wglGetPixelFormatAttribivARB = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)load("wglGetPixelFormatAttribivARB");
229
        glad_wglGetPixelFormatAttribfvARB = (PFNWGLGETPIXELFORMATATTRIBFVARBPROC)load("wglGetPixelFormatAttribfvARB");
230
        glad_wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)load("wglChoosePixelFormatARB");
231
}
232
static void load_WGL_EXT_extensions_string(GLADloadproc load) {
233
        if(!GLAD_WGL_EXT_extensions_string) return;
234
        glad_wglGetExtensionsStringEXT = (PFNWGLGETEXTENSIONSSTRINGEXTPROC)load("wglGetExtensionsStringEXT");
235
}
236
static void load_WGL_EXT_swap_control(GLADloadproc load) {
237
        if(!GLAD_WGL_EXT_swap_control) return;
238
        glad_wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)load("wglSwapIntervalEXT");
239
        glad_wglGetSwapIntervalEXT = (PFNWGLGETSWAPINTERVALEXTPROC)load("wglGetSwapIntervalEXT");
240
}
241
static int find_extensionsWGL(void) {
242
        if (!get_exts()) return 0;
243
        GLAD_WGL_ARB_create_context = has_ext("WGL_ARB_create_context");
244
        GLAD_WGL_ARB_create_context_profile = has_ext("WGL_ARB_create_context_profile");
245
        GLAD_WGL_ARB_extensions_string = has_ext("WGL_ARB_extensions_string");
246
        GLAD_WGL_ARB_pixel_format = has_ext("WGL_ARB_pixel_format");
247
        GLAD_WGL_EXT_extensions_string = has_ext("WGL_EXT_extensions_string");
248
        GLAD_WGL_EXT_swap_control = has_ext("WGL_EXT_swap_control");
249
        free_exts();
250
        return 1;
251
}
252
 
253
static void find_coreWGL(HDC hdc) {
254
        GLADWGLhdc = hdc;
255
}
256
 
257
int gladLoadWGLLoader(GLADloadproc load, HDC hdc) {
258
        wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)load("wglGetExtensionsStringARB");
259
        wglGetExtensionsStringEXT = (PFNWGLGETEXTENSIONSSTRINGEXTPROC)load("wglGetExtensionsStringEXT");
260
        if(wglGetExtensionsStringARB == NULL && wglGetExtensionsStringEXT == NULL) return 0;
261
        find_coreWGL(hdc);
262
 
263
        if (!find_extensionsWGL()) return 0;
264
        load_WGL_ARB_create_context(load);
265
        load_WGL_ARB_extensions_string(load);
266
        load_WGL_ARB_pixel_format(load);
267
        load_WGL_EXT_extensions_string(load);
268
        load_WGL_EXT_swap_control(load);
269
        return 1;
270
}
271