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 /* This factor is the result of a trial-and-error search. Both ZBIAS and DEPTHBIAS require
1470 * guesswork by design. d3d9 apps usually use a DEPTHBIAS of -0.00002(Mass Effect 2, WoW).
1471 * d3d8 apps(Final Fantasy XI) set ZBIAS to 15 and still expect the depth test to sort
1472 * objects properly. */
1473 static const float zbias_factor = -0.000005f;
1475 static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderState(IDirect3DDevice8 *iface,
1476 D3DRENDERSTATETYPE State, DWORD Value)
1478 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1486 TRACE("iface %p, state %#x, value %#x.\n", iface, State, Value);
1488 wined3d_mutex_lock();
1492 wined3d_value.f = Value * zbias_factor;
1493 hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, WINED3DRS_DEPTHBIAS, wined3d_value.d);
1497 hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, State, Value);
1499 wined3d_mutex_unlock();
1504 static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderState(IDirect3DDevice8 *iface,
1505 D3DRENDERSTATETYPE State, DWORD *pValue)
1507 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1515 TRACE("iface %p, state %#x, value %p.\n", iface, State, pValue);
1517 wined3d_mutex_lock();
1521 hr = IWineD3DDevice_GetRenderState(This->WineD3DDevice, WINED3DRS_DEPTHBIAS, &wined3d_value.d);
1522 if (SUCCEEDED(hr)) *pValue = wined3d_value.f / zbias_factor;
1526 hr = IWineD3DDevice_GetRenderState(This->WineD3DDevice, State, pValue);
1528 wined3d_mutex_unlock();
1533 static HRESULT WINAPI IDirect3DDevice8Impl_BeginStateBlock(IDirect3DDevice8 *iface)
1535 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1538 TRACE("iface %p.\n", iface);
1540 wined3d_mutex_lock();
1541 hr = IWineD3DDevice_BeginStateBlock(This->WineD3DDevice);
1542 wined3d_mutex_unlock();
1547 static HRESULT WINAPI IDirect3DDevice8Impl_EndStateBlock(IDirect3DDevice8 *iface, DWORD *pToken)
1549 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1550 struct wined3d_stateblock *stateblock;
1553 TRACE("iface %p, token %p.\n", iface, pToken);
1555 /* Tell wineD3D to endstateblock before anything else (in case we run out
1556 * of memory later and cause locking problems)
1558 wined3d_mutex_lock();
1559 hr = IWineD3DDevice_EndStateBlock(This->WineD3DDevice , &stateblock);
1561 WARN("IWineD3DDevice_EndStateBlock returned an error\n");
1562 wined3d_mutex_unlock();
1566 *pToken = d3d8_allocate_handle(&This->handle_table, stateblock, D3D8_HANDLE_SB);
1567 wined3d_mutex_unlock();
1569 if (*pToken == D3D8_INVALID_HANDLE)
1571 ERR("Failed to create a handle\n");
1572 wined3d_mutex_lock();
1573 wined3d_stateblock_decref(stateblock);
1574 wined3d_mutex_unlock();
1579 TRACE("Returning %#x (%p).\n", *pToken, stateblock);
1584 static HRESULT WINAPI IDirect3DDevice8Impl_ApplyStateBlock(IDirect3DDevice8 *iface, DWORD Token)
1586 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1587 struct wined3d_stateblock *stateblock;
1590 TRACE("iface %p, token %#x.\n", iface, Token);
1592 if (!Token) return D3D_OK;
1594 wined3d_mutex_lock();
1595 stateblock = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1598 WARN("Invalid handle (%#x) passed.\n", Token);
1599 wined3d_mutex_unlock();
1600 return D3DERR_INVALIDCALL;
1602 hr = wined3d_stateblock_apply(stateblock);
1603 wined3d_mutex_unlock();
1608 static HRESULT WINAPI IDirect3DDevice8Impl_CaptureStateBlock(IDirect3DDevice8 *iface, DWORD Token)
1610 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1611 struct wined3d_stateblock *stateblock;
1614 TRACE("iface %p, token %#x.\n", iface, Token);
1616 wined3d_mutex_lock();
1617 stateblock = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1620 WARN("Invalid handle (%#x) passed.\n", Token);
1621 wined3d_mutex_unlock();
1622 return D3DERR_INVALIDCALL;
1624 hr = wined3d_stateblock_capture(stateblock);
1625 wined3d_mutex_unlock();
1630 static HRESULT WINAPI IDirect3DDevice8Impl_DeleteStateBlock(IDirect3DDevice8 *iface, DWORD Token)
1632 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1633 struct wined3d_stateblock *stateblock;
1635 TRACE("iface %p, token %#x.\n", iface, Token);
1637 wined3d_mutex_lock();
1638 stateblock = d3d8_free_handle(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1642 WARN("Invalid handle (%#x) passed.\n", Token);
1643 wined3d_mutex_unlock();
1644 return D3DERR_INVALIDCALL;
1647 if (wined3d_stateblock_decref(stateblock))
1649 ERR("Stateblock %p has references left, this shouldn't happen.\n", stateblock);
1651 wined3d_mutex_unlock();
1656 static HRESULT WINAPI IDirect3DDevice8Impl_CreateStateBlock(IDirect3DDevice8 *iface,
1657 D3DSTATEBLOCKTYPE Type, DWORD *handle)
1659 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1660 struct wined3d_stateblock *stateblock;
1663 TRACE("iface %p, type %#x, handle %p.\n", iface, Type, handle);
1665 if (Type != D3DSBT_ALL
1666 && Type != D3DSBT_PIXELSTATE
1667 && Type != D3DSBT_VERTEXSTATE)
1669 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL\n");
1670 return D3DERR_INVALIDCALL;
1673 wined3d_mutex_lock();
1674 hr = IWineD3DDevice_CreateStateBlock(This->WineD3DDevice, (WINED3DSTATEBLOCKTYPE)Type, &stateblock);
1677 wined3d_mutex_unlock();
1678 ERR("IWineD3DDevice_CreateStateBlock failed, hr %#x\n", hr);
1682 *handle = d3d8_allocate_handle(&This->handle_table, stateblock, D3D8_HANDLE_SB);
1683 wined3d_mutex_unlock();
1685 if (*handle == D3D8_INVALID_HANDLE)
1687 ERR("Failed to allocate a handle.\n");
1688 wined3d_mutex_lock();
1689 wined3d_stateblock_decref(stateblock);
1690 wined3d_mutex_unlock();
1695 TRACE("Returning %#x (%p).\n", *handle, stateblock);
1700 static HRESULT WINAPI IDirect3DDevice8Impl_SetClipStatus(IDirect3DDevice8 *iface,
1701 const D3DCLIPSTATUS8 *pClipStatus)
1703 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1706 TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
1707 /* FIXME: Verify that D3DCLIPSTATUS8 ~= WINED3DCLIPSTATUS */
1709 wined3d_mutex_lock();
1710 hr = IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
1711 wined3d_mutex_unlock();
1716 static HRESULT WINAPI IDirect3DDevice8Impl_GetClipStatus(IDirect3DDevice8 *iface,
1717 D3DCLIPSTATUS8 *pClipStatus)
1719 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1722 TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
1724 wined3d_mutex_lock();
1725 hr = IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
1726 wined3d_mutex_unlock();
1731 static HRESULT WINAPI IDirect3DDevice8Impl_GetTexture(IDirect3DDevice8 *iface,
1732 DWORD Stage, IDirect3DBaseTexture8 **ppTexture)
1734 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1735 struct wined3d_texture *wined3d_texture;
1738 TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, ppTexture);
1740 if(ppTexture == NULL){
1741 return D3DERR_INVALIDCALL;
1744 wined3d_mutex_lock();
1745 hr = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, &wined3d_texture);
1748 WARN("Failed to get texture for stage %u, hr %#x.\n", Stage, hr);
1749 wined3d_mutex_unlock();
1754 if (wined3d_texture)
1756 *ppTexture = wined3d_texture_get_parent(wined3d_texture);
1757 IDirect3DBaseTexture8_AddRef(*ppTexture);
1758 wined3d_texture_decref(wined3d_texture);
1764 wined3d_mutex_unlock();
1769 static HRESULT WINAPI IDirect3DDevice8Impl_SetTexture(IDirect3DDevice8 *iface, DWORD Stage,
1770 IDirect3DBaseTexture8 *pTexture)
1772 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1775 TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, pTexture);
1777 wined3d_mutex_lock();
1778 hr = IWineD3DDevice_SetTexture(This->WineD3DDevice, Stage,
1779 pTexture ? ((IDirect3DBaseTexture8Impl *)pTexture)->wined3d_texture : NULL);
1780 wined3d_mutex_unlock();
1785 static const struct tss_lookup
1792 {FALSE, WINED3DTSS_FORCE_DWORD}, /* 0, unused */
1793 {FALSE, WINED3DTSS_COLOROP}, /* 1, D3DTSS_COLOROP */
1794 {FALSE, WINED3DTSS_COLORARG1}, /* 2, D3DTSS_COLORARG1 */
1795 {FALSE, WINED3DTSS_COLORARG2}, /* 3, D3DTSS_COLORARG2 */
1796 {FALSE, WINED3DTSS_ALPHAOP}, /* 4, D3DTSS_ALPHAOP */
1797 {FALSE, WINED3DTSS_ALPHAARG1}, /* 5, D3DTSS_ALPHAARG1 */
1798 {FALSE, WINED3DTSS_ALPHAARG2}, /* 6, D3DTSS_ALPHAARG2 */
1799 {FALSE, WINED3DTSS_BUMPENVMAT00}, /* 7, D3DTSS_BUMPENVMAT00 */
1800 {FALSE, WINED3DTSS_BUMPENVMAT01}, /* 8, D3DTSS_BUMPENVMAT01 */
1801 {FALSE, WINED3DTSS_BUMPENVMAT10}, /* 9, D3DTSS_BUMPENVMAT10 */
1802 {FALSE, WINED3DTSS_BUMPENVMAT11}, /* 10, D3DTSS_BUMPENVMAT11 */
1803 {FALSE, WINED3DTSS_TEXCOORDINDEX}, /* 11, D3DTSS_TEXCOORDINDEX */
1804 {FALSE, WINED3DTSS_FORCE_DWORD}, /* 12, unused */
1805 {TRUE, WINED3DSAMP_ADDRESSU}, /* 13, D3DTSS_ADDRESSU */
1806 {TRUE, WINED3DSAMP_ADDRESSV}, /* 14, D3DTSS_ADDRESSV */
1807 {TRUE, WINED3DSAMP_BORDERCOLOR}, /* 15, D3DTSS_BORDERCOLOR */
1808 {TRUE, WINED3DSAMP_MAGFILTER}, /* 16, D3DTSS_MAGFILTER */
1809 {TRUE, WINED3DSAMP_MINFILTER}, /* 17, D3DTSS_MINFILTER */
1810 {TRUE, WINED3DSAMP_MIPFILTER}, /* 18, D3DTSS_MIPFILTER */
1811 {TRUE, WINED3DSAMP_MIPMAPLODBIAS}, /* 19, D3DTSS_MIPMAPLODBIAS */
1812 {TRUE, WINED3DSAMP_MAXMIPLEVEL}, /* 20, D3DTSS_MAXMIPLEVEL */
1813 {TRUE, WINED3DSAMP_MAXANISOTROPY}, /* 21, D3DTSS_MAXANISOTROPY */
1814 {FALSE, WINED3DTSS_BUMPENVLSCALE}, /* 22, D3DTSS_BUMPENVLSCALE */
1815 {FALSE, WINED3DTSS_BUMPENVLOFFSET}, /* 23, D3DTSS_BUMPENVLOFFSET */
1816 {FALSE, WINED3DTSS_TEXTURETRANSFORMFLAGS}, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1817 {TRUE, WINED3DSAMP_ADDRESSW}, /* 25, D3DTSS_ADDRESSW */
1818 {FALSE, WINED3DTSS_COLORARG0}, /* 26, D3DTSS_COLORARG0 */
1819 {FALSE, WINED3DTSS_ALPHAARG0}, /* 27, D3DTSS_ALPHAARG0 */
1820 {FALSE, WINED3DTSS_RESULTARG}, /* 28, D3DTSS_RESULTARG */
1823 static HRESULT WINAPI IDirect3DDevice8Impl_GetTextureStageState(IDirect3DDevice8 *iface,
1824 DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD *pValue)
1826 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1827 const struct tss_lookup *l;
1830 TRACE("iface %p, stage %u, state %#x, value %p.\n", iface, Stage, Type, pValue);
1832 if (Type >= sizeof(tss_lookup) / sizeof(*tss_lookup))
1834 WARN("Invalid Type %#x passed.\n", Type);
1838 l = &tss_lookup[Type];
1840 wined3d_mutex_lock();
1841 if (l->sampler_state) hr = IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Stage, l->state, pValue);
1842 else hr = IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, l->state, pValue);
1843 wined3d_mutex_unlock();
1848 static HRESULT WINAPI IDirect3DDevice8Impl_SetTextureStageState(IDirect3DDevice8 *iface,
1849 DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value)
1851 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1852 const struct tss_lookup *l;
1855 TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface, Stage, Type, Value);
1857 if (Type >= sizeof(tss_lookup) / sizeof(*tss_lookup))
1859 WARN("Invalid Type %#x passed.\n", Type);
1863 l = &tss_lookup[Type];
1865 wined3d_mutex_lock();
1866 if (l->sampler_state) hr = IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Stage, l->state, Value);
1867 else hr = IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, l->state, Value);
1868 wined3d_mutex_unlock();
1873 static HRESULT WINAPI IDirect3DDevice8Impl_ValidateDevice(IDirect3DDevice8 *iface,
1876 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1879 TRACE("iface %p, pass_count %p.\n", iface, pNumPasses);
1881 wined3d_mutex_lock();
1882 hr = IWineD3DDevice_ValidateDevice(This->WineD3DDevice, pNumPasses);
1883 wined3d_mutex_unlock();
1888 static HRESULT WINAPI IDirect3DDevice8Impl_GetInfo(IDirect3DDevice8 *iface,
1889 DWORD info_id, void *info, DWORD info_size)
1891 FIXME("iface %p, info_id %#x, info %p, info_size %u stub!\n", iface, info_id, info, info_size);
1896 static HRESULT WINAPI IDirect3DDevice8Impl_SetPaletteEntries(IDirect3DDevice8 *iface,
1897 UINT PaletteNumber, const PALETTEENTRY *pEntries)
1899 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1902 TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
1904 wined3d_mutex_lock();
1905 hr = IWineD3DDevice_SetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1906 wined3d_mutex_unlock();
1911 static HRESULT WINAPI IDirect3DDevice8Impl_GetPaletteEntries(IDirect3DDevice8 *iface,
1912 UINT PaletteNumber, PALETTEENTRY *pEntries)
1914 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1917 TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
1919 wined3d_mutex_lock();
1920 hr = IWineD3DDevice_GetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1921 wined3d_mutex_unlock();
1926 static HRESULT WINAPI IDirect3DDevice8Impl_SetCurrentTexturePalette(IDirect3DDevice8 *iface,
1929 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1932 TRACE("iface %p, palette_idx %u.\n", iface, PaletteNumber);
1934 wined3d_mutex_lock();
1935 hr = IWineD3DDevice_SetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1936 wined3d_mutex_unlock();
1941 static HRESULT WINAPI IDirect3DDevice8Impl_GetCurrentTexturePalette(IDirect3DDevice8 *iface,
1942 UINT *PaletteNumber)
1944 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1947 TRACE("iface %p, palette_idx %p.\n", iface, PaletteNumber);
1949 wined3d_mutex_lock();
1950 hr = IWineD3DDevice_GetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1951 wined3d_mutex_unlock();
1956 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitive(IDirect3DDevice8 *iface,
1957 D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount)
1959 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1962 TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
1963 iface, PrimitiveType, StartVertex, PrimitiveCount);
1965 wined3d_mutex_lock();
1966 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1967 hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, StartVertex,
1968 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount));
1969 wined3d_mutex_unlock();
1974 static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitive(IDirect3DDevice8 *iface,
1975 D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertices, UINT startIndex,
1978 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1981 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, vertex_count %u, start_idx %u, primitive_count %u.\n",
1982 iface, PrimitiveType, MinVertexIndex, NumVertices, startIndex, primCount);
1984 wined3d_mutex_lock();
1985 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1986 hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, startIndex,
1987 vertex_count_from_primitive_count(PrimitiveType, primCount));
1988 wined3d_mutex_unlock();
1993 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitiveUP(IDirect3DDevice8 *iface,
1994 D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, const void *pVertexStreamZeroData,
1995 UINT VertexStreamZeroStride)
1997 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2000 TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
2001 iface, PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride);
2003 wined3d_mutex_lock();
2004 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
2005 hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice,
2006 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount),
2007 pVertexStreamZeroData, VertexStreamZeroStride);
2008 wined3d_mutex_unlock();
2013 static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitiveUP(IDirect3DDevice8 *iface,
2014 D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertexIndices,
2015 UINT PrimitiveCount, const void *pIndexData, D3DFORMAT IndexDataFormat,
2016 const void *pVertexStreamZeroData, UINT VertexStreamZeroStride)
2018 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2021 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, index_count %u, primitive_count %u,\n"
2022 "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
2023 iface, PrimitiveType, MinVertexIndex, NumVertexIndices, PrimitiveCount,
2024 pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride);
2026 wined3d_mutex_lock();
2027 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
2028 hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice,
2029 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount), pIndexData,
2030 wined3dformat_from_d3dformat(IndexDataFormat), pVertexStreamZeroData, VertexStreamZeroStride);
2031 wined3d_mutex_unlock();
2036 static HRESULT WINAPI IDirect3DDevice8Impl_ProcessVertices(IDirect3DDevice8 *iface,
2037 UINT SrcStartIndex, UINT DestIndex, UINT VertexCount, IDirect3DVertexBuffer8 *pDestBuffer,
2040 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2042 IDirect3DVertexBuffer8Impl *dest = (IDirect3DVertexBuffer8Impl *) pDestBuffer;
2044 TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, flags %#x.\n",
2045 iface, SrcStartIndex, DestIndex, VertexCount, pDestBuffer, Flags);
2047 wined3d_mutex_lock();
2048 hr = IWineD3DDevice_ProcessVertices(This->WineD3DDevice,SrcStartIndex, DestIndex, VertexCount, dest->wineD3DVertexBuffer, NULL, Flags, dest->fvf);
2049 wined3d_mutex_unlock();
2054 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexShader(IDirect3DDevice8 *iface,
2055 const DWORD *declaration, const DWORD *byte_code, DWORD *shader, DWORD usage)
2057 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2058 IDirect3DVertexShader8Impl *object;
2059 DWORD shader_handle;
2063 TRACE("iface %p, declaration %p, byte_code %p, shader %p, usage %#x.\n",
2064 iface, declaration, byte_code, shader, usage);
2066 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2069 ERR("Failed to allocate vertex shader memory.\n");
2071 return E_OUTOFMEMORY;
2074 wined3d_mutex_lock();
2075 handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_VS);
2076 wined3d_mutex_unlock();
2077 if (handle == D3D8_INVALID_HANDLE)
2079 ERR("Failed to allocate vertex shader handle.\n");
2080 HeapFree(GetProcessHeap(), 0, object);
2082 return E_OUTOFMEMORY;
2085 shader_handle = handle + VS_HIGHESTFIXEDFXF + 1;
2087 hr = vertexshader_init(object, This, declaration, byte_code, shader_handle, usage);
2090 WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
2091 wined3d_mutex_lock();
2092 d3d8_free_handle(&This->handle_table, handle, D3D8_HANDLE_VS);
2093 wined3d_mutex_unlock();
2094 HeapFree(GetProcessHeap(), 0, object);
2099 TRACE("Created vertex shader %p (handle %#x).\n", object, shader_handle);
2100 *shader = shader_handle;
2105 static IDirect3DVertexDeclaration8Impl *IDirect3DDevice8Impl_FindDecl(IDirect3DDevice8Impl *This, DWORD fvf)
2107 IDirect3DVertexDeclaration8Impl *d3d8_declaration;
2109 int p, low, high; /* deliberately signed */
2110 struct FvfToDecl *convertedDecls = This->decls;
2112 TRACE("Searching for declaration for fvf %08x... ", fvf);
2115 high = This->numConvertedDecls - 1;
2116 while(low <= high) {
2117 p = (low + high) >> 1;
2119 if(convertedDecls[p].fvf == fvf) {
2120 TRACE("found %p\n", convertedDecls[p].decl);
2121 return (IDirect3DVertexDeclaration8Impl *)convertedDecls[p].decl;
2122 } else if(convertedDecls[p].fvf < fvf) {
2128 TRACE("not found. Creating and inserting at position %d.\n", low);
2130 d3d8_declaration = HeapAlloc(GetProcessHeap(), 0, sizeof(*d3d8_declaration));
2131 if (!d3d8_declaration)
2133 ERR("Memory allocation failed.\n");
2137 hr = vertexdeclaration_init_fvf(d3d8_declaration, This, fvf);
2140 WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
2141 HeapFree(GetProcessHeap(), 0, d3d8_declaration);
2145 if(This->declArraySize == This->numConvertedDecls) {
2146 int grow = This->declArraySize / 2;
2147 convertedDecls = HeapReAlloc(GetProcessHeap(), 0, convertedDecls,
2148 sizeof(convertedDecls[0]) * (This->numConvertedDecls + grow));
2149 if(!convertedDecls) {
2150 /* This will destroy it */
2151 IDirect3DVertexDeclaration8_Release((IDirect3DVertexDeclaration8 *)d3d8_declaration);
2154 This->decls = convertedDecls;
2155 This->declArraySize += grow;
2158 memmove(convertedDecls + low + 1, convertedDecls + low, sizeof(convertedDecls[0]) * (This->numConvertedDecls - low));
2159 convertedDecls[low].decl = (IDirect3DVertexDeclaration8 *)d3d8_declaration;
2160 convertedDecls[low].fvf = fvf;
2161 This->numConvertedDecls++;
2163 TRACE("Returning %p. %u decls in array\n", d3d8_declaration, This->numConvertedDecls);
2164 return d3d8_declaration;
2167 static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShader(IDirect3DDevice8 *iface, DWORD pShader)
2169 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2170 IDirect3DVertexShader8Impl *shader;
2173 TRACE("iface %p, shader %#x.\n", iface, pShader);
2175 if (VS_HIGHESTFIXEDFXF >= pShader) {
2176 TRACE("Setting FVF, %#x\n", pShader);
2178 wined3d_mutex_lock();
2179 IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
2180 IDirect3DDevice8Impl_FindDecl(This, pShader)->wined3d_vertex_declaration);
2181 IWineD3DDevice_SetVertexShader(This->WineD3DDevice, NULL);
2182 wined3d_mutex_unlock();
2187 TRACE("Setting shader\n");
2189 wined3d_mutex_lock();
2190 shader = d3d8_get_object(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2193 WARN("Invalid handle (%#x) passed.\n", pShader);
2194 wined3d_mutex_unlock();
2196 return D3DERR_INVALIDCALL;
2199 hr = IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
2200 ((IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration)->wined3d_vertex_declaration);
2202 hr = IWineD3DDevice_SetVertexShader(This->WineD3DDevice, shader->wined3d_shader);
2203 wined3d_mutex_unlock();
2205 TRACE("Returning hr %#x\n", hr);
2210 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShader(IDirect3DDevice8 *iface, DWORD *ppShader)
2212 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2213 struct wined3d_vertex_declaration *wined3d_declaration;
2214 IDirect3DVertexDeclaration8 *d3d8_declaration;
2217 TRACE("iface %p, shader %p.\n", iface, ppShader);
2219 wined3d_mutex_lock();
2220 hr = IWineD3DDevice_GetVertexDeclaration(This->WineD3DDevice, &wined3d_declaration);
2223 wined3d_mutex_unlock();
2224 WARN("(%p) : Call to IWineD3DDevice_GetVertexDeclaration failed %#x (device %p)\n",
2225 This, hr, This->WineD3DDevice);
2229 if (!wined3d_declaration)
2231 wined3d_mutex_unlock();
2236 d3d8_declaration = wined3d_vertex_declaration_get_parent(wined3d_declaration);
2237 wined3d_vertex_declaration_decref(wined3d_declaration);
2238 wined3d_mutex_unlock();
2239 *ppShader = ((IDirect3DVertexDeclaration8Impl *)d3d8_declaration)->shader_handle;
2241 TRACE("(%p) : returning %#x\n", This, *ppShader);
2246 static HRESULT WINAPI IDirect3DDevice8Impl_DeleteVertexShader(IDirect3DDevice8 *iface, DWORD pShader)
2248 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2249 IDirect3DVertexShader8Impl *shader;
2250 struct wined3d_shader *cur;
2252 TRACE("iface %p, shader %#x.\n", iface, pShader);
2254 wined3d_mutex_lock();
2255 shader = d3d8_free_handle(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2258 WARN("Invalid handle (%#x) passed.\n", pShader);
2259 wined3d_mutex_unlock();
2261 return D3DERR_INVALIDCALL;
2264 cur = IWineD3DDevice_GetVertexShader(This->WineD3DDevice);
2267 if (cur == shader->wined3d_shader)
2268 IDirect3DDevice8_SetVertexShader(iface, 0);
2269 wined3d_shader_decref(cur);
2272 wined3d_mutex_unlock();
2274 if (IDirect3DVertexShader8_Release(&shader->IDirect3DVertexShader8_iface))
2276 ERR("Shader %p has references left, this shouldn't happen.\n", shader);
2282 static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShaderConstant(IDirect3DDevice8 *iface,
2283 DWORD Register, const void *pConstantData, DWORD ConstantCount)
2285 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2288 TRACE("iface %p, register %u, data %p, count %u.\n",
2289 iface, Register, pConstantData, ConstantCount);
2291 if(Register + ConstantCount > D3D8_MAX_VERTEX_SHADER_CONSTANTF) {
2292 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2293 Register + ConstantCount, D3D8_MAX_VERTEX_SHADER_CONSTANTF);
2294 return D3DERR_INVALIDCALL;
2297 wined3d_mutex_lock();
2298 hr = IWineD3DDevice_SetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2299 wined3d_mutex_unlock();
2304 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderConstant(IDirect3DDevice8 *iface,
2305 DWORD Register, void *pConstantData, DWORD ConstantCount)
2307 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2310 TRACE("iface %p, register %u, data %p, count %u.\n",
2311 iface, Register, pConstantData, ConstantCount);
2313 if(Register + ConstantCount > D3D8_MAX_VERTEX_SHADER_CONSTANTF) {
2314 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2315 Register + ConstantCount, D3D8_MAX_VERTEX_SHADER_CONSTANTF);
2316 return D3DERR_INVALIDCALL;
2319 wined3d_mutex_lock();
2320 hr = IWineD3DDevice_GetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2321 wined3d_mutex_unlock();
2326 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderDeclaration(IDirect3DDevice8 *iface,
2327 DWORD pVertexShader, void *pData, DWORD *pSizeOfData)
2329 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2330 IDirect3DVertexDeclaration8Impl *declaration;
2331 IDirect3DVertexShader8Impl *shader;
2333 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2334 iface, pVertexShader, pData, pSizeOfData);
2336 wined3d_mutex_lock();
2337 shader = d3d8_get_object(&This->handle_table, pVertexShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2338 wined3d_mutex_unlock();
2342 WARN("Invalid handle (%#x) passed.\n", pVertexShader);
2343 return D3DERR_INVALIDCALL;
2345 declaration = (IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration;
2347 /* If pData is NULL, we just return the required size of the buffer. */
2349 *pSizeOfData = declaration->elements_size;
2353 /* MSDN claims that if *pSizeOfData is smaller than the required size
2354 * we should write the required size and return D3DERR_MOREDATA.
2355 * That's not actually true. */
2356 if (*pSizeOfData < declaration->elements_size) {
2357 return D3DERR_INVALIDCALL;
2360 CopyMemory(pData, declaration->elements, declaration->elements_size);
2365 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderFunction(IDirect3DDevice8 *iface,
2366 DWORD pVertexShader, void *pData, DWORD *pSizeOfData)
2368 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2369 IDirect3DVertexShader8Impl *shader = NULL;
2372 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2373 iface, pVertexShader, pData, pSizeOfData);
2375 wined3d_mutex_lock();
2376 shader = d3d8_get_object(&This->handle_table, pVertexShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2379 WARN("Invalid handle (%#x) passed.\n", pVertexShader);
2380 wined3d_mutex_unlock();
2382 return D3DERR_INVALIDCALL;
2385 if (!shader->wined3d_shader)
2387 wined3d_mutex_unlock();
2392 hr = wined3d_shader_get_byte_code(shader->wined3d_shader, pData, pSizeOfData);
2393 wined3d_mutex_unlock();
2398 static HRESULT WINAPI IDirect3DDevice8Impl_SetIndices(IDirect3DDevice8 *iface,
2399 IDirect3DIndexBuffer8 *pIndexData, UINT baseVertexIndex)
2401 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2403 IDirect3DIndexBuffer8Impl *ib = (IDirect3DIndexBuffer8Impl *)pIndexData;
2405 TRACE("iface %p, buffer %p, base_vertex_idx %u.\n", iface, pIndexData, baseVertexIndex);
2407 /* WineD3D takes an INT(due to d3d9), but d3d8 uses UINTs. Do I have to add a check here that
2408 * the UINT doesn't cause an overflow in the INT? It seems rather unlikely because such large
2409 * vertex buffers can't be created to address them with an index that requires the 32nd bit
2410 * (4 Byte minimum vertex size * 2^31-1 -> 8 gb buffer. The index sign would be the least
2413 wined3d_mutex_lock();
2414 IWineD3DDevice_SetBaseVertexIndex(This->WineD3DDevice, baseVertexIndex);
2415 hr = IWineD3DDevice_SetIndexBuffer(This->WineD3DDevice,
2416 ib ? ib->wineD3DIndexBuffer : NULL,
2417 ib ? ib->format : WINED3DFMT_UNKNOWN);
2418 wined3d_mutex_unlock();
2423 static HRESULT WINAPI IDirect3DDevice8Impl_GetIndices(IDirect3DDevice8 *iface,
2424 IDirect3DIndexBuffer8 **ppIndexData, UINT *pBaseVertexIndex)
2426 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2427 struct wined3d_buffer *retIndexData = NULL;
2430 TRACE("iface %p, buffer %p, base_vertex_index %p.\n", iface, ppIndexData, pBaseVertexIndex);
2432 if(ppIndexData == NULL){
2433 return D3DERR_INVALIDCALL;
2436 /* The case from UINT to INT is safe because d3d8 will never set negative values */
2437 wined3d_mutex_lock();
2438 IWineD3DDevice_GetBaseVertexIndex(This->WineD3DDevice, (INT *) pBaseVertexIndex);
2439 hr = IWineD3DDevice_GetIndexBuffer(This->WineD3DDevice, &retIndexData);
2440 if (SUCCEEDED(hr) && retIndexData)
2442 *ppIndexData = wined3d_buffer_get_parent(retIndexData);
2443 IDirect3DIndexBuffer8_AddRef(*ppIndexData);
2444 wined3d_buffer_decref(retIndexData);
2446 if (FAILED(hr)) FIXME("Call to GetIndices failed\n");
2447 *ppIndexData = NULL;
2449 wined3d_mutex_unlock();
2454 static HRESULT WINAPI IDirect3DDevice8Impl_CreatePixelShader(IDirect3DDevice8 *iface,
2455 const DWORD *byte_code, DWORD *shader)
2457 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2458 IDirect3DPixelShader8Impl *object;
2459 DWORD shader_handle;
2463 TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
2467 TRACE("(%p) Invalid call\n", This);
2468 return D3DERR_INVALIDCALL;
2471 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2474 ERR("Failed to allocate pixel shader memmory.\n");
2475 return E_OUTOFMEMORY;
2478 wined3d_mutex_lock();
2479 handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_PS);
2480 wined3d_mutex_unlock();
2481 if (handle == D3D8_INVALID_HANDLE)
2483 ERR("Failed to allocate pixel shader handle.\n");
2484 HeapFree(GetProcessHeap(), 0, object);
2485 return E_OUTOFMEMORY;
2488 shader_handle = handle + VS_HIGHESTFIXEDFXF + 1;
2490 hr = pixelshader_init(object, This, byte_code, shader_handle);
2493 WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
2494 wined3d_mutex_lock();
2495 d3d8_free_handle(&This->handle_table, handle, D3D8_HANDLE_PS);
2496 wined3d_mutex_unlock();
2497 HeapFree(GetProcessHeap(), 0, object);
2502 TRACE("Created pixel shader %p (handle %#x).\n", object, shader_handle);
2503 *shader = shader_handle;
2508 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShader(IDirect3DDevice8 *iface, DWORD pShader)
2510 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2511 IDirect3DPixelShader8Impl *shader;
2514 TRACE("iface %p, shader %#x.\n", iface, pShader);
2516 wined3d_mutex_lock();
2520 hr = IWineD3DDevice_SetPixelShader(This->WineD3DDevice, NULL);
2521 wined3d_mutex_unlock();
2525 shader = d3d8_get_object(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2528 WARN("Invalid handle (%#x) passed.\n", pShader);
2529 wined3d_mutex_unlock();
2530 return D3DERR_INVALIDCALL;
2533 TRACE("(%p) : Setting shader %p\n", This, shader);
2534 hr = IWineD3DDevice_SetPixelShader(This->WineD3DDevice, shader->wined3d_shader);
2535 wined3d_mutex_unlock();
2540 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShader(IDirect3DDevice8 *iface, DWORD *ppShader)
2542 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2543 struct wined3d_shader *object;
2545 TRACE("iface %p, shader %p.\n", iface, ppShader);
2547 if (NULL == ppShader) {
2548 TRACE("(%p) Invalid call\n", This);
2549 return D3DERR_INVALIDCALL;
2552 wined3d_mutex_lock();
2553 object = IWineD3DDevice_GetPixelShader(This->WineD3DDevice);
2556 IDirect3DPixelShader8Impl *d3d8_shader;
2557 d3d8_shader = wined3d_shader_get_parent(object);
2558 wined3d_shader_decref(object);
2559 *ppShader = d3d8_shader->handle;
2565 wined3d_mutex_unlock();
2567 TRACE("(%p) : returning %#x\n", This, *ppShader);
2572 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePixelShader(IDirect3DDevice8 *iface, DWORD pShader)
2574 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2575 IDirect3DPixelShader8Impl *shader;
2576 struct wined3d_shader *cur;
2578 TRACE("iface %p, shader %#x.\n", iface, pShader);
2580 wined3d_mutex_lock();
2582 shader = d3d8_free_handle(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2585 WARN("Invalid handle (%#x) passed.\n", pShader);
2586 wined3d_mutex_unlock();
2587 return D3DERR_INVALIDCALL;
2590 cur = IWineD3DDevice_GetPixelShader(This->WineD3DDevice);
2593 if (cur == shader->wined3d_shader)
2594 IDirect3DDevice8_SetPixelShader(iface, 0);
2595 wined3d_shader_decref(cur);
2598 wined3d_mutex_unlock();
2600 if (IDirect3DPixelShader8_Release(&shader->IDirect3DPixelShader8_iface))
2602 ERR("Shader %p has references left, this shouldn't happen.\n", shader);
2608 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShaderConstant(IDirect3DDevice8 *iface,
2609 DWORD Register, const void *pConstantData, DWORD ConstantCount)
2611 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2614 TRACE("iface %p, register %u, data %p, count %u.\n",
2615 iface, Register, pConstantData, ConstantCount);
2617 wined3d_mutex_lock();
2618 hr = IWineD3DDevice_SetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2619 wined3d_mutex_unlock();
2624 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderConstant(IDirect3DDevice8 *iface,
2625 DWORD Register, void *pConstantData, DWORD ConstantCount)
2627 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2630 TRACE("iface %p, register %u, data %p, count %u.\n",
2631 iface, Register, pConstantData, ConstantCount);
2633 wined3d_mutex_lock();
2634 hr = IWineD3DDevice_GetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2635 wined3d_mutex_unlock();
2640 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderFunction(IDirect3DDevice8 *iface,
2641 DWORD pPixelShader, void *pData, DWORD *pSizeOfData)
2643 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2644 IDirect3DPixelShader8Impl *shader = NULL;
2647 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2648 iface, pPixelShader, pData, pSizeOfData);
2650 wined3d_mutex_lock();
2651 shader = d3d8_get_object(&This->handle_table, pPixelShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2654 WARN("Invalid handle (%#x) passed.\n", pPixelShader);
2655 wined3d_mutex_unlock();
2657 return D3DERR_INVALIDCALL;
2660 hr = wined3d_shader_get_byte_code(shader->wined3d_shader, pData, pSizeOfData);
2661 wined3d_mutex_unlock();
2666 static HRESULT WINAPI IDirect3DDevice8Impl_DrawRectPatch(IDirect3DDevice8 *iface, UINT Handle,
2667 const float *pNumSegs, const D3DRECTPATCH_INFO *pRectPatchInfo)
2669 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2672 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2673 iface, Handle, pNumSegs, pRectPatchInfo);
2675 wined3d_mutex_lock();
2676 hr = IWineD3DDevice_DrawRectPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DRECTPATCH_INFO *)pRectPatchInfo);
2677 wined3d_mutex_unlock();
2682 static HRESULT WINAPI IDirect3DDevice8Impl_DrawTriPatch(IDirect3DDevice8 *iface, UINT Handle,
2683 const float *pNumSegs, const D3DTRIPATCH_INFO *pTriPatchInfo)
2685 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2688 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2689 iface, Handle, pNumSegs, pTriPatchInfo);
2691 wined3d_mutex_lock();
2692 hr = IWineD3DDevice_DrawTriPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DTRIPATCH_INFO *)pTriPatchInfo);
2693 wined3d_mutex_unlock();
2698 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePatch(IDirect3DDevice8 *iface, UINT Handle)
2700 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2703 TRACE("iface %p, handle %#x.\n", iface, Handle);
2705 wined3d_mutex_lock();
2706 hr = IWineD3DDevice_DeletePatch(This->WineD3DDevice, Handle);
2707 wined3d_mutex_unlock();
2712 static HRESULT WINAPI IDirect3DDevice8Impl_SetStreamSource(IDirect3DDevice8 *iface,
2713 UINT StreamNumber, IDirect3DVertexBuffer8 *pStreamData, UINT Stride)
2715 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2718 TRACE("iface %p, stream_idx %u, buffer %p, stride %u.\n",
2719 iface, StreamNumber, pStreamData, Stride);
2721 wined3d_mutex_lock();
2722 hr = IWineD3DDevice_SetStreamSource(This->WineD3DDevice, StreamNumber,
2723 NULL == pStreamData ? NULL : ((IDirect3DVertexBuffer8Impl *)pStreamData)->wineD3DVertexBuffer,
2724 0/* Offset in bytes */, Stride);
2725 wined3d_mutex_unlock();
2730 static HRESULT WINAPI IDirect3DDevice8Impl_GetStreamSource(IDirect3DDevice8 *iface,
2731 UINT StreamNumber, IDirect3DVertexBuffer8 **pStream, UINT *pStride)
2733 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2734 struct wined3d_buffer *retStream = NULL;
2737 TRACE("iface %p, stream_idx %u, buffer %p, stride %p.\n",
2738 iface, StreamNumber, pStream, pStride);
2740 if(pStream == NULL){
2741 return D3DERR_INVALIDCALL;
2744 wined3d_mutex_lock();
2745 hr = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber,
2746 &retStream, 0 /* Offset in bytes */, pStride);
2747 if (SUCCEEDED(hr) && retStream)
2749 *pStream = wined3d_buffer_get_parent(retStream);
2750 IDirect3DVertexBuffer8_AddRef(*pStream);
2751 wined3d_buffer_decref(retStream);
2755 if (FAILED(hr)) FIXME("Call to GetStreamSource failed, hr %#x.\n", hr);
2758 wined3d_mutex_unlock();
2763 static const IDirect3DDevice8Vtbl Direct3DDevice8_Vtbl =
2765 IDirect3DDevice8Impl_QueryInterface,
2766 IDirect3DDevice8Impl_AddRef,
2767 IDirect3DDevice8Impl_Release,
2768 IDirect3DDevice8Impl_TestCooperativeLevel,
2769 IDirect3DDevice8Impl_GetAvailableTextureMem,
2770 IDirect3DDevice8Impl_ResourceManagerDiscardBytes,
2771 IDirect3DDevice8Impl_GetDirect3D,
2772 IDirect3DDevice8Impl_GetDeviceCaps,
2773 IDirect3DDevice8Impl_GetDisplayMode,
2774 IDirect3DDevice8Impl_GetCreationParameters,
2775 IDirect3DDevice8Impl_SetCursorProperties,
2776 IDirect3DDevice8Impl_SetCursorPosition,
2777 IDirect3DDevice8Impl_ShowCursor,
2778 IDirect3DDevice8Impl_CreateAdditionalSwapChain,
2779 IDirect3DDevice8Impl_Reset,
2780 IDirect3DDevice8Impl_Present,
2781 IDirect3DDevice8Impl_GetBackBuffer,
2782 IDirect3DDevice8Impl_GetRasterStatus,
2783 IDirect3DDevice8Impl_SetGammaRamp,
2784 IDirect3DDevice8Impl_GetGammaRamp,
2785 IDirect3DDevice8Impl_CreateTexture,
2786 IDirect3DDevice8Impl_CreateVolumeTexture,
2787 IDirect3DDevice8Impl_CreateCubeTexture,
2788 IDirect3DDevice8Impl_CreateVertexBuffer,
2789 IDirect3DDevice8Impl_CreateIndexBuffer,
2790 IDirect3DDevice8Impl_CreateRenderTarget,
2791 IDirect3DDevice8Impl_CreateDepthStencilSurface,
2792 IDirect3DDevice8Impl_CreateImageSurface,
2793 IDirect3DDevice8Impl_CopyRects,
2794 IDirect3DDevice8Impl_UpdateTexture,
2795 IDirect3DDevice8Impl_GetFrontBuffer,
2796 IDirect3DDevice8Impl_SetRenderTarget,
2797 IDirect3DDevice8Impl_GetRenderTarget,
2798 IDirect3DDevice8Impl_GetDepthStencilSurface,
2799 IDirect3DDevice8Impl_BeginScene,
2800 IDirect3DDevice8Impl_EndScene,
2801 IDirect3DDevice8Impl_Clear,
2802 IDirect3DDevice8Impl_SetTransform,
2803 IDirect3DDevice8Impl_GetTransform,
2804 IDirect3DDevice8Impl_MultiplyTransform,
2805 IDirect3DDevice8Impl_SetViewport,
2806 IDirect3DDevice8Impl_GetViewport,
2807 IDirect3DDevice8Impl_SetMaterial,
2808 IDirect3DDevice8Impl_GetMaterial,
2809 IDirect3DDevice8Impl_SetLight,
2810 IDirect3DDevice8Impl_GetLight,
2811 IDirect3DDevice8Impl_LightEnable,
2812 IDirect3DDevice8Impl_GetLightEnable,
2813 IDirect3DDevice8Impl_SetClipPlane,
2814 IDirect3DDevice8Impl_GetClipPlane,
2815 IDirect3DDevice8Impl_SetRenderState,
2816 IDirect3DDevice8Impl_GetRenderState,
2817 IDirect3DDevice8Impl_BeginStateBlock,
2818 IDirect3DDevice8Impl_EndStateBlock,
2819 IDirect3DDevice8Impl_ApplyStateBlock,
2820 IDirect3DDevice8Impl_CaptureStateBlock,
2821 IDirect3DDevice8Impl_DeleteStateBlock,
2822 IDirect3DDevice8Impl_CreateStateBlock,
2823 IDirect3DDevice8Impl_SetClipStatus,
2824 IDirect3DDevice8Impl_GetClipStatus,
2825 IDirect3DDevice8Impl_GetTexture,
2826 IDirect3DDevice8Impl_SetTexture,
2827 IDirect3DDevice8Impl_GetTextureStageState,
2828 IDirect3DDevice8Impl_SetTextureStageState,
2829 IDirect3DDevice8Impl_ValidateDevice,
2830 IDirect3DDevice8Impl_GetInfo,
2831 IDirect3DDevice8Impl_SetPaletteEntries,
2832 IDirect3DDevice8Impl_GetPaletteEntries,
2833 IDirect3DDevice8Impl_SetCurrentTexturePalette,
2834 IDirect3DDevice8Impl_GetCurrentTexturePalette,
2835 IDirect3DDevice8Impl_DrawPrimitive,
2836 IDirect3DDevice8Impl_DrawIndexedPrimitive,
2837 IDirect3DDevice8Impl_DrawPrimitiveUP,
2838 IDirect3DDevice8Impl_DrawIndexedPrimitiveUP,
2839 IDirect3DDevice8Impl_ProcessVertices,
2840 IDirect3DDevice8Impl_CreateVertexShader,
2841 IDirect3DDevice8Impl_SetVertexShader,
2842 IDirect3DDevice8Impl_GetVertexShader,
2843 IDirect3DDevice8Impl_DeleteVertexShader,
2844 IDirect3DDevice8Impl_SetVertexShaderConstant,
2845 IDirect3DDevice8Impl_GetVertexShaderConstant,
2846 IDirect3DDevice8Impl_GetVertexShaderDeclaration,
2847 IDirect3DDevice8Impl_GetVertexShaderFunction,
2848 IDirect3DDevice8Impl_SetStreamSource,
2849 IDirect3DDevice8Impl_GetStreamSource,
2850 IDirect3DDevice8Impl_SetIndices,
2851 IDirect3DDevice8Impl_GetIndices,
2852 IDirect3DDevice8Impl_CreatePixelShader,
2853 IDirect3DDevice8Impl_SetPixelShader,
2854 IDirect3DDevice8Impl_GetPixelShader,
2855 IDirect3DDevice8Impl_DeletePixelShader,
2856 IDirect3DDevice8Impl_SetPixelShaderConstant,
2857 IDirect3DDevice8Impl_GetPixelShaderConstant,
2858 IDirect3DDevice8Impl_GetPixelShaderFunction,
2859 IDirect3DDevice8Impl_DrawRectPatch,
2860 IDirect3DDevice8Impl_DrawTriPatch,
2861 IDirect3DDevice8Impl_DeletePatch
2864 static inline IDirect3DDevice8Impl *impl_from_IWineD3DDeviceParent(IWineD3DDeviceParent *iface)
2866 return CONTAINING_RECORD(iface, IDirect3DDevice8Impl, IWineD3DDeviceParent_iface);
2869 static HRESULT STDMETHODCALLTYPE device_parent_QueryInterface(IWineD3DDeviceParent *iface,
2870 REFIID riid, void **object)
2872 IDirect3DDevice8Impl *This = impl_from_IWineD3DDeviceParent(iface);
2873 return IDirect3DDevice8Impl_QueryInterface(&This->IDirect3DDevice8_iface, riid, object);
2876 static ULONG STDMETHODCALLTYPE device_parent_AddRef(IWineD3DDeviceParent *iface)
2878 IDirect3DDevice8Impl *This = impl_from_IWineD3DDeviceParent(iface);
2879 return IDirect3DDevice8Impl_AddRef(&This->IDirect3DDevice8_iface);
2882 static ULONG STDMETHODCALLTYPE device_parent_Release(IWineD3DDeviceParent *iface)
2884 IDirect3DDevice8Impl *This = impl_from_IWineD3DDeviceParent(iface);
2885 return IDirect3DDevice8Impl_Release(&This->IDirect3DDevice8_iface);
2888 /* IWineD3DDeviceParent methods */
2890 static void STDMETHODCALLTYPE device_parent_WineD3DDeviceCreated(IWineD3DDeviceParent *iface, IWineD3DDevice *device)
2892 TRACE("iface %p, device %p\n", iface, device);
2895 static HRESULT STDMETHODCALLTYPE device_parent_CreateSurface(IWineD3DDeviceParent *iface,
2896 void *container_parent, UINT width, UINT height, enum wined3d_format_id format, DWORD usage,
2897 WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, struct wined3d_surface **surface)
2899 IDirect3DDevice8Impl *This = impl_from_IWineD3DDeviceParent(iface);
2900 IDirect3DSurface8Impl *d3d_surface;
2901 BOOL lockable = TRUE;
2904 TRACE("iface %p, container_parent %p, width %u, height %u, format %#x, usage %#x,\n"
2905 "\tpool %#x, level %u, face %u, surface %p\n",
2906 iface, container_parent, width, height, format, usage, pool, level, face, surface);
2909 if (pool == WINED3DPOOL_DEFAULT && !(usage & WINED3DUSAGE_DYNAMIC)) lockable = FALSE;
2911 hr = IDirect3DDevice8Impl_CreateSurface(This, width, height,
2912 d3dformat_from_wined3dformat(format), lockable, FALSE /* Discard */, level,
2913 (IDirect3DSurface8 **)&d3d_surface, usage, pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
2916 ERR("(%p) CreateSurface failed, returning %#x\n", iface, hr);
2920 *surface = d3d_surface->wined3d_surface;
2921 wined3d_surface_incref(*surface);
2923 d3d_surface->container = container_parent;
2924 IUnknown_Release(d3d_surface->parentDevice);
2925 d3d_surface->parentDevice = NULL;
2927 IDirect3DSurface8_Release((IDirect3DSurface8 *)d3d_surface);
2928 d3d_surface->forwardReference = container_parent;
2933 static HRESULT STDMETHODCALLTYPE device_parent_CreateRenderTarget(IWineD3DDeviceParent *iface,
2934 void *container_parent, UINT width, UINT height, enum wined3d_format_id format,
2935 WINED3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality, BOOL lockable,
2936 struct wined3d_surface **surface)
2938 IDirect3DDevice8Impl *This = impl_from_IWineD3DDeviceParent(iface);
2939 IDirect3DSurface8Impl *d3d_surface;
2942 TRACE("iface %p, container_parent %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2943 "\tmultisample_quality %u, lockable %u, surface %p\n",
2944 iface, container_parent, width, height, format, multisample_type, multisample_quality, lockable, surface);
2946 hr = IDirect3DDevice8_CreateRenderTarget(&This->IDirect3DDevice8_iface, width, height,
2947 d3dformat_from_wined3dformat(format), multisample_type, lockable, (IDirect3DSurface8 **)&d3d_surface);
2950 ERR("(%p) CreateRenderTarget failed, returning %#x\n", iface, hr);
2954 *surface = d3d_surface->wined3d_surface;
2955 wined3d_surface_incref(*surface);
2957 d3d_surface->container = (IUnknown *)&This->IDirect3DDevice8_iface;
2958 /* Implicit surfaces are created with an refcount of 0 */
2959 IUnknown_Release((IUnknown *)d3d_surface);
2964 static HRESULT STDMETHODCALLTYPE device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent *iface,
2965 UINT width, UINT height, enum wined3d_format_id format, WINED3DMULTISAMPLE_TYPE multisample_type,
2966 DWORD multisample_quality, BOOL discard, struct wined3d_surface **surface)
2968 IDirect3DDevice8Impl *This = impl_from_IWineD3DDeviceParent(iface);
2969 IDirect3DSurface8Impl *d3d_surface;
2972 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2973 "\tmultisample_quality %u, discard %u, surface %p\n",
2974 iface, width, height, format, multisample_type, multisample_quality, discard, surface);
2976 hr = IDirect3DDevice8_CreateDepthStencilSurface(&This->IDirect3DDevice8_iface, width, height,
2977 d3dformat_from_wined3dformat(format), multisample_type, (IDirect3DSurface8 **)&d3d_surface);
2980 ERR("(%p) CreateDepthStencilSurface failed, returning %#x\n", iface, hr);
2984 *surface = d3d_surface->wined3d_surface;
2985 wined3d_surface_incref(*surface);
2987 d3d_surface->container = (IUnknown *)&This->IDirect3DDevice8_iface;
2988 /* Implicit surfaces are created with an refcount of 0 */
2989 IUnknown_Release((IUnknown *)d3d_surface);
2994 static HRESULT STDMETHODCALLTYPE device_parent_CreateVolume(IWineD3DDeviceParent *iface,
2995 void *container_parent, UINT width, UINT height, UINT depth, enum wined3d_format_id format,
2996 WINED3DPOOL pool, DWORD usage, struct wined3d_volume **volume)
2998 IDirect3DDevice8Impl *This = impl_from_IWineD3DDeviceParent(iface);
2999 IDirect3DVolume8Impl *object;
3002 TRACE("iface %p, container_parent %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p\n",
3003 iface, container_parent, width, height, depth, format, pool, usage, volume);
3005 /* Allocate the storage for the device */
3006 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
3009 FIXME("Allocation of memory failed\n");
3011 return D3DERR_OUTOFVIDEOMEMORY;
3014 hr = volume_init(object, This, width, height, depth, usage, format, pool);
3017 WARN("Failed to initialize volume, hr %#x.\n", hr);
3018 HeapFree(GetProcessHeap(), 0, object);
3022 *volume = object->wined3d_volume;
3023 wined3d_volume_incref(*volume);
3024 IDirect3DVolume8_Release(&object->IDirect3DVolume8_iface);
3026 object->container = container_parent;
3027 object->forwardReference = container_parent;
3029 TRACE("(%p) Created volume %p\n", iface, object);
3034 static HRESULT STDMETHODCALLTYPE device_parent_CreateSwapChain(IWineD3DDeviceParent *iface,
3035 WINED3DPRESENT_PARAMETERS *present_parameters, struct wined3d_swapchain **swapchain)
3037 IDirect3DDevice8Impl *This = impl_from_IWineD3DDeviceParent(iface);
3038 D3DPRESENT_PARAMETERS local_parameters;
3039 IDirect3DSwapChain8 *d3d_swapchain;
3042 TRACE("iface %p, present_parameters %p, swapchain %p\n", iface, present_parameters, swapchain);
3044 /* Copy the presentation parameters */
3045 local_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
3046 local_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
3047 local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(present_parameters->BackBufferFormat);
3048 local_parameters.BackBufferCount = present_parameters->BackBufferCount;
3049 local_parameters.MultiSampleType = present_parameters->MultiSampleType;
3050 local_parameters.SwapEffect = present_parameters->SwapEffect;
3051 local_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
3052 local_parameters.Windowed = present_parameters->Windowed;
3053 local_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
3054 local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(present_parameters->AutoDepthStencilFormat);
3055 local_parameters.Flags = present_parameters->Flags;
3056 local_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
3057 local_parameters.FullScreen_PresentationInterval = present_parameters->PresentationInterval;
3059 hr = IDirect3DDevice8_CreateAdditionalSwapChain(&This->IDirect3DDevice8_iface,
3060 &local_parameters, &d3d_swapchain);
3063 ERR("(%p) CreateAdditionalSwapChain failed, returning %#x\n", iface, hr);
3068 *swapchain = ((IDirect3DSwapChain8Impl *)d3d_swapchain)->wined3d_swapchain;
3069 wined3d_swapchain_incref(*swapchain);
3070 IDirect3DSwapChain8_Release(d3d_swapchain);
3072 /* Copy back the presentation parameters */
3073 present_parameters->BackBufferWidth = local_parameters.BackBufferWidth;
3074 present_parameters->BackBufferHeight = local_parameters.BackBufferHeight;
3075 present_parameters->BackBufferFormat = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat);
3076 present_parameters->BackBufferCount = local_parameters.BackBufferCount;
3077 present_parameters->MultiSampleType = local_parameters.MultiSampleType;
3078 present_parameters->SwapEffect = local_parameters.SwapEffect;
3079 present_parameters->hDeviceWindow = local_parameters.hDeviceWindow;
3080 present_parameters->Windowed = local_parameters.Windowed;
3081 present_parameters->EnableAutoDepthStencil = local_parameters.EnableAutoDepthStencil;
3082 present_parameters->AutoDepthStencilFormat = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat);
3083 present_parameters->Flags = local_parameters.Flags;
3084 present_parameters->FullScreen_RefreshRateInHz = local_parameters.FullScreen_RefreshRateInHz;
3085 present_parameters->PresentationInterval = local_parameters.FullScreen_PresentationInterval;
3090 static const IWineD3DDeviceParentVtbl d3d8_wined3d_device_parent_vtbl =
3092 /* IUnknown methods */
3093 device_parent_QueryInterface,
3094 device_parent_AddRef,
3095 device_parent_Release,
3096 /* IWineD3DDeviceParent methods */
3097 device_parent_WineD3DDeviceCreated,
3098 device_parent_CreateSurface,
3099 device_parent_CreateRenderTarget,
3100 device_parent_CreateDepthStencilSurface,
3101 device_parent_CreateVolume,
3102 device_parent_CreateSwapChain,
3105 static void setup_fpu(void)
3107 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3109 __asm__ volatile ("fnstcw %0" : "=m" (cw));
3110 cw = (cw & ~0xf3f) | 0x3f;
3111 __asm__ volatile ("fldcw %0" : : "m" (cw));
3113 FIXME("FPU setup not implemented for this platform.\n");
3117 HRESULT device_init(IDirect3DDevice8Impl *device, struct wined3d *wined3d, UINT adapter,
3118 D3DDEVTYPE device_type, HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters)
3120 WINED3DPRESENT_PARAMETERS wined3d_parameters;
3123 device->IDirect3DDevice8_iface.lpVtbl = &Direct3DDevice8_Vtbl;
3124 device->IWineD3DDeviceParent_iface.lpVtbl = &d3d8_wined3d_device_parent_vtbl;
3126 device->handle_table.entries = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
3127 D3D8_INITIAL_HANDLE_TABLE_SIZE * sizeof(*device->handle_table.entries));
3128 if (!device->handle_table.entries)
3130 ERR("Failed to allocate handle table memory.\n");
3131 return E_OUTOFMEMORY;
3133 device->handle_table.table_size = D3D8_INITIAL_HANDLE_TABLE_SIZE;
3135 if (!(flags & D3DCREATE_FPU_PRESERVE)) setup_fpu();
3137 wined3d_mutex_lock();
3138 hr = wined3d_device_create(wined3d, adapter, device_type, focus_window, flags,
3139 &device->IWineD3DDeviceParent_iface, &device->WineD3DDevice);
3142 WARN("Failed to create wined3d device, hr %#x.\n", hr);
3143 wined3d_mutex_unlock();
3144 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);
3148 if (!parameters->Windowed)
3150 HWND device_window = parameters->hDeviceWindow;
3152 if (!focus_window) focus_window = device_window;
3153 if (FAILED(hr = IWineD3DDevice_AcquireFocusWindow(device->WineD3DDevice, focus_window)))
3155 ERR("Failed to acquire focus window, hr %#x.\n", hr);
3156 IWineD3DDevice_Release(device->WineD3DDevice);
3157 wined3d_mutex_unlock();
3158 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);
3162 if (!device_window) device_window = focus_window;
3163 IWineD3DDevice_SetupFullscreenWindow(device->WineD3DDevice, device_window,
3164 parameters->BackBufferWidth,
3165 parameters->BackBufferHeight);
3168 if (flags & D3DCREATE_MULTITHREADED) IWineD3DDevice_SetMultithreaded(device->WineD3DDevice);
3170 wined3d_parameters.BackBufferWidth = parameters->BackBufferWidth;
3171 wined3d_parameters.BackBufferHeight = parameters->BackBufferHeight;
3172 wined3d_parameters.BackBufferFormat = wined3dformat_from_d3dformat(parameters->BackBufferFormat);
3173 wined3d_parameters.BackBufferCount = parameters->BackBufferCount;
3174 wined3d_parameters.MultiSampleType = parameters->MultiSampleType;
3175 wined3d_parameters.MultiSampleQuality = 0; /* d3d9 only */
3176 wined3d_parameters.SwapEffect = parameters->SwapEffect;
3177 wined3d_parameters.hDeviceWindow = parameters->hDeviceWindow;
3178 wined3d_parameters.Windowed = parameters->Windowed;
3179 wined3d_parameters.EnableAutoDepthStencil = parameters->EnableAutoDepthStencil;
3180 wined3d_parameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(parameters->AutoDepthStencilFormat);
3181 wined3d_parameters.Flags = parameters->Flags;
3182 wined3d_parameters.FullScreen_RefreshRateInHz = parameters->FullScreen_RefreshRateInHz;
3183 wined3d_parameters.PresentationInterval = parameters->FullScreen_PresentationInterval;
3184 wined3d_parameters.AutoRestoreDisplayMode = TRUE;
3186 hr = IWineD3DDevice_Init3D(device->WineD3DDevice, &wined3d_parameters);
3189 WARN("Failed to initialize 3D, hr %#x.\n", hr);
3190 IWineD3DDevice_ReleaseFocusWindow(device->WineD3DDevice);
3191 IWineD3DDevice_Release(device->WineD3DDevice);
3192 wined3d_mutex_unlock();
3193 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);
3197 hr = IWineD3DDevice_SetRenderState(device->WineD3DDevice, WINED3DRS_POINTSIZE_MIN, 0);
3198 wined3d_mutex_unlock();
3201 ERR("Failed to set minimum pointsize, hr %#x.\n", hr);
3205 parameters->BackBufferWidth = wined3d_parameters.BackBufferWidth;
3206 parameters->BackBufferHeight = wined3d_parameters.BackBufferHeight;
3207 parameters->BackBufferFormat = d3dformat_from_wined3dformat(wined3d_parameters.BackBufferFormat);
3208 parameters->BackBufferCount = wined3d_parameters.BackBufferCount;
3209 parameters->MultiSampleType = wined3d_parameters.MultiSampleType;
3210 parameters->SwapEffect = wined3d_parameters.SwapEffect;
3211 parameters->hDeviceWindow = wined3d_parameters.hDeviceWindow;
3212 parameters->Windowed = wined3d_parameters.Windowed;
3213 parameters->EnableAutoDepthStencil = wined3d_parameters.EnableAutoDepthStencil;
3214 parameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(wined3d_parameters.AutoDepthStencilFormat);
3215 parameters->Flags = wined3d_parameters.Flags;
3216 parameters->FullScreen_RefreshRateInHz = wined3d_parameters.FullScreen_RefreshRateInHz;
3217 parameters->FullScreen_PresentationInterval = wined3d_parameters.PresentationInterval;
3219 device->declArraySize = 16;
3220 device->decls = HeapAlloc(GetProcessHeap(), 0, device->declArraySize * sizeof(*device->decls));
3223 ERR("Failed to allocate FVF vertex delcaration map memory.\n");
3231 wined3d_mutex_lock();
3232 IWineD3DDevice_Uninit3D(device->WineD3DDevice);
3233 IWineD3DDevice_ReleaseFocusWindow(device->WineD3DDevice);
3234 IWineD3DDevice_Release(device->WineD3DDevice);
3235 wined3d_mutex_unlock();
3236 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);