| 122 | static HMODULE glModule; |
| 123 | |
| 124 | bool queryOpenGL(BHashTable<U32, GLPixelFormatPtr>& formatsById, std::vector<GLPixelFormatPtr>& glformats) { |
| 125 | WNDCLASS tmpClass; |
| 126 | memset(&tmpClass, 0, sizeof(WNDCLASS)); |
| 127 | tmpClass.style = CS_OWNDC; |
| 128 | tmpClass.hInstance = GetModuleHandle(NULL); |
| 129 | tmpClass.lpfnWndProc = dummyWndProc; |
| 130 | tmpClass.lpszClassName = "boxedwine"; |
| 131 | RegisterClass(&tmpClass); |
| 132 | |
| 133 | HWND hwnd = CreateWindow("boxedwine", "boxedwine", WS_POPUP | WS_CLIPCHILDREN, 0, 0, 32, 32, 0, 0, tmpClass.hInstance, 0); |
| 134 | |
| 135 | if (!hwnd) { |
| 136 | kpanic("queryOpenGL failed to create opengl window"); |
| 137 | } |
| 138 | |
| 139 | HDC hdc = GetDC(hwnd); |
| 140 | |
| 141 | PIXELFORMATDESCRIPTOR pfd; |
| 142 | memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR)); |
| 143 | pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); |
| 144 | pfd.nVersion = 1; |
| 145 | pfd.cColorBits = 32; |
| 146 | pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER; |
| 147 | pfd.iPixelType = PFD_TYPE_RGBA; |
| 148 | |
| 149 | if (!glModule) { |
| 150 | const char* openGL = "opengl32.dll"; |
| 151 | BString path; |
| 152 | if (KSystem::openglLib.length()) { |
| 153 | path = KSystem::openglLib.replace('/', '\\'); |
| 154 | if (!path.contains(":")) { |
| 155 | char appPath[MAX_PATH]; |
| 156 | GetModuleFileNameA(NULL, appPath, MAX_PATH); |
| 157 | BString fullPath; |
| 158 | fullPath = appPath; |
| 159 | fullPath = fullPath.substr(0, fullPath.lastIndexOf('\\')); |
| 160 | path = fullPath.stringByApppendingPath(path); |
| 161 | } |
| 162 | openGL = path.c_str(); |
| 163 | } |
| 164 | glModule = LoadLibraryEx(openGL, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); |
| 165 | } |
| 166 | |
| 167 | int format = ChoosePixelFormat(hdc, &pfd); |
| 168 | if (format != 0) { |
| 169 | SetPixelFormat(hdc, format, &pfd); |
| 170 | } |
| 171 | |
| 172 | pfnwglCreateContext = (PFNWGLCREATECONTEXT)GetProcAddress(glModule, "wglCreateContext"); |
| 173 | pfnwglMakeCurrent = (PFNWGLMAKECURRENT)GetProcAddress(glModule, "wglMakeCurrent"); |
| 174 | pfnwglDeleteContext = (PFNWGLDELETECONTEXT)GetProcAddress(glModule, "wglDeleteContext"); |
| 175 | pfnwglGetProcAddress = (PFNWGLGETPROCADDRESS)GetProcAddress(glModule, "wglGetProcAddress"); |
| 176 | pfnwglGetCurrentDC = (PFNWGLGETCURRENTDC)GetProcAddress(glModule, "wglGetCurrentDC"); |
| 177 | pfnwglGetCurrentContext = (PFNWGLGETCURRENTCONTEXT)GetProcAddress(glModule, "wglGetCurrentContext"); |
| 178 | |
| 179 | HGLRC hrc = pfnwglCreateContext ? pfnwglCreateContext(hdc) : 0; |
| 180 | if (hrc) { |
| 181 | HGLRC oldrc = pfnwglGetCurrentContext(); |
no test coverage detected