1 /*
2 Copyright (C) 1997-2001 Id Software, Inc.
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (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.
12 
13 See the GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 
19 */
20 #include "win_local.h"
21 #include "win_glimp.h"
22 #include "win_wgl.h"
23 
24 void ( APIENTRY * qglDrawBuffer )(GLenum mode);
25 const GLubyte * ( APIENTRY * qglGetString )(GLenum name);
26 
27 int   ( WINAPI * qwglChoosePixelFormat )(HDC, CONST PIXELFORMATDESCRIPTOR *);
28 int   ( WINAPI * qwglDescribePixelFormat) (HDC, int, UINT, LPPIXELFORMATDESCRIPTOR);
29 int   ( WINAPI * qwglGetPixelFormat)(HDC);
30 BOOL  ( WINAPI * qwglSetPixelFormat)(HDC, int, CONST PIXELFORMATDESCRIPTOR *);
31 BOOL  ( WINAPI * qwglSwapBuffers)(HDC);
32 
33 BOOL  ( WINAPI * qwglCopyContext)(HGLRC, HGLRC, UINT);
34 HGLRC ( WINAPI * qwglCreateContext)(HDC);
35 HGLRC ( WINAPI * qwglCreateLayerContext)(HDC, int);
36 BOOL  ( WINAPI * qwglDeleteContext)(HGLRC);
37 HGLRC ( WINAPI * qwglGetCurrentContext)(VOID);
38 HDC   ( WINAPI * qwglGetCurrentDC)(VOID);
39 PROC  ( WINAPI * qwglGetProcAddress)(LPCSTR);
40 BOOL  ( WINAPI * qwglMakeCurrent)(HDC, HGLRC);
41 BOOL  ( WINAPI * qwglShareLists)(HGLRC, HGLRC);
42 BOOL ( WINAPI * qwglDescribeLayerPlane)(HDC, int, int, UINT,
43                                             LPLAYERPLANEDESCRIPTOR);
44 int  ( WINAPI * qwglSetLayerPaletteEntries)(HDC, int, int, int,
45                                                 CONST COLORREF *);
46 int  ( WINAPI * qwglGetLayerPaletteEntries)(HDC, int, int, int,
47                                                 COLORREF *);
48 BOOL ( WINAPI * qwglRealizeLayerPalette)(HDC, int, BOOL);
49 BOOL ( WINAPI * qwglSwapLayerBuffers)(HDC, UINT);
50 
51 BOOL ( WINAPI * qwglSwapIntervalEXT)( int interval );
52 BOOL ( WINAPI * qwglGetDeviceGammaRampEXT)( unsigned char *, unsigned char *, unsigned char * );
53 BOOL ( WINAPI * qwglSetDeviceGammaRampEXT)( const unsigned char *, const unsigned char *, const unsigned char * );
54 
WGL_Shutdown(void)55 void WGL_Shutdown( void ) {
56     if( glw_state.hinstOpenGL ) {
57     	FreeLibrary( glw_state.hinstOpenGL );
58 	    glw_state.hinstOpenGL = NULL;
59     }
60 
61 	qglDrawBuffer	= NULL;
62 	qglGetString	= NULL;
63 
64 	qwglCopyContext              = NULL;
65 	qwglCreateContext            = NULL;
66 	qwglCreateLayerContext       = NULL;
67 	qwglDeleteContext            = NULL;
68 	qwglDescribeLayerPlane       = NULL;
69 	qwglGetCurrentContext        = NULL;
70 	qwglGetCurrentDC             = NULL;
71 	qwglGetLayerPaletteEntries   = NULL;
72 	qwglGetProcAddress           = NULL;
73 	qwglMakeCurrent              = NULL;
74 	qwglRealizeLayerPalette      = NULL;
75 	qwglSetLayerPaletteEntries   = NULL;
76 	qwglShareLists               = NULL;
77 	qwglSwapLayerBuffers         = NULL;
78 
79 	qwglChoosePixelFormat        = NULL;
80 	qwglDescribePixelFormat      = NULL;
81 	qwglGetPixelFormat           = NULL;
82 	qwglSetPixelFormat           = NULL;
83 	qwglSwapBuffers              = NULL;
84 
85 	qwglSwapIntervalEXT          = NULL;
86 	qwglGetDeviceGammaRampEXT    = NULL;
87 	qwglSetDeviceGammaRampEXT    = NULL;
88 }
89 
90 
91 #define GPA( x ) do { \
92         q ## x = ( void * )GetProcAddress( glw_state.hinstOpenGL, #x ); \
93         if( !q ## x ) { \
94             return qfalse; \
95         } \
96     } while( 0 )
97 
WGL_Init(const char * dllname)98 qboolean WGL_Init( const char *dllname ) {
99 	if( ( glw_state.hinstOpenGL = LoadLibrary( dllname ) ) == NULL ) {
100 		return qfalse;
101 	}
102 
103 	GPA( glDrawBuffer );
104 	GPA( glGetString );
105 
106 	GPA( wglCopyContext );
107 	GPA( wglCreateContext );
108 	GPA( wglCreateLayerContext );
109 	GPA( wglDeleteContext );
110 	GPA( wglDescribeLayerPlane );
111 	GPA( wglGetCurrentContext );
112 	GPA( wglGetCurrentDC );
113 	GPA( wglGetLayerPaletteEntries );
114 	GPA( wglGetProcAddress );
115 	GPA( wglMakeCurrent );
116 	GPA( wglRealizeLayerPalette );
117 	GPA( wglSetLayerPaletteEntries );
118 	GPA( wglShareLists );
119 	GPA( wglSwapLayerBuffers );
120 
121 	GPA( wglChoosePixelFormat );
122 	GPA( wglDescribePixelFormat );
123 	GPA( wglGetPixelFormat );
124 	GPA( wglSetPixelFormat );
125 	GPA( wglSwapBuffers );
126 
127 	qwglSwapIntervalEXT			 = NULL;
128 	qwglGetDeviceGammaRampEXT	 = NULL;
129 	qwglSetDeviceGammaRampEXT	 = NULL;
130 
131 	return qtrue;
132 }
133 
WGL_GetProcAddress(const char * symbol)134 void *WGL_GetProcAddress( const char *symbol ) {
135     return ( void * )GetProcAddress( glw_state.hinstOpenGL, symbol );
136 }
137 
138 #undef GPA
139 
140