2 * IDirect3DDevice8 implementation
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2004 Christian Costa
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
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
33 #include "wine/debug.h"
35 #include "d3d8_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
39 D3DFORMAT d3dformat_from_wined3dformat(enum wined3d_format_id format)
41 BYTE *c = (BYTE *)&format;
43 /* Don't translate FOURCC formats */
44 if (isprint(c[0]) && isprint(c[1]) && isprint(c[2]) && isprint(c[3])) return format;
48 case WINED3DFMT_UNKNOWN: return D3DFMT_UNKNOWN;
49 case WINED3DFMT_B8G8R8_UNORM: return D3DFMT_R8G8B8;
50 case WINED3DFMT_B8G8R8A8_UNORM: return D3DFMT_A8R8G8B8;
51 case WINED3DFMT_B8G8R8X8_UNORM: return D3DFMT_X8R8G8B8;
52 case WINED3DFMT_B5G6R5_UNORM: return D3DFMT_R5G6B5;
53 case WINED3DFMT_B5G5R5X1_UNORM: return D3DFMT_X1R5G5B5;
54 case WINED3DFMT_B5G5R5A1_UNORM: return D3DFMT_A1R5G5B5;
55 case WINED3DFMT_B4G4R4A4_UNORM: return D3DFMT_A4R4G4B4;
56 case WINED3DFMT_B2G3R3_UNORM: return D3DFMT_R3G3B2;
57 case WINED3DFMT_A8_UNORM: return D3DFMT_A8;
58 case WINED3DFMT_B2G3R3A8_UNORM: return D3DFMT_A8R3G3B2;
59 case WINED3DFMT_B4G4R4X4_UNORM: return D3DFMT_X4R4G4B4;
60 case WINED3DFMT_R10G10B10A2_UNORM: return D3DFMT_A2B10G10R10;
61 case WINED3DFMT_R16G16_UNORM: return D3DFMT_G16R16;
62 case WINED3DFMT_P8_UINT_A8_UNORM: return D3DFMT_A8P8;
63 case WINED3DFMT_P8_UINT: return D3DFMT_P8;
64 case WINED3DFMT_L8_UNORM: return D3DFMT_L8;
65 case WINED3DFMT_L8A8_UNORM: return D3DFMT_A8L8;
66 case WINED3DFMT_L4A4_UNORM: return D3DFMT_A4L4;
67 case WINED3DFMT_R8G8_SNORM: return D3DFMT_V8U8;
68 case WINED3DFMT_R5G5_SNORM_L6_UNORM: return D3DFMT_L6V5U5;
69 case WINED3DFMT_R8G8_SNORM_L8X8_UNORM: return D3DFMT_X8L8V8U8;
70 case WINED3DFMT_R8G8B8A8_SNORM: return D3DFMT_Q8W8V8U8;
71 case WINED3DFMT_R16G16_SNORM: return D3DFMT_V16U16;
72 case WINED3DFMT_R10G11B11_SNORM: return D3DFMT_W11V11U10;
73 case WINED3DFMT_R10G10B10_SNORM_A2_UNORM: return D3DFMT_A2W10V10U10;
74 case WINED3DFMT_D16_LOCKABLE: return D3DFMT_D16_LOCKABLE;
75 case WINED3DFMT_D32_UNORM: return D3DFMT_D32;
76 case WINED3DFMT_S1_UINT_D15_UNORM: return D3DFMT_D15S1;
77 case WINED3DFMT_D24_UNORM_S8_UINT: return D3DFMT_D24S8;
78 case WINED3DFMT_X8D24_UNORM: return D3DFMT_D24X8;
79 case WINED3DFMT_S4X4_UINT_D24_UNORM: return D3DFMT_D24X4S4;
80 case WINED3DFMT_D16_UNORM: return D3DFMT_D16;
81 case WINED3DFMT_VERTEXDATA: return D3DFMT_VERTEXDATA;
82 case WINED3DFMT_R16_UINT: return D3DFMT_INDEX16;
83 case WINED3DFMT_R32_UINT: return D3DFMT_INDEX32;
85 FIXME("Unhandled wined3d format %#x.\n", format);
86 return D3DFMT_UNKNOWN;
90 enum wined3d_format_id wined3dformat_from_d3dformat(D3DFORMAT format)
92 BYTE *c = (BYTE *)&format;
94 /* Don't translate FOURCC formats */
95 if (isprint(c[0]) && isprint(c[1]) && isprint(c[2]) && isprint(c[3])) return format;
99 case D3DFMT_UNKNOWN: return WINED3DFMT_UNKNOWN;
100 case D3DFMT_R8G8B8: return WINED3DFMT_B8G8R8_UNORM;
101 case D3DFMT_A8R8G8B8: return WINED3DFMT_B8G8R8A8_UNORM;
102 case D3DFMT_X8R8G8B8: return WINED3DFMT_B8G8R8X8_UNORM;
103 case D3DFMT_R5G6B5: return WINED3DFMT_B5G6R5_UNORM;
104 case D3DFMT_X1R5G5B5: return WINED3DFMT_B5G5R5X1_UNORM;
105 case D3DFMT_A1R5G5B5: return WINED3DFMT_B5G5R5A1_UNORM;
106 case D3DFMT_A4R4G4B4: return WINED3DFMT_B4G4R4A4_UNORM;
107 case D3DFMT_R3G3B2: return WINED3DFMT_B2G3R3_UNORM;
108 case D3DFMT_A8: return WINED3DFMT_A8_UNORM;
109 case D3DFMT_A8R3G3B2: return WINED3DFMT_B2G3R3A8_UNORM;
110 case D3DFMT_X4R4G4B4: return WINED3DFMT_B4G4R4X4_UNORM;
111 case D3DFMT_A2B10G10R10: return WINED3DFMT_R10G10B10A2_UNORM;
112 case D3DFMT_G16R16: return WINED3DFMT_R16G16_UNORM;
113 case D3DFMT_A8P8: return WINED3DFMT_P8_UINT_A8_UNORM;
114 case D3DFMT_P8: return WINED3DFMT_P8_UINT;
115 case D3DFMT_L8: return WINED3DFMT_L8_UNORM;
116 case D3DFMT_A8L8: return WINED3DFMT_L8A8_UNORM;
117 case D3DFMT_A4L4: return WINED3DFMT_L4A4_UNORM;
118 case D3DFMT_V8U8: return WINED3DFMT_R8G8_SNORM;
119 case D3DFMT_L6V5U5: return WINED3DFMT_R5G5_SNORM_L6_UNORM;
120 case D3DFMT_X8L8V8U8: return WINED3DFMT_R8G8_SNORM_L8X8_UNORM;
121 case D3DFMT_Q8W8V8U8: return WINED3DFMT_R8G8B8A8_SNORM;
122 case D3DFMT_V16U16: return WINED3DFMT_R16G16_SNORM;
123 case D3DFMT_W11V11U10: return WINED3DFMT_R10G11B11_SNORM;
124 case D3DFMT_A2W10V10U10: return WINED3DFMT_R10G10B10_SNORM_A2_UNORM;
125 case D3DFMT_D16_LOCKABLE: return WINED3DFMT_D16_LOCKABLE;
126 case D3DFMT_D32: return WINED3DFMT_D32_UNORM;
127 case D3DFMT_D15S1: return WINED3DFMT_S1_UINT_D15_UNORM;
128 case D3DFMT_D24S8: return WINED3DFMT_D24_UNORM_S8_UINT;
129 case D3DFMT_D24X8: return WINED3DFMT_X8D24_UNORM;
130 case D3DFMT_D24X4S4: return WINED3DFMT_S4X4_UINT_D24_UNORM;
131 case D3DFMT_D16: return WINED3DFMT_D16_UNORM;
132 case D3DFMT_VERTEXDATA: return WINED3DFMT_VERTEXDATA;
133 case D3DFMT_INDEX16: return WINED3DFMT_R16_UINT;
134 case D3DFMT_INDEX32: return WINED3DFMT_R32_UINT;
136 FIXME("Unhandled D3DFORMAT %#x\n", format);
137 return WINED3DFMT_UNKNOWN;
141 static UINT vertex_count_from_primitive_count(D3DPRIMITIVETYPE primitive_type, UINT primitive_count)
143 switch(primitive_type)
145 case D3DPT_POINTLIST:
146 return primitive_count;
149 return primitive_count * 2;
151 case D3DPT_LINESTRIP:
152 return primitive_count + 1;
154 case D3DPT_TRIANGLELIST:
155 return primitive_count * 3;
157 case D3DPT_TRIANGLESTRIP:
158 case D3DPT_TRIANGLEFAN:
159 return primitive_count + 2;
162 FIXME("Unhandled primitive type %#x\n", primitive_type);
167 /* Handle table functions */
168 static DWORD d3d8_allocate_handle(struct d3d8_handle_table *t, void *object, enum d3d8_handle_type type)
170 struct d3d8_handle_entry *entry;
174 DWORD index = t->free_entries - t->entries;
175 /* Use a free handle */
176 entry = t->free_entries;
177 if (entry->type != D3D8_HANDLE_FREE)
179 ERR("Handle %u(%p) is in the free list, but has type %#x.\n", index, entry, entry->type);
180 return D3D8_INVALID_HANDLE;
182 t->free_entries = entry->object;
183 entry->object = object;
189 if (!(t->entry_count < t->table_size))
192 UINT new_size = t->table_size + (t->table_size >> 1);
193 struct d3d8_handle_entry *new_entries = HeapReAlloc(GetProcessHeap(),
194 0, t->entries, new_size * sizeof(*t->entries));
197 ERR("Failed to grow the handle table.\n");
198 return D3D8_INVALID_HANDLE;
200 t->entries = new_entries;
201 t->table_size = new_size;
204 entry = &t->entries[t->entry_count];
205 entry->object = object;
208 return t->entry_count++;
211 static void *d3d8_free_handle(struct d3d8_handle_table *t, DWORD handle, enum d3d8_handle_type type)
213 struct d3d8_handle_entry *entry;
216 if (handle == D3D8_INVALID_HANDLE || handle >= t->entry_count)
218 WARN("Invalid handle %u passed.\n", handle);
222 entry = &t->entries[handle];
223 if (entry->type != type)
225 WARN("Handle %u(%p) is not of type %#x.\n", handle, entry, type);
229 object = entry->object;
230 entry->object = t->free_entries;
231 entry->type = D3D8_HANDLE_FREE;
232 t->free_entries = entry;
237 static void *d3d8_get_object(struct d3d8_handle_table *t, DWORD handle, enum d3d8_handle_type type)
239 struct d3d8_handle_entry *entry;
241 if (handle == D3D8_INVALID_HANDLE || handle >= t->entry_count)
243 WARN("Invalid handle %u passed.\n", handle);
247 entry = &t->entries[handle];
248 if (entry->type != type)
250 WARN("Handle %u(%p) is not of type %#x.\n", handle, entry, type);
254 return entry->object;
257 static inline IDirect3DDevice8Impl *impl_from_IDirect3DDevice8(IDirect3DDevice8 *iface)
259 return CONTAINING_RECORD(iface, IDirect3DDevice8Impl, IDirect3DDevice8_iface);
262 static HRESULT WINAPI IDirect3DDevice8Impl_QueryInterface(IDirect3DDevice8 *iface, REFIID riid,
265 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
267 TRACE("iface %p, riid %s, object %p.\n",
268 iface, debugstr_guid(riid), ppobj);
270 if (IsEqualGUID(riid, &IID_IUnknown)
271 || IsEqualGUID(riid, &IID_IDirect3DDevice8)) {
272 IUnknown_AddRef(iface);
277 if (IsEqualGUID(riid, &IID_IWineD3DDeviceParent))
279 IWineD3DDeviceParent_AddRef(&This->IWineD3DDeviceParent_iface);
280 *ppobj = &This->IWineD3DDeviceParent_iface;
284 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
286 return E_NOINTERFACE;
289 static ULONG WINAPI IDirect3DDevice8Impl_AddRef(IDirect3DDevice8 *iface)
291 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
292 ULONG ref = InterlockedIncrement(&This->ref);
294 TRACE("%p increasing refcount to %u.\n", iface, ref);
299 static ULONG WINAPI IDirect3DDevice8Impl_Release(IDirect3DDevice8 *iface)
301 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
304 if (This->inDestruction) return 0;
305 ref = InterlockedDecrement(&This->ref);
307 TRACE("%p decreasing refcount to %u.\n", iface, ref);
312 TRACE("Releasing wined3d device %p\n", This->WineD3DDevice);
314 wined3d_mutex_lock();
316 This->inDestruction = TRUE;
318 for(i = 0; i < This->numConvertedDecls; i++) {
319 IDirect3DVertexDeclaration8_Release(This->decls[i].decl);
321 HeapFree(GetProcessHeap(), 0, This->decls);
323 IWineD3DDevice_Uninit3D(This->WineD3DDevice);
324 IWineD3DDevice_ReleaseFocusWindow(This->WineD3DDevice);
325 IWineD3DDevice_Release(This->WineD3DDevice);
326 HeapFree(GetProcessHeap(), 0, This->handle_table.entries);
327 HeapFree(GetProcessHeap(), 0, This);
329 wined3d_mutex_unlock();
334 /* IDirect3DDevice Interface follow: */
335 static HRESULT WINAPI IDirect3DDevice8Impl_TestCooperativeLevel(IDirect3DDevice8 *iface)
337 IDirect3DDevice8Impl *device = impl_from_IDirect3DDevice8(iface);
339 TRACE("iface %p.\n", iface);
343 TRACE("Device is lost.\n");
344 return D3DERR_DEVICENOTRESET;
350 static UINT WINAPI IDirect3DDevice8Impl_GetAvailableTextureMem(IDirect3DDevice8 *iface)
352 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
355 TRACE("iface %p.\n", iface);
357 wined3d_mutex_lock();
358 hr = IWineD3DDevice_GetAvailableTextureMem(This->WineD3DDevice);
359 wined3d_mutex_unlock();
364 static HRESULT WINAPI IDirect3DDevice8Impl_ResourceManagerDiscardBytes(IDirect3DDevice8 *iface,
367 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
370 TRACE("iface %p, byte_count %u.\n", iface, Bytes);
371 FIXME("Byte count ignored.\n");
373 wined3d_mutex_lock();
374 hr = IWineD3DDevice_EvictManagedResources(This->WineD3DDevice);
375 wined3d_mutex_unlock();
380 static HRESULT WINAPI IDirect3DDevice8Impl_GetDirect3D(IDirect3DDevice8 *iface, IDirect3D8 **ppD3D8)
382 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
383 struct wined3d *wined3d;
386 TRACE("iface %p, d3d8 %p.\n", iface, ppD3D8);
388 if (NULL == ppD3D8) {
389 return D3DERR_INVALIDCALL;
392 wined3d_mutex_lock();
393 hr = IWineD3DDevice_GetDirect3D(This->WineD3DDevice, &wined3d);
394 if (SUCCEEDED(hr) && wined3d)
396 *ppD3D8 = wined3d_get_parent(wined3d);
397 IDirect3D8_AddRef(*ppD3D8);
398 wined3d_decref(wined3d);
402 FIXME("Call to IWineD3DDevice_GetDirect3D failed\n");
405 wined3d_mutex_unlock();
407 TRACE("(%p) returning %p\n",This , *ppD3D8);
412 static HRESULT WINAPI IDirect3DDevice8Impl_GetDeviceCaps(IDirect3DDevice8 *iface, D3DCAPS8 *pCaps)
414 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
415 HRESULT hrc = D3D_OK;
416 WINED3DCAPS *pWineCaps;
418 TRACE("iface %p, caps %p.\n", iface, pCaps);
421 return D3DERR_INVALIDCALL;
423 pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
424 if(pWineCaps == NULL){
425 return D3DERR_INVALIDCALL; /* well this is what MSDN says to return */
428 wined3d_mutex_lock();
429 hrc = IWineD3DDevice_GetDeviceCaps(This->WineD3DDevice, pWineCaps);
430 wined3d_mutex_unlock();
432 fixup_caps(pWineCaps);
433 WINECAPSTOD3D8CAPS(pCaps, pWineCaps)
434 HeapFree(GetProcessHeap(), 0, pWineCaps);
436 TRACE("Returning %p %p\n", This, pCaps);
440 static HRESULT WINAPI IDirect3DDevice8Impl_GetDisplayMode(IDirect3DDevice8 *iface,
441 D3DDISPLAYMODE *pMode)
443 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
446 TRACE("iface %p, mode %p.\n", iface, pMode);
448 wined3d_mutex_lock();
449 hr = IWineD3DDevice_GetDisplayMode(This->WineD3DDevice, 0, (WINED3DDISPLAYMODE *) pMode);
450 wined3d_mutex_unlock();
452 if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
457 static HRESULT WINAPI IDirect3DDevice8Impl_GetCreationParameters(IDirect3DDevice8 *iface,
458 D3DDEVICE_CREATION_PARAMETERS *pParameters)
460 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
463 TRACE("iface %p, parameters %p.\n", iface, pParameters);
465 wined3d_mutex_lock();
466 hr = IWineD3DDevice_GetCreationParameters(This->WineD3DDevice, (WINED3DDEVICE_CREATION_PARAMETERS *) pParameters);
467 wined3d_mutex_unlock();
472 static HRESULT WINAPI IDirect3DDevice8Impl_SetCursorProperties(IDirect3DDevice8 *iface,
473 UINT XHotSpot, UINT YHotSpot, IDirect3DSurface8 *pCursorBitmap)
475 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
476 IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl*)pCursorBitmap;
479 TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
480 iface, XHotSpot, YHotSpot, pCursorBitmap);
484 WARN("No cursor bitmap, returning D3DERR_INVALIDCALL.\n");
485 return D3DERR_INVALIDCALL;
488 wined3d_mutex_lock();
489 hr = IWineD3DDevice_SetCursorProperties(This->WineD3DDevice, XHotSpot, YHotSpot, pSurface->wined3d_surface);
490 wined3d_mutex_unlock();
495 static void WINAPI IDirect3DDevice8Impl_SetCursorPosition(IDirect3DDevice8 *iface,
496 UINT XScreenSpace, UINT YScreenSpace, DWORD Flags)
498 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
500 TRACE("iface %p, x %u, y %u, flags %#x.\n",
501 iface, XScreenSpace, YScreenSpace, Flags);
503 wined3d_mutex_lock();
504 IWineD3DDevice_SetCursorPosition(This->WineD3DDevice, XScreenSpace, YScreenSpace, Flags);
505 wined3d_mutex_unlock();
508 static BOOL WINAPI IDirect3DDevice8Impl_ShowCursor(IDirect3DDevice8 *iface, BOOL bShow)
510 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
513 TRACE("iface %p, show %#x.\n", iface, bShow);
515 wined3d_mutex_lock();
516 ret = IWineD3DDevice_ShowCursor(This->WineD3DDevice, bShow);
517 wined3d_mutex_unlock();
522 static HRESULT WINAPI IDirect3DDevice8Impl_CreateAdditionalSwapChain(IDirect3DDevice8 *iface,
523 D3DPRESENT_PARAMETERS *present_parameters, IDirect3DSwapChain8 **swapchain)
525 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
526 IDirect3DSwapChain8Impl *object;
529 TRACE("iface %p, present_parameters %p, swapchain %p.\n",
530 iface, present_parameters, swapchain);
532 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
535 ERR("Failed to allocate swapchain memory.\n");
536 return E_OUTOFMEMORY;
539 hr = swapchain_init(object, This, present_parameters);
542 WARN("Failed to initialize swapchain, hr %#x.\n", hr);
543 HeapFree(GetProcessHeap(), 0, object);
547 TRACE("Created swapchain %p.\n", object);
548 *swapchain = &object->IDirect3DSwapChain8_iface;
553 static HRESULT WINAPI reset_enum_callback(struct wined3d_resource *resource, void *data)
555 struct wined3d_resource_desc desc;
556 BOOL *resources_ok = data;
558 wined3d_resource_get_desc(resource, &desc);
559 if (desc.pool == WINED3DPOOL_DEFAULT)
561 IDirect3DSurface8 *surface;
563 if (desc.resource_type != WINED3DRTYPE_SURFACE)
565 WARN("Resource %p in pool D3DPOOL_DEFAULT blocks the Reset call.\n", resource);
566 *resources_ok = FALSE;
570 surface = wined3d_resource_get_parent(resource);
572 IDirect3DSurface8_AddRef(surface);
573 if (IDirect3DSurface8_Release(surface))
575 WARN("Surface %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", surface, resource);
576 *resources_ok = FALSE;
580 WARN("Surface %p (resource %p) is an implicit resource with ref 0.\n", surface, resource);
586 static HRESULT WINAPI IDirect3DDevice8Impl_Reset(IDirect3DDevice8 *iface,
587 D3DPRESENT_PARAMETERS *pPresentationParameters)
589 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
590 WINED3DPRESENT_PARAMETERS localParameters;
591 BOOL resources_ok = TRUE;
595 TRACE("iface %p, present_parameters %p.\n", iface, pPresentationParameters);
597 wined3d_mutex_lock();
598 IWineD3DDevice_SetIndexBuffer(This->WineD3DDevice, NULL, WINED3DFMT_UNKNOWN);
599 for (i = 0; i < 16; ++i)
601 IWineD3DDevice_SetStreamSource(This->WineD3DDevice, i, NULL, 0, 0);
603 for (i = 0; i < 16; ++i)
605 IWineD3DDevice_SetTexture(This->WineD3DDevice, i, NULL);
608 IWineD3DDevice_EnumResources(This->WineD3DDevice, reset_enum_callback, &resources_ok);
611 WARN("The application is holding D3DPOOL_DEFAULT resources, rejecting reset.\n");
613 wined3d_mutex_unlock();
615 return D3DERR_DEVICELOST;
618 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
619 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
620 localParameters.BackBufferFormat = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
621 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
622 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
623 localParameters.MultiSampleQuality = 0; /* d3d9 only */
624 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
625 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
626 localParameters.Windowed = pPresentationParameters->Windowed;
627 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
628 localParameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
629 localParameters.Flags = pPresentationParameters->Flags;
630 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
631 localParameters.PresentationInterval = pPresentationParameters->FullScreen_PresentationInterval;
632 localParameters.AutoRestoreDisplayMode = TRUE;
634 hr = IWineD3DDevice_Reset(This->WineD3DDevice, &localParameters);
637 hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, WINED3DRS_POINTSIZE_MIN, 0);
644 wined3d_mutex_unlock();
646 pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
647 pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
648 pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(localParameters.BackBufferFormat);
649 pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
650 pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
651 pPresentationParameters->SwapEffect = localParameters.SwapEffect;
652 pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
653 pPresentationParameters->Windowed = localParameters.Windowed;
654 pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
655 pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat);
656 pPresentationParameters->Flags = localParameters.Flags;
657 pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
658 pPresentationParameters->FullScreen_PresentationInterval = localParameters.PresentationInterval;
663 static HRESULT WINAPI IDirect3DDevice8Impl_Present(IDirect3DDevice8 *iface, const RECT *pSourceRect,
664 const RECT *pDestRect, HWND hDestWindowOverride, const RGNDATA *pDirtyRegion)
666 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
669 TRACE("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p.\n",
670 iface, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
672 wined3d_mutex_lock();
673 hr = IWineD3DDevice_Present(This->WineD3DDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
674 wined3d_mutex_unlock();
679 static HRESULT WINAPI IDirect3DDevice8Impl_GetBackBuffer(IDirect3DDevice8 *iface,
680 UINT BackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface8 **ppBackBuffer)
682 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
683 struct wined3d_surface *wined3d_surface = NULL;
686 TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
687 iface, BackBuffer, Type, ppBackBuffer);
689 wined3d_mutex_lock();
690 hr = IWineD3DDevice_GetBackBuffer(This->WineD3DDevice, 0,
691 BackBuffer, (WINED3DBACKBUFFER_TYPE)Type, &wined3d_surface);
692 if (SUCCEEDED(hr) && wined3d_surface && ppBackBuffer)
694 *ppBackBuffer = wined3d_surface_get_parent(wined3d_surface);
695 IDirect3DSurface8_AddRef(*ppBackBuffer);
696 wined3d_surface_decref(wined3d_surface);
698 wined3d_mutex_unlock();
703 static HRESULT WINAPI IDirect3DDevice8Impl_GetRasterStatus(IDirect3DDevice8 *iface,
704 D3DRASTER_STATUS *pRasterStatus)
706 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
709 TRACE("iface %p, raster_status %p.\n", iface, pRasterStatus);
711 wined3d_mutex_lock();
712 hr = IWineD3DDevice_GetRasterStatus(This->WineD3DDevice, 0, (WINED3DRASTER_STATUS *) pRasterStatus);
713 wined3d_mutex_unlock();
718 static void WINAPI IDirect3DDevice8Impl_SetGammaRamp(IDirect3DDevice8 *iface, DWORD Flags,
719 const D3DGAMMARAMP *pRamp)
721 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
723 TRACE("iface %p, flags %#x, ramp %p.\n", iface, Flags, pRamp);
725 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
726 wined3d_mutex_lock();
727 IWineD3DDevice_SetGammaRamp(This->WineD3DDevice, 0, Flags, (CONST WINED3DGAMMARAMP *) pRamp);
728 wined3d_mutex_unlock();
731 static void WINAPI IDirect3DDevice8Impl_GetGammaRamp(IDirect3DDevice8 *iface, D3DGAMMARAMP *pRamp)
733 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
735 TRACE("iface %p, ramp %p.\n", iface, pRamp);
737 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
738 wined3d_mutex_lock();
739 IWineD3DDevice_GetGammaRamp(This->WineD3DDevice, 0, (WINED3DGAMMARAMP *) pRamp);
740 wined3d_mutex_unlock();
743 static HRESULT WINAPI IDirect3DDevice8Impl_CreateTexture(IDirect3DDevice8 *iface,
744 UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format,
745 D3DPOOL pool, IDirect3DTexture8 **texture)
747 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
748 IDirect3DTexture8Impl *object;
751 TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
752 iface, width, height, levels, usage, format, pool, texture);
754 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
757 ERR("Failed to allocate texture memory.\n");
758 return D3DERR_OUTOFVIDEOMEMORY;
761 hr = texture_init(object, This, width, height, levels, usage, format, pool);
764 WARN("Failed to initialize texture, hr %#x.\n", hr);
765 HeapFree(GetProcessHeap(), 0, object);
769 TRACE("Created texture %p.\n", object);
770 *texture = &object->IDirect3DTexture8_iface;
775 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVolumeTexture(IDirect3DDevice8 *iface,
776 UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format,
777 D3DPOOL pool, IDirect3DVolumeTexture8 **texture)
779 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
780 IDirect3DVolumeTexture8Impl *object;
783 TRACE("iface %p, width %u, height %u, depth %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
784 iface, width, height, depth, levels, usage, format, pool, texture);
786 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
789 ERR("Failed to allocate volume texture memory.\n");
790 return D3DERR_OUTOFVIDEOMEMORY;
793 hr = volumetexture_init(object, This, width, height, depth, levels, usage, format, pool);
796 WARN("Failed to initialize volume texture, hr %#x.\n", hr);
797 HeapFree(GetProcessHeap(), 0, object);
801 TRACE("Created volume texture %p.\n", object);
802 *texture = &object->IDirect3DVolumeTexture8_iface;
807 static HRESULT WINAPI IDirect3DDevice8Impl_CreateCubeTexture(IDirect3DDevice8 *iface, UINT edge_length,
808 UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool, IDirect3DCubeTexture8 **texture)
810 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
811 IDirect3DCubeTexture8Impl *object;
814 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
815 iface, edge_length, levels, usage, format, pool, texture);
817 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
820 ERR("Failed to allocate cube texture memory.\n");
821 return D3DERR_OUTOFVIDEOMEMORY;
824 hr = cubetexture_init(object, This, edge_length, levels, usage, format, pool);
827 WARN("Failed to initialize cube texture, hr %#x.\n", hr);
828 HeapFree(GetProcessHeap(), 0, object);
832 TRACE("Created cube texture %p.\n", object);
833 *texture = &object->IDirect3DCubeTexture8_iface;
838 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexBuffer(IDirect3DDevice8 *iface, UINT size,
839 DWORD usage, DWORD fvf, D3DPOOL pool, IDirect3DVertexBuffer8 **buffer)
841 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
842 IDirect3DVertexBuffer8Impl *object;
845 TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p.\n",
846 iface, size, usage, fvf, pool, buffer);
848 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
851 ERR("Failed to allocate buffer memory.\n");
852 return D3DERR_OUTOFVIDEOMEMORY;
855 hr = vertexbuffer_init(object, This, size, usage, fvf, pool);
858 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr);
859 HeapFree(GetProcessHeap(), 0, object);
863 TRACE("Created vertex buffer %p.\n", object);
864 *buffer = (IDirect3DVertexBuffer8 *)object;
869 static HRESULT WINAPI IDirect3DDevice8Impl_CreateIndexBuffer(IDirect3DDevice8 *iface, UINT size,
870 DWORD usage, D3DFORMAT format, D3DPOOL pool, IDirect3DIndexBuffer8 **buffer)
872 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
873 IDirect3DIndexBuffer8Impl *object;
876 TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p.\n",
877 iface, size, usage, format, pool, buffer);
879 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
882 ERR("Failed to allocate buffer memory.\n");
883 return D3DERR_OUTOFVIDEOMEMORY;
886 hr = indexbuffer_init(object, This, size, usage, format, pool);
889 WARN("Failed to initialize index buffer, hr %#x.\n", hr);
890 HeapFree(GetProcessHeap(), 0, object);
894 TRACE("Created index buffer %p.\n", object);
895 *buffer = (IDirect3DIndexBuffer8 *)object;
900 static HRESULT IDirect3DDevice8Impl_CreateSurface(IDirect3DDevice8Impl *device, UINT Width,
901 UINT Height, D3DFORMAT Format, BOOL Lockable, BOOL Discard, UINT Level,
902 IDirect3DSurface8 **ppSurface, UINT Usage, D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample,
903 DWORD MultisampleQuality)
905 IDirect3DSurface8Impl *object;
908 TRACE("device %p, width %u, height %u, format %#x, lockable %#x, discard %#x, level %u, surface %p,\n"
909 "\tusage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
910 device, Width, Height, Format, Lockable, Discard, Level, ppSurface,
911 Usage, Pool, MultiSample, MultisampleQuality);
913 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface8Impl));
916 FIXME("Failed to allocate surface memory.\n");
917 return D3DERR_OUTOFVIDEOMEMORY;
920 hr = surface_init(object, device, Width, Height, Format, Lockable, Discard, Level, Usage,
921 Pool, MultiSample, MultisampleQuality);
924 WARN("Failed to initialize surface, hr %#x.\n", hr);
925 HeapFree(GetProcessHeap(), 0, object);
929 TRACE("Created surface %p.\n", object);
930 *ppSurface = (IDirect3DSurface8 *)object;
935 static HRESULT WINAPI IDirect3DDevice8Impl_CreateRenderTarget(IDirect3DDevice8 *iface, UINT Width,
936 UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, BOOL Lockable,
937 IDirect3DSurface8 **ppSurface)
939 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
942 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, lockable %#x, surface %p.\n",
943 iface, Width, Height, Format, MultiSample, Lockable, ppSurface);
945 hr = IDirect3DDevice8Impl_CreateSurface(This, Width, Height, Format, Lockable,
946 FALSE /* Discard */, 0 /* Level */, ppSurface, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT,
952 static HRESULT WINAPI IDirect3DDevice8Impl_CreateDepthStencilSurface(IDirect3DDevice8 *iface,
953 UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample,
954 IDirect3DSurface8 **ppSurface)
956 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
959 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, surface %p.\n",
960 iface, Width, Height, Format, MultiSample, ppSurface);
962 /* TODO: Verify that Discard is false */
963 hr = IDirect3DDevice8Impl_CreateSurface(This, Width, Height, Format, TRUE /* Lockable */, FALSE,
964 0 /* Level */, ppSurface, D3DUSAGE_DEPTHSTENCIL, D3DPOOL_DEFAULT, MultiSample, 0);
969 /* IDirect3DDevice8Impl::CreateImageSurface returns surface with pool type SYSTEMMEM */
970 static HRESULT WINAPI IDirect3DDevice8Impl_CreateImageSurface(IDirect3DDevice8 *iface, UINT Width,
971 UINT Height, D3DFORMAT Format, IDirect3DSurface8 **ppSurface)
973 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
976 TRACE("iface %p, width %u, height %u, format %#x, surface %p.\n",
977 iface, Width, Height, Format, ppSurface);
979 hr = IDirect3DDevice8Impl_CreateSurface(This, Width, Height, Format, TRUE /* Lockable */,
980 FALSE /* Discard */, 0 /* Level */, ppSurface, 0 /* Usage (undefined/none) */,
981 D3DPOOL_SYSTEMMEM, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
986 static HRESULT WINAPI IDirect3DDevice8Impl_CopyRects(IDirect3DDevice8 *iface,
987 IDirect3DSurface8 *pSourceSurface, const RECT *pSourceRects, UINT cRects,
988 IDirect3DSurface8 *pDestinationSurface, const POINT *pDestPoints)
990 IDirect3DSurface8Impl *Source = (IDirect3DSurface8Impl *) pSourceSurface;
991 IDirect3DSurface8Impl *Dest = (IDirect3DSurface8Impl *) pDestinationSurface;
992 enum wined3d_format_id srcFormat, destFormat;
993 struct wined3d_resource_desc wined3d_desc;
994 struct wined3d_resource *wined3d_resource;
996 TRACE("iface %p, src_surface %p, src_rects %p, rect_count %u, dst_surface %p, dst_points %p.\n",
997 iface, pSourceSurface, pSourceRects, cRects, pDestinationSurface, pDestPoints);
999 /* Check that the source texture is in WINED3DPOOL_SYSTEMMEM and the
1000 * destination texture is in WINED3DPOOL_DEFAULT. */
1002 wined3d_mutex_lock();
1003 wined3d_resource = wined3d_surface_get_resource(Source->wined3d_surface);
1004 wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
1005 srcFormat = wined3d_desc.format;
1007 wined3d_resource = wined3d_surface_get_resource(Dest->wined3d_surface);
1008 wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
1009 destFormat = wined3d_desc.format;
1011 /* Check that the source and destination formats match */
1012 if (srcFormat != destFormat && WINED3DFMT_UNKNOWN != destFormat)
1014 WARN("Source %p format must match the dest %p format, returning D3DERR_INVALIDCALL.\n",
1015 pSourceSurface, pDestinationSurface);
1016 wined3d_mutex_unlock();
1017 return D3DERR_INVALIDCALL;
1019 else if (WINED3DFMT_UNKNOWN == destFormat)
1021 TRACE("(%p) : Converting destination surface from WINED3DFMT_UNKNOWN to the source format\n", iface);
1022 wined3d_surface_set_format(Dest->wined3d_surface, srcFormat);
1025 /* Quick if complete copy ... */
1026 if (!cRects && !pSourceRects && !pDestPoints)
1028 wined3d_surface_bltfast(Dest->wined3d_surface, 0, 0,
1029 Source->wined3d_surface, NULL, WINEDDBLTFAST_NOCOLORKEY);
1034 /* Copy rect by rect */
1035 if (pSourceRects && pDestPoints)
1037 for (i = 0; i < cRects; ++i)
1039 wined3d_surface_bltfast(Dest->wined3d_surface, pDestPoints[i].x, pDestPoints[i].y,
1040 Source->wined3d_surface, &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY);
1045 for (i = 0; i < cRects; ++i)
1047 wined3d_surface_bltfast(Dest->wined3d_surface, 0, 0,
1048 Source->wined3d_surface, &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY);
1052 wined3d_mutex_unlock();
1057 static HRESULT WINAPI IDirect3DDevice8Impl_UpdateTexture(IDirect3DDevice8 *iface,
1058 IDirect3DBaseTexture8 *src_texture, IDirect3DBaseTexture8 *dst_texture)
1060 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1063 TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface, src_texture, dst_texture);
1065 wined3d_mutex_lock();
1066 hr = IWineD3DDevice_UpdateTexture(This->WineD3DDevice,
1067 ((IDirect3DBaseTexture8Impl *)src_texture)->wined3d_texture,
1068 ((IDirect3DBaseTexture8Impl *)dst_texture)->wined3d_texture);
1069 wined3d_mutex_unlock();
1074 static HRESULT WINAPI IDirect3DDevice8Impl_GetFrontBuffer(IDirect3DDevice8 *iface,
1075 IDirect3DSurface8 *pDestSurface)
1077 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1078 IDirect3DSurface8Impl *destSurface = (IDirect3DSurface8Impl *)pDestSurface;
1081 TRACE("iface %p, dst_surface %p.\n", iface, pDestSurface);
1083 if (pDestSurface == NULL) {
1084 WARN("(%p) : Caller passed NULL as pDestSurface returning D3DERR_INVALIDCALL\n", This);
1085 return D3DERR_INVALIDCALL;
1088 wined3d_mutex_lock();
1089 hr = IWineD3DDevice_GetFrontBufferData(This->WineD3DDevice, 0, destSurface->wined3d_surface);
1090 wined3d_mutex_unlock();
1095 static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderTarget(IDirect3DDevice8 *iface,
1096 IDirect3DSurface8 *pRenderTarget, IDirect3DSurface8 *pNewZStencil)
1098 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1099 IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl *)pRenderTarget;
1100 IDirect3DSurface8Impl *pZSurface = (IDirect3DSurface8Impl *)pNewZStencil;
1101 struct wined3d_surface *original_ds = NULL;
1104 TRACE("iface %p, render_target %p, depth_stencil %p.\n", iface, pRenderTarget, pNewZStencil);
1106 wined3d_mutex_lock();
1110 struct wined3d_resource_desc ds_desc, rt_desc;
1111 struct wined3d_resource *wined3d_resource;
1112 IDirect3DSurface8 *orig_rt = NULL;
1114 /* If no render target is passed in check the size against the current RT */
1117 hr = IDirect3DDevice8_GetRenderTarget(iface, &orig_rt);
1120 wined3d_mutex_unlock();
1123 pSurface = (IDirect3DSurface8Impl *)orig_rt;
1126 wined3d_resource = wined3d_surface_get_resource(pZSurface->wined3d_surface);
1127 wined3d_resource_get_desc(wined3d_resource, &ds_desc);
1128 wined3d_resource = wined3d_surface_get_resource(pSurface->wined3d_surface);
1129 wined3d_resource_get_desc(wined3d_resource, &rt_desc);
1130 if (orig_rt) IDirect3DSurface8_Release(orig_rt);
1132 if (ds_desc.width < rt_desc.width || ds_desc.height < rt_desc.height)
1134 WARN("Depth stencil is smaller than the render target, returning D3DERR_INVALIDCALL\n");
1135 wined3d_mutex_unlock();
1136 return D3DERR_INVALIDCALL;
1140 hr = IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice, &original_ds);
1141 if (hr == WINED3D_OK || hr == WINED3DERR_NOTFOUND)
1143 hr = IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, pZSurface ? pZSurface->wined3d_surface : NULL);
1144 if (SUCCEEDED(hr) && pRenderTarget)
1146 hr = IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, 0, pSurface->wined3d_surface, TRUE);
1147 if (FAILED(hr)) IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, original_ds);
1151 wined3d_surface_decref(original_ds);
1153 wined3d_mutex_unlock();
1158 static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderTarget(IDirect3DDevice8 *iface,
1159 IDirect3DSurface8 **ppRenderTarget)
1161 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1162 struct wined3d_surface *wined3d_surface;
1165 TRACE("iface %p, render_target %p.\n", iface, ppRenderTarget);
1167 if (ppRenderTarget == NULL) {
1168 return D3DERR_INVALIDCALL;
1171 wined3d_mutex_lock();
1172 hr = IWineD3DDevice_GetRenderTarget(This->WineD3DDevice, 0, &wined3d_surface);
1173 if (SUCCEEDED(hr) && wined3d_surface)
1175 *ppRenderTarget = wined3d_surface_get_parent(wined3d_surface);
1176 IDirect3DSurface8_AddRef(*ppRenderTarget);
1177 wined3d_surface_decref(wined3d_surface);
1181 FIXME("Call to IWineD3DDevice_GetRenderTarget failed\n");
1182 *ppRenderTarget = NULL;
1184 wined3d_mutex_unlock();
1189 static HRESULT WINAPI IDirect3DDevice8Impl_GetDepthStencilSurface(IDirect3DDevice8 *iface,
1190 IDirect3DSurface8 **ppZStencilSurface)
1192 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1193 struct wined3d_surface *wined3d_surface;
1196 TRACE("iface %p, depth_stencil %p.\n", iface, ppZStencilSurface);
1198 if(ppZStencilSurface == NULL){
1199 return D3DERR_INVALIDCALL;
1202 wined3d_mutex_lock();
1203 hr = IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice, &wined3d_surface);
1206 *ppZStencilSurface = wined3d_surface_get_parent(wined3d_surface);
1207 IDirect3DSurface8_AddRef(*ppZStencilSurface);
1208 wined3d_surface_decref(wined3d_surface);
1212 if (hr != WINED3DERR_NOTFOUND)
1213 FIXME("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr);
1214 *ppZStencilSurface = NULL;
1216 wined3d_mutex_unlock();
1221 static HRESULT WINAPI IDirect3DDevice8Impl_BeginScene(IDirect3DDevice8 *iface)
1223 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1226 TRACE("iface %p.\n", iface);
1228 wined3d_mutex_lock();
1229 hr = IWineD3DDevice_BeginScene(This->WineD3DDevice);
1230 wined3d_mutex_unlock();
1235 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice8Impl_EndScene(IDirect3DDevice8 *iface)
1237 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1240 TRACE("iface %p.\n", iface);
1242 wined3d_mutex_lock();
1243 hr = IWineD3DDevice_EndScene(This->WineD3DDevice);
1244 wined3d_mutex_unlock();
1249 static HRESULT WINAPI IDirect3DDevice8Impl_Clear(IDirect3DDevice8 *iface, DWORD Count,
1250 const D3DRECT *pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil)
1252 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1255 TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
1256 iface, Count, pRects, Flags, Color, Z, Stencil);
1258 wined3d_mutex_lock();
1259 hr = IWineD3DDevice_Clear(This->WineD3DDevice, Count, (const RECT *)pRects, Flags, Color, Z, Stencil);
1260 wined3d_mutex_unlock();
1265 static HRESULT WINAPI IDirect3DDevice8Impl_SetTransform(IDirect3DDevice8 *iface,
1266 D3DTRANSFORMSTATETYPE State, const D3DMATRIX *lpMatrix)
1268 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1271 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, lpMatrix);
1273 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1274 wined3d_mutex_lock();
1275 hr = IWineD3DDevice_SetTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) lpMatrix);
1276 wined3d_mutex_unlock();
1281 static HRESULT WINAPI IDirect3DDevice8Impl_GetTransform(IDirect3DDevice8 *iface,
1282 D3DTRANSFORMSTATETYPE State, D3DMATRIX *pMatrix)
1284 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1287 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
1289 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1290 wined3d_mutex_lock();
1291 hr = IWineD3DDevice_GetTransform(This->WineD3DDevice, State, (WINED3DMATRIX*) pMatrix);
1292 wined3d_mutex_unlock();
1297 static HRESULT WINAPI IDirect3DDevice8Impl_MultiplyTransform(IDirect3DDevice8 *iface,
1298 D3DTRANSFORMSTATETYPE State, const D3DMATRIX *pMatrix)
1300 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1303 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
1305 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1306 wined3d_mutex_lock();
1307 hr = IWineD3DDevice_MultiplyTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) pMatrix);
1308 wined3d_mutex_unlock();
1313 static HRESULT WINAPI IDirect3DDevice8Impl_SetViewport(IDirect3DDevice8 *iface,
1314 const D3DVIEWPORT8 *pViewport)
1316 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1319 TRACE("iface %p, viewport %p.\n", iface, pViewport);
1321 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
1322 wined3d_mutex_lock();
1323 hr = IWineD3DDevice_SetViewport(This->WineD3DDevice, (const WINED3DVIEWPORT *)pViewport);
1324 wined3d_mutex_unlock();
1329 static HRESULT WINAPI IDirect3DDevice8Impl_GetViewport(IDirect3DDevice8 *iface,
1330 D3DVIEWPORT8 *pViewport)
1332 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1335 TRACE("iface %p, viewport %p.\n", iface, pViewport);
1337 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
1338 wined3d_mutex_lock();
1339 hr = IWineD3DDevice_GetViewport(This->WineD3DDevice, (WINED3DVIEWPORT *)pViewport);
1340 wined3d_mutex_unlock();
1345 static HRESULT WINAPI IDirect3DDevice8Impl_SetMaterial(IDirect3DDevice8 *iface,
1346 const D3DMATERIAL8 *pMaterial)
1348 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1351 TRACE("iface %p, material %p.\n", iface, pMaterial);
1353 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
1354 wined3d_mutex_lock();
1355 hr = IWineD3DDevice_SetMaterial(This->WineD3DDevice, (const WINED3DMATERIAL *)pMaterial);
1356 wined3d_mutex_unlock();
1361 static HRESULT WINAPI IDirect3DDevice8Impl_GetMaterial(IDirect3DDevice8 *iface,
1362 D3DMATERIAL8 *pMaterial)
1364 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1367 TRACE("iface %p, material %p.\n", iface, pMaterial);
1369 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
1370 wined3d_mutex_lock();
1371 hr = IWineD3DDevice_GetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
1372 wined3d_mutex_unlock();
1377 static HRESULT WINAPI IDirect3DDevice8Impl_SetLight(IDirect3DDevice8 *iface, DWORD Index,
1378 const D3DLIGHT8 *pLight)
1380 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1383 TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
1385 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1386 wined3d_mutex_lock();
1387 hr = IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (const WINED3DLIGHT *)pLight);
1388 wined3d_mutex_unlock();
1393 static HRESULT WINAPI IDirect3DDevice8Impl_GetLight(IDirect3DDevice8 *iface, DWORD Index,
1396 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1399 TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
1401 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1402 wined3d_mutex_lock();
1403 hr = IWineD3DDevice_GetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
1404 wined3d_mutex_unlock();
1409 static HRESULT WINAPI IDirect3DDevice8Impl_LightEnable(IDirect3DDevice8 *iface, DWORD Index,
1412 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1415 TRACE("iface %p, index %u, enable %#x.\n", iface, Index, Enable);
1417 wined3d_mutex_lock();
1418 hr = IWineD3DDevice_SetLightEnable(This->WineD3DDevice, Index, Enable);
1419 wined3d_mutex_unlock();
1424 static HRESULT WINAPI IDirect3DDevice8Impl_GetLightEnable(IDirect3DDevice8 *iface, DWORD Index,
1427 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1430 TRACE("iface %p, index %u, enable %p.\n", iface, Index, pEnable);
1432 wined3d_mutex_lock();
1433 hr = IWineD3DDevice_GetLightEnable(This->WineD3DDevice, Index, pEnable);
1434 wined3d_mutex_unlock();
1439 static HRESULT WINAPI IDirect3DDevice8Impl_SetClipPlane(IDirect3DDevice8 *iface, DWORD Index,
1440 const float *pPlane)
1442 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1445 TRACE("iface %p, index %u, plane %p.\n", iface, Index, pPlane);
1447 wined3d_mutex_lock();
1448 hr = IWineD3DDevice_SetClipPlane(This->WineD3DDevice, Index, pPlane);
1449 wined3d_mutex_unlock();
1454 static HRESULT WINAPI IDirect3DDevice8Impl_GetClipPlane(IDirect3DDevice8 *iface, DWORD Index,
1457 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1460 TRACE("iface %p, index %u, plane %p.\n", iface, Index, pPlane);
1462 wined3d_mutex_lock();
1463 hr = IWineD3DDevice_GetClipPlane(This->WineD3DDevice, Index, pPlane);
1464 wined3d_mutex_unlock();
1469 static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderState(IDirect3DDevice8 *iface,
1470 D3DRENDERSTATETYPE State, DWORD Value)
1472 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1480 TRACE("iface %p, state %#x, value %#x.\n", iface, State, Value);
1482 wined3d_mutex_lock();
1486 wined3d_value.f = Value / -16.0f;
1487 hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, WINED3DRS_DEPTHBIAS, wined3d_value.d);
1491 hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, State, Value);
1493 wined3d_mutex_unlock();
1498 static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderState(IDirect3DDevice8 *iface,
1499 D3DRENDERSTATETYPE State, DWORD *pValue)
1501 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1509 TRACE("iface %p, state %#x, value %p.\n", iface, State, pValue);
1511 wined3d_mutex_lock();
1515 hr = IWineD3DDevice_GetRenderState(This->WineD3DDevice, WINED3DRS_DEPTHBIAS, &wined3d_value.d);
1516 if (SUCCEEDED(hr)) *pValue = -wined3d_value.f * 16.0f;
1520 hr = IWineD3DDevice_GetRenderState(This->WineD3DDevice, State, pValue);
1522 wined3d_mutex_unlock();
1527 static HRESULT WINAPI IDirect3DDevice8Impl_BeginStateBlock(IDirect3DDevice8 *iface)
1529 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1532 TRACE("iface %p.\n", iface);
1534 wined3d_mutex_lock();
1535 hr = IWineD3DDevice_BeginStateBlock(This->WineD3DDevice);
1536 wined3d_mutex_unlock();
1541 static HRESULT WINAPI IDirect3DDevice8Impl_EndStateBlock(IDirect3DDevice8 *iface, DWORD *pToken)
1543 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1544 struct wined3d_stateblock *stateblock;
1547 TRACE("iface %p, token %p.\n", iface, pToken);
1549 /* Tell wineD3D to endstateblock before anything else (in case we run out
1550 * of memory later and cause locking problems)
1552 wined3d_mutex_lock();
1553 hr = IWineD3DDevice_EndStateBlock(This->WineD3DDevice , &stateblock);
1555 WARN("IWineD3DDevice_EndStateBlock returned an error\n");
1556 wined3d_mutex_unlock();
1560 *pToken = d3d8_allocate_handle(&This->handle_table, stateblock, D3D8_HANDLE_SB);
1561 wined3d_mutex_unlock();
1563 if (*pToken == D3D8_INVALID_HANDLE)
1565 ERR("Failed to create a handle\n");
1566 wined3d_mutex_lock();
1567 wined3d_stateblock_decref(stateblock);
1568 wined3d_mutex_unlock();
1573 TRACE("Returning %#x (%p).\n", *pToken, stateblock);
1578 static HRESULT WINAPI IDirect3DDevice8Impl_ApplyStateBlock(IDirect3DDevice8 *iface, DWORD Token)
1580 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1581 struct wined3d_stateblock *stateblock;
1584 TRACE("iface %p, token %#x.\n", iface, Token);
1586 if (!Token) return D3D_OK;
1588 wined3d_mutex_lock();
1589 stateblock = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1592 WARN("Invalid handle (%#x) passed.\n", Token);
1593 wined3d_mutex_unlock();
1594 return D3DERR_INVALIDCALL;
1596 hr = wined3d_stateblock_apply(stateblock);
1597 wined3d_mutex_unlock();
1602 static HRESULT WINAPI IDirect3DDevice8Impl_CaptureStateBlock(IDirect3DDevice8 *iface, DWORD Token)
1604 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1605 struct wined3d_stateblock *stateblock;
1608 TRACE("iface %p, token %#x.\n", iface, Token);
1610 wined3d_mutex_lock();
1611 stateblock = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1614 WARN("Invalid handle (%#x) passed.\n", Token);
1615 wined3d_mutex_unlock();
1616 return D3DERR_INVALIDCALL;
1618 hr = wined3d_stateblock_capture(stateblock);
1619 wined3d_mutex_unlock();
1624 static HRESULT WINAPI IDirect3DDevice8Impl_DeleteStateBlock(IDirect3DDevice8 *iface, DWORD Token)
1626 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1627 struct wined3d_stateblock *stateblock;
1629 TRACE("iface %p, token %#x.\n", iface, Token);
1631 wined3d_mutex_lock();
1632 stateblock = d3d8_free_handle(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1636 WARN("Invalid handle (%#x) passed.\n", Token);
1637 wined3d_mutex_unlock();
1638 return D3DERR_INVALIDCALL;
1641 if (wined3d_stateblock_decref(stateblock))
1643 ERR("Stateblock %p has references left, this shouldn't happen.\n", stateblock);
1645 wined3d_mutex_unlock();
1650 static HRESULT WINAPI IDirect3DDevice8Impl_CreateStateBlock(IDirect3DDevice8 *iface,
1651 D3DSTATEBLOCKTYPE Type, DWORD *handle)
1653 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1654 struct wined3d_stateblock *stateblock;
1657 TRACE("iface %p, type %#x, handle %p.\n", iface, Type, handle);
1659 if (Type != D3DSBT_ALL
1660 && Type != D3DSBT_PIXELSTATE
1661 && Type != D3DSBT_VERTEXSTATE)
1663 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL\n");
1664 return D3DERR_INVALIDCALL;
1667 wined3d_mutex_lock();
1668 hr = IWineD3DDevice_CreateStateBlock(This->WineD3DDevice, (WINED3DSTATEBLOCKTYPE)Type, &stateblock);
1671 wined3d_mutex_unlock();
1672 ERR("IWineD3DDevice_CreateStateBlock failed, hr %#x\n", hr);
1676 *handle = d3d8_allocate_handle(&This->handle_table, stateblock, D3D8_HANDLE_SB);
1677 wined3d_mutex_unlock();
1679 if (*handle == D3D8_INVALID_HANDLE)
1681 ERR("Failed to allocate a handle.\n");
1682 wined3d_mutex_lock();
1683 wined3d_stateblock_decref(stateblock);
1684 wined3d_mutex_unlock();
1689 TRACE("Returning %#x (%p).\n", *handle, stateblock);
1694 static HRESULT WINAPI IDirect3DDevice8Impl_SetClipStatus(IDirect3DDevice8 *iface,
1695 const D3DCLIPSTATUS8 *pClipStatus)
1697 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1700 TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
1701 /* FIXME: Verify that D3DCLIPSTATUS8 ~= WINED3DCLIPSTATUS */
1703 wined3d_mutex_lock();
1704 hr = IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
1705 wined3d_mutex_unlock();
1710 static HRESULT WINAPI IDirect3DDevice8Impl_GetClipStatus(IDirect3DDevice8 *iface,
1711 D3DCLIPSTATUS8 *pClipStatus)
1713 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1716 TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
1718 wined3d_mutex_lock();
1719 hr = IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
1720 wined3d_mutex_unlock();
1725 static HRESULT WINAPI IDirect3DDevice8Impl_GetTexture(IDirect3DDevice8 *iface,
1726 DWORD Stage, IDirect3DBaseTexture8 **ppTexture)
1728 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1729 struct wined3d_texture *wined3d_texture;
1732 TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, ppTexture);
1734 if(ppTexture == NULL){
1735 return D3DERR_INVALIDCALL;
1738 wined3d_mutex_lock();
1739 hr = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, &wined3d_texture);
1742 WARN("Failed to get texture for stage %u, hr %#x.\n", Stage, hr);
1743 wined3d_mutex_unlock();
1748 if (wined3d_texture)
1750 *ppTexture = wined3d_texture_get_parent(wined3d_texture);
1751 IDirect3DBaseTexture8_AddRef(*ppTexture);
1752 wined3d_texture_decref(wined3d_texture);
1758 wined3d_mutex_unlock();
1763 static HRESULT WINAPI IDirect3DDevice8Impl_SetTexture(IDirect3DDevice8 *iface, DWORD Stage,
1764 IDirect3DBaseTexture8 *pTexture)
1766 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1769 TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, pTexture);
1771 wined3d_mutex_lock();
1772 hr = IWineD3DDevice_SetTexture(This->WineD3DDevice, Stage,
1773 pTexture ? ((IDirect3DBaseTexture8Impl *)pTexture)->wined3d_texture : NULL);
1774 wined3d_mutex_unlock();
1779 static const struct tss_lookup
1786 {FALSE, WINED3DTSS_FORCE_DWORD}, /* 0, unused */
1787 {FALSE, WINED3DTSS_COLOROP}, /* 1, D3DTSS_COLOROP */
1788 {FALSE, WINED3DTSS_COLORARG1}, /* 2, D3DTSS_COLORARG1 */
1789 {FALSE, WINED3DTSS_COLORARG2}, /* 3, D3DTSS_COLORARG2 */
1790 {FALSE, WINED3DTSS_ALPHAOP}, /* 4, D3DTSS_ALPHAOP */
1791 {FALSE, WINED3DTSS_ALPHAARG1}, /* 5, D3DTSS_ALPHAARG1 */
1792 {FALSE, WINED3DTSS_ALPHAARG2}, /* 6, D3DTSS_ALPHAARG2 */
1793 {FALSE, WINED3DTSS_BUMPENVMAT00}, /* 7, D3DTSS_BUMPENVMAT00 */
1794 {FALSE, WINED3DTSS_BUMPENVMAT01}, /* 8, D3DTSS_BUMPENVMAT01 */
1795 {FALSE, WINED3DTSS_BUMPENVMAT10}, /* 9, D3DTSS_BUMPENVMAT10 */
1796 {FALSE, WINED3DTSS_BUMPENVMAT11}, /* 10, D3DTSS_BUMPENVMAT11 */
1797 {FALSE, WINED3DTSS_TEXCOORDINDEX}, /* 11, D3DTSS_TEXCOORDINDEX */
1798 {FALSE, WINED3DTSS_FORCE_DWORD}, /* 12, unused */
1799 {TRUE, WINED3DSAMP_ADDRESSU}, /* 13, D3DTSS_ADDRESSU */
1800 {TRUE, WINED3DSAMP_ADDRESSV}, /* 14, D3DTSS_ADDRESSV */
1801 {TRUE, WINED3DSAMP_BORDERCOLOR}, /* 15, D3DTSS_BORDERCOLOR */
1802 {TRUE, WINED3DSAMP_MAGFILTER}, /* 16, D3DTSS_MAGFILTER */
1803 {TRUE, WINED3DSAMP_MINFILTER}, /* 17, D3DTSS_MINFILTER */
1804 {TRUE, WINED3DSAMP_MIPFILTER}, /* 18, D3DTSS_MIPFILTER */
1805 {TRUE, WINED3DSAMP_MIPMAPLODBIAS}, /* 19, D3DTSS_MIPMAPLODBIAS */
1806 {TRUE, WINED3DSAMP_MAXMIPLEVEL}, /* 20, D3DTSS_MAXMIPLEVEL */
1807 {TRUE, WINED3DSAMP_MAXANISOTROPY}, /* 21, D3DTSS_MAXANISOTROPY */
1808 {FALSE, WINED3DTSS_BUMPENVLSCALE}, /* 22, D3DTSS_BUMPENVLSCALE */
1809 {FALSE, WINED3DTSS_BUMPENVLOFFSET}, /* 23, D3DTSS_BUMPENVLOFFSET */
1810 {FALSE, WINED3DTSS_TEXTURETRANSFORMFLAGS}, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1811 {TRUE, WINED3DSAMP_ADDRESSW}, /* 25, D3DTSS_ADDRESSW */
1812 {FALSE, WINED3DTSS_COLORARG0}, /* 26, D3DTSS_COLORARG0 */
1813 {FALSE, WINED3DTSS_ALPHAARG0}, /* 27, D3DTSS_ALPHAARG0 */
1814 {FALSE, WINED3DTSS_RESULTARG}, /* 28, D3DTSS_RESULTARG */
1817 static HRESULT WINAPI IDirect3DDevice8Impl_GetTextureStageState(IDirect3DDevice8 *iface,
1818 DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD *pValue)
1820 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1821 const struct tss_lookup *l;
1824 TRACE("iface %p, stage %u, state %#x, value %p.\n", iface, Stage, Type, pValue);
1826 if (Type >= sizeof(tss_lookup) / sizeof(*tss_lookup))
1828 WARN("Invalid Type %#x passed.\n", Type);
1832 l = &tss_lookup[Type];
1834 wined3d_mutex_lock();
1835 if (l->sampler_state) hr = IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Stage, l->state, pValue);
1836 else hr = IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, l->state, pValue);
1837 wined3d_mutex_unlock();
1842 static HRESULT WINAPI IDirect3DDevice8Impl_SetTextureStageState(IDirect3DDevice8 *iface,
1843 DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value)
1845 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1846 const struct tss_lookup *l;
1849 TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface, Stage, Type, Value);
1851 if (Type >= sizeof(tss_lookup) / sizeof(*tss_lookup))
1853 WARN("Invalid Type %#x passed.\n", Type);
1857 l = &tss_lookup[Type];
1859 wined3d_mutex_lock();
1860 if (l->sampler_state) hr = IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Stage, l->state, Value);
1861 else hr = IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, l->state, Value);
1862 wined3d_mutex_unlock();
1867 static HRESULT WINAPI IDirect3DDevice8Impl_ValidateDevice(IDirect3DDevice8 *iface,
1870 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1873 TRACE("iface %p, pass_count %p.\n", iface, pNumPasses);
1875 wined3d_mutex_lock();
1876 hr = IWineD3DDevice_ValidateDevice(This->WineD3DDevice, pNumPasses);
1877 wined3d_mutex_unlock();
1882 static HRESULT WINAPI IDirect3DDevice8Impl_GetInfo(IDirect3DDevice8 *iface,
1883 DWORD info_id, void *info, DWORD info_size)
1885 FIXME("iface %p, info_id %#x, info %p, info_size %u stub!\n", iface, info_id, info, info_size);
1890 static HRESULT WINAPI IDirect3DDevice8Impl_SetPaletteEntries(IDirect3DDevice8 *iface,
1891 UINT PaletteNumber, const PALETTEENTRY *pEntries)
1893 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1896 TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
1898 wined3d_mutex_lock();
1899 hr = IWineD3DDevice_SetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1900 wined3d_mutex_unlock();
1905 static HRESULT WINAPI IDirect3DDevice8Impl_GetPaletteEntries(IDirect3DDevice8 *iface,
1906 UINT PaletteNumber, PALETTEENTRY *pEntries)
1908 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1911 TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
1913 wined3d_mutex_lock();
1914 hr = IWineD3DDevice_GetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1915 wined3d_mutex_unlock();
1920 static HRESULT WINAPI IDirect3DDevice8Impl_SetCurrentTexturePalette(IDirect3DDevice8 *iface,
1923 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1926 TRACE("iface %p, palette_idx %u.\n", iface, PaletteNumber);
1928 wined3d_mutex_lock();
1929 hr = IWineD3DDevice_SetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1930 wined3d_mutex_unlock();
1935 static HRESULT WINAPI IDirect3DDevice8Impl_GetCurrentTexturePalette(IDirect3DDevice8 *iface,
1936 UINT *PaletteNumber)
1938 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1941 TRACE("iface %p, palette_idx %p.\n", iface, PaletteNumber);
1943 wined3d_mutex_lock();
1944 hr = IWineD3DDevice_GetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1945 wined3d_mutex_unlock();
1950 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitive(IDirect3DDevice8 *iface,
1951 D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount)
1953 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1956 TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
1957 iface, PrimitiveType, StartVertex, PrimitiveCount);
1959 wined3d_mutex_lock();
1960 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1961 hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, StartVertex,
1962 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount));
1963 wined3d_mutex_unlock();
1968 static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitive(IDirect3DDevice8 *iface,
1969 D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertices, UINT startIndex,
1972 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1975 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, vertex_count %u, start_idx %u, primitive_count %u.\n",
1976 iface, PrimitiveType, MinVertexIndex, NumVertices, startIndex, primCount);
1978 wined3d_mutex_lock();
1979 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1980 hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, startIndex,
1981 vertex_count_from_primitive_count(PrimitiveType, primCount));
1982 wined3d_mutex_unlock();
1987 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitiveUP(IDirect3DDevice8 *iface,
1988 D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, const void *pVertexStreamZeroData,
1989 UINT VertexStreamZeroStride)
1991 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1994 TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
1995 iface, PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride);
1997 wined3d_mutex_lock();
1998 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1999 hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice,
2000 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount),
2001 pVertexStreamZeroData, VertexStreamZeroStride);
2002 wined3d_mutex_unlock();
2007 static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitiveUP(IDirect3DDevice8 *iface,
2008 D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertexIndices,
2009 UINT PrimitiveCount, const void *pIndexData, D3DFORMAT IndexDataFormat,
2010 const void *pVertexStreamZeroData, UINT VertexStreamZeroStride)
2012 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2015 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, index_count %u, primitive_count %u,\n"
2016 "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
2017 iface, PrimitiveType, MinVertexIndex, NumVertexIndices, PrimitiveCount,
2018 pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride);
2020 wined3d_mutex_lock();
2021 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
2022 hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice,
2023 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount), pIndexData,
2024 wined3dformat_from_d3dformat(IndexDataFormat), pVertexStreamZeroData, VertexStreamZeroStride);
2025 wined3d_mutex_unlock();
2030 static HRESULT WINAPI IDirect3DDevice8Impl_ProcessVertices(IDirect3DDevice8 *iface,
2031 UINT SrcStartIndex, UINT DestIndex, UINT VertexCount, IDirect3DVertexBuffer8 *pDestBuffer,
2034 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2036 IDirect3DVertexBuffer8Impl *dest = (IDirect3DVertexBuffer8Impl *) pDestBuffer;
2038 TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, flags %#x.\n",
2039 iface, SrcStartIndex, DestIndex, VertexCount, pDestBuffer, Flags);
2041 wined3d_mutex_lock();
2042 hr = IWineD3DDevice_ProcessVertices(This->WineD3DDevice,SrcStartIndex, DestIndex, VertexCount, dest->wineD3DVertexBuffer, NULL, Flags, dest->fvf);
2043 wined3d_mutex_unlock();
2048 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexShader(IDirect3DDevice8 *iface,
2049 const DWORD *declaration, const DWORD *byte_code, DWORD *shader, DWORD usage)
2051 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2052 IDirect3DVertexShader8Impl *object;
2053 DWORD shader_handle;
2057 TRACE("iface %p, declaration %p, byte_code %p, shader %p, usage %#x.\n",
2058 iface, declaration, byte_code, shader, usage);
2060 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2063 ERR("Failed to allocate vertex shader memory.\n");
2065 return E_OUTOFMEMORY;
2068 wined3d_mutex_lock();
2069 handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_VS);
2070 wined3d_mutex_unlock();
2071 if (handle == D3D8_INVALID_HANDLE)
2073 ERR("Failed to allocate vertex shader handle.\n");
2074 HeapFree(GetProcessHeap(), 0, object);
2076 return E_OUTOFMEMORY;
2079 shader_handle = handle + VS_HIGHESTFIXEDFXF + 1;
2081 hr = vertexshader_init(object, This, declaration, byte_code, shader_handle, usage);
2084 WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
2085 wined3d_mutex_lock();
2086 d3d8_free_handle(&This->handle_table, handle, D3D8_HANDLE_VS);
2087 wined3d_mutex_unlock();
2088 HeapFree(GetProcessHeap(), 0, object);
2093 TRACE("Created vertex shader %p (handle %#x).\n", object, shader_handle);
2094 *shader = shader_handle;
2099 static IDirect3DVertexDeclaration8Impl *IDirect3DDevice8Impl_FindDecl(IDirect3DDevice8Impl *This, DWORD fvf)
2101 IDirect3DVertexDeclaration8Impl *d3d8_declaration;
2103 int p, low, high; /* deliberately signed */
2104 struct FvfToDecl *convertedDecls = This->decls;
2106 TRACE("Searching for declaration for fvf %08x... ", fvf);
2109 high = This->numConvertedDecls - 1;
2110 while(low <= high) {
2111 p = (low + high) >> 1;
2113 if(convertedDecls[p].fvf == fvf) {
2114 TRACE("found %p\n", convertedDecls[p].decl);
2115 return (IDirect3DVertexDeclaration8Impl *)convertedDecls[p].decl;
2116 } else if(convertedDecls[p].fvf < fvf) {
2122 TRACE("not found. Creating and inserting at position %d.\n", low);
2124 d3d8_declaration = HeapAlloc(GetProcessHeap(), 0, sizeof(*d3d8_declaration));
2125 if (!d3d8_declaration)
2127 ERR("Memory allocation failed.\n");
2131 hr = vertexdeclaration_init_fvf(d3d8_declaration, This, fvf);
2134 WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
2135 HeapFree(GetProcessHeap(), 0, d3d8_declaration);
2139 if(This->declArraySize == This->numConvertedDecls) {
2140 int grow = This->declArraySize / 2;
2141 convertedDecls = HeapReAlloc(GetProcessHeap(), 0, convertedDecls,
2142 sizeof(convertedDecls[0]) * (This->numConvertedDecls + grow));
2143 if(!convertedDecls) {
2144 /* This will destroy it */
2145 IDirect3DVertexDeclaration8_Release((IDirect3DVertexDeclaration8 *)d3d8_declaration);
2148 This->decls = convertedDecls;
2149 This->declArraySize += grow;
2152 memmove(convertedDecls + low + 1, convertedDecls + low, sizeof(convertedDecls[0]) * (This->numConvertedDecls - low));
2153 convertedDecls[low].decl = (IDirect3DVertexDeclaration8 *)d3d8_declaration;
2154 convertedDecls[low].fvf = fvf;
2155 This->numConvertedDecls++;
2157 TRACE("Returning %p. %u decls in array\n", d3d8_declaration, This->numConvertedDecls);
2158 return d3d8_declaration;
2161 static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShader(IDirect3DDevice8 *iface, DWORD pShader)
2163 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2164 IDirect3DVertexShader8Impl *shader;
2167 TRACE("iface %p, shader %#x.\n", iface, pShader);
2169 if (VS_HIGHESTFIXEDFXF >= pShader) {
2170 TRACE("Setting FVF, %#x\n", pShader);
2172 wined3d_mutex_lock();
2173 IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
2174 IDirect3DDevice8Impl_FindDecl(This, pShader)->wined3d_vertex_declaration);
2175 IWineD3DDevice_SetVertexShader(This->WineD3DDevice, NULL);
2176 wined3d_mutex_unlock();
2181 TRACE("Setting shader\n");
2183 wined3d_mutex_lock();
2184 shader = d3d8_get_object(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2187 WARN("Invalid handle (%#x) passed.\n", pShader);
2188 wined3d_mutex_unlock();
2190 return D3DERR_INVALIDCALL;
2193 hr = IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
2194 ((IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration)->wined3d_vertex_declaration);
2196 hr = IWineD3DDevice_SetVertexShader(This->WineD3DDevice, shader->wined3d_shader);
2197 wined3d_mutex_unlock();
2199 TRACE("Returning hr %#x\n", hr);
2204 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShader(IDirect3DDevice8 *iface, DWORD *ppShader)
2206 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2207 struct wined3d_vertex_declaration *wined3d_declaration;
2208 IDirect3DVertexDeclaration8 *d3d8_declaration;
2211 TRACE("iface %p, shader %p.\n", iface, ppShader);
2213 wined3d_mutex_lock();
2214 hr = IWineD3DDevice_GetVertexDeclaration(This->WineD3DDevice, &wined3d_declaration);
2217 wined3d_mutex_unlock();
2218 WARN("(%p) : Call to IWineD3DDevice_GetVertexDeclaration failed %#x (device %p)\n",
2219 This, hr, This->WineD3DDevice);
2223 if (!wined3d_declaration)
2225 wined3d_mutex_unlock();
2230 d3d8_declaration = wined3d_vertex_declaration_get_parent(wined3d_declaration);
2231 wined3d_vertex_declaration_decref(wined3d_declaration);
2232 wined3d_mutex_unlock();
2233 *ppShader = ((IDirect3DVertexDeclaration8Impl *)d3d8_declaration)->shader_handle;
2235 TRACE("(%p) : returning %#x\n", This, *ppShader);
2240 static HRESULT WINAPI IDirect3DDevice8Impl_DeleteVertexShader(IDirect3DDevice8 *iface, DWORD pShader)
2242 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2243 IDirect3DVertexShader8Impl *shader;
2244 struct wined3d_shader *cur;
2246 TRACE("iface %p, shader %#x.\n", iface, pShader);
2248 wined3d_mutex_lock();
2249 shader = d3d8_free_handle(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2252 WARN("Invalid handle (%#x) passed.\n", pShader);
2253 wined3d_mutex_unlock();
2255 return D3DERR_INVALIDCALL;
2258 cur = IWineD3DDevice_GetVertexShader(This->WineD3DDevice);
2261 if (cur == shader->wined3d_shader)
2262 IDirect3DDevice8_SetVertexShader(iface, 0);
2263 wined3d_shader_decref(cur);
2266 wined3d_mutex_unlock();
2268 if (IDirect3DVertexShader8_Release(&shader->IDirect3DVertexShader8_iface))
2270 ERR("Shader %p has references left, this shouldn't happen.\n", shader);
2276 static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShaderConstant(IDirect3DDevice8 *iface,
2277 DWORD Register, const void *pConstantData, DWORD ConstantCount)
2279 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2282 TRACE("iface %p, register %u, data %p, count %u.\n",
2283 iface, Register, pConstantData, ConstantCount);
2285 if(Register + ConstantCount > D3D8_MAX_VERTEX_SHADER_CONSTANTF) {
2286 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2287 Register + ConstantCount, D3D8_MAX_VERTEX_SHADER_CONSTANTF);
2288 return D3DERR_INVALIDCALL;
2291 wined3d_mutex_lock();
2292 hr = IWineD3DDevice_SetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2293 wined3d_mutex_unlock();
2298 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderConstant(IDirect3DDevice8 *iface,
2299 DWORD Register, void *pConstantData, DWORD ConstantCount)
2301 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2304 TRACE("iface %p, register %u, data %p, count %u.\n",
2305 iface, Register, pConstantData, ConstantCount);
2307 if(Register + ConstantCount > D3D8_MAX_VERTEX_SHADER_CONSTANTF) {
2308 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2309 Register + ConstantCount, D3D8_MAX_VERTEX_SHADER_CONSTANTF);
2310 return D3DERR_INVALIDCALL;
2313 wined3d_mutex_lock();
2314 hr = IWineD3DDevice_GetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2315 wined3d_mutex_unlock();
2320 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderDeclaration(IDirect3DDevice8 *iface,
2321 DWORD pVertexShader, void *pData, DWORD *pSizeOfData)
2323 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2324 IDirect3DVertexDeclaration8Impl *declaration;
2325 IDirect3DVertexShader8Impl *shader;
2327 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2328 iface, pVertexShader, pData, pSizeOfData);
2330 wined3d_mutex_lock();
2331 shader = d3d8_get_object(&This->handle_table, pVertexShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2332 wined3d_mutex_unlock();
2336 WARN("Invalid handle (%#x) passed.\n", pVertexShader);
2337 return D3DERR_INVALIDCALL;
2339 declaration = (IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration;
2341 /* If pData is NULL, we just return the required size of the buffer. */
2343 *pSizeOfData = declaration->elements_size;
2347 /* MSDN claims that if *pSizeOfData is smaller than the required size
2348 * we should write the required size and return D3DERR_MOREDATA.
2349 * That's not actually true. */
2350 if (*pSizeOfData < declaration->elements_size) {
2351 return D3DERR_INVALIDCALL;
2354 CopyMemory(pData, declaration->elements, declaration->elements_size);
2359 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderFunction(IDirect3DDevice8 *iface,
2360 DWORD pVertexShader, void *pData, DWORD *pSizeOfData)
2362 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2363 IDirect3DVertexShader8Impl *shader = NULL;
2366 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2367 iface, pVertexShader, pData, pSizeOfData);
2369 wined3d_mutex_lock();
2370 shader = d3d8_get_object(&This->handle_table, pVertexShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2373 WARN("Invalid handle (%#x) passed.\n", pVertexShader);
2374 wined3d_mutex_unlock();
2376 return D3DERR_INVALIDCALL;
2379 if (!shader->wined3d_shader)
2381 wined3d_mutex_unlock();
2386 hr = wined3d_shader_get_byte_code(shader->wined3d_shader, pData, pSizeOfData);
2387 wined3d_mutex_unlock();
2392 static HRESULT WINAPI IDirect3DDevice8Impl_SetIndices(IDirect3DDevice8 *iface,
2393 IDirect3DIndexBuffer8 *pIndexData, UINT baseVertexIndex)
2395 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2397 IDirect3DIndexBuffer8Impl *ib = (IDirect3DIndexBuffer8Impl *)pIndexData;
2399 TRACE("iface %p, buffer %p, base_vertex_idx %u.\n", iface, pIndexData, baseVertexIndex);
2401 /* WineD3D takes an INT(due to d3d9), but d3d8 uses UINTs. Do I have to add a check here that
2402 * the UINT doesn't cause an overflow in the INT? It seems rather unlikely because such large
2403 * vertex buffers can't be created to address them with an index that requires the 32nd bit
2404 * (4 Byte minimum vertex size * 2^31-1 -> 8 gb buffer. The index sign would be the least
2407 wined3d_mutex_lock();
2408 IWineD3DDevice_SetBaseVertexIndex(This->WineD3DDevice, baseVertexIndex);
2409 hr = IWineD3DDevice_SetIndexBuffer(This->WineD3DDevice,
2410 ib ? ib->wineD3DIndexBuffer : NULL,
2411 ib ? ib->format : WINED3DFMT_UNKNOWN);
2412 wined3d_mutex_unlock();
2417 static HRESULT WINAPI IDirect3DDevice8Impl_GetIndices(IDirect3DDevice8 *iface,
2418 IDirect3DIndexBuffer8 **ppIndexData, UINT *pBaseVertexIndex)
2420 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2421 struct wined3d_buffer *retIndexData = NULL;
2424 TRACE("iface %p, buffer %p, base_vertex_index %p.\n", iface, ppIndexData, pBaseVertexIndex);
2426 if(ppIndexData == NULL){
2427 return D3DERR_INVALIDCALL;
2430 /* The case from UINT to INT is safe because d3d8 will never set negative values */
2431 wined3d_mutex_lock();
2432 IWineD3DDevice_GetBaseVertexIndex(This->WineD3DDevice, (INT *) pBaseVertexIndex);
2433 hr = IWineD3DDevice_GetIndexBuffer(This->WineD3DDevice, &retIndexData);
2434 if (SUCCEEDED(hr) && retIndexData)
2436 *ppIndexData = wined3d_buffer_get_parent(retIndexData);
2437 IDirect3DIndexBuffer8_AddRef(*ppIndexData);
2438 wined3d_buffer_decref(retIndexData);
2440 if (FAILED(hr)) FIXME("Call to GetIndices failed\n");
2441 *ppIndexData = NULL;
2443 wined3d_mutex_unlock();
2448 static HRESULT WINAPI IDirect3DDevice8Impl_CreatePixelShader(IDirect3DDevice8 *iface,
2449 const DWORD *byte_code, DWORD *shader)
2451 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2452 IDirect3DPixelShader8Impl *object;
2453 DWORD shader_handle;
2457 TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
2461 TRACE("(%p) Invalid call\n", This);
2462 return D3DERR_INVALIDCALL;
2465 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2468 ERR("Failed to allocate pixel shader memmory.\n");
2469 return E_OUTOFMEMORY;
2472 wined3d_mutex_lock();
2473 handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_PS);
2474 wined3d_mutex_unlock();
2475 if (handle == D3D8_INVALID_HANDLE)
2477 ERR("Failed to allocate pixel shader handle.\n");
2478 HeapFree(GetProcessHeap(), 0, object);
2479 return E_OUTOFMEMORY;
2482 shader_handle = handle + VS_HIGHESTFIXEDFXF + 1;
2484 hr = pixelshader_init(object, This, byte_code, shader_handle);
2487 WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
2488 wined3d_mutex_lock();
2489 d3d8_free_handle(&This->handle_table, handle, D3D8_HANDLE_PS);
2490 wined3d_mutex_unlock();
2491 HeapFree(GetProcessHeap(), 0, object);
2496 TRACE("Created pixel shader %p (handle %#x).\n", object, shader_handle);
2497 *shader = shader_handle;
2502 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShader(IDirect3DDevice8 *iface, DWORD pShader)
2504 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2505 IDirect3DPixelShader8Impl *shader;
2508 TRACE("iface %p, shader %#x.\n", iface, pShader);
2510 wined3d_mutex_lock();
2514 hr = IWineD3DDevice_SetPixelShader(This->WineD3DDevice, NULL);
2515 wined3d_mutex_unlock();
2519 shader = d3d8_get_object(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2522 WARN("Invalid handle (%#x) passed.\n", pShader);
2523 wined3d_mutex_unlock();
2524 return D3DERR_INVALIDCALL;
2527 TRACE("(%p) : Setting shader %p\n", This, shader);
2528 hr = IWineD3DDevice_SetPixelShader(This->WineD3DDevice, shader->wined3d_shader);
2529 wined3d_mutex_unlock();
2534 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShader(IDirect3DDevice8 *iface, DWORD *ppShader)
2536 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2537 struct wined3d_shader *object;
2539 TRACE("iface %p, shader %p.\n", iface, ppShader);
2541 if (NULL == ppShader) {
2542 TRACE("(%p) Invalid call\n", This);
2543 return D3DERR_INVALIDCALL;
2546 wined3d_mutex_lock();
2547 object = IWineD3DDevice_GetPixelShader(This->WineD3DDevice);
2550 IDirect3DPixelShader8Impl *d3d8_shader;
2551 d3d8_shader = wined3d_shader_get_parent(object);
2552 wined3d_shader_decref(object);
2553 *ppShader = d3d8_shader->handle;
2559 wined3d_mutex_unlock();
2561 TRACE("(%p) : returning %#x\n", This, *ppShader);
2566 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePixelShader(IDirect3DDevice8 *iface, DWORD pShader)
2568 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2569 IDirect3DPixelShader8Impl *shader;
2570 struct wined3d_shader *cur;
2572 TRACE("iface %p, shader %#x.\n", iface, pShader);
2574 wined3d_mutex_lock();
2576 shader = d3d8_free_handle(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2579 WARN("Invalid handle (%#x) passed.\n", pShader);
2580 wined3d_mutex_unlock();
2581 return D3DERR_INVALIDCALL;
2584 cur = IWineD3DDevice_GetPixelShader(This->WineD3DDevice);
2587 if (cur == shader->wined3d_shader)
2588 IDirect3DDevice8_SetPixelShader(iface, 0);
2589 wined3d_shader_decref(cur);
2592 wined3d_mutex_unlock();
2594 if (IDirect3DPixelShader8_Release(&shader->IDirect3DPixelShader8_iface))
2596 ERR("Shader %p has references left, this shouldn't happen.\n", shader);
2602 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShaderConstant(IDirect3DDevice8 *iface,
2603 DWORD Register, const void *pConstantData, DWORD ConstantCount)
2605 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2608 TRACE("iface %p, register %u, data %p, count %u.\n",
2609 iface, Register, pConstantData, ConstantCount);
2611 wined3d_mutex_lock();
2612 hr = IWineD3DDevice_SetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2613 wined3d_mutex_unlock();
2618 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderConstant(IDirect3DDevice8 *iface,
2619 DWORD Register, void *pConstantData, DWORD ConstantCount)
2621 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2624 TRACE("iface %p, register %u, data %p, count %u.\n",
2625 iface, Register, pConstantData, ConstantCount);
2627 wined3d_mutex_lock();
2628 hr = IWineD3DDevice_GetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2629 wined3d_mutex_unlock();
2634 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderFunction(IDirect3DDevice8 *iface,
2635 DWORD pPixelShader, void *pData, DWORD *pSizeOfData)
2637 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2638 IDirect3DPixelShader8Impl *shader = NULL;
2641 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2642 iface, pPixelShader, pData, pSizeOfData);
2644 wined3d_mutex_lock();
2645 shader = d3d8_get_object(&This->handle_table, pPixelShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2648 WARN("Invalid handle (%#x) passed.\n", pPixelShader);
2649 wined3d_mutex_unlock();
2651 return D3DERR_INVALIDCALL;
2654 hr = wined3d_shader_get_byte_code(shader->wined3d_shader, pData, pSizeOfData);
2655 wined3d_mutex_unlock();
2660 static HRESULT WINAPI IDirect3DDevice8Impl_DrawRectPatch(IDirect3DDevice8 *iface, UINT Handle,
2661 const float *pNumSegs, const D3DRECTPATCH_INFO *pRectPatchInfo)
2663 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2666 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2667 iface, Handle, pNumSegs, pRectPatchInfo);
2669 wined3d_mutex_lock();
2670 hr = IWineD3DDevice_DrawRectPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DRECTPATCH_INFO *)pRectPatchInfo);
2671 wined3d_mutex_unlock();
2676 static HRESULT WINAPI IDirect3DDevice8Impl_DrawTriPatch(IDirect3DDevice8 *iface, UINT Handle,
2677 const float *pNumSegs, const D3DTRIPATCH_INFO *pTriPatchInfo)
2679 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2682 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2683 iface, Handle, pNumSegs, pTriPatchInfo);
2685 wined3d_mutex_lock();
2686 hr = IWineD3DDevice_DrawTriPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DTRIPATCH_INFO *)pTriPatchInfo);
2687 wined3d_mutex_unlock();
2692 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePatch(IDirect3DDevice8 *iface, UINT Handle)
2694 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2697 TRACE("iface %p, handle %#x.\n", iface, Handle);
2699 wined3d_mutex_lock();
2700 hr = IWineD3DDevice_DeletePatch(This->WineD3DDevice, Handle);
2701 wined3d_mutex_unlock();
2706 static HRESULT WINAPI IDirect3DDevice8Impl_SetStreamSource(IDirect3DDevice8 *iface,
2707 UINT StreamNumber, IDirect3DVertexBuffer8 *pStreamData, UINT Stride)
2709 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2712 TRACE("iface %p, stream_idx %u, buffer %p, stride %u.\n",
2713 iface, StreamNumber, pStreamData, Stride);
2715 wined3d_mutex_lock();
2716 hr = IWineD3DDevice_SetStreamSource(This->WineD3DDevice, StreamNumber,
2717 NULL == pStreamData ? NULL : ((IDirect3DVertexBuffer8Impl *)pStreamData)->wineD3DVertexBuffer,
2718 0/* Offset in bytes */, Stride);
2719 wined3d_mutex_unlock();
2724 static HRESULT WINAPI IDirect3DDevice8Impl_GetStreamSource(IDirect3DDevice8 *iface,
2725 UINT StreamNumber, IDirect3DVertexBuffer8 **pStream, UINT *pStride)
2727 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2728 struct wined3d_buffer *retStream = NULL;
2731 TRACE("iface %p, stream_idx %u, buffer %p, stride %p.\n",
2732 iface, StreamNumber, pStream, pStride);
2734 if(pStream == NULL){
2735 return D3DERR_INVALIDCALL;
2738 wined3d_mutex_lock();
2739 hr = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber,
2740 &retStream, 0 /* Offset in bytes */, pStride);
2741 if (SUCCEEDED(hr) && retStream)
2743 *pStream = wined3d_buffer_get_parent(retStream);
2744 IDirect3DVertexBuffer8_AddRef(*pStream);
2745 wined3d_buffer_decref(retStream);
2749 if (FAILED(hr)) FIXME("Call to GetStreamSource failed, hr %#x.\n", hr);
2752 wined3d_mutex_unlock();
2757 static const IDirect3DDevice8Vtbl Direct3DDevice8_Vtbl =
2759 IDirect3DDevice8Impl_QueryInterface,
2760 IDirect3DDevice8Impl_AddRef,
2761 IDirect3DDevice8Impl_Release,
2762 IDirect3DDevice8Impl_TestCooperativeLevel,
2763 IDirect3DDevice8Impl_GetAvailableTextureMem,
2764 IDirect3DDevice8Impl_ResourceManagerDiscardBytes,
2765 IDirect3DDevice8Impl_GetDirect3D,
2766 IDirect3DDevice8Impl_GetDeviceCaps,
2767 IDirect3DDevice8Impl_GetDisplayMode,
2768 IDirect3DDevice8Impl_GetCreationParameters,
2769 IDirect3DDevice8Impl_SetCursorProperties,
2770 IDirect3DDevice8Impl_SetCursorPosition,
2771 IDirect3DDevice8Impl_ShowCursor,
2772 IDirect3DDevice8Impl_CreateAdditionalSwapChain,
2773 IDirect3DDevice8Impl_Reset,
2774 IDirect3DDevice8Impl_Present,
2775 IDirect3DDevice8Impl_GetBackBuffer,
2776 IDirect3DDevice8Impl_GetRasterStatus,
2777 IDirect3DDevice8Impl_SetGammaRamp,
2778 IDirect3DDevice8Impl_GetGammaRamp,
2779 IDirect3DDevice8Impl_CreateTexture,
2780 IDirect3DDevice8Impl_CreateVolumeTexture,
2781 IDirect3DDevice8Impl_CreateCubeTexture,
2782 IDirect3DDevice8Impl_CreateVertexBuffer,
2783 IDirect3DDevice8Impl_CreateIndexBuffer,
2784 IDirect3DDevice8Impl_CreateRenderTarget,
2785 IDirect3DDevice8Impl_CreateDepthStencilSurface,
2786 IDirect3DDevice8Impl_CreateImageSurface,
2787 IDirect3DDevice8Impl_CopyRects,
2788 IDirect3DDevice8Impl_UpdateTexture,
2789 IDirect3DDevice8Impl_GetFrontBuffer,
2790 IDirect3DDevice8Impl_SetRenderTarget,
2791 IDirect3DDevice8Impl_GetRenderTarget,
2792 IDirect3DDevice8Impl_GetDepthStencilSurface,
2793 IDirect3DDevice8Impl_BeginScene,
2794 IDirect3DDevice8Impl_EndScene,
2795 IDirect3DDevice8Impl_Clear,
2796 IDirect3DDevice8Impl_SetTransform,
2797 IDirect3DDevice8Impl_GetTransform,
2798 IDirect3DDevice8Impl_MultiplyTransform,
2799 IDirect3DDevice8Impl_SetViewport,
2800 IDirect3DDevice8Impl_GetViewport,
2801 IDirect3DDevice8Impl_SetMaterial,
2802 IDirect3DDevice8Impl_GetMaterial,
2803 IDirect3DDevice8Impl_SetLight,
2804 IDirect3DDevice8Impl_GetLight,
2805 IDirect3DDevice8Impl_LightEnable,
2806 IDirect3DDevice8Impl_GetLightEnable,
2807 IDirect3DDevice8Impl_SetClipPlane,
2808 IDirect3DDevice8Impl_GetClipPlane,
2809 IDirect3DDevice8Impl_SetRenderState,
2810 IDirect3DDevice8Impl_GetRenderState,
2811 IDirect3DDevice8Impl_BeginStateBlock,
2812 IDirect3DDevice8Impl_EndStateBlock,
2813 IDirect3DDevice8Impl_ApplyStateBlock,
2814 IDirect3DDevice8Impl_CaptureStateBlock,
2815 IDirect3DDevice8Impl_DeleteStateBlock,
2816 IDirect3DDevice8Impl_CreateStateBlock,
2817 IDirect3DDevice8Impl_SetClipStatus,
2818 IDirect3DDevice8Impl_GetClipStatus,
2819 IDirect3DDevice8Impl_GetTexture,
2820 IDirect3DDevice8Impl_SetTexture,
2821 IDirect3DDevice8Impl_GetTextureStageState,
2822 IDirect3DDevice8Impl_SetTextureStageState,
2823 IDirect3DDevice8Impl_ValidateDevice,
2824 IDirect3DDevice8Impl_GetInfo,
2825 IDirect3DDevice8Impl_SetPaletteEntries,
2826 IDirect3DDevice8Impl_GetPaletteEntries,
2827 IDirect3DDevice8Impl_SetCurrentTexturePalette,
2828 IDirect3DDevice8Impl_GetCurrentTexturePalette,
2829 IDirect3DDevice8Impl_DrawPrimitive,
2830 IDirect3DDevice8Impl_DrawIndexedPrimitive,
2831 IDirect3DDevice8Impl_DrawPrimitiveUP,
2832 IDirect3DDevice8Impl_DrawIndexedPrimitiveUP,
2833 IDirect3DDevice8Impl_ProcessVertices,
2834 IDirect3DDevice8Impl_CreateVertexShader,
2835 IDirect3DDevice8Impl_SetVertexShader,
2836 IDirect3DDevice8Impl_GetVertexShader,
2837 IDirect3DDevice8Impl_DeleteVertexShader,
2838 IDirect3DDevice8Impl_SetVertexShaderConstant,
2839 IDirect3DDevice8Impl_GetVertexShaderConstant,
2840 IDirect3DDevice8Impl_GetVertexShaderDeclaration,
2841 IDirect3DDevice8Impl_GetVertexShaderFunction,
2842 IDirect3DDevice8Impl_SetStreamSource,
2843 IDirect3DDevice8Impl_GetStreamSource,
2844 IDirect3DDevice8Impl_SetIndices,
2845 IDirect3DDevice8Impl_GetIndices,
2846 IDirect3DDevice8Impl_CreatePixelShader,
2847 IDirect3DDevice8Impl_SetPixelShader,
2848 IDirect3DDevice8Impl_GetPixelShader,
2849 IDirect3DDevice8Impl_DeletePixelShader,
2850 IDirect3DDevice8Impl_SetPixelShaderConstant,
2851 IDirect3DDevice8Impl_GetPixelShaderConstant,
2852 IDirect3DDevice8Impl_GetPixelShaderFunction,
2853 IDirect3DDevice8Impl_DrawRectPatch,
2854 IDirect3DDevice8Impl_DrawTriPatch,
2855 IDirect3DDevice8Impl_DeletePatch
2858 static inline IDirect3DDevice8Impl *impl_from_IWineD3DDeviceParent(IWineD3DDeviceParent *iface)
2860 return CONTAINING_RECORD(iface, IDirect3DDevice8Impl, IWineD3DDeviceParent_iface);
2863 static HRESULT STDMETHODCALLTYPE device_parent_QueryInterface(IWineD3DDeviceParent *iface,
2864 REFIID riid, void **object)
2866 IDirect3DDevice8Impl *This = impl_from_IWineD3DDeviceParent(iface);
2867 return IDirect3DDevice8Impl_QueryInterface(&This->IDirect3DDevice8_iface, riid, object);
2870 static ULONG STDMETHODCALLTYPE device_parent_AddRef(IWineD3DDeviceParent *iface)
2872 IDirect3DDevice8Impl *This = impl_from_IWineD3DDeviceParent(iface);
2873 return IDirect3DDevice8Impl_AddRef(&This->IDirect3DDevice8_iface);
2876 static ULONG STDMETHODCALLTYPE device_parent_Release(IWineD3DDeviceParent *iface)
2878 IDirect3DDevice8Impl *This = impl_from_IWineD3DDeviceParent(iface);
2879 return IDirect3DDevice8Impl_Release(&This->IDirect3DDevice8_iface);
2882 /* IWineD3DDeviceParent methods */
2884 static void STDMETHODCALLTYPE device_parent_WineD3DDeviceCreated(IWineD3DDeviceParent *iface, IWineD3DDevice *device)
2886 TRACE("iface %p, device %p\n", iface, device);
2889 static HRESULT STDMETHODCALLTYPE device_parent_CreateSurface(IWineD3DDeviceParent *iface,
2890 void *container_parent, UINT width, UINT height, enum wined3d_format_id format, DWORD usage,
2891 WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, struct wined3d_surface **surface)
2893 IDirect3DDevice8Impl *This = impl_from_IWineD3DDeviceParent(iface);
2894 IDirect3DSurface8Impl *d3d_surface;
2895 BOOL lockable = TRUE;
2898 TRACE("iface %p, container_parent %p, width %u, height %u, format %#x, usage %#x,\n"
2899 "\tpool %#x, level %u, face %u, surface %p\n",
2900 iface, container_parent, width, height, format, usage, pool, level, face, surface);
2903 if (pool == WINED3DPOOL_DEFAULT && !(usage & WINED3DUSAGE_DYNAMIC)) lockable = FALSE;
2905 hr = IDirect3DDevice8Impl_CreateSurface(This, width, height,
2906 d3dformat_from_wined3dformat(format), lockable, FALSE /* Discard */, level,
2907 (IDirect3DSurface8 **)&d3d_surface, usage, pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
2910 ERR("(%p) CreateSurface failed, returning %#x\n", iface, hr);
2914 *surface = d3d_surface->wined3d_surface;
2915 wined3d_surface_incref(*surface);
2917 d3d_surface->container = container_parent;
2918 IUnknown_Release(d3d_surface->parentDevice);
2919 d3d_surface->parentDevice = NULL;
2921 IDirect3DSurface8_Release((IDirect3DSurface8 *)d3d_surface);
2922 d3d_surface->forwardReference = container_parent;
2927 static HRESULT STDMETHODCALLTYPE device_parent_CreateRenderTarget(IWineD3DDeviceParent *iface,
2928 void *container_parent, UINT width, UINT height, enum wined3d_format_id format,
2929 WINED3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality, BOOL lockable,
2930 struct wined3d_surface **surface)
2932 IDirect3DDevice8Impl *This = impl_from_IWineD3DDeviceParent(iface);
2933 IDirect3DSurface8Impl *d3d_surface;
2936 TRACE("iface %p, container_parent %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2937 "\tmultisample_quality %u, lockable %u, surface %p\n",
2938 iface, container_parent, width, height, format, multisample_type, multisample_quality, lockable, surface);
2940 hr = IDirect3DDevice8_CreateRenderTarget(&This->IDirect3DDevice8_iface, width, height,
2941 d3dformat_from_wined3dformat(format), multisample_type, lockable, (IDirect3DSurface8 **)&d3d_surface);
2944 ERR("(%p) CreateRenderTarget failed, returning %#x\n", iface, hr);
2948 *surface = d3d_surface->wined3d_surface;
2949 wined3d_surface_incref(*surface);
2951 d3d_surface->container = (IUnknown *)&This->IDirect3DDevice8_iface;
2952 /* Implicit surfaces are created with an refcount of 0 */
2953 IUnknown_Release((IUnknown *)d3d_surface);
2958 static HRESULT STDMETHODCALLTYPE device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent *iface,
2959 UINT width, UINT height, enum wined3d_format_id format, WINED3DMULTISAMPLE_TYPE multisample_type,
2960 DWORD multisample_quality, BOOL discard, struct wined3d_surface **surface)
2962 IDirect3DDevice8Impl *This = impl_from_IWineD3DDeviceParent(iface);
2963 IDirect3DSurface8Impl *d3d_surface;
2966 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2967 "\tmultisample_quality %u, discard %u, surface %p\n",
2968 iface, width, height, format, multisample_type, multisample_quality, discard, surface);
2970 hr = IDirect3DDevice8_CreateDepthStencilSurface(&This->IDirect3DDevice8_iface, width, height,
2971 d3dformat_from_wined3dformat(format), multisample_type, (IDirect3DSurface8 **)&d3d_surface);
2974 ERR("(%p) CreateDepthStencilSurface failed, returning %#x\n", iface, hr);
2978 *surface = d3d_surface->wined3d_surface;
2979 wined3d_surface_incref(*surface);
2981 d3d_surface->container = (IUnknown *)&This->IDirect3DDevice8_iface;
2982 /* Implicit surfaces are created with an refcount of 0 */
2983 IUnknown_Release((IUnknown *)d3d_surface);
2988 static HRESULT STDMETHODCALLTYPE device_parent_CreateVolume(IWineD3DDeviceParent *iface,
2989 void *container_parent, UINT width, UINT height, UINT depth, enum wined3d_format_id format,
2990 WINED3DPOOL pool, DWORD usage, struct wined3d_volume **volume)
2992 IDirect3DDevice8Impl *This = impl_from_IWineD3DDeviceParent(iface);
2993 IDirect3DVolume8Impl *object;
2996 TRACE("iface %p, container_parent %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p\n",
2997 iface, container_parent, width, height, depth, format, pool, usage, volume);
2999 /* Allocate the storage for the device */
3000 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
3003 FIXME("Allocation of memory failed\n");
3005 return D3DERR_OUTOFVIDEOMEMORY;
3008 hr = volume_init(object, This, width, height, depth, usage, format, pool);
3011 WARN("Failed to initialize volume, hr %#x.\n", hr);
3012 HeapFree(GetProcessHeap(), 0, object);
3016 *volume = object->wined3d_volume;
3017 wined3d_volume_incref(*volume);
3018 IDirect3DVolume8_Release(&object->IDirect3DVolume8_iface);
3020 object->container = container_parent;
3021 object->forwardReference = container_parent;
3023 TRACE("(%p) Created volume %p\n", iface, object);
3028 static HRESULT STDMETHODCALLTYPE device_parent_CreateSwapChain(IWineD3DDeviceParent *iface,
3029 WINED3DPRESENT_PARAMETERS *present_parameters, struct wined3d_swapchain **swapchain)
3031 IDirect3DDevice8Impl *This = impl_from_IWineD3DDeviceParent(iface);
3032 D3DPRESENT_PARAMETERS local_parameters;
3033 IDirect3DSwapChain8 *d3d_swapchain;
3036 TRACE("iface %p, present_parameters %p, swapchain %p\n", iface, present_parameters, swapchain);
3038 /* Copy the presentation parameters */
3039 local_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
3040 local_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
3041 local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(present_parameters->BackBufferFormat);
3042 local_parameters.BackBufferCount = present_parameters->BackBufferCount;
3043 local_parameters.MultiSampleType = present_parameters->MultiSampleType;
3044 local_parameters.SwapEffect = present_parameters->SwapEffect;
3045 local_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
3046 local_parameters.Windowed = present_parameters->Windowed;
3047 local_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
3048 local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(present_parameters->AutoDepthStencilFormat);
3049 local_parameters.Flags = present_parameters->Flags;
3050 local_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
3051 local_parameters.FullScreen_PresentationInterval = present_parameters->PresentationInterval;
3053 hr = IDirect3DDevice8_CreateAdditionalSwapChain(&This->IDirect3DDevice8_iface,
3054 &local_parameters, &d3d_swapchain);
3057 ERR("(%p) CreateAdditionalSwapChain failed, returning %#x\n", iface, hr);
3062 *swapchain = ((IDirect3DSwapChain8Impl *)d3d_swapchain)->wined3d_swapchain;
3063 wined3d_swapchain_incref(*swapchain);
3064 IDirect3DSwapChain8_Release(d3d_swapchain);
3066 /* Copy back the presentation parameters */
3067 present_parameters->BackBufferWidth = local_parameters.BackBufferWidth;
3068 present_parameters->BackBufferHeight = local_parameters.BackBufferHeight;
3069 present_parameters->BackBufferFormat = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat);
3070 present_parameters->BackBufferCount = local_parameters.BackBufferCount;
3071 present_parameters->MultiSampleType = local_parameters.MultiSampleType;
3072 present_parameters->SwapEffect = local_parameters.SwapEffect;
3073 present_parameters->hDeviceWindow = local_parameters.hDeviceWindow;
3074 present_parameters->Windowed = local_parameters.Windowed;
3075 present_parameters->EnableAutoDepthStencil = local_parameters.EnableAutoDepthStencil;
3076 present_parameters->AutoDepthStencilFormat = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat);
3077 present_parameters->Flags = local_parameters.Flags;
3078 present_parameters->FullScreen_RefreshRateInHz = local_parameters.FullScreen_RefreshRateInHz;
3079 present_parameters->PresentationInterval = local_parameters.FullScreen_PresentationInterval;
3084 static const IWineD3DDeviceParentVtbl d3d8_wined3d_device_parent_vtbl =
3086 /* IUnknown methods */
3087 device_parent_QueryInterface,
3088 device_parent_AddRef,
3089 device_parent_Release,
3090 /* IWineD3DDeviceParent methods */
3091 device_parent_WineD3DDeviceCreated,
3092 device_parent_CreateSurface,
3093 device_parent_CreateRenderTarget,
3094 device_parent_CreateDepthStencilSurface,
3095 device_parent_CreateVolume,
3096 device_parent_CreateSwapChain,
3099 static void setup_fpu(void)
3101 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3103 __asm__ volatile ("fnstcw %0" : "=m" (cw));
3104 cw = (cw & ~0xf3f) | 0x3f;
3105 __asm__ volatile ("fldcw %0" : : "m" (cw));
3107 FIXME("FPU setup not implemented for this platform.\n");
3111 HRESULT device_init(IDirect3DDevice8Impl *device, struct wined3d *wined3d, UINT adapter,
3112 D3DDEVTYPE device_type, HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters)
3114 WINED3DPRESENT_PARAMETERS wined3d_parameters;
3117 device->IDirect3DDevice8_iface.lpVtbl = &Direct3DDevice8_Vtbl;
3118 device->IWineD3DDeviceParent_iface.lpVtbl = &d3d8_wined3d_device_parent_vtbl;
3120 device->handle_table.entries = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
3121 D3D8_INITIAL_HANDLE_TABLE_SIZE * sizeof(*device->handle_table.entries));
3122 if (!device->handle_table.entries)
3124 ERR("Failed to allocate handle table memory.\n");
3125 return E_OUTOFMEMORY;
3127 device->handle_table.table_size = D3D8_INITIAL_HANDLE_TABLE_SIZE;
3129 if (!(flags & D3DCREATE_FPU_PRESERVE)) setup_fpu();
3131 wined3d_mutex_lock();
3132 hr = wined3d_device_create(wined3d, adapter, device_type, focus_window, flags,
3133 &device->IWineD3DDeviceParent_iface, &device->WineD3DDevice);
3136 WARN("Failed to create wined3d device, hr %#x.\n", hr);
3137 wined3d_mutex_unlock();
3138 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);
3142 if (!parameters->Windowed)
3144 HWND device_window = parameters->hDeviceWindow;
3146 if (!focus_window) focus_window = device_window;
3147 if (FAILED(hr = IWineD3DDevice_AcquireFocusWindow(device->WineD3DDevice, focus_window)))
3149 ERR("Failed to acquire focus window, hr %#x.\n", hr);
3150 IWineD3DDevice_Release(device->WineD3DDevice);
3151 wined3d_mutex_unlock();
3152 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);
3156 if (!device_window) device_window = focus_window;
3157 IWineD3DDevice_SetupFullscreenWindow(device->WineD3DDevice, device_window,
3158 parameters->BackBufferWidth,
3159 parameters->BackBufferHeight);
3162 if (flags & D3DCREATE_MULTITHREADED) IWineD3DDevice_SetMultithreaded(device->WineD3DDevice);
3164 wined3d_parameters.BackBufferWidth = parameters->BackBufferWidth;
3165 wined3d_parameters.BackBufferHeight = parameters->BackBufferHeight;
3166 wined3d_parameters.BackBufferFormat = wined3dformat_from_d3dformat(parameters->BackBufferFormat);
3167 wined3d_parameters.BackBufferCount = parameters->BackBufferCount;
3168 wined3d_parameters.MultiSampleType = parameters->MultiSampleType;
3169 wined3d_parameters.MultiSampleQuality = 0; /* d3d9 only */
3170 wined3d_parameters.SwapEffect = parameters->SwapEffect;
3171 wined3d_parameters.hDeviceWindow = parameters->hDeviceWindow;
3172 wined3d_parameters.Windowed = parameters->Windowed;
3173 wined3d_parameters.EnableAutoDepthStencil = parameters->EnableAutoDepthStencil;
3174 wined3d_parameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(parameters->AutoDepthStencilFormat);
3175 wined3d_parameters.Flags = parameters->Flags;
3176 wined3d_parameters.FullScreen_RefreshRateInHz = parameters->FullScreen_RefreshRateInHz;
3177 wined3d_parameters.PresentationInterval = parameters->FullScreen_PresentationInterval;
3178 wined3d_parameters.AutoRestoreDisplayMode = TRUE;
3180 hr = IWineD3DDevice_Init3D(device->WineD3DDevice, &wined3d_parameters);
3183 WARN("Failed to initialize 3D, hr %#x.\n", hr);
3184 IWineD3DDevice_ReleaseFocusWindow(device->WineD3DDevice);
3185 IWineD3DDevice_Release(device->WineD3DDevice);
3186 wined3d_mutex_unlock();
3187 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);
3191 hr = IWineD3DDevice_SetRenderState(device->WineD3DDevice, WINED3DRS_POINTSIZE_MIN, 0);
3192 wined3d_mutex_unlock();
3195 ERR("Failed to set minimum pointsize, hr %#x.\n", hr);
3199 parameters->BackBufferWidth = wined3d_parameters.BackBufferWidth;
3200 parameters->BackBufferHeight = wined3d_parameters.BackBufferHeight;
3201 parameters->BackBufferFormat = d3dformat_from_wined3dformat(wined3d_parameters.BackBufferFormat);
3202 parameters->BackBufferCount = wined3d_parameters.BackBufferCount;
3203 parameters->MultiSampleType = wined3d_parameters.MultiSampleType;
3204 parameters->SwapEffect = wined3d_parameters.SwapEffect;
3205 parameters->hDeviceWindow = wined3d_parameters.hDeviceWindow;
3206 parameters->Windowed = wined3d_parameters.Windowed;
3207 parameters->EnableAutoDepthStencil = wined3d_parameters.EnableAutoDepthStencil;
3208 parameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(wined3d_parameters.AutoDepthStencilFormat);
3209 parameters->Flags = wined3d_parameters.Flags;
3210 parameters->FullScreen_RefreshRateInHz = wined3d_parameters.FullScreen_RefreshRateInHz;
3211 parameters->FullScreen_PresentationInterval = wined3d_parameters.PresentationInterval;
3213 device->declArraySize = 16;
3214 device->decls = HeapAlloc(GetProcessHeap(), 0, device->declArraySize * sizeof(*device->decls));
3217 ERR("Failed to allocate FVF vertex delcaration map memory.\n");
3225 wined3d_mutex_lock();
3226 IWineD3DDevice_Uninit3D(device->WineD3DDevice);
3227 IWineD3DDevice_ReleaseFocusWindow(device->WineD3DDevice);
3228 IWineD3DDevice_Release(device->WineD3DDevice);
3229 wined3d_mutex_unlock();
3230 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);