source: trunk/src/opengl/mesa/wgl.c@ 2962

Last change on this file since 2962 was 2962, checked in by jeroen, 25 years ago

* empty log message *

File size: 14.4 KB
Line 
1/* $Id: wgl.c,v 1.2 2000-03-01 18:49:40 jeroen Exp $ */
2
3/*
4* This library is free software; you can redistribute it and/or
5* modify it under the terms of the GNU Library General Public
6* License as published by the Free Software Foundation; either
7* version 2 of the License, or (at your option) any later version.
8*
9* This library 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 GNU
12* Library General Public License for more details.
13*
14* You should have received a copy of the GNU Library General Public
15* License along with this library; if not, write to the Free
16* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17*
18*/
19
20/*
21* File name : wgl.c
22* WGL stuff. Added by Oleg Letsinsky, ajl@ultersys.ru
23* Some things originated from the 3Dfx WGL functions
24*/
25
26#if defined(WIN32) || defined(__WIN32OS2__)
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31#include <windows.h>
32
33#ifdef __cplusplus
34}
35#endif
36
37#include <stdio.h>
38#include <tchar.h>
39#include "gl.h"
40#include "types.h"
41#include "context.h"
42#include "wmesadef.h"
43#include "wmesa.h"
44
45#define MAX_MESA_ATTRS 20
46
47struct __extensions__
48{
49 PROC proc;
50 char *name;
51};
52
53struct __pixelformat__
54{
55 PIXELFORMATDESCRIPTOR pfd;
56 GLboolean doubleBuffered;
57};
58
59struct __extensions__ ext[] = {
60
61#ifdef GL_EXT_polygon_offset
62 { (PROC)glPolygonOffsetEXT, "glPolygonOffsetEXT" },
63#endif
64 { (PROC)glBlendEquationEXT, "glBlendEquationEXT" },
65 { (PROC)glBlendColorEXT, "glBlendColorExt" },
66 { (PROC)glVertexPointerEXT, "glVertexPointerEXT" },
67 { (PROC)glNormalPointerEXT, "glNormalPointerEXT" },
68 { (PROC)glColorPointerEXT, "glColorPointerEXT" },
69 { (PROC)glIndexPointerEXT, "glIndexPointerEXT" },
70 { (PROC)glTexCoordPointerEXT, "glTexCoordPointer" },
71 { (PROC)glEdgeFlagPointerEXT, "glEdgeFlagPointerEXT" },
72 { (PROC)glGetPointervEXT, "glGetPointervEXT" },
73 { (PROC)glArrayElementEXT, "glArrayElementEXT" },
74 { (PROC)glDrawArraysEXT, "glDrawArrayEXT" },
75 { (PROC)glAreTexturesResidentEXT, "glAreTexturesResidentEXT" },
76 { (PROC)glBindTextureEXT, "glBindTextureEXT" },
77 { (PROC)glDeleteTexturesEXT, "glDeleteTexturesEXT" },
78 { (PROC)glGenTexturesEXT, "glGenTexturesEXT" },
79 { (PROC)glIsTextureEXT, "glIsTextureEXT" },
80 { (PROC)glPrioritizeTexturesEXT, "glPrioritizeTexturesEXT" },
81 { (PROC)glCopyTexSubImage3DEXT, "glCopyTexSubImage3DEXT" },
82 { (PROC)glTexImage3DEXT, "glTexImage3DEXT" },
83 { (PROC)glTexSubImage3DEXT, "glTexSubImage3DEXT" },
84 { (PROC)glColorTableEXT, "glColorTableEXT" },
85 { (PROC)glColorSubTableEXT, "glColorSubTableEXT" },
86 { (PROC)glGetColorTableEXT, "glGetColorTableEXT" },
87 { (PROC)glGetColorTableParameterfvEXT, "glGetColorTableParameterfvEXT" },
88 { (PROC)glGetColorTableParameterivEXT, "glGetColorTableParameterivEXT" },
89 { (PROC)glPointParameterfEXT, "glPointParameterfEXT" },
90 { (PROC)glPointParameterfvEXT, "glPointParameterfvEXT" },
91 { (PROC)glBlendFuncSeparateINGR, "glBlendFuncSeparateINGR" },
92 { (PROC)glLockArraysEXT, "glLockArraysEXT" },
93 { (PROC)glUnlockArraysEXT, "glUnlockArraysEXT" }
94};
95
96int qt_ext = sizeof(ext) / sizeof(ext[0]);
97
98struct __pixelformat__ pix[] =
99{
100 { { sizeof(PIXELFORMATDESCRIPTOR), 1,
101 PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_GENERIC_FORMAT|PFD_DOUBLEBUFFER|PFD_SWAP_COPY,
102 PFD_TYPE_RGBA,
103 24, 8, 0, 8, 8, 8, 16, 8, 24,
104 0, 0, 0, 0, 0, 16, 8, 0, 0, 0, 0, 0, 0 },
105 GL_TRUE
106 },
107 { { sizeof(PIXELFORMATDESCRIPTOR), 1,
108 PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_GENERIC_FORMAT,
109 PFD_TYPE_RGBA,
110 24, 8, 0, 8, 8, 8, 16, 8, 24,
111 0, 0, 0, 0, 0, 16, 8, 0, 0, 0, 0, 0, 0 },
112 GL_FALSE
113 },
114};
115
116int qt_pix = sizeof(pix) / sizeof(pix[0]);
117
118typedef struct {
119 WMesaContext ctx;
120 HDC hdc;
121} MesaWglCtx;
122
123#define MESAWGL_CTX_MAX_COUNT 20
124
125static MesaWglCtx wgl_ctx[MESAWGL_CTX_MAX_COUNT];
126
127static unsigned ctx_count = 0;
128static unsigned ctx_current = -1;
129static unsigned curPFD = 0;
130
131GLAPI BOOL GLWINAPI wglCopyContext(HGLRC hglrcSrc,HGLRC hglrcDst,UINT mask)
132{
133 return(FALSE);
134}
135
136GLAPI HGLRC GLWINAPI wglCreateContext(HDC hdc)
137{
138 HWND hWnd;
139 int i = 0;
140 if(!(hWnd = WindowFromDC(hdc)))
141 {
142 SetLastError(0);
143 return(NULL);
144 }
145 if (!ctx_count)
146 {
147 for(i=0;i<MESAWGL_CTX_MAX_COUNT;i++)
148 {
149 wgl_ctx[i].ctx = NULL;
150 wgl_ctx[i].hdc = NULL;
151 }
152 }
153 for( i = 0; i < MESAWGL_CTX_MAX_COUNT; i++ )
154 {
155 if ( wgl_ctx[i].ctx == NULL )
156 {
157 wgl_ctx[i].ctx = WMesaCreateContext( hWnd, NULL, GL_TRUE,
158 pix[curPFD-1].doubleBuffered );
159 if (wgl_ctx[i].ctx == NULL)
160 break;
161 wgl_ctx[i].hdc = hdc;
162 ctx_count++;
163 return ((HGLRC)wgl_ctx[i].ctx);
164 }
165 }
166 SetLastError(0);
167 return(NULL);
168}
169
170GLAPI BOOL GLWINAPI wglDeleteContext(HGLRC hglrc)
171{
172 int i;
173 for ( i = 0; i < MESAWGL_CTX_MAX_COUNT; i++ )
174 {
175 if ( wgl_ctx[i].ctx == (PWMC) hglrc )
176 {
177 WMesaMakeCurrent((PWMC) hglrc);
178 WMesaDestroyContext();
179 wgl_ctx[i].ctx = NULL;
180 wgl_ctx[i].hdc = NULL;
181 ctx_count--;
182 return(TRUE);
183 }
184 }
185 SetLastError(0);
186 return(FALSE);
187}
188
189GLAPI HGLRC GLWINAPI wglCreateLayerContext(HDC hdc,int iLayerPlane)
190{
191 SetLastError(0);
192 return(NULL);
193}
194
195GLAPI HGLRC GLWINAPI wglGetCurrentContext(VOID)
196{
197 if (ctx_current < 0)
198 return 0;
199 else
200 return (HGLRC) wgl_ctx[ctx_current].ctx;
201}
202
203GLAPI HDC GLWINAPI wglGetCurrentDC(VOID)
204{
205 if (ctx_current < 0)
206 return 0;
207 else
208 return wgl_ctx[ctx_current].hdc;
209}
210
211GLAPI BOOL GLWINAPI wglMakeCurrent(HDC hdc,HGLRC hglrc)
212{
213 int i;
214
215 /* new code suggested by Andy Sy */
216 if (!hdc || !hglrc) {
217 WMesaMakeCurrent(NULL);
218 ctx_current = -1;
219 return TRUE;
220 }
221
222 for ( i = 0; i < MESAWGL_CTX_MAX_COUNT; i++ )
223 {
224 if ( wgl_ctx[i].ctx == (PWMC) hglrc )
225 {
226 wgl_ctx[i].hdc = hdc;
227 WMesaMakeCurrent( (WMesaContext) hglrc );
228 ctx_current = i;
229 return TRUE;
230 }
231 }
232 return FALSE;
233}
234
235GLAPI BOOL GLWINAPI wglShareLists(HGLRC hglrc1,HGLRC hglrc2)
236{
237 return(TRUE);
238}
239
240
241static FIXED FixedFromDouble(double d)
242{
243 long l = (long) (d * 65536L);
244 return *(FIXED *)&l;
245}
246
247
248GLAPI BOOL GLWINAPI wglUseFontBitmapsA(HDC hdc, DWORD first,
249 DWORD count, DWORD listBase)
250{
251 int i;
252 GLuint font_list;
253 DWORD size;
254 GLYPHMETRICS gm;
255 HANDLE hBits;
256 LPSTR lpBits;
257 MAT2 mat;
258
259 if (first<0)
260 return FALSE;
261 if (count<0)
262 return FALSE;
263 if (listBase<0)
264 return FALSE;
265
266 font_list = glGenLists( count );
267 if(font_list == 0)
268 return FALSE;
269
270 mat.eM11 = FixedFromDouble(1);
271 mat.eM12 = FixedFromDouble(0);
272 mat.eM21 = FixedFromDouble(0);
273 mat.eM22 = FixedFromDouble(1);
274
275 memset(&gm,0,sizeof(gm));
276
277 for (i = 0; i < count; i++)
278 {
279 glNewList( font_list+i, GL_COMPILE );
280
281 /* allocate space for the bitmap/outline */
282 size = GetGlyphOutline(hdc, first + i, GGO_BITMAP, &gm, 0, NULL, &mat);
283 if (size == GDI_ERROR)
284 {
285 DWORD err;
286 err = GetLastError();
287 return(FALSE);
288 }
289
290 hBits = GlobalAlloc(GHND, size);
291 lpBits = (LPSTR)GlobalLock(hBits);
292
293 GetGlyphOutline(hdc, /* handle to device context*/
294 first + i, /* character to query*/
295 GGO_BITMAP, /* format of data to return*/
296 &gm, /* pointer to structure for metrics*/
297 size, /* size of buffer for data*/
298 lpBits, /* pointer to buffer for data*/
299 &mat /* pointer to transformation*/
300 /* matrix structure */
301 );
302 if (*lpBits == GDI_ERROR)
303 {
304 DWORD err;
305 err = GetLastError();
306
307 GlobalUnlock(hBits);
308 GlobalFree(hBits);
309
310 return(FALSE);
311 }
312
313 glBitmap(gm.gmBlackBoxX,gm.gmBlackBoxY,
314 gm.gmptGlyphOrigin.x,
315 gm.gmptGlyphOrigin.y,
316 gm.gmCellIncX,gm.gmCellIncY,
317 (const GLubyte * )lpBits);
318
319 GlobalUnlock(hBits);
320 GlobalFree(hBits);
321
322 glEndList( );
323 }
324
325 return TRUE;
326}
327
328GLAPI BOOL GLWINAPI wglUseFontBitmapsW(HDC hdc,DWORD first,DWORD count,DWORD listBase)
329{
330 return FALSE;
331}
332
333GLAPI BOOL GLWINAPI wglUseFontOutlinesA(HDC hdc,DWORD first,DWORD count,
334 DWORD listBase,FLOAT deviation,
335 FLOAT extrusion,int format,
336 LPGLYPHMETRICSFLOAT lpgmf)
337{
338 SetLastError(0);
339 return(FALSE);
340}
341
342GLAPI BOOL GLWINAPI wglUseFontOutlinesW(HDC hdc,DWORD first,DWORD count,
343 DWORD listBase,FLOAT deviation,
344 FLOAT extrusion,int format,
345 LPGLYPHMETRICSFLOAT lpgmf)
346{
347 SetLastError(0);
348 return(FALSE);
349}
350
351GLAPI BOOL GLWINAPI wglDescribeLayerPlane(HDC hdc,int iPixelFormat,
352 int iLayerPlane,UINT nBytes,
353 LAYERPLANEDESCRIPTOR *plpd)
354{
355 SetLastError(0);
356 return(FALSE);
357}
358
359GLAPI int GLWINAPI wglSetLayerPaletteEntries(HDC hdc,int iLayerPlane,
360 int iStart,int cEntries,
361 CONST COLORREF *pcr)
362{
363 SetLastError(0);
364 return(0);
365}
366
367GLAPI int GLWINAPI wglGetLayerPaletteEntries(HDC hdc,int iLayerPlane,
368 int iStart,int cEntries,
369 COLORREF *pcr)
370{
371 SetLastError(0);
372 return(0);
373}
374
375GLAPI BOOL GLWINAPI wglRealizeLayerPalette(HDC hdc,int iLayerPlane,BOOL bRealize)
376{
377 SetLastError(0);
378 return(FALSE);
379}
380
381GLAPI BOOL GLWINAPI wglSwapLayerBuffers(HDC hdc,UINT fuPlanes)
382{
383 if( !hdc )
384 {
385 WMesaSwapBuffers();
386 return(TRUE);
387 }
388 SetLastError(0);
389 return(FALSE);
390}
391
392GLAPI int GLWINAPI wglChoosePixelFormat(HDC hdc,
393 CONST PIXELFORMATDESCRIPTOR *ppfd)
394{
395 int i,best = -1,bestdelta = 0x7FFFFFFF,delta,qt_valid_pix;
396
397 qt_valid_pix = qt_pix;
398 if(ppfd->nSize != sizeof(PIXELFORMATDESCRIPTOR) || ppfd->nVersion != 1)
399 {
400 SetLastError(0);
401 return(0);
402 }
403 for(i = 0;i < qt_valid_pix;i++)
404 {
405 delta = 0;
406 if(
407 (ppfd->dwFlags & PFD_DRAW_TO_WINDOW) &&
408 !(pix[i].pfd.dwFlags & PFD_DRAW_TO_WINDOW))
409 continue;
410 if(
411 (ppfd->dwFlags & PFD_DRAW_TO_BITMAP) &&
412 !(pix[i].pfd.dwFlags & PFD_DRAW_TO_BITMAP))
413 continue;
414 if(
415 (ppfd->dwFlags & PFD_SUPPORT_GDI) &&
416 !(pix[i].pfd.dwFlags & PFD_SUPPORT_GDI))
417 continue;
418 if(
419 (ppfd->dwFlags & PFD_SUPPORT_OPENGL) &&
420 !(pix[i].pfd.dwFlags & PFD_SUPPORT_OPENGL))
421 continue;
422 if(
423 !(ppfd->dwFlags & PFD_DOUBLEBUFFER_DONTCARE) &&
424 ((ppfd->dwFlags & PFD_DOUBLEBUFFER) != (pix[i].pfd.dwFlags & PFD_DOUBLEBUFFER)))
425 continue;
426 if(
427 !(ppfd->dwFlags & PFD_STEREO_DONTCARE) &&
428 ((ppfd->dwFlags & PFD_STEREO) != (pix[i].pfd.dwFlags & PFD_STEREO)))
429 continue;
430 if(ppfd->iPixelType != pix[i].pfd.iPixelType)
431 delta++;
432 if(delta < bestdelta)
433 {
434 best = i + 1;
435 bestdelta = delta;
436 if(bestdelta == 0)
437 break;
438 }
439 }
440 if(best == -1)
441 {
442 SetLastError(0);
443 return(0);
444 }
445 return(best);
446}
447
448GLAPI int GLWINAPI wglDescribePixelFormat(HDC hdc,int iPixelFormat,UINT nBytes,
449 LPPIXELFORMATDESCRIPTOR ppfd)
450{
451 int qt_valid_pix;
452
453 qt_valid_pix = qt_pix;
454 if(iPixelFormat < 1 || iPixelFormat > qt_valid_pix || nBytes != sizeof(PIXELFORMATDESCRIPTOR))
455 {
456 SetLastError(0);
457 return(0);
458 }
459 *ppfd = pix[iPixelFormat - 1].pfd;
460 return(qt_valid_pix);
461}
462
463/*
464* GetProcAddress - return the address of an appropriate extension
465*/
466GLAPI PROC GLWINAPI wglGetProcAddress(LPCSTR lpszProc)
467{
468 int i;
469 for(i = 0;i < qt_ext;i++)
470 if(!strcmp(lpszProc,ext[i].name))
471 return(ext[i].proc);
472
473 SetLastError(0);
474 return(NULL);
475}
476
477GLAPI int GLWINAPI wglGetPixelFormat(HDC hdc)
478{
479 if(curPFD == 0)
480 {
481 SetLastError(0);
482 return(0);
483 }
484 return(curPFD);
485}
486
487GLAPI BOOL GLWINAPI wglSetPixelFormat(HDC hdc, int iPixelFormat,
488 PIXELFORMATDESCRIPTOR *ppfd)
489{
490 int qt_valid_pix;
491
492 qt_valid_pix = qt_pix;
493 if(iPixelFormat < 1 || iPixelFormat > qt_valid_pix || ppfd->nSize != sizeof(PIXELFORMATDESCRIPTOR))
494 {
495 SetLastError(0);
496 return(FALSE);
497 }
498 curPFD = iPixelFormat;
499 return(TRUE);
500}
501
502GLAPI BOOL GLWINAPI wglSwapBuffers(HDC hdc)
503{
504 if (ctx_current < 0)
505 return FALSE;
506
507 if(wgl_ctx[ctx_current].ctx == NULL) {
508 SetLastError(0);
509 return(FALSE);
510 }
511 WMesaSwapBuffers();
512 return(TRUE);
513}
514
515#endif /* WIN32 or __WIN32OS2__ */
Note: See TracBrowser for help on using the repository browser.