• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2014 Jon Turney
3  *
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:
10  *
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
13  * Software.
14  *
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
21  * IN THE SOFTWARE.
22  */
23 
24 /*
25   Wrapper functions for calling WGL extension functions
26  */
27 
28 #include "wgl.h"
29 
30 #include <stdio.h>
31 
32 #define RESOLVE_DECL(type) \
33     static type type##proc = NULL;
34 
35 #define PRERESOLVE(type, symbol) \
36     type##proc = (type)wglGetProcAddress(symbol); \
37     if (type##proc == NULL) \
38        printf("Can't resolve \"%s\"\n", symbol);
39 
40 #define CHECK_RESOLVED(type, retval) \
41   if (type##proc == NULL) { \
42     return retval; \
43   }
44 
45 #define RESOLVED_PROC(type) type##proc
46 
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);
54 
wglResolveExtensionProcs(void)55 void wglResolveExtensionProcs(void)
56 {
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");
64 }
65 
wglGetExtensionsStringARB(HDC hdc_)66 const char *wglGetExtensionsStringARB(HDC hdc_)
67 {
68    CHECK_RESOLVED(PFNWGLGETEXTENSIONSSTRINGARBPROC, "");
69    return RESOLVED_PROC(PFNWGLGETEXTENSIONSSTRINGARBPROC)(hdc_);
70 }
71 
wglCreateContextAttribsARB(HDC hdc_,HGLRC hShareContext_,const int * attribList_)72 HGLRC wglCreateContextAttribsARB(HDC hdc_, HGLRC hShareContext_,
73                                      const int *attribList_)
74 {
75    CHECK_RESOLVED(PFNWGLCREATECONTEXTATTRIBSARBPROC, NULL);
76    return RESOLVED_PROC(PFNWGLCREATECONTEXTATTRIBSARBPROC)(hdc_, hShareContext_, attribList_);
77 }
78 
wglMakeContextCurrentARB(HDC hDrawDC_,HDC hReadDC_,HGLRC hglrc_)79 BOOL wglMakeContextCurrentARB(HDC hDrawDC_, HDC hReadDC_, HGLRC hglrc_)
80 {
81    CHECK_RESOLVED(PFNWGLMAKECONTEXTCURRENTARBPROC, FALSE);
82    return RESOLVED_PROC(PFNWGLMAKECONTEXTCURRENTARBPROC)(hDrawDC_, hReadDC_, hglrc_);
83 }
84 
wglCreatePbufferARB(HDC hDC_,int iPixelFormat_,int iWidth_,int iHeight_,const int * piAttribList_)85 HPBUFFERARB wglCreatePbufferARB(HDC hDC_, int iPixelFormat_, int iWidth_,
86                                 int iHeight_, const int *piAttribList_)
87 {
88    CHECK_RESOLVED(PFNWGLCREATEPBUFFERARBPROC, NULL);
89    return RESOLVED_PROC(PFNWGLCREATEPBUFFERARBPROC)(hDC_, iPixelFormat_, iWidth_, iHeight_, piAttribList_);
90 }
91 
wglGetPbufferDCARB(HPBUFFERARB hPbuffer_)92 HDC wglGetPbufferDCARB(HPBUFFERARB hPbuffer_)
93 {
94    CHECK_RESOLVED(PFNWGLGETPBUFFERDCARBPROC, NULL);
95    return RESOLVED_PROC(PFNWGLGETPBUFFERDCARBPROC)(hPbuffer_);
96 }
97 
wglReleasePbufferDCARB(HPBUFFERARB hPbuffer_,HDC hDC_)98 int wglReleasePbufferDCARB(HPBUFFERARB hPbuffer_, HDC hDC_)
99 {
100    CHECK_RESOLVED(PFNWGLRELEASEPBUFFERDCARBPROC, 0)
101    return RESOLVED_PROC(PFNWGLRELEASEPBUFFERDCARBPROC)(hPbuffer_, hDC_);
102 }
103 
wglDestroyPbufferARB(HPBUFFERARB hPbuffer_)104 BOOL wglDestroyPbufferARB(HPBUFFERARB hPbuffer_)
105 {
106    CHECK_RESOLVED(PFNWGLDESTROYPBUFFERARBPROC, FALSE);
107    return RESOLVED_PROC(PFNWGLDESTROYPBUFFERARBPROC)(hPbuffer_);
108 }
109