ole32: Rename PROPSET_BLOCK_SIZE to RAW_DIRENTRY_SIZE.
[wine/testsucceed.git] / dlls / d3d8 / device.c
blob50a257d3427eb65a1ab7b743e08c158088585aed
1 /*
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
22 #include "config.h"
24 #include <math.h>
25 #include <stdarg.h>
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winuser.h"
32 #include "wingdi.h"
33 #include "wine/debug.h"
35 #include "d3d8_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
39 D3DFORMAT d3dformat_from_wined3dformat(WINED3DFORMAT 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;
46 switch(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;
84 default:
85 FIXME("Unhandled WINED3DFORMAT %#x\n", format);
86 return D3DFMT_UNKNOWN;
90 WINED3DFORMAT 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;
97 switch(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;
135 default:
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;
148 case D3DPT_LINELIST:
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;
161 default:
162 FIXME("Unhandled primitive type %#x\n", primitive_type);
163 return 0;
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;
172 if (t->free_entries)
174 /* Use a free handle */
175 entry = t->free_entries;
176 if (entry->type != D3D8_HANDLE_FREE)
178 ERR("Handle %u(%p) is in the free list, but has type %#x.\n", (entry - t->entries), entry, entry->type);
179 return D3D8_INVALID_HANDLE;
181 t->free_entries = entry->object;
182 entry->object = object;
183 entry->type = type;
185 return entry - t->entries;
188 if (!(t->entry_count < t->table_size))
190 /* Grow the table */
191 UINT new_size = t->table_size + (t->table_size >> 1);
192 struct d3d8_handle_entry *new_entries = HeapReAlloc(GetProcessHeap(),
193 0, t->entries, new_size * sizeof(*t->entries));
194 if (!new_entries)
196 ERR("Failed to grow the handle table.\n");
197 return D3D8_INVALID_HANDLE;
199 t->entries = new_entries;
200 t->table_size = new_size;
203 entry = &t->entries[t->entry_count];
204 entry->object = object;
205 entry->type = type;
207 return t->entry_count++;
210 static void *d3d8_free_handle(struct d3d8_handle_table *t, DWORD handle, enum d3d8_handle_type type)
212 struct d3d8_handle_entry *entry;
213 void *object;
215 if (handle == D3D8_INVALID_HANDLE || handle >= t->entry_count)
217 WARN("Invalid handle %u passed.\n", handle);
218 return NULL;
221 entry = &t->entries[handle];
222 if (entry->type != type)
224 WARN("Handle %u(%p) is not of type %#x.\n", handle, entry, type);
225 return NULL;
228 object = entry->object;
229 entry->object = t->free_entries;
230 entry->type = D3D8_HANDLE_FREE;
231 t->free_entries = entry;
233 return object;
236 static void *d3d8_get_object(struct d3d8_handle_table *t, DWORD handle, enum d3d8_handle_type type)
238 struct d3d8_handle_entry *entry;
240 if (handle == D3D8_INVALID_HANDLE || handle >= t->entry_count)
242 WARN("Invalid handle %u passed.\n", handle);
243 return NULL;
246 entry = &t->entries[handle];
247 if (entry->type != type)
249 WARN("Handle %u(%p) is not of type %#x.\n", handle, entry, type);
250 return NULL;
253 return entry->object;
256 /* IDirect3D IUnknown parts follow: */
257 static HRESULT WINAPI IDirect3DDevice8Impl_QueryInterface(LPDIRECT3DDEVICE8 iface,REFIID riid,LPVOID *ppobj)
259 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
261 TRACE("iface %p, riid %s, object %p.\n",
262 iface, debugstr_guid(riid), ppobj);
264 if (IsEqualGUID(riid, &IID_IUnknown)
265 || IsEqualGUID(riid, &IID_IDirect3DDevice8)) {
266 IUnknown_AddRef(iface);
267 *ppobj = This;
268 return S_OK;
271 if (IsEqualGUID(riid, &IID_IWineD3DDeviceParent))
273 IUnknown_AddRef((IUnknown *)&This->device_parent_vtbl);
274 *ppobj = &This->device_parent_vtbl;
275 return S_OK;
278 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
279 *ppobj = NULL;
280 return E_NOINTERFACE;
283 static ULONG WINAPI IDirect3DDevice8Impl_AddRef(LPDIRECT3DDEVICE8 iface) {
284 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
285 ULONG ref = InterlockedIncrement(&This->ref);
287 TRACE("%p increasing refcount to %u.\n", iface, ref);
289 return ref;
292 static ULONG WINAPI IDirect3DDevice8Impl_Release(LPDIRECT3DDEVICE8 iface) {
293 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
294 ULONG ref;
296 if (This->inDestruction) return 0;
297 ref = InterlockedDecrement(&This->ref);
299 TRACE("%p decreasing refcount to %u.\n", iface, ref);
301 if (ref == 0) {
302 unsigned i;
304 TRACE("Releasing wined3d device %p\n", This->WineD3DDevice);
306 wined3d_mutex_lock();
308 This->inDestruction = TRUE;
310 for(i = 0; i < This->numConvertedDecls; i++) {
311 IDirect3DVertexDeclaration8_Release(This->decls[i].decl);
313 HeapFree(GetProcessHeap(), 0, This->decls);
315 IWineD3DDevice_Uninit3D(This->WineD3DDevice, D3D8CB_DestroySwapChain);
316 IWineD3DDevice_Release(This->WineD3DDevice);
317 HeapFree(GetProcessHeap(), 0, This->handle_table.entries);
318 HeapFree(GetProcessHeap(), 0, This);
320 wined3d_mutex_unlock();
322 return ref;
325 /* IDirect3DDevice Interface follow: */
326 static HRESULT WINAPI IDirect3DDevice8Impl_TestCooperativeLevel(LPDIRECT3DDEVICE8 iface) {
327 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
328 HRESULT hr;
330 TRACE("iface %p.\n", iface);
332 wined3d_mutex_lock();
333 hr = IWineD3DDevice_TestCooperativeLevel(This->WineD3DDevice);
334 wined3d_mutex_unlock();
336 return hr;
339 static UINT WINAPI IDirect3DDevice8Impl_GetAvailableTextureMem(LPDIRECT3DDEVICE8 iface) {
340 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
341 HRESULT hr;
343 TRACE("iface %p.\n", iface);
345 wined3d_mutex_lock();
346 hr = IWineD3DDevice_GetAvailableTextureMem(This->WineD3DDevice);
347 wined3d_mutex_unlock();
349 return hr;
352 static HRESULT WINAPI IDirect3DDevice8Impl_ResourceManagerDiscardBytes(LPDIRECT3DDEVICE8 iface, DWORD Bytes) {
353 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
354 HRESULT hr;
356 TRACE("iface %p, byte_count %u.\n", iface, Bytes);
357 FIXME("Byte count ignored.\n");
359 wined3d_mutex_lock();
360 hr = IWineD3DDevice_EvictManagedResources(This->WineD3DDevice);
361 wined3d_mutex_unlock();
363 return hr;
366 static HRESULT WINAPI IDirect3DDevice8Impl_GetDirect3D(LPDIRECT3DDEVICE8 iface, IDirect3D8** ppD3D8) {
367 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
368 HRESULT hr = D3D_OK;
369 IWineD3D* pWineD3D;
371 TRACE("iface %p, d3d8 %p.\n", iface, ppD3D8);
373 if (NULL == ppD3D8) {
374 return D3DERR_INVALIDCALL;
377 wined3d_mutex_lock();
378 hr = IWineD3DDevice_GetDirect3D(This->WineD3DDevice, &pWineD3D);
379 if (hr == D3D_OK && pWineD3D != NULL)
381 IWineD3D_GetParent(pWineD3D,(IUnknown **)ppD3D8);
382 IWineD3D_Release(pWineD3D);
383 } else {
384 FIXME("Call to IWineD3DDevice_GetDirect3D failed\n");
385 *ppD3D8 = NULL;
387 wined3d_mutex_unlock();
389 TRACE("(%p) returning %p\n",This , *ppD3D8);
391 return hr;
394 static HRESULT WINAPI IDirect3DDevice8Impl_GetDeviceCaps(LPDIRECT3DDEVICE8 iface, D3DCAPS8* pCaps) {
395 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
396 HRESULT hrc = D3D_OK;
397 WINED3DCAPS *pWineCaps;
399 TRACE("iface %p, caps %p.\n", iface, pCaps);
401 if(NULL == pCaps){
402 return D3DERR_INVALIDCALL;
404 pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
405 if(pWineCaps == NULL){
406 return D3DERR_INVALIDCALL; /* well this is what MSDN says to return */
409 wined3d_mutex_lock();
410 hrc = IWineD3DDevice_GetDeviceCaps(This->WineD3DDevice, pWineCaps);
411 wined3d_mutex_unlock();
413 fixup_caps(pWineCaps);
414 WINECAPSTOD3D8CAPS(pCaps, pWineCaps)
415 HeapFree(GetProcessHeap(), 0, pWineCaps);
417 TRACE("Returning %p %p\n", This, pCaps);
418 return hrc;
421 static HRESULT WINAPI IDirect3DDevice8Impl_GetDisplayMode(LPDIRECT3DDEVICE8 iface, D3DDISPLAYMODE* pMode) {
422 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
423 HRESULT hr;
425 TRACE("iface %p, mode %p.\n", iface, pMode);
427 wined3d_mutex_lock();
428 hr = IWineD3DDevice_GetDisplayMode(This->WineD3DDevice, 0, (WINED3DDISPLAYMODE *) pMode);
429 wined3d_mutex_unlock();
431 if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
433 return hr;
436 static HRESULT WINAPI IDirect3DDevice8Impl_GetCreationParameters(LPDIRECT3DDEVICE8 iface, D3DDEVICE_CREATION_PARAMETERS *pParameters) {
437 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
438 HRESULT hr;
440 TRACE("iface %p, parameters %p.\n", iface, pParameters);
442 wined3d_mutex_lock();
443 hr = IWineD3DDevice_GetCreationParameters(This->WineD3DDevice, (WINED3DDEVICE_CREATION_PARAMETERS *) pParameters);
444 wined3d_mutex_unlock();
446 return hr;
449 static HRESULT WINAPI IDirect3DDevice8Impl_SetCursorProperties(LPDIRECT3DDEVICE8 iface, UINT XHotSpot, UINT YHotSpot, IDirect3DSurface8* pCursorBitmap) {
450 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
451 IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl*)pCursorBitmap;
452 HRESULT hr;
454 TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
455 iface, XHotSpot, YHotSpot, pCursorBitmap);
457 if(!pCursorBitmap) {
458 WARN("No cursor bitmap, returning WINED3DERR_INVALIDCALL\n");
459 return WINED3DERR_INVALIDCALL;
462 wined3d_mutex_lock();
463 hr = IWineD3DDevice_SetCursorProperties(This->WineD3DDevice,XHotSpot,YHotSpot,pSurface->wineD3DSurface);
464 wined3d_mutex_unlock();
466 return hr;
469 static void WINAPI IDirect3DDevice8Impl_SetCursorPosition(LPDIRECT3DDEVICE8 iface, UINT XScreenSpace, UINT YScreenSpace, DWORD Flags) {
470 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
472 TRACE("iface %p, x %u, y %u, flags %#x.\n",
473 iface, XScreenSpace, YScreenSpace, Flags);
475 wined3d_mutex_lock();
476 IWineD3DDevice_SetCursorPosition(This->WineD3DDevice, XScreenSpace, YScreenSpace, Flags);
477 wined3d_mutex_unlock();
480 static BOOL WINAPI IDirect3DDevice8Impl_ShowCursor(LPDIRECT3DDEVICE8 iface, BOOL bShow) {
481 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
482 BOOL ret;
484 TRACE("iface %p, show %#x.\n", iface, bShow);
486 wined3d_mutex_lock();
487 ret = IWineD3DDevice_ShowCursor(This->WineD3DDevice, bShow);
488 wined3d_mutex_unlock();
490 return ret;
493 static HRESULT WINAPI IDirect3DDevice8Impl_CreateAdditionalSwapChain(LPDIRECT3DDEVICE8 iface, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DSwapChain8** pSwapChain) {
494 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
495 IDirect3DSwapChain8Impl* object;
496 HRESULT hrc = D3D_OK;
497 WINED3DPRESENT_PARAMETERS localParameters;
499 TRACE("iface %p, present_parameters %p, swapchain %p.\n",
500 iface, pPresentationParameters, pSwapChain);
502 /* Fix the back buffer count */
503 if(pPresentationParameters->BackBufferCount == 0) {
504 pPresentationParameters->BackBufferCount = 1;
507 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
508 if (NULL == object) {
509 FIXME("Allocation of memory failed\n");
510 *pSwapChain = NULL;
511 return D3DERR_OUTOFVIDEOMEMORY;
513 object->ref = 1;
514 object->lpVtbl = &Direct3DSwapChain8_Vtbl;
516 /* Allocate an associated WineD3DDevice object */
517 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
518 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
519 localParameters.BackBufferFormat = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
520 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
521 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
522 localParameters.MultiSampleQuality = 0; /* d3d9 only */
523 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
524 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
525 localParameters.Windowed = pPresentationParameters->Windowed;
526 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
527 localParameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
528 localParameters.Flags = pPresentationParameters->Flags;
529 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
530 localParameters.PresentationInterval = pPresentationParameters->FullScreen_PresentationInterval;
531 localParameters.AutoRestoreDisplayMode = TRUE;
533 wined3d_mutex_lock();
534 hrc = IWineD3DDevice_CreateSwapChain(This->WineD3DDevice, &localParameters,
535 &object->wineD3DSwapChain, (IUnknown *)object, SURFACE_OPENGL);
536 wined3d_mutex_unlock();
538 pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
539 pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
540 pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(localParameters.BackBufferFormat);
541 pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
542 pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
543 pPresentationParameters->SwapEffect = localParameters.SwapEffect;
544 pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
545 pPresentationParameters->Windowed = localParameters.Windowed;
546 pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
547 pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat);
548 pPresentationParameters->Flags = localParameters.Flags;
549 pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
550 pPresentationParameters->FullScreen_PresentationInterval = localParameters.PresentationInterval;
552 if (hrc != D3D_OK) {
553 FIXME("(%p) call to IWineD3DDevice_CreateSwapChain failed\n", This);
554 HeapFree(GetProcessHeap(), 0 , object);
555 *pSwapChain = NULL;
556 }else{
557 IUnknown_AddRef(iface);
558 object->parentDevice = iface;
559 *pSwapChain = (IDirect3DSwapChain8 *)object;
561 TRACE("(%p) returning %p\n", This, *pSwapChain);
562 return hrc;
565 static HRESULT WINAPI IDirect3DDevice8Impl_Reset(LPDIRECT3DDEVICE8 iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
566 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
567 WINED3DPRESENT_PARAMETERS localParameters;
568 HRESULT hr;
570 TRACE("iface %p, present_parameters %p.\n", iface, pPresentationParameters);
572 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
573 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
574 localParameters.BackBufferFormat = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
575 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
576 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
577 localParameters.MultiSampleQuality = 0; /* d3d9 only */
578 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
579 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
580 localParameters.Windowed = pPresentationParameters->Windowed;
581 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
582 localParameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
583 localParameters.Flags = pPresentationParameters->Flags;
584 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
585 localParameters.PresentationInterval = pPresentationParameters->FullScreen_PresentationInterval;
586 localParameters.AutoRestoreDisplayMode = TRUE;
588 wined3d_mutex_lock();
589 hr = IWineD3DDevice_Reset(This->WineD3DDevice, &localParameters);
590 if(SUCCEEDED(hr)) {
591 hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, WINED3DRS_POINTSIZE_MIN, 0);
593 wined3d_mutex_unlock();
595 pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
596 pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
597 pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(localParameters.BackBufferFormat);
598 pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
599 pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
600 pPresentationParameters->SwapEffect = localParameters.SwapEffect;
601 pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
602 pPresentationParameters->Windowed = localParameters.Windowed;
603 pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
604 pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat);
605 pPresentationParameters->Flags = localParameters.Flags;
606 pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
607 pPresentationParameters->FullScreen_PresentationInterval = localParameters.PresentationInterval;
609 return hr;
612 static HRESULT WINAPI IDirect3DDevice8Impl_Present(LPDIRECT3DDEVICE8 iface, CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion) {
613 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
614 HRESULT hr;
616 TRACE("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p.\n",
617 iface, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
619 wined3d_mutex_lock();
620 hr = IWineD3DDevice_Present(This->WineD3DDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
621 wined3d_mutex_unlock();
623 return hr;
626 static HRESULT WINAPI IDirect3DDevice8Impl_GetBackBuffer(LPDIRECT3DDEVICE8 iface, UINT BackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface8** ppBackBuffer) {
627 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
628 IWineD3DSurface *retSurface = NULL;
629 HRESULT rc = D3D_OK;
631 TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
632 iface, BackBuffer, Type, ppBackBuffer);
634 wined3d_mutex_lock();
635 rc = IWineD3DDevice_GetBackBuffer(This->WineD3DDevice, 0, BackBuffer, (WINED3DBACKBUFFER_TYPE) Type, &retSurface);
636 if (rc == D3D_OK && NULL != retSurface && NULL != ppBackBuffer) {
637 IWineD3DSurface_GetParent(retSurface, (IUnknown **)ppBackBuffer);
638 IWineD3DSurface_Release(retSurface);
640 wined3d_mutex_unlock();
642 return rc;
645 static HRESULT WINAPI IDirect3DDevice8Impl_GetRasterStatus(LPDIRECT3DDEVICE8 iface, D3DRASTER_STATUS* pRasterStatus) {
646 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
647 HRESULT hr;
649 TRACE("iface %p, raster_status %p.\n", iface, pRasterStatus);
651 wined3d_mutex_lock();
652 hr = IWineD3DDevice_GetRasterStatus(This->WineD3DDevice, 0, (WINED3DRASTER_STATUS *) pRasterStatus);
653 wined3d_mutex_unlock();
655 return hr;
658 static void WINAPI IDirect3DDevice8Impl_SetGammaRamp(LPDIRECT3DDEVICE8 iface, DWORD Flags, CONST D3DGAMMARAMP* pRamp) {
659 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
661 TRACE("iface %p, flags %#x, ramp %p.\n", iface, Flags, pRamp);
663 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
664 wined3d_mutex_lock();
665 IWineD3DDevice_SetGammaRamp(This->WineD3DDevice, 0, Flags, (CONST WINED3DGAMMARAMP *) pRamp);
666 wined3d_mutex_unlock();
669 static void WINAPI IDirect3DDevice8Impl_GetGammaRamp(LPDIRECT3DDEVICE8 iface, D3DGAMMARAMP* pRamp) {
670 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
672 TRACE("iface %p, ramp %p.\n", iface, pRamp);
674 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
675 wined3d_mutex_lock();
676 IWineD3DDevice_GetGammaRamp(This->WineD3DDevice, 0, (WINED3DGAMMARAMP *) pRamp);
677 wined3d_mutex_unlock();
680 static HRESULT WINAPI IDirect3DDevice8Impl_CreateTexture(IDirect3DDevice8 *iface,
681 UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format,
682 D3DPOOL pool, IDirect3DTexture8 **texture)
684 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
685 IDirect3DTexture8Impl *object;
686 HRESULT hr;
688 TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
689 iface, width, height, levels, usage, format, pool, texture);
691 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
692 if (!object)
694 ERR("Failed to allocate texture memory.\n");
695 return D3DERR_OUTOFVIDEOMEMORY;
698 hr = texture_init(object, This, width, height, levels, usage, format, pool);
699 if (FAILED(hr))
701 WARN("Failed to initialize texture, hr %#x.\n", hr);
702 HeapFree(GetProcessHeap(), 0, object);
703 return hr;
706 TRACE("Created texture %p.\n", object);
707 *texture = (IDirect3DTexture8 *)object;
709 return D3D_OK;
712 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVolumeTexture(IDirect3DDevice8 *iface,
713 UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format,
714 D3DPOOL pool, IDirect3DVolumeTexture8 **texture)
716 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
717 IDirect3DVolumeTexture8Impl *object;
718 HRESULT hr;
720 TRACE("iface %p, width %u, height %u, depth %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
721 iface, width, height, depth, levels, usage, format, pool, texture);
723 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
724 if (!object)
726 ERR("Failed to allocate volume texture memory.\n");
727 return D3DERR_OUTOFVIDEOMEMORY;
730 hr = volumetexture_init(object, This, width, height, depth, levels, usage, format, pool);
731 if (FAILED(hr))
733 WARN("Failed to initialize volume texture, hr %#x.\n", hr);
734 HeapFree(GetProcessHeap(), 0, object);
735 return hr;
738 TRACE("Created volume texture %p.\n", object);
739 *texture = (IDirect3DVolumeTexture8 *)object;
741 return D3D_OK;
744 static HRESULT WINAPI IDirect3DDevice8Impl_CreateCubeTexture(IDirect3DDevice8 *iface, UINT edge_length,
745 UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool, IDirect3DCubeTexture8 **texture)
747 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
748 IDirect3DCubeTexture8Impl *object;
749 HRESULT hr;
751 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
752 iface, edge_length, levels, usage, format, pool, texture);
754 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
755 if (!object)
757 ERR("Failed to allocate cube texture memory.\n");
758 return D3DERR_OUTOFVIDEOMEMORY;
761 hr = cubetexture_init(object, This, edge_length, levels, usage, format, pool);
762 if (FAILED(hr))
764 WARN("Failed to initialize cube texture, hr %#x.\n", hr);
765 HeapFree(GetProcessHeap(), 0, object);
766 return hr;
769 TRACE("Created cube texture %p.\n", object);
770 *texture = (IDirect3DCubeTexture8 *)object;
772 return hr;
775 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexBuffer(IDirect3DDevice8 *iface, UINT size, DWORD usage,
776 DWORD fvf, D3DPOOL pool, IDirect3DVertexBuffer8 **buffer)
778 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
779 IDirect3DVertexBuffer8Impl *object;
780 HRESULT hr;
782 TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p.\n",
783 iface, size, usage, fvf, pool, buffer);
785 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
786 if (!object)
788 ERR("Failed to allocate buffer memory.\n");
789 return D3DERR_OUTOFVIDEOMEMORY;
792 hr = vertexbuffer_init(object, This, size, usage, fvf, pool);
793 if (FAILED(hr))
795 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr);
796 HeapFree(GetProcessHeap(), 0, object);
797 return hr;
800 TRACE("Created vertex buffer %p.\n", object);
801 *buffer = (IDirect3DVertexBuffer8 *)object;
803 return D3D_OK;
806 static HRESULT WINAPI IDirect3DDevice8Impl_CreateIndexBuffer(IDirect3DDevice8 *iface, UINT size, DWORD usage,
807 D3DFORMAT format, D3DPOOL pool, IDirect3DIndexBuffer8 **buffer)
809 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
810 IDirect3DIndexBuffer8Impl *object;
811 HRESULT hr;
813 TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p.\n",
814 iface, size, usage, format, pool, buffer);
816 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
817 if (!object)
819 ERR("Failed to allocate buffer memory.\n");
820 return D3DERR_OUTOFVIDEOMEMORY;
823 hr = indexbuffer_init(object, This, size, usage, format, pool);
824 if (FAILED(hr))
826 WARN("Failed to initialize index buffer, hr %#x.\n", hr);
827 HeapFree(GetProcessHeap(), 0, object);
828 return hr;
831 TRACE("Created index buffer %p.\n", object);
832 *buffer = (IDirect3DIndexBuffer8 *)object;
834 return D3D_OK;
837 static HRESULT IDirect3DDevice8Impl_CreateSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height,
838 D3DFORMAT Format, BOOL Lockable, BOOL Discard, UINT Level, IDirect3DSurface8 **ppSurface,
839 UINT Usage, D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality)
841 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
842 IDirect3DSurface8Impl *object;
843 HRESULT hr;
845 TRACE("iface %p, width %u, height %u, format %#x, lockable %#x, discard %#x, level %u, surface %p,\n"
846 "\tusage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
847 iface, Width, Height, Format, Lockable, Discard, Level, ppSurface,
848 Usage, Pool, MultiSample, MultisampleQuality);
850 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface8Impl));
851 if (!object)
853 FIXME("Failed to allocate surface memory.\n");
854 return D3DERR_OUTOFVIDEOMEMORY;
857 hr = surface_init(object, This, Width, Height, Format, Lockable, Discard,
858 Level, Usage, Pool, MultiSample, MultisampleQuality);
859 if (FAILED(hr))
861 WARN("Failed to initialize surface, hr %#x.\n", hr);
862 HeapFree(GetProcessHeap(), 0, object);
863 return hr;
866 TRACE("Created surface %p.\n", object);
867 *ppSurface = (IDirect3DSurface8 *)object;
869 return D3D_OK;
872 static HRESULT WINAPI IDirect3DDevice8Impl_CreateRenderTarget(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, BOOL Lockable, IDirect3DSurface8** ppSurface) {
873 HRESULT hr;
875 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, lockable %#x, surface %p.\n",
876 iface, Width, Height, Format, MultiSample, Lockable, ppSurface);
878 hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, Lockable, FALSE /* Discard */,
879 0 /* Level */, ppSurface, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT, MultiSample, 0);
881 return hr;
884 static HRESULT WINAPI IDirect3DDevice8Impl_CreateDepthStencilSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, IDirect3DSurface8** ppSurface) {
885 HRESULT hr;
887 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, surface %p.\n",
888 iface, Width, Height, Format, MultiSample, ppSurface);
890 /* TODO: Verify that Discard is false */
891 hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE,
892 0 /* Level */, ppSurface, D3DUSAGE_DEPTHSTENCIL, D3DPOOL_DEFAULT, MultiSample, 0);
894 return hr;
897 /* IDirect3DDevice8Impl::CreateImageSurface returns surface with pool type SYSTEMMEM */
898 static HRESULT WINAPI IDirect3DDevice8Impl_CreateImageSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, IDirect3DSurface8** ppSurface) {
899 HRESULT hr;
901 TRACE("iface %p, width %u, height %u, format %#x, surface %p.\n",
902 iface, Width, Height, Format, ppSurface);
904 hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE /* Discard */,
905 0 /* Level */, ppSurface, 0 /* Usage (undefined/none) */, D3DPOOL_SYSTEMMEM, D3DMULTISAMPLE_NONE,
906 0 /* MultisampleQuality */);
908 return hr;
911 static HRESULT WINAPI IDirect3DDevice8Impl_CopyRects(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8 *pSourceSurface, CONST RECT *pSourceRects, UINT cRects, IDirect3DSurface8 *pDestinationSurface, CONST POINT *pDestPoints) {
912 IDirect3DSurface8Impl *Source = (IDirect3DSurface8Impl *) pSourceSurface;
913 IDirect3DSurface8Impl *Dest = (IDirect3DSurface8Impl *) pDestinationSurface;
915 HRESULT hr = WINED3D_OK;
916 WINED3DFORMAT srcFormat, destFormat;
917 WINED3DSURFACE_DESC winedesc;
919 TRACE("iface %p, src_surface %p, src_rects %p, rect_count %u, dst_surface %p, dst_points %p.\n",
920 iface, pSourceSurface, pSourceRects, cRects, pDestinationSurface, pDestPoints);
922 /* Check that the source texture is in WINED3DPOOL_SYSTEMMEM and the
923 * destination texture is in WINED3DPOOL_DEFAULT. */
925 wined3d_mutex_lock();
926 IWineD3DSurface_GetDesc(Source->wineD3DSurface, &winedesc);
927 srcFormat = winedesc.format;
929 IWineD3DSurface_GetDesc(Dest->wineD3DSurface, &winedesc);
930 destFormat = winedesc.format;
932 /* Check that the source and destination formats match */
933 if (srcFormat != destFormat && WINED3DFMT_UNKNOWN != destFormat) {
934 WARN("(%p) source %p format must match the dest %p format, returning WINED3DERR_INVALIDCALL\n", iface, pSourceSurface, pDestinationSurface);
935 wined3d_mutex_unlock();
936 return WINED3DERR_INVALIDCALL;
937 } else if (WINED3DFMT_UNKNOWN == destFormat) {
938 TRACE("(%p) : Converting destination surface from WINED3DFMT_UNKNOWN to the source format\n", iface);
939 IWineD3DSurface_SetFormat(Dest->wineD3DSurface, srcFormat);
942 /* Quick if complete copy ... */
943 if (cRects == 0 && pSourceRects == NULL && pDestPoints == NULL) {
944 IWineD3DSurface_BltFast(Dest->wineD3DSurface, 0, 0, Source->wineD3DSurface, NULL, WINEDDBLTFAST_NOCOLORKEY);
945 } else {
946 unsigned int i;
947 /* Copy rect by rect */
948 if (NULL != pSourceRects && NULL != pDestPoints) {
949 for (i = 0; i < cRects; ++i) {
950 IWineD3DSurface_BltFast(Dest->wineD3DSurface, pDestPoints[i].x, pDestPoints[i].y, Source->wineD3DSurface, &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY);
952 } else {
953 for (i = 0; i < cRects; ++i) {
954 IWineD3DSurface_BltFast(Dest->wineD3DSurface, 0, 0, Source->wineD3DSurface, &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY);
958 wined3d_mutex_unlock();
960 return hr;
963 static HRESULT WINAPI IDirect3DDevice8Impl_UpdateTexture(LPDIRECT3DDEVICE8 iface, IDirect3DBaseTexture8* pSourceTexture, IDirect3DBaseTexture8* pDestinationTexture) {
964 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
965 HRESULT hr;
967 TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface, pSourceTexture, pDestinationTexture);
969 wined3d_mutex_lock();
970 hr = IWineD3DDevice_UpdateTexture(This->WineD3DDevice, ((IDirect3DBaseTexture8Impl *)pSourceTexture)->wineD3DBaseTexture, ((IDirect3DBaseTexture8Impl *)pDestinationTexture)->wineD3DBaseTexture);
971 wined3d_mutex_unlock();
973 return hr;
976 static HRESULT WINAPI IDirect3DDevice8Impl_GetFrontBuffer(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* pDestSurface) {
977 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
978 IDirect3DSurface8Impl *destSurface = (IDirect3DSurface8Impl *)pDestSurface;
979 HRESULT hr;
981 TRACE("iface %p, dst_surface %p.\n", iface, pDestSurface);
983 if (pDestSurface == NULL) {
984 WARN("(%p) : Caller passed NULL as pDestSurface returning D3DERR_INVALIDCALL\n", This);
985 return D3DERR_INVALIDCALL;
988 wined3d_mutex_lock();
989 hr = IWineD3DDevice_GetFrontBufferData(This->WineD3DDevice, 0, destSurface->wineD3DSurface);
990 wined3d_mutex_unlock();
992 return hr;
995 static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderTarget(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* pRenderTarget, IDirect3DSurface8* pNewZStencil) {
996 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
997 IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl *)pRenderTarget;
998 IDirect3DSurface8Impl *pZSurface = (IDirect3DSurface8Impl *)pNewZStencil;
999 IWineD3DSurface *original_ds = NULL;
1000 HRESULT hr;
1002 TRACE("iface %p, render_target %p, depth_stencil %p.\n", iface, pRenderTarget, pNewZStencil);
1004 wined3d_mutex_lock();
1006 hr = IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice, &original_ds);
1007 if (hr == WINED3D_OK || hr == WINED3DERR_NOTFOUND)
1009 hr = IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, pZSurface ? pZSurface->wineD3DSurface : NULL);
1010 if (SUCCEEDED(hr) && pSurface)
1011 hr = IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, 0, pSurface->wineD3DSurface, TRUE);
1012 if (FAILED(hr)) IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, original_ds);
1014 if (original_ds) IWineD3DSurface_Release(original_ds);
1016 wined3d_mutex_unlock();
1018 return hr;
1021 static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderTarget(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8** ppRenderTarget) {
1022 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1023 HRESULT hr = D3D_OK;
1024 IWineD3DSurface *pRenderTarget;
1026 TRACE("iface %p, render_target %p.\n", iface, ppRenderTarget);
1028 if (ppRenderTarget == NULL) {
1029 return D3DERR_INVALIDCALL;
1032 wined3d_mutex_lock();
1033 hr = IWineD3DDevice_GetRenderTarget(This->WineD3DDevice, 0, &pRenderTarget);
1035 if (hr == D3D_OK && pRenderTarget != NULL) {
1036 IWineD3DSurface_GetParent(pRenderTarget,(IUnknown**)ppRenderTarget);
1037 IWineD3DSurface_Release(pRenderTarget);
1038 } else {
1039 FIXME("Call to IWineD3DDevice_GetRenderTarget failed\n");
1040 *ppRenderTarget = NULL;
1042 wined3d_mutex_unlock();
1044 return hr;
1047 static HRESULT WINAPI IDirect3DDevice8Impl_GetDepthStencilSurface(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8** ppZStencilSurface) {
1048 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1049 HRESULT hr = D3D_OK;
1050 IWineD3DSurface *pZStencilSurface;
1052 TRACE("iface %p, depth_stencil %p.\n", iface, ppZStencilSurface);
1054 if(ppZStencilSurface == NULL){
1055 return D3DERR_INVALIDCALL;
1058 wined3d_mutex_lock();
1059 hr=IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice,&pZStencilSurface);
1060 if (hr == WINED3D_OK) {
1061 IWineD3DSurface_GetParent(pZStencilSurface,(IUnknown**)ppZStencilSurface);
1062 IWineD3DSurface_Release(pZStencilSurface);
1063 }else{
1064 if (hr != WINED3DERR_NOTFOUND)
1065 FIXME("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr);
1066 *ppZStencilSurface = NULL;
1068 wined3d_mutex_unlock();
1070 return hr;
1073 static HRESULT WINAPI IDirect3DDevice8Impl_BeginScene(LPDIRECT3DDEVICE8 iface) {
1074 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1075 HRESULT hr;
1077 TRACE("iface %p.\n", iface);
1079 wined3d_mutex_lock();
1080 hr = IWineD3DDevice_BeginScene(This->WineD3DDevice);
1081 wined3d_mutex_unlock();
1083 return hr;
1086 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice8Impl_EndScene(LPDIRECT3DDEVICE8 iface) {
1087 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1088 HRESULT hr;
1090 TRACE("iface %p.\n", iface);
1092 wined3d_mutex_lock();
1093 hr = IWineD3DDevice_EndScene(This->WineD3DDevice);
1094 wined3d_mutex_unlock();
1096 return hr;
1099 static HRESULT WINAPI IDirect3DDevice8Impl_Clear(LPDIRECT3DDEVICE8 iface, DWORD Count, CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) {
1100 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1101 HRESULT hr;
1103 TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
1104 iface, Count, pRects, Flags, Color, Z, Stencil);
1106 /* Note: D3DRECT is compatible with WINED3DRECT */
1107 wined3d_mutex_lock();
1108 hr = IWineD3DDevice_Clear(This->WineD3DDevice, Count, (CONST WINED3DRECT*) pRects, Flags, Color, Z, Stencil);
1109 wined3d_mutex_unlock();
1111 return hr;
1114 static HRESULT WINAPI IDirect3DDevice8Impl_SetTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* lpMatrix) {
1115 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1116 HRESULT hr;
1118 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, lpMatrix);
1120 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1121 wined3d_mutex_lock();
1122 hr = IWineD3DDevice_SetTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) lpMatrix);
1123 wined3d_mutex_unlock();
1125 return hr;
1128 static HRESULT WINAPI IDirect3DDevice8Impl_GetTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State,D3DMATRIX* pMatrix) {
1129 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1130 HRESULT hr;
1132 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
1134 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1135 wined3d_mutex_lock();
1136 hr = IWineD3DDevice_GetTransform(This->WineD3DDevice, State, (WINED3DMATRIX*) pMatrix);
1137 wined3d_mutex_unlock();
1139 return hr;
1142 static HRESULT WINAPI IDirect3DDevice8Impl_MultiplyTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix) {
1143 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1144 HRESULT hr;
1146 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
1148 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1149 wined3d_mutex_lock();
1150 hr = IWineD3DDevice_MultiplyTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) pMatrix);
1151 wined3d_mutex_unlock();
1153 return hr;
1156 static HRESULT WINAPI IDirect3DDevice8Impl_SetViewport(LPDIRECT3DDEVICE8 iface, CONST D3DVIEWPORT8* pViewport) {
1157 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1158 HRESULT hr;
1160 TRACE("iface %p, viewport %p.\n", iface, pViewport);
1162 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
1163 wined3d_mutex_lock();
1164 hr = IWineD3DDevice_SetViewport(This->WineD3DDevice, (const WINED3DVIEWPORT *)pViewport);
1165 wined3d_mutex_unlock();
1167 return hr;
1170 static HRESULT WINAPI IDirect3DDevice8Impl_GetViewport(LPDIRECT3DDEVICE8 iface, D3DVIEWPORT8* pViewport) {
1171 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1172 HRESULT hr;
1174 TRACE("iface %p, viewport %p.\n", iface, pViewport);
1176 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
1177 wined3d_mutex_lock();
1178 hr = IWineD3DDevice_GetViewport(This->WineD3DDevice, (WINED3DVIEWPORT *)pViewport);
1179 wined3d_mutex_unlock();
1181 return hr;
1184 static HRESULT WINAPI IDirect3DDevice8Impl_SetMaterial(LPDIRECT3DDEVICE8 iface, CONST D3DMATERIAL8* pMaterial) {
1185 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1186 HRESULT hr;
1188 TRACE("iface %p, material %p.\n", iface, pMaterial);
1190 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
1191 wined3d_mutex_lock();
1192 hr = IWineD3DDevice_SetMaterial(This->WineD3DDevice, (const WINED3DMATERIAL *)pMaterial);
1193 wined3d_mutex_unlock();
1195 return hr;
1198 static HRESULT WINAPI IDirect3DDevice8Impl_GetMaterial(LPDIRECT3DDEVICE8 iface, D3DMATERIAL8* pMaterial) {
1199 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1200 HRESULT hr;
1202 TRACE("iface %p, material %p.\n", iface, pMaterial);
1204 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
1205 wined3d_mutex_lock();
1206 hr = IWineD3DDevice_GetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
1207 wined3d_mutex_unlock();
1209 return hr;
1212 static HRESULT WINAPI IDirect3DDevice8Impl_SetLight(LPDIRECT3DDEVICE8 iface, DWORD Index, CONST D3DLIGHT8* pLight) {
1213 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1214 HRESULT hr;
1216 TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
1218 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1219 wined3d_mutex_lock();
1220 hr = IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (const WINED3DLIGHT *)pLight);
1221 wined3d_mutex_unlock();
1223 return hr;
1226 static HRESULT WINAPI IDirect3DDevice8Impl_GetLight(LPDIRECT3DDEVICE8 iface, DWORD Index,D3DLIGHT8* pLight) {
1227 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1228 HRESULT hr;
1230 TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
1232 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1233 wined3d_mutex_lock();
1234 hr = IWineD3DDevice_GetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
1235 wined3d_mutex_unlock();
1237 return hr;
1240 static HRESULT WINAPI IDirect3DDevice8Impl_LightEnable(LPDIRECT3DDEVICE8 iface, DWORD Index,BOOL Enable) {
1241 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1242 HRESULT hr;
1244 TRACE("iface %p, index %u, enable %#x.\n", iface, Index, Enable);
1246 wined3d_mutex_lock();
1247 hr = IWineD3DDevice_SetLightEnable(This->WineD3DDevice, Index, Enable);
1248 wined3d_mutex_unlock();
1250 return hr;
1253 static HRESULT WINAPI IDirect3DDevice8Impl_GetLightEnable(LPDIRECT3DDEVICE8 iface, DWORD Index,BOOL* pEnable) {
1254 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1255 HRESULT hr;
1257 TRACE("iface %p, index %u, enable %p.\n", iface, Index, pEnable);
1259 wined3d_mutex_lock();
1260 hr = IWineD3DDevice_GetLightEnable(This->WineD3DDevice, Index, pEnable);
1261 wined3d_mutex_unlock();
1263 return hr;
1266 static HRESULT WINAPI IDirect3DDevice8Impl_SetClipPlane(LPDIRECT3DDEVICE8 iface, DWORD Index,CONST float* pPlane) {
1267 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1268 HRESULT hr;
1270 TRACE("iface %p, index %u, plane %p.\n", iface, Index, pPlane);
1272 wined3d_mutex_lock();
1273 hr = IWineD3DDevice_SetClipPlane(This->WineD3DDevice, Index, pPlane);
1274 wined3d_mutex_unlock();
1276 return hr;
1279 static HRESULT WINAPI IDirect3DDevice8Impl_GetClipPlane(LPDIRECT3DDEVICE8 iface, DWORD Index,float* pPlane) {
1280 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1281 HRESULT hr;
1283 TRACE("iface %p, index %u, plane %p.\n", iface, Index, pPlane);
1285 wined3d_mutex_lock();
1286 hr = IWineD3DDevice_GetClipPlane(This->WineD3DDevice, Index, pPlane);
1287 wined3d_mutex_unlock();
1289 return hr;
1292 static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderState(LPDIRECT3DDEVICE8 iface, D3DRENDERSTATETYPE State,DWORD Value) {
1293 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1294 HRESULT hr;
1296 TRACE("iface %p, state %#x, value %#x.\n", iface, State, Value);
1298 wined3d_mutex_lock();
1299 hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, State, Value);
1300 wined3d_mutex_unlock();
1302 return hr;
1305 static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderState(LPDIRECT3DDEVICE8 iface, D3DRENDERSTATETYPE State,DWORD* pValue) {
1306 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1307 HRESULT hr;
1309 TRACE("iface %p, state %#x, value %p.\n", iface, State, pValue);
1311 wined3d_mutex_lock();
1312 hr = IWineD3DDevice_GetRenderState(This->WineD3DDevice, State, pValue);
1313 wined3d_mutex_unlock();
1315 return hr;
1318 static HRESULT WINAPI IDirect3DDevice8Impl_BeginStateBlock(LPDIRECT3DDEVICE8 iface) {
1319 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1320 HRESULT hr;
1322 TRACE("iface %p.\n", iface);
1324 wined3d_mutex_lock();
1325 hr = IWineD3DDevice_BeginStateBlock(This->WineD3DDevice);
1326 wined3d_mutex_unlock();
1328 return hr;
1331 static HRESULT WINAPI IDirect3DDevice8Impl_EndStateBlock(LPDIRECT3DDEVICE8 iface, DWORD* pToken) {
1332 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1333 HRESULT hr;
1334 IWineD3DStateBlock* wineD3DStateBlock;
1335 IDirect3DStateBlock8Impl* object;
1337 TRACE("iface %p, token %p.\n", iface, pToken);
1339 /* Tell wineD3D to endstateblock before anything else (in case we run out
1340 * of memory later and cause locking problems)
1342 wined3d_mutex_lock();
1343 hr = IWineD3DDevice_EndStateBlock(This->WineD3DDevice , &wineD3DStateBlock);
1344 if (hr != D3D_OK) {
1345 WARN("IWineD3DDevice_EndStateBlock returned an error\n");
1346 wined3d_mutex_unlock();
1347 return hr;
1350 /* allocate a new IDirectD3DStateBlock */
1351 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY ,sizeof(IDirect3DStateBlock8Impl));
1352 object->ref = 1;
1353 object->lpVtbl = &Direct3DStateBlock8_Vtbl;
1355 object->wineD3DStateBlock = wineD3DStateBlock;
1357 *pToken = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_SB);
1358 wined3d_mutex_unlock();
1360 if (*pToken == D3D8_INVALID_HANDLE)
1362 ERR("Failed to create a handle\n");
1363 IDirect3DStateBlock8_Release((IDirect3DStateBlock8 *)object);
1364 return E_FAIL;
1366 ++*pToken;
1368 TRACE("Returning %#x (%p).\n", *pToken, object);
1370 return hr;
1373 static HRESULT WINAPI IDirect3DDevice8Impl_ApplyStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1374 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1375 IDirect3DStateBlock8Impl *pSB;
1376 HRESULT hr;
1378 TRACE("iface %p, token %#x.\n", iface, Token);
1380 wined3d_mutex_lock();
1381 pSB = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1382 if (!pSB)
1384 WARN("Invalid handle (%#x) passed.\n", Token);
1385 wined3d_mutex_unlock();
1386 return D3DERR_INVALIDCALL;
1388 hr = IWineD3DStateBlock_Apply(pSB->wineD3DStateBlock);
1389 wined3d_mutex_unlock();
1391 return hr;
1394 static HRESULT WINAPI IDirect3DDevice8Impl_CaptureStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1395 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1396 IDirect3DStateBlock8Impl *pSB;
1397 HRESULT hr;
1399 TRACE("iface %p, token %#x.\n", iface, Token);
1401 wined3d_mutex_lock();
1402 pSB = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1403 if (!pSB)
1405 WARN("Invalid handle (%#x) passed.\n", Token);
1406 wined3d_mutex_unlock();
1407 return D3DERR_INVALIDCALL;
1409 hr = IWineD3DStateBlock_Capture(pSB->wineD3DStateBlock);
1410 wined3d_mutex_unlock();
1412 return hr;
1415 static HRESULT WINAPI IDirect3DDevice8Impl_DeleteStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1416 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1417 IDirect3DStateBlock8Impl *pSB;
1419 TRACE("iface %p, token %#x.\n", iface, Token);
1421 wined3d_mutex_lock();
1422 pSB = d3d8_free_handle(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1423 wined3d_mutex_unlock();
1425 if (!pSB)
1427 WARN("Invalid handle (%#x) passed.\n", Token);
1428 return D3DERR_INVALIDCALL;
1431 if (IUnknown_Release((IUnknown *)pSB))
1433 ERR("Stateblock %p has references left, this shouldn't happen.\n", pSB);
1436 return D3D_OK;
1439 static HRESULT WINAPI IDirect3DDevice8Impl_CreateStateBlock(IDirect3DDevice8 *iface,
1440 D3DSTATEBLOCKTYPE Type, DWORD *handle)
1442 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1443 IDirect3DStateBlock8Impl *object;
1444 HRESULT hr;
1446 TRACE("iface %p, type %#x, handle %p.\n", iface, Type, handle);
1448 if (Type != D3DSBT_ALL
1449 && Type != D3DSBT_PIXELSTATE
1450 && Type != D3DSBT_VERTEXSTATE)
1452 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL\n");
1453 return D3DERR_INVALIDCALL;
1456 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DStateBlock8Impl));
1457 if (!object)
1459 ERR("Failed to allocate memory.\n");
1460 return E_OUTOFMEMORY;
1463 object->lpVtbl = &Direct3DStateBlock8_Vtbl;
1464 object->ref = 1;
1466 wined3d_mutex_lock();
1467 hr = IWineD3DDevice_CreateStateBlock(This->WineD3DDevice, (WINED3DSTATEBLOCKTYPE)Type,
1468 &object->wineD3DStateBlock, (IUnknown *)object);
1469 if (FAILED(hr))
1471 wined3d_mutex_unlock();
1472 ERR("IWineD3DDevice_CreateStateBlock failed, hr %#x\n", hr);
1473 HeapFree(GetProcessHeap(), 0, object);
1474 return hr;
1477 *handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_SB);
1478 wined3d_mutex_unlock();
1480 if (*handle == D3D8_INVALID_HANDLE)
1482 ERR("Failed to allocate a handle.\n");
1483 IDirect3DStateBlock8_Release((IDirect3DStateBlock8 *)object);
1484 return E_FAIL;
1486 ++*handle;
1488 TRACE("Returning %#x (%p).\n", *handle, object);
1490 return hr;
1493 static HRESULT WINAPI IDirect3DDevice8Impl_SetClipStatus(LPDIRECT3DDEVICE8 iface, CONST D3DCLIPSTATUS8* pClipStatus) {
1494 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1495 HRESULT hr;
1497 TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
1498 /* FIXME: Verify that D3DCLIPSTATUS8 ~= WINED3DCLIPSTATUS */
1500 wined3d_mutex_lock();
1501 hr = IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
1502 wined3d_mutex_unlock();
1504 return hr;
1507 static HRESULT WINAPI IDirect3DDevice8Impl_GetClipStatus(LPDIRECT3DDEVICE8 iface, D3DCLIPSTATUS8* pClipStatus) {
1508 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1509 HRESULT hr;
1511 TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
1513 wined3d_mutex_lock();
1514 hr = IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
1515 wined3d_mutex_unlock();
1517 return hr;
1520 static HRESULT WINAPI IDirect3DDevice8Impl_GetTexture(LPDIRECT3DDEVICE8 iface, DWORD Stage,IDirect3DBaseTexture8** ppTexture) {
1521 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1522 IWineD3DBaseTexture *retTexture;
1523 HRESULT hr;
1525 TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, ppTexture);
1527 if(ppTexture == NULL){
1528 return D3DERR_INVALIDCALL;
1531 wined3d_mutex_lock();
1532 hr = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, &retTexture);
1533 if (FAILED(hr))
1535 WARN("Failed to get texture for stage %u, hr %#x.\n", Stage, hr);
1536 wined3d_mutex_unlock();
1537 *ppTexture = NULL;
1538 return hr;
1541 if (retTexture)
1543 IWineD3DBaseTexture_GetParent(retTexture, (IUnknown **)ppTexture);
1544 IWineD3DBaseTexture_Release(retTexture);
1546 else
1548 *ppTexture = NULL;
1550 wined3d_mutex_unlock();
1552 return D3D_OK;
1555 static HRESULT WINAPI IDirect3DDevice8Impl_SetTexture(LPDIRECT3DDEVICE8 iface, DWORD Stage, IDirect3DBaseTexture8* pTexture) {
1556 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1557 HRESULT hr;
1559 TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, pTexture);
1561 wined3d_mutex_lock();
1562 hr = IWineD3DDevice_SetTexture(This->WineD3DDevice, Stage,
1563 pTexture==NULL ? NULL : ((IDirect3DBaseTexture8Impl *)pTexture)->wineD3DBaseTexture);
1564 wined3d_mutex_unlock();
1566 return hr;
1569 static const struct tss_lookup
1571 BOOL sampler_state;
1572 DWORD state;
1574 tss_lookup[] =
1576 {FALSE, WINED3DTSS_FORCE_DWORD}, /* 0, unused */
1577 {FALSE, WINED3DTSS_COLOROP}, /* 1, D3DTSS_COLOROP */
1578 {FALSE, WINED3DTSS_COLORARG1}, /* 2, D3DTSS_COLORARG1 */
1579 {FALSE, WINED3DTSS_COLORARG2}, /* 3, D3DTSS_COLORARG2 */
1580 {FALSE, WINED3DTSS_ALPHAOP}, /* 4, D3DTSS_ALPHAOP */
1581 {FALSE, WINED3DTSS_ALPHAARG1}, /* 5, D3DTSS_ALPHAARG1 */
1582 {FALSE, WINED3DTSS_ALPHAARG2}, /* 6, D3DTSS_ALPHAARG2 */
1583 {FALSE, WINED3DTSS_BUMPENVMAT00}, /* 7, D3DTSS_BUMPENVMAT00 */
1584 {FALSE, WINED3DTSS_BUMPENVMAT01}, /* 8, D3DTSS_BUMPENVMAT01 */
1585 {FALSE, WINED3DTSS_BUMPENVMAT10}, /* 9, D3DTSS_BUMPENVMAT10 */
1586 {FALSE, WINED3DTSS_BUMPENVMAT11}, /* 10, D3DTSS_BUMPENVMAT11 */
1587 {FALSE, WINED3DTSS_TEXCOORDINDEX}, /* 11, D3DTSS_TEXCOORDINDEX */
1588 {FALSE, WINED3DTSS_FORCE_DWORD}, /* 12, unused */
1589 {TRUE, WINED3DSAMP_ADDRESSU}, /* 13, D3DTSS_ADDRESSU */
1590 {TRUE, WINED3DSAMP_ADDRESSV}, /* 14, D3DTSS_ADDRESSV */
1591 {TRUE, WINED3DSAMP_BORDERCOLOR}, /* 15, D3DTSS_BORDERCOLOR */
1592 {TRUE, WINED3DSAMP_MAGFILTER}, /* 16, D3DTSS_MAGFILTER */
1593 {TRUE, WINED3DSAMP_MINFILTER}, /* 17, D3DTSS_MINFILTER */
1594 {TRUE, WINED3DSAMP_MIPFILTER}, /* 18, D3DTSS_MIPFILTER */
1595 {TRUE, WINED3DSAMP_MIPMAPLODBIAS}, /* 19, D3DTSS_MIPMAPLODBIAS */
1596 {TRUE, WINED3DSAMP_MAXMIPLEVEL}, /* 20, D3DTSS_MAXMIPLEVEL */
1597 {TRUE, WINED3DSAMP_MAXANISOTROPY}, /* 21, D3DTSS_MAXANISOTROPY */
1598 {FALSE, WINED3DTSS_BUMPENVLSCALE}, /* 22, D3DTSS_BUMPENVLSCALE */
1599 {FALSE, WINED3DTSS_BUMPENVLOFFSET}, /* 23, D3DTSS_BUMPENVLOFFSET */
1600 {FALSE, WINED3DTSS_TEXTURETRANSFORMFLAGS}, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1601 {TRUE, WINED3DSAMP_ADDRESSW}, /* 25, D3DTSS_ADDRESSW */
1602 {FALSE, WINED3DTSS_COLORARG0}, /* 26, D3DTSS_COLORARG0 */
1603 {FALSE, WINED3DTSS_ALPHAARG0}, /* 27, D3DTSS_ALPHAARG0 */
1604 {FALSE, WINED3DTSS_RESULTARG}, /* 28, D3DTSS_RESULTARG */
1607 static HRESULT WINAPI IDirect3DDevice8Impl_GetTextureStageState(LPDIRECT3DDEVICE8 iface, DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD* pValue) {
1608 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1609 const struct tss_lookup *l = &tss_lookup[Type];
1610 HRESULT hr;
1612 TRACE("iface %p, stage %u, state %#x, value %p.\n", iface, Stage, Type, pValue);
1614 wined3d_mutex_lock();
1615 if (l->sampler_state) hr = IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Stage, l->state, pValue);
1616 else hr = IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, l->state, pValue);
1617 wined3d_mutex_unlock();
1619 return hr;
1622 static HRESULT WINAPI IDirect3DDevice8Impl_SetTextureStageState(LPDIRECT3DDEVICE8 iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value) {
1623 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1624 const struct tss_lookup *l = &tss_lookup[Type];
1625 HRESULT hr;
1627 TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface, Stage, Type, Value);
1629 wined3d_mutex_lock();
1630 if (l->sampler_state) hr = IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Stage, l->state, Value);
1631 else hr = IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, l->state, Value);
1632 wined3d_mutex_unlock();
1634 return hr;
1637 static HRESULT WINAPI IDirect3DDevice8Impl_ValidateDevice(LPDIRECT3DDEVICE8 iface, DWORD* pNumPasses) {
1638 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1639 HRESULT hr;
1641 TRACE("iface %p, pass_count %p.\n", iface, pNumPasses);
1643 wined3d_mutex_lock();
1644 hr = IWineD3DDevice_ValidateDevice(This->WineD3DDevice, pNumPasses);
1645 wined3d_mutex_unlock();
1647 return hr;
1650 static HRESULT WINAPI IDirect3DDevice8Impl_GetInfo(IDirect3DDevice8 *iface,
1651 DWORD info_id, void *info, DWORD info_size)
1653 FIXME("iface %p, info_id %#x, info %p, info_size %u stub!\n", iface, info_id, info, info_size);
1655 return D3D_OK;
1658 static HRESULT WINAPI IDirect3DDevice8Impl_SetPaletteEntries(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber, CONST PALETTEENTRY* pEntries) {
1659 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1660 HRESULT hr;
1662 TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
1664 wined3d_mutex_lock();
1665 hr = IWineD3DDevice_SetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1666 wined3d_mutex_unlock();
1668 return hr;
1671 static HRESULT WINAPI IDirect3DDevice8Impl_GetPaletteEntries(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber, PALETTEENTRY* pEntries) {
1672 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1673 HRESULT hr;
1675 TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
1677 wined3d_mutex_lock();
1678 hr = IWineD3DDevice_GetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1679 wined3d_mutex_unlock();
1681 return hr;
1684 static HRESULT WINAPI IDirect3DDevice8Impl_SetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber) {
1685 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1686 HRESULT hr;
1688 TRACE("iface %p, palette_idx %u.\n", iface, PaletteNumber);
1690 wined3d_mutex_lock();
1691 hr = IWineD3DDevice_SetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1692 wined3d_mutex_unlock();
1694 return hr;
1697 static HRESULT WINAPI IDirect3DDevice8Impl_GetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface, UINT *PaletteNumber) {
1698 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1699 HRESULT hr;
1701 TRACE("iface %p, palette_idx %p.\n", iface, PaletteNumber);
1703 wined3d_mutex_lock();
1704 hr = IWineD3DDevice_GetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1705 wined3d_mutex_unlock();
1707 return hr;
1710 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitive(IDirect3DDevice8 *iface, D3DPRIMITIVETYPE PrimitiveType,
1711 UINT StartVertex, UINT PrimitiveCount)
1713 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1714 HRESULT hr;
1716 TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
1717 iface, PrimitiveType, StartVertex, PrimitiveCount);
1719 wined3d_mutex_lock();
1720 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1721 hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, StartVertex,
1722 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount));
1723 wined3d_mutex_unlock();
1725 return hr;
1728 static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitive(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,
1729 UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount) {
1730 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1731 HRESULT hr;
1733 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, vertex_count %u, start_idx %u, primitive_count %u.\n",
1734 iface, PrimitiveType, MinVertexIndex, NumVertices, startIndex, primCount);
1736 wined3d_mutex_lock();
1737 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1738 hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, startIndex,
1739 vertex_count_from_primitive_count(PrimitiveType, primCount));
1740 wined3d_mutex_unlock();
1742 return hr;
1745 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitiveUP(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,UINT PrimitiveCount,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride) {
1746 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1747 HRESULT hr;
1749 TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
1750 iface, PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride);
1752 wined3d_mutex_lock();
1753 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1754 hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice,
1755 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount),
1756 pVertexStreamZeroData, VertexStreamZeroStride);
1757 wined3d_mutex_unlock();
1759 return hr;
1762 static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitiveUP(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,UINT MinVertexIndex,
1763 UINT NumVertexIndices,UINT PrimitiveCount,CONST void* pIndexData,
1764 D3DFORMAT IndexDataFormat,CONST void* pVertexStreamZeroData,
1765 UINT VertexStreamZeroStride) {
1766 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1767 HRESULT hr;
1769 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, index_count %u, primitive_count %u,\n"
1770 "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
1771 iface, PrimitiveType, MinVertexIndex, NumVertexIndices, PrimitiveCount,
1772 pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride);
1774 wined3d_mutex_lock();
1775 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1776 hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice,
1777 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount), pIndexData,
1778 wined3dformat_from_d3dformat(IndexDataFormat), pVertexStreamZeroData, VertexStreamZeroStride);
1779 wined3d_mutex_unlock();
1781 return hr;
1784 static HRESULT WINAPI IDirect3DDevice8Impl_ProcessVertices(LPDIRECT3DDEVICE8 iface, UINT SrcStartIndex,UINT DestIndex,UINT VertexCount,IDirect3DVertexBuffer8* pDestBuffer,DWORD Flags) {
1785 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1786 HRESULT hr;
1787 IDirect3DVertexBuffer8Impl *dest = (IDirect3DVertexBuffer8Impl *) pDestBuffer;
1789 TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, flags %#x.\n",
1790 iface, SrcStartIndex, DestIndex, VertexCount, pDestBuffer, Flags);
1792 wined3d_mutex_lock();
1793 hr = IWineD3DDevice_ProcessVertices(This->WineD3DDevice,SrcStartIndex, DestIndex, VertexCount, dest->wineD3DVertexBuffer, NULL, Flags, dest->fvf);
1794 wined3d_mutex_unlock();
1796 return hr;
1799 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexShader(IDirect3DDevice8 *iface,
1800 const DWORD *declaration, const DWORD *byte_code, DWORD *shader, DWORD usage)
1802 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1803 IDirect3DVertexShader8Impl *object;
1804 DWORD shader_handle;
1805 DWORD handle;
1806 HRESULT hr;
1808 TRACE("iface %p, declaration %p, byte_code %p, shader %p, usage %#x.\n",
1809 iface, declaration, byte_code, shader, usage);
1811 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1812 if (!object)
1814 ERR("Failed to allocate vertex shader memory.\n");
1815 *shader = 0;
1816 return E_OUTOFMEMORY;
1819 wined3d_mutex_lock();
1820 handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_VS);
1821 wined3d_mutex_unlock();
1822 if (handle == D3D8_INVALID_HANDLE)
1824 ERR("Failed to allocate vertex shader handle.\n");
1825 HeapFree(GetProcessHeap(), 0, object);
1826 *shader = 0;
1827 return E_OUTOFMEMORY;
1830 shader_handle = handle + VS_HIGHESTFIXEDFXF + 1;
1832 hr = vertexshader_init(object, This, declaration, byte_code, shader_handle, usage);
1833 if (FAILED(hr))
1835 WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
1836 wined3d_mutex_lock();
1837 d3d8_free_handle(&This->handle_table, handle, D3D8_HANDLE_VS);
1838 wined3d_mutex_unlock();
1839 HeapFree(GetProcessHeap(), 0, object);
1840 *shader = 0;
1841 return hr;
1844 TRACE("Created vertex shader %p (handle %#x).\n", object, shader_handle);
1845 *shader = shader_handle;
1847 return D3D_OK;
1850 static IDirect3DVertexDeclaration8Impl *IDirect3DDevice8Impl_FindDecl(IDirect3DDevice8Impl *This, DWORD fvf)
1852 IDirect3DVertexDeclaration8Impl *d3d8_declaration;
1853 HRESULT hr;
1854 int p, low, high; /* deliberately signed */
1855 struct FvfToDecl *convertedDecls = This->decls;
1857 TRACE("Searching for declaration for fvf %08x... ", fvf);
1859 low = 0;
1860 high = This->numConvertedDecls - 1;
1861 while(low <= high) {
1862 p = (low + high) >> 1;
1863 TRACE("%d ", p);
1864 if(convertedDecls[p].fvf == fvf) {
1865 TRACE("found %p\n", convertedDecls[p].decl);
1866 return (IDirect3DVertexDeclaration8Impl *)convertedDecls[p].decl;
1867 } else if(convertedDecls[p].fvf < fvf) {
1868 low = p + 1;
1869 } else {
1870 high = p - 1;
1873 TRACE("not found. Creating and inserting at position %d.\n", low);
1875 d3d8_declaration = HeapAlloc(GetProcessHeap(), 0, sizeof(*d3d8_declaration));
1876 if (!d3d8_declaration)
1878 ERR("Memory allocation failed.\n");
1879 return NULL;
1882 hr = vertexdeclaration_init_fvf(d3d8_declaration, This, fvf);
1883 if (FAILED(hr))
1885 WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
1886 HeapFree(GetProcessHeap(), 0, d3d8_declaration);
1887 return NULL;
1890 if(This->declArraySize == This->numConvertedDecls) {
1891 int grow = This->declArraySize / 2;
1892 convertedDecls = HeapReAlloc(GetProcessHeap(), 0, convertedDecls,
1893 sizeof(convertedDecls[0]) * (This->numConvertedDecls + grow));
1894 if(!convertedDecls) {
1895 /* This will destroy it */
1896 IDirect3DVertexDeclaration8_Release((IDirect3DVertexDeclaration8 *)d3d8_declaration);
1897 return NULL;
1899 This->decls = convertedDecls;
1900 This->declArraySize += grow;
1903 memmove(convertedDecls + low + 1, convertedDecls + low, sizeof(convertedDecls[0]) * (This->numConvertedDecls - low));
1904 convertedDecls[low].decl = (IDirect3DVertexDeclaration8 *)d3d8_declaration;
1905 convertedDecls[low].fvf = fvf;
1906 This->numConvertedDecls++;
1908 TRACE("Returning %p. %u decls in array\n", d3d8_declaration, This->numConvertedDecls);
1909 return d3d8_declaration;
1912 static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
1913 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1914 IDirect3DVertexShader8Impl *shader;
1915 HRESULT hr;
1917 TRACE("iface %p, shader %#x.\n", iface, pShader);
1919 if (VS_HIGHESTFIXEDFXF >= pShader) {
1920 TRACE("Setting FVF, %#x\n", pShader);
1922 wined3d_mutex_lock();
1923 IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
1924 IDirect3DDevice8Impl_FindDecl(This, pShader)->wined3d_vertex_declaration);
1925 IWineD3DDevice_SetVertexShader(This->WineD3DDevice, NULL);
1926 wined3d_mutex_unlock();
1928 return D3D_OK;
1931 TRACE("Setting shader\n");
1933 wined3d_mutex_lock();
1934 shader = d3d8_get_object(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
1935 if (!shader)
1937 WARN("Invalid handle (%#x) passed.\n", pShader);
1938 wined3d_mutex_unlock();
1940 return D3DERR_INVALIDCALL;
1943 hr = IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
1944 ((IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration)->wined3d_vertex_declaration);
1945 if (SUCCEEDED(hr)) hr = IWineD3DDevice_SetVertexShader(This->WineD3DDevice, shader->wineD3DVertexShader);
1946 wined3d_mutex_unlock();
1948 TRACE("Returning hr %#x\n", hr);
1950 return hr;
1953 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShader(LPDIRECT3DDEVICE8 iface, DWORD* ppShader) {
1954 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1955 IWineD3DVertexDeclaration *wined3d_declaration;
1956 IDirect3DVertexDeclaration8 *d3d8_declaration;
1957 HRESULT hrc;
1959 TRACE("iface %p, shader %p.\n", iface, ppShader);
1961 wined3d_mutex_lock();
1962 hrc = IWineD3DDevice_GetVertexDeclaration(This->WineD3DDevice, &wined3d_declaration);
1963 if (FAILED(hrc))
1965 wined3d_mutex_unlock();
1966 WARN("(%p) : Call to IWineD3DDevice_GetVertexDeclaration failed %#x (device %p)\n",
1967 This, hrc, This->WineD3DDevice);
1968 return hrc;
1971 if (!wined3d_declaration)
1973 wined3d_mutex_unlock();
1974 *ppShader = 0;
1975 return D3D_OK;
1978 hrc = IWineD3DVertexDeclaration_GetParent(wined3d_declaration, (IUnknown **)&d3d8_declaration);
1979 IWineD3DVertexDeclaration_Release(wined3d_declaration);
1980 wined3d_mutex_unlock();
1981 if (SUCCEEDED(hrc))
1983 *ppShader = ((IDirect3DVertexDeclaration8Impl *)d3d8_declaration)->shader_handle;
1984 IDirect3DVertexDeclaration8_Release(d3d8_declaration);
1987 TRACE("(%p) : returning %#x\n", This, *ppShader);
1989 return hrc;
1992 static HRESULT WINAPI IDirect3DDevice8Impl_DeleteVertexShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
1993 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1994 IDirect3DVertexShader8Impl *shader;
1995 IWineD3DVertexShader *cur = NULL;
1997 TRACE("iface %p, shader %#x.\n", iface, pShader);
1999 wined3d_mutex_lock();
2000 shader = d3d8_free_handle(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2001 if (!shader)
2003 WARN("Invalid handle (%#x) passed.\n", pShader);
2004 wined3d_mutex_unlock();
2006 return D3DERR_INVALIDCALL;
2009 IWineD3DDevice_GetVertexShader(This->WineD3DDevice, &cur);
2011 if (cur)
2013 if (cur == shader->wineD3DVertexShader) IDirect3DDevice8_SetVertexShader(iface, 0);
2014 IWineD3DVertexShader_Release(cur);
2017 wined3d_mutex_unlock();
2019 if (IUnknown_Release((IUnknown *)shader))
2021 ERR("Shader %p has references left, this shouldn't happen.\n", shader);
2024 return D3D_OK;
2027 static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, CONST void* pConstantData, DWORD ConstantCount) {
2028 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2029 HRESULT hr;
2031 TRACE("iface %p, register %u, data %p, count %u.\n",
2032 iface, Register, pConstantData, ConstantCount);
2034 if(Register + ConstantCount > D3D8_MAX_VERTEX_SHADER_CONSTANTF) {
2035 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2036 Register + ConstantCount, D3D8_MAX_VERTEX_SHADER_CONSTANTF);
2037 return D3DERR_INVALIDCALL;
2040 wined3d_mutex_lock();
2041 hr = IWineD3DDevice_SetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2042 wined3d_mutex_unlock();
2044 return hr;
2047 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, void* pConstantData, DWORD ConstantCount) {
2048 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2049 HRESULT hr;
2051 TRACE("iface %p, register %u, data %p, count %u.\n",
2052 iface, Register, pConstantData, ConstantCount);
2054 if(Register + ConstantCount > D3D8_MAX_VERTEX_SHADER_CONSTANTF) {
2055 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2056 Register + ConstantCount, D3D8_MAX_VERTEX_SHADER_CONSTANTF);
2057 return D3DERR_INVALIDCALL;
2060 wined3d_mutex_lock();
2061 hr = IWineD3DDevice_GetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2062 wined3d_mutex_unlock();
2064 return hr;
2067 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderDeclaration(LPDIRECT3DDEVICE8 iface, DWORD pVertexShader, void* pData, DWORD* pSizeOfData) {
2068 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2069 IDirect3DVertexDeclaration8Impl *declaration;
2070 IDirect3DVertexShader8Impl *shader;
2072 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2073 iface, pVertexShader, pData, pSizeOfData);
2075 wined3d_mutex_lock();
2076 shader = d3d8_get_object(&This->handle_table, pVertexShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2077 wined3d_mutex_unlock();
2079 if (!shader)
2081 WARN("Invalid handle (%#x) passed.\n", pVertexShader);
2082 return D3DERR_INVALIDCALL;
2084 declaration = (IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration;
2086 /* If pData is NULL, we just return the required size of the buffer. */
2087 if (!pData) {
2088 *pSizeOfData = declaration->elements_size;
2089 return D3D_OK;
2092 /* MSDN claims that if *pSizeOfData is smaller than the required size
2093 * we should write the required size and return D3DERR_MOREDATA.
2094 * That's not actually true. */
2095 if (*pSizeOfData < declaration->elements_size) {
2096 return D3DERR_INVALIDCALL;
2099 CopyMemory(pData, declaration->elements, declaration->elements_size);
2101 return D3D_OK;
2104 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderFunction(LPDIRECT3DDEVICE8 iface, DWORD pVertexShader, void* pData, DWORD* pSizeOfData) {
2105 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2106 IDirect3DVertexShader8Impl *shader = NULL;
2107 HRESULT hr;
2109 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2110 iface, pVertexShader, pData, pSizeOfData);
2112 wined3d_mutex_lock();
2113 shader = d3d8_get_object(&This->handle_table, pVertexShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2114 if (!shader)
2116 WARN("Invalid handle (%#x) passed.\n", pVertexShader);
2117 wined3d_mutex_unlock();
2119 return D3DERR_INVALIDCALL;
2122 if (!shader->wineD3DVertexShader)
2124 wined3d_mutex_unlock();
2125 *pSizeOfData = 0;
2126 return D3D_OK;
2129 hr = IWineD3DVertexShader_GetFunction(shader->wineD3DVertexShader, pData, pSizeOfData);
2130 wined3d_mutex_unlock();
2132 return hr;
2135 static HRESULT WINAPI IDirect3DDevice8Impl_SetIndices(LPDIRECT3DDEVICE8 iface, IDirect3DIndexBuffer8* pIndexData, UINT baseVertexIndex) {
2136 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2137 HRESULT hr;
2138 IDirect3DIndexBuffer8Impl *ib = (IDirect3DIndexBuffer8Impl *)pIndexData;
2140 TRACE("iface %p, buffer %p, base_vertex_idx %u.\n", iface, pIndexData, baseVertexIndex);
2142 /* WineD3D takes an INT(due to d3d9), but d3d8 uses UINTs. Do I have to add a check here that
2143 * the UINT doesn't cause an overflow in the INT? It seems rather unlikely because such large
2144 * vertex buffers can't be created to address them with an index that requires the 32nd bit
2145 * (4 Byte minimum vertex size * 2^31-1 -> 8 gb buffer. The index sign would be the least
2146 * problem)
2148 wined3d_mutex_lock();
2149 IWineD3DDevice_SetBaseVertexIndex(This->WineD3DDevice, baseVertexIndex);
2150 hr = IWineD3DDevice_SetIndexBuffer(This->WineD3DDevice,
2151 ib ? ib->wineD3DIndexBuffer : NULL,
2152 ib ? ib->format : WINED3DFMT_UNKNOWN);
2153 wined3d_mutex_unlock();
2155 return hr;
2158 static HRESULT WINAPI IDirect3DDevice8Impl_GetIndices(LPDIRECT3DDEVICE8 iface, IDirect3DIndexBuffer8** ppIndexData,UINT* pBaseVertexIndex) {
2159 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2160 IWineD3DBuffer *retIndexData = NULL;
2161 HRESULT rc = D3D_OK;
2163 TRACE("iface %p, buffer %p, base_vertex_index %p.\n", iface, ppIndexData, pBaseVertexIndex);
2165 if(ppIndexData == NULL){
2166 return D3DERR_INVALIDCALL;
2169 /* The case from UINT to INT is safe because d3d8 will never set negative values */
2170 wined3d_mutex_lock();
2171 IWineD3DDevice_GetBaseVertexIndex(This->WineD3DDevice, (INT *) pBaseVertexIndex);
2172 rc = IWineD3DDevice_GetIndexBuffer(This->WineD3DDevice, &retIndexData);
2173 if (SUCCEEDED(rc) && retIndexData) {
2174 IWineD3DBuffer_GetParent(retIndexData, (IUnknown **)ppIndexData);
2175 IWineD3DBuffer_Release(retIndexData);
2176 } else {
2177 if (FAILED(rc)) FIXME("Call to GetIndices failed\n");
2178 *ppIndexData = NULL;
2180 wined3d_mutex_unlock();
2182 return rc;
2185 static HRESULT WINAPI IDirect3DDevice8Impl_CreatePixelShader(IDirect3DDevice8 *iface,
2186 const DWORD *byte_code, DWORD *shader)
2188 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2189 IDirect3DPixelShader8Impl *object;
2190 DWORD shader_handle;
2191 DWORD handle;
2192 HRESULT hr;
2194 TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
2196 if (!shader)
2198 TRACE("(%p) Invalid call\n", This);
2199 return D3DERR_INVALIDCALL;
2202 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2203 if (!object)
2205 ERR("Failed to allocate pixel shader memmory.\n");
2206 return E_OUTOFMEMORY;
2209 wined3d_mutex_lock();
2210 handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_PS);
2211 wined3d_mutex_unlock();
2212 if (handle == D3D8_INVALID_HANDLE)
2214 ERR("Failed to allocate pixel shader handle.\n");
2215 HeapFree(GetProcessHeap(), 0, object);
2216 return E_OUTOFMEMORY;
2219 shader_handle = handle + VS_HIGHESTFIXEDFXF + 1;
2221 hr = pixelshader_init(object, This, byte_code, shader_handle);
2222 if (FAILED(hr))
2224 WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
2225 wined3d_mutex_lock();
2226 d3d8_free_handle(&This->handle_table, handle, D3D8_HANDLE_PS);
2227 wined3d_mutex_unlock();
2228 HeapFree(GetProcessHeap(), 0, object);
2229 *shader = 0;
2230 return hr;
2233 TRACE("Created pixel shader %p (handle %#x).\n", object, shader_handle);
2234 *shader = shader_handle;
2236 return D3D_OK;
2239 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
2240 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2241 IDirect3DPixelShader8Impl *shader;
2242 HRESULT hr;
2244 TRACE("iface %p, shader %#x.\n", iface, pShader);
2246 wined3d_mutex_lock();
2248 if (!pShader)
2250 hr = IWineD3DDevice_SetPixelShader(This->WineD3DDevice, NULL);
2251 wined3d_mutex_unlock();
2252 return hr;
2255 shader = d3d8_get_object(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2256 if (!shader)
2258 WARN("Invalid handle (%#x) passed.\n", pShader);
2259 wined3d_mutex_unlock();
2260 return D3DERR_INVALIDCALL;
2263 TRACE("(%p) : Setting shader %p\n", This, shader);
2264 hr = IWineD3DDevice_SetPixelShader(This->WineD3DDevice, shader->wineD3DPixelShader);
2265 wined3d_mutex_unlock();
2267 return hr;
2270 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShader(LPDIRECT3DDEVICE8 iface, DWORD* ppShader) {
2271 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2272 IWineD3DPixelShader *object;
2273 HRESULT hrc = D3D_OK;
2275 TRACE("iface %p, shader %p.\n", iface, ppShader);
2277 if (NULL == ppShader) {
2278 TRACE("(%p) Invalid call\n", This);
2279 return D3DERR_INVALIDCALL;
2282 wined3d_mutex_lock();
2283 hrc = IWineD3DDevice_GetPixelShader(This->WineD3DDevice, &object);
2284 if (D3D_OK == hrc && NULL != object) {
2285 IDirect3DPixelShader8Impl *d3d8_shader;
2286 hrc = IWineD3DPixelShader_GetParent(object, (IUnknown **)&d3d8_shader);
2287 IWineD3DPixelShader_Release(object);
2288 *ppShader = d3d8_shader->handle;
2289 IDirect3DPixelShader8_Release((IDirect3DPixelShader8 *)d3d8_shader);
2290 } else {
2291 *ppShader = 0;
2293 wined3d_mutex_unlock();
2295 TRACE("(%p) : returning %#x\n", This, *ppShader);
2297 return hrc;
2300 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePixelShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
2301 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2302 IDirect3DPixelShader8Impl *shader;
2303 IWineD3DPixelShader *cur = NULL;
2305 TRACE("iface %p, shader %#x.\n", iface, pShader);
2307 wined3d_mutex_lock();
2309 shader = d3d8_free_handle(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2310 if (!shader)
2312 WARN("Invalid handle (%#x) passed.\n", pShader);
2313 wined3d_mutex_unlock();
2314 return D3D_OK;
2317 IWineD3DDevice_GetPixelShader(This->WineD3DDevice, &cur);
2319 if (cur)
2321 if (cur == shader->wineD3DPixelShader) IDirect3DDevice8_SetPixelShader(iface, 0);
2322 IWineD3DPixelShader_Release(cur);
2325 wined3d_mutex_unlock();
2327 if (IUnknown_Release((IUnknown *)shader))
2329 ERR("Shader %p has references left, this shouldn't happen.\n", shader);
2332 return D3D_OK;
2335 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, CONST void* pConstantData, DWORD ConstantCount) {
2336 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2337 HRESULT hr;
2339 TRACE("iface %p, register %u, data %p, count %u.\n",
2340 iface, Register, pConstantData, ConstantCount);
2342 wined3d_mutex_lock();
2343 hr = IWineD3DDevice_SetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2344 wined3d_mutex_unlock();
2346 return hr;
2349 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, void* pConstantData, DWORD ConstantCount) {
2350 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2351 HRESULT hr;
2353 TRACE("iface %p, register %u, data %p, count %u.\n",
2354 iface, Register, pConstantData, ConstantCount);
2356 wined3d_mutex_lock();
2357 hr = IWineD3DDevice_GetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2358 wined3d_mutex_unlock();
2360 return hr;
2363 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderFunction(LPDIRECT3DDEVICE8 iface, DWORD pPixelShader, void* pData, DWORD* pSizeOfData) {
2364 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2365 IDirect3DPixelShader8Impl *shader = NULL;
2366 HRESULT hr;
2368 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2369 iface, pPixelShader, pData, pSizeOfData);
2371 wined3d_mutex_lock();
2372 shader = d3d8_get_object(&This->handle_table, pPixelShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2373 if (!shader)
2375 WARN("Invalid handle (%#x) passed.\n", pPixelShader);
2376 wined3d_mutex_unlock();
2378 return D3DERR_INVALIDCALL;
2381 hr = IWineD3DPixelShader_GetFunction(shader->wineD3DPixelShader, pData, pSizeOfData);
2382 wined3d_mutex_unlock();
2384 return hr;
2387 static HRESULT WINAPI IDirect3DDevice8Impl_DrawRectPatch(LPDIRECT3DDEVICE8 iface, UINT Handle,CONST float* pNumSegs,CONST D3DRECTPATCH_INFO* pRectPatchInfo) {
2388 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2389 HRESULT hr;
2391 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2392 iface, Handle, pNumSegs, pRectPatchInfo);
2394 wined3d_mutex_lock();
2395 hr = IWineD3DDevice_DrawRectPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DRECTPATCH_INFO *)pRectPatchInfo);
2396 wined3d_mutex_unlock();
2398 return hr;
2401 static HRESULT WINAPI IDirect3DDevice8Impl_DrawTriPatch(LPDIRECT3DDEVICE8 iface, UINT Handle,CONST float* pNumSegs,CONST D3DTRIPATCH_INFO* pTriPatchInfo) {
2402 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2403 HRESULT hr;
2405 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2406 iface, Handle, pNumSegs, pTriPatchInfo);
2408 wined3d_mutex_lock();
2409 hr = IWineD3DDevice_DrawTriPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DTRIPATCH_INFO *)pTriPatchInfo);
2410 wined3d_mutex_unlock();
2412 return hr;
2415 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePatch(LPDIRECT3DDEVICE8 iface, UINT Handle) {
2416 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2417 HRESULT hr;
2419 TRACE("iface %p, handle %#x.\n", iface, Handle);
2421 wined3d_mutex_lock();
2422 hr = IWineD3DDevice_DeletePatch(This->WineD3DDevice, Handle);
2423 wined3d_mutex_unlock();
2425 return hr;
2428 static HRESULT WINAPI IDirect3DDevice8Impl_SetStreamSource(LPDIRECT3DDEVICE8 iface, UINT StreamNumber,IDirect3DVertexBuffer8* pStreamData,UINT Stride) {
2429 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2430 HRESULT hr;
2432 TRACE("iface %p, stream_idx %u, buffer %p, stride %u.\n",
2433 iface, StreamNumber, pStreamData, Stride);
2435 wined3d_mutex_lock();
2436 hr = IWineD3DDevice_SetStreamSource(This->WineD3DDevice, StreamNumber,
2437 NULL == pStreamData ? NULL : ((IDirect3DVertexBuffer8Impl *)pStreamData)->wineD3DVertexBuffer,
2438 0/* Offset in bytes */, Stride);
2439 wined3d_mutex_unlock();
2441 return hr;
2444 static HRESULT WINAPI IDirect3DDevice8Impl_GetStreamSource(LPDIRECT3DDEVICE8 iface, UINT StreamNumber,IDirect3DVertexBuffer8** pStream,UINT* pStride) {
2445 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2446 IWineD3DBuffer *retStream = NULL;
2447 HRESULT rc = D3D_OK;
2449 TRACE("iface %p, stream_idx %u, buffer %p, stride %p.\n",
2450 iface, StreamNumber, pStream, pStride);
2452 if(pStream == NULL){
2453 return D3DERR_INVALIDCALL;
2456 wined3d_mutex_lock();
2457 rc = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber, &retStream, 0 /* Offset in bytes */, pStride);
2458 if (rc == D3D_OK && NULL != retStream) {
2459 IWineD3DBuffer_GetParent(retStream, (IUnknown **)pStream);
2460 IWineD3DBuffer_Release(retStream);
2461 }else{
2462 if (rc != D3D_OK){
2463 FIXME("Call to GetStreamSource failed %p\n", pStride);
2465 *pStream = NULL;
2467 wined3d_mutex_unlock();
2469 return rc;
2473 const IDirect3DDevice8Vtbl Direct3DDevice8_Vtbl =
2475 IDirect3DDevice8Impl_QueryInterface,
2476 IDirect3DDevice8Impl_AddRef,
2477 IDirect3DDevice8Impl_Release,
2478 IDirect3DDevice8Impl_TestCooperativeLevel,
2479 IDirect3DDevice8Impl_GetAvailableTextureMem,
2480 IDirect3DDevice8Impl_ResourceManagerDiscardBytes,
2481 IDirect3DDevice8Impl_GetDirect3D,
2482 IDirect3DDevice8Impl_GetDeviceCaps,
2483 IDirect3DDevice8Impl_GetDisplayMode,
2484 IDirect3DDevice8Impl_GetCreationParameters,
2485 IDirect3DDevice8Impl_SetCursorProperties,
2486 IDirect3DDevice8Impl_SetCursorPosition,
2487 IDirect3DDevice8Impl_ShowCursor,
2488 IDirect3DDevice8Impl_CreateAdditionalSwapChain,
2489 IDirect3DDevice8Impl_Reset,
2490 IDirect3DDevice8Impl_Present,
2491 IDirect3DDevice8Impl_GetBackBuffer,
2492 IDirect3DDevice8Impl_GetRasterStatus,
2493 IDirect3DDevice8Impl_SetGammaRamp,
2494 IDirect3DDevice8Impl_GetGammaRamp,
2495 IDirect3DDevice8Impl_CreateTexture,
2496 IDirect3DDevice8Impl_CreateVolumeTexture,
2497 IDirect3DDevice8Impl_CreateCubeTexture,
2498 IDirect3DDevice8Impl_CreateVertexBuffer,
2499 IDirect3DDevice8Impl_CreateIndexBuffer,
2500 IDirect3DDevice8Impl_CreateRenderTarget,
2501 IDirect3DDevice8Impl_CreateDepthStencilSurface,
2502 IDirect3DDevice8Impl_CreateImageSurface,
2503 IDirect3DDevice8Impl_CopyRects,
2504 IDirect3DDevice8Impl_UpdateTexture,
2505 IDirect3DDevice8Impl_GetFrontBuffer,
2506 IDirect3DDevice8Impl_SetRenderTarget,
2507 IDirect3DDevice8Impl_GetRenderTarget,
2508 IDirect3DDevice8Impl_GetDepthStencilSurface,
2509 IDirect3DDevice8Impl_BeginScene,
2510 IDirect3DDevice8Impl_EndScene,
2511 IDirect3DDevice8Impl_Clear,
2512 IDirect3DDevice8Impl_SetTransform,
2513 IDirect3DDevice8Impl_GetTransform,
2514 IDirect3DDevice8Impl_MultiplyTransform,
2515 IDirect3DDevice8Impl_SetViewport,
2516 IDirect3DDevice8Impl_GetViewport,
2517 IDirect3DDevice8Impl_SetMaterial,
2518 IDirect3DDevice8Impl_GetMaterial,
2519 IDirect3DDevice8Impl_SetLight,
2520 IDirect3DDevice8Impl_GetLight,
2521 IDirect3DDevice8Impl_LightEnable,
2522 IDirect3DDevice8Impl_GetLightEnable,
2523 IDirect3DDevice8Impl_SetClipPlane,
2524 IDirect3DDevice8Impl_GetClipPlane,
2525 IDirect3DDevice8Impl_SetRenderState,
2526 IDirect3DDevice8Impl_GetRenderState,
2527 IDirect3DDevice8Impl_BeginStateBlock,
2528 IDirect3DDevice8Impl_EndStateBlock,
2529 IDirect3DDevice8Impl_ApplyStateBlock,
2530 IDirect3DDevice8Impl_CaptureStateBlock,
2531 IDirect3DDevice8Impl_DeleteStateBlock,
2532 IDirect3DDevice8Impl_CreateStateBlock,
2533 IDirect3DDevice8Impl_SetClipStatus,
2534 IDirect3DDevice8Impl_GetClipStatus,
2535 IDirect3DDevice8Impl_GetTexture,
2536 IDirect3DDevice8Impl_SetTexture,
2537 IDirect3DDevice8Impl_GetTextureStageState,
2538 IDirect3DDevice8Impl_SetTextureStageState,
2539 IDirect3DDevice8Impl_ValidateDevice,
2540 IDirect3DDevice8Impl_GetInfo,
2541 IDirect3DDevice8Impl_SetPaletteEntries,
2542 IDirect3DDevice8Impl_GetPaletteEntries,
2543 IDirect3DDevice8Impl_SetCurrentTexturePalette,
2544 IDirect3DDevice8Impl_GetCurrentTexturePalette,
2545 IDirect3DDevice8Impl_DrawPrimitive,
2546 IDirect3DDevice8Impl_DrawIndexedPrimitive,
2547 IDirect3DDevice8Impl_DrawPrimitiveUP,
2548 IDirect3DDevice8Impl_DrawIndexedPrimitiveUP,
2549 IDirect3DDevice8Impl_ProcessVertices,
2550 IDirect3DDevice8Impl_CreateVertexShader,
2551 IDirect3DDevice8Impl_SetVertexShader,
2552 IDirect3DDevice8Impl_GetVertexShader,
2553 IDirect3DDevice8Impl_DeleteVertexShader,
2554 IDirect3DDevice8Impl_SetVertexShaderConstant,
2555 IDirect3DDevice8Impl_GetVertexShaderConstant,
2556 IDirect3DDevice8Impl_GetVertexShaderDeclaration,
2557 IDirect3DDevice8Impl_GetVertexShaderFunction,
2558 IDirect3DDevice8Impl_SetStreamSource,
2559 IDirect3DDevice8Impl_GetStreamSource,
2560 IDirect3DDevice8Impl_SetIndices,
2561 IDirect3DDevice8Impl_GetIndices,
2562 IDirect3DDevice8Impl_CreatePixelShader,
2563 IDirect3DDevice8Impl_SetPixelShader,
2564 IDirect3DDevice8Impl_GetPixelShader,
2565 IDirect3DDevice8Impl_DeletePixelShader,
2566 IDirect3DDevice8Impl_SetPixelShaderConstant,
2567 IDirect3DDevice8Impl_GetPixelShaderConstant,
2568 IDirect3DDevice8Impl_GetPixelShaderFunction,
2569 IDirect3DDevice8Impl_DrawRectPatch,
2570 IDirect3DDevice8Impl_DrawTriPatch,
2571 IDirect3DDevice8Impl_DeletePatch
2574 /* IWineD3DDeviceParent IUnknown methods */
2576 static inline struct IDirect3DDevice8Impl *device_from_device_parent(IWineD3DDeviceParent *iface)
2578 return (struct IDirect3DDevice8Impl *)((char*)iface
2579 - FIELD_OFFSET(struct IDirect3DDevice8Impl, device_parent_vtbl));
2582 static HRESULT STDMETHODCALLTYPE device_parent_QueryInterface(IWineD3DDeviceParent *iface, REFIID riid, void **object)
2584 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2585 return IDirect3DDevice8Impl_QueryInterface((IDirect3DDevice8 *)This, riid, object);
2588 static ULONG STDMETHODCALLTYPE device_parent_AddRef(IWineD3DDeviceParent *iface)
2590 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2591 return IDirect3DDevice8Impl_AddRef((IDirect3DDevice8 *)This);
2594 static ULONG STDMETHODCALLTYPE device_parent_Release(IWineD3DDeviceParent *iface)
2596 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2597 return IDirect3DDevice8Impl_Release((IDirect3DDevice8 *)This);
2600 /* IWineD3DDeviceParent methods */
2602 static void STDMETHODCALLTYPE device_parent_WineD3DDeviceCreated(IWineD3DDeviceParent *iface, IWineD3DDevice *device)
2604 TRACE("iface %p, device %p\n", iface, device);
2607 static HRESULT STDMETHODCALLTYPE device_parent_CreateSurface(IWineD3DDeviceParent *iface,
2608 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, DWORD usage,
2609 WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, IWineD3DSurface **surface)
2611 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2612 IDirect3DSurface8Impl *d3d_surface;
2613 BOOL lockable = TRUE;
2614 HRESULT hr;
2616 TRACE("iface %p, superior %p, width %u, height %u, format %#x, usage %#x,\n"
2617 "\tpool %#x, level %u, face %u, surface %p\n",
2618 iface, superior, width, height, format, usage, pool, level, face, surface);
2621 if (pool == WINED3DPOOL_DEFAULT && !(usage & WINED3DUSAGE_DYNAMIC)) lockable = FALSE;
2623 hr = IDirect3DDevice8Impl_CreateSurface((IDirect3DDevice8 *)This, width, height,
2624 d3dformat_from_wined3dformat(format), lockable, FALSE /* Discard */, level,
2625 (IDirect3DSurface8 **)&d3d_surface, usage, pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
2626 if (FAILED(hr))
2628 ERR("(%p) CreateSurface failed, returning %#x\n", iface, hr);
2629 return hr;
2632 *surface = d3d_surface->wineD3DSurface;
2633 IWineD3DSurface_AddRef(*surface);
2635 d3d_surface->container = superior;
2636 IUnknown_Release(d3d_surface->parentDevice);
2637 d3d_surface->parentDevice = NULL;
2639 IDirect3DSurface8_Release((IDirect3DSurface8 *)d3d_surface);
2640 d3d_surface->forwardReference = superior;
2642 return hr;
2645 static HRESULT STDMETHODCALLTYPE device_parent_CreateRenderTarget(IWineD3DDeviceParent *iface,
2646 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type,
2647 DWORD multisample_quality, BOOL lockable, IWineD3DSurface **surface)
2649 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2650 IDirect3DSurface8Impl *d3d_surface;
2651 HRESULT hr;
2653 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2654 "\tmultisample_quality %u, lockable %u, surface %p\n",
2655 iface, superior, width, height, format, multisample_type, multisample_quality, lockable, surface);
2657 hr = IDirect3DDevice8_CreateRenderTarget((IDirect3DDevice8 *)This, width, height,
2658 d3dformat_from_wined3dformat(format), multisample_type, lockable, (IDirect3DSurface8 **)&d3d_surface);
2659 if (FAILED(hr))
2661 ERR("(%p) CreateRenderTarget failed, returning %#x\n", iface, hr);
2662 return hr;
2665 *surface = d3d_surface->wineD3DSurface;
2666 IWineD3DSurface_AddRef(*surface);
2668 d3d_surface->container = (IUnknown *)This;
2669 /* Implicit surfaces are created with an refcount of 0 */
2670 IUnknown_Release((IUnknown *)d3d_surface);
2672 return hr;
2675 static HRESULT STDMETHODCALLTYPE device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent *iface,
2676 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type,
2677 DWORD multisample_quality, BOOL discard, IWineD3DSurface **surface)
2679 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2680 IDirect3DSurface8Impl *d3d_surface;
2681 HRESULT hr;
2683 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2684 "\tmultisample_quality %u, discard %u, surface %p\n",
2685 iface, superior, width, height, format, multisample_type, multisample_quality, discard, surface);
2687 hr = IDirect3DDevice8_CreateDepthStencilSurface((IDirect3DDevice8 *)This, width, height,
2688 d3dformat_from_wined3dformat(format), multisample_type, (IDirect3DSurface8 **)&d3d_surface);
2689 if (FAILED(hr))
2691 ERR("(%p) CreateDepthStencilSurface failed, returning %#x\n", iface, hr);
2692 return hr;
2695 *surface = d3d_surface->wineD3DSurface;
2696 IWineD3DSurface_AddRef(*surface);
2698 d3d_surface->container = (IUnknown *)This;
2699 /* Implicit surfaces are created with an refcount of 0 */
2700 IUnknown_Release((IUnknown *)d3d_surface);
2702 return hr;
2705 static HRESULT STDMETHODCALLTYPE device_parent_CreateVolume(IWineD3DDeviceParent *iface,
2706 IUnknown *superior, UINT width, UINT height, UINT depth, WINED3DFORMAT format,
2707 WINED3DPOOL pool, DWORD usage, IWineD3DVolume **volume)
2709 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2710 IDirect3DVolume8Impl *object;
2711 HRESULT hr;
2713 TRACE("iface %p, superior %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p\n",
2714 iface, superior, width, height, depth, format, pool, usage, volume);
2716 /* Allocate the storage for the device */
2717 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2718 if (!object)
2720 FIXME("Allocation of memory failed\n");
2721 *volume = NULL;
2722 return D3DERR_OUTOFVIDEOMEMORY;
2725 hr = volume_init(object, This, width, height, depth, usage, format, pool);
2726 if (FAILED(hr))
2728 WARN("Failed to initialize volume, hr %#x.\n", hr);
2729 HeapFree(GetProcessHeap(), 0, object);
2730 return hr;
2733 *volume = object->wineD3DVolume;
2734 IWineD3DVolume_AddRef(*volume);
2735 IDirect3DVolume8_Release((IDirect3DVolume8 *)object);
2737 object->container = superior;
2738 object->forwardReference = superior;
2740 TRACE("(%p) Created volume %p\n", iface, object);
2742 return hr;
2745 static HRESULT STDMETHODCALLTYPE device_parent_CreateSwapChain(IWineD3DDeviceParent *iface,
2746 WINED3DPRESENT_PARAMETERS *present_parameters, IWineD3DSwapChain **swapchain)
2748 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2749 IDirect3DSwapChain8Impl *d3d_swapchain;
2750 D3DPRESENT_PARAMETERS local_parameters;
2751 HRESULT hr;
2753 TRACE("iface %p, present_parameters %p, swapchain %p\n", iface, present_parameters, swapchain);
2755 /* Copy the presentation parameters */
2756 local_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
2757 local_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
2758 local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(present_parameters->BackBufferFormat);
2759 local_parameters.BackBufferCount = present_parameters->BackBufferCount;
2760 local_parameters.MultiSampleType = present_parameters->MultiSampleType;
2761 local_parameters.SwapEffect = present_parameters->SwapEffect;
2762 local_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
2763 local_parameters.Windowed = present_parameters->Windowed;
2764 local_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
2765 local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(present_parameters->AutoDepthStencilFormat);
2766 local_parameters.Flags = present_parameters->Flags;
2767 local_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
2768 local_parameters.FullScreen_PresentationInterval = present_parameters->PresentationInterval;
2770 hr = IDirect3DDevice8_CreateAdditionalSwapChain((IDirect3DDevice8 *)This,
2771 &local_parameters, (IDirect3DSwapChain8 **)&d3d_swapchain);
2772 if (FAILED(hr))
2774 ERR("(%p) CreateAdditionalSwapChain failed, returning %#x\n", iface, hr);
2775 *swapchain = NULL;
2776 return hr;
2779 *swapchain = d3d_swapchain->wineD3DSwapChain;
2780 IUnknown_Release(d3d_swapchain->parentDevice);
2781 d3d_swapchain->parentDevice = NULL;
2783 /* Copy back the presentation parameters */
2784 present_parameters->BackBufferWidth = local_parameters.BackBufferWidth;
2785 present_parameters->BackBufferHeight = local_parameters.BackBufferHeight;
2786 present_parameters->BackBufferFormat = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat);
2787 present_parameters->BackBufferCount = local_parameters.BackBufferCount;
2788 present_parameters->MultiSampleType = local_parameters.MultiSampleType;
2789 present_parameters->SwapEffect = local_parameters.SwapEffect;
2790 present_parameters->hDeviceWindow = local_parameters.hDeviceWindow;
2791 present_parameters->Windowed = local_parameters.Windowed;
2792 present_parameters->EnableAutoDepthStencil = local_parameters.EnableAutoDepthStencil;
2793 present_parameters->AutoDepthStencilFormat = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat);
2794 present_parameters->Flags = local_parameters.Flags;
2795 present_parameters->FullScreen_RefreshRateInHz = local_parameters.FullScreen_RefreshRateInHz;
2796 present_parameters->PresentationInterval = local_parameters.FullScreen_PresentationInterval;
2798 return hr;
2801 const IWineD3DDeviceParentVtbl d3d8_wined3d_device_parent_vtbl =
2803 /* IUnknown methods */
2804 device_parent_QueryInterface,
2805 device_parent_AddRef,
2806 device_parent_Release,
2807 /* IWineD3DDeviceParent methods */
2808 device_parent_WineD3DDeviceCreated,
2809 device_parent_CreateSurface,
2810 device_parent_CreateRenderTarget,
2811 device_parent_CreateDepthStencilSurface,
2812 device_parent_CreateVolume,
2813 device_parent_CreateSwapChain,