2 * Copyright (C) 2012 Józef Kucia
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.
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.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "d3dx9_private.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(d3dx
);
27 DWORD num_render_targets
;
28 IDirect3DSurface9
**render_targets
;
29 IDirect3DSurface9
*depth_stencil
;
30 D3DVIEWPORT9 viewport
;
33 static HRESULT
device_state_init(IDirect3DDevice9
*device
, struct device_state
*state
)
39 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
40 if (FAILED(hr
)) return hr
;
42 state
->num_render_targets
= caps
.NumSimultaneousRTs
;
43 state
->render_targets
= HeapAlloc(GetProcessHeap(), 0,
44 state
->num_render_targets
* sizeof(IDirect3DSurface9
*));
45 if (!state
->render_targets
)
48 for (i
= 0; i
< state
->num_render_targets
; i
++)
49 state
->render_targets
[i
] = NULL
;
50 state
->depth_stencil
= NULL
;
54 static void device_state_capture(IDirect3DDevice9
*device
, struct device_state
*state
)
59 IDirect3DDevice9_GetViewport(device
, &state
->viewport
);
61 for (i
= 0; i
< state
->num_render_targets
; i
++)
63 hr
= IDirect3DDevice9_GetRenderTarget(device
, i
, &state
->render_targets
[i
]);
64 if (FAILED(hr
)) state
->render_targets
[i
] = NULL
;
67 hr
= IDirect3DDevice9_GetDepthStencilSurface(device
, &state
->depth_stencil
);
68 if (FAILED(hr
)) state
->depth_stencil
= NULL
;
71 static void device_state_restore(IDirect3DDevice9
*device
, struct device_state
*state
)
75 for (i
= 0; i
< state
->num_render_targets
; i
++)
77 IDirect3DDevice9_SetRenderTarget(device
, i
, state
->render_targets
[i
]);
78 if (state
->render_targets
[i
])
79 IDirect3DSurface9_Release(state
->render_targets
[i
]);
80 state
->render_targets
[i
] = NULL
;
83 IDirect3DDevice9_SetDepthStencilSurface(device
, state
->depth_stencil
);
84 if (state
->depth_stencil
)
86 IDirect3DSurface9_Release(state
->depth_stencil
);
87 state
->depth_stencil
= NULL
;
90 IDirect3DDevice9_SetViewport(device
, &state
->viewport
);
93 static void device_state_release(struct device_state
*state
)
97 for (i
= 0; i
< state
->num_render_targets
; i
++)
99 if (state
->render_targets
[i
])
100 IDirect3DSurface9_Release(state
->render_targets
[i
]);
103 HeapFree(GetProcessHeap(), 0, state
->render_targets
);
105 if (state
->depth_stencil
) IDirect3DSurface9_Release(state
->depth_stencil
);
108 struct render_to_surface
110 ID3DXRenderToSurface ID3DXRenderToSurface_iface
;
113 IDirect3DDevice9
*device
;
116 IDirect3DSurface9
*dst_surface
;
118 IDirect3DSurface9
*render_target
;
119 IDirect3DSurface9
*depth_stencil
;
121 struct device_state previous_state
;
124 static inline struct render_to_surface
*impl_from_ID3DXRenderToSurface(ID3DXRenderToSurface
*iface
)
126 return CONTAINING_RECORD(iface
, struct render_to_surface
, ID3DXRenderToSurface_iface
);
129 static HRESULT WINAPI
D3DXRenderToSurface_QueryInterface(ID3DXRenderToSurface
*iface
,
133 TRACE("iface %p, riid %s, out %p\n", iface
, debugstr_guid(riid
), out
);
135 if (IsEqualGUID(riid
, &IID_ID3DXRenderToSurface
)
136 || IsEqualGUID(riid
, &IID_IUnknown
))
138 IUnknown_AddRef(iface
);
143 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid
));
146 return E_NOINTERFACE
;
149 static ULONG WINAPI
D3DXRenderToSurface_AddRef(ID3DXRenderToSurface
*iface
)
151 struct render_to_surface
*render
= impl_from_ID3DXRenderToSurface(iface
);
152 ULONG ref
= InterlockedIncrement(&render
->ref
);
154 TRACE("%p increasing refcount to %lu.\n", iface
, ref
);
159 static ULONG WINAPI
D3DXRenderToSurface_Release(ID3DXRenderToSurface
*iface
)
161 struct render_to_surface
*render
= impl_from_ID3DXRenderToSurface(iface
);
162 ULONG ref
= InterlockedDecrement(&render
->ref
);
164 TRACE("%p decreasing refcount to %lu.\n", iface
, ref
);
168 if (render
->dst_surface
) IDirect3DSurface9_Release(render
->dst_surface
);
170 if (render
->render_target
) IDirect3DSurface9_Release(render
->render_target
);
171 if (render
->depth_stencil
) IDirect3DSurface9_Release(render
->depth_stencil
);
173 device_state_release(&render
->previous_state
);
175 IDirect3DDevice9_Release(render
->device
);
177 HeapFree(GetProcessHeap(), 0, render
);
183 static HRESULT WINAPI
D3DXRenderToSurface_GetDevice(ID3DXRenderToSurface
*iface
,
184 IDirect3DDevice9
**device
)
186 struct render_to_surface
*render
= impl_from_ID3DXRenderToSurface(iface
);
188 TRACE("iface %p, device %p.\n", iface
, device
);
190 if (!device
) return D3DERR_INVALIDCALL
;
192 IDirect3DDevice9_AddRef(render
->device
);
193 *device
= render
->device
;
197 static HRESULT WINAPI
D3DXRenderToSurface_GetDesc(ID3DXRenderToSurface
*iface
,
200 struct render_to_surface
*render
= impl_from_ID3DXRenderToSurface(iface
);
202 TRACE("iface %p, desc %p.\n", iface
, desc
);
204 if (!desc
) return D3DERR_INVALIDCALL
;
206 *desc
= render
->desc
;
210 static HRESULT WINAPI
D3DXRenderToSurface_BeginScene(ID3DXRenderToSurface
*iface
,
211 IDirect3DSurface9
*surface
,
212 const D3DVIEWPORT9
*viewport
)
214 struct render_to_surface
*render
= impl_from_ID3DXRenderToSurface(iface
);
216 IDirect3DDevice9
*device
;
217 D3DSURFACE_DESC surface_desc
;
218 HRESULT hr
= D3DERR_INVALIDCALL
;
219 D3DMULTISAMPLE_TYPE multi_sample_type
= D3DMULTISAMPLE_NONE
;
220 DWORD multi_sample_quality
= 0;
222 TRACE("iface %p, surface %p, viewport %p.\n", iface
, surface
, viewport
);
224 if (!surface
|| render
->dst_surface
) return D3DERR_INVALIDCALL
;
226 IDirect3DSurface9_GetDesc(surface
, &surface_desc
);
227 if (surface_desc
.Format
!= render
->desc
.Format
228 || surface_desc
.Width
!= render
->desc
.Width
229 || surface_desc
.Height
!= render
->desc
.Height
)
230 return D3DERR_INVALIDCALL
;
234 if (viewport
->X
> render
->desc
.Width
|| viewport
->Y
> render
->desc
.Height
235 || viewport
->X
+ viewport
->Width
> render
->desc
.Width
236 || viewport
->Y
+ viewport
->Height
> render
->desc
.Height
)
237 return D3DERR_INVALIDCALL
;
239 if (!(surface_desc
.Usage
& D3DUSAGE_RENDERTARGET
)
240 && (viewport
->X
!= 0 || viewport
->Y
!= 0
241 || viewport
->Width
!= render
->desc
.Width
242 || viewport
->Height
!= render
->desc
.Height
))
243 return D3DERR_INVALIDCALL
;
246 device
= render
->device
;
248 device_state_capture(device
, &render
->previous_state
);
250 /* prepare for rendering to surface */
251 for (i
= 1; i
< render
->previous_state
.num_render_targets
; i
++)
252 IDirect3DDevice9_SetRenderTarget(device
, i
, NULL
);
254 if (surface_desc
.Usage
& D3DUSAGE_RENDERTARGET
)
256 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, surface
);
257 multi_sample_type
= surface_desc
.MultiSampleType
;
258 multi_sample_quality
= surface_desc
.MultiSampleQuality
;
262 hr
= IDirect3DDevice9_CreateRenderTarget(device
, render
->desc
.Width
, render
->desc
.Height
,
263 render
->desc
.Format
, multi_sample_type
, multi_sample_quality
, FALSE
,
264 &render
->render_target
, NULL
);
265 if (FAILED(hr
)) goto cleanup
;
266 hr
= IDirect3DDevice9_SetRenderTarget(device
, 0, render
->render_target
);
269 if (FAILED(hr
)) goto cleanup
;
271 if (render
->desc
.DepthStencil
)
273 hr
= IDirect3DDevice9_CreateDepthStencilSurface(device
, render
->desc
.Width
, render
->desc
.Height
,
274 render
->desc
.DepthStencilFormat
, multi_sample_type
, multi_sample_quality
, TRUE
,
275 &render
->depth_stencil
, NULL
);
277 else render
->depth_stencil
= NULL
;
279 if (FAILED(hr
)) goto cleanup
;
281 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, render
->depth_stencil
);
282 if (FAILED(hr
)) goto cleanup
;
284 if (viewport
) IDirect3DDevice9_SetViewport(device
, viewport
);
286 IDirect3DSurface9_AddRef(surface
);
287 render
->dst_surface
= surface
;
288 return IDirect3DDevice9_BeginScene(device
);
291 device_state_restore(device
, &render
->previous_state
);
293 if (render
->dst_surface
) IDirect3DSurface9_Release(render
->dst_surface
);
294 render
->dst_surface
= NULL
;
296 if (render
->render_target
) IDirect3DSurface9_Release(render
->render_target
);
297 render
->render_target
= NULL
;
298 if (render
->depth_stencil
) IDirect3DSurface9_Release(render
->depth_stencil
);
299 render
->depth_stencil
= NULL
;
304 static HRESULT WINAPI
D3DXRenderToSurface_EndScene(ID3DXRenderToSurface
*iface
,
307 struct render_to_surface
*render
= impl_from_ID3DXRenderToSurface(iface
);
310 TRACE("iface %p, filter %#lx.\n", iface
, filter
);
312 if (!render
->dst_surface
) return D3DERR_INVALIDCALL
;
314 hr
= IDirect3DDevice9_EndScene(render
->device
);
316 /* copy render target data to destination surface, if needed */
317 if (render
->render_target
)
319 hr
= D3DXLoadSurfaceFromSurface(render
->dst_surface
, NULL
, NULL
,
320 render
->render_target
, NULL
, NULL
, filter
, 0);
322 ERR("Copying render target data to surface failed, hr %#lx.\n", hr
);
325 device_state_restore(render
->device
, &render
->previous_state
);
327 /* release resources */
328 if (render
->render_target
)
330 IDirect3DSurface9_Release(render
->render_target
);
331 render
->render_target
= NULL
;
334 if (render
->depth_stencil
)
336 IDirect3DSurface9_Release(render
->depth_stencil
);
337 render
->depth_stencil
= NULL
;
340 IDirect3DSurface9_Release(render
->dst_surface
);
341 render
->dst_surface
= NULL
;
346 static HRESULT WINAPI
D3DXRenderToSurface_OnLostDevice(ID3DXRenderToSurface
*iface
)
348 FIXME("iface %p stub!\n", iface
);
352 static HRESULT WINAPI
D3DXRenderToSurface_OnResetDevice(ID3DXRenderToSurface
*iface
)
354 FIXME("iface %p stub!\n", iface
);
358 static const ID3DXRenderToSurfaceVtbl render_to_surface_vtbl
=
360 /* IUnknown methods */
361 D3DXRenderToSurface_QueryInterface
,
362 D3DXRenderToSurface_AddRef
,
363 D3DXRenderToSurface_Release
,
364 /* ID3DXRenderToSurface methods */
365 D3DXRenderToSurface_GetDevice
,
366 D3DXRenderToSurface_GetDesc
,
367 D3DXRenderToSurface_BeginScene
,
368 D3DXRenderToSurface_EndScene
,
369 D3DXRenderToSurface_OnLostDevice
,
370 D3DXRenderToSurface_OnResetDevice
373 HRESULT WINAPI
D3DXCreateRenderToSurface(IDirect3DDevice9
*device
,
378 D3DFORMAT depth_stencil_format
,
379 ID3DXRenderToSurface
**out
)
382 struct render_to_surface
*render
;
384 TRACE("device %p, width %u, height %u, format %#x, depth_stencil %#x, depth_stencil_format %#x, out %p.\n",
385 device
, width
, height
, format
, depth_stencil
, depth_stencil_format
, out
);
387 if (!device
|| !out
) return D3DERR_INVALIDCALL
;
389 render
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct render_to_surface
));
390 if (!render
) return E_OUTOFMEMORY
;
392 render
->ID3DXRenderToSurface_iface
.lpVtbl
= &render_to_surface_vtbl
;
395 render
->desc
.Width
= width
;
396 render
->desc
.Height
= height
;
397 render
->desc
.Format
= format
;
398 render
->desc
.DepthStencil
= depth_stencil
;
399 render
->desc
.DepthStencilFormat
= depth_stencil_format
;
401 render
->dst_surface
= NULL
;
402 render
->render_target
= NULL
;
403 render
->depth_stencil
= NULL
;
405 hr
= device_state_init(device
, &render
->previous_state
);
408 HeapFree(GetProcessHeap(), 0, render
);
412 IDirect3DDevice9_AddRef(device
);
413 render
->device
= device
;
415 *out
= &render
->ID3DXRenderToSurface_iface
;
428 struct render_to_envmap
430 ID3DXRenderToEnvMap ID3DXRenderToEnvMap_iface
;
433 IDirect3DDevice9
*device
;
436 enum render_state state
;
437 struct device_state previous_device_state
;
439 D3DCUBEMAP_FACES face
;
442 IDirect3DSurface9
*render_target
;
443 IDirect3DSurface9
*depth_stencil
;
445 IDirect3DCubeTexture9
*dst_cube_texture
;
448 static void copy_render_target_to_cube_texture_face(IDirect3DCubeTexture9
*cube_texture
,
449 D3DCUBEMAP_FACES face
, IDirect3DSurface9
*render_target
, DWORD filter
)
452 IDirect3DSurface9
*cube_surface
;
454 IDirect3DCubeTexture9_GetCubeMapSurface(cube_texture
, face
, 0, &cube_surface
);
456 hr
= D3DXLoadSurfaceFromSurface(cube_surface
, NULL
, NULL
, render_target
, NULL
, NULL
, filter
, 0);
458 ERR("Copying render target data to surface failed, hr %#lx.\n", hr
);
460 IDirect3DSurface9_Release(cube_surface
);
463 static inline struct render_to_envmap
*impl_from_ID3DXRenderToEnvMap(ID3DXRenderToEnvMap
*iface
)
465 return CONTAINING_RECORD(iface
, struct render_to_envmap
, ID3DXRenderToEnvMap_iface
);
468 static HRESULT WINAPI
D3DXRenderToEnvMap_QueryInterface(ID3DXRenderToEnvMap
*iface
,
472 TRACE("iface %p, riid %s, out %p\n", iface
, debugstr_guid(riid
), out
);
474 if (IsEqualGUID(riid
, &IID_ID3DXRenderToEnvMap
)
475 || IsEqualGUID(riid
, &IID_IUnknown
))
477 IUnknown_AddRef(iface
);
482 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid
));
485 return E_NOINTERFACE
;
488 static ULONG WINAPI
D3DXRenderToEnvMap_AddRef(ID3DXRenderToEnvMap
*iface
)
490 struct render_to_envmap
*render
= impl_from_ID3DXRenderToEnvMap(iface
);
491 ULONG ref
= InterlockedIncrement(&render
->ref
);
493 TRACE("%p increasing refcount to %lu.\n", iface
, ref
);
498 static ULONG WINAPI
D3DXRenderToEnvMap_Release(ID3DXRenderToEnvMap
*iface
)
500 struct render_to_envmap
*render
= impl_from_ID3DXRenderToEnvMap(iface
);
501 ULONG ref
= InterlockedDecrement(&render
->ref
);
503 TRACE("%p decreasing refcount to %lu.\n", iface
, ref
);
507 if (render
->dst_cube_texture
) IDirect3DSurface9_Release(render
->dst_cube_texture
);
509 if (render
->render_target
) IDirect3DSurface9_Release(render
->render_target
);
510 if (render
->depth_stencil
) IDirect3DSurface9_Release(render
->depth_stencil
);
512 device_state_release(&render
->previous_device_state
);
514 IDirect3DDevice9_Release(render
->device
);
516 HeapFree(GetProcessHeap(), 0, render
);
522 static HRESULT WINAPI
D3DXRenderToEnvMap_GetDevice(ID3DXRenderToEnvMap
*iface
,
523 IDirect3DDevice9
**device
)
525 struct render_to_envmap
*render
= impl_from_ID3DXRenderToEnvMap(iface
);
527 TRACE("iface %p, device %p.\n", iface
, device
);
529 if (!device
) return D3DERR_INVALIDCALL
;
531 IDirect3DDevice9_AddRef(render
->device
);
532 *device
= render
->device
;
536 static HRESULT WINAPI
D3DXRenderToEnvMap_GetDesc(ID3DXRenderToEnvMap
*iface
,
539 struct render_to_envmap
*render
= impl_from_ID3DXRenderToEnvMap(iface
);
541 TRACE("iface %p, desc %p.\n", iface
, desc
);
543 if (!desc
) return D3DERR_INVALIDCALL
;
545 *desc
= render
->desc
;
549 static HRESULT WINAPI
D3DXRenderToEnvMap_BeginCube(ID3DXRenderToEnvMap
*iface
,
550 IDirect3DCubeTexture9
*texture
)
552 struct render_to_envmap
*render
= impl_from_ID3DXRenderToEnvMap(iface
);
554 D3DSURFACE_DESC level_desc
;
556 TRACE("iface %p, texture %p.\n", iface
, texture
);
558 if (!texture
) return D3DERR_INVALIDCALL
;
560 if (render
->state
!= INITIAL
) return D3DERR_INVALIDCALL
;
562 IDirect3DCubeTexture9_GetLevelDesc(texture
, 0, &level_desc
);
563 if (level_desc
.Format
!= render
->desc
.Format
|| level_desc
.Width
!= render
->desc
.Size
)
564 return D3DERR_INVALIDCALL
;
566 if (!(level_desc
.Usage
& D3DUSAGE_RENDERTARGET
))
568 hr
= IDirect3DDevice9_CreateRenderTarget(render
->device
, level_desc
.Width
, level_desc
.Height
,
569 level_desc
.Format
, level_desc
.MultiSampleType
, level_desc
.MultiSampleQuality
,
570 TRUE
, &render
->render_target
, NULL
);
571 if (FAILED(hr
)) goto cleanup
;
572 IDirect3DCubeTexture9_GetLevelDesc(texture
, 0, &level_desc
);
575 if (render
->desc
.DepthStencil
)
577 hr
= IDirect3DDevice9_CreateDepthStencilSurface(render
->device
, level_desc
.Width
, level_desc
.Height
,
578 render
->desc
.DepthStencilFormat
, level_desc
.MultiSampleType
, level_desc
.MultiSampleQuality
,
579 TRUE
, &render
->depth_stencil
, NULL
);
580 if (FAILED(hr
)) goto cleanup
;
583 IDirect3DCubeTexture9_AddRef(texture
);
584 render
->dst_cube_texture
= texture
;
585 render
->state
= CUBE_BEGIN
;
589 if (render
->dst_cube_texture
) IDirect3DSurface9_Release(render
->dst_cube_texture
);
590 render
->dst_cube_texture
= NULL
;
592 if (render
->render_target
) IDirect3DSurface9_Release(render
->render_target
);
593 render
->render_target
= NULL
;
594 if (render
->depth_stencil
) IDirect3DSurface9_Release(render
->depth_stencil
);
595 render
->depth_stencil
= NULL
;
600 static HRESULT WINAPI
D3DXRenderToEnvMap_BeginSphere(ID3DXRenderToEnvMap
*iface
,
601 IDirect3DTexture9
*texture
)
603 FIXME("iface %p, texture %p stub!\n", iface
, texture
);
607 static HRESULT WINAPI
D3DXRenderToEnvMap_BeginHemisphere(ID3DXRenderToEnvMap
*iface
,
608 IDirect3DTexture9
*pos_z_texture
,
609 IDirect3DTexture9
*neg_z_texture
)
611 FIXME("iface %p, pos_z_texture %p, neg_z_texture %p stub!\n", iface
, pos_z_texture
, neg_z_texture
);
615 static HRESULT WINAPI
D3DXRenderToEnvMap_BeginParabolic(ID3DXRenderToEnvMap
*iface
,
616 IDirect3DTexture9
*pos_z_texture
,
617 IDirect3DTexture9
*neg_z_texture
)
619 FIXME("iface %p, pos_z_texture %p, neg_z_texture %p stub!\n", iface
, pos_z_texture
, neg_z_texture
);
623 static HRESULT WINAPI
D3DXRenderToEnvMap_Face(ID3DXRenderToEnvMap
*iface
,
624 D3DCUBEMAP_FACES face
,
627 struct render_to_envmap
*render
= impl_from_ID3DXRenderToEnvMap(iface
);
631 TRACE("iface %p, face %u, filter %#lx.\n", iface
, face
, filter
);
633 if (render
->state
== CUBE_FACE
)
635 IDirect3DDevice9_EndScene(render
->device
);
636 if (render
->render_target
)
637 copy_render_target_to_cube_texture_face(render
->dst_cube_texture
, render
->face
,
638 render
->render_target
, render
->filter
);
640 device_state_restore(render
->device
, &render
->previous_device_state
);
642 render
->state
= CUBE_BEGIN
;
644 else if (render
->state
!= CUBE_BEGIN
)
645 return D3DERR_INVALIDCALL
;
647 device_state_capture(render
->device
, &render
->previous_device_state
);
649 for (i
= 1; i
< render
->previous_device_state
.num_render_targets
; i
++)
650 IDirect3DDevice9_SetRenderTarget(render
->device
, i
, NULL
);
652 if (!render
->render_target
)
654 IDirect3DSurface9
*render_target
;
655 IDirect3DCubeTexture9_GetCubeMapSurface(render
->dst_cube_texture
, face
, 0, &render_target
);
656 hr
= IDirect3DDevice9_SetRenderTarget(render
->device
, 0, render_target
);
657 IDirect3DSurface9_Release(render_target
);
659 else hr
= IDirect3DDevice9_SetRenderTarget(render
->device
, 0, render
->render_target
);
661 if (FAILED(hr
)) goto cleanup
;
663 hr
= IDirect3DDevice9_SetDepthStencilSurface(render
->device
, render
->depth_stencil
);
664 if (FAILED(hr
)) goto cleanup
;
666 render
->state
= CUBE_FACE
;
668 render
->filter
= filter
;
669 return IDirect3DDevice9_BeginScene(render
->device
);
672 device_state_restore(render
->device
, &render
->previous_device_state
);
676 static HRESULT WINAPI
D3DXRenderToEnvMap_End(ID3DXRenderToEnvMap
*iface
,
679 struct render_to_envmap
*render
= impl_from_ID3DXRenderToEnvMap(iface
);
681 TRACE("iface %p, filter %#lx.\n", iface
, filter
);
683 if (render
->state
== INITIAL
) return D3DERR_INVALIDCALL
;
685 if (render
->state
== CUBE_FACE
)
687 IDirect3DDevice9_EndScene(render
->device
);
688 if (render
->render_target
)
689 copy_render_target_to_cube_texture_face(render
->dst_cube_texture
, render
->face
,
690 render
->render_target
, render
->filter
);
692 device_state_restore(render
->device
, &render
->previous_device_state
);
695 D3DXFilterTexture((IDirect3DBaseTexture9
*)render
->dst_cube_texture
, NULL
, 0, filter
);
697 if (render
->render_target
)
699 IDirect3DSurface9_Release(render
->render_target
);
700 render
->render_target
= NULL
;
703 if (render
->depth_stencil
)
705 IDirect3DSurface9_Release(render
->depth_stencil
);
706 render
->depth_stencil
= NULL
;
709 IDirect3DSurface9_Release(render
->dst_cube_texture
);
710 render
->dst_cube_texture
= NULL
;
712 render
->state
= INITIAL
;
716 static HRESULT WINAPI
D3DXRenderToEnvMap_OnLostDevice(ID3DXRenderToEnvMap
*iface
)
718 FIXME("iface %p stub!\n", iface
);
722 static HRESULT WINAPI
D3DXRenderToEnvMap_OnResetDevice(ID3DXRenderToEnvMap
*iface
)
724 FIXME("iface %p stub!\n", iface
);
728 static const ID3DXRenderToEnvMapVtbl render_to_envmap_vtbl
=
730 /* IUnknown methods */
731 D3DXRenderToEnvMap_QueryInterface
,
732 D3DXRenderToEnvMap_AddRef
,
733 D3DXRenderToEnvMap_Release
,
734 /* ID3DXRenderToEnvMap methods */
735 D3DXRenderToEnvMap_GetDevice
,
736 D3DXRenderToEnvMap_GetDesc
,
737 D3DXRenderToEnvMap_BeginCube
,
738 D3DXRenderToEnvMap_BeginSphere
,
739 D3DXRenderToEnvMap_BeginHemisphere
,
740 D3DXRenderToEnvMap_BeginParabolic
,
741 D3DXRenderToEnvMap_Face
,
742 D3DXRenderToEnvMap_End
,
743 D3DXRenderToEnvMap_OnLostDevice
,
744 D3DXRenderToEnvMap_OnResetDevice
747 HRESULT WINAPI
D3DXCreateRenderToEnvMap(IDirect3DDevice9
*device
,
752 D3DFORMAT depth_stencil_format
,
753 ID3DXRenderToEnvMap
**out
)
756 struct render_to_envmap
*render
;
758 TRACE("(%p, %u, %u, %#x, %d, %#x, %p)\n", device
, size
, mip_levels
,
759 format
, depth_stencil
, depth_stencil_format
, out
);
761 if (!device
|| !out
) return D3DERR_INVALIDCALL
;
763 hr
= D3DXCheckTextureRequirements(device
, &size
, &size
, &mip_levels
,
764 D3DUSAGE_RENDERTARGET
, &format
, D3DPOOL_DEFAULT
);
765 if (FAILED(hr
)) return hr
;
767 render
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct render_to_envmap
));
768 if (!render
) return E_OUTOFMEMORY
;
770 render
->ID3DXRenderToEnvMap_iface
.lpVtbl
= &render_to_envmap_vtbl
;
773 render
->desc
.Size
= size
;
774 render
->desc
.MipLevels
= mip_levels
;
775 render
->desc
.Format
= format
;
776 render
->desc
.DepthStencil
= depth_stencil
;
777 render
->desc
.DepthStencilFormat
= depth_stencil_format
;
779 render
->state
= INITIAL
;
780 render
->render_target
= NULL
;
781 render
->depth_stencil
= NULL
;
782 render
->dst_cube_texture
= NULL
;
784 hr
= device_state_init(device
, &render
->previous_device_state
);
787 HeapFree(GetProcessHeap(), 0, render
);
791 IDirect3DDevice9_AddRef(device
);
792 render
->device
= device
;
794 *out
= &render
->ID3DXRenderToEnvMap_iface
;