reshuffling of dlls
[reactos.git] / reactos / dll / win32 / gdi32 / misc / wingl.c
1 /*
2 * ReactOS Gdi32
3 * Copyright (C) 2003 ReactOS Team
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 *
20 *
21 *
22 */
23
24 #include "precomp.h"
25
26 #define NDEBUG
27 #include <debug.h>
28
29
30
31 typedef int (*CHOOSEPIXELFMT) (HDC, CONST PIXELFORMATDESCRIPTOR *);
32 typedef BOOL (*SETPIXELFMT) (HDC, int, CONST PIXELFORMATDESCRIPTOR *);
33 typedef BOOL (*SWAPBUFFERS) (HDC hdc);
34 typedef int (*DESCRIBEPIXELFMT) (HDC, int, UINT, LPPIXELFORMATDESCRIPTOR);
35 typedef int (*GETPIXELFMT) (HDC);
36
37
38 static CHOOSEPIXELFMT glChoosePixelFormat = NULL;
39 static SETPIXELFMT glSetPixelFormat = NULL;
40 static SWAPBUFFERS glSwapBuffers = NULL;
41 static DESCRIBEPIXELFMT glDescribePixelFormat = NULL;
42 static GETPIXELFMT glGetPixelFormat = NULL;
43
44 /*
45 OpenGL Handle.
46 */
47 HINSTANCE hOpenGL = NULL;
48
49 static BOOL OpenGLEnable(void)
50 {
51 if(hOpenGL == NULL)
52 {
53 hOpenGL = LoadLibraryA("OPENGL32.DLL");
54 if(hOpenGL == NULL)
55 return(FALSE);
56 }
57
58 if(glChoosePixelFormat == NULL) {
59 glChoosePixelFormat = (CHOOSEPIXELFMT)GetProcAddress(hOpenGL, "wglChoosePixelFormat");
60 if(glChoosePixelFormat == NULL)
61 return(0);
62 }
63
64 if(glSetPixelFormat == NULL) {
65 glSetPixelFormat = (SETPIXELFMT)GetProcAddress(hOpenGL, "wglSetPixelFormat");
66 if(glSetPixelFormat == NULL)
67 return(FALSE);
68 }
69
70 if(glSwapBuffers == NULL) {
71 glSwapBuffers = (SWAPBUFFERS)GetProcAddress(hOpenGL, "wglSwapBuffers");
72 if(glSwapBuffers == NULL)
73 return(FALSE);
74 }
75
76 if(glDescribePixelFormat == NULL) {
77 glDescribePixelFormat = (DESCRIBEPIXELFMT)GetProcAddress(hOpenGL, "wglDescribePixelFormat");
78 if(glDescribePixelFormat == NULL)
79 return(FALSE);
80 }
81
82 if(glGetPixelFormat == NULL) {
83 glGetPixelFormat = (GETPIXELFMT)GetProcAddress(hOpenGL, "wglGetPixelFormat");
84 if(glGetPixelFormat == NULL)
85 return(FALSE);
86 }
87
88 return(TRUE); /* OpenGL is initialized and enabled*/
89 }
90
91
92
93 /*
94 * @implemented
95 */
96 INT
97 STDCALL
98 ChoosePixelFormat(HDC hdc,
99 CONST PIXELFORMATDESCRIPTOR * ppfd)
100 {
101 if (glChoosePixelFormat == NULL)
102 if (OpenGLEnable() == FALSE)
103 return(0);
104
105 return(glChoosePixelFormat(hdc, ppfd));
106 }
107
108
109
110 /*
111 * @implemented
112 */
113 INT
114 STDCALL
115 DescribePixelFormat(HDC hdc,
116 INT iPixelFormat,
117 UINT nBytes,
118 LPPIXELFORMATDESCRIPTOR ppfd)
119 {
120 if (glDescribePixelFormat == NULL)
121 if (OpenGLEnable() == FALSE)
122 return(0);
123
124 return(glDescribePixelFormat(hdc, iPixelFormat, nBytes, ppfd));
125 }
126
127
128
129 /*
130 * @implemented
131 */
132 INT
133 STDCALL
134 GetPixelFormat(HDC hdc)
135 {
136 if (glGetPixelFormat == NULL)
137 if (OpenGLEnable() == FALSE)
138 return(0);
139
140 return(glGetPixelFormat(hdc));
141 }
142
143
144
145 /*
146 * @implemented
147 */
148 BOOL
149 STDCALL
150 SetPixelFormat(HDC hdc,
151 INT iPixelFormat,
152 CONST PIXELFORMATDESCRIPTOR * ppfd)
153 {
154 if (glSetPixelFormat == NULL)
155 if (OpenGLEnable() == FALSE)
156 return(0);
157
158 return(glSetPixelFormat(hdc, iPixelFormat, ppfd));
159 }
160
161
162
163 /*
164 * @implemented
165 */
166 BOOL
167 STDCALL
168 SwapBuffers(HDC hdc)
169 {
170 if (glSwapBuffers == NULL)
171 if (OpenGLEnable() == FALSE)
172 return(0);
173
174
175 return(glSwapBuffers(hdc));
176 }
177
178
179 /*
180 Do this here for now.
181 */
182
183 /*
184 * @implemented
185 */
186 UINT
187 STDCALL
188 GetEnhMetaFilePixelFormat(
189 HENHMETAFILE hemf,
190 UINT cbBuffer,
191 PIXELFORMATDESCRIPTOR *ppfd
192 )
193 {
194 ENHMETAHEADER pemh;
195
196 if(GetEnhMetaFileHeader(hemf, sizeof(ENHMETAHEADER), &pemh))
197 {
198 if(pemh.bOpenGL)
199 {
200 if(pemh.cbPixelFormat)
201 {
202 memcpy((void*)ppfd, UlongToPtr(pemh.offPixelFormat), cbBuffer );
203 return(pemh.cbPixelFormat);
204 }
205 }
206 }
207 return(0);
208 }
209
210 /* EOF */