wined3d: Get resource info from the texture in wined3d_surface_cleanup().
[wine.git] / dlls / d3drm / d3drm.c
blob6d756051771ffecfe8f8121da689be1f7f14913e
1 /*
2 * Implementation of IDirect3DRM Interface
4 * Copyright 2010, 2012 Christian Costa
5 * Copyright 2011 André Hentschel
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/debug.h"
24 #define COBJMACROS
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "dxfile.h"
29 #include "rmxfguid.h"
31 #include "d3drm_private.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(d3drm);
35 static const char* get_IID_string(const GUID* guid)
37 if (IsEqualGUID(guid, &IID_IDirect3DRMFrame))
38 return "IID_IDirect3DRMFrame";
39 else if (IsEqualGUID(guid, &IID_IDirect3DRMFrame2))
40 return "IID_IDirect3DRMFrame2";
41 else if (IsEqualGUID(guid, &IID_IDirect3DRMFrame3))
42 return "IID_IDirect3DRMFrame3";
43 else if (IsEqualGUID(guid, &IID_IDirect3DRMMeshBuilder))
44 return "IID_IDirect3DRMMeshBuilder";
45 else if (IsEqualGUID(guid, &IID_IDirect3DRMMeshBuilder2))
46 return "IID_IDirect3DRMMeshBuilder2";
47 else if (IsEqualGUID(guid, &IID_IDirect3DRMMeshBuilder3))
48 return "IID_IDirect3DRMMeshBuilder3";
50 return "?";
53 struct d3drm
55 IDirect3DRM IDirect3DRM_iface;
56 IDirect3DRM2 IDirect3DRM2_iface;
57 IDirect3DRM3 IDirect3DRM3_iface;
58 LONG ref1, ref2, ref3, iface_count;
61 static inline struct d3drm *impl_from_IDirect3DRM(IDirect3DRM *iface)
63 return CONTAINING_RECORD(iface, struct d3drm, IDirect3DRM_iface);
66 static inline struct d3drm *impl_from_IDirect3DRM2(IDirect3DRM2 *iface)
68 return CONTAINING_RECORD(iface, struct d3drm, IDirect3DRM2_iface);
71 static inline struct d3drm *impl_from_IDirect3DRM3(IDirect3DRM3 *iface)
73 return CONTAINING_RECORD(iface, struct d3drm, IDirect3DRM3_iface);
76 static void d3drm_destroy(struct d3drm *d3drm)
78 HeapFree(GetProcessHeap(), 0, d3drm);
79 TRACE("d3drm object %p is being destroyed.\n", d3drm);
82 static HRESULT WINAPI d3drm1_QueryInterface(IDirect3DRM *iface, REFIID riid, void **out)
84 struct d3drm *d3drm = impl_from_IDirect3DRM(iface);
86 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
88 if (IsEqualGUID(riid, &IID_IDirect3DRM)
89 || IsEqualGUID(riid, &IID_IUnknown))
91 *out = &d3drm->IDirect3DRM_iface;
93 else if (IsEqualGUID(riid, &IID_IDirect3DRM2))
95 *out = &d3drm->IDirect3DRM2_iface;
97 else if (IsEqualGUID(riid, &IID_IDirect3DRM3))
99 *out = &d3drm->IDirect3DRM3_iface;
101 else
103 *out = NULL;
104 WARN("%s not implemented, returning CLASS_E_CLASSNOTAVAILABLE.\n", debugstr_guid(riid));
105 return CLASS_E_CLASSNOTAVAILABLE;
108 IUnknown_AddRef((IUnknown *)*out);
109 return S_OK;
112 static ULONG WINAPI d3drm1_AddRef(IDirect3DRM *iface)
114 struct d3drm *d3drm = impl_from_IDirect3DRM(iface);
115 ULONG refcount = InterlockedIncrement(&d3drm->ref1);
117 TRACE("%p increasing refcount to %u.\n", iface, refcount);
119 if (refcount == 1)
120 InterlockedIncrement(&d3drm->iface_count);
122 return refcount;
125 static ULONG WINAPI d3drm1_Release(IDirect3DRM *iface)
127 struct d3drm *d3drm = impl_from_IDirect3DRM(iface);
128 ULONG refcount = InterlockedDecrement(&d3drm->ref1);
130 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
132 if (!refcount && !InterlockedDecrement(&d3drm->iface_count))
133 d3drm_destroy(d3drm);
135 return refcount;
138 static HRESULT WINAPI d3drm1_CreateObject(IDirect3DRM *iface,
139 REFCLSID clsid, IUnknown *outer, REFIID iid, void **out)
141 FIXME("iface %p, clsid %s, outer %p, iid %s, out %p stub!\n",
142 iface, debugstr_guid(clsid), outer, debugstr_guid(iid), out);
144 return E_NOTIMPL;
147 static HRESULT WINAPI d3drm1_CreateFrame(IDirect3DRM *iface,
148 IDirect3DRMFrame *parent_frame, IDirect3DRMFrame **frame)
150 TRACE("iface %p, parent_frame %p, frame %p.\n", iface, parent_frame, frame);
152 return Direct3DRMFrame_create(&IID_IDirect3DRMFrame, (IUnknown *)parent_frame, (IUnknown **)frame);
155 static HRESULT WINAPI d3drm1_CreateMesh(IDirect3DRM *iface, IDirect3DRMMesh **mesh)
157 struct d3drm *d3drm = impl_from_IDirect3DRM(iface);
159 TRACE("iface %p, mesh %p.\n", iface, mesh);
161 return IDirect3DRM3_CreateMesh(&d3drm->IDirect3DRM3_iface, mesh);
164 static HRESULT WINAPI d3drm1_CreateMeshBuilder(IDirect3DRM *iface, IDirect3DRMMeshBuilder **mesh_builder)
166 TRACE("iface %p, mesh_builder %p.\n", iface, mesh_builder);
168 return Direct3DRMMeshBuilder_create(&IID_IDirect3DRMMeshBuilder, (IUnknown **)mesh_builder);
171 static HRESULT WINAPI d3drm1_CreateFace(IDirect3DRM *iface, IDirect3DRMFace **face)
173 TRACE("iface %p, face %p.\n", iface, face);
175 return Direct3DRMFace_create(&IID_IDirect3DRMFace, (IUnknown **)face);
178 static HRESULT WINAPI d3drm1_CreateAnimation(IDirect3DRM *iface, IDirect3DRMAnimation **animation)
180 FIXME("iface %p, animation %p stub!\n", iface, animation);
182 return E_NOTIMPL;
185 static HRESULT WINAPI d3drm1_CreateAnimationSet(IDirect3DRM *iface, IDirect3DRMAnimationSet **set)
187 FIXME("iface %p, set %p stub!\n", iface, set);
189 return E_NOTIMPL;
192 static HRESULT WINAPI d3drm1_CreateTexture(IDirect3DRM *iface,
193 D3DRMIMAGE *image, IDirect3DRMTexture **texture)
195 FIXME("iface %p, image %p, texture %p partial stub.\n", iface, image, texture);
197 return Direct3DRMTexture_create(&IID_IDirect3DRMTexture, (IUnknown **)texture);
200 static HRESULT WINAPI d3drm1_CreateLight(IDirect3DRM *iface,
201 D3DRMLIGHTTYPE type, D3DCOLOR color, IDirect3DRMLight **light)
203 struct d3drm *d3drm = impl_from_IDirect3DRM(iface);
205 TRACE("iface %p, type %#x, color 0x%08x, light %p.\n", iface, type, color, light);
207 return IDirect3DRM3_CreateLight(&d3drm->IDirect3DRM3_iface, type, color, light);
210 static HRESULT WINAPI d3drm1_CreateLightRGB(IDirect3DRM *iface, D3DRMLIGHTTYPE type,
211 D3DVALUE red, D3DVALUE green, D3DVALUE blue, IDirect3DRMLight **light)
213 struct d3drm *d3drm = impl_from_IDirect3DRM(iface);
215 TRACE("iface %p, type %#x, red %.8e, green %.8e, blue %.8e, light %p.\n",
216 iface, type, red, green, blue, light);
218 return IDirect3DRM3_CreateLightRGB(&d3drm->IDirect3DRM3_iface, type, red, green, blue, light);
221 static HRESULT WINAPI d3drm1_CreateMaterial(IDirect3DRM *iface,
222 D3DVALUE power, IDirect3DRMMaterial **material)
224 struct d3drm *d3drm = impl_from_IDirect3DRM(iface);
226 TRACE("iface %p, power %.8e, material %p.\n", iface, power, material);
228 return IDirect3DRM3_CreateMaterial(&d3drm->IDirect3DRM3_iface, power, (IDirect3DRMMaterial2 **)material);
231 static HRESULT WINAPI d3drm1_CreateDevice(IDirect3DRM *iface,
232 DWORD width, DWORD height, IDirect3DRMDevice **device)
234 struct d3drm_device *object;
235 HRESULT hr;
236 FIXME("iface %p, width %u, height %u, device %p partial stub!\n", iface, width, height, device);
238 hr = d3drm_device_create(&object);
239 if (FAILED(hr))
240 return hr;
242 *device = IDirect3DRMDevice_from_impl(object);
244 return D3DRM_OK;
247 static HRESULT WINAPI d3drm1_CreateDeviceFromSurface(IDirect3DRM *iface, GUID *guid,
248 IDirectDraw *ddraw, IDirectDrawSurface *backbuffer, IDirect3DRMDevice **device)
250 struct d3drm *d3drm = impl_from_IDirect3DRM(iface);
251 struct d3drm_device *object;
252 HRESULT hr;
254 TRACE("iface %p, guid %s, ddraw %p, backbuffer %p, device %p.\n",
255 iface, debugstr_guid(guid), ddraw, backbuffer, device);
257 if (!device)
258 return D3DRMERR_BADVALUE;
259 *device = NULL;
261 if (!backbuffer || !ddraw)
262 return D3DRMERR_BADDEVICE;
264 hr = d3drm_device_create(&object);
265 if (FAILED(hr))
266 return hr;
268 hr = d3drm_device_init(object, 1, &d3drm->IDirect3DRM_iface, ddraw, backbuffer, TRUE);
269 if (SUCCEEDED(hr))
270 *device = IDirect3DRMDevice_from_impl(object);
271 else
272 d3drm_device_destroy(object);
274 return hr;
277 static HRESULT WINAPI d3drm1_CreateDeviceFromD3D(IDirect3DRM *iface,
278 IDirect3D *d3d, IDirect3DDevice *d3d_device, IDirect3DRMDevice **device)
280 struct d3drm_device *object;
281 HRESULT hr;
282 TRACE("iface %p, d3d %p, d3d_device %p, device %p.\n",
283 iface, d3d, d3d_device, device);
285 if (!device)
286 return D3DRMERR_BADVALUE;
287 *device = NULL;
288 if (!d3d || !d3d_device)
289 return D3DRMERR_BADVALUE;
291 hr = d3drm_device_create(&object);
292 if (FAILED(hr))
293 return hr;
295 hr = d3drm_device_set_ddraw_device_d3d(object, iface, d3d, d3d_device);
296 if (FAILED(hr))
298 d3drm_device_destroy(object);
299 return hr;
301 *device = IDirect3DRMDevice_from_impl(object);
303 return D3DRM_OK;
306 static HRESULT WINAPI d3drm1_CreateDeviceFromClipper(IDirect3DRM *iface,
307 IDirectDrawClipper *clipper, GUID *guid, int width, int height,
308 IDirect3DRMDevice **device)
310 struct d3drm_device *object;
311 IDirectDraw *ddraw;
312 IDirectDrawSurface *render_target;
313 HRESULT hr;
315 TRACE("iface %p, clipper %p, guid %s, width %d, height %d, device %p.\n",
316 iface, clipper, debugstr_guid(guid), width, height, device);
318 if (!device)
319 return D3DRMERR_BADVALUE;
320 *device = NULL;
322 if (!clipper || !width || !height)
323 return D3DRMERR_BADVALUE;
325 hr = DirectDrawCreate(NULL, &ddraw, NULL);
326 if (FAILED(hr))
327 return hr;
329 hr = d3drm_device_create(&object);
330 if (FAILED(hr))
332 IDirectDraw_Release(ddraw);
333 return hr;
336 hr = d3drm_device_create_surfaces_from_clipper(object, ddraw, clipper, width, height, &render_target);
337 if (FAILED(hr))
339 IDirectDraw_Release(ddraw);
340 d3drm_device_destroy(object);
341 return hr;
344 hr = d3drm_device_init(object, 1, iface, ddraw, render_target, TRUE);
345 IDirectDraw_Release(ddraw);
346 IDirectDrawSurface_Release(render_target);
347 if (FAILED(hr))
348 d3drm_device_destroy(object);
349 else
350 *device = IDirect3DRMDevice_from_impl(object);
352 return hr;
355 static HRESULT WINAPI d3drm1_CreateTextureFromSurface(IDirect3DRM *iface,
356 IDirectDrawSurface *surface, IDirect3DRMTexture **texture)
358 FIXME("iface %p, surface %p, texture %p stub!\n", iface, surface, texture);
360 return E_NOTIMPL;
363 static HRESULT WINAPI d3drm1_CreateShadow(IDirect3DRM *iface, IDirect3DRMVisual *visual,
364 IDirect3DRMLight *light, D3DVALUE px, D3DVALUE py, D3DVALUE pz, D3DVALUE nx, D3DVALUE ny, D3DVALUE nz,
365 IDirect3DRMVisual **shadow)
367 FIXME("iface %p, visual %p, light %p, px %.8e, py %.8e, pz %.8e, nx %.8e, ny %.8e, nz %.8e, shadow %p stub!\n",
368 iface, visual, light, px, py, pz, nx, ny, nz, shadow);
370 return E_NOTIMPL;
373 static HRESULT WINAPI d3drm1_CreateViewport(IDirect3DRM *iface, IDirect3DRMDevice *device,
374 IDirect3DRMFrame *camera, DWORD x, DWORD y, DWORD width, DWORD height, IDirect3DRMViewport **viewport)
376 FIXME("iface %p, device %p, camera %p, x %u, y %u, width %u, height %u, viewport %p partial stub!\n",
377 iface, device, camera, x, y, width, height, viewport);
379 return Direct3DRMViewport_create(&IID_IDirect3DRMViewport, (IUnknown **)viewport);
382 static HRESULT WINAPI d3drm1_CreateWrap(IDirect3DRM *iface, D3DRMWRAPTYPE type, IDirect3DRMFrame *frame,
383 D3DVALUE ox, D3DVALUE oy, D3DVALUE oz, D3DVALUE dx, D3DVALUE dy, D3DVALUE dz,
384 D3DVALUE ux, D3DVALUE uy, D3DVALUE uz, D3DVALUE ou, D3DVALUE ov, D3DVALUE su, D3DVALUE sv,
385 IDirect3DRMWrap **wrap)
387 FIXME("iface %p, type %#x, frame %p, ox %.8e, oy %.8e, oz %.8e, dx %.8e, dy %.8e, dz %.8e, "
388 "ux %.8e, uy %.8e, uz %.8e, ou %.8e, ov %.8e, su %.8e, sv %.8e, wrap %p stub!\n",
389 iface, type, frame, ox, oy, oz, dx, dy, dz, ux, uy, uz, ou, ov, su, sv, wrap);
391 return E_NOTIMPL;
394 static HRESULT WINAPI d3drm1_CreateUserVisual(IDirect3DRM *iface,
395 D3DRMUSERVISUALCALLBACK cb, void *ctx, IDirect3DRMUserVisual **visual)
397 FIXME("iface %p, cb %p, ctx %p visual %p stub!\n", iface, cb, ctx, visual);
399 return E_NOTIMPL;
402 static HRESULT WINAPI d3drm1_LoadTexture(IDirect3DRM *iface,
403 const char *filename, IDirect3DRMTexture **texture)
405 FIXME("iface %p, filename %s, texture %p stub!\n", iface, debugstr_a(filename), texture);
407 return Direct3DRMTexture_create(&IID_IDirect3DRMTexture, (IUnknown **)texture);
410 static HRESULT WINAPI d3drm1_LoadTextureFromResource(IDirect3DRM *iface,
411 HRSRC resource, IDirect3DRMTexture **texture)
413 FIXME("iface %p, resource %p, texture %p stub!\n", iface, resource, texture);
415 return Direct3DRMTexture_create(&IID_IDirect3DRMTexture, (IUnknown **)texture);
418 static HRESULT WINAPI d3drm1_SetSearchPath(IDirect3DRM *iface, const char *path)
420 FIXME("iface %p, path %s stub!\n", iface, debugstr_a(path));
422 return E_NOTIMPL;
425 static HRESULT WINAPI d3drm1_AddSearchPath(IDirect3DRM *iface, const char *path)
427 FIXME("iface %p, path %s stub!\n", iface, debugstr_a(path));
429 return E_NOTIMPL;
432 static HRESULT WINAPI d3drm1_GetSearchPath(IDirect3DRM *iface, DWORD *size, char *path)
434 FIXME("iface %p, size %p, path %p stub!\n", iface, size, path);
436 return E_NOTIMPL;
439 static HRESULT WINAPI d3drm1_SetDefaultTextureColors(IDirect3DRM *iface, DWORD color_count)
441 FIXME("iface %p, color_count %u stub!\n", iface, color_count);
443 return E_NOTIMPL;
446 static HRESULT WINAPI d3drm1_SetDefaultTextureShades(IDirect3DRM *iface, DWORD shade_count)
448 FIXME("iface %p, shade_count %u stub!\n", iface, shade_count);
450 return E_NOTIMPL;
453 static HRESULT WINAPI d3drm1_GetDevices(IDirect3DRM *iface, IDirect3DRMDeviceArray **array)
455 FIXME("iface %p, array %p stub!\n", iface, array);
457 return E_NOTIMPL;
460 static HRESULT WINAPI d3drm1_GetNamedObject(IDirect3DRM *iface,
461 const char *name, IDirect3DRMObject **object)
463 FIXME("iface %p, name %s, object %p stub!\n", iface, debugstr_a(name), object);
465 return E_NOTIMPL;
468 static HRESULT WINAPI d3drm1_EnumerateObjects(IDirect3DRM *iface, D3DRMOBJECTCALLBACK cb, void *ctx)
470 FIXME("iface %p, cb %p, ctx %p stub!\n", iface, cb, ctx);
472 return E_NOTIMPL;
475 static HRESULT WINAPI d3drm1_Load(IDirect3DRM *iface, void *source, void *object_id, IID **iids,
476 DWORD iid_count, D3DRMLOADOPTIONS flags, D3DRMLOADCALLBACK load_cb, void *load_ctx,
477 D3DRMLOADTEXTURECALLBACK load_tex_cb, void *load_tex_ctx, IDirect3DRMFrame *parent_frame)
479 struct d3drm *d3drm = impl_from_IDirect3DRM(iface);
480 IDirect3DRMFrame3 *parent_frame3 = NULL;
481 HRESULT hr = D3DRM_OK;
483 TRACE("iface %p, source %p, object_id %p, iids %p, iid_count %u, flags %#x, "
484 "load_cb %p, load_ctx %p, load_tex_cb %p, load_tex_ctx %p, parent_frame %p.\n",
485 iface, source, object_id, iids, iid_count, flags,
486 load_cb, load_ctx, load_tex_cb, load_tex_ctx, parent_frame);
488 if (parent_frame)
489 hr = IDirect3DRMFrame_QueryInterface(parent_frame, &IID_IDirect3DRMFrame3, (void **)&parent_frame3);
490 if (SUCCEEDED(hr))
491 hr = IDirect3DRM3_Load(&d3drm->IDirect3DRM3_iface, source, object_id, iids, iid_count,
492 flags, load_cb, load_ctx, load_tex_cb, load_tex_ctx, parent_frame3);
493 if (parent_frame3)
494 IDirect3DRMFrame3_Release(parent_frame3);
496 return hr;
499 static HRESULT WINAPI d3drm1_Tick(IDirect3DRM *iface, D3DVALUE tick)
501 FIXME("iface %p, tick %.8e stub!\n", iface, tick);
503 return E_NOTIMPL;
506 static const struct IDirect3DRMVtbl d3drm1_vtbl =
508 d3drm1_QueryInterface,
509 d3drm1_AddRef,
510 d3drm1_Release,
511 d3drm1_CreateObject,
512 d3drm1_CreateFrame,
513 d3drm1_CreateMesh,
514 d3drm1_CreateMeshBuilder,
515 d3drm1_CreateFace,
516 d3drm1_CreateAnimation,
517 d3drm1_CreateAnimationSet,
518 d3drm1_CreateTexture,
519 d3drm1_CreateLight,
520 d3drm1_CreateLightRGB,
521 d3drm1_CreateMaterial,
522 d3drm1_CreateDevice,
523 d3drm1_CreateDeviceFromSurface,
524 d3drm1_CreateDeviceFromD3D,
525 d3drm1_CreateDeviceFromClipper,
526 d3drm1_CreateTextureFromSurface,
527 d3drm1_CreateShadow,
528 d3drm1_CreateViewport,
529 d3drm1_CreateWrap,
530 d3drm1_CreateUserVisual,
531 d3drm1_LoadTexture,
532 d3drm1_LoadTextureFromResource,
533 d3drm1_SetSearchPath,
534 d3drm1_AddSearchPath,
535 d3drm1_GetSearchPath,
536 d3drm1_SetDefaultTextureColors,
537 d3drm1_SetDefaultTextureShades,
538 d3drm1_GetDevices,
539 d3drm1_GetNamedObject,
540 d3drm1_EnumerateObjects,
541 d3drm1_Load,
542 d3drm1_Tick,
545 static HRESULT WINAPI d3drm2_QueryInterface(IDirect3DRM2 *iface, REFIID riid, void **out)
547 struct d3drm *d3drm = impl_from_IDirect3DRM2(iface);
549 return d3drm1_QueryInterface(&d3drm->IDirect3DRM_iface, riid, out);
552 static ULONG WINAPI d3drm2_AddRef(IDirect3DRM2 *iface)
554 struct d3drm *d3drm = impl_from_IDirect3DRM2(iface);
555 ULONG refcount = InterlockedIncrement(&d3drm->ref2);
557 TRACE("%p increasing refcount to %u.\n", iface, refcount);
559 if (refcount == 1)
560 InterlockedIncrement(&d3drm->iface_count);
562 return refcount;
565 static ULONG WINAPI d3drm2_Release(IDirect3DRM2 *iface)
567 struct d3drm *d3drm = impl_from_IDirect3DRM2(iface);
568 ULONG refcount = InterlockedDecrement(&d3drm->ref2);
570 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
572 if (!refcount && !InterlockedDecrement(&d3drm->iface_count))
573 d3drm_destroy(d3drm);
575 return refcount;
578 static HRESULT WINAPI d3drm2_CreateObject(IDirect3DRM2 *iface,
579 REFCLSID clsid, IUnknown *outer, REFIID iid, void **out)
581 FIXME("iface %p, clsid %s, outer %p, iid %s, out %p stub!\n",
582 iface, debugstr_guid(clsid), outer, debugstr_guid(iid), out);
584 return E_NOTIMPL;
587 static HRESULT WINAPI d3drm2_CreateFrame(IDirect3DRM2 *iface,
588 IDirect3DRMFrame *parent_frame, IDirect3DRMFrame2 **frame)
590 TRACE("iface %p, parent_frame %p, frame %p.\n", iface, parent_frame, frame);
592 return Direct3DRMFrame_create(&IID_IDirect3DRMFrame2, (IUnknown*)parent_frame, (IUnknown**)frame);
595 static HRESULT WINAPI d3drm2_CreateMesh(IDirect3DRM2 *iface, IDirect3DRMMesh **mesh)
597 struct d3drm *d3drm = impl_from_IDirect3DRM2(iface);
599 TRACE("iface %p, mesh %p.\n", iface, mesh);
601 return IDirect3DRM3_CreateMesh(&d3drm->IDirect3DRM3_iface, mesh);
604 static HRESULT WINAPI d3drm2_CreateMeshBuilder(IDirect3DRM2 *iface, IDirect3DRMMeshBuilder2 **mesh_builder)
606 TRACE("iface %p, mesh_builder %p.\n", iface, mesh_builder);
608 return Direct3DRMMeshBuilder_create(&IID_IDirect3DRMMeshBuilder2, (IUnknown **)mesh_builder);
611 static HRESULT WINAPI d3drm2_CreateFace(IDirect3DRM2 *iface, IDirect3DRMFace **face)
613 TRACE("iface %p, face %p.\n", iface, face);
615 return Direct3DRMFace_create(&IID_IDirect3DRMFace, (IUnknown **)face);
618 static HRESULT WINAPI d3drm2_CreateAnimation(IDirect3DRM2 *iface, IDirect3DRMAnimation **animation)
620 FIXME("iface %p, animation %p stub!\n", iface, animation);
622 return E_NOTIMPL;
625 static HRESULT WINAPI d3drm2_CreateAnimationSet(IDirect3DRM2 *iface, IDirect3DRMAnimationSet **set)
627 FIXME("iface %p, set %p stub!\n", iface, set);
629 return E_NOTIMPL;
632 static HRESULT WINAPI d3drm2_CreateTexture(IDirect3DRM2 *iface,
633 D3DRMIMAGE *image, IDirect3DRMTexture2 **texture)
635 FIXME("iface %p, image %p, texture %p partial stub.\n", iface, image, texture);
637 return Direct3DRMTexture_create(&IID_IDirect3DRMTexture2, (IUnknown **)texture);
640 static HRESULT WINAPI d3drm2_CreateLight(IDirect3DRM2 *iface,
641 D3DRMLIGHTTYPE type, D3DCOLOR color, IDirect3DRMLight **light)
643 struct d3drm *d3drm = impl_from_IDirect3DRM2(iface);
645 TRACE("iface %p, type %#x, color 0x%08x, light %p.\n", iface, type, color, light);
647 return IDirect3DRM3_CreateLight(&d3drm->IDirect3DRM3_iface, type, color, light);
650 static HRESULT WINAPI d3drm2_CreateLightRGB(IDirect3DRM2 *iface, D3DRMLIGHTTYPE type,
651 D3DVALUE red, D3DVALUE green, D3DVALUE blue, IDirect3DRMLight **light)
653 struct d3drm *d3drm = impl_from_IDirect3DRM2(iface);
655 TRACE("iface %p, type %#x, red %.8e, green %.8e, blue %.8e, light %p.\n",
656 iface, type, red, green, blue, light);
658 return IDirect3DRM3_CreateLightRGB(&d3drm->IDirect3DRM3_iface, type, red, green, blue, light);
661 static HRESULT WINAPI d3drm2_CreateMaterial(IDirect3DRM2 *iface,
662 D3DVALUE power, IDirect3DRMMaterial **material)
664 struct d3drm *d3drm = impl_from_IDirect3DRM2(iface);
666 TRACE("iface %p, power %.8e, material %p.\n", iface, power, material);
668 return IDirect3DRM3_CreateMaterial(&d3drm->IDirect3DRM3_iface, power, (IDirect3DRMMaterial2 **)material);
671 static HRESULT WINAPI d3drm2_CreateDevice(IDirect3DRM2 *iface,
672 DWORD width, DWORD height, IDirect3DRMDevice2 **device)
674 struct d3drm_device *object;
675 HRESULT hr;
676 FIXME("iface %p, width %u, height %u, device %p partial stub!\n", iface, width, height, device);
678 hr = d3drm_device_create(&object);
679 if (FAILED(hr))
680 return hr;
682 *device = IDirect3DRMDevice2_from_impl(object);
684 return D3DRM_OK;
687 static HRESULT WINAPI d3drm2_CreateDeviceFromSurface(IDirect3DRM2 *iface, GUID *guid,
688 IDirectDraw *ddraw, IDirectDrawSurface *backbuffer, IDirect3DRMDevice2 **device)
690 struct d3drm *d3drm = impl_from_IDirect3DRM2(iface);
691 IDirect3DRMDevice3 *device3;
692 HRESULT hr;
693 TRACE("iface %p, guid %s, ddraw %p, backbuffer %p, device %p.\n",
694 iface, debugstr_guid(guid), ddraw, backbuffer, device);
696 if (!device)
697 return D3DRMERR_BADVALUE;
698 *device = NULL;
699 hr = IDirect3DRM3_CreateDeviceFromSurface(&d3drm->IDirect3DRM3_iface, guid, ddraw, backbuffer, 0, &device3);
700 if (FAILED(hr))
701 return hr;
703 hr = IDirect3DRMDevice3_QueryInterface(device3, &IID_IDirect3DRMDevice2, (void**)device);
704 IDirect3DRMDevice3_Release(device3);
706 return hr;
709 static HRESULT WINAPI d3drm2_CreateDeviceFromD3D(IDirect3DRM2 *iface,
710 IDirect3D2 *d3d, IDirect3DDevice2 *d3d_device, IDirect3DRMDevice2 **device)
712 struct d3drm *d3drm = impl_from_IDirect3DRM2(iface);
713 IDirect3D *d3d1;
714 IDirect3DDevice *d3d_device1;
715 IDirect3DRMDevice *device1;
716 HRESULT hr;
717 TRACE("iface %p, d3d %p, d3d_device %p, device %p.\n",
718 iface, d3d, d3d_device, device);
720 if (!device)
721 return D3DRMERR_BADVALUE;
722 *device = NULL;
723 if (!d3d || !d3d_device)
724 return D3DRMERR_BADVALUE;
726 hr = IDirect3D2_QueryInterface(d3d, &IID_IDirect3D, (void **)&d3d1);
727 if (FAILED(hr))
728 return hr;
730 hr = IDirect3DDevice2_QueryInterface(d3d_device, &IID_IDirect3DDevice, (void **)&d3d_device1);
731 if (FAILED(hr))
733 IDirect3D_Release(d3d1);
734 return hr;
737 hr = IDirect3DRM_CreateDeviceFromD3D(&d3drm->IDirect3DRM_iface, d3d1, d3d_device1, &device1);
738 IDirect3D_Release(d3d1);
739 IDirect3DDevice_Release(d3d_device1);
740 if (FAILED(hr))
741 return hr;
743 hr = IDirect3DRMDevice_QueryInterface(device1, &IID_IDirect3DRMDevice2, (void **)device);
744 IDirect3DRMDevice_Release(device1);
746 return hr;
749 static HRESULT WINAPI d3drm2_CreateDeviceFromClipper(IDirect3DRM2 *iface,
750 IDirectDrawClipper *clipper, GUID *guid, int width, int height,
751 IDirect3DRMDevice2 **device)
753 struct d3drm *d3drm = impl_from_IDirect3DRM2(iface);
754 IDirect3DRMDevice3 *device3;
755 HRESULT hr;
757 TRACE("iface %p, clipper %p, guid %s, width %d, height %d, device %p.\n",
758 iface, clipper, debugstr_guid(guid), width, height, device);
760 if (!device)
761 return D3DRMERR_BADVALUE;
762 *device = NULL;
763 hr = IDirect3DRM3_CreateDeviceFromClipper(&d3drm->IDirect3DRM3_iface, clipper, guid, width, height, &device3);
764 if (FAILED(hr))
765 return hr;
767 hr = IDirect3DRMDevice3_QueryInterface(device3, &IID_IDirect3DRMDevice2, (void**)device);
768 IDirect3DRMDevice3_Release(device3);
770 return hr;
773 static HRESULT WINAPI d3drm2_CreateTextureFromSurface(IDirect3DRM2 *iface,
774 IDirectDrawSurface *surface, IDirect3DRMTexture2 **texture)
776 FIXME("iface %p, surface %p, texture %p stub!\n", iface, surface, texture);
778 return E_NOTIMPL;
781 static HRESULT WINAPI d3drm2_CreateShadow(IDirect3DRM2 *iface, IDirect3DRMVisual *visual,
782 IDirect3DRMLight *light, D3DVALUE px, D3DVALUE py, D3DVALUE pz, D3DVALUE nx, D3DVALUE ny, D3DVALUE nz,
783 IDirect3DRMVisual **shadow)
785 FIXME("iface %p, visual %p, light %p, px %.8e, py %.8e, pz %.8e, nx %.8e, ny %.8e, nz %.8e, shadow %p stub!\n",
786 iface, visual, light, px, py, pz, nx, ny, nz, shadow);
788 return E_NOTIMPL;
791 static HRESULT WINAPI d3drm2_CreateViewport(IDirect3DRM2 *iface, IDirect3DRMDevice *device,
792 IDirect3DRMFrame *camera, DWORD x, DWORD y, DWORD width, DWORD height, IDirect3DRMViewport **viewport)
794 FIXME("iface %p, device %p, camera %p, x %u, y %u, width %u, height %u, viewport %p partial stub!\n",
795 iface, device, camera, x, y, width, height, viewport);
797 return Direct3DRMViewport_create(&IID_IDirect3DRMViewport, (IUnknown **)viewport);
800 static HRESULT WINAPI d3drm2_CreateWrap(IDirect3DRM2 *iface, D3DRMWRAPTYPE type, IDirect3DRMFrame *frame,
801 D3DVALUE ox, D3DVALUE oy, D3DVALUE oz, D3DVALUE dx, D3DVALUE dy, D3DVALUE dz,
802 D3DVALUE ux, D3DVALUE uy, D3DVALUE uz, D3DVALUE ou, D3DVALUE ov, D3DVALUE su, D3DVALUE sv,
803 IDirect3DRMWrap **wrap)
805 FIXME("iface %p, type %#x, frame %p, ox %.8e, oy %.8e, oz %.8e, dx %.8e, dy %.8e, dz %.8e, "
806 "ux %.8e, uy %.8e, uz %.8e, ou %.8e, ov %.8e, su %.8e, sv %.8e, wrap %p stub!\n",
807 iface, type, frame, ox, oy, oz, dx, dy, dz, ux, uy, uz, ou, ov, su, sv, wrap);
809 return E_NOTIMPL;
812 static HRESULT WINAPI d3drm2_CreateUserVisual(IDirect3DRM2 *iface,
813 D3DRMUSERVISUALCALLBACK cb, void *ctx, IDirect3DRMUserVisual **visual)
815 FIXME("iface %p, cb %p, ctx %p, visual %p stub!\n", iface, cb, ctx, visual);
817 return E_NOTIMPL;
820 static HRESULT WINAPI d3drm2_LoadTexture(IDirect3DRM2 *iface,
821 const char *filename, IDirect3DRMTexture2 **texture)
823 FIXME("iface %p, filename %s, texture %p stub!\n", iface, debugstr_a(filename), texture);
825 return Direct3DRMTexture_create(&IID_IDirect3DRMTexture2, (IUnknown **)texture);
828 static HRESULT WINAPI d3drm2_LoadTextureFromResource(IDirect3DRM2 *iface, HMODULE module,
829 const char *resource_name, const char *resource_type, IDirect3DRMTexture2 **texture)
831 FIXME("iface %p, resource_name %s, resource_type %s, texture %p stub!\n",
832 iface, debugstr_a(resource_name), debugstr_a(resource_type), texture);
834 return Direct3DRMTexture_create(&IID_IDirect3DRMTexture2, (IUnknown **)texture);
837 static HRESULT WINAPI d3drm2_SetSearchPath(IDirect3DRM2 *iface, const char *path)
839 FIXME("iface %p, path %s stub!\n", iface, debugstr_a(path));
841 return E_NOTIMPL;
844 static HRESULT WINAPI d3drm2_AddSearchPath(IDirect3DRM2 *iface, const char *path)
846 FIXME("iface %p, path %s stub!\n", iface, debugstr_a(path));
848 return E_NOTIMPL;
851 static HRESULT WINAPI d3drm2_GetSearchPath(IDirect3DRM2 *iface, DWORD *size, char *path)
853 FIXME("iface %p, size %p, path %p stub!\n", iface, size, path);
855 return E_NOTIMPL;
858 static HRESULT WINAPI d3drm2_SetDefaultTextureColors(IDirect3DRM2 *iface, DWORD color_count)
860 FIXME("iface %p, color_count %u stub!\n", iface, color_count);
862 return E_NOTIMPL;
865 static HRESULT WINAPI d3drm2_SetDefaultTextureShades(IDirect3DRM2 *iface, DWORD shade_count)
867 FIXME("iface %p, shade_count %u stub!\n", iface, shade_count);
869 return E_NOTIMPL;
872 static HRESULT WINAPI d3drm2_GetDevices(IDirect3DRM2 *iface, IDirect3DRMDeviceArray **array)
874 FIXME("iface %p, array %p stub!\n", iface, array);
876 return E_NOTIMPL;
879 static HRESULT WINAPI d3drm2_GetNamedObject(IDirect3DRM2 *iface,
880 const char *name, IDirect3DRMObject **object)
882 FIXME("iface %p, name %s, object %p stub!\n", iface, debugstr_a(name), object);
884 return E_NOTIMPL;
887 static HRESULT WINAPI d3drm2_EnumerateObjects(IDirect3DRM2 *iface, D3DRMOBJECTCALLBACK cb, void *ctx)
889 FIXME("iface %p, cb %p, ctx %p stub!\n", iface, cb, ctx);
891 return E_NOTIMPL;
894 static HRESULT WINAPI d3drm2_Load(IDirect3DRM2 *iface, void *source, void *object_id, IID **iids,
895 DWORD iid_count, D3DRMLOADOPTIONS flags, D3DRMLOADCALLBACK load_cb, void *load_ctx,
896 D3DRMLOADTEXTURECALLBACK load_tex_cb, void *load_tex_ctx, IDirect3DRMFrame *parent_frame)
898 struct d3drm *d3drm = impl_from_IDirect3DRM2(iface);
899 IDirect3DRMFrame3 *parent_frame3 = NULL;
900 HRESULT hr = D3DRM_OK;
902 TRACE("iface %p, source %p, object_id %p, iids %p, iid_count %u, flags %#x, "
903 "load_cb %p, load_ctx %p, load_tex_cb %p, load_tex_ctx %p, parent_frame %p.\n",
904 iface, source, object_id, iids, iid_count, flags,
905 load_cb, load_ctx, load_tex_cb, load_tex_ctx, parent_frame);
907 if (parent_frame)
908 hr = IDirect3DRMFrame_QueryInterface(parent_frame, &IID_IDirect3DRMFrame3, (void **)&parent_frame3);
909 if (SUCCEEDED(hr))
910 hr = IDirect3DRM3_Load(&d3drm->IDirect3DRM3_iface, source, object_id, iids, iid_count,
911 flags, load_cb, load_ctx, load_tex_cb, load_tex_ctx, parent_frame3);
912 if (parent_frame3)
913 IDirect3DRMFrame3_Release(parent_frame3);
915 return hr;
918 static HRESULT WINAPI d3drm2_Tick(IDirect3DRM2 *iface, D3DVALUE tick)
920 FIXME("iface %p, tick %.8e stub!\n", iface, tick);
922 return E_NOTIMPL;
925 static HRESULT WINAPI d3drm2_CreateProgressiveMesh(IDirect3DRM2 *iface, IDirect3DRMProgressiveMesh **mesh)
927 FIXME("iface %p, mesh %p stub!\n", iface, mesh);
929 return E_NOTIMPL;
932 static const struct IDirect3DRM2Vtbl d3drm2_vtbl =
934 d3drm2_QueryInterface,
935 d3drm2_AddRef,
936 d3drm2_Release,
937 d3drm2_CreateObject,
938 d3drm2_CreateFrame,
939 d3drm2_CreateMesh,
940 d3drm2_CreateMeshBuilder,
941 d3drm2_CreateFace,
942 d3drm2_CreateAnimation,
943 d3drm2_CreateAnimationSet,
944 d3drm2_CreateTexture,
945 d3drm2_CreateLight,
946 d3drm2_CreateLightRGB,
947 d3drm2_CreateMaterial,
948 d3drm2_CreateDevice,
949 d3drm2_CreateDeviceFromSurface,
950 d3drm2_CreateDeviceFromD3D,
951 d3drm2_CreateDeviceFromClipper,
952 d3drm2_CreateTextureFromSurface,
953 d3drm2_CreateShadow,
954 d3drm2_CreateViewport,
955 d3drm2_CreateWrap,
956 d3drm2_CreateUserVisual,
957 d3drm2_LoadTexture,
958 d3drm2_LoadTextureFromResource,
959 d3drm2_SetSearchPath,
960 d3drm2_AddSearchPath,
961 d3drm2_GetSearchPath,
962 d3drm2_SetDefaultTextureColors,
963 d3drm2_SetDefaultTextureShades,
964 d3drm2_GetDevices,
965 d3drm2_GetNamedObject,
966 d3drm2_EnumerateObjects,
967 d3drm2_Load,
968 d3drm2_Tick,
969 d3drm2_CreateProgressiveMesh,
972 static HRESULT WINAPI d3drm3_QueryInterface(IDirect3DRM3 *iface, REFIID riid, void **out)
974 struct d3drm *d3drm = impl_from_IDirect3DRM3(iface);
976 return d3drm1_QueryInterface(&d3drm->IDirect3DRM_iface, riid, out);
979 static ULONG WINAPI d3drm3_AddRef(IDirect3DRM3 *iface)
981 struct d3drm *d3drm = impl_from_IDirect3DRM3(iface);
982 ULONG refcount = InterlockedIncrement(&d3drm->ref3);
984 TRACE("%p increasing refcount to %u.\n", iface, refcount);
986 if (refcount == 1)
987 InterlockedIncrement(&d3drm->iface_count);
989 return refcount;
992 static ULONG WINAPI d3drm3_Release(IDirect3DRM3 *iface)
994 struct d3drm *d3drm = impl_from_IDirect3DRM3(iface);
995 ULONG refcount = InterlockedDecrement(&d3drm->ref3);
997 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
999 if (!refcount && !InterlockedDecrement(&d3drm->iface_count))
1000 d3drm_destroy(d3drm);
1002 return refcount;
1005 static HRESULT WINAPI d3drm3_CreateObject(IDirect3DRM3 *iface,
1006 REFCLSID clsid, IUnknown *outer, REFIID iid, void **out)
1008 FIXME("iface %p, clsid %s, outer %p, iid %s, out %p stub!\n",
1009 iface, debugstr_guid(clsid), outer, debugstr_guid(iid), out);
1011 return E_NOTIMPL;
1014 static HRESULT WINAPI d3drm3_CreateFrame(IDirect3DRM3 *iface,
1015 IDirect3DRMFrame3 *parent, IDirect3DRMFrame3 **frame)
1017 TRACE("iface %p, parent %p, frame %p.\n", iface, parent, frame);
1019 return Direct3DRMFrame_create(&IID_IDirect3DRMFrame3, (IUnknown *)parent, (IUnknown **)frame);
1022 static HRESULT WINAPI d3drm3_CreateMesh(IDirect3DRM3 *iface, IDirect3DRMMesh **mesh)
1024 TRACE("iface %p, mesh %p.\n", iface, mesh);
1026 return Direct3DRMMesh_create(mesh);
1029 static HRESULT WINAPI d3drm3_CreateMeshBuilder(IDirect3DRM3 *iface, IDirect3DRMMeshBuilder3 **mesh_builder)
1031 TRACE("iface %p, mesh_builder %p.\n", iface, mesh_builder);
1033 return Direct3DRMMeshBuilder_create(&IID_IDirect3DRMMeshBuilder3, (IUnknown **)mesh_builder);
1036 static HRESULT WINAPI d3drm3_CreateFace(IDirect3DRM3 *iface, IDirect3DRMFace2 **face)
1038 TRACE("iface %p, face %p.\n", iface, face);
1040 return Direct3DRMFace_create(&IID_IDirect3DRMFace2, (IUnknown **)face);
1043 static HRESULT WINAPI d3drm3_CreateAnimation(IDirect3DRM3 *iface, IDirect3DRMAnimation2 **animation)
1045 FIXME("iface %p, animation %p stub!\n", iface, animation);
1047 return E_NOTIMPL;
1050 static HRESULT WINAPI d3drm3_CreateAnimationSet(IDirect3DRM3 *iface, IDirect3DRMAnimationSet2 **set)
1052 FIXME("iface %p, set %p stub!\n", iface, set);
1054 return E_NOTIMPL;
1057 static HRESULT WINAPI d3drm3_CreateTexture(IDirect3DRM3 *iface,
1058 D3DRMIMAGE *image, IDirect3DRMTexture3 **texture)
1060 FIXME("iface %p, image %p, texture %p partial stub.\n", iface, image, texture);
1062 return Direct3DRMTexture_create(&IID_IDirect3DRMTexture3, (IUnknown **)texture);
1065 static HRESULT WINAPI d3drm3_CreateLight(IDirect3DRM3 *iface,
1066 D3DRMLIGHTTYPE type, D3DCOLOR color, IDirect3DRMLight **light)
1068 HRESULT hr;
1070 FIXME("iface %p, type %#x, color 0x%08x, light %p partial stub!\n", iface, type, color, light);
1072 if (SUCCEEDED(hr = Direct3DRMLight_create((IUnknown **)light)))
1074 IDirect3DRMLight_SetType(*light, type);
1075 IDirect3DRMLight_SetColor(*light, color);
1078 return hr;
1081 static HRESULT WINAPI d3drm3_CreateLightRGB(IDirect3DRM3 *iface, D3DRMLIGHTTYPE type,
1082 D3DVALUE red, D3DVALUE green, D3DVALUE blue, IDirect3DRMLight **light)
1084 HRESULT hr;
1086 FIXME("iface %p, type %#x, red %.8e, green %.8e, blue %.8e, light %p partial stub!\n",
1087 iface, type, red, green, blue, light);
1089 if (SUCCEEDED(hr = Direct3DRMLight_create((IUnknown **)light)))
1091 IDirect3DRMLight_SetType(*light, type);
1092 IDirect3DRMLight_SetColorRGB(*light, red, green, blue);
1095 return hr;
1098 static HRESULT WINAPI d3drm3_CreateMaterial(IDirect3DRM3 *iface,
1099 D3DVALUE power, IDirect3DRMMaterial2 **material)
1101 HRESULT hr;
1103 TRACE("iface %p, power %.8e, material %p.\n", iface, power, material);
1105 if (SUCCEEDED(hr = Direct3DRMMaterial_create(material)))
1106 IDirect3DRMMaterial2_SetPower(*material, power);
1108 return hr;
1111 static HRESULT WINAPI d3drm3_CreateDevice(IDirect3DRM3 *iface,
1112 DWORD width, DWORD height, IDirect3DRMDevice3 **device)
1114 struct d3drm_device *object;
1115 HRESULT hr;
1116 FIXME("iface %p, width %u, height %u, device %p partial stub!\n", iface, width, height, device);
1118 hr = d3drm_device_create(&object);
1119 if (FAILED(hr))
1120 return hr;
1122 *device = IDirect3DRMDevice3_from_impl(object);
1124 return D3DRM_OK;
1127 static HRESULT WINAPI d3drm3_CreateDeviceFromSurface(IDirect3DRM3 *iface, GUID *guid,
1128 IDirectDraw *ddraw, IDirectDrawSurface *backbuffer, DWORD flags, IDirect3DRMDevice3 **device)
1130 struct d3drm *d3drm = impl_from_IDirect3DRM3(iface);
1131 struct d3drm_device *object;
1132 BOOL use_z_surface;
1133 HRESULT hr;
1135 TRACE("iface %p, guid %s, ddraw %p, backbuffer %p, flags %#x, device %p.\n",
1136 iface, debugstr_guid(guid), ddraw, backbuffer, flags, device);
1138 if (!device)
1139 return D3DRMERR_BADVALUE;
1140 *device = NULL;
1142 if (!backbuffer || !ddraw)
1143 return D3DRMERR_BADDEVICE;
1145 hr = d3drm_device_create(&object);
1146 if (FAILED(hr))
1147 return hr;
1149 use_z_surface = !(flags & D3DRMDEVICE_NOZBUFFER);
1151 hr = d3drm_device_init(object, 3, &d3drm->IDirect3DRM_iface, ddraw, backbuffer, use_z_surface);
1152 if (SUCCEEDED(hr))
1153 *device = IDirect3DRMDevice3_from_impl(object);
1154 else
1155 d3drm_device_destroy(object);
1157 return hr;
1160 static HRESULT WINAPI d3drm3_CreateDeviceFromD3D(IDirect3DRM3 *iface,
1161 IDirect3D2 *d3d, IDirect3DDevice2 *d3d_device, IDirect3DRMDevice3 **device)
1163 struct d3drm *d3drm = impl_from_IDirect3DRM3(iface);
1164 IDirect3D *d3d1;
1165 IDirect3DDevice *d3d_device1;
1166 IDirect3DRMDevice *device1;
1167 HRESULT hr;
1168 TRACE("iface %p, d3d %p, d3d_device %p, device %p.\n",
1169 iface, d3d, d3d_device, device);
1171 if (!device)
1172 return D3DRMERR_BADVALUE;
1173 *device = NULL;
1174 if (!d3d || !d3d_device)
1175 return D3DRMERR_BADVALUE;
1177 hr = IDirect3D2_QueryInterface(d3d, &IID_IDirect3D, (void **)&d3d1);
1178 if (FAILED(hr))
1179 return hr;
1180 hr = IDirect3DDevice2_QueryInterface(d3d_device, &IID_IDirect3DDevice, (void **)&d3d_device1);
1181 if (FAILED(hr))
1183 IDirect3D_Release(d3d1);
1184 return hr;
1187 hr = IDirect3DRM_CreateDeviceFromD3D(&d3drm->IDirect3DRM_iface, d3d1, d3d_device1, &device1);
1188 IDirect3D_Release(d3d1);
1189 IDirect3DDevice_Release(d3d_device1);
1190 if (FAILED(hr))
1191 return hr;
1193 hr = IDirect3DRMDevice_QueryInterface(device1, &IID_IDirect3DRMDevice3, (void **)device);
1194 IDirect3DRMDevice_Release(device1);
1196 return hr;
1199 static HRESULT WINAPI d3drm3_CreateDeviceFromClipper(IDirect3DRM3 *iface,
1200 IDirectDrawClipper *clipper, GUID *guid, int width, int height,
1201 IDirect3DRMDevice3 **device)
1203 struct d3drm *d3drm = impl_from_IDirect3DRM3(iface);
1204 struct d3drm_device *object;
1205 IDirectDraw *ddraw;
1206 IDirectDrawSurface *render_target;
1207 HRESULT hr;
1209 TRACE("iface %p, clipper %p, guid %s, width %d, height %d, device %p.\n",
1210 iface, clipper, debugstr_guid(guid), width, height, device);
1212 if (!device)
1213 return D3DRMERR_BADVALUE;
1214 *device = NULL;
1216 if (!clipper || !width || !height)
1217 return D3DRMERR_BADVALUE;
1219 hr = DirectDrawCreate(NULL, &ddraw, NULL);
1220 if (FAILED(hr))
1221 return hr;
1223 hr = d3drm_device_create(&object);
1224 if (FAILED(hr))
1226 IDirectDraw_Release(ddraw);
1227 return hr;
1230 hr = d3drm_device_create_surfaces_from_clipper(object, ddraw, clipper, width, height, &render_target);
1231 if (FAILED(hr))
1233 IDirectDraw_Release(ddraw);
1234 d3drm_device_destroy(object);
1235 return hr;
1238 hr = d3drm_device_init(object, 3, &d3drm->IDirect3DRM_iface, ddraw, render_target, TRUE);
1239 IDirectDraw_Release(ddraw);
1240 IDirectDrawSurface_Release(render_target);
1241 if (FAILED(hr))
1242 d3drm_device_destroy(object);
1243 else
1244 *device = IDirect3DRMDevice3_from_impl(object);
1246 return hr;
1249 static HRESULT WINAPI d3drm3_CreateShadow(IDirect3DRM3 *iface, IUnknown *object, IDirect3DRMLight *light,
1250 D3DVALUE px, D3DVALUE py, D3DVALUE pz, D3DVALUE nx, D3DVALUE ny, D3DVALUE nz, IDirect3DRMShadow2 **shadow)
1252 FIXME("iface %p, object %p, light %p, px %.8e, py %.8e, pz %.8e, nx %.8e, ny %.8e, nz %.8e, shadow %p stub!\n",
1253 iface, object, light, px, py, pz, nx, ny, nz, shadow);
1255 return E_NOTIMPL;
1258 static HRESULT WINAPI d3drm3_CreateTextureFromSurface(IDirect3DRM3 *iface,
1259 IDirectDrawSurface *surface, IDirect3DRMTexture3 **texture)
1261 FIXME("iface %p, surface %p, texture %p stub!\n", iface, surface, texture);
1263 return E_NOTIMPL;
1266 static HRESULT WINAPI d3drm3_CreateViewport(IDirect3DRM3 *iface, IDirect3DRMDevice3 *device,
1267 IDirect3DRMFrame3 *camera, DWORD x, DWORD y, DWORD width, DWORD height, IDirect3DRMViewport2 **viewport)
1269 FIXME("iface %p, device %p, camera %p, x %u, y %u, width %u, height %u, viewport %p partial stub!\n",
1270 iface, device, camera, x, y, width, height, viewport);
1272 return Direct3DRMViewport_create(&IID_IDirect3DRMViewport2, (IUnknown **)viewport);
1275 static HRESULT WINAPI d3drm3_CreateWrap(IDirect3DRM3 *iface, D3DRMWRAPTYPE type, IDirect3DRMFrame3 *frame,
1276 D3DVALUE ox, D3DVALUE oy, D3DVALUE oz, D3DVALUE dx, D3DVALUE dy, D3DVALUE dz,
1277 D3DVALUE ux, D3DVALUE uy, D3DVALUE uz, D3DVALUE ou, D3DVALUE ov, D3DVALUE su, D3DVALUE sv,
1278 IDirect3DRMWrap **wrap)
1280 FIXME("iface %p, type %#x, frame %p, ox %.8e, oy %.8e, oz %.8e, dx %.8e, dy %.8e, dz %.8e, "
1281 "ux %.8e, uy %.8e, uz %.8e, ou %.8e, ov %.8e, su %.8e, sv %.8e, wrap %p stub!\n",
1282 iface, type, frame, ox, oy, oz, dx, dy, dz, ux, uy, uz, ou, ov, su, sv, wrap);
1284 return E_NOTIMPL;
1287 static HRESULT WINAPI d3drm3_CreateUserVisual(IDirect3DRM3 *iface,
1288 D3DRMUSERVISUALCALLBACK cb, void *ctx, IDirect3DRMUserVisual **visual)
1290 FIXME("iface %p, cb %p, ctx %p, visual %p stub!\n", iface, cb, ctx, visual);
1292 return E_NOTIMPL;
1295 static HRESULT WINAPI d3drm3_LoadTexture(IDirect3DRM3 *iface,
1296 const char *filename, IDirect3DRMTexture3 **texture)
1298 FIXME("iface %p, filename %s, texture %p stub!\n", iface, debugstr_a(filename), texture);
1300 return Direct3DRMTexture_create(&IID_IDirect3DRMTexture3, (IUnknown **)texture);
1303 static HRESULT WINAPI d3drm3_LoadTextureFromResource(IDirect3DRM3 *iface, HMODULE module,
1304 const char *resource_name, const char *resource_type, IDirect3DRMTexture3 **texture)
1306 FIXME("iface %p, module %p, resource_name %s, resource_type %s, texture %p stub!\n",
1307 iface, module, debugstr_a(resource_name), debugstr_a(resource_type), texture);
1309 return Direct3DRMTexture_create(&IID_IDirect3DRMTexture3, (IUnknown **)texture);
1312 static HRESULT WINAPI d3drm3_SetSearchPath(IDirect3DRM3 *iface, const char *path)
1314 FIXME("iface %p, path %s stub!\n", iface, debugstr_a(path));
1316 return E_NOTIMPL;
1319 static HRESULT WINAPI d3drm3_AddSearchPath(IDirect3DRM3 *iface, const char *path)
1321 FIXME("iface %p, path %s stub!\n", iface, debugstr_a(path));
1323 return E_NOTIMPL;
1326 static HRESULT WINAPI d3drm3_GetSearchPath(IDirect3DRM3 *iface, DWORD *size, char *path)
1328 FIXME("iface %p, size %p, path %p stub!\n", iface, size, path);
1330 return E_NOTIMPL;
1333 static HRESULT WINAPI d3drm3_SetDefaultTextureColors(IDirect3DRM3 *iface, DWORD color_count)
1335 FIXME("iface %p, color_count %u stub!\n", iface, color_count);
1337 return E_NOTIMPL;
1340 static HRESULT WINAPI d3drm3_SetDefaultTextureShades(IDirect3DRM3 *iface, DWORD shade_count)
1342 FIXME("iface %p, shade_count %u stub!\n", iface, shade_count);
1344 return E_NOTIMPL;
1347 static HRESULT WINAPI d3drm3_GetDevices(IDirect3DRM3 *iface, IDirect3DRMDeviceArray **array)
1349 FIXME("iface %p, array %p stub!\n", iface, array);
1351 return E_NOTIMPL;
1354 static HRESULT WINAPI d3drm3_GetNamedObject(IDirect3DRM3 *iface,
1355 const char *name, IDirect3DRMObject **object)
1357 FIXME("iface %p, name %s, object %p stub!\n", iface, debugstr_a(name), object);
1359 return E_NOTIMPL;
1362 static HRESULT WINAPI d3drm3_EnumerateObjects(IDirect3DRM3 *iface, D3DRMOBJECTCALLBACK cb, void *ctx)
1364 FIXME("iface %p, cb %p, ctx %p stub!\n", iface, cb, ctx);
1366 return E_NOTIMPL;
1369 static HRESULT load_data(IDirect3DRM3 *iface, IDirectXFileData *data_object, IID **GUIDs, DWORD nb_GUIDs, D3DRMLOADCALLBACK LoadProc,
1370 void *ArgLP, D3DRMLOADTEXTURECALLBACK LoadTextureProc, void *ArgLTP, IDirect3DRMFrame3 *parent_frame)
1372 HRESULT ret = D3DRMERR_BADOBJECT;
1373 HRESULT hr;
1374 const GUID* guid;
1375 DWORD i;
1376 BOOL requested = FALSE;
1378 hr = IDirectXFileData_GetType(data_object, &guid);
1379 if (hr != DXFILE_OK)
1380 goto end;
1382 TRACE("Found object type whose GUID = %s\n", debugstr_guid(guid));
1384 /* Load object only if it is top level and requested or if it is part of another object */
1386 if (IsEqualGUID(guid, &TID_D3DRMMesh))
1388 TRACE("Found TID_D3DRMMesh\n");
1390 for (i = 0; i < nb_GUIDs; i++)
1391 if (IsEqualGUID(GUIDs[i], &IID_IDirect3DRMMeshBuilder) ||
1392 IsEqualGUID(GUIDs[i], &IID_IDirect3DRMMeshBuilder2) ||
1393 IsEqualGUID(GUIDs[i], &IID_IDirect3DRMMeshBuilder3))
1395 requested = TRUE;
1396 break;
1399 if (requested || parent_frame)
1401 IDirect3DRMMeshBuilder3 *meshbuilder;
1403 TRACE("Load mesh data\n");
1405 hr = IDirect3DRM3_CreateMeshBuilder(iface, &meshbuilder);
1406 if (SUCCEEDED(hr))
1408 hr = load_mesh_data(meshbuilder, data_object, LoadTextureProc, ArgLTP);
1409 if (SUCCEEDED(hr))
1411 /* Only top level objects are notified */
1412 if (!parent_frame)
1414 IDirect3DRMObject *object;
1416 hr = IDirect3DRMMeshBuilder3_QueryInterface(meshbuilder, GUIDs[i], (void**)&object);
1417 if (SUCCEEDED(hr))
1419 LoadProc(object, GUIDs[i], ArgLP);
1420 IDirect3DRMObject_Release(object);
1423 else
1425 IDirect3DRMFrame3_AddVisual(parent_frame, (IUnknown*)meshbuilder);
1428 IDirect3DRMMeshBuilder3_Release(meshbuilder);
1431 if (FAILED(hr))
1432 ERR("Cannot process mesh\n");
1435 else if (IsEqualGUID(guid, &TID_D3DRMFrame))
1437 TRACE("Found TID_D3DRMFrame\n");
1439 for (i = 0; i < nb_GUIDs; i++)
1440 if (IsEqualGUID(GUIDs[i], &IID_IDirect3DRMFrame) ||
1441 IsEqualGUID(GUIDs[i], &IID_IDirect3DRMFrame2) ||
1442 IsEqualGUID(GUIDs[i], &IID_IDirect3DRMFrame3))
1444 requested = TRUE;
1445 break;
1448 if (requested || parent_frame)
1450 IDirect3DRMFrame3 *frame;
1452 TRACE("Load frame data\n");
1454 hr = IDirect3DRM3_CreateFrame(iface, parent_frame, &frame);
1455 if (SUCCEEDED(hr))
1457 IDirectXFileObject *child;
1459 while (SUCCEEDED(hr = IDirectXFileData_GetNextObject(data_object, &child)))
1461 IDirectXFileData *data;
1462 IDirectXFileDataReference *reference;
1463 IDirectXFileBinary *binary;
1465 if (SUCCEEDED(IDirectXFileObject_QueryInterface(child,
1466 &IID_IDirectXFileBinary, (void **)&binary)))
1468 FIXME("Binary Object not supported yet\n");
1469 IDirectXFileBinary_Release(binary);
1471 else if (SUCCEEDED(IDirectXFileObject_QueryInterface(child,
1472 &IID_IDirectXFileData, (void **)&data)))
1474 TRACE("Found Data Object\n");
1475 hr = load_data(iface, data, GUIDs, nb_GUIDs, LoadProc, ArgLP, LoadTextureProc, ArgLTP, frame);
1476 IDirectXFileData_Release(data);
1478 else if (SUCCEEDED(IDirectXFileObject_QueryInterface(child,
1479 &IID_IDirectXFileDataReference, (void **)&reference)))
1481 TRACE("Found Data Object Reference\n");
1482 IDirectXFileDataReference_Resolve(reference, &data);
1483 hr = load_data(iface, data, GUIDs, nb_GUIDs, LoadProc, ArgLP, LoadTextureProc, ArgLTP, frame);
1484 IDirectXFileData_Release(data);
1485 IDirectXFileDataReference_Release(reference);
1487 IDirectXFileObject_Release(child);
1490 if (hr != DXFILEERR_NOMOREOBJECTS)
1492 IDirect3DRMFrame3_Release(frame);
1493 goto end;
1495 hr = S_OK;
1497 /* Only top level objects are notified */
1498 if (!parent_frame)
1500 IDirect3DRMObject *object;
1502 hr = IDirect3DRMFrame3_QueryInterface(frame, GUIDs[i], (void**)&object);
1503 if (SUCCEEDED(hr))
1505 LoadProc(object, GUIDs[i], ArgLP);
1506 IDirect3DRMObject_Release(object);
1509 IDirect3DRMFrame3_Release(frame);
1512 if (FAILED(hr))
1513 ERR("Cannot process frame\n");
1516 else if (IsEqualGUID(guid, &TID_D3DRMMaterial))
1518 TRACE("Found TID_D3DRMMaterial\n");
1520 /* Cannot be requested so nothing to do */
1522 else if (IsEqualGUID(guid, &TID_D3DRMFrameTransformMatrix))
1524 TRACE("Found TID_D3DRMFrameTransformMatrix\n");
1526 /* Cannot be requested */
1527 if (parent_frame)
1529 D3DRMMATRIX4D *matrix;
1530 DWORD size;
1532 TRACE("Load Frame Transform Matrix data\n");
1534 hr = IDirectXFileData_GetData(data_object, NULL, &size, (void**)&matrix);
1535 if ((hr != DXFILE_OK) || (size != sizeof(matrix)))
1536 goto end;
1538 hr = IDirect3DRMFrame3_AddTransform(parent_frame, D3DRMCOMBINE_REPLACE, *matrix);
1539 if (FAILED(hr))
1540 goto end;
1543 else
1545 FIXME("Found unknown TID %s\n", debugstr_guid(guid));
1548 ret = D3DRM_OK;
1550 end:
1552 return ret;
1555 static HRESULT WINAPI d3drm3_Load(IDirect3DRM3 *iface, void *source, void *object_id, IID **iids,
1556 DWORD iid_count, D3DRMLOADOPTIONS flags, D3DRMLOADCALLBACK load_cb, void *load_ctx,
1557 D3DRMLOADTEXTURECALLBACK load_tex_cb, void *load_tex_ctx, IDirect3DRMFrame3 *parent_frame)
1559 DXFILELOADOPTIONS load_options;
1560 IDirectXFile *file = NULL;
1561 IDirectXFileEnumObject *enum_object = NULL;
1562 IDirectXFileData *data = NULL;
1563 HRESULT hr;
1564 const GUID* pGuid;
1565 DWORD size;
1566 struct d3drm_file_header *header;
1567 HRESULT ret = D3DRMERR_BADOBJECT;
1568 DWORD i;
1570 TRACE("iface %p, source %p, object_id %p, iids %p, iid_count %u, flags %#x, "
1571 "load_cb %p, load_ctx %p, load_tex_cb %p, load_tex_ctx %p, parent_frame %p.\n",
1572 iface, source, object_id, iids, iid_count, flags,
1573 load_cb, load_ctx, load_tex_cb, load_tex_ctx, parent_frame);
1575 TRACE("Looking for GUIDs:\n");
1576 for (i = 0; i < iid_count; ++i)
1577 TRACE("- %s (%s)\n", debugstr_guid(iids[i]), get_IID_string(iids[i]));
1579 if (flags == D3DRMLOAD_FROMMEMORY)
1581 load_options = DXFILELOAD_FROMMEMORY;
1583 else if (flags == D3DRMLOAD_FROMFILE)
1585 load_options = DXFILELOAD_FROMFILE;
1586 TRACE("Loading from file %s\n", debugstr_a(source));
1588 else
1590 FIXME("Load options %#x not supported yet.\n", flags);
1591 return E_NOTIMPL;
1594 hr = DirectXFileCreate(&file);
1595 if (hr != DXFILE_OK)
1596 goto end;
1598 hr = IDirectXFile_RegisterTemplates(file, templates, strlen(templates));
1599 if (hr != DXFILE_OK)
1600 goto end;
1602 hr = IDirectXFile_CreateEnumObject(file, source, load_options, &enum_object);
1603 if (hr != DXFILE_OK)
1604 goto end;
1606 hr = IDirectXFileEnumObject_GetNextDataObject(enum_object, &data);
1607 if (hr != DXFILE_OK)
1608 goto end;
1610 hr = IDirectXFileData_GetType(data, &pGuid);
1611 if (hr != DXFILE_OK)
1612 goto end;
1614 TRACE("Found object type whose GUID = %s\n", debugstr_guid(pGuid));
1616 if (!IsEqualGUID(pGuid, &TID_DXFILEHeader))
1618 ret = D3DRMERR_BADFILE;
1619 goto end;
1622 hr = IDirectXFileData_GetData(data, NULL, &size, (void **)&header);
1623 if ((hr != DXFILE_OK) || (size != sizeof(*header)))
1624 goto end;
1626 TRACE("Version is %u.%u, flags %#x.\n", header->major, header->minor, header->flags);
1628 /* Version must be 1.0.x */
1629 if ((header->major != 1) || (header->minor != 0))
1631 ret = D3DRMERR_BADFILE;
1632 goto end;
1635 IDirectXFileData_Release(data);
1636 data = NULL;
1638 while (1)
1640 hr = IDirectXFileEnumObject_GetNextDataObject(enum_object, &data);
1641 if (hr == DXFILEERR_NOMOREOBJECTS)
1643 TRACE("No more object\n");
1644 break;
1646 else if (hr != DXFILE_OK)
1648 ret = D3DRMERR_BADFILE;
1649 goto end;
1652 ret = load_data(iface, data, iids, iid_count, load_cb, load_ctx, load_tex_cb, load_tex_ctx, parent_frame);
1653 if (ret != D3DRM_OK)
1654 goto end;
1656 IDirectXFileData_Release(data);
1657 data = NULL;
1660 ret = D3DRM_OK;
1662 end:
1663 if (data)
1664 IDirectXFileData_Release(data);
1665 if (enum_object)
1666 IDirectXFileEnumObject_Release(enum_object);
1667 if (file)
1668 IDirectXFile_Release(file);
1670 return ret;
1673 static HRESULT WINAPI d3drm3_Tick(IDirect3DRM3 *iface, D3DVALUE tick)
1675 FIXME("iface %p, tick %.8e stub!\n", iface, tick);
1677 return E_NOTIMPL;
1680 static HRESULT WINAPI d3drm3_CreateProgressiveMesh(IDirect3DRM3 *iface, IDirect3DRMProgressiveMesh **mesh)
1682 FIXME("iface %p, mesh %p stub!\n", iface, mesh);
1684 return E_NOTIMPL;
1687 static HRESULT WINAPI d3drm3_RegisterClient(IDirect3DRM3 *iface, REFGUID guid, DWORD *id)
1689 FIXME("iface %p, guid %s, id %p stub!\n", iface, debugstr_guid(guid), id);
1691 return E_NOTIMPL;
1694 static HRESULT WINAPI d3drm3_UnregisterClient(IDirect3DRM3 *iface, REFGUID guid)
1696 FIXME("iface %p, guid %s stub!\n", iface, debugstr_guid(guid));
1698 return E_NOTIMPL;
1701 static HRESULT WINAPI d3drm3_CreateClippedVisual(IDirect3DRM3 *iface,
1702 IDirect3DRMVisual *visual, IDirect3DRMClippedVisual **clipped_visual)
1704 FIXME("iface %p, visual %p, clipped_visual %p stub!\n", iface, visual, clipped_visual);
1706 return E_NOTIMPL;
1709 static HRESULT WINAPI d3drm3_SetOptions(IDirect3DRM3 *iface, DWORD flags)
1711 FIXME("iface %p, flags %#x stub!\n", iface, flags);
1713 return E_NOTIMPL;
1716 static HRESULT WINAPI d3drm3_GetOptions(IDirect3DRM3 *iface, DWORD *flags)
1718 FIXME("iface %p, flags %p stub!\n", iface, flags);
1720 return E_NOTIMPL;
1723 static const struct IDirect3DRM3Vtbl d3drm3_vtbl =
1725 d3drm3_QueryInterface,
1726 d3drm3_AddRef,
1727 d3drm3_Release,
1728 d3drm3_CreateObject,
1729 d3drm3_CreateFrame,
1730 d3drm3_CreateMesh,
1731 d3drm3_CreateMeshBuilder,
1732 d3drm3_CreateFace,
1733 d3drm3_CreateAnimation,
1734 d3drm3_CreateAnimationSet,
1735 d3drm3_CreateTexture,
1736 d3drm3_CreateLight,
1737 d3drm3_CreateLightRGB,
1738 d3drm3_CreateMaterial,
1739 d3drm3_CreateDevice,
1740 d3drm3_CreateDeviceFromSurface,
1741 d3drm3_CreateDeviceFromD3D,
1742 d3drm3_CreateDeviceFromClipper,
1743 d3drm3_CreateTextureFromSurface,
1744 d3drm3_CreateShadow,
1745 d3drm3_CreateViewport,
1746 d3drm3_CreateWrap,
1747 d3drm3_CreateUserVisual,
1748 d3drm3_LoadTexture,
1749 d3drm3_LoadTextureFromResource,
1750 d3drm3_SetSearchPath,
1751 d3drm3_AddSearchPath,
1752 d3drm3_GetSearchPath,
1753 d3drm3_SetDefaultTextureColors,
1754 d3drm3_SetDefaultTextureShades,
1755 d3drm3_GetDevices,
1756 d3drm3_GetNamedObject,
1757 d3drm3_EnumerateObjects,
1758 d3drm3_Load,
1759 d3drm3_Tick,
1760 d3drm3_CreateProgressiveMesh,
1761 d3drm3_RegisterClient,
1762 d3drm3_UnregisterClient,
1763 d3drm3_CreateClippedVisual,
1764 d3drm3_SetOptions,
1765 d3drm3_GetOptions,
1768 HRESULT WINAPI Direct3DRMCreate(IDirect3DRM **d3drm)
1770 struct d3drm *object;
1772 TRACE("d3drm %p.\n", d3drm);
1774 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
1775 return E_OUTOFMEMORY;
1777 object->IDirect3DRM_iface.lpVtbl = &d3drm1_vtbl;
1778 object->IDirect3DRM2_iface.lpVtbl = &d3drm2_vtbl;
1779 object->IDirect3DRM3_iface.lpVtbl = &d3drm3_vtbl;
1780 object->ref1 = 1;
1781 object->iface_count = 1;
1783 *d3drm = &object->IDirect3DRM_iface;
1785 return S_OK;
1788 HRESULT WINAPI DllCanUnloadNow(void)
1790 return S_FALSE;
1793 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
1795 TRACE("(%s, %s, %p): stub\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
1797 if(!ppv)
1798 return E_INVALIDARG;
1800 return CLASS_E_CLASSNOTAVAILABLE;