- Made sure that the files that contains the declarations
[wine.git] / dlls / ddraw / direct3d / mesa.c
blobea4d5b9d5fb89b2ce0594d00ffc45f8bfb88ec22
1 #include "config.h"
3 #include <assert.h>
4 #include <unistd.h>
5 #include <fcntl.h>
6 #include <string.h>
7 #include <stdio.h>
9 #include "d3d.h"
10 #include "ddraw.h"
11 #include "winerror.h"
13 #include "ddraw_private.h"
14 #include "mesa_private.h"
15 #include "options.h"
17 #include "debugtools.h"
19 DEFAULT_DEBUG_CHANNEL(ddraw);
21 /*******************************************************************************
22 * IDirect3D
24 static HRESULT WINAPI MESA_IDirect3DImpl_QueryInterface(
25 LPDIRECT3D iface,REFIID refiid,LPVOID *obj
26 ) {
27 ICOM_THIS(IDirect3DImpl,iface);
28 /* FIXME: Not sure if this is correct */
30 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(refiid),obj);
31 if (( IsEqualGUID( &IID_IDirectDraw, refiid ) ) ||
32 ( IsEqualGUID (&IID_IDirectDraw2, refiid ) ) ||
33 ( IsEqualGUID( &IID_IDirectDraw4, refiid ) )
34 ) {
35 *obj = This->ddraw;
36 IDirect3D_AddRef(iface);
37 TRACE(" Creating IDirectDrawX interface (%p)\n", *obj);
38 return S_OK;
40 if (( IsEqualGUID( &IID_IDirect3D, refiid ) ) ||
41 ( IsEqualGUID( &IID_IUnknown, refiid ) ) ) {
42 *obj = This;
43 IDirect3D_AddRef(iface);
44 TRACE(" Creating IDirect3D interface (%p)\n", *obj);
45 return S_OK;
47 if ( IsEqualGUID( &IID_IDirect3D2, refiid ) ) {
48 IDirect3D2Impl* d3d;
50 d3d = HeapAlloc(GetProcessHeap(),0,sizeof(*d3d));
51 d3d->ref = 1;
52 d3d->ddraw = This->ddraw;
53 IDirect3D_AddRef(iface);
54 ICOM_VTBL(d3d) = &mesa_d3d2vt;
55 *obj = d3d;
56 TRACE(" Creating IDirect3D2 interface (%p)\n", *obj);
57 return S_OK;
59 FIXME("(%p):interface for IID %s NOT found!\n",This,debugstr_guid(refiid));
60 return OLE_E_ENUM_NOMORE;
63 static ULONG WINAPI MESA_IDirect3DImpl_Release(LPDIRECT3D iface)
65 ICOM_THIS(IDirect3DImpl,iface);
66 TRACE("(%p)->() decrementing from %lu.\n", This, This->ref );
68 if (!--(This->ref)) {
69 IDirectDraw2_Release((IDirectDraw2*)This->ddraw);
70 HeapFree(GetProcessHeap(),0,This);
71 return S_OK;
73 return This->ref;
76 static HRESULT WINAPI MESA_IDirect3DImpl_EnumDevices(
77 LPDIRECT3D iface, LPD3DENUMDEVICESCALLBACK cb, LPVOID context
78 ) {
79 ICOM_THIS(IDirect3DImpl,iface);
80 FIXME("(%p)->(%p,%p),stub!\n",This,cb,context);
82 /* Call functions defined in d3ddevices.c */
83 if (!d3d_OpenGL_dx3(cb, context))
84 return D3D_OK;
86 return D3D_OK;
89 static HRESULT WINAPI MESA_IDirect3DImpl_CreateLight(
90 LPDIRECT3D iface, LPDIRECT3DLIGHT *lplight, IUnknown *lpunk
91 ) {
92 ICOM_THIS(IDirect3DImpl,iface);
93 TRACE("(%p)->(%p,%p): stub\n", This, lplight, lpunk);
95 /* Call the creation function that is located in d3dlight.c */
96 *lplight = d3dlight_create_dx3(This);
98 return D3D_OK;
101 static HRESULT WINAPI MESA_IDirect3DImpl_CreateMaterial(
102 LPDIRECT3D iface, LPDIRECT3DMATERIAL *lpmaterial, IUnknown *lpunk
104 ICOM_THIS(IDirect3DImpl,iface);
105 TRACE("(%p)->(%p,%p): stub\n", This, lpmaterial, lpunk);
106 /* Call the creation function that is located in d3dviewport.c */
107 *lpmaterial = d3dmaterial_create(This);
108 return D3D_OK;
111 static HRESULT WINAPI MESA_IDirect3DImpl_CreateViewport(
112 LPDIRECT3D iface, LPDIRECT3DVIEWPORT *lpviewport, IUnknown *lpunk
114 ICOM_THIS(IDirect3DImpl,iface);
115 TRACE("(%p)->(%p,%p): stub\n", This, lpviewport, lpunk);
117 /* Call the creation function that is located in d3dviewport.c */
118 *lpviewport = d3dviewport_create(This);
120 return D3D_OK;
123 static HRESULT WINAPI MESA_IDirect3DImpl_FindDevice(
124 LPDIRECT3D iface, LPD3DFINDDEVICESEARCH lpfinddevsrc,
125 LPD3DFINDDEVICERESULT lpfinddevrst)
127 ICOM_THIS(IDirect3DImpl,iface);
128 FIXME("(%p)->(%p,%p): stub\n", This, lpfinddevsrc, lpfinddevrst);
130 return D3D_OK;
133 ICOM_VTABLE(IDirect3D) mesa_d3dvt =
135 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
136 MESA_IDirect3DImpl_QueryInterface,
137 IDirect3DImpl_AddRef,
138 MESA_IDirect3DImpl_Release,
139 IDirect3DImpl_Initialize,
140 MESA_IDirect3DImpl_EnumDevices,
141 MESA_IDirect3DImpl_CreateLight,
142 MESA_IDirect3DImpl_CreateMaterial,
143 MESA_IDirect3DImpl_CreateViewport,
144 MESA_IDirect3DImpl_FindDevice
147 /*******************************************************************************
148 * IDirect3D2
150 static HRESULT WINAPI MESA_IDirect3D2Impl_QueryInterface(
151 LPDIRECT3D2 iface,REFIID refiid,LPVOID *obj) {
152 ICOM_THIS(IDirect3D2Impl,iface);
154 /* FIXME: Not sure if this is correct */
156 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(refiid),obj);
157 if ( ( IsEqualGUID( &IID_IDirectDraw, refiid ) ) ||
158 ( IsEqualGUID( &IID_IDirectDraw2, refiid ) ) ||
159 ( IsEqualGUID( &IID_IDirectDraw4, refiid ) ) ) {
160 *obj = This->ddraw;
161 IDirect3D2_AddRef(iface);
163 TRACE(" Creating IDirectDrawX interface (%p)\n", *obj);
165 return S_OK;
167 if ( ( IsEqualGUID( &IID_IDirect3D2, refiid ) ) ||
168 ( IsEqualGUID( &IID_IUnknown, refiid ) ) ) {
169 *obj = This;
170 IDirect3D2_AddRef(iface);
172 TRACE(" Creating IDirect3D2 interface (%p)\n", *obj);
174 return S_OK;
176 if ( IsEqualGUID( &IID_IDirect3D, refiid ) ) {
177 IDirect3DImpl* d3d;
179 d3d = HeapAlloc(GetProcessHeap(),0,sizeof(*d3d));
180 d3d->ref = 1;
181 d3d->ddraw = This->ddraw;
182 IDirect3D2_AddRef(iface);
183 ICOM_VTBL(d3d) = &mesa_d3dvt;
184 *obj = d3d;
185 TRACE(" Creating IDirect3D interface (%p)\n", *obj);
186 return S_OK;
188 FIXME("(%p):interface for IID %s NOT found!\n",This,debugstr_guid(refiid));
189 return OLE_E_ENUM_NOMORE;
192 static ULONG WINAPI MESA_IDirect3D2Impl_Release(LPDIRECT3D2 iface) {
193 ICOM_THIS(IDirect3D2Impl,iface);
194 TRACE("(%p)->() decrementing from %lu.\n", This, This->ref );
196 if (!--(This->ref)) {
197 IDirectDraw2_Release((IDirectDraw2*)This->ddraw);
198 HeapFree(GetProcessHeap(),0,This);
199 return S_OK;
201 return This->ref;
204 static HRESULT WINAPI MESA_IDirect3D2Impl_EnumDevices(
205 LPDIRECT3D2 iface,LPD3DENUMDEVICESCALLBACK cb, LPVOID context
207 ICOM_THIS(IDirect3D2Impl,iface);
208 FIXME("(%p)->(%p,%p),stub!\n",This,cb,context);
210 /* Call functions defined in d3ddevices.c */
211 if (!d3d_OpenGL(cb, context))
212 return D3D_OK;
213 return D3D_OK;
216 static HRESULT WINAPI MESA_IDirect3D2Impl_CreateLight(
217 LPDIRECT3D2 iface, LPDIRECT3DLIGHT *lplight, IUnknown *lpunk
219 ICOM_THIS(IDirect3D2Impl,iface);
220 TRACE("(%p)->(%p,%p): stub\n", This, lplight, lpunk);
222 /* Call the creation function that is located in d3dlight.c */
223 *lplight = d3dlight_create(This);
225 return D3D_OK;
228 static HRESULT WINAPI MESA_IDirect3D2Impl_CreateMaterial(
229 LPDIRECT3D2 iface, LPDIRECT3DMATERIAL2 *lpmaterial, IUnknown *lpunk
231 ICOM_THIS(IDirect3D2Impl,iface);
232 TRACE("(%p)->(%p,%p): stub\n", This, lpmaterial, lpunk);
234 /* Call the creation function that is located in d3dviewport.c */
235 *lpmaterial = d3dmaterial2_create(This);
237 return D3D_OK;
240 static HRESULT WINAPI MESA_IDirect3D2Impl_CreateViewport(
241 LPDIRECT3D2 iface, LPDIRECT3DVIEWPORT2 *lpviewport, IUnknown *lpunk
243 ICOM_THIS(IDirect3D2Impl,iface);
244 TRACE("(%p)->(%p,%p): stub\n", This, lpviewport, lpunk);
246 /* Call the creation function that is located in d3dviewport.c */
247 *lpviewport = d3dviewport2_create(This);
249 return D3D_OK;
252 static HRESULT WINAPI MESA_IDirect3D2Impl_FindDevice(
253 LPDIRECT3D2 iface, LPD3DFINDDEVICESEARCH lpfinddevsrc,
254 LPD3DFINDDEVICERESULT lpfinddevrst)
256 ICOM_THIS(IDirect3D2Impl,iface);
257 FIXME("(%p)->(%p,%p): stub\n", This, lpfinddevsrc, lpfinddevrst);
258 return D3D_OK;
261 static HRESULT WINAPI MESA_IDirect3D2Impl_CreateDevice(
262 LPDIRECT3D2 iface, REFCLSID rguid, LPDIRECTDRAWSURFACE surface,
263 LPDIRECT3DDEVICE2 *device)
265 ICOM_THIS(IDirect3D2Impl,iface);
267 FIXME("(%p)->(%s,%p,%p): stub\n",This,debugstr_guid(rguid),surface,device);
269 if (is_OpenGL(rguid, (IDirectDrawSurfaceImpl*)surface, (IDirect3DDevice2Impl**)device, This)) {
270 IDirect3D2_AddRef(iface);
271 return D3D_OK;
274 return DDERR_INVALIDPARAMS;
277 ICOM_VTABLE(IDirect3D2) mesa_d3d2vt =
279 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
280 MESA_IDirect3D2Impl_QueryInterface,
281 IDirect3D2Impl_AddRef,
282 MESA_IDirect3D2Impl_Release,
283 MESA_IDirect3D2Impl_EnumDevices,
284 MESA_IDirect3D2Impl_CreateLight,
285 MESA_IDirect3D2Impl_CreateMaterial,
286 MESA_IDirect3D2Impl_CreateViewport,
287 MESA_IDirect3D2Impl_FindDevice,
288 MESA_IDirect3D2Impl_CreateDevice
291 static HRESULT WINAPI MESA_IDirect3D3Impl_CreateVertexBuffer(
292 LPDIRECT3D3 iface,
293 LPD3DVERTEXBUFFERDESC lpD3DVertBufDesc,
294 LPDIRECT3DVERTEXBUFFER* lplpD3DVertBuf,
295 DWORD dwFlags,
296 LPUNKNOWN lpUnk)
298 FIXME(":stub\n");
299 return D3D_OK;
302 static HRESULT WINAPI MESA_IDirect3D3Impl_EnumZBufferFormats(
303 LPDIRECT3D3 iface,
304 REFCLSID riidDevice,
305 LPD3DENUMPIXELFORMATSCALLBACK lpEnumCallback,
306 LPVOID lpContext)
308 FIXME(":stub\n");
309 return DDERR_NOZBUFFERHW; /* Pretend we don't have valid HW */
312 static HRESULT WINAPI MESA_IDirect3D3Impl_EvictManagedTextures(
313 LPDIRECT3D3 iface)
315 FIXME(":stub\n");
316 return D3D_OK;
320 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
321 # define XCAST(fun) (typeof(mesa_d3d3vt.fun))
322 #else
323 # define XCAST(fun) (void*)
324 #endif
326 ICOM_VTABLE(IDirect3D3) mesa_d3d3vt =
328 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
329 XCAST(QueryInterface)MESA_IDirect3D2Impl_QueryInterface,
330 XCAST(AddRef)IDirect3D2Impl_AddRef,
331 XCAST(Release)MESA_IDirect3D2Impl_Release,
332 XCAST(EnumDevices)MESA_IDirect3D2Impl_EnumDevices,
333 XCAST(CreateLight)MESA_IDirect3D2Impl_CreateLight,
334 XCAST(CreateMaterial)MESA_IDirect3D2Impl_CreateMaterial,
335 XCAST(CreateViewport)MESA_IDirect3D2Impl_CreateViewport,
336 XCAST(FindDevice)MESA_IDirect3D2Impl_FindDevice,
337 XCAST(CreateDevice)MESA_IDirect3D2Impl_CreateDevice,
338 XCAST(CreateVertexBuffer)MESA_IDirect3D3Impl_CreateVertexBuffer,
339 XCAST(EnumZBufferFormats)MESA_IDirect3D3Impl_EnumZBufferFormats,
340 XCAST(EvictManagedTextures)MESA_IDirect3D3Impl_EvictManagedTextures
343 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
344 #undef XCAST
345 #endif
347 HRESULT create_direct3d(LPVOID *obj,IDirectDrawImpl* ddraw) {
348 IDirect3DImpl* d3d;
350 d3d = HeapAlloc(GetProcessHeap(),0,sizeof(*d3d));
351 d3d->ref = 1;
352 d3d->ddraw = (IDirectDrawImpl *) ddraw;
353 d3d->private = NULL; /* unused for now */
354 IDirectDraw_AddRef((LPDIRECTDRAW)ddraw);
355 ICOM_VTBL(d3d) = &mesa_d3dvt;
356 *obj = (LPUNKNOWN)d3d;
357 TRACE(" Created IDirect3D interface (%p)\n", *obj);
359 return S_OK;
362 HRESULT create_direct3d2(LPVOID *obj,IDirectDrawImpl* ddraw) {
363 IDirect3D2Impl* d3d;
365 d3d = HeapAlloc(GetProcessHeap(),0,sizeof(*d3d));
366 d3d->ref = 1;
367 d3d->ddraw = (IDirectDrawImpl *) ddraw;
368 d3d->private = NULL; /* unused for now */
369 IDirectDraw_AddRef((LPDIRECTDRAW)ddraw);
370 ICOM_VTBL(d3d) = &mesa_d3d2vt;
371 *obj = (LPUNKNOWN)d3d;
372 TRACE(" Creating IDirect3D2 interface (%p)\n", *obj);
374 return S_OK;
377 HRESULT create_direct3d3(LPVOID *obj,IDirectDrawImpl* ddraw) {
378 IDirect3D3Impl* d3d;
380 d3d = HeapAlloc(GetProcessHeap(),0,sizeof(*d3d));
381 d3d->ref = 1;
382 d3d->ddraw = (IDirectDrawImpl *) ddraw;
383 d3d->private = NULL; /* unused for now */
385 IDirectDraw_AddRef((LPDIRECTDRAW)ddraw);
386 ICOM_VTBL(d3d) = &mesa_d3d3vt;
387 *obj = (LPUNKNOWN)d3d;
389 TRACE(" Creating IDirect3D3 interface (%p)\n", *obj);
391 return S_OK;