2 * Copyright © 2014 Jon Turney
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 Wrapper functions for calling WGL extension functions
32 #define RESOLVE_DECL(type) \
33 static type type##proc = NULL;
35 #define PRERESOLVE(type, symbol) \
36 type##proc = (type)wglGetProcAddress(symbol); \
37 if (type##proc == NULL) \
38 printf("Can't resolve \"%s\"\n", symbol);
40 #define CHECK_RESOLVED(type, retval) \
41 if (type##proc == NULL) { \
45 #define RESOLVED_PROC(type) type##proc
47 RESOLVE_DECL(PFNWGLGETEXTENSIONSSTRINGARBPROC
);
48 RESOLVE_DECL(PFNWGLCREATECONTEXTATTRIBSARBPROC
);
49 RESOLVE_DECL(PFNWGLMAKECONTEXTCURRENTARBPROC
);
50 RESOLVE_DECL(PFNWGLCREATEPBUFFERARBPROC
);
51 RESOLVE_DECL(PFNWGLGETPBUFFERDCARBPROC
);
52 RESOLVE_DECL(PFNWGLRELEASEPBUFFERDCARBPROC
);
53 RESOLVE_DECL(PFNWGLDESTROYPBUFFERARBPROC
);
55 void wglResolveExtensionProcs(void)
57 PRERESOLVE(PFNWGLGETEXTENSIONSSTRINGARBPROC
, "wglGetExtensionsStringARB");
58 PRERESOLVE(PFNWGLCREATECONTEXTATTRIBSARBPROC
, "wglCreateContextAttribsARB");
59 PRERESOLVE(PFNWGLMAKECONTEXTCURRENTARBPROC
, "wglMakeContextCurrentARB");
60 PRERESOLVE(PFNWGLCREATEPBUFFERARBPROC
, "wglCreatePbufferARB");
61 PRERESOLVE(PFNWGLGETPBUFFERDCARBPROC
, "wglGetPbufferDCARB");
62 PRERESOLVE(PFNWGLRELEASEPBUFFERDCARBPROC
, "wglReleasePbufferDCARB");
63 PRERESOLVE(PFNWGLDESTROYPBUFFERARBPROC
, "wglDestroyPbufferARB");
66 const char *wglGetExtensionsStringARB(HDC hdc_
)
68 CHECK_RESOLVED(PFNWGLGETEXTENSIONSSTRINGARBPROC
, "");
69 return RESOLVED_PROC(PFNWGLGETEXTENSIONSSTRINGARBPROC
)(hdc_
);
72 HGLRC
wglCreateContextAttribsARB(HDC hdc_
, HGLRC hShareContext_
,
73 const int *attribList_
)
75 CHECK_RESOLVED(PFNWGLCREATECONTEXTATTRIBSARBPROC
, NULL
);
76 return RESOLVED_PROC(PFNWGLCREATECONTEXTATTRIBSARBPROC
)(hdc_
, hShareContext_
, attribList_
);
79 BOOL
wglMakeContextCurrentARB(HDC hDrawDC_
, HDC hReadDC_
, HGLRC hglrc_
)
81 CHECK_RESOLVED(PFNWGLMAKECONTEXTCURRENTARBPROC
, FALSE
);
82 return RESOLVED_PROC(PFNWGLMAKECONTEXTCURRENTARBPROC
)(hDrawDC_
, hReadDC_
, hglrc_
);
85 HPBUFFERARB
wglCreatePbufferARB(HDC hDC_
, int iPixelFormat_
, int iWidth_
,
86 int iHeight_
, const int *piAttribList_
)
88 CHECK_RESOLVED(PFNWGLCREATEPBUFFERARBPROC
, NULL
);
89 return RESOLVED_PROC(PFNWGLCREATEPBUFFERARBPROC
)(hDC_
, iPixelFormat_
, iWidth_
, iHeight_
, piAttribList_
);
92 HDC
wglGetPbufferDCARB(HPBUFFERARB hPbuffer_
)
94 CHECK_RESOLVED(PFNWGLGETPBUFFERDCARBPROC
, NULL
);
95 return RESOLVED_PROC(PFNWGLGETPBUFFERDCARBPROC
)(hPbuffer_
);
98 int wglReleasePbufferDCARB(HPBUFFERARB hPbuffer_
, HDC hDC_
)
100 CHECK_RESOLVED(PFNWGLRELEASEPBUFFERDCARBPROC
, 0)
101 return RESOLVED_PROC(PFNWGLRELEASEPBUFFERDCARBPROC
)(hPbuffer_
, hDC_
);
104 BOOL
wglDestroyPbufferARB(HPBUFFERARB hPbuffer_
)
106 CHECK_RESOLVED(PFNWGLDESTROYPBUFFERARBPROC
, FALSE
);
107 return RESOLVED_PROC(PFNWGLDESTROYPBUFFERARBPROC
)(hPbuffer_
);