56 if (qwglMakeCurrent) {
57 qwglMakeCurrent(NULL, NULL);
60 if (
glw.
hGLRC && qwglDeleteContext) {
75 memset(&
glw, 0,
sizeof(
glw));
80 Com_EPrintf(
"%s failed with error %lu\n", what, GetLastError());
85 Com_DPrintf(
"GL_FPD(%d): flags(%#lx) color(%d) Z(%d) stencil(%d)\n",
86 pixelformat, pfd->dwFlags, pfd->cColorBits, pfd->cDepthBits,
94 static int SetupGL(
int colorbits,
int depthbits,
int stencilbits,
int multisamples)
96 PIXELFORMATDESCRIPTOR pfd;
106 depthbits = colorbits > 16 ? 24 : 16;
112 if (qwglChoosePixelFormatARB && multisamples > 1) {
116 iAttributes[0] = WGL_DRAW_TO_WINDOW_ARB;
117 iAttributes[1] = TRUE;
118 iAttributes[2] = WGL_SUPPORT_OPENGL_ARB;
119 iAttributes[3] = TRUE;
120 iAttributes[4] = WGL_DOUBLE_BUFFER_ARB;
121 iAttributes[5] = TRUE;
122 iAttributes[6] = WGL_PIXEL_TYPE_ARB;
123 iAttributes[7] = WGL_TYPE_RGBA_ARB;
124 iAttributes[8] = WGL_COLOR_BITS_ARB;
125 iAttributes[9] = colorbits;
126 iAttributes[10] = WGL_DEPTH_BITS_ARB;
127 iAttributes[11] = depthbits;
128 iAttributes[12] = WGL_STENCIL_BITS_ARB;
129 iAttributes[13] = stencilbits;
130 iAttributes[14] = WGL_SAMPLE_BUFFERS_ARB;
132 iAttributes[16] = WGL_SAMPLES_ARB;
133 iAttributes[17] = multisamples;
137 if (qwglChoosePixelFormatARB(
win.dc, iAttributes, NULL, 1, &pixelformat, &numFormats) == FALSE) {
141 if (numFormats == 0) {
142 Com_EPrintf(
"No suitable OpenGL pixelformat found for %d multisamples\n", multisamples);
146 memset(&pfd, 0,
sizeof(pfd));
147 pfd.nSize =
sizeof(pfd);
149 pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
150 pfd.iPixelType = PFD_TYPE_RGBA;
151 pfd.cColorBits = colorbits;
152 pfd.cDepthBits = depthbits;
153 pfd.cStencilBits = stencilbits;
154 pfd.iLayerType = PFD_MAIN_PLANE;
157 if ((pixelformat = qwglChoosePixelFormat(
win.dc, &pfd)) == 0) {
162 if ((pixelformat = ChoosePixelFormat(
win.dc, &pfd)) == 0) {
171 qwglDescribePixelFormat(
win.dc, pixelformat,
sizeof(pfd), &pfd);
174 if (qwglSetPixelFormat(
win.dc, pixelformat, &pfd) == FALSE) {
179 DescribePixelFormat(
win.dc, pixelformat,
sizeof(pfd), &pfd);
182 if (SetPixelFormat(
win.dc, pixelformat, &pfd) == FALSE) {
189 if (pfd.dwFlags & PFD_GENERIC_FORMAT) {
191 Com_EPrintf(
"No hardware OpenGL acceleration detected\n");
194 Com_WPrintf(
"...using software emulation\n");
195 }
else if (pfd.dwFlags & PFD_GENERIC_ACCELERATED) {
196 Com_DPrintf(
"...MCD acceleration found\n");
197 win.flags |= QVF_ACCELERATED;
199 Com_DPrintf(
"...ICD acceleration found\n");
200 win.flags |= QVF_ACCELERATED;
204 if ((
glw.
hGLRC = qwglCreateContext(
win.dc)) == NULL) {
228 #define FAKE_WINDOW_CLASS "Q2PRO FAKE WINDOW CLASS"
229 #define FAKE_WINDOW_NAME "Q2PRO FAKE WINDOW NAME"
234 PIXELFORMATDESCRIPTOR pfd;
239 unsigned extensions = 0;
241 memset(&wc, 0,
sizeof(wc));
242 wc.cbSize =
sizeof(wc);
243 wc.lpfnWndProc = DefWindowProc;
247 if (!RegisterClassEx(&wc))
262 if ((dc = GetDC(wnd)) == NULL)
265 memset(&pfd, 0,
sizeof(pfd));
266 pfd.nSize =
sizeof(pfd);
268 pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
269 pfd.iPixelType = PFD_TYPE_RGBA;
272 pfd.cStencilBits = 8;
273 pfd.iLayerType = PFD_MAIN_PLANE;
276 if ((pixelformat = qwglChoosePixelFormat(dc, &pfd)) == 0)
279 if (qwglSetPixelFormat(dc, pixelformat, &pfd) == FALSE)
282 if ((pixelformat = ChoosePixelFormat(dc, &pfd)) == 0)
285 if (SetPixelFormat(dc, pixelformat, &pfd) == FALSE)
289 if ((rc = qwglCreateContext(dc)) == NULL)
292 if (qwglMakeCurrent(dc, rc) == FALSE)
303 Com_Printf(
"...enabling WGL_ARB_pixel_format\n");
308 qwglMakeCurrent(NULL, NULL);
310 qwglDeleteContext(rc);
330 if (!Q_stricmp(driver,
"opengl32") ||
331 !Q_stricmp(driver,
"opengl32.dll")) {
334 Com_Printf(
"...running a minidriver: %s\n", driver);
345 if (!qwglCreateContext || !qwglMakeCurrent || !qwglDeleteContext) {
346 Com_EPrintf(
"Required WGL entry points are missing\n");
352 if (!qwglChoosePixelFormat || !qwglSetPixelFormat ||
353 !qwglDescribePixelFormat || !qwglSwapBuffers) {
354 Com_EPrintf(
"Required MCD entry points are missing\n");
360 if (multisamples > 1) {
364 if (qwglChoosePixelFormatARB) {
365 Com_Printf(
"...enabling WGL_ARB_multisample\n");
367 Com_Printf(
"...ignoring WGL_ARB_multisample, WGL_ARB_pixel_format not found\n");
372 Com_Printf(
"WGL_ARB_multisample not found\n");
379 ret =
SetupGL(colorbits, depthbits, stencilbits, multisamples);
382 if (ret ==
FAIL_SOFT && (colorbits || depthbits || stencilbits || multisamples > 1)) {
401 Com_Printf(
"Negative swap interval is not supported on this system.\n");
405 if (qwglSwapIntervalEXT && !qwglSwapIntervalEXT(self->integer))
411 if (!Q_stricmp(self->string,
"GL_FRONT")) {
413 }
else if (!Q_stricmp(self->string,
"GL_BACK")) {
432 const char *extensions;
452 Com_Printf(
"...falling back to opengl32\n");
470 if (!extensions || !*extensions)
477 Com_Printf(
"...enabling WGL_EXT_swap_control(_tear)\n");
479 Com_Printf(
"...enabling WGL_EXT_swap_control\n");
484 Com_Printf(
"WGL_EXT_swap_control not found\n");
526 ret = qwglSwapBuffers(
win.dc);
528 ret = SwapBuffers(
win.dc);
532 DWORD error = GetLastError();
535 if (!IsIconic(
win.wnd)) {
536 Com_Error(ERR_FATAL,
"%s failed with error %lu",
552 Com_EPrintf(
"Couldn't get OpenGL entry point: %s\n", sym);
561 if (qwglGetProcAddress)
562 entry = (
void *)qwglGetProcAddress(sym);
567 Com_EPrintf(
"Couldn't get OpenGL entry point: %s\n", sym);