1 //
2 // Copyright 2015 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6
7 // FunctionsWGL.h: Implements the FuntionsWGL class.
8
9 #include "libANGLE/renderer/gl/wgl/FunctionsWGL.h"
10
11 #include <algorithm>
12
13 #include "common/string_utils.h"
14
15 namespace rx
16 {
17
18 template <typename T>
GetWGLProcAddress(HMODULE glModule,PFNWGLGETPROCADDRESSPROC getProcAddressWGL,const std::string & procName,T * outProcAddress)19 static void GetWGLProcAddress(HMODULE glModule,
20 PFNWGLGETPROCADDRESSPROC getProcAddressWGL,
21 const std::string &procName,
22 T *outProcAddress)
23 {
24 T proc = nullptr;
25 if (getProcAddressWGL)
26 {
27 proc = reinterpret_cast<T>(getProcAddressWGL(procName.c_str()));
28 }
29
30 if (!proc)
31 {
32 proc = reinterpret_cast<T>(GetProcAddress(glModule, procName.c_str()));
33 }
34
35 *outProcAddress = proc;
36 }
37
38 template <typename T>
GetWGLExtensionProcAddress(HMODULE glModule,PFNWGLGETPROCADDRESSPROC getProcAddressWGL,const std::vector<std::string> & extensions,const std::string & extensionName,const std::string & procName,T * outProcAddress)39 static void GetWGLExtensionProcAddress(HMODULE glModule,
40 PFNWGLGETPROCADDRESSPROC getProcAddressWGL,
41 const std::vector<std::string> &extensions,
42 const std::string &extensionName,
43 const std::string &procName,
44 T *outProcAddress)
45 {
46 T proc = nullptr;
47 if (std::find(extensions.begin(), extensions.end(), extensionName) != extensions.end())
48 {
49 GetWGLProcAddress(glModule, getProcAddressWGL, procName, &proc);
50 }
51
52 *outProcAddress = proc;
53 }
54
FunctionsWGL()55 FunctionsWGL::FunctionsWGL()
56 : copyContext(nullptr),
57 createContext(nullptr),
58 createLayerContext(nullptr),
59 deleteContext(nullptr),
60 getCurrentContext(nullptr),
61 getCurrentDC(nullptr),
62 getProcAddress(nullptr),
63 makeCurrent(nullptr),
64 shareLists(nullptr),
65 useFontBitmapsA(nullptr),
66 useFontBitmapsW(nullptr),
67 swapBuffers(nullptr),
68 useFontOutlinesA(nullptr),
69 useFontOutlinesW(nullptr),
70 describeLayerPlane(nullptr),
71 setLayerPaletteEntries(nullptr),
72 getLayerPaletteEntries(nullptr),
73 realizeLayerPalette(nullptr),
74 swapLayerBuffers(nullptr),
75 swapMultipleBuffers(nullptr),
76 getExtensionStringEXT(nullptr),
77 getExtensionStringARB(nullptr),
78 createContextAttribsARB(nullptr),
79 getPixelFormatAttribivARB(nullptr),
80 getPixelFormatAttribfvARB(nullptr),
81 choosePixelFormatARB(nullptr),
82 swapIntervalEXT(nullptr),
83 createPbufferARB(nullptr),
84 getPbufferDCARB(nullptr),
85 releasePbufferDCARB(nullptr),
86 destroyPbufferARB(nullptr),
87 queryPbufferARB(nullptr),
88 bindTexImageARB(nullptr),
89 releaseTexImageARB(nullptr),
90 setPbufferAttribARB(nullptr),
91 dxSetResourceShareHandleNV(nullptr),
92 dxOpenDeviceNV(nullptr),
93 dxCloseDeviceNV(nullptr),
94 dxRegisterObjectNV(nullptr),
95 dxUnregisterObjectNV(nullptr),
96 dxObjectAccessNV(nullptr),
97 dxLockObjectsNV(nullptr),
98 dxUnlockObjectsNV(nullptr)
99 {}
100
~FunctionsWGL()101 FunctionsWGL::~FunctionsWGL() {}
102
initialize(HMODULE glModule,HDC context)103 void FunctionsWGL::initialize(HMODULE glModule, HDC context)
104 {
105 // First grab the wglGetProcAddress function from the gl module
106 GetWGLProcAddress(glModule, nullptr, "wglGetProcAddress", &getProcAddress);
107
108 // Load the core wgl functions
109 GetWGLProcAddress(glModule, getProcAddress, "wglCopyContext", ©Context);
110 GetWGLProcAddress(glModule, getProcAddress, "wglCreateContext", &createContext);
111 GetWGLProcAddress(glModule, getProcAddress, "wglCreateLayerContext", &createLayerContext);
112 GetWGLProcAddress(glModule, getProcAddress, "wglDeleteContext", &deleteContext);
113 GetWGLProcAddress(glModule, getProcAddress, "wglGetCurrentContext", &getCurrentContext);
114 GetWGLProcAddress(glModule, getProcAddress, "wglGetCurrentDC", &getCurrentDC);
115 GetWGLProcAddress(glModule, getProcAddress, "wglMakeCurrent", &makeCurrent);
116 GetWGLProcAddress(glModule, getProcAddress, "wglShareLists", &shareLists);
117 GetWGLProcAddress(glModule, getProcAddress, "wglUseFontBitmapsA", &useFontBitmapsA);
118 GetWGLProcAddress(glModule, getProcAddress, "wglUseFontBitmapsW", &useFontBitmapsW);
119 swapBuffers = SwapBuffers; // SwapBuffers is statically linked from GDI
120 GetWGLProcAddress(glModule, getProcAddress, "wglUseFontOutlinesA", &useFontOutlinesA);
121 GetWGLProcAddress(glModule, getProcAddress, "wglUseFontOutlinesW", &useFontOutlinesW);
122 GetWGLProcAddress(glModule, getProcAddress, "wglDescribeLayerPlane", &describeLayerPlane);
123 GetWGLProcAddress(glModule, getProcAddress, "wglSetLayerPaletteEntries",
124 &setLayerPaletteEntries);
125 GetWGLProcAddress(glModule, getProcAddress, "wglGetLayerPaletteEntries",
126 &getLayerPaletteEntries);
127 GetWGLProcAddress(glModule, getProcAddress, "wglRealizeLayerPalette", &realizeLayerPalette);
128 GetWGLProcAddress(glModule, getProcAddress, "wglSwapLayerBuffers", &swapLayerBuffers);
129 GetWGLProcAddress(glModule, getProcAddress, "wglSwapMultipleBuffers", &swapMultipleBuffers);
130
131 // Load extension string getter functions
132 GetWGLProcAddress(glModule, getProcAddress, "wglGetExtensionsStringEXT",
133 &getExtensionStringEXT);
134 GetWGLProcAddress(glModule, getProcAddress, "wglGetExtensionsStringARB",
135 &getExtensionStringARB);
136
137 std::string extensionString = "";
138 if (getExtensionStringEXT)
139 {
140 extensionString = getExtensionStringEXT();
141 }
142 else if (getExtensionStringARB && context)
143 {
144 extensionString = getExtensionStringARB(context);
145 }
146 angle::SplitStringAlongWhitespace(extensionString, &extensions);
147
148 // Load the wgl extension functions by checking if the context supports the extension first
149
150 // WGL_ARB_create_context
151 GetWGLExtensionProcAddress(glModule, getProcAddress, extensions, "WGL_ARB_create_context",
152 "wglCreateContextAttribsARB", &createContextAttribsARB);
153
154 // WGL_ARB_pixel_format
155 GetWGLExtensionProcAddress(glModule, getProcAddress, extensions, "WGL_ARB_pixel_format",
156 "wglGetPixelFormatAttribivARB", &getPixelFormatAttribivARB);
157 GetWGLExtensionProcAddress(glModule, getProcAddress, extensions, "WGL_ARB_pixel_format",
158 "wglGetPixelFormatAttribfvARB", &getPixelFormatAttribfvARB);
159 GetWGLExtensionProcAddress(glModule, getProcAddress, extensions, "WGL_ARB_pixel_format",
160 "wglChoosePixelFormatARB", &choosePixelFormatARB);
161
162 // WGL_EXT_swap_control
163 GetWGLExtensionProcAddress(glModule, getProcAddress, extensions, "WGL_EXT_swap_control",
164 "wglSwapIntervalEXT", &swapIntervalEXT);
165
166 // WGL_ARB_pbuffer
167 GetWGLExtensionProcAddress(glModule, getProcAddress, extensions, "WGL_ARB_pbuffer",
168 "wglCreatePbufferARB", &createPbufferARB);
169 GetWGLExtensionProcAddress(glModule, getProcAddress, extensions, "WGL_ARB_pbuffer",
170 "wglGetPbufferDCARB", &getPbufferDCARB);
171 GetWGLExtensionProcAddress(glModule, getProcAddress, extensions, "WGL_ARB_pbuffer",
172 "wglReleasePbufferDCARB", &releasePbufferDCARB);
173 GetWGLExtensionProcAddress(glModule, getProcAddress, extensions, "WGL_ARB_pbuffer",
174 "wglDestroyPbufferARB", &destroyPbufferARB);
175 GetWGLExtensionProcAddress(glModule, getProcAddress, extensions, "WGL_ARB_pbuffer",
176 "wglQueryPbufferARB", &queryPbufferARB);
177
178 // WGL_ARB_render_texture
179 GetWGLExtensionProcAddress(glModule, getProcAddress, extensions, "WGL_ARB_render_texture",
180 "wglBindTexImageARB", &bindTexImageARB);
181 GetWGLExtensionProcAddress(glModule, getProcAddress, extensions, "WGL_ARB_render_texture",
182 "wglReleaseTexImageARB", &releaseTexImageARB);
183 GetWGLExtensionProcAddress(glModule, getProcAddress, extensions, "WGL_ARB_render_texture",
184 "wglSetPbufferAttribARB", &setPbufferAttribARB);
185
186 // WGL_NV_DX_interop
187 GetWGLExtensionProcAddress(glModule, getProcAddress, extensions, "WGL_NV_DX_interop",
188 "wglDXSetResourceShareHandleNV", &dxSetResourceShareHandleNV);
189 GetWGLExtensionProcAddress(glModule, getProcAddress, extensions, "WGL_NV_DX_interop",
190 "wglDXOpenDeviceNV", &dxOpenDeviceNV);
191 GetWGLExtensionProcAddress(glModule, getProcAddress, extensions, "WGL_NV_DX_interop",
192 "wglDXCloseDeviceNV", &dxCloseDeviceNV);
193 GetWGLExtensionProcAddress(glModule, getProcAddress, extensions, "WGL_NV_DX_interop",
194 "wglDXRegisterObjectNV", &dxRegisterObjectNV);
195 GetWGLExtensionProcAddress(glModule, getProcAddress, extensions, "WGL_NV_DX_interop",
196 "wglDXUnregisterObjectNV", &dxUnregisterObjectNV);
197 GetWGLExtensionProcAddress(glModule, getProcAddress, extensions, "WGL_NV_DX_interop",
198 "wglDXObjectAccessNV", &dxObjectAccessNV);
199 GetWGLExtensionProcAddress(glModule, getProcAddress, extensions, "WGL_NV_DX_interop",
200 "wglDXLockObjectsNV", &dxLockObjectsNV);
201 GetWGLExtensionProcAddress(glModule, getProcAddress, extensions, "WGL_NV_DX_interop",
202 "wglDXUnlockObjectsNV", &dxUnlockObjectsNV);
203 }
204
hasExtension(const std::string & ext) const205 bool FunctionsWGL::hasExtension(const std::string &ext) const
206 {
207 return std::find(extensions.begin(), extensions.end(), ext) != extensions.end();
208 }
209 } // namespace rx
210