Better windows handling.
[wine] / dlls / ddraw / direct3d_main.c
1 /*
2  * Copyright 2000 Marcus Meissner
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 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  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19 #include "config.h"
20
21 #include <assert.h>
22 #ifdef HAVE_UNISTD_H
23 # include <unistd.h>
24 #endif
25 #include <fcntl.h>
26 #include <stdarg.h>
27 #include <string.h>
28 #include <stdio.h>
29
30 #include "winerror.h"
31 #include "windef.h"
32 #include "winbase.h"
33 #include "wingdi.h"
34 #include "ddraw.h"
35 #include "d3d.h"
36 #include "wine/debug.h"
37
38 #include "d3d_private.h"
39
40 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
41
42
43 HRESULT WINAPI
44 Main_IDirect3DImpl_1_Initialize(LPDIRECT3D iface,
45                                 REFIID riid)
46 {
47     ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D, iface);
48     TRACE("(%p/%p)->(%s) no-op...\n", This, iface, debugstr_guid(riid));
49     return D3D_OK;
50 }
51
52 HRESULT WINAPI
53 Main_IDirect3DImpl_3_2T_1T_EnumDevices(LPDIRECT3D3 iface,
54                                        LPD3DENUMDEVICESCALLBACK lpEnumDevicesCallback,
55                                        LPVOID lpUserArg)
56 {
57     ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
58     FIXME("(%p/%p)->(%p,%p): stub!\n", This, iface, lpEnumDevicesCallback, lpUserArg);
59     return D3D_OK;
60 }
61
62 HRESULT WINAPI
63 Main_IDirect3DImpl_3_2T_1T_CreateLight(LPDIRECT3D3 iface,
64                                        LPDIRECT3DLIGHT* lplpDirect3DLight,
65                                        IUnknown* pUnkOuter)
66 {
67     ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
68     FIXME("(%p/%p)->(%p,%p): stub!\n", This, iface, lplpDirect3DLight, pUnkOuter);
69     return D3D_OK;
70 }
71
72 HRESULT WINAPI
73 Main_IDirect3DImpl_3_2T_1T_CreateMaterial(LPDIRECT3D3 iface,
74                                           LPDIRECT3DMATERIAL3* lplpDirect3DMaterial3,
75                                           IUnknown* pUnkOuter)
76 {
77     ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
78     FIXME("(%p/%p)->(%p,%p): stub!\n", This, iface, lplpDirect3DMaterial3, pUnkOuter);
79     return D3D_OK;
80 }
81
82 HRESULT WINAPI
83 Main_IDirect3DImpl_3_2T_1T_CreateViewport(LPDIRECT3D3 iface,
84                                           LPDIRECT3DVIEWPORT3* lplpD3DViewport3,
85                                           IUnknown* pUnkOuter)
86 {
87     ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
88     FIXME("(%p/%p)->(%p,%p): stub!\n", This, iface, lplpD3DViewport3, pUnkOuter);
89     return D3D_OK;
90 }
91
92 HRESULT WINAPI
93 Main_IDirect3DImpl_3_2T_1T_FindDevice(LPDIRECT3D3 iface,
94                                       LPD3DFINDDEVICESEARCH lpD3DDFS,
95                                       LPD3DFINDDEVICERESULT lpD3DFDR)
96 {
97     ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
98     FIXME("(%p/%p)->(%p,%p): stub!\n", This, iface, lpD3DDFS, lpD3DFDR);
99     return D3D_OK;
100 }
101
102 HRESULT WINAPI
103 Main_IDirect3DImpl_2_CreateDevice(LPDIRECT3D2 iface,
104                                   REFCLSID rclsid,
105                                   LPDIRECTDRAWSURFACE lpDDS,
106                                   LPDIRECT3DDEVICE2* lplpD3DDevice2)
107 {
108     ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D2, iface);
109     FIXME("(%p/%p)->(%s,%p,%p): stub!\n", This, iface, debugstr_guid(rclsid), lpDDS, lplpD3DDevice2);
110     return D3D_OK;
111 }
112
113 HRESULT WINAPI
114 Main_IDirect3DImpl_3_CreateDevice(LPDIRECT3D3 iface,
115                                   REFCLSID rclsid,
116                                   LPDIRECTDRAWSURFACE4 lpDDS,
117                                   LPDIRECT3DDEVICE3* lplpD3DDevice3,
118                                   LPUNKNOWN lpUnk)
119 {
120     ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
121     FIXME("(%p/%p)->(%s,%p,%p,%p): stub!\n", This, iface, debugstr_guid(rclsid), lpDDS, lplpD3DDevice3, lpUnk);
122     return D3D_OK;
123 }
124
125 HRESULT WINAPI
126 Main_IDirect3DImpl_7_3T_EnumZBufferFormats(LPDIRECT3D7 iface,
127                                            REFCLSID riidDevice,
128                                            LPD3DENUMPIXELFORMATSCALLBACK lpEnumCallback,
129                                            LPVOID lpContext)
130 {
131     ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D7, iface);
132     FIXME("(%p/%p)->(%s,%p,%p): stub!\n", This, iface, debugstr_guid(riidDevice), lpEnumCallback, lpContext);
133     return D3D_OK;
134 }
135
136 HRESULT WINAPI
137 Main_IDirect3DImpl_7_3T_EvictManagedTextures(LPDIRECT3D7 iface)
138 {
139     ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D7, iface);
140     FIXME("(%p/%p)->(): stub!\n", This, iface);
141     return D3D_OK;
142 }
143
144 HRESULT WINAPI
145 Main_IDirect3DImpl_7_EnumDevices(LPDIRECT3D7 iface,
146                                  LPD3DENUMDEVICESCALLBACK7 lpEnumDevicesCallback,
147                                  LPVOID lpUserArg)
148 {
149     ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D7, iface);
150     FIXME("(%p/%p)->(%p,%p): stub!\n", This, iface, lpEnumDevicesCallback, lpUserArg);
151     return D3D_OK;
152 }
153
154 HRESULT WINAPI
155 Main_IDirect3DImpl_7_CreateDevice(LPDIRECT3D7 iface,
156                                   REFCLSID rclsid,
157                                   LPDIRECTDRAWSURFACE7 lpDDS,
158                                   LPDIRECT3DDEVICE7* lplpD3DDevice)
159 {
160     ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D7, iface);
161     FIXME("(%p/%p)->(%s,%p,%p): stub!\n", This, iface, debugstr_guid(rclsid), lpDDS, lplpD3DDevice);
162     return D3D_OK;
163 }
164
165 HRESULT WINAPI
166 Main_IDirect3DImpl_7_3T_CreateVertexBuffer(LPDIRECT3D7 iface,
167                                            LPD3DVERTEXBUFFERDESC lpD3DVertBufDesc,
168                                            LPDIRECT3DVERTEXBUFFER7* lplpD3DVertBuf,
169                                            DWORD dwFlags)
170 {
171     ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D7, iface);
172     FIXME("(%p/%p)->(%p,%p,%08lx): stub!\n", This, iface, lpD3DVertBufDesc, lplpD3DVertBuf, dwFlags);
173     return D3D_OK;
174 }
175
176 HRESULT WINAPI
177 Thunk_IDirect3DImpl_7_QueryInterface(LPDIRECT3D7 iface,
178                                      REFIID riid,
179                                      LPVOID* obp)
180 {
181     TRACE("(%p)->(%s,%p) thunking to IDirectDraw7 interface.\n", iface, debugstr_guid(riid), obp);
182     return IDirectDraw7_QueryInterface(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D7, IDirectDraw7, iface),
183                                        riid,
184                                        obp);
185 }
186
187 HRESULT WINAPI
188 Thunk_IDirect3DImpl_3_QueryInterface(LPDIRECT3D3 iface,
189                                      REFIID riid,
190                                      LPVOID* obp)
191 {
192     TRACE("(%p)->(%s,%p) thunking to IDirectDraw7 interface.\n", iface, debugstr_guid(riid), obp);
193     return IDirectDraw7_QueryInterface(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D3, IDirectDraw7, iface),
194                                        riid,
195                                        obp);
196 }
197
198 HRESULT WINAPI
199 Thunk_IDirect3DImpl_2_QueryInterface(LPDIRECT3D2 iface,
200                                      REFIID riid,
201                                      LPVOID* obp)
202 {
203     TRACE("(%p)->(%s,%p) thunking to IDirectDraw7 interface.\n", iface, debugstr_guid(riid), obp);
204     return IDirectDraw7_QueryInterface(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D2, IDirectDraw7, iface),
205                                        riid,
206                                        obp);
207 }
208
209 HRESULT WINAPI
210 Thunk_IDirect3DImpl_1_QueryInterface(LPDIRECT3D iface,
211                                      REFIID riid,
212                                      LPVOID* obp)
213 {
214     TRACE("(%p)->(%s,%p) thunking to IDirectDraw7 interface.\n", iface, debugstr_guid(riid), obp);
215     return IDirectDraw7_QueryInterface(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D, IDirectDraw7, iface),
216                                        riid,
217                                        obp);
218 }
219
220 ULONG WINAPI
221 Thunk_IDirect3DImpl_7_AddRef(LPDIRECT3D7 iface)
222 {
223     TRACE("(%p)->() thunking to IDirectDraw7 interface.\n", iface);
224     return IDirectDraw7_AddRef(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D7, IDirectDraw7, iface));
225 }
226
227 ULONG WINAPI
228 Thunk_IDirect3DImpl_3_AddRef(LPDIRECT3D3 iface)
229 {
230     TRACE("(%p)->() thunking to IDirectDraw7 interface.\n", iface);
231     return IDirectDraw7_AddRef(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D3, IDirectDraw7, iface));
232 }
233
234 ULONG WINAPI
235 Thunk_IDirect3DImpl_2_AddRef(LPDIRECT3D2 iface)
236 {
237     TRACE("(%p)->() thunking to IDirectDraw7 interface.\n", iface);
238     return IDirectDraw7_AddRef(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D2, IDirectDraw7, iface));
239 }
240
241 ULONG WINAPI
242 Thunk_IDirect3DImpl_1_AddRef(LPDIRECT3D iface)
243 {
244     TRACE("(%p)->() thunking to IDirectDraw7 interface.\n", iface);
245     return IDirectDraw7_AddRef(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D, IDirectDraw7, iface));
246 }
247
248 ULONG WINAPI
249 Thunk_IDirect3DImpl_7_Release(LPDIRECT3D7 iface)
250 {
251     TRACE("(%p)->() thunking to IDirectDraw7 interface.\n", iface);
252     return IDirectDraw7_Release(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D7, IDirectDraw7, iface));
253 }
254
255 ULONG WINAPI
256 Thunk_IDirect3DImpl_3_Release(LPDIRECT3D3 iface)
257 {
258     TRACE("(%p)->() thunking to IDirectDraw7 interface.\n", iface);
259     return IDirectDraw7_Release(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D3, IDirectDraw7, iface));
260 }
261
262 ULONG WINAPI
263 Thunk_IDirect3DImpl_2_Release(LPDIRECT3D2 iface)
264 {
265     TRACE("(%p)->() thunking to IDirectDraw7 interface.\n", iface);
266     return IDirectDraw7_Release(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D2, IDirectDraw7, iface));
267 }
268
269 ULONG WINAPI
270 Thunk_IDirect3DImpl_1_Release(LPDIRECT3D iface)
271 {
272     TRACE("(%p)->() thunking to IDirectDraw7 interface.\n", iface);
273     return IDirectDraw7_Release(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D, IDirectDraw7, iface));
274 }
275
276 HRESULT WINAPI
277 Thunk_IDirect3DImpl_3_EnumZBufferFormats(LPDIRECT3D3 iface,
278                                          REFCLSID riidDevice,
279                                          LPD3DENUMPIXELFORMATSCALLBACK lpEnumCallback,
280                                          LPVOID lpContext)
281 {
282     TRACE("(%p)->(%s,%p,%p) thunking to IDirect3D7 interface.\n", iface, debugstr_guid(riidDevice), lpEnumCallback, lpContext);
283     return IDirect3D7_EnumZBufferFormats(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D3, IDirect3D7, iface),
284                                          riidDevice,
285                                          lpEnumCallback,
286                                          lpContext);
287 }
288
289 HRESULT WINAPI
290 Thunk_IDirect3DImpl_3_EvictManagedTextures(LPDIRECT3D3 iface)
291 {
292     TRACE("(%p)->() thunking to IDirect3D7 interface.\n", iface);
293     return IDirect3D7_EvictManagedTextures(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D3, IDirect3D7, iface));
294 }
295
296 HRESULT WINAPI
297 Thunk_IDirect3DImpl_2_EnumDevices(LPDIRECT3D2 iface,
298                                   LPD3DENUMDEVICESCALLBACK lpEnumDevicesCallback,
299                                   LPVOID lpUserArg)
300 {
301     TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", iface, lpEnumDevicesCallback, lpUserArg);
302     return IDirect3D3_EnumDevices(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D2, IDirect3D3, iface),
303                                   lpEnumDevicesCallback,
304                                   lpUserArg);
305 }
306
307 HRESULT WINAPI
308 Thunk_IDirect3DImpl_2_CreateLight(LPDIRECT3D2 iface,
309                                   LPDIRECT3DLIGHT* lplpDirect3DLight,
310                                   IUnknown* pUnkOuter)
311 {
312     TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", iface, lplpDirect3DLight, pUnkOuter);
313     return IDirect3D3_CreateLight(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D2, IDirect3D3, iface),
314                                   lplpDirect3DLight,
315                                   pUnkOuter);
316 }
317
318 HRESULT WINAPI
319 Thunk_IDirect3DImpl_1_CreateLight(LPDIRECT3D iface,
320                                   LPDIRECT3DLIGHT* lplpDirect3DLight,
321                                   IUnknown* pUnkOuter)
322 {
323     TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", iface, lplpDirect3DLight, pUnkOuter);
324     return IDirect3D3_CreateLight(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D, IDirect3D3, iface),
325                                   lplpDirect3DLight,
326                                   pUnkOuter);
327 }
328
329 HRESULT WINAPI
330 Thunk_IDirect3DImpl_1_CreateMaterial(LPDIRECT3D iface,
331                                      LPDIRECT3DMATERIAL* lplpDirect3DMaterial,
332                                      IUnknown* pUnkOuter)
333 {
334     HRESULT ret;
335     LPDIRECT3DMATERIAL3 ret_val;
336
337     TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", iface, lplpDirect3DMaterial, pUnkOuter);
338     ret = IDirect3D3_CreateMaterial(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D, IDirect3D3, iface),
339                                     &ret_val,
340                                     pUnkOuter);
341
342     *lplpDirect3DMaterial = COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial3, IDirect3DMaterial, ret_val);
343
344     TRACE(" returning interface %p.\n", *lplpDirect3DMaterial);
345     
346     return ret;
347 }
348
349 HRESULT WINAPI
350 Thunk_IDirect3DImpl_1_CreateViewport(LPDIRECT3D iface,
351                                      LPDIRECT3DVIEWPORT* lplpD3DViewport,
352                                      IUnknown* pUnkOuter)
353 {
354     TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", iface, lplpD3DViewport, pUnkOuter);
355     return IDirect3D3_CreateViewport(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D, IDirect3D3, iface),
356                                     (LPDIRECT3DVIEWPORT3 *) lplpD3DViewport /* No need to cast here */,
357                                     pUnkOuter);
358 }
359
360 HRESULT WINAPI
361 Thunk_IDirect3DImpl_2_CreateMaterial(LPDIRECT3D2 iface,
362                                      LPDIRECT3DMATERIAL2* lplpDirect3DMaterial2,
363                                      IUnknown* pUnkOuter)
364 {
365     HRESULT ret;
366     LPDIRECT3DMATERIAL3 ret_val;
367
368     TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", iface, lplpDirect3DMaterial2, pUnkOuter);
369     ret = IDirect3D3_CreateMaterial(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D2, IDirect3D3, iface),
370                                     &ret_val,
371                                     pUnkOuter);
372
373     *lplpDirect3DMaterial2 = COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial3, IDirect3DMaterial2, ret_val);
374
375     TRACE(" returning interface %p.\n", *lplpDirect3DMaterial2);
376     
377     return ret;
378 }
379
380 HRESULT WINAPI
381 Thunk_IDirect3DImpl_2_CreateViewport(LPDIRECT3D2 iface,
382                                      LPDIRECT3DVIEWPORT2* lplpD3DViewport2,
383                                      IUnknown* pUnkOuter)
384 {
385     TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", iface, lplpD3DViewport2, pUnkOuter);
386     return IDirect3D3_CreateViewport(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D2, IDirect3D3, iface),
387                                      (LPDIRECT3DVIEWPORT3 *) lplpD3DViewport2 /* No need to cast here */,
388                                      pUnkOuter);
389 }
390
391
392 HRESULT WINAPI
393 Thunk_IDirect3DImpl_3_CreateVertexBuffer(LPDIRECT3D3 iface,
394                                          LPD3DVERTEXBUFFERDESC lpD3DVertBufDesc,
395                                          LPDIRECT3DVERTEXBUFFER* lplpD3DVertBuf,
396                                          DWORD dwFlags,
397                                          LPUNKNOWN lpUnk)
398 {
399     HRESULT ret;
400     LPDIRECT3DVERTEXBUFFER7 ret_val;
401
402     TRACE("(%p)->(%p,%p,%08lx,%p) thunking to IDirect3D7 interface.\n", iface, lpD3DVertBufDesc, lplpD3DVertBuf, dwFlags, lpUnk);
403     
404     /* dwFlags is not used in the D3D7 interface, use the vertex buffer description instead */
405     if (dwFlags & D3DDP_DONOTCLIP) lpD3DVertBufDesc->dwCaps |= D3DVBCAPS_DONOTCLIP;
406
407     ret = IDirect3D7_CreateVertexBuffer(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D3, IDirect3D7, iface),
408                                         lpD3DVertBufDesc,
409                                         &ret_val,
410                                         dwFlags);
411
412     *lplpD3DVertBuf = COM_INTERFACE_CAST(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, IDirect3DVertexBuffer, ret_val);
413
414     TRACE(" returning interface %p.\n", *lplpD3DVertBuf);
415     
416     return ret;
417 }
418
419 HRESULT WINAPI
420 Thunk_IDirect3DImpl_1_FindDevice(LPDIRECT3D iface,
421                                  LPD3DFINDDEVICESEARCH lpD3DDFS,
422                                  LPD3DFINDDEVICERESULT lplpD3DDevice)
423 {
424     TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", iface, lpD3DDFS, lplpD3DDevice);
425     return IDirect3D3_FindDevice(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D, IDirect3D3, iface),
426                                  lpD3DDFS,
427                                  lplpD3DDevice);
428 }
429
430 HRESULT WINAPI
431 Thunk_IDirect3DImpl_2_FindDevice(LPDIRECT3D2 iface,
432                                  LPD3DFINDDEVICESEARCH lpD3DDFS,
433                                  LPD3DFINDDEVICERESULT lpD3DFDR)
434 {
435     TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", iface, lpD3DDFS, lpD3DFDR);
436     return IDirect3D3_FindDevice(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D2, IDirect3D3, iface),
437                                  lpD3DDFS,
438                                  lpD3DFDR);
439 }