Quake II RTX doxygen  1.0 dev
wgl.c
Go to the documentation of this file.
1 /*
2 Copyright (C) 1997-2001 Id Software, Inc.
3 
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18 #include "client.h"
19 #include "glimp.h"
20 #include "wgl.h"
21 
22 void (APIENTRY * qwglDrawBuffer)(GLenum mode);
23 const GLubyte * (APIENTRY * qwglGetString)(GLenum name);
24 
25 int (WINAPI * qwglChoosePixelFormat)(HDC, CONST PIXELFORMATDESCRIPTOR *);
26 int (WINAPI * qwglDescribePixelFormat)(HDC, int, UINT, LPPIXELFORMATDESCRIPTOR);
27 BOOL (WINAPI * qwglSetPixelFormat)(HDC, int, CONST PIXELFORMATDESCRIPTOR *);
28 BOOL (WINAPI * qwglSwapBuffers)(HDC);
29 
30 HGLRC (WINAPI * qwglCreateContext)(HDC);
31 BOOL (WINAPI * qwglDeleteContext)(HGLRC);
32 PROC (WINAPI * qwglGetProcAddress)(LPCSTR);
33 BOOL (WINAPI * qwglMakeCurrent)(HDC, HGLRC);
34 
35 const char * (WINAPI * qwglGetExtensionsStringARB)(HDC hdc);
36 
37 BOOL (WINAPI * qwglChoosePixelFormatARB)(HDC, const int *, const FLOAT *, UINT, int *, UINT *);
38 
39 BOOL (WINAPI * qwglSwapIntervalEXT)(int interval);
40 
41 void WGL_Shutdown(void)
42 {
43  if (glw.hinstOpenGL) {
44  FreeLibrary(glw.hinstOpenGL);
45  glw.hinstOpenGL = NULL;
46  }
47 
48  qwglDrawBuffer = NULL;
49  qwglGetString = NULL;
50 
51  qwglChoosePixelFormat = NULL;
52  qwglDescribePixelFormat = NULL;
53  qwglSetPixelFormat = NULL;
54  qwglSwapBuffers = NULL;
55 
56  qwglCreateContext = NULL;
57  qwglDeleteContext = NULL;
58  qwglGetProcAddress = NULL;
59  qwglMakeCurrent = NULL;
60 
62 }
63 
64 #define GPA(x) (void *)GetProcAddress(glw.hinstOpenGL, x);
65 
66 qboolean WGL_Init(const char *dllname)
67 {
68  if ((glw.hinstOpenGL = LoadLibrary(dllname)) == NULL) {
69  return qfalse;
70  }
71 
72  qwglDrawBuffer = GPA("glDrawBuffer");
73  qwglGetString = GPA("glGetString");
74 
75  qwglChoosePixelFormat = GPA("wglChoosePixelFormat");
76  qwglDescribePixelFormat = GPA("wglDescribePixelFormat");
77  qwglSetPixelFormat = GPA("wglSetPixelFormat");
78  qwglSwapBuffers = GPA("wglSwapBuffers");
79 
80  qwglCreateContext = GPA("wglCreateContext");
81  qwglDeleteContext = GPA("wglDeleteContext");
82  qwglGetProcAddress = GPA("wglGetProcAddress");
83  qwglMakeCurrent = GPA("wglMakeCurrent");
84 
85  return qtrue;
86 }
87 
88 #undef GPA
89 
90 void WGL_ShutdownExtensions(unsigned mask)
91 {
92  if (mask & QWGL_ARB_extensions_string) {
94  }
95  if (mask & QWGL_ARB_pixel_format) {
96  qwglChoosePixelFormatARB = NULL;
97  }
98  if (mask & QWGL_EXT_swap_control) {
99  qwglSwapIntervalEXT = NULL;
100  }
101 }
102 
103 #define GPA(x) (void *)qwglGetProcAddress(x)
104 
105 void WGL_InitExtensions(unsigned mask)
106 {
107  if (mask & QWGL_ARB_extensions_string) {
108  qwglGetExtensionsStringARB = GPA("wglGetExtensionsStringARB");
109  }
110  if (mask & QWGL_ARB_pixel_format) {
111  qwglChoosePixelFormatARB = GPA("wglChoosePixelFormatARB");
112  }
113  if (mask & QWGL_EXT_swap_control) {
114  qwglSwapIntervalEXT = GPA("wglSwapIntervalEXT");
115  }
116 }
117 
118 #undef GPA
119 
120 unsigned WGL_ParseExtensionString(const char *s)
121 {
122  // must match defines in win_wgl.h!
123  static const char *const extnames[] = {
124  "WGL_ARB_extensions_string",
125  "WGL_ARB_multisample",
126  "WGL_ARB_pixel_format",
127  "WGL_EXT_swap_control",
128  "WGL_EXT_swap_control_tear",
129  NULL
130  };
131 
132  return Com_ParseExtensionString(s, extnames);
133 }
134 
PROC
PROC(WINAPI *qwglGetProcAddress)(LPCSTR)
wgl.h
QWGL_ARB_pixel_format
#define QWGL_ARB_pixel_format
Definition: wgl.h:25
QWGL_ARB_extensions_string
#define QWGL_ARB_extensions_string
Definition: wgl.h:23
WGL_ParseExtensionString
unsigned WGL_ParseExtensionString(const char *s)
Definition: wgl.c:120
glw
glwstate_t glw
Definition: glimp.c:35
BOOL
BOOL(WINAPI *qwglSetPixelFormat)(HDC
glimp.h
WGL_Shutdown
void WGL_Shutdown(void)
Definition: wgl.c:41
LPPIXELFORMATDESCRIPTOR
CONST PIXELFORMATDESCRIPTOR LPPIXELFORMATDESCRIPTOR
Definition: wgl.c:26
client.h
WGL_Init
qboolean WGL_Init(const char *dllname)
Definition: wgl.c:66
void
void(APIENTRY *qwglDrawBuffer)(GLenum mode)
QWGL_EXT_swap_control
#define QWGL_EXT_swap_control
Definition: wgl.h:26
WGL_InitExtensions
void WGL_InitExtensions(unsigned mask)
Definition: wgl.c:105
APIENTRY
#define APIENTRY
Definition: dynamic.h:32
WGL_ShutdownExtensions
void WGL_ShutdownExtensions(unsigned mask)
Definition: wgl.c:90
UINT
CONST PIXELFORMATDESCRIPTOR UINT
Definition: wgl.c:26
GPA
#define GPA(x)
Definition: wgl.c:103
HGLRC
HGLRC
Definition: wgl.c:33
qwglGetString
const GLubyte *APIENTRY * qwglGetString(GLenum name)
int
CONST PIXELFORMATDESCRIPTOR int
Definition: wgl.c:26
glwstate_t::hinstOpenGL
HINSTANCE hinstOpenGL
Definition: glimp.h:28
qwglGetExtensionsStringARB
const char *WINAPI * qwglGetExtensionsStringARB(HDC hdc)