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 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
279 return E_NOINTERFACE;
282 static ULONG WINAPI IDirect3DDevice8Impl_AddRef(IDirect3DDevice8 *iface)
284 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
285 ULONG ref = InterlockedIncrement(&This->ref);
287 TRACE("%p increasing refcount to %u.\n", iface, ref);
292 static ULONG WINAPI IDirect3DDevice8Impl_Release(IDirect3DDevice8 *iface)
294 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
297 if (This->inDestruction) return 0;
298 ref = InterlockedDecrement(&This->ref);
300 TRACE("%p decreasing refcount to %u.\n", iface, ref);
304 IDirect3D8 *parent = This->d3d_parent;
306 TRACE("Releasing wined3d device %p.\n", This->wined3d_device);
308 wined3d_mutex_lock();
310 This->inDestruction = TRUE;
312 for(i = 0; i < This->numConvertedDecls; i++) {
313 IDirect3DVertexDeclaration8_Release(This->decls[i].decl);
315 HeapFree(GetProcessHeap(), 0, This->decls);
317 wined3d_device_uninit_3d(This->wined3d_device);
318 wined3d_device_release_focus_window(This->wined3d_device);
319 wined3d_device_decref(This->wined3d_device);
320 HeapFree(GetProcessHeap(), 0, This->handle_table.entries);
321 HeapFree(GetProcessHeap(), 0, This);
323 wined3d_mutex_unlock();
325 IDirect3D8_Release(parent);
330 /* IDirect3DDevice Interface follow: */
331 static HRESULT WINAPI IDirect3DDevice8Impl_TestCooperativeLevel(IDirect3DDevice8 *iface)
333 IDirect3DDevice8Impl *device = impl_from_IDirect3DDevice8(iface);
335 TRACE("iface %p.\n", iface);
339 TRACE("Device is lost.\n");
340 return D3DERR_DEVICENOTRESET;
346 static UINT WINAPI IDirect3DDevice8Impl_GetAvailableTextureMem(IDirect3DDevice8 *iface)
348 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
351 TRACE("iface %p.\n", iface);
353 wined3d_mutex_lock();
354 hr = wined3d_device_get_available_texture_mem(This->wined3d_device);
355 wined3d_mutex_unlock();
360 static HRESULT WINAPI IDirect3DDevice8Impl_ResourceManagerDiscardBytes(IDirect3DDevice8 *iface,
363 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
365 TRACE("iface %p, byte_count %u.\n", iface, Bytes);
366 if (Bytes) FIXME("Byte count ignored.\n");
368 wined3d_mutex_lock();
369 wined3d_device_evict_managed_resources(This->wined3d_device);
370 wined3d_mutex_unlock();
375 static HRESULT WINAPI IDirect3DDevice8Impl_GetDirect3D(IDirect3DDevice8 *iface, IDirect3D8 **ppD3D8)
377 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
379 TRACE("iface %p, d3d8 %p.\n", iface, ppD3D8);
381 if (NULL == ppD3D8) {
382 return D3DERR_INVALIDCALL;
385 return IDirect3D8_QueryInterface(This->d3d_parent, &IID_IDirect3D8, (void **)ppD3D8);
388 static HRESULT WINAPI IDirect3DDevice8Impl_GetDeviceCaps(IDirect3DDevice8 *iface, D3DCAPS8 *pCaps)
390 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
391 HRESULT hrc = D3D_OK;
392 WINED3DCAPS *pWineCaps;
394 TRACE("iface %p, caps %p.\n", iface, pCaps);
397 return D3DERR_INVALIDCALL;
399 pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
400 if(pWineCaps == NULL){
401 return D3DERR_INVALIDCALL; /* well this is what MSDN says to return */
404 wined3d_mutex_lock();
405 hrc = wined3d_device_get_device_caps(This->wined3d_device, pWineCaps);
406 wined3d_mutex_unlock();
408 fixup_caps(pWineCaps);
409 WINECAPSTOD3D8CAPS(pCaps, pWineCaps)
410 HeapFree(GetProcessHeap(), 0, pWineCaps);
412 TRACE("Returning %p %p\n", This, pCaps);
416 static HRESULT WINAPI IDirect3DDevice8Impl_GetDisplayMode(IDirect3DDevice8 *iface,
417 D3DDISPLAYMODE *pMode)
419 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
422 TRACE("iface %p, mode %p.\n", iface, pMode);
424 wined3d_mutex_lock();
425 hr = wined3d_device_get_display_mode(This->wined3d_device, 0, (WINED3DDISPLAYMODE *)pMode);
426 wined3d_mutex_unlock();
428 if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
433 static HRESULT WINAPI IDirect3DDevice8Impl_GetCreationParameters(IDirect3DDevice8 *iface,
434 D3DDEVICE_CREATION_PARAMETERS *pParameters)
436 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
439 TRACE("iface %p, parameters %p.\n", iface, pParameters);
441 wined3d_mutex_lock();
442 hr = wined3d_device_get_creation_parameters(This->wined3d_device,
443 (WINED3DDEVICE_CREATION_PARAMETERS *)pParameters);
444 wined3d_mutex_unlock();
449 static HRESULT WINAPI IDirect3DDevice8Impl_SetCursorProperties(IDirect3DDevice8 *iface,
450 UINT XHotSpot, UINT YHotSpot, IDirect3DSurface8 *pCursorBitmap)
452 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
453 IDirect3DSurface8Impl *pSurface = unsafe_impl_from_IDirect3DSurface8(pCursorBitmap);
456 TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
457 iface, XHotSpot, YHotSpot, pCursorBitmap);
461 WARN("No cursor bitmap, returning D3DERR_INVALIDCALL.\n");
462 return D3DERR_INVALIDCALL;
465 wined3d_mutex_lock();
466 hr = wined3d_device_set_cursor_properties(This->wined3d_device, XHotSpot, YHotSpot, pSurface->wined3d_surface);
467 wined3d_mutex_unlock();
472 static void WINAPI IDirect3DDevice8Impl_SetCursorPosition(IDirect3DDevice8 *iface,
473 UINT XScreenSpace, UINT YScreenSpace, DWORD Flags)
475 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
477 TRACE("iface %p, x %u, y %u, flags %#x.\n",
478 iface, XScreenSpace, YScreenSpace, Flags);
480 wined3d_mutex_lock();
481 wined3d_device_set_cursor_position(This->wined3d_device, XScreenSpace, YScreenSpace, Flags);
482 wined3d_mutex_unlock();
485 static BOOL WINAPI IDirect3DDevice8Impl_ShowCursor(IDirect3DDevice8 *iface, BOOL bShow)
487 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
490 TRACE("iface %p, show %#x.\n", iface, bShow);
492 wined3d_mutex_lock();
493 ret = wined3d_device_show_cursor(This->wined3d_device, bShow);
494 wined3d_mutex_unlock();
499 static HRESULT WINAPI IDirect3DDevice8Impl_CreateAdditionalSwapChain(IDirect3DDevice8 *iface,
500 D3DPRESENT_PARAMETERS *present_parameters, IDirect3DSwapChain8 **swapchain)
502 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
503 IDirect3DSwapChain8Impl *object;
506 TRACE("iface %p, present_parameters %p, swapchain %p.\n",
507 iface, present_parameters, swapchain);
509 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
512 ERR("Failed to allocate swapchain memory.\n");
513 return E_OUTOFMEMORY;
516 hr = swapchain_init(object, This, present_parameters);
519 WARN("Failed to initialize swapchain, hr %#x.\n", hr);
520 HeapFree(GetProcessHeap(), 0, object);
524 TRACE("Created swapchain %p.\n", object);
525 *swapchain = &object->IDirect3DSwapChain8_iface;
530 static HRESULT CDECL reset_enum_callback(struct wined3d_resource *resource)
532 struct wined3d_resource_desc desc;
534 wined3d_resource_get_desc(resource, &desc);
535 if (desc.pool == WINED3DPOOL_DEFAULT)
537 IDirect3DSurface8 *surface;
539 if (desc.resource_type != WINED3DRTYPE_SURFACE)
541 WARN("Resource %p in pool D3DPOOL_DEFAULT blocks the Reset call.\n", resource);
542 return D3DERR_DEVICELOST;
545 surface = wined3d_resource_get_parent(resource);
547 IDirect3DSurface8_AddRef(surface);
548 if (IDirect3DSurface8_Release(surface))
550 WARN("Surface %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", surface, resource);
551 return D3DERR_DEVICELOST;
554 WARN("Surface %p (resource %p) is an implicit resource with ref 0.\n", surface, resource);
560 static HRESULT WINAPI IDirect3DDevice8Impl_Reset(IDirect3DDevice8 *iface,
561 D3DPRESENT_PARAMETERS *pPresentationParameters)
563 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
564 WINED3DPRESENT_PARAMETERS localParameters;
567 TRACE("iface %p, present_parameters %p.\n", iface, pPresentationParameters);
569 wined3d_mutex_lock();
571 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
572 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
573 localParameters.BackBufferFormat = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
574 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
575 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
576 localParameters.MultiSampleQuality = 0; /* d3d9 only */
577 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
578 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
579 localParameters.Windowed = pPresentationParameters->Windowed;
580 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
581 localParameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
582 localParameters.Flags = pPresentationParameters->Flags;
583 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
584 localParameters.PresentationInterval = pPresentationParameters->FullScreen_PresentationInterval;
585 localParameters.AutoRestoreDisplayMode = TRUE;
587 hr = wined3d_device_reset(This->wined3d_device, &localParameters, reset_enum_callback);
590 hr = wined3d_device_set_render_state(This->wined3d_device, WINED3DRS_POINTSIZE_MIN, 0);
597 wined3d_mutex_unlock();
602 static HRESULT WINAPI IDirect3DDevice8Impl_Present(IDirect3DDevice8 *iface, const RECT *pSourceRect,
603 const RECT *pDestRect, HWND hDestWindowOverride, const RGNDATA *pDirtyRegion)
605 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
608 TRACE("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p.\n",
609 iface, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
611 wined3d_mutex_lock();
612 hr = wined3d_device_present(This->wined3d_device, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
613 wined3d_mutex_unlock();
618 static HRESULT WINAPI IDirect3DDevice8Impl_GetBackBuffer(IDirect3DDevice8 *iface,
619 UINT BackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface8 **ppBackBuffer)
621 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
622 struct wined3d_surface *wined3d_surface = NULL;
625 TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
626 iface, BackBuffer, Type, ppBackBuffer);
628 wined3d_mutex_lock();
629 hr = wined3d_device_get_back_buffer(This->wined3d_device, 0,
630 BackBuffer, (WINED3DBACKBUFFER_TYPE)Type, &wined3d_surface);
631 if (SUCCEEDED(hr) && wined3d_surface && ppBackBuffer)
633 *ppBackBuffer = wined3d_surface_get_parent(wined3d_surface);
634 IDirect3DSurface8_AddRef(*ppBackBuffer);
635 wined3d_surface_decref(wined3d_surface);
637 wined3d_mutex_unlock();
642 static HRESULT WINAPI IDirect3DDevice8Impl_GetRasterStatus(IDirect3DDevice8 *iface,
643 D3DRASTER_STATUS *pRasterStatus)
645 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
648 TRACE("iface %p, raster_status %p.\n", iface, pRasterStatus);
650 wined3d_mutex_lock();
651 hr = wined3d_device_get_raster_status(This->wined3d_device, 0, (WINED3DRASTER_STATUS *)pRasterStatus);
652 wined3d_mutex_unlock();
657 static void WINAPI IDirect3DDevice8Impl_SetGammaRamp(IDirect3DDevice8 *iface, DWORD Flags,
658 const D3DGAMMARAMP *pRamp)
660 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
662 TRACE("iface %p, flags %#x, ramp %p.\n", iface, Flags, pRamp);
664 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
665 wined3d_mutex_lock();
666 wined3d_device_set_gamma_ramp(This->wined3d_device, 0, Flags, (const WINED3DGAMMARAMP *)pRamp);
667 wined3d_mutex_unlock();
670 static void WINAPI IDirect3DDevice8Impl_GetGammaRamp(IDirect3DDevice8 *iface, D3DGAMMARAMP *pRamp)
672 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
674 TRACE("iface %p, ramp %p.\n", iface, pRamp);
676 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
677 wined3d_mutex_lock();
678 wined3d_device_get_gamma_ramp(This->wined3d_device, 0, (WINED3DGAMMARAMP *)pRamp);
679 wined3d_mutex_unlock();
682 static HRESULT WINAPI IDirect3DDevice8Impl_CreateTexture(IDirect3DDevice8 *iface,
683 UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format,
684 D3DPOOL pool, IDirect3DTexture8 **texture)
686 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
687 IDirect3DTexture8Impl *object;
690 TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
691 iface, width, height, levels, usage, format, pool, texture);
693 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
696 ERR("Failed to allocate texture memory.\n");
697 return D3DERR_OUTOFVIDEOMEMORY;
700 hr = texture_init(object, This, width, height, levels, usage, format, pool);
703 WARN("Failed to initialize texture, hr %#x.\n", hr);
704 HeapFree(GetProcessHeap(), 0, object);
708 TRACE("Created texture %p.\n", object);
709 *texture = &object->IDirect3DTexture8_iface;
714 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVolumeTexture(IDirect3DDevice8 *iface,
715 UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format,
716 D3DPOOL pool, IDirect3DVolumeTexture8 **texture)
718 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
719 IDirect3DVolumeTexture8Impl *object;
722 TRACE("iface %p, width %u, height %u, depth %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
723 iface, width, height, depth, levels, usage, format, pool, texture);
725 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
728 ERR("Failed to allocate volume texture memory.\n");
729 return D3DERR_OUTOFVIDEOMEMORY;
732 hr = volumetexture_init(object, This, width, height, depth, levels, usage, format, pool);
735 WARN("Failed to initialize volume texture, hr %#x.\n", hr);
736 HeapFree(GetProcessHeap(), 0, object);
740 TRACE("Created volume texture %p.\n", object);
741 *texture = &object->IDirect3DVolumeTexture8_iface;
746 static HRESULT WINAPI IDirect3DDevice8Impl_CreateCubeTexture(IDirect3DDevice8 *iface, UINT edge_length,
747 UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool, IDirect3DCubeTexture8 **texture)
749 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
750 IDirect3DCubeTexture8Impl *object;
753 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
754 iface, edge_length, levels, usage, format, pool, texture);
756 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
759 ERR("Failed to allocate cube texture memory.\n");
760 return D3DERR_OUTOFVIDEOMEMORY;
763 hr = cubetexture_init(object, This, edge_length, levels, usage, format, pool);
766 WARN("Failed to initialize cube texture, hr %#x.\n", hr);
767 HeapFree(GetProcessHeap(), 0, object);
771 TRACE("Created cube texture %p.\n", object);
772 *texture = &object->IDirect3DCubeTexture8_iface;
777 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexBuffer(IDirect3DDevice8 *iface, UINT size,
778 DWORD usage, DWORD fvf, D3DPOOL pool, IDirect3DVertexBuffer8 **buffer)
780 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
781 IDirect3DVertexBuffer8Impl *object;
784 TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p.\n",
785 iface, size, usage, fvf, pool, buffer);
787 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
790 ERR("Failed to allocate buffer memory.\n");
791 return D3DERR_OUTOFVIDEOMEMORY;
794 hr = vertexbuffer_init(object, This, size, usage, fvf, pool);
797 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr);
798 HeapFree(GetProcessHeap(), 0, object);
802 TRACE("Created vertex buffer %p.\n", object);
803 *buffer = &object->IDirect3DVertexBuffer8_iface;
808 static HRESULT WINAPI IDirect3DDevice8Impl_CreateIndexBuffer(IDirect3DDevice8 *iface, UINT size,
809 DWORD usage, D3DFORMAT format, D3DPOOL pool, IDirect3DIndexBuffer8 **buffer)
811 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
812 IDirect3DIndexBuffer8Impl *object;
815 TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p.\n",
816 iface, size, usage, format, pool, buffer);
818 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
821 ERR("Failed to allocate buffer memory.\n");
822 return D3DERR_OUTOFVIDEOMEMORY;
825 hr = indexbuffer_init(object, This, size, usage, format, pool);
828 WARN("Failed to initialize index buffer, hr %#x.\n", hr);
829 HeapFree(GetProcessHeap(), 0, object);
833 TRACE("Created index buffer %p.\n", object);
834 *buffer = &object->IDirect3DIndexBuffer8_iface;
839 static HRESULT IDirect3DDevice8Impl_CreateSurface(IDirect3DDevice8Impl *device, UINT Width,
840 UINT Height, D3DFORMAT Format, BOOL Lockable, BOOL Discard, UINT Level,
841 IDirect3DSurface8 **ppSurface, UINT Usage, D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample,
842 DWORD MultisampleQuality)
844 IDirect3DSurface8Impl *object;
847 TRACE("device %p, width %u, height %u, format %#x, lockable %#x, discard %#x, level %u, surface %p,\n"
848 "\tusage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
849 device, Width, Height, Format, Lockable, Discard, Level, ppSurface,
850 Usage, Pool, MultiSample, MultisampleQuality);
852 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface8Impl));
855 FIXME("Failed to allocate surface memory.\n");
856 return D3DERR_OUTOFVIDEOMEMORY;
859 hr = surface_init(object, device, Width, Height, Format, Lockable, Discard, Level, Usage,
860 Pool, MultiSample, MultisampleQuality);
863 WARN("Failed to initialize surface, hr %#x.\n", hr);
864 HeapFree(GetProcessHeap(), 0, object);
868 TRACE("Created surface %p.\n", object);
869 *ppSurface = &object->IDirect3DSurface8_iface;
874 static HRESULT WINAPI IDirect3DDevice8Impl_CreateRenderTarget(IDirect3DDevice8 *iface, UINT Width,
875 UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, BOOL Lockable,
876 IDirect3DSurface8 **ppSurface)
878 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
881 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, lockable %#x, surface %p.\n",
882 iface, Width, Height, Format, MultiSample, Lockable, ppSurface);
884 hr = IDirect3DDevice8Impl_CreateSurface(This, Width, Height, Format, Lockable,
885 FALSE /* Discard */, 0 /* Level */, ppSurface, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT,
891 static HRESULT WINAPI IDirect3DDevice8Impl_CreateDepthStencilSurface(IDirect3DDevice8 *iface,
892 UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample,
893 IDirect3DSurface8 **ppSurface)
895 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
898 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, surface %p.\n",
899 iface, Width, Height, Format, MultiSample, ppSurface);
901 /* TODO: Verify that Discard is false */
902 hr = IDirect3DDevice8Impl_CreateSurface(This, Width, Height, Format, TRUE /* Lockable */, FALSE,
903 0 /* Level */, ppSurface, D3DUSAGE_DEPTHSTENCIL, D3DPOOL_DEFAULT, MultiSample, 0);
908 /* IDirect3DDevice8Impl::CreateImageSurface returns surface with pool type SYSTEMMEM */
909 static HRESULT WINAPI IDirect3DDevice8Impl_CreateImageSurface(IDirect3DDevice8 *iface, UINT Width,
910 UINT Height, D3DFORMAT Format, IDirect3DSurface8 **ppSurface)
912 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
915 TRACE("iface %p, width %u, height %u, format %#x, surface %p.\n",
916 iface, Width, Height, Format, ppSurface);
918 hr = IDirect3DDevice8Impl_CreateSurface(This, Width, Height, Format, TRUE /* Lockable */,
919 FALSE /* Discard */, 0 /* Level */, ppSurface, 0 /* Usage (undefined/none) */,
920 D3DPOOL_SYSTEMMEM, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
925 static HRESULT WINAPI IDirect3DDevice8Impl_CopyRects(IDirect3DDevice8 *iface,
926 IDirect3DSurface8 *pSourceSurface, const RECT *pSourceRects, UINT cRects,
927 IDirect3DSurface8 *pDestinationSurface, const POINT *pDestPoints)
929 IDirect3DSurface8Impl *Source = unsafe_impl_from_IDirect3DSurface8(pSourceSurface);
930 IDirect3DSurface8Impl *Dest = unsafe_impl_from_IDirect3DSurface8(pDestinationSurface);
931 enum wined3d_format_id srcFormat, destFormat;
932 struct wined3d_resource_desc wined3d_desc;
933 struct wined3d_resource *wined3d_resource;
935 TRACE("iface %p, src_surface %p, src_rects %p, rect_count %u, dst_surface %p, dst_points %p.\n",
936 iface, pSourceSurface, pSourceRects, cRects, pDestinationSurface, pDestPoints);
938 /* Check that the source texture is in WINED3DPOOL_SYSTEMMEM and the
939 * destination texture is in WINED3DPOOL_DEFAULT. */
941 wined3d_mutex_lock();
942 wined3d_resource = wined3d_surface_get_resource(Source->wined3d_surface);
943 wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
944 srcFormat = wined3d_desc.format;
946 wined3d_resource = wined3d_surface_get_resource(Dest->wined3d_surface);
947 wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
948 destFormat = wined3d_desc.format;
950 /* Check that the source and destination formats match */
951 if (srcFormat != destFormat && WINED3DFMT_UNKNOWN != destFormat)
953 WARN("Source %p format must match the dest %p format, returning D3DERR_INVALIDCALL.\n",
954 pSourceSurface, pDestinationSurface);
955 wined3d_mutex_unlock();
956 return D3DERR_INVALIDCALL;
958 else if (WINED3DFMT_UNKNOWN == destFormat)
960 TRACE("(%p) : Converting destination surface from WINED3DFMT_UNKNOWN to the source format\n", iface);
961 wined3d_surface_set_format(Dest->wined3d_surface, srcFormat);
964 /* Quick if complete copy ... */
965 if (!cRects && !pSourceRects && !pDestPoints)
967 wined3d_surface_bltfast(Dest->wined3d_surface, 0, 0,
968 Source->wined3d_surface, NULL, WINEDDBLTFAST_NOCOLORKEY);
973 /* Copy rect by rect */
974 if (pSourceRects && pDestPoints)
976 for (i = 0; i < cRects; ++i)
978 wined3d_surface_bltfast(Dest->wined3d_surface, pDestPoints[i].x, pDestPoints[i].y,
979 Source->wined3d_surface, &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY);
984 for (i = 0; i < cRects; ++i)
986 wined3d_surface_bltfast(Dest->wined3d_surface, 0, 0,
987 Source->wined3d_surface, &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY);
991 wined3d_mutex_unlock();
996 static HRESULT WINAPI IDirect3DDevice8Impl_UpdateTexture(IDirect3DDevice8 *iface,
997 IDirect3DBaseTexture8 *src_texture, IDirect3DBaseTexture8 *dst_texture)
999 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1002 TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface, src_texture, dst_texture);
1004 wined3d_mutex_lock();
1005 hr = wined3d_device_update_texture(This->wined3d_device,
1006 ((IDirect3DBaseTexture8Impl *)src_texture)->wined3d_texture,
1007 ((IDirect3DBaseTexture8Impl *)dst_texture)->wined3d_texture);
1008 wined3d_mutex_unlock();
1013 static HRESULT WINAPI IDirect3DDevice8Impl_GetFrontBuffer(IDirect3DDevice8 *iface,
1014 IDirect3DSurface8 *pDestSurface)
1016 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1017 IDirect3DSurface8Impl *destSurface = unsafe_impl_from_IDirect3DSurface8(pDestSurface);
1020 TRACE("iface %p, dst_surface %p.\n", iface, pDestSurface);
1022 if (pDestSurface == NULL) {
1023 WARN("(%p) : Caller passed NULL as pDestSurface returning D3DERR_INVALIDCALL\n", This);
1024 return D3DERR_INVALIDCALL;
1027 wined3d_mutex_lock();
1028 hr = wined3d_device_get_front_buffer_data(This->wined3d_device, 0, destSurface->wined3d_surface);
1029 wined3d_mutex_unlock();
1034 static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderTarget(IDirect3DDevice8 *iface,
1035 IDirect3DSurface8 *pRenderTarget, IDirect3DSurface8 *pNewZStencil)
1037 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1038 IDirect3DSurface8Impl *pSurface = unsafe_impl_from_IDirect3DSurface8(pRenderTarget);
1039 IDirect3DSurface8Impl *pZSurface = unsafe_impl_from_IDirect3DSurface8(pNewZStencil);
1040 struct wined3d_surface *original_ds = NULL;
1043 TRACE("iface %p, render_target %p, depth_stencil %p.\n", iface, pRenderTarget, pNewZStencil);
1045 wined3d_mutex_lock();
1049 struct wined3d_resource_desc ds_desc, rt_desc;
1050 struct wined3d_resource *wined3d_resource;
1051 struct wined3d_surface *original_rt = NULL;
1053 /* If no render target is passed in check the size against the current RT */
1056 hr = wined3d_device_get_render_target(This->wined3d_device, 0, &original_rt);
1057 if (FAILED(hr) || !original_rt)
1059 wined3d_mutex_unlock();
1062 wined3d_resource = wined3d_surface_get_resource(original_rt);
1063 wined3d_surface_decref(original_rt);
1066 wined3d_resource = wined3d_surface_get_resource(pSurface->wined3d_surface);
1067 wined3d_resource_get_desc(wined3d_resource, &rt_desc);
1069 wined3d_resource = wined3d_surface_get_resource(pZSurface->wined3d_surface);
1070 wined3d_resource_get_desc(wined3d_resource, &ds_desc);
1072 if (ds_desc.width < rt_desc.width || ds_desc.height < rt_desc.height)
1074 WARN("Depth stencil is smaller than the render target, returning D3DERR_INVALIDCALL\n");
1075 wined3d_mutex_unlock();
1076 return D3DERR_INVALIDCALL;
1080 hr = wined3d_device_get_depth_stencil(This->wined3d_device, &original_ds);
1081 if (hr == WINED3D_OK || hr == WINED3DERR_NOTFOUND)
1083 hr = wined3d_device_set_depth_stencil(This->wined3d_device, pZSurface ? pZSurface->wined3d_surface : NULL);
1084 if (SUCCEEDED(hr) && pRenderTarget)
1086 hr = wined3d_device_set_render_target(This->wined3d_device, 0, pSurface->wined3d_surface, TRUE);
1088 wined3d_device_set_depth_stencil(This->wined3d_device, original_ds);
1092 wined3d_surface_decref(original_ds);
1094 wined3d_mutex_unlock();
1099 static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderTarget(IDirect3DDevice8 *iface,
1100 IDirect3DSurface8 **ppRenderTarget)
1102 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1103 struct wined3d_surface *wined3d_surface;
1106 TRACE("iface %p, render_target %p.\n", iface, ppRenderTarget);
1108 if (ppRenderTarget == NULL) {
1109 return D3DERR_INVALIDCALL;
1112 wined3d_mutex_lock();
1113 hr = wined3d_device_get_render_target(This->wined3d_device, 0, &wined3d_surface);
1114 if (SUCCEEDED(hr) && wined3d_surface)
1116 *ppRenderTarget = wined3d_surface_get_parent(wined3d_surface);
1117 IDirect3DSurface8_AddRef(*ppRenderTarget);
1118 wined3d_surface_decref(wined3d_surface);
1122 FIXME("Call to IWineD3DDevice_GetRenderTarget failed\n");
1123 *ppRenderTarget = NULL;
1125 wined3d_mutex_unlock();
1130 static HRESULT WINAPI IDirect3DDevice8Impl_GetDepthStencilSurface(IDirect3DDevice8 *iface,
1131 IDirect3DSurface8 **ppZStencilSurface)
1133 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1134 struct wined3d_surface *wined3d_surface;
1137 TRACE("iface %p, depth_stencil %p.\n", iface, ppZStencilSurface);
1139 if(ppZStencilSurface == NULL){
1140 return D3DERR_INVALIDCALL;
1143 wined3d_mutex_lock();
1144 hr = wined3d_device_get_depth_stencil(This->wined3d_device, &wined3d_surface);
1147 *ppZStencilSurface = wined3d_surface_get_parent(wined3d_surface);
1148 IDirect3DSurface8_AddRef(*ppZStencilSurface);
1149 wined3d_surface_decref(wined3d_surface);
1153 if (hr != WINED3DERR_NOTFOUND)
1154 FIXME("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr);
1155 *ppZStencilSurface = NULL;
1157 wined3d_mutex_unlock();
1162 static HRESULT WINAPI IDirect3DDevice8Impl_BeginScene(IDirect3DDevice8 *iface)
1164 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1167 TRACE("iface %p.\n", iface);
1169 wined3d_mutex_lock();
1170 hr = wined3d_device_begin_scene(This->wined3d_device);
1171 wined3d_mutex_unlock();
1176 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice8Impl_EndScene(IDirect3DDevice8 *iface)
1178 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1181 TRACE("iface %p.\n", iface);
1183 wined3d_mutex_lock();
1184 hr = wined3d_device_end_scene(This->wined3d_device);
1185 wined3d_mutex_unlock();
1190 static HRESULT WINAPI IDirect3DDevice8Impl_Clear(IDirect3DDevice8 *iface, DWORD Count,
1191 const D3DRECT *pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil)
1193 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1196 TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
1197 iface, Count, pRects, Flags, Color, Z, Stencil);
1199 wined3d_mutex_lock();
1200 hr = wined3d_device_clear(This->wined3d_device, Count, (const RECT *)pRects, Flags, Color, Z, Stencil);
1201 wined3d_mutex_unlock();
1206 static HRESULT WINAPI IDirect3DDevice8Impl_SetTransform(IDirect3DDevice8 *iface,
1207 D3DTRANSFORMSTATETYPE State, const D3DMATRIX *lpMatrix)
1209 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1212 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, lpMatrix);
1214 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1215 wined3d_mutex_lock();
1216 hr = wined3d_device_set_transform(This->wined3d_device, State, (const WINED3DMATRIX *)lpMatrix);
1217 wined3d_mutex_unlock();
1222 static HRESULT WINAPI IDirect3DDevice8Impl_GetTransform(IDirect3DDevice8 *iface,
1223 D3DTRANSFORMSTATETYPE State, D3DMATRIX *pMatrix)
1225 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1228 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
1230 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1231 wined3d_mutex_lock();
1232 hr = wined3d_device_get_transform(This->wined3d_device, State, (WINED3DMATRIX *)pMatrix);
1233 wined3d_mutex_unlock();
1238 static HRESULT WINAPI IDirect3DDevice8Impl_MultiplyTransform(IDirect3DDevice8 *iface,
1239 D3DTRANSFORMSTATETYPE State, const D3DMATRIX *pMatrix)
1241 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1244 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
1246 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1247 wined3d_mutex_lock();
1248 hr = wined3d_device_multiply_transform(This->wined3d_device, State, (const WINED3DMATRIX *)pMatrix);
1249 wined3d_mutex_unlock();
1254 static HRESULT WINAPI IDirect3DDevice8Impl_SetViewport(IDirect3DDevice8 *iface,
1255 const D3DVIEWPORT8 *pViewport)
1257 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1260 TRACE("iface %p, viewport %p.\n", iface, pViewport);
1262 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
1263 wined3d_mutex_lock();
1264 hr = wined3d_device_set_viewport(This->wined3d_device, (const WINED3DVIEWPORT *)pViewport);
1265 wined3d_mutex_unlock();
1270 static HRESULT WINAPI IDirect3DDevice8Impl_GetViewport(IDirect3DDevice8 *iface,
1271 D3DVIEWPORT8 *pViewport)
1273 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1276 TRACE("iface %p, viewport %p.\n", iface, pViewport);
1278 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
1279 wined3d_mutex_lock();
1280 hr = wined3d_device_get_viewport(This->wined3d_device, (WINED3DVIEWPORT *)pViewport);
1281 wined3d_mutex_unlock();
1286 static HRESULT WINAPI IDirect3DDevice8Impl_SetMaterial(IDirect3DDevice8 *iface,
1287 const D3DMATERIAL8 *pMaterial)
1289 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1292 TRACE("iface %p, material %p.\n", iface, pMaterial);
1294 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
1295 wined3d_mutex_lock();
1296 hr = wined3d_device_set_material(This->wined3d_device, (const WINED3DMATERIAL *)pMaterial);
1297 wined3d_mutex_unlock();
1302 static HRESULT WINAPI IDirect3DDevice8Impl_GetMaterial(IDirect3DDevice8 *iface,
1303 D3DMATERIAL8 *pMaterial)
1305 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1308 TRACE("iface %p, material %p.\n", iface, pMaterial);
1310 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
1311 wined3d_mutex_lock();
1312 hr = wined3d_device_get_material(This->wined3d_device, (WINED3DMATERIAL *)pMaterial);
1313 wined3d_mutex_unlock();
1318 static HRESULT WINAPI IDirect3DDevice8Impl_SetLight(IDirect3DDevice8 *iface, DWORD Index,
1319 const D3DLIGHT8 *pLight)
1321 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1324 TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
1326 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1327 wined3d_mutex_lock();
1328 hr = wined3d_device_set_light(This->wined3d_device, Index, (const WINED3DLIGHT *)pLight);
1329 wined3d_mutex_unlock();
1334 static HRESULT WINAPI IDirect3DDevice8Impl_GetLight(IDirect3DDevice8 *iface, DWORD Index,
1337 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1340 TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
1342 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1343 wined3d_mutex_lock();
1344 hr = wined3d_device_get_light(This->wined3d_device, Index, (WINED3DLIGHT *)pLight);
1345 wined3d_mutex_unlock();
1350 static HRESULT WINAPI IDirect3DDevice8Impl_LightEnable(IDirect3DDevice8 *iface, DWORD Index,
1353 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1356 TRACE("iface %p, index %u, enable %#x.\n", iface, Index, Enable);
1358 wined3d_mutex_lock();
1359 hr = wined3d_device_set_light_enable(This->wined3d_device, Index, Enable);
1360 wined3d_mutex_unlock();
1365 static HRESULT WINAPI IDirect3DDevice8Impl_GetLightEnable(IDirect3DDevice8 *iface, DWORD Index,
1368 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1371 TRACE("iface %p, index %u, enable %p.\n", iface, Index, pEnable);
1373 wined3d_mutex_lock();
1374 hr = wined3d_device_get_light_enable(This->wined3d_device, Index, pEnable);
1375 wined3d_mutex_unlock();
1380 static HRESULT WINAPI IDirect3DDevice8Impl_SetClipPlane(IDirect3DDevice8 *iface, DWORD Index,
1381 const float *pPlane)
1383 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1386 TRACE("iface %p, index %u, plane %p.\n", iface, Index, pPlane);
1388 wined3d_mutex_lock();
1389 hr = wined3d_device_set_clip_plane(This->wined3d_device, Index, pPlane);
1390 wined3d_mutex_unlock();
1395 static HRESULT WINAPI IDirect3DDevice8Impl_GetClipPlane(IDirect3DDevice8 *iface, DWORD Index,
1398 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1401 TRACE("iface %p, index %u, plane %p.\n", iface, Index, pPlane);
1403 wined3d_mutex_lock();
1404 hr = wined3d_device_get_clip_plane(This->wined3d_device, Index, pPlane);
1405 wined3d_mutex_unlock();
1410 static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderState(IDirect3DDevice8 *iface,
1411 D3DRENDERSTATETYPE State, DWORD Value)
1413 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1416 TRACE("iface %p, state %#x, value %#x.\n", iface, State, Value);
1418 wined3d_mutex_lock();
1422 hr = wined3d_device_set_render_state(This->wined3d_device, WINED3DRS_DEPTHBIAS, Value);
1426 hr = wined3d_device_set_render_state(This->wined3d_device, State, Value);
1428 wined3d_mutex_unlock();
1433 static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderState(IDirect3DDevice8 *iface,
1434 D3DRENDERSTATETYPE State, DWORD *pValue)
1436 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1439 TRACE("iface %p, state %#x, value %p.\n", iface, State, pValue);
1441 wined3d_mutex_lock();
1445 hr = wined3d_device_get_render_state(This->wined3d_device, WINED3DRS_DEPTHBIAS, pValue);
1449 hr = wined3d_device_get_render_state(This->wined3d_device, State, pValue);
1451 wined3d_mutex_unlock();
1456 static HRESULT WINAPI IDirect3DDevice8Impl_BeginStateBlock(IDirect3DDevice8 *iface)
1458 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1461 TRACE("iface %p.\n", iface);
1463 wined3d_mutex_lock();
1464 hr = wined3d_device_begin_stateblock(This->wined3d_device);
1465 wined3d_mutex_unlock();
1470 static HRESULT WINAPI IDirect3DDevice8Impl_EndStateBlock(IDirect3DDevice8 *iface, DWORD *pToken)
1472 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1473 struct wined3d_stateblock *stateblock;
1476 TRACE("iface %p, token %p.\n", iface, pToken);
1478 /* Tell wineD3D to endstateblock before anything else (in case we run out
1479 * of memory later and cause locking problems)
1481 wined3d_mutex_lock();
1482 hr = wined3d_device_end_stateblock(This->wined3d_device, &stateblock);
1485 WARN("IWineD3DDevice_EndStateBlock returned an error\n");
1486 wined3d_mutex_unlock();
1490 *pToken = d3d8_allocate_handle(&This->handle_table, stateblock, D3D8_HANDLE_SB);
1491 wined3d_mutex_unlock();
1493 if (*pToken == D3D8_INVALID_HANDLE)
1495 ERR("Failed to create a handle\n");
1496 wined3d_mutex_lock();
1497 wined3d_stateblock_decref(stateblock);
1498 wined3d_mutex_unlock();
1503 TRACE("Returning %#x (%p).\n", *pToken, stateblock);
1508 static HRESULT WINAPI IDirect3DDevice8Impl_ApplyStateBlock(IDirect3DDevice8 *iface, DWORD Token)
1510 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1511 struct wined3d_stateblock *stateblock;
1514 TRACE("iface %p, token %#x.\n", iface, Token);
1516 if (!Token) return D3D_OK;
1518 wined3d_mutex_lock();
1519 stateblock = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1522 WARN("Invalid handle (%#x) passed.\n", Token);
1523 wined3d_mutex_unlock();
1524 return D3DERR_INVALIDCALL;
1526 hr = wined3d_stateblock_apply(stateblock);
1527 wined3d_mutex_unlock();
1532 static HRESULT WINAPI IDirect3DDevice8Impl_CaptureStateBlock(IDirect3DDevice8 *iface, DWORD Token)
1534 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1535 struct wined3d_stateblock *stateblock;
1538 TRACE("iface %p, token %#x.\n", iface, Token);
1540 wined3d_mutex_lock();
1541 stateblock = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1544 WARN("Invalid handle (%#x) passed.\n", Token);
1545 wined3d_mutex_unlock();
1546 return D3DERR_INVALIDCALL;
1548 hr = wined3d_stateblock_capture(stateblock);
1549 wined3d_mutex_unlock();
1554 static HRESULT WINAPI IDirect3DDevice8Impl_DeleteStateBlock(IDirect3DDevice8 *iface, DWORD Token)
1556 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1557 struct wined3d_stateblock *stateblock;
1559 TRACE("iface %p, token %#x.\n", iface, Token);
1561 wined3d_mutex_lock();
1562 stateblock = d3d8_free_handle(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1566 WARN("Invalid handle (%#x) passed.\n", Token);
1567 wined3d_mutex_unlock();
1568 return D3DERR_INVALIDCALL;
1571 if (wined3d_stateblock_decref(stateblock))
1573 ERR("Stateblock %p has references left, this shouldn't happen.\n", stateblock);
1575 wined3d_mutex_unlock();
1580 static HRESULT WINAPI IDirect3DDevice8Impl_CreateStateBlock(IDirect3DDevice8 *iface,
1581 D3DSTATEBLOCKTYPE Type, DWORD *handle)
1583 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1584 struct wined3d_stateblock *stateblock;
1587 TRACE("iface %p, type %#x, handle %p.\n", iface, Type, handle);
1589 if (Type != D3DSBT_ALL
1590 && Type != D3DSBT_PIXELSTATE
1591 && Type != D3DSBT_VERTEXSTATE)
1593 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL\n");
1594 return D3DERR_INVALIDCALL;
1597 wined3d_mutex_lock();
1598 hr = wined3d_stateblock_create(This->wined3d_device, (WINED3DSTATEBLOCKTYPE)Type, &stateblock);
1601 wined3d_mutex_unlock();
1602 ERR("IWineD3DDevice_CreateStateBlock failed, hr %#x\n", hr);
1606 *handle = d3d8_allocate_handle(&This->handle_table, stateblock, D3D8_HANDLE_SB);
1607 wined3d_mutex_unlock();
1609 if (*handle == D3D8_INVALID_HANDLE)
1611 ERR("Failed to allocate a handle.\n");
1612 wined3d_mutex_lock();
1613 wined3d_stateblock_decref(stateblock);
1614 wined3d_mutex_unlock();
1619 TRACE("Returning %#x (%p).\n", *handle, stateblock);
1624 static HRESULT WINAPI IDirect3DDevice8Impl_SetClipStatus(IDirect3DDevice8 *iface,
1625 const D3DCLIPSTATUS8 *pClipStatus)
1627 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1630 TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
1631 /* FIXME: Verify that D3DCLIPSTATUS8 ~= WINED3DCLIPSTATUS */
1633 wined3d_mutex_lock();
1634 hr = wined3d_device_set_clip_status(This->wined3d_device, (const WINED3DCLIPSTATUS *)pClipStatus);
1635 wined3d_mutex_unlock();
1640 static HRESULT WINAPI IDirect3DDevice8Impl_GetClipStatus(IDirect3DDevice8 *iface,
1641 D3DCLIPSTATUS8 *pClipStatus)
1643 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1646 TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
1648 wined3d_mutex_lock();
1649 hr = wined3d_device_get_clip_status(This->wined3d_device, (WINED3DCLIPSTATUS *)pClipStatus);
1650 wined3d_mutex_unlock();
1655 static HRESULT WINAPI IDirect3DDevice8Impl_GetTexture(IDirect3DDevice8 *iface,
1656 DWORD Stage, IDirect3DBaseTexture8 **ppTexture)
1658 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1659 struct wined3d_texture *wined3d_texture;
1662 TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, ppTexture);
1664 if(ppTexture == NULL){
1665 return D3DERR_INVALIDCALL;
1668 wined3d_mutex_lock();
1669 hr = wined3d_device_get_texture(This->wined3d_device, Stage, &wined3d_texture);
1672 WARN("Failed to get texture for stage %u, hr %#x.\n", Stage, hr);
1673 wined3d_mutex_unlock();
1678 if (wined3d_texture)
1680 *ppTexture = wined3d_texture_get_parent(wined3d_texture);
1681 IDirect3DBaseTexture8_AddRef(*ppTexture);
1682 wined3d_texture_decref(wined3d_texture);
1688 wined3d_mutex_unlock();
1693 static HRESULT WINAPI IDirect3DDevice8Impl_SetTexture(IDirect3DDevice8 *iface, DWORD Stage,
1694 IDirect3DBaseTexture8 *pTexture)
1696 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1699 TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, pTexture);
1701 wined3d_mutex_lock();
1702 hr = wined3d_device_set_texture(This->wined3d_device, Stage,
1703 pTexture ? ((IDirect3DBaseTexture8Impl *)pTexture)->wined3d_texture : NULL);
1704 wined3d_mutex_unlock();
1709 static const struct tss_lookup
1716 {FALSE, WINED3DTSS_FORCE_DWORD}, /* 0, unused */
1717 {FALSE, WINED3DTSS_COLOROP}, /* 1, D3DTSS_COLOROP */
1718 {FALSE, WINED3DTSS_COLORARG1}, /* 2, D3DTSS_COLORARG1 */
1719 {FALSE, WINED3DTSS_COLORARG2}, /* 3, D3DTSS_COLORARG2 */
1720 {FALSE, WINED3DTSS_ALPHAOP}, /* 4, D3DTSS_ALPHAOP */
1721 {FALSE, WINED3DTSS_ALPHAARG1}, /* 5, D3DTSS_ALPHAARG1 */
1722 {FALSE, WINED3DTSS_ALPHAARG2}, /* 6, D3DTSS_ALPHAARG2 */
1723 {FALSE, WINED3DTSS_BUMPENVMAT00}, /* 7, D3DTSS_BUMPENVMAT00 */
1724 {FALSE, WINED3DTSS_BUMPENVMAT01}, /* 8, D3DTSS_BUMPENVMAT01 */
1725 {FALSE, WINED3DTSS_BUMPENVMAT10}, /* 9, D3DTSS_BUMPENVMAT10 */
1726 {FALSE, WINED3DTSS_BUMPENVMAT11}, /* 10, D3DTSS_BUMPENVMAT11 */
1727 {FALSE, WINED3DTSS_TEXCOORDINDEX}, /* 11, D3DTSS_TEXCOORDINDEX */
1728 {FALSE, WINED3DTSS_FORCE_DWORD}, /* 12, unused */
1729 {TRUE, WINED3DSAMP_ADDRESSU}, /* 13, D3DTSS_ADDRESSU */
1730 {TRUE, WINED3DSAMP_ADDRESSV}, /* 14, D3DTSS_ADDRESSV */
1731 {TRUE, WINED3DSAMP_BORDERCOLOR}, /* 15, D3DTSS_BORDERCOLOR */
1732 {TRUE, WINED3DSAMP_MAGFILTER}, /* 16, D3DTSS_MAGFILTER */
1733 {TRUE, WINED3DSAMP_MINFILTER}, /* 17, D3DTSS_MINFILTER */
1734 {TRUE, WINED3DSAMP_MIPFILTER}, /* 18, D3DTSS_MIPFILTER */
1735 {TRUE, WINED3DSAMP_MIPMAPLODBIAS}, /* 19, D3DTSS_MIPMAPLODBIAS */
1736 {TRUE, WINED3DSAMP_MAXMIPLEVEL}, /* 20, D3DTSS_MAXMIPLEVEL */
1737 {TRUE, WINED3DSAMP_MAXANISOTROPY}, /* 21, D3DTSS_MAXANISOTROPY */
1738 {FALSE, WINED3DTSS_BUMPENVLSCALE}, /* 22, D3DTSS_BUMPENVLSCALE */
1739 {FALSE, WINED3DTSS_BUMPENVLOFFSET}, /* 23, D3DTSS_BUMPENVLOFFSET */
1740 {FALSE, WINED3DTSS_TEXTURETRANSFORMFLAGS}, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1741 {TRUE, WINED3DSAMP_ADDRESSW}, /* 25, D3DTSS_ADDRESSW */
1742 {FALSE, WINED3DTSS_COLORARG0}, /* 26, D3DTSS_COLORARG0 */
1743 {FALSE, WINED3DTSS_ALPHAARG0}, /* 27, D3DTSS_ALPHAARG0 */
1744 {FALSE, WINED3DTSS_RESULTARG}, /* 28, D3DTSS_RESULTARG */
1747 static HRESULT WINAPI IDirect3DDevice8Impl_GetTextureStageState(IDirect3DDevice8 *iface,
1748 DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD *pValue)
1750 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1751 const struct tss_lookup *l;
1754 TRACE("iface %p, stage %u, state %#x, value %p.\n", iface, Stage, Type, pValue);
1756 if (Type >= sizeof(tss_lookup) / sizeof(*tss_lookup))
1758 WARN("Invalid Type %#x passed.\n", Type);
1762 l = &tss_lookup[Type];
1764 wined3d_mutex_lock();
1765 if (l->sampler_state)
1766 hr = wined3d_device_get_sampler_state(This->wined3d_device, Stage, l->state, pValue);
1768 hr = wined3d_device_get_texture_stage_state(This->wined3d_device, Stage, l->state, pValue);
1769 wined3d_mutex_unlock();
1774 static HRESULT WINAPI IDirect3DDevice8Impl_SetTextureStageState(IDirect3DDevice8 *iface,
1775 DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value)
1777 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1778 const struct tss_lookup *l;
1781 TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface, Stage, Type, Value);
1783 if (Type >= sizeof(tss_lookup) / sizeof(*tss_lookup))
1785 WARN("Invalid Type %#x passed.\n", Type);
1789 l = &tss_lookup[Type];
1791 wined3d_mutex_lock();
1792 if (l->sampler_state)
1793 hr = wined3d_device_set_sampler_state(This->wined3d_device, Stage, l->state, Value);
1795 hr = wined3d_device_set_texture_stage_state(This->wined3d_device, Stage, l->state, Value);
1796 wined3d_mutex_unlock();
1801 static HRESULT WINAPI IDirect3DDevice8Impl_ValidateDevice(IDirect3DDevice8 *iface,
1804 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1807 TRACE("iface %p, pass_count %p.\n", iface, pNumPasses);
1809 wined3d_mutex_lock();
1810 hr = wined3d_device_validate_device(This->wined3d_device, pNumPasses);
1811 wined3d_mutex_unlock();
1816 static HRESULT WINAPI IDirect3DDevice8Impl_GetInfo(IDirect3DDevice8 *iface,
1817 DWORD info_id, void *info, DWORD info_size)
1819 FIXME("iface %p, info_id %#x, info %p, info_size %u stub!\n", iface, info_id, info, info_size);
1824 static HRESULT WINAPI IDirect3DDevice8Impl_SetPaletteEntries(IDirect3DDevice8 *iface,
1825 UINT PaletteNumber, const PALETTEENTRY *pEntries)
1827 FIXME("iface %p, palette_idx %u, entries %p unimplemented\n", iface, PaletteNumber, pEntries);
1829 /* GPUs stopped supporting palettized textures with the Shader Model 1 generation. Wined3d
1830 * does not have a d3d8/9-style palette API */
1832 return D3DERR_INVALIDCALL;
1835 static HRESULT WINAPI IDirect3DDevice8Impl_GetPaletteEntries(IDirect3DDevice8 *iface,
1836 UINT PaletteNumber, PALETTEENTRY *pEntries)
1838 FIXME("iface %p, palette_idx %u, entries %p unimplemented.\n", iface, PaletteNumber, pEntries);
1840 return D3DERR_INVALIDCALL;
1843 static HRESULT WINAPI IDirect3DDevice8Impl_SetCurrentTexturePalette(IDirect3DDevice8 *iface,
1846 FIXME("iface %p, palette_idx %u unimplemented.\n", iface, PaletteNumber);
1848 return D3DERR_INVALIDCALL;
1851 static HRESULT WINAPI IDirect3DDevice8Impl_GetCurrentTexturePalette(IDirect3DDevice8 *iface,
1852 UINT *PaletteNumber)
1854 FIXME("iface %p, palette_idx %p unimplemented.\n", iface, PaletteNumber);
1856 return D3DERR_INVALIDCALL;
1859 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitive(IDirect3DDevice8 *iface,
1860 D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount)
1862 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1865 TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
1866 iface, PrimitiveType, StartVertex, PrimitiveCount);
1868 wined3d_mutex_lock();
1869 wined3d_device_set_primitive_type(This->wined3d_device, PrimitiveType);
1870 hr = wined3d_device_draw_primitive(This->wined3d_device, StartVertex,
1871 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount));
1872 wined3d_mutex_unlock();
1877 static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitive(IDirect3DDevice8 *iface,
1878 D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertices, UINT startIndex,
1881 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1884 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, vertex_count %u, start_idx %u, primitive_count %u.\n",
1885 iface, PrimitiveType, MinVertexIndex, NumVertices, startIndex, primCount);
1887 wined3d_mutex_lock();
1888 wined3d_device_set_primitive_type(This->wined3d_device, PrimitiveType);
1889 hr = wined3d_device_draw_indexed_primitive(This->wined3d_device, startIndex,
1890 vertex_count_from_primitive_count(PrimitiveType, primCount));
1891 wined3d_mutex_unlock();
1896 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitiveUP(IDirect3DDevice8 *iface,
1897 D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, const void *pVertexStreamZeroData,
1898 UINT VertexStreamZeroStride)
1900 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1903 TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
1904 iface, PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride);
1906 wined3d_mutex_lock();
1907 wined3d_device_set_primitive_type(This->wined3d_device, PrimitiveType);
1908 hr = wined3d_device_draw_primitive_up(This->wined3d_device,
1909 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount),
1910 pVertexStreamZeroData, VertexStreamZeroStride);
1911 wined3d_mutex_unlock();
1916 static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitiveUP(IDirect3DDevice8 *iface,
1917 D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertexIndices,
1918 UINT PrimitiveCount, const void *pIndexData, D3DFORMAT IndexDataFormat,
1919 const void *pVertexStreamZeroData, UINT VertexStreamZeroStride)
1921 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1924 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, index_count %u, primitive_count %u,\n"
1925 "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
1926 iface, PrimitiveType, MinVertexIndex, NumVertexIndices, PrimitiveCount,
1927 pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride);
1929 wined3d_mutex_lock();
1930 wined3d_device_set_primitive_type(This->wined3d_device, PrimitiveType);
1931 hr = wined3d_device_draw_indexed_primitive_up(This->wined3d_device,
1932 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount), pIndexData,
1933 wined3dformat_from_d3dformat(IndexDataFormat), pVertexStreamZeroData, VertexStreamZeroStride);
1934 wined3d_mutex_unlock();
1939 static HRESULT WINAPI IDirect3DDevice8Impl_ProcessVertices(IDirect3DDevice8 *iface,
1940 UINT SrcStartIndex, UINT DestIndex, UINT VertexCount, IDirect3DVertexBuffer8 *pDestBuffer,
1943 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1944 IDirect3DVertexBuffer8Impl *dest = unsafe_impl_from_IDirect3DVertexBuffer8(pDestBuffer);
1947 TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, flags %#x.\n",
1948 iface, SrcStartIndex, DestIndex, VertexCount, pDestBuffer, Flags);
1950 wined3d_mutex_lock();
1951 hr = wined3d_device_process_vertices(This->wined3d_device, SrcStartIndex, DestIndex,
1952 VertexCount, dest->wineD3DVertexBuffer, NULL, Flags, dest->fvf);
1953 wined3d_mutex_unlock();
1958 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexShader(IDirect3DDevice8 *iface,
1959 const DWORD *declaration, const DWORD *byte_code, DWORD *shader, DWORD usage)
1961 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1962 IDirect3DVertexShader8Impl *object;
1963 DWORD shader_handle;
1967 TRACE("iface %p, declaration %p, byte_code %p, shader %p, usage %#x.\n",
1968 iface, declaration, byte_code, shader, usage);
1970 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1973 ERR("Failed to allocate vertex shader memory.\n");
1975 return E_OUTOFMEMORY;
1978 wined3d_mutex_lock();
1979 handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_VS);
1980 wined3d_mutex_unlock();
1981 if (handle == D3D8_INVALID_HANDLE)
1983 ERR("Failed to allocate vertex shader handle.\n");
1984 HeapFree(GetProcessHeap(), 0, object);
1986 return E_OUTOFMEMORY;
1989 shader_handle = handle + VS_HIGHESTFIXEDFXF + 1;
1991 hr = vertexshader_init(object, This, declaration, byte_code, shader_handle, usage);
1994 WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
1995 wined3d_mutex_lock();
1996 d3d8_free_handle(&This->handle_table, handle, D3D8_HANDLE_VS);
1997 wined3d_mutex_unlock();
1998 HeapFree(GetProcessHeap(), 0, object);
2003 TRACE("Created vertex shader %p (handle %#x).\n", object, shader_handle);
2004 *shader = shader_handle;
2009 static IDirect3DVertexDeclaration8Impl *IDirect3DDevice8Impl_FindDecl(IDirect3DDevice8Impl *This, DWORD fvf)
2011 IDirect3DVertexDeclaration8Impl *d3d8_declaration;
2013 int p, low, high; /* deliberately signed */
2014 struct FvfToDecl *convertedDecls = This->decls;
2016 TRACE("Searching for declaration for fvf %08x... ", fvf);
2019 high = This->numConvertedDecls - 1;
2020 while(low <= high) {
2021 p = (low + high) >> 1;
2023 if(convertedDecls[p].fvf == fvf) {
2024 TRACE("found %p\n", convertedDecls[p].decl);
2025 return (IDirect3DVertexDeclaration8Impl *)convertedDecls[p].decl;
2026 } else if(convertedDecls[p].fvf < fvf) {
2032 TRACE("not found. Creating and inserting at position %d.\n", low);
2034 d3d8_declaration = HeapAlloc(GetProcessHeap(), 0, sizeof(*d3d8_declaration));
2035 if (!d3d8_declaration)
2037 ERR("Memory allocation failed.\n");
2041 hr = vertexdeclaration_init_fvf(d3d8_declaration, This, fvf);
2044 WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
2045 HeapFree(GetProcessHeap(), 0, d3d8_declaration);
2049 if(This->declArraySize == This->numConvertedDecls) {
2050 int grow = This->declArraySize / 2;
2051 convertedDecls = HeapReAlloc(GetProcessHeap(), 0, convertedDecls,
2052 sizeof(convertedDecls[0]) * (This->numConvertedDecls + grow));
2053 if(!convertedDecls) {
2054 /* This will destroy it */
2055 IDirect3DVertexDeclaration8_Release((IDirect3DVertexDeclaration8 *)d3d8_declaration);
2058 This->decls = convertedDecls;
2059 This->declArraySize += grow;
2062 memmove(convertedDecls + low + 1, convertedDecls + low, sizeof(convertedDecls[0]) * (This->numConvertedDecls - low));
2063 convertedDecls[low].decl = (IDirect3DVertexDeclaration8 *)d3d8_declaration;
2064 convertedDecls[low].fvf = fvf;
2065 This->numConvertedDecls++;
2067 TRACE("Returning %p. %u decls in array\n", d3d8_declaration, This->numConvertedDecls);
2068 return d3d8_declaration;
2071 static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShader(IDirect3DDevice8 *iface, DWORD pShader)
2073 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2074 IDirect3DVertexShader8Impl *shader;
2077 TRACE("iface %p, shader %#x.\n", iface, pShader);
2079 if (VS_HIGHESTFIXEDFXF >= pShader) {
2080 TRACE("Setting FVF, %#x\n", pShader);
2082 wined3d_mutex_lock();
2083 wined3d_device_set_vertex_declaration(This->wined3d_device,
2084 IDirect3DDevice8Impl_FindDecl(This, pShader)->wined3d_vertex_declaration);
2085 wined3d_device_set_vertex_shader(This->wined3d_device, NULL);
2086 wined3d_mutex_unlock();
2091 TRACE("Setting shader\n");
2093 wined3d_mutex_lock();
2094 shader = d3d8_get_object(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2097 WARN("Invalid handle (%#x) passed.\n", pShader);
2098 wined3d_mutex_unlock();
2100 return D3DERR_INVALIDCALL;
2103 hr = wined3d_device_set_vertex_declaration(This->wined3d_device,
2104 ((IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration)->wined3d_vertex_declaration);
2106 hr = wined3d_device_set_vertex_shader(This->wined3d_device, shader->wined3d_shader);
2107 wined3d_mutex_unlock();
2109 TRACE("Returning hr %#x\n", hr);
2114 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShader(IDirect3DDevice8 *iface, DWORD *ppShader)
2116 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2117 struct wined3d_vertex_declaration *wined3d_declaration;
2118 IDirect3DVertexDeclaration8 *d3d8_declaration;
2121 TRACE("iface %p, shader %p.\n", iface, ppShader);
2123 wined3d_mutex_lock();
2124 hr = wined3d_device_get_vertex_declaration(This->wined3d_device, &wined3d_declaration);
2127 wined3d_mutex_unlock();
2128 WARN("(%p) : Call to IWineD3DDevice_GetVertexDeclaration failed %#x (device %p)\n",
2129 This, hr, This->wined3d_device);
2133 if (!wined3d_declaration)
2135 wined3d_mutex_unlock();
2140 d3d8_declaration = wined3d_vertex_declaration_get_parent(wined3d_declaration);
2141 wined3d_vertex_declaration_decref(wined3d_declaration);
2142 wined3d_mutex_unlock();
2143 *ppShader = ((IDirect3DVertexDeclaration8Impl *)d3d8_declaration)->shader_handle;
2145 TRACE("(%p) : returning %#x\n", This, *ppShader);
2150 static HRESULT WINAPI IDirect3DDevice8Impl_DeleteVertexShader(IDirect3DDevice8 *iface, DWORD pShader)
2152 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2153 IDirect3DVertexShader8Impl *shader;
2154 struct wined3d_shader *cur;
2156 TRACE("iface %p, shader %#x.\n", iface, pShader);
2158 wined3d_mutex_lock();
2159 shader = d3d8_free_handle(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2162 WARN("Invalid handle (%#x) passed.\n", pShader);
2163 wined3d_mutex_unlock();
2165 return D3DERR_INVALIDCALL;
2168 cur = wined3d_device_get_vertex_shader(This->wined3d_device);
2171 if (cur == shader->wined3d_shader)
2172 IDirect3DDevice8_SetVertexShader(iface, 0);
2173 wined3d_shader_decref(cur);
2176 wined3d_mutex_unlock();
2178 if (IDirect3DVertexShader8_Release(&shader->IDirect3DVertexShader8_iface))
2180 ERR("Shader %p has references left, this shouldn't happen.\n", shader);
2186 static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShaderConstant(IDirect3DDevice8 *iface,
2187 DWORD Register, const void *pConstantData, DWORD ConstantCount)
2189 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2192 TRACE("iface %p, register %u, data %p, count %u.\n",
2193 iface, Register, pConstantData, ConstantCount);
2195 if(Register + ConstantCount > D3D8_MAX_VERTEX_SHADER_CONSTANTF) {
2196 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2197 Register + ConstantCount, D3D8_MAX_VERTEX_SHADER_CONSTANTF);
2198 return D3DERR_INVALIDCALL;
2201 wined3d_mutex_lock();
2202 hr = wined3d_device_set_vs_consts_f(This->wined3d_device, Register, pConstantData, ConstantCount);
2203 wined3d_mutex_unlock();
2208 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderConstant(IDirect3DDevice8 *iface,
2209 DWORD Register, void *pConstantData, DWORD ConstantCount)
2211 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2214 TRACE("iface %p, register %u, data %p, count %u.\n",
2215 iface, Register, pConstantData, ConstantCount);
2217 if(Register + ConstantCount > D3D8_MAX_VERTEX_SHADER_CONSTANTF) {
2218 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2219 Register + ConstantCount, D3D8_MAX_VERTEX_SHADER_CONSTANTF);
2220 return D3DERR_INVALIDCALL;
2223 wined3d_mutex_lock();
2224 hr = wined3d_device_get_vs_consts_f(This->wined3d_device, Register, pConstantData, ConstantCount);
2225 wined3d_mutex_unlock();
2230 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderDeclaration(IDirect3DDevice8 *iface,
2231 DWORD pVertexShader, void *pData, DWORD *pSizeOfData)
2233 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2234 IDirect3DVertexDeclaration8Impl *declaration;
2235 IDirect3DVertexShader8Impl *shader;
2237 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2238 iface, pVertexShader, pData, pSizeOfData);
2240 wined3d_mutex_lock();
2241 shader = d3d8_get_object(&This->handle_table, pVertexShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2242 wined3d_mutex_unlock();
2246 WARN("Invalid handle (%#x) passed.\n", pVertexShader);
2247 return D3DERR_INVALIDCALL;
2249 declaration = (IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration;
2251 /* If pData is NULL, we just return the required size of the buffer. */
2253 *pSizeOfData = declaration->elements_size;
2257 /* MSDN claims that if *pSizeOfData is smaller than the required size
2258 * we should write the required size and return D3DERR_MOREDATA.
2259 * That's not actually true. */
2260 if (*pSizeOfData < declaration->elements_size) {
2261 return D3DERR_INVALIDCALL;
2264 CopyMemory(pData, declaration->elements, declaration->elements_size);
2269 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderFunction(IDirect3DDevice8 *iface,
2270 DWORD pVertexShader, void *pData, DWORD *pSizeOfData)
2272 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2273 IDirect3DVertexShader8Impl *shader = NULL;
2276 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2277 iface, pVertexShader, pData, pSizeOfData);
2279 wined3d_mutex_lock();
2280 shader = d3d8_get_object(&This->handle_table, pVertexShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2283 WARN("Invalid handle (%#x) passed.\n", pVertexShader);
2284 wined3d_mutex_unlock();
2286 return D3DERR_INVALIDCALL;
2289 if (!shader->wined3d_shader)
2291 wined3d_mutex_unlock();
2296 hr = wined3d_shader_get_byte_code(shader->wined3d_shader, pData, pSizeOfData);
2297 wined3d_mutex_unlock();
2302 static HRESULT WINAPI IDirect3DDevice8Impl_SetIndices(IDirect3DDevice8 *iface,
2303 IDirect3DIndexBuffer8 *pIndexData, UINT baseVertexIndex)
2305 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2306 IDirect3DIndexBuffer8Impl *ib = unsafe_impl_from_IDirect3DIndexBuffer8(pIndexData);
2309 TRACE("iface %p, buffer %p, base_vertex_idx %u.\n", iface, pIndexData, baseVertexIndex);
2311 /* WineD3D takes an INT(due to d3d9), but d3d8 uses UINTs. Do I have to add a check here that
2312 * the UINT doesn't cause an overflow in the INT? It seems rather unlikely because such large
2313 * vertex buffers can't be created to address them with an index that requires the 32nd bit
2314 * (4 Byte minimum vertex size * 2^31-1 -> 8 gb buffer. The index sign would be the least
2317 wined3d_mutex_lock();
2318 wined3d_device_set_base_vertex_index(This->wined3d_device, baseVertexIndex);
2319 hr = wined3d_device_set_index_buffer(This->wined3d_device,
2320 ib ? ib->wineD3DIndexBuffer : NULL,
2321 ib ? ib->format : WINED3DFMT_UNKNOWN);
2322 wined3d_mutex_unlock();
2327 static HRESULT WINAPI IDirect3DDevice8Impl_GetIndices(IDirect3DDevice8 *iface,
2328 IDirect3DIndexBuffer8 **ppIndexData, UINT *pBaseVertexIndex)
2330 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2331 struct wined3d_buffer *retIndexData = NULL;
2334 TRACE("iface %p, buffer %p, base_vertex_index %p.\n", iface, ppIndexData, pBaseVertexIndex);
2336 if(ppIndexData == NULL){
2337 return D3DERR_INVALIDCALL;
2340 /* The case from UINT to INT is safe because d3d8 will never set negative values */
2341 wined3d_mutex_lock();
2342 *pBaseVertexIndex = wined3d_device_get_base_vertex_index(This->wined3d_device);
2343 hr = wined3d_device_get_index_buffer(This->wined3d_device, &retIndexData);
2344 if (SUCCEEDED(hr) && retIndexData)
2346 *ppIndexData = wined3d_buffer_get_parent(retIndexData);
2347 IDirect3DIndexBuffer8_AddRef(*ppIndexData);
2348 wined3d_buffer_decref(retIndexData);
2350 if (FAILED(hr)) FIXME("Call to GetIndices failed\n");
2351 *ppIndexData = NULL;
2353 wined3d_mutex_unlock();
2358 static HRESULT WINAPI IDirect3DDevice8Impl_CreatePixelShader(IDirect3DDevice8 *iface,
2359 const DWORD *byte_code, DWORD *shader)
2361 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2362 IDirect3DPixelShader8Impl *object;
2363 DWORD shader_handle;
2367 TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
2371 TRACE("(%p) Invalid call\n", This);
2372 return D3DERR_INVALIDCALL;
2375 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2378 ERR("Failed to allocate pixel shader memmory.\n");
2379 return E_OUTOFMEMORY;
2382 wined3d_mutex_lock();
2383 handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_PS);
2384 wined3d_mutex_unlock();
2385 if (handle == D3D8_INVALID_HANDLE)
2387 ERR("Failed to allocate pixel shader handle.\n");
2388 HeapFree(GetProcessHeap(), 0, object);
2389 return E_OUTOFMEMORY;
2392 shader_handle = handle + VS_HIGHESTFIXEDFXF + 1;
2394 hr = pixelshader_init(object, This, byte_code, shader_handle);
2397 WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
2398 wined3d_mutex_lock();
2399 d3d8_free_handle(&This->handle_table, handle, D3D8_HANDLE_PS);
2400 wined3d_mutex_unlock();
2401 HeapFree(GetProcessHeap(), 0, object);
2406 TRACE("Created pixel shader %p (handle %#x).\n", object, shader_handle);
2407 *shader = shader_handle;
2412 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShader(IDirect3DDevice8 *iface, DWORD pShader)
2414 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2415 IDirect3DPixelShader8Impl *shader;
2418 TRACE("iface %p, shader %#x.\n", iface, pShader);
2420 wined3d_mutex_lock();
2424 hr = wined3d_device_set_pixel_shader(This->wined3d_device, NULL);
2425 wined3d_mutex_unlock();
2429 shader = d3d8_get_object(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2432 WARN("Invalid handle (%#x) passed.\n", pShader);
2433 wined3d_mutex_unlock();
2434 return D3DERR_INVALIDCALL;
2437 TRACE("(%p) : Setting shader %p\n", This, shader);
2438 hr = wined3d_device_set_pixel_shader(This->wined3d_device, shader->wined3d_shader);
2439 wined3d_mutex_unlock();
2444 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShader(IDirect3DDevice8 *iface, DWORD *ppShader)
2446 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2447 struct wined3d_shader *object;
2449 TRACE("iface %p, shader %p.\n", iface, ppShader);
2451 if (NULL == ppShader) {
2452 TRACE("(%p) Invalid call\n", This);
2453 return D3DERR_INVALIDCALL;
2456 wined3d_mutex_lock();
2457 object = wined3d_device_get_pixel_shader(This->wined3d_device);
2460 IDirect3DPixelShader8Impl *d3d8_shader;
2461 d3d8_shader = wined3d_shader_get_parent(object);
2462 wined3d_shader_decref(object);
2463 *ppShader = d3d8_shader->handle;
2469 wined3d_mutex_unlock();
2471 TRACE("(%p) : returning %#x\n", This, *ppShader);
2476 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePixelShader(IDirect3DDevice8 *iface, DWORD pShader)
2478 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2479 IDirect3DPixelShader8Impl *shader;
2480 struct wined3d_shader *cur;
2482 TRACE("iface %p, shader %#x.\n", iface, pShader);
2484 wined3d_mutex_lock();
2486 shader = d3d8_free_handle(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2489 WARN("Invalid handle (%#x) passed.\n", pShader);
2490 wined3d_mutex_unlock();
2491 return D3DERR_INVALIDCALL;
2494 cur = wined3d_device_get_pixel_shader(This->wined3d_device);
2497 if (cur == shader->wined3d_shader)
2498 IDirect3DDevice8_SetPixelShader(iface, 0);
2499 wined3d_shader_decref(cur);
2502 wined3d_mutex_unlock();
2504 if (IDirect3DPixelShader8_Release(&shader->IDirect3DPixelShader8_iface))
2506 ERR("Shader %p has references left, this shouldn't happen.\n", shader);
2512 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShaderConstant(IDirect3DDevice8 *iface,
2513 DWORD Register, const void *pConstantData, DWORD ConstantCount)
2515 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2518 TRACE("iface %p, register %u, data %p, count %u.\n",
2519 iface, Register, pConstantData, ConstantCount);
2521 wined3d_mutex_lock();
2522 hr = wined3d_device_set_ps_consts_f(This->wined3d_device, Register, pConstantData, ConstantCount);
2523 wined3d_mutex_unlock();
2528 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderConstant(IDirect3DDevice8 *iface,
2529 DWORD Register, void *pConstantData, DWORD ConstantCount)
2531 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2534 TRACE("iface %p, register %u, data %p, count %u.\n",
2535 iface, Register, pConstantData, ConstantCount);
2537 wined3d_mutex_lock();
2538 hr = wined3d_device_get_ps_consts_f(This->wined3d_device, Register, pConstantData, ConstantCount);
2539 wined3d_mutex_unlock();
2544 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderFunction(IDirect3DDevice8 *iface,
2545 DWORD pPixelShader, void *pData, DWORD *pSizeOfData)
2547 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2548 IDirect3DPixelShader8Impl *shader = NULL;
2551 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2552 iface, pPixelShader, pData, pSizeOfData);
2554 wined3d_mutex_lock();
2555 shader = d3d8_get_object(&This->handle_table, pPixelShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2558 WARN("Invalid handle (%#x) passed.\n", pPixelShader);
2559 wined3d_mutex_unlock();
2561 return D3DERR_INVALIDCALL;
2564 hr = wined3d_shader_get_byte_code(shader->wined3d_shader, pData, pSizeOfData);
2565 wined3d_mutex_unlock();
2570 static HRESULT WINAPI IDirect3DDevice8Impl_DrawRectPatch(IDirect3DDevice8 *iface, UINT Handle,
2571 const float *pNumSegs, const D3DRECTPATCH_INFO *pRectPatchInfo)
2573 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2576 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2577 iface, Handle, pNumSegs, pRectPatchInfo);
2579 wined3d_mutex_lock();
2580 hr = wined3d_device_draw_rect_patch(This->wined3d_device, Handle,
2581 pNumSegs, (const WINED3DRECTPATCH_INFO *)pRectPatchInfo);
2582 wined3d_mutex_unlock();
2587 static HRESULT WINAPI IDirect3DDevice8Impl_DrawTriPatch(IDirect3DDevice8 *iface, UINT Handle,
2588 const float *pNumSegs, const D3DTRIPATCH_INFO *pTriPatchInfo)
2590 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2593 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2594 iface, Handle, pNumSegs, pTriPatchInfo);
2596 wined3d_mutex_lock();
2597 hr = wined3d_device_draw_tri_patch(This->wined3d_device, Handle,
2598 pNumSegs, (const WINED3DTRIPATCH_INFO *)pTriPatchInfo);
2599 wined3d_mutex_unlock();
2604 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePatch(IDirect3DDevice8 *iface, UINT Handle)
2606 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2609 TRACE("iface %p, handle %#x.\n", iface, Handle);
2611 wined3d_mutex_lock();
2612 hr = wined3d_device_delete_patch(This->wined3d_device, Handle);
2613 wined3d_mutex_unlock();
2618 static HRESULT WINAPI IDirect3DDevice8Impl_SetStreamSource(IDirect3DDevice8 *iface,
2619 UINT StreamNumber, IDirect3DVertexBuffer8 *pStreamData, UINT Stride)
2621 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2622 IDirect3DVertexBuffer8Impl *streamdata = unsafe_impl_from_IDirect3DVertexBuffer8(pStreamData);
2625 TRACE("iface %p, stream_idx %u, buffer %p, stride %u.\n",
2626 iface, StreamNumber, pStreamData, Stride);
2628 wined3d_mutex_lock();
2629 hr = wined3d_device_set_stream_source(This->wined3d_device, StreamNumber,
2630 streamdata ? streamdata->wineD3DVertexBuffer : NULL, 0/* Offset in bytes */, Stride);
2631 wined3d_mutex_unlock();
2636 static HRESULT WINAPI IDirect3DDevice8Impl_GetStreamSource(IDirect3DDevice8 *iface,
2637 UINT StreamNumber, IDirect3DVertexBuffer8 **pStream, UINT *pStride)
2639 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2640 struct wined3d_buffer *retStream = NULL;
2643 TRACE("iface %p, stream_idx %u, buffer %p, stride %p.\n",
2644 iface, StreamNumber, pStream, pStride);
2646 if(pStream == NULL){
2647 return D3DERR_INVALIDCALL;
2650 wined3d_mutex_lock();
2651 hr = wined3d_device_get_stream_source(This->wined3d_device, StreamNumber,
2652 &retStream, 0 /* Offset in bytes */, pStride);
2653 if (SUCCEEDED(hr) && retStream)
2655 *pStream = wined3d_buffer_get_parent(retStream);
2656 IDirect3DVertexBuffer8_AddRef(*pStream);
2657 wined3d_buffer_decref(retStream);
2661 if (FAILED(hr)) FIXME("Call to GetStreamSource failed, hr %#x.\n", hr);
2664 wined3d_mutex_unlock();
2669 static const IDirect3DDevice8Vtbl Direct3DDevice8_Vtbl =
2671 IDirect3DDevice8Impl_QueryInterface,
2672 IDirect3DDevice8Impl_AddRef,
2673 IDirect3DDevice8Impl_Release,
2674 IDirect3DDevice8Impl_TestCooperativeLevel,
2675 IDirect3DDevice8Impl_GetAvailableTextureMem,
2676 IDirect3DDevice8Impl_ResourceManagerDiscardBytes,
2677 IDirect3DDevice8Impl_GetDirect3D,
2678 IDirect3DDevice8Impl_GetDeviceCaps,
2679 IDirect3DDevice8Impl_GetDisplayMode,
2680 IDirect3DDevice8Impl_GetCreationParameters,
2681 IDirect3DDevice8Impl_SetCursorProperties,
2682 IDirect3DDevice8Impl_SetCursorPosition,
2683 IDirect3DDevice8Impl_ShowCursor,
2684 IDirect3DDevice8Impl_CreateAdditionalSwapChain,
2685 IDirect3DDevice8Impl_Reset,
2686 IDirect3DDevice8Impl_Present,
2687 IDirect3DDevice8Impl_GetBackBuffer,
2688 IDirect3DDevice8Impl_GetRasterStatus,
2689 IDirect3DDevice8Impl_SetGammaRamp,
2690 IDirect3DDevice8Impl_GetGammaRamp,
2691 IDirect3DDevice8Impl_CreateTexture,
2692 IDirect3DDevice8Impl_CreateVolumeTexture,
2693 IDirect3DDevice8Impl_CreateCubeTexture,
2694 IDirect3DDevice8Impl_CreateVertexBuffer,
2695 IDirect3DDevice8Impl_CreateIndexBuffer,
2696 IDirect3DDevice8Impl_CreateRenderTarget,
2697 IDirect3DDevice8Impl_CreateDepthStencilSurface,
2698 IDirect3DDevice8Impl_CreateImageSurface,
2699 IDirect3DDevice8Impl_CopyRects,
2700 IDirect3DDevice8Impl_UpdateTexture,
2701 IDirect3DDevice8Impl_GetFrontBuffer,
2702 IDirect3DDevice8Impl_SetRenderTarget,
2703 IDirect3DDevice8Impl_GetRenderTarget,
2704 IDirect3DDevice8Impl_GetDepthStencilSurface,
2705 IDirect3DDevice8Impl_BeginScene,
2706 IDirect3DDevice8Impl_EndScene,
2707 IDirect3DDevice8Impl_Clear,
2708 IDirect3DDevice8Impl_SetTransform,
2709 IDirect3DDevice8Impl_GetTransform,
2710 IDirect3DDevice8Impl_MultiplyTransform,
2711 IDirect3DDevice8Impl_SetViewport,
2712 IDirect3DDevice8Impl_GetViewport,
2713 IDirect3DDevice8Impl_SetMaterial,
2714 IDirect3DDevice8Impl_GetMaterial,
2715 IDirect3DDevice8Impl_SetLight,
2716 IDirect3DDevice8Impl_GetLight,
2717 IDirect3DDevice8Impl_LightEnable,
2718 IDirect3DDevice8Impl_GetLightEnable,
2719 IDirect3DDevice8Impl_SetClipPlane,
2720 IDirect3DDevice8Impl_GetClipPlane,
2721 IDirect3DDevice8Impl_SetRenderState,
2722 IDirect3DDevice8Impl_GetRenderState,
2723 IDirect3DDevice8Impl_BeginStateBlock,
2724 IDirect3DDevice8Impl_EndStateBlock,
2725 IDirect3DDevice8Impl_ApplyStateBlock,
2726 IDirect3DDevice8Impl_CaptureStateBlock,
2727 IDirect3DDevice8Impl_DeleteStateBlock,
2728 IDirect3DDevice8Impl_CreateStateBlock,
2729 IDirect3DDevice8Impl_SetClipStatus,
2730 IDirect3DDevice8Impl_GetClipStatus,
2731 IDirect3DDevice8Impl_GetTexture,
2732 IDirect3DDevice8Impl_SetTexture,
2733 IDirect3DDevice8Impl_GetTextureStageState,
2734 IDirect3DDevice8Impl_SetTextureStageState,
2735 IDirect3DDevice8Impl_ValidateDevice,
2736 IDirect3DDevice8Impl_GetInfo,
2737 IDirect3DDevice8Impl_SetPaletteEntries,
2738 IDirect3DDevice8Impl_GetPaletteEntries,
2739 IDirect3DDevice8Impl_SetCurrentTexturePalette,
2740 IDirect3DDevice8Impl_GetCurrentTexturePalette,
2741 IDirect3DDevice8Impl_DrawPrimitive,
2742 IDirect3DDevice8Impl_DrawIndexedPrimitive,
2743 IDirect3DDevice8Impl_DrawPrimitiveUP,
2744 IDirect3DDevice8Impl_DrawIndexedPrimitiveUP,
2745 IDirect3DDevice8Impl_ProcessVertices,
2746 IDirect3DDevice8Impl_CreateVertexShader,
2747 IDirect3DDevice8Impl_SetVertexShader,
2748 IDirect3DDevice8Impl_GetVertexShader,
2749 IDirect3DDevice8Impl_DeleteVertexShader,
2750 IDirect3DDevice8Impl_SetVertexShaderConstant,
2751 IDirect3DDevice8Impl_GetVertexShaderConstant,
2752 IDirect3DDevice8Impl_GetVertexShaderDeclaration,
2753 IDirect3DDevice8Impl_GetVertexShaderFunction,
2754 IDirect3DDevice8Impl_SetStreamSource,
2755 IDirect3DDevice8Impl_GetStreamSource,
2756 IDirect3DDevice8Impl_SetIndices,
2757 IDirect3DDevice8Impl_GetIndices,
2758 IDirect3DDevice8Impl_CreatePixelShader,
2759 IDirect3DDevice8Impl_SetPixelShader,
2760 IDirect3DDevice8Impl_GetPixelShader,
2761 IDirect3DDevice8Impl_DeletePixelShader,
2762 IDirect3DDevice8Impl_SetPixelShaderConstant,
2763 IDirect3DDevice8Impl_GetPixelShaderConstant,
2764 IDirect3DDevice8Impl_GetPixelShaderFunction,
2765 IDirect3DDevice8Impl_DrawRectPatch,
2766 IDirect3DDevice8Impl_DrawTriPatch,
2767 IDirect3DDevice8Impl_DeletePatch
2770 static inline IDirect3DDevice8Impl *device_from_device_parent(struct wined3d_device_parent *device_parent)
2772 return CONTAINING_RECORD(device_parent, IDirect3DDevice8Impl, device_parent);
2775 static void CDECL device_parent_wined3d_device_created(struct wined3d_device_parent *device_parent,
2776 struct wined3d_device *device)
2778 TRACE("device_parent %p, device %p\n", device_parent, device);
2781 static HRESULT CDECL device_parent_create_surface(struct wined3d_device_parent *device_parent,
2782 void *container_parent, UINT width, UINT height, enum wined3d_format_id format, DWORD usage,
2783 WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, struct wined3d_surface **surface)
2785 IDirect3DDevice8Impl *device = device_from_device_parent(device_parent);
2786 IDirect3DSurface8Impl *d3d_surface;
2787 BOOL lockable = TRUE;
2790 TRACE("device_parent %p, container_parent %p, width %u, height %u, format %#x, usage %#x,\n"
2791 "\tpool %#x, level %u, face %u, surface %p.\n",
2792 device_parent, container_parent, width, height, format, usage, pool, level, face, surface);
2795 if (pool == WINED3DPOOL_DEFAULT && !(usage & WINED3DUSAGE_DYNAMIC)) lockable = FALSE;
2797 hr = IDirect3DDevice8Impl_CreateSurface(device, width, height,
2798 d3dformat_from_wined3dformat(format), lockable, FALSE /* Discard */, level,
2799 (IDirect3DSurface8 **)&d3d_surface, usage, pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
2802 WARN("Failed to create surface, hr %#x.\n", hr);
2806 *surface = d3d_surface->wined3d_surface;
2807 wined3d_surface_incref(*surface);
2809 d3d_surface->container = container_parent;
2810 IUnknown_Release(d3d_surface->parentDevice);
2811 d3d_surface->parentDevice = NULL;
2813 IDirect3DSurface8_Release(&d3d_surface->IDirect3DSurface8_iface);
2814 d3d_surface->forwardReference = container_parent;
2819 static HRESULT CDECL device_parent_create_rendertarget(struct wined3d_device_parent *device_parent,
2820 void *container_parent, UINT width, UINT height, enum wined3d_format_id format,
2821 WINED3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality, BOOL lockable,
2822 struct wined3d_surface **surface)
2824 IDirect3DDevice8Impl *device = device_from_device_parent(device_parent);
2825 IDirect3DSurface8Impl *d3d_surface;
2828 TRACE("device_parent %p, container_parent %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2829 "\tmultisample_quality %u, lockable %u, surface %p.\n",
2830 device_parent, container_parent, width, height, format,
2831 multisample_type, multisample_quality, lockable, surface);
2833 hr = IDirect3DDevice8_CreateRenderTarget(&device->IDirect3DDevice8_iface, width, height,
2834 d3dformat_from_wined3dformat(format), multisample_type, lockable, (IDirect3DSurface8 **)&d3d_surface);
2837 WARN("Failed to create rendertarget, hr %#x.\n", hr);
2841 *surface = d3d_surface->wined3d_surface;
2842 wined3d_surface_incref(*surface);
2844 d3d_surface->container = (IUnknown *)&device->IDirect3DDevice8_iface;
2845 /* Implicit surfaces are created with an refcount of 0 */
2846 IDirect3DSurface8_Release(&d3d_surface->IDirect3DSurface8_iface);
2851 static HRESULT CDECL device_parent_create_depth_stencil(struct wined3d_device_parent *device_parent,
2852 UINT width, UINT height, enum wined3d_format_id format, WINED3DMULTISAMPLE_TYPE multisample_type,
2853 DWORD multisample_quality, BOOL discard, struct wined3d_surface **surface)
2855 IDirect3DDevice8Impl *device = device_from_device_parent(device_parent);
2856 IDirect3DSurface8Impl *d3d_surface;
2859 TRACE("device_parent %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2860 "\tmultisample_quality %u, discard %u, surface %p.\n",
2861 device_parent, width, height, format, multisample_type, multisample_quality, discard, surface);
2863 hr = IDirect3DDevice8_CreateDepthStencilSurface(&device->IDirect3DDevice8_iface, width, height,
2864 d3dformat_from_wined3dformat(format), multisample_type, (IDirect3DSurface8 **)&d3d_surface);
2867 WARN("Failed to create depth/stencil surface, hr %#x.\n", hr);
2871 *surface = d3d_surface->wined3d_surface;
2872 wined3d_surface_incref(*surface);
2874 d3d_surface->container = (IUnknown *)&device->IDirect3DDevice8_iface;
2875 /* Implicit surfaces are created with an refcount of 0 */
2876 IDirect3DSurface8_Release(&d3d_surface->IDirect3DSurface8_iface);
2881 static HRESULT CDECL device_parent_create_volume(struct wined3d_device_parent *device_parent,
2882 void *container_parent, UINT width, UINT height, UINT depth, enum wined3d_format_id format,
2883 WINED3DPOOL pool, DWORD usage, struct wined3d_volume **volume)
2885 IDirect3DDevice8Impl *device = device_from_device_parent(device_parent);
2886 IDirect3DVolume8Impl *object;
2889 TRACE("device_parent %p, container_parent %p, width %u, height %u, depth %u, "
2890 "format %#x, pool %#x, usage %#x, volume %p.\n",
2891 device_parent, container_parent, width, height, depth,
2892 format, pool, usage, volume);
2894 /* Allocate the storage for the device */
2895 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2898 FIXME("Allocation of memory failed\n");
2900 return D3DERR_OUTOFVIDEOMEMORY;
2903 hr = volume_init(object, device, width, height, depth, usage, format, pool);
2906 WARN("Failed to initialize volume, hr %#x.\n", hr);
2907 HeapFree(GetProcessHeap(), 0, object);
2911 *volume = object->wined3d_volume;
2912 wined3d_volume_incref(*volume);
2913 IDirect3DVolume8_Release(&object->IDirect3DVolume8_iface);
2915 object->container = container_parent;
2916 object->forwardReference = container_parent;
2918 TRACE("Created volume %p.\n", object);
2923 static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent *device_parent,
2924 WINED3DPRESENT_PARAMETERS *present_parameters, struct wined3d_swapchain **swapchain)
2926 IDirect3DDevice8Impl *device = device_from_device_parent(device_parent);
2927 D3DPRESENT_PARAMETERS local_parameters;
2928 IDirect3DSwapChain8 *d3d_swapchain;
2931 TRACE("device_parent %p, present_parameters %p, swapchain %p.\n", device_parent, present_parameters, swapchain);
2933 /* Copy the presentation parameters */
2934 local_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
2935 local_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
2936 local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(present_parameters->BackBufferFormat);
2937 local_parameters.BackBufferCount = present_parameters->BackBufferCount;
2938 local_parameters.MultiSampleType = present_parameters->MultiSampleType;
2939 local_parameters.SwapEffect = present_parameters->SwapEffect;
2940 local_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
2941 local_parameters.Windowed = present_parameters->Windowed;
2942 local_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
2943 local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(present_parameters->AutoDepthStencilFormat);
2944 local_parameters.Flags = present_parameters->Flags;
2945 local_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
2946 local_parameters.FullScreen_PresentationInterval = present_parameters->PresentationInterval;
2948 hr = IDirect3DDevice8_CreateAdditionalSwapChain(&device->IDirect3DDevice8_iface,
2949 &local_parameters, &d3d_swapchain);
2952 WARN("Failed to create swapchain, hr %#x.\n", hr);
2957 *swapchain = ((IDirect3DSwapChain8Impl *)d3d_swapchain)->wined3d_swapchain;
2958 wined3d_swapchain_incref(*swapchain);
2959 IDirect3DSwapChain8_Release(d3d_swapchain);
2961 /* Copy back the presentation parameters */
2962 present_parameters->BackBufferWidth = local_parameters.BackBufferWidth;
2963 present_parameters->BackBufferHeight = local_parameters.BackBufferHeight;
2964 present_parameters->BackBufferFormat = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat);
2965 present_parameters->BackBufferCount = local_parameters.BackBufferCount;
2966 present_parameters->MultiSampleType = local_parameters.MultiSampleType;
2967 present_parameters->SwapEffect = local_parameters.SwapEffect;
2968 present_parameters->hDeviceWindow = local_parameters.hDeviceWindow;
2969 present_parameters->Windowed = local_parameters.Windowed;
2970 present_parameters->EnableAutoDepthStencil = local_parameters.EnableAutoDepthStencil;
2971 present_parameters->AutoDepthStencilFormat = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat);
2972 present_parameters->Flags = local_parameters.Flags;
2973 present_parameters->FullScreen_RefreshRateInHz = local_parameters.FullScreen_RefreshRateInHz;
2974 present_parameters->PresentationInterval = local_parameters.FullScreen_PresentationInterval;
2979 static const struct wined3d_device_parent_ops d3d8_wined3d_device_parent_ops =
2981 device_parent_wined3d_device_created,
2982 device_parent_create_surface,
2983 device_parent_create_rendertarget,
2984 device_parent_create_depth_stencil,
2985 device_parent_create_volume,
2986 device_parent_create_swapchain,
2989 static void setup_fpu(void)
2991 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
2993 __asm__ volatile ("fnstcw %0" : "=m" (cw));
2994 cw = (cw & ~0xf3f) | 0x3f;
2995 __asm__ volatile ("fldcw %0" : : "m" (cw));
2996 #elif defined(__i386__) && defined(_MSC_VER)
2999 cw = (cw & ~0xf3f) | 0x3f;
3002 FIXME("FPU setup not implemented for this platform.\n");
3006 HRESULT device_init(IDirect3DDevice8Impl *device, IDirect3D8Impl *parent, struct wined3d *wined3d, UINT adapter,
3007 D3DDEVTYPE device_type, HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters)
3009 WINED3DPRESENT_PARAMETERS wined3d_parameters;
3012 device->IDirect3DDevice8_iface.lpVtbl = &Direct3DDevice8_Vtbl;
3013 device->device_parent.ops = &d3d8_wined3d_device_parent_ops;
3015 device->handle_table.entries = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
3016 D3D8_INITIAL_HANDLE_TABLE_SIZE * sizeof(*device->handle_table.entries));
3017 if (!device->handle_table.entries)
3019 ERR("Failed to allocate handle table memory.\n");
3020 return E_OUTOFMEMORY;
3022 device->handle_table.table_size = D3D8_INITIAL_HANDLE_TABLE_SIZE;
3024 if (!(flags & D3DCREATE_FPU_PRESERVE)) setup_fpu();
3026 wined3d_mutex_lock();
3027 hr = wined3d_device_create(wined3d, adapter, device_type, focus_window, flags, 4,
3028 &device->device_parent, &device->wined3d_device);
3031 WARN("Failed to create wined3d device, hr %#x.\n", hr);
3032 wined3d_mutex_unlock();
3033 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);
3037 if (!parameters->Windowed)
3039 HWND device_window = parameters->hDeviceWindow;
3042 focus_window = device_window;
3043 if (FAILED(hr = wined3d_device_acquire_focus_window(device->wined3d_device, focus_window)))
3045 ERR("Failed to acquire focus window, hr %#x.\n", hr);
3046 wined3d_device_decref(device->wined3d_device);
3047 wined3d_mutex_unlock();
3048 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);
3053 device_window = focus_window;
3054 wined3d_device_setup_fullscreen_window(device->wined3d_device, device_window,
3055 parameters->BackBufferWidth,
3056 parameters->BackBufferHeight);
3059 if (flags & D3DCREATE_MULTITHREADED)
3060 wined3d_device_set_multithreaded(device->wined3d_device);
3062 wined3d_parameters.BackBufferWidth = parameters->BackBufferWidth;
3063 wined3d_parameters.BackBufferHeight = parameters->BackBufferHeight;
3064 wined3d_parameters.BackBufferFormat = wined3dformat_from_d3dformat(parameters->BackBufferFormat);
3065 wined3d_parameters.BackBufferCount = parameters->BackBufferCount;
3066 wined3d_parameters.MultiSampleType = parameters->MultiSampleType;
3067 wined3d_parameters.MultiSampleQuality = 0; /* d3d9 only */
3068 wined3d_parameters.SwapEffect = parameters->SwapEffect;
3069 wined3d_parameters.hDeviceWindow = parameters->hDeviceWindow;
3070 wined3d_parameters.Windowed = parameters->Windowed;
3071 wined3d_parameters.EnableAutoDepthStencil = parameters->EnableAutoDepthStencil;
3072 wined3d_parameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(parameters->AutoDepthStencilFormat);
3073 wined3d_parameters.Flags = parameters->Flags;
3074 wined3d_parameters.FullScreen_RefreshRateInHz = parameters->FullScreen_RefreshRateInHz;
3075 wined3d_parameters.PresentationInterval = parameters->FullScreen_PresentationInterval;
3076 wined3d_parameters.AutoRestoreDisplayMode = TRUE;
3078 hr = wined3d_device_init_3d(device->wined3d_device, &wined3d_parameters);
3081 WARN("Failed to initialize 3D, hr %#x.\n", hr);
3082 wined3d_device_release_focus_window(device->wined3d_device);
3083 wined3d_device_decref(device->wined3d_device);
3084 wined3d_mutex_unlock();
3085 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);
3089 hr = wined3d_device_set_render_state(device->wined3d_device, WINED3DRS_POINTSIZE_MIN, 0);
3090 wined3d_mutex_unlock();
3093 ERR("Failed to set minimum pointsize, hr %#x.\n", hr);
3097 parameters->BackBufferWidth = wined3d_parameters.BackBufferWidth;
3098 parameters->BackBufferHeight = wined3d_parameters.BackBufferHeight;
3099 parameters->BackBufferFormat = d3dformat_from_wined3dformat(wined3d_parameters.BackBufferFormat);
3100 parameters->BackBufferCount = wined3d_parameters.BackBufferCount;
3101 parameters->MultiSampleType = wined3d_parameters.MultiSampleType;
3102 parameters->SwapEffect = wined3d_parameters.SwapEffect;
3103 parameters->hDeviceWindow = wined3d_parameters.hDeviceWindow;
3104 parameters->Windowed = wined3d_parameters.Windowed;
3105 parameters->EnableAutoDepthStencil = wined3d_parameters.EnableAutoDepthStencil;
3106 parameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(wined3d_parameters.AutoDepthStencilFormat);
3107 parameters->Flags = wined3d_parameters.Flags;
3108 parameters->FullScreen_RefreshRateInHz = wined3d_parameters.FullScreen_RefreshRateInHz;
3109 parameters->FullScreen_PresentationInterval = wined3d_parameters.PresentationInterval;
3111 device->declArraySize = 16;
3112 device->decls = HeapAlloc(GetProcessHeap(), 0, device->declArraySize * sizeof(*device->decls));
3115 ERR("Failed to allocate FVF vertex declaration map memory.\n");
3120 device->d3d_parent = &parent->IDirect3D8_iface;
3121 IDirect3D8_AddRef(device->d3d_parent);
3126 wined3d_mutex_lock();
3127 wined3d_device_uninit_3d(device->wined3d_device);
3128 wined3d_device_release_focus_window(device->wined3d_device);
3129 wined3d_device_decref(device->wined3d_device);
3130 wined3d_mutex_unlock();
3131 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);