quartz: Win64 printf format warning fixes.
[wine] / dlls / gdi / opengl.c
1 /*
2  * OpenGL function forwarding to the display driver
3  *
4  * Copyright (c) 1999 Lionel Ulmer
5  * Copyright (c) 2005 Raphael Junqueira
6  * Copyright (c) 2006 Roderick Colenbrander
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21  */
22
23 #include "config.h"
24 #include "wine/port.h"
25
26 #include <stdarg.h>
27 #include <string.h>
28 #include <stdlib.h>
29
30 #include "windef.h"
31 #include "winbase.h"
32 #include "wingdi.h"
33 #include "winerror.h"
34 #include "gdi.h"
35 #include "gdi_private.h"
36 #include "wine/debug.h"
37
38 WINE_DEFAULT_DEBUG_CHANNEL(wgl);
39
40 static HDC default_hdc = 0;
41
42 /* We route all wgl functions from opengl32.dll through gdi32.dll to
43  * the display driver. Various wgl calls have a hDC as one of their parameters.
44  * Using DC_GetDCPtr we get access to the functions exported by the driver.
45  * Some functions don't receive a hDC. This function creates a global hdc and
46  * if there's already a global hdc, it returns it.
47  */
48 static DC* OPENGL_GetDefaultDC()
49 {
50     if(!default_hdc)
51         default_hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
52         
53     return DC_GetDCPtr(default_hdc);
54 }
55
56 /***********************************************************************
57  *              wglCreateContext (OPENGL32.@)
58  */
59 HGLRC WINAPI wglCreateContext(HDC hdc)
60 {
61     HGLRC ret = 0;
62     DC * dc = DC_GetDCPtr( hdc );
63
64     TRACE("(%p)\n",hdc);
65
66     if (!dc) return 0;
67
68     if (!dc->funcs->pwglCreateContext) FIXME(" :stub\n");
69     else ret = dc->funcs->pwglCreateContext(dc->physDev);
70
71     GDI_ReleaseObj( hdc );
72     return ret;
73 }
74
75 /***********************************************************************
76  *              wglMakeCurrent (OPENGL32.@)
77  */
78 BOOL WINAPI wglMakeCurrent(HDC hdc, HGLRC hglrc)
79 {
80     BOOL ret = FALSE;
81     DC * dc = NULL;
82
83     /* When the context hglrc is NULL, the HDC is ignored and can be NULL.
84      * In that case use the global hDC to get access to the driver.  */
85     if(hglrc == NULL)
86         dc = OPENGL_GetDefaultDC();
87     else
88         dc = DC_GetDCPtr( hdc );
89
90     TRACE("hdc: (%p), hglrc: (%p)\n", hdc, hglrc);
91
92     if (!dc) return FALSE;
93
94     if (!dc->funcs->pwglMakeCurrent) FIXME(" :stub\n");
95     else ret = dc->funcs->pwglMakeCurrent(dc->physDev,hglrc);
96
97     if(hglrc == NULL)
98         GDI_ReleaseObj(default_hdc);
99     else
100         GDI_ReleaseObj(hdc);
101
102     return ret;
103 }
104
105 /***********************************************************************
106  *              wglUseFontBitmapsA (OPENGL32.@)
107  */
108 BOOL WINAPI wglUseFontBitmapsA(HDC hdc, DWORD first, DWORD count, DWORD listBase)
109 {
110     BOOL ret = FALSE;
111     DC * dc = DC_GetDCPtr( hdc );
112
113     TRACE("(%p, %d, %d, %d)\n", hdc, first, count, listBase);
114
115     if (!dc) return FALSE;
116
117     if (!dc->funcs->pwglUseFontBitmapsA) FIXME(" :stub\n");
118     else ret = dc->funcs->pwglUseFontBitmapsA(dc->physDev, first, count, listBase);
119
120     GDI_ReleaseObj( hdc);
121     return ret;
122 }
123
124 /***********************************************************************
125  *              wglUseFontBitmapsW (OPENGL32.@)
126  */
127 BOOL WINAPI wglUseFontBitmapsW(HDC hdc, DWORD first, DWORD count, DWORD listBase)
128 {
129     BOOL ret = FALSE;
130     DC * dc = DC_GetDCPtr( hdc );
131
132     TRACE("(%p, %d, %d, %d)\n", hdc, first, count, listBase);
133
134     if (!dc) return FALSE;
135
136     if (!dc->funcs->pwglUseFontBitmapsW) FIXME(" :stub\n");
137     else ret = dc->funcs->pwglUseFontBitmapsW(dc->physDev, first, count, listBase);
138
139     GDI_ReleaseObj( hdc);
140     return ret;
141 }