d3d8: IDirect3DDevice8Impl_GetVertexShaderDeclaration gets passed a handle instead...
[wine/hacks.git] / dlls / d3d8 / device.c
blobb6fde8fc6274368a2d50c2fc959a0a5e845e17e6
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 /* Shader handle functions */
40 static shader_handle *alloc_shader_handle(IDirect3DDevice8Impl *This) {
41 if (This->free_shader_handles) {
42 /* Use a free handle */
43 shader_handle *handle = This->free_shader_handles;
44 This->free_shader_handles = *handle;
45 return handle;
47 if (!(This->allocated_shader_handles < This->shader_handle_table_size)) {
48 /* Grow the table */
49 DWORD new_size = This->shader_handle_table_size + (This->shader_handle_table_size >> 1);
50 shader_handle *new_handles = HeapReAlloc(GetProcessHeap(), 0, This->shader_handles, new_size * sizeof(shader_handle));
51 if (!new_handles) return NULL;
52 This->shader_handles = new_handles;
53 This->shader_handle_table_size = new_size;
56 return &This->shader_handles[This->allocated_shader_handles++];
59 static void free_shader_handle(IDirect3DDevice8Impl *This, shader_handle *handle) {
60 *handle = This->free_shader_handles;
61 This->free_shader_handles = handle;
64 /* IDirect3D IUnknown parts follow: */
65 static HRESULT WINAPI IDirect3DDevice8Impl_QueryInterface(LPDIRECT3DDEVICE8 iface,REFIID riid,LPVOID *ppobj)
67 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
69 if (IsEqualGUID(riid, &IID_IUnknown)
70 || IsEqualGUID(riid, &IID_IDirect3DDevice8)) {
71 IUnknown_AddRef(iface);
72 *ppobj = This;
73 return S_OK;
76 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
77 *ppobj = NULL;
78 return E_NOINTERFACE;
81 static ULONG WINAPI IDirect3DDevice8Impl_AddRef(LPDIRECT3DDEVICE8 iface) {
82 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
83 ULONG ref = InterlockedIncrement(&This->ref);
85 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
87 return ref;
90 static ULONG WINAPI IDirect3DDevice8Impl_Release(LPDIRECT3DDEVICE8 iface) {
91 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
92 ULONG ref;
94 if (This->inDestruction) return 0;
95 ref = InterlockedDecrement(&This->ref);
97 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
99 if (ref == 0) {
100 TRACE("Releasing wined3d device %p\n", This->WineD3DDevice);
101 This->inDestruction = TRUE;
102 IWineD3DDevice_Uninit3D(This->WineD3DDevice, D3D8CB_DestroyDepthStencilSurface, D3D8CB_DestroySwapChain);
103 IWineD3DDevice_Release(This->WineD3DDevice);
104 HeapFree(GetProcessHeap(), 0, This->shader_handles);
105 HeapFree(GetProcessHeap(), 0, This);
107 return ref;
110 /* IDirect3DDevice Interface follow: */
111 static HRESULT WINAPI IDirect3DDevice8Impl_TestCooperativeLevel(LPDIRECT3DDEVICE8 iface) {
112 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
114 TRACE("(%p) : Relay\n", This);
115 return IWineD3DDevice_TestCooperativeLevel(This->WineD3DDevice);
118 static UINT WINAPI IDirect3DDevice8Impl_GetAvailableTextureMem(LPDIRECT3DDEVICE8 iface) {
119 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
121 TRACE("(%p) Relay\n", This);
122 return IWineD3DDevice_GetAvailableTextureMem(This->WineD3DDevice);
125 static HRESULT WINAPI IDirect3DDevice8Impl_ResourceManagerDiscardBytes(LPDIRECT3DDEVICE8 iface, DWORD Bytes) {
126 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
128 TRACE("(%p) : Relay bytes(%d)\n", This, Bytes);
129 return IWineD3DDevice_EvictManagedResources(This->WineD3DDevice);
132 static HRESULT WINAPI IDirect3DDevice8Impl_GetDirect3D(LPDIRECT3DDEVICE8 iface, IDirect3D8** ppD3D8) {
133 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
134 HRESULT hr = D3D_OK;
135 IWineD3D* pWineD3D;
137 TRACE("(%p) Relay\n", This);
139 if (NULL == ppD3D8) {
140 return D3DERR_INVALIDCALL;
142 hr = IWineD3DDevice_GetDirect3D(This->WineD3DDevice, &pWineD3D);
143 if (hr == D3D_OK && pWineD3D != NULL)
145 IWineD3D_GetParent(pWineD3D,(IUnknown **)ppD3D8);
146 IWineD3D_Release(pWineD3D);
147 } else {
148 FIXME("Call to IWineD3DDevice_GetDirect3D failed\n");
149 *ppD3D8 = NULL;
151 TRACE("(%p) returning %p\n",This , *ppD3D8);
152 return hr;
155 static HRESULT WINAPI IDirect3DDevice8Impl_GetDeviceCaps(LPDIRECT3DDEVICE8 iface, D3DCAPS8* pCaps) {
156 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
157 HRESULT hrc = D3D_OK;
158 WINED3DCAPS *pWineCaps;
160 TRACE("(%p) : Relay pCaps %p\n", This, pCaps);
161 if(NULL == pCaps){
162 return D3DERR_INVALIDCALL;
164 pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
165 if(pWineCaps == NULL){
166 return D3DERR_INVALIDCALL; /* well this is what MSDN says to return */
169 D3D8CAPSTOWINECAPS(pCaps, pWineCaps)
170 hrc = IWineD3DDevice_GetDeviceCaps(This->WineD3DDevice, pWineCaps);
171 HeapFree(GetProcessHeap(), 0, pWineCaps);
173 /* D3D8 doesn't support SM 2.0 or higher, so clamp to 1.x */
174 if(pCaps->PixelShaderVersion > D3DPS_VERSION(1,4)){
175 pCaps->PixelShaderVersion = D3DPS_VERSION(1,4);
177 if(pCaps->VertexShaderVersion > D3DVS_VERSION(1,1)){
178 pCaps->VertexShaderVersion = D3DVS_VERSION(1,1);
181 TRACE("Returning %p %p\n", This, pCaps);
182 return hrc;
185 static HRESULT WINAPI IDirect3DDevice8Impl_GetDisplayMode(LPDIRECT3DDEVICE8 iface, D3DDISPLAYMODE* pMode) {
186 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
187 TRACE("(%p) Relay\n", This);
188 return IWineD3DDevice_GetDisplayMode(This->WineD3DDevice, 0, (WINED3DDISPLAYMODE *) pMode);
191 static HRESULT WINAPI IDirect3DDevice8Impl_GetCreationParameters(LPDIRECT3DDEVICE8 iface, D3DDEVICE_CREATION_PARAMETERS *pParameters) {
192 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
193 TRACE("(%p) Relay\n", This);
194 return IWineD3DDevice_GetCreationParameters(This->WineD3DDevice, (WINED3DDEVICE_CREATION_PARAMETERS *) pParameters);
197 static HRESULT WINAPI IDirect3DDevice8Impl_SetCursorProperties(LPDIRECT3DDEVICE8 iface, UINT XHotSpot, UINT YHotSpot, IDirect3DSurface8* pCursorBitmap) {
198 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
199 IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl*)pCursorBitmap;
200 TRACE("(%p) Relay\n", This);
201 if(!pCursorBitmap) {
202 WARN("No cursor bitmap, returning WINED3DERR_INVALIDCALL\n");
203 return WINED3DERR_INVALIDCALL;
205 return IWineD3DDevice_SetCursorProperties(This->WineD3DDevice,XHotSpot,YHotSpot,(IWineD3DSurface*)pSurface->wineD3DSurface);
208 static void WINAPI IDirect3DDevice8Impl_SetCursorPosition(LPDIRECT3DDEVICE8 iface, UINT XScreenSpace, UINT YScreenSpace, DWORD Flags) {
209 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
210 TRACE("(%p) Relay\n", This);
211 return IWineD3DDevice_SetCursorPosition(This->WineD3DDevice, XScreenSpace, YScreenSpace, Flags);
214 static BOOL WINAPI IDirect3DDevice8Impl_ShowCursor(LPDIRECT3DDEVICE8 iface, BOOL bShow) {
215 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
216 TRACE("(%p) Relay\n", This);
218 return IWineD3DDevice_ShowCursor(This->WineD3DDevice, bShow);
221 static HRESULT WINAPI IDirect3DDevice8Impl_CreateAdditionalSwapChain(LPDIRECT3DDEVICE8 iface, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DSwapChain8** pSwapChain) {
222 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
223 IDirect3DSwapChain8Impl* object;
224 HRESULT hrc = D3D_OK;
225 WINED3DPRESENT_PARAMETERS localParameters;
227 TRACE("(%p) Relay\n", This);
229 /* Fix the back buffer count */
230 if(pPresentationParameters->BackBufferCount == 0) {
231 pPresentationParameters->BackBufferCount = 1;
234 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
235 if (NULL == object) {
236 FIXME("Allocation of memory failed\n");
237 *pSwapChain = NULL;
238 return D3DERR_OUTOFVIDEOMEMORY;
240 object->ref = 1;
241 object->lpVtbl = &Direct3DSwapChain8_Vtbl;
243 /* Allocate an associated WineD3DDevice object */
244 localParameters.BackBufferWidth = &pPresentationParameters->BackBufferWidth;
245 localParameters.BackBufferHeight = &pPresentationParameters->BackBufferHeight;
246 localParameters.BackBufferFormat = (WINED3DFORMAT *)&pPresentationParameters->BackBufferFormat;
247 localParameters.BackBufferCount = &pPresentationParameters->BackBufferCount;
248 localParameters.MultiSampleType = (WINED3DMULTISAMPLE_TYPE *) &pPresentationParameters->MultiSampleType;
249 localParameters.MultiSampleQuality = NULL; /* d3d9 only */
250 localParameters.SwapEffect = (WINED3DSWAPEFFECT *) &pPresentationParameters->SwapEffect;
251 localParameters.hDeviceWindow = &pPresentationParameters->hDeviceWindow;
252 localParameters.Windowed = &pPresentationParameters->Windowed;
253 localParameters.EnableAutoDepthStencil = &pPresentationParameters->EnableAutoDepthStencil;
254 localParameters.AutoDepthStencilFormat = (WINED3DFORMAT *)&pPresentationParameters->AutoDepthStencilFormat;
255 localParameters.Flags = &pPresentationParameters->Flags;
256 localParameters.FullScreen_RefreshRateInHz = &pPresentationParameters->FullScreen_RefreshRateInHz;
257 localParameters.PresentationInterval = &pPresentationParameters->FullScreen_PresentationInterval;
260 hrc = IWineD3DDevice_CreateAdditionalSwapChain(This->WineD3DDevice, &localParameters, &object->wineD3DSwapChain, (IUnknown*)object, D3D8CB_CreateRenderTarget, D3D8CB_CreateDepthStencilSurface);
261 if (hrc != D3D_OK) {
262 FIXME("(%p) call to IWineD3DDevice_CreateAdditionalSwapChain failed\n", This);
263 HeapFree(GetProcessHeap(), 0 , object);
264 *pSwapChain = NULL;
265 }else{
266 IUnknown_AddRef(iface);
267 object->parentDevice = iface;
268 *pSwapChain = (IDirect3DSwapChain8 *)object;
270 TRACE("(%p) returning %p\n", This, *pSwapChain);
271 return hrc;
274 static HRESULT WINAPI IDirect3DDevice8Impl_Reset(LPDIRECT3DDEVICE8 iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
275 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
276 WINED3DPRESENT_PARAMETERS localParameters;
277 TRACE("(%p) Relay pPresentationParameters(%p)\n", This, pPresentationParameters);
278 /* FINDME: FIXME: */
279 localParameters.BackBufferWidth = &pPresentationParameters->BackBufferWidth;
280 localParameters.BackBufferHeight = &pPresentationParameters->BackBufferHeight;
281 localParameters.BackBufferFormat = (WINED3DFORMAT *)&pPresentationParameters->BackBufferFormat;
282 localParameters.BackBufferCount = &pPresentationParameters->BackBufferCount;
283 localParameters.MultiSampleType = (WINED3DMULTISAMPLE_TYPE *) &pPresentationParameters->MultiSampleType;
284 localParameters.MultiSampleQuality = NULL; /* D3d9 only */
285 localParameters.SwapEffect = (WINED3DSWAPEFFECT *) &pPresentationParameters->SwapEffect;
286 localParameters.hDeviceWindow = &pPresentationParameters->hDeviceWindow;
287 localParameters.Windowed = &pPresentationParameters->Windowed;
288 localParameters.EnableAutoDepthStencil = &pPresentationParameters->EnableAutoDepthStencil;
289 localParameters.AutoDepthStencilFormat = (WINED3DFORMAT *)&pPresentationParameters->AutoDepthStencilFormat;
290 localParameters.Flags = &pPresentationParameters->Flags;
291 localParameters.FullScreen_RefreshRateInHz = &pPresentationParameters->FullScreen_RefreshRateInHz;
292 localParameters.PresentationInterval = &pPresentationParameters->FullScreen_PresentationInterval;
293 return IWineD3DDevice_Reset(This->WineD3DDevice, &localParameters);
296 static HRESULT WINAPI IDirect3DDevice8Impl_Present(LPDIRECT3DDEVICE8 iface, CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion) {
297 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
298 TRACE("(%p) Relay\n", This);
299 return IWineD3DDevice_Present(This->WineD3DDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
302 static HRESULT WINAPI IDirect3DDevice8Impl_GetBackBuffer(LPDIRECT3DDEVICE8 iface, UINT BackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface8** ppBackBuffer) {
303 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
304 IWineD3DSurface *retSurface = NULL;
305 HRESULT rc = D3D_OK;
307 TRACE("(%p) Relay\n", This);
309 rc = IWineD3DDevice_GetBackBuffer(This->WineD3DDevice, 0, BackBuffer, (WINED3DBACKBUFFER_TYPE) Type, (IWineD3DSurface **)&retSurface);
310 if (rc == D3D_OK && NULL != retSurface && NULL != ppBackBuffer) {
311 IWineD3DSurface_GetParent(retSurface, (IUnknown **)ppBackBuffer);
312 IWineD3DSurface_Release(retSurface);
314 return rc;
317 static HRESULT WINAPI IDirect3DDevice8Impl_GetRasterStatus(LPDIRECT3DDEVICE8 iface, D3DRASTER_STATUS* pRasterStatus) {
318 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
319 TRACE("(%p) Relay\n", This);
321 return IWineD3DDevice_GetRasterStatus(This->WineD3DDevice, 0, (WINED3DRASTER_STATUS *) pRasterStatus);
324 static void WINAPI IDirect3DDevice8Impl_SetGammaRamp(LPDIRECT3DDEVICE8 iface, DWORD Flags, CONST D3DGAMMARAMP* pRamp) {
325 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
326 TRACE("(%p) Relay\n", This);
328 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
329 return IWineD3DDevice_SetGammaRamp(This->WineD3DDevice, 0, Flags, (CONST WINED3DGAMMARAMP *) pRamp);
332 static void WINAPI IDirect3DDevice8Impl_GetGammaRamp(LPDIRECT3DDEVICE8 iface, D3DGAMMARAMP* pRamp) {
333 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
334 TRACE("(%p) Relay\n", This);
336 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
337 return IWineD3DDevice_GetGammaRamp(This->WineD3DDevice, 0, (WINED3DGAMMARAMP *) pRamp);
340 static HRESULT WINAPI IDirect3DDevice8Impl_CreateTexture(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, UINT Levels, DWORD Usage,
341 D3DFORMAT Format, D3DPOOL Pool, IDirect3DTexture8 **ppTexture) {
342 IDirect3DTexture8Impl *object;
343 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
344 HRESULT hrc = D3D_OK;
346 TRACE("(%p) : W(%d) H(%d), Lvl(%d) d(%d), Fmt(%u), Pool(%d)\n", This, Width, Height, Levels, Usage, Format, Pool);
348 /* Allocate the storage for the device */
349 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DTexture8Impl));
351 if (NULL == object) {
352 FIXME("Allocation of memory failed\n");
353 /* *ppTexture = NULL; */
354 return D3DERR_OUTOFVIDEOMEMORY;
357 object->lpVtbl = &Direct3DTexture8_Vtbl;
358 object->ref = 1;
359 hrc = IWineD3DDevice_CreateTexture(This->WineD3DDevice, Width, Height, Levels, Usage & WINED3DUSAGE_MASK,
360 (WINED3DFORMAT)Format, (WINED3DPOOL) Pool, &object->wineD3DTexture, NULL, (IUnknown *)object, D3D8CB_CreateSurface);
362 if (FAILED(hrc)) {
363 /* free up object */
364 FIXME("(%p) call to IWineD3DDevice_CreateTexture failed\n", This);
365 HeapFree(GetProcessHeap(), 0, object);
366 /* *ppTexture = NULL; */
367 } else {
368 IUnknown_AddRef(iface);
369 object->parentDevice = iface;
370 *ppTexture = (LPDIRECT3DTEXTURE8) object;
373 TRACE("(%p) Created Texture %p, %p\n",This,object,object->wineD3DTexture);
374 return hrc;
377 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVolumeTexture(LPDIRECT3DDEVICE8 iface,
378 UINT Width, UINT Height, UINT Depth, UINT Levels, DWORD Usage,
379 D3DFORMAT Format, D3DPOOL Pool, IDirect3DVolumeTexture8** ppVolumeTexture) {
381 IDirect3DVolumeTexture8Impl *object;
382 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
383 HRESULT hrc = D3D_OK;
385 TRACE("(%p) Relay\n", This);
387 /* Allocate the storage for the device */
388 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVolumeTexture8Impl));
389 if (NULL == object) {
390 FIXME("(%p) allocation of memory failed\n", This);
391 *ppVolumeTexture = NULL;
392 return D3DERR_OUTOFVIDEOMEMORY;
395 object->lpVtbl = &Direct3DVolumeTexture8_Vtbl;
396 object->ref = 1;
397 hrc = IWineD3DDevice_CreateVolumeTexture(This->WineD3DDevice, Width, Height, Depth, Levels, Usage & WINED3DUSAGE_MASK,
398 (WINED3DFORMAT)Format, (WINED3DPOOL) Pool, &object->wineD3DVolumeTexture, NULL,
399 (IUnknown *)object, D3D8CB_CreateVolume);
401 if (hrc != D3D_OK) {
403 /* free up object */
404 FIXME("(%p) call to IWineD3DDevice_CreateVolumeTexture failed\n", This);
405 HeapFree(GetProcessHeap(), 0, object);
406 *ppVolumeTexture = NULL;
407 } else {
408 IUnknown_AddRef(iface);
409 object->parentDevice = iface;
410 *ppVolumeTexture = (LPDIRECT3DVOLUMETEXTURE8) object;
412 TRACE("(%p) returning %p\n", This , *ppVolumeTexture);
413 return hrc;
416 static HRESULT WINAPI IDirect3DDevice8Impl_CreateCubeTexture(LPDIRECT3DDEVICE8 iface, UINT EdgeLength, UINT Levels, DWORD Usage,
417 D3DFORMAT Format, D3DPOOL Pool, IDirect3DCubeTexture8** ppCubeTexture) {
419 IDirect3DCubeTexture8Impl *object;
420 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
421 HRESULT hr = D3D_OK;
423 TRACE("(%p) : ELen(%d) Lvl(%d) Usage(%d) fmt(%u), Pool(%d)\n" , This, EdgeLength, Levels, Usage, Format, Pool);
425 /* Allocate the storage for the device */
426 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
428 if (NULL == object) {
429 FIXME("(%p) allocation of CubeTexture failed\n", This);
430 *ppCubeTexture = NULL;
431 return D3DERR_OUTOFVIDEOMEMORY;
434 object->lpVtbl = &Direct3DCubeTexture8_Vtbl;
435 object->ref = 1;
436 hr = IWineD3DDevice_CreateCubeTexture(This->WineD3DDevice, EdgeLength, Levels, Usage & WINED3DUSAGE_MASK,
437 (WINED3DFORMAT)Format, (WINED3DPOOL) Pool, &object->wineD3DCubeTexture, NULL, (IUnknown*)object,
438 D3D8CB_CreateSurface);
440 if (hr != D3D_OK){
442 /* free up object */
443 FIXME("(%p) call to IWineD3DDevice_CreateCubeTexture failed\n", This);
444 HeapFree(GetProcessHeap(), 0, object);
445 *ppCubeTexture = NULL;
446 } else {
447 IUnknown_AddRef(iface);
448 object->parentDevice = iface;
449 *ppCubeTexture = (LPDIRECT3DCUBETEXTURE8) object;
452 TRACE("(%p) returning %p\n",This, *ppCubeTexture);
453 return hr;
456 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexBuffer(LPDIRECT3DDEVICE8 iface, UINT Size, DWORD Usage, DWORD FVF, D3DPOOL Pool, IDirect3DVertexBuffer8** ppVertexBuffer) {
457 IDirect3DVertexBuffer8Impl *object;
458 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
459 HRESULT hrc = D3D_OK;
461 TRACE("(%p) Relay\n", This);
462 /* Allocate the storage for the device */
463 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVertexBuffer8Impl));
464 if (NULL == object) {
465 FIXME("Allocation of memory failed\n");
466 *ppVertexBuffer = NULL;
467 return D3DERR_OUTOFVIDEOMEMORY;
470 object->lpVtbl = &Direct3DVertexBuffer8_Vtbl;
471 object->ref = 1;
472 hrc = IWineD3DDevice_CreateVertexBuffer(This->WineD3DDevice, Size, Usage & WINED3DUSAGE_MASK, FVF, (WINED3DPOOL) Pool, &(object->wineD3DVertexBuffer), NULL, (IUnknown *)object);
474 if (D3D_OK != hrc) {
476 /* free up object */
477 FIXME("(%p) call to IWineD3DDevice_CreateVertexBuffer failed\n", This);
478 HeapFree(GetProcessHeap(), 0, object);
479 *ppVertexBuffer = NULL;
480 } else {
481 IUnknown_AddRef(iface);
482 object->parentDevice = iface;
483 *ppVertexBuffer = (LPDIRECT3DVERTEXBUFFER8) object;
485 return hrc;
488 static HRESULT WINAPI IDirect3DDevice8Impl_CreateIndexBuffer(LPDIRECT3DDEVICE8 iface, UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DIndexBuffer8** ppIndexBuffer) {
489 IDirect3DIndexBuffer8Impl *object;
490 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
491 HRESULT hrc = D3D_OK;
493 TRACE("(%p) Relay\n", This);
494 /* Allocate the storage for the device */
495 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
496 if (NULL == object) {
497 FIXME("Allocation of memory failed\n");
498 *ppIndexBuffer = NULL;
499 return D3DERR_OUTOFVIDEOMEMORY;
502 object->lpVtbl = &Direct3DIndexBuffer8_Vtbl;
503 object->ref = 1;
504 TRACE("Calling wined3d create index buffer\n");
505 hrc = IWineD3DDevice_CreateIndexBuffer(This->WineD3DDevice, Length, Usage & WINED3DUSAGE_MASK, Format, (WINED3DPOOL) Pool, &object->wineD3DIndexBuffer, NULL, (IUnknown *)object);
507 if (D3D_OK != hrc) {
509 /* free up object */
510 FIXME("(%p) call to IWineD3DDevice_CreateIndexBuffer failed\n", This);
511 HeapFree(GetProcessHeap(), 0, object);
512 *ppIndexBuffer = NULL;
513 } else {
514 IUnknown_AddRef(iface);
515 object->parentDevice = iface;
516 *ppIndexBuffer = (LPDIRECT3DINDEXBUFFER8)object;
518 return hrc;
521 static HRESULT WINAPI IDirect3DDevice8Impl_CreateSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, BOOL Lockable, BOOL Discard, UINT Level, IDirect3DSurface8 **ppSurface,D3DRESOURCETYPE Type, UINT Usage,D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality) {
522 HRESULT hrc;
523 IDirect3DSurface8Impl *object;
524 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
525 TRACE("(%p) Relay\n", This);
526 if(MultisampleQuality < 0) {
527 FIXME("MultisampleQuality out of range %d, substituting 0\n", MultisampleQuality);
528 /*FIXME: Find out what windows does with a MultisampleQuality < 0 */
529 MultisampleQuality=0;
532 if(MultisampleQuality > 0){
533 FIXME("MultisampleQuality set to %d, substituting 0\n" , MultisampleQuality);
535 MultisampleQuality
536 [in] Quality level. The valid range is between zero and one less than the level returned by pQualityLevels used by IDirect3D8::CheckDeviceMultiSampleType. Passing a larger value returns the error D3DERR_INVALIDCALL. The MultisampleQuality values of paired render targets, depth stencil surfaces, and the MultiSample type must all match.
538 MultisampleQuality=0;
540 /*FIXME: Check MAX bounds of MultisampleQuality*/
542 /* Allocate the storage for the device */
543 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface8Impl));
544 if (NULL == object) {
545 FIXME("Allocation of memory failed\n");
546 *ppSurface = NULL;
547 return D3DERR_OUTOFVIDEOMEMORY;
550 object->lpVtbl = &Direct3DSurface8_Vtbl;
551 object->ref = 1;
553 TRACE("(%p) : w(%d) h(%d) fmt(%d) surf@%p\n", This, Width, Height, Format, *ppSurface);
555 hrc = IWineD3DDevice_CreateSurface(This->WineD3DDevice, Width, Height, Format, Lockable, Discard, Level, &object->wineD3DSurface, Type, Usage & WINED3DUSAGE_MASK, (WINED3DPOOL) Pool,MultiSample,MultisampleQuality, NULL, SURFACE_OPENGL, (IUnknown *)object);
556 if (hrc != D3D_OK || NULL == object->wineD3DSurface) {
557 /* free up object */
558 FIXME("(%p) call to IWineD3DDevice_CreateSurface failed\n", This);
559 HeapFree(GetProcessHeap(), 0, object);
560 *ppSurface = NULL;
561 } else {
562 IUnknown_AddRef(iface);
563 object->parentDevice = iface;
564 *ppSurface = (LPDIRECT3DSURFACE8) object;
566 return hrc;
569 static HRESULT WINAPI IDirect3DDevice8Impl_CreateRenderTarget(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, BOOL Lockable, IDirect3DSurface8** ppSurface) {
570 TRACE("Relay\n");
572 return IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, Lockable, FALSE /* Discard */, 0 /* Level */ , ppSurface, D3DRTYPE_SURFACE, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT, MultiSample, 0);
575 static HRESULT WINAPI IDirect3DDevice8Impl_CreateDepthStencilSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, IDirect3DSurface8** ppSurface) {
576 TRACE("Relay\n");
577 /* TODO: Verify that Discard is false */
578 return IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE, 0 /* Level */
579 ,ppSurface, D3DRTYPE_SURFACE, D3DUSAGE_DEPTHSTENCIL,
580 D3DPOOL_DEFAULT, MultiSample, 0);
583 static HRESULT WINAPI IDirect3DDevice8Impl_CreateImageSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, IDirect3DSurface8** ppSurface) {
584 TRACE("Relay\n");
586 return IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Loackable */ , FALSE /*Discard*/ , 0 /* Level */ , ppSurface, D3DRTYPE_SURFACE, 0 /* Usage (undefined/none) */ , D3DPOOL_SCRATCH, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
589 static HRESULT WINAPI IDirect3DDevice8Impl_CopyRects(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8 *pSourceSurface, CONST RECT *pSourceRects, UINT cRects, IDirect3DSurface8 *pDestinationSurface, CONST POINT *pDestPoints) {
590 IDirect3DSurface8Impl *Source = (IDirect3DSurface8Impl *) pSourceSurface;
591 IDirect3DSurface8Impl *Dest = (IDirect3DSurface8Impl *) pDestinationSurface;
593 HRESULT hr = WINED3D_OK;
594 WINED3DFORMAT srcFormat, destFormat;
595 UINT srcWidth, destWidth;
596 UINT srcHeight, destHeight;
597 UINT srcSize;
598 WINED3DSURFACE_DESC winedesc;
600 TRACE("(%p) pSrcSur=%p, pSourceRects=%p, cRects=%d, pDstSur=%p, pDestPtsArr=%p\n", iface,
601 pSourceSurface, pSourceRects, cRects, pDestinationSurface, pDestPoints);
604 /* Check that the source texture is in WINED3DPOOL_SYSTEMMEM and the destination texture is in WINED3DPOOL_DEFAULT */
605 memset(&winedesc, 0, sizeof(winedesc));
607 winedesc.Format = &srcFormat;
608 winedesc.Width = &srcWidth;
609 winedesc.Height = &srcHeight;
610 winedesc.Size = &srcSize;
611 IWineD3DSurface_GetDesc(Source->wineD3DSurface, &winedesc);
613 winedesc.Format = &destFormat;
614 winedesc.Width = &destWidth;
615 winedesc.Height = &destHeight;
616 winedesc.Size = NULL;
617 IWineD3DSurface_GetDesc(Dest->wineD3DSurface, &winedesc);
619 /* Check that the source and destination formats match */
620 if (srcFormat != destFormat && WINED3DFMT_UNKNOWN != destFormat) {
621 WARN("(%p) source %p format must match the dest %p format, returning WINED3DERR_INVALIDCALL\n", iface, pSourceSurface, pDestinationSurface);
622 return WINED3DERR_INVALIDCALL;
623 } else if (WINED3DFMT_UNKNOWN == destFormat) {
624 TRACE("(%p) : Converting destination surface from WINED3DFMT_UNKNOWN to the source format\n", iface);
625 IWineD3DSurface_SetFormat(Dest->wineD3DSurface, srcFormat);
626 destFormat = srcFormat;
629 /* Quick if complete copy ... */
630 if (cRects == 0 && pSourceRects == NULL && pDestPoints == NULL) {
631 IWineD3DSurface_BltFast(Dest->wineD3DSurface, 0, 0, Source->wineD3DSurface, NULL, DDBLTFAST_NOCOLORKEY);
632 } else {
633 unsigned int i;
634 /* Copy rect by rect */
635 if (NULL != pSourceRects && NULL != pDestPoints) {
636 for (i = 0; i < cRects; ++i) {
637 IWineD3DSurface_BltFast(Dest->wineD3DSurface, pDestPoints[i].x, pDestPoints[i].y, Source->wineD3DSurface, (RECT *) &pSourceRects[i], DDBLTFAST_NOCOLORKEY);
639 } else {
640 for (i = 0; i < cRects; ++i) {
641 IWineD3DSurface_BltFast(Dest->wineD3DSurface, 0, 0, Source->wineD3DSurface, (RECT *) &pSourceRects[i], DDBLTFAST_NOCOLORKEY);
646 return hr;
649 static HRESULT WINAPI IDirect3DDevice8Impl_UpdateTexture(LPDIRECT3DDEVICE8 iface, IDirect3DBaseTexture8* pSourceTexture, IDirect3DBaseTexture8* pDestinationTexture) {
650 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
651 TRACE("(%p) Relay\n" , This);
653 return IWineD3DDevice_UpdateTexture(This->WineD3DDevice, ((IDirect3DBaseTexture8Impl *)pSourceTexture)->wineD3DBaseTexture, ((IDirect3DBaseTexture8Impl *)pDestinationTexture)->wineD3DBaseTexture);
656 static HRESULT WINAPI IDirect3DDevice8Impl_GetFrontBuffer(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* pDestSurface) {
657 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
658 IDirect3DSurface8Impl *destSurface = (IDirect3DSurface8Impl *)pDestSurface;
660 TRACE("(%p) Relay\n" , This);
662 if (pDestSurface == NULL) {
663 WARN("(%p) : Caller passed NULL as pDestSurface returning D3DERR_INVALIDCALL\n", This);
664 return D3DERR_INVALIDCALL;
667 return IWineD3DDevice_GetFrontBufferData(This->WineD3DDevice, 0, destSurface->wineD3DSurface);
670 static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderTarget(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* pRenderTarget, IDirect3DSurface8* pNewZStencil) {
671 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
672 IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl *)pRenderTarget;
673 IDirect3DSurface8Impl *pZSurface = (IDirect3DSurface8Impl *)pNewZStencil;
674 TRACE("(%p) Relay\n" , This);
676 IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, NULL == pZSurface ? NULL : (IWineD3DSurface *)pZSurface->wineD3DSurface);
678 return IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, 0, pSurface ? (IWineD3DSurface *)pSurface->wineD3DSurface : NULL);
681 static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderTarget(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8** ppRenderTarget) {
682 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
683 HRESULT hr = D3D_OK;
684 IWineD3DSurface *pRenderTarget;
686 TRACE("(%p) Relay\n" , This);
688 if (ppRenderTarget == NULL) {
689 return D3DERR_INVALIDCALL;
691 hr = IWineD3DDevice_GetRenderTarget(This->WineD3DDevice, 0, &pRenderTarget);
693 if (hr == D3D_OK && pRenderTarget != NULL) {
694 IWineD3DSurface_GetParent(pRenderTarget,(IUnknown**)ppRenderTarget);
695 IWineD3DSurface_Release(pRenderTarget);
696 } else {
697 FIXME("Call to IWineD3DDevice_GetRenderTarget failed\n");
698 *ppRenderTarget = NULL;
701 return hr;
704 static HRESULT WINAPI IDirect3DDevice8Impl_GetDepthStencilSurface(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8** ppZStencilSurface) {
705 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
706 HRESULT hr = D3D_OK;
707 IWineD3DSurface *pZStencilSurface;
709 TRACE("(%p) Relay\n" , This);
710 if(ppZStencilSurface == NULL){
711 return D3DERR_INVALIDCALL;
714 hr=IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice,&pZStencilSurface);
715 if(hr == D3D_OK && pZStencilSurface != NULL){
716 IWineD3DSurface_GetParent(pZStencilSurface,(IUnknown**)ppZStencilSurface);
717 IWineD3DSurface_Release(pZStencilSurface);
718 }else{
719 FIXME("Call to IWineD3DDevice_GetDepthStencilSurface failed\n");
720 *ppZStencilSurface = NULL;
723 return D3D_OK;
726 static HRESULT WINAPI IDirect3DDevice8Impl_BeginScene(LPDIRECT3DDEVICE8 iface) {
727 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
728 return IWineD3DDevice_BeginScene(This->WineD3DDevice);
731 static HRESULT WINAPI IDirect3DDevice8Impl_EndScene(LPDIRECT3DDEVICE8 iface) {
732 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
733 TRACE("(%p) Relay\n" , This);
735 return IWineD3DDevice_EndScene(This->WineD3DDevice);
738 static HRESULT WINAPI IDirect3DDevice8Impl_Clear(LPDIRECT3DDEVICE8 iface, DWORD Count, CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) {
739 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
740 TRACE("(%p) Relay\n" , This);
742 /* Note: D3DRECT is compatible with WINED3DRECT */
743 return IWineD3DDevice_Clear(This->WineD3DDevice, Count, (CONST WINED3DRECT*) pRects, Flags, Color, Z, Stencil);
746 static HRESULT WINAPI IDirect3DDevice8Impl_SetTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* lpMatrix) {
747 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
748 TRACE("(%p) Relay\n" , This);
750 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
751 return IWineD3DDevice_SetTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) lpMatrix);
754 static HRESULT WINAPI IDirect3DDevice8Impl_GetTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State,D3DMATRIX* pMatrix) {
755 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
756 TRACE("(%p) Relay\n" , This);
758 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
759 return IWineD3DDevice_GetTransform(This->WineD3DDevice, State, (WINED3DMATRIX*) pMatrix);
762 static HRESULT WINAPI IDirect3DDevice8Impl_MultiplyTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix) {
763 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
764 TRACE("(%p) Relay\n" , This);
766 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
767 return IWineD3DDevice_MultiplyTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) pMatrix);
770 static HRESULT WINAPI IDirect3DDevice8Impl_SetViewport(LPDIRECT3DDEVICE8 iface, CONST D3DVIEWPORT8* pViewport) {
771 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
772 TRACE("(%p) Relay\n" , This);
774 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
775 return IWineD3DDevice_SetViewport(This->WineD3DDevice, (const WINED3DVIEWPORT *)pViewport);
778 static HRESULT WINAPI IDirect3DDevice8Impl_GetViewport(LPDIRECT3DDEVICE8 iface, D3DVIEWPORT8* pViewport) {
779 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
780 TRACE("(%p) Relay\n" , This);
782 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
783 return IWineD3DDevice_GetViewport(This->WineD3DDevice, (WINED3DVIEWPORT *)pViewport);
786 static HRESULT WINAPI IDirect3DDevice8Impl_SetMaterial(LPDIRECT3DDEVICE8 iface, CONST D3DMATERIAL8* pMaterial) {
787 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
788 TRACE("(%p) Relay\n" , This);
790 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
791 return IWineD3DDevice_SetMaterial(This->WineD3DDevice, (const WINED3DMATERIAL *)pMaterial);
794 static HRESULT WINAPI IDirect3DDevice8Impl_GetMaterial(LPDIRECT3DDEVICE8 iface, D3DMATERIAL8* pMaterial) {
795 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
796 TRACE("(%p) Relay\n" , This);
798 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
799 return IWineD3DDevice_GetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
802 static HRESULT WINAPI IDirect3DDevice8Impl_SetLight(LPDIRECT3DDEVICE8 iface, DWORD Index, CONST D3DLIGHT8* pLight) {
803 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
804 TRACE("(%p) Relay\n" , This);
806 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
807 return IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (const WINED3DLIGHT *)pLight);
810 static HRESULT WINAPI IDirect3DDevice8Impl_GetLight(LPDIRECT3DDEVICE8 iface, DWORD Index,D3DLIGHT8* pLight) {
811 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
812 TRACE("(%p) Relay\n" , This);
814 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
815 return IWineD3DDevice_GetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
818 static HRESULT WINAPI IDirect3DDevice8Impl_LightEnable(LPDIRECT3DDEVICE8 iface, DWORD Index,BOOL Enable) {
819 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
820 TRACE("(%p) Relay\n" , This);
822 return IWineD3DDevice_SetLightEnable(This->WineD3DDevice, Index, Enable);
825 static HRESULT WINAPI IDirect3DDevice8Impl_GetLightEnable(LPDIRECT3DDEVICE8 iface, DWORD Index,BOOL* pEnable) {
826 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
827 TRACE("(%p) Relay\n" , This);
829 return IWineD3DDevice_GetLightEnable(This->WineD3DDevice, Index, pEnable);
832 static HRESULT WINAPI IDirect3DDevice8Impl_SetClipPlane(LPDIRECT3DDEVICE8 iface, DWORD Index,CONST float* pPlane) {
833 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
834 TRACE("(%p) Relay\n" , This);
836 return IWineD3DDevice_SetClipPlane(This->WineD3DDevice, Index, pPlane);
839 static HRESULT WINAPI IDirect3DDevice8Impl_GetClipPlane(LPDIRECT3DDEVICE8 iface, DWORD Index,float* pPlane) {
840 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
841 TRACE("(%p) Relay\n" , This);
843 return IWineD3DDevice_GetClipPlane(This->WineD3DDevice, Index, pPlane);
846 static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderState(LPDIRECT3DDEVICE8 iface, D3DRENDERSTATETYPE State,DWORD Value) {
847 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
848 TRACE("(%p) Relay\n" , This);
850 return IWineD3DDevice_SetRenderState(This->WineD3DDevice, State, Value);
853 static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderState(LPDIRECT3DDEVICE8 iface, D3DRENDERSTATETYPE State,DWORD* pValue) {
854 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
855 TRACE("(%p) Relay\n" , This);
857 return IWineD3DDevice_GetRenderState(This->WineD3DDevice, State, pValue);
860 static HRESULT WINAPI IDirect3DDevice8Impl_BeginStateBlock(LPDIRECT3DDEVICE8 iface) {
861 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
863 TRACE("(%p)\n", This);
865 return IWineD3DDevice_BeginStateBlock(This->WineD3DDevice);
868 static HRESULT WINAPI IDirect3DDevice8Impl_EndStateBlock(LPDIRECT3DDEVICE8 iface, DWORD* pToken) {
869 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
870 HRESULT hr;
871 IWineD3DStateBlock* wineD3DStateBlock;
872 IDirect3DStateBlock8Impl* object;
874 TRACE("(%p) Relay\n", This);
876 /* Tell wineD3D to endstatablock before anything else (in case we run out
877 * of memory later and cause locking problems)
879 hr = IWineD3DDevice_EndStateBlock(This->WineD3DDevice , &wineD3DStateBlock);
880 if (hr != D3D_OK) {
881 FIXME("IWineD3DDevice_EndStateBlock returned an error\n");
882 return hr;
885 /* allocate a new IDirectD3DStateBlock */
886 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY ,sizeof(IDirect3DStateBlock8Impl));
887 object->ref = 1;
888 object->lpVtbl = &Direct3DStateBlock8_Vtbl;
890 object->wineD3DStateBlock = wineD3DStateBlock;
892 *pToken = (DWORD)object;
893 TRACE("(%p)Returning %p %p\n", This, object, wineD3DStateBlock);
895 return hr;
898 static HRESULT WINAPI IDirect3DDevice8Impl_ApplyStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
899 IDirect3DStateBlock8Impl *pSB = (IDirect3DStateBlock8Impl*) Token;
900 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
902 TRACE("(%p) %p Relay\n", This, pSB);
904 return IWineD3DStateBlock_Apply(pSB->wineD3DStateBlock);
907 static HRESULT WINAPI IDirect3DDevice8Impl_CaptureStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
908 IDirect3DStateBlock8Impl* pSB = (IDirect3DStateBlock8Impl *)Token;
909 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
911 TRACE("(%p) %p Relay\n", This, pSB);
913 return IWineD3DStateBlock_Capture(pSB->wineD3DStateBlock);
916 static HRESULT WINAPI IDirect3DDevice8Impl_DeleteStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
917 IDirect3DStateBlock8Impl* pSB = (IDirect3DStateBlock8Impl *)Token;
918 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
920 TRACE("(%p) Relay\n", This);
922 while(IUnknown_Release((IUnknown *)pSB));
924 return D3D_OK;
927 static HRESULT WINAPI IDirect3DDevice8Impl_CreateStateBlock(LPDIRECT3DDEVICE8 iface, D3DSTATEBLOCKTYPE Type, DWORD* pToken) {
928 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
929 IDirect3DStateBlock8Impl *object;
930 HRESULT hrc = D3D_OK;
932 TRACE("(%p) Relay\n", This);
934 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DStateBlock8Impl));
935 if (NULL == object) {
936 *pToken = 0;
937 return E_OUTOFMEMORY;
939 object->lpVtbl = &Direct3DStateBlock8_Vtbl;
940 object->ref = 1;
942 hrc = IWineD3DDevice_CreateStateBlock(This->WineD3DDevice, (WINED3DSTATEBLOCKTYPE)Type, &object->wineD3DStateBlock, (IUnknown *)object);
943 if(D3D_OK != hrc){
944 FIXME("(%p) Call to IWineD3DDevice_CreateStateBlock failed.\n", This);
945 HeapFree(GetProcessHeap(), 0, object);
946 *pToken = 0;
947 } else {
948 *pToken = (DWORD)object;
950 TRACE("(%p) returning token (ptr to stateblock) of %p\n", This, object);
952 return hrc;
955 static HRESULT WINAPI IDirect3DDevice8Impl_SetClipStatus(LPDIRECT3DDEVICE8 iface, CONST D3DCLIPSTATUS8* pClipStatus) {
956 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
957 TRACE("(%p) Relay\n" , This);
958 /* FIXME: Verify that D3DCLIPSTATUS8 ~= WINED3DCLIPSTATUS */
959 return IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
962 static HRESULT WINAPI IDirect3DDevice8Impl_GetClipStatus(LPDIRECT3DDEVICE8 iface, D3DCLIPSTATUS8* pClipStatus) {
963 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
964 TRACE("(%p) Relay\n" , This);
966 return IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
969 static HRESULT WINAPI IDirect3DDevice8Impl_GetTexture(LPDIRECT3DDEVICE8 iface, DWORD Stage,IDirect3DBaseTexture8** ppTexture) {
970 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
971 IWineD3DBaseTexture *retTexture = NULL;
972 HRESULT rc = D3D_OK;
974 TRACE("(%p) Relay\n" , This);
976 if(ppTexture == NULL){
977 return D3DERR_INVALIDCALL;
980 rc = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, (IWineD3DBaseTexture **)&retTexture);
981 if (rc == D3D_OK && NULL != retTexture) {
982 IWineD3DBaseTexture_GetParent(retTexture, (IUnknown **)ppTexture);
983 IWineD3DBaseTexture_Release(retTexture);
984 } else {
985 FIXME("Call to get texture (%d) failed (%p)\n", Stage, retTexture);
986 *ppTexture = NULL;
989 return rc;
992 static HRESULT WINAPI IDirect3DDevice8Impl_SetTexture(LPDIRECT3DDEVICE8 iface, DWORD Stage, IDirect3DBaseTexture8* pTexture) {
993 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
994 TRACE("(%p) Relay %d %p\n" , This, Stage, pTexture);
996 return IWineD3DDevice_SetTexture(This->WineD3DDevice, Stage,
997 pTexture==NULL ? NULL : ((IDirect3DBaseTexture8Impl *)pTexture)->wineD3DBaseTexture);
1000 static HRESULT WINAPI IDirect3DDevice8Impl_GetTextureStageState(LPDIRECT3DDEVICE8 iface, DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD* pValue) {
1001 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1002 TRACE("(%p) Relay\n" , This);
1004 switch(Type) {
1005 case D3DTSS_ADDRESSU:
1006 Type = WINED3DSAMP_ADDRESSU;
1007 break;
1008 case D3DTSS_ADDRESSV:
1009 Type = WINED3DSAMP_ADDRESSV;
1010 break;
1011 case D3DTSS_ADDRESSW:
1012 Type = WINED3DSAMP_ADDRESSW;
1013 break;
1014 case D3DTSS_BORDERCOLOR:
1015 Type = WINED3DSAMP_BORDERCOLOR;
1016 break;
1017 case D3DTSS_MAGFILTER:
1018 Type = WINED3DSAMP_MAGFILTER;
1019 break;
1020 case D3DTSS_MAXANISOTROPY:
1021 Type = WINED3DSAMP_MAXANISOTROPY;
1022 break;
1023 case D3DTSS_MAXMIPLEVEL:
1024 Type = WINED3DSAMP_MAXMIPLEVEL;
1025 break;
1026 case D3DTSS_MINFILTER:
1027 Type = WINED3DSAMP_MINFILTER;
1028 break;
1029 case D3DTSS_MIPFILTER:
1030 Type = WINED3DSAMP_MIPFILTER;
1031 break;
1032 case D3DTSS_MIPMAPLODBIAS:
1033 Type = WINED3DSAMP_MIPMAPLODBIAS;
1034 break;
1035 default:
1036 return IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, Type, pValue);
1039 return IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Stage, Type, pValue);
1042 static HRESULT WINAPI IDirect3DDevice8Impl_SetTextureStageState(LPDIRECT3DDEVICE8 iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value) {
1043 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1044 TRACE("(%p) Relay\n" , This);
1046 switch(Type) {
1047 case D3DTSS_ADDRESSU:
1048 Type = WINED3DSAMP_ADDRESSU;
1049 break;
1050 case D3DTSS_ADDRESSV:
1051 Type = WINED3DSAMP_ADDRESSV;
1052 break;
1053 case D3DTSS_ADDRESSW:
1054 Type = WINED3DSAMP_ADDRESSW;
1055 break;
1056 case D3DTSS_BORDERCOLOR:
1057 Type = WINED3DSAMP_BORDERCOLOR;
1058 break;
1059 case D3DTSS_MAGFILTER:
1060 Type = WINED3DSAMP_MAGFILTER;
1061 break;
1062 case D3DTSS_MAXANISOTROPY:
1063 Type = WINED3DSAMP_MAXANISOTROPY;
1064 break;
1065 case D3DTSS_MAXMIPLEVEL:
1066 Type = WINED3DSAMP_MAXMIPLEVEL;
1067 break;
1068 case D3DTSS_MINFILTER:
1069 Type = WINED3DSAMP_MINFILTER;
1070 break;
1071 case D3DTSS_MIPFILTER:
1072 Type = WINED3DSAMP_MIPFILTER;
1073 break;
1074 case D3DTSS_MIPMAPLODBIAS:
1075 Type = WINED3DSAMP_MIPMAPLODBIAS;
1076 break;
1077 default:
1078 return IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, Type, Value);
1081 return IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Stage, Type, Value);
1084 static HRESULT WINAPI IDirect3DDevice8Impl_ValidateDevice(LPDIRECT3DDEVICE8 iface, DWORD* pNumPasses) {
1085 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1086 TRACE("(%p) Relay\n" , This);
1088 return IWineD3DDevice_ValidateDevice(This->WineD3DDevice, pNumPasses);
1091 static HRESULT WINAPI IDirect3DDevice8Impl_GetInfo(LPDIRECT3DDEVICE8 iface, DWORD DevInfoID, void* pDevInfoStruct, DWORD DevInfoStructSize) {
1092 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1093 FIXME("(%p) : stub\n", This);
1094 return D3D_OK;
1097 static HRESULT WINAPI IDirect3DDevice8Impl_SetPaletteEntries(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber, CONST PALETTEENTRY* pEntries) {
1098 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1099 TRACE("(%p) Relay\n" , This);
1101 return IWineD3DDevice_SetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1104 static HRESULT WINAPI IDirect3DDevice8Impl_GetPaletteEntries(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber, PALETTEENTRY* pEntries) {
1105 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1106 TRACE("(%p) Relay\n" , This);
1108 return IWineD3DDevice_GetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1111 static HRESULT WINAPI IDirect3DDevice8Impl_SetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber) {
1112 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1113 TRACE("(%p) Relay\n" , This);
1115 return IWineD3DDevice_SetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1118 static HRESULT WINAPI IDirect3DDevice8Impl_GetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface, UINT *PaletteNumber) {
1119 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1120 TRACE("(%p) Relay\n" , This);
1122 return IWineD3DDevice_GetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1125 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitive(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount) {
1126 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1127 TRACE("(%p) Relay\n" , This);
1129 return IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, PrimitiveType, StartVertex, PrimitiveCount);
1132 static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitive(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,
1133 UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount) {
1134 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1135 TRACE("(%p) Relay\n" , This);
1137 return IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, PrimitiveType, MinVertexIndex, NumVertices, startIndex, primCount);
1140 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitiveUP(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,UINT PrimitiveCount,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride) {
1141 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1142 TRACE("(%p) Relay\n" , This);
1144 return IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice, PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride);
1147 static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitiveUP(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,UINT MinVertexIndex,
1148 UINT NumVertexIndices,UINT PrimitiveCount,CONST void* pIndexData,
1149 D3DFORMAT IndexDataFormat,CONST void* pVertexStreamZeroData,
1150 UINT VertexStreamZeroStride) {
1151 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1152 TRACE("(%p) Relay\n" , This);
1154 return IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice, PrimitiveType, MinVertexIndex, NumVertexIndices, PrimitiveCount,
1155 pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride);
1158 static HRESULT WINAPI IDirect3DDevice8Impl_ProcessVertices(LPDIRECT3DDEVICE8 iface, UINT SrcStartIndex,UINT DestIndex,UINT VertexCount,IDirect3DVertexBuffer8* pDestBuffer,DWORD Flags) {
1159 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1160 TRACE("(%p) Relay\n" , This);
1162 return IWineD3DDevice_ProcessVertices(This->WineD3DDevice,SrcStartIndex, DestIndex, VertexCount, ((IDirect3DVertexBuffer8Impl *)pDestBuffer)->wineD3DVertexBuffer, NULL, Flags);
1165 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexShader(LPDIRECT3DDEVICE8 iface, CONST DWORD* pDeclaration, CONST DWORD* pFunction, DWORD* ppShader, DWORD Usage) {
1166 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1167 HRESULT hrc = D3D_OK;
1168 IDirect3DVertexShader8Impl *object;
1170 /* Setup a stub object for now */
1171 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1172 TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This, pFunction, ppShader);
1173 if (NULL == object) {
1174 FIXME("Allocation of memory failed\n");
1175 *ppShader = 0;
1176 return D3DERR_OUTOFVIDEOMEMORY;
1179 object->ref = 1;
1180 object->lpVtbl = &Direct3DVertexShader8_Vtbl;
1181 /* Usage is missing ..*/
1182 hrc = IWineD3DDevice_CreateVertexShader(This->WineD3DDevice, pDeclaration, pFunction, &object->wineD3DVertexShader, (IUnknown *)object);
1184 if (FAILED(hrc)) {
1185 /* free up object */
1186 FIXME("Call to IWineD3DDevice_CreateVertexShader failed\n");
1187 HeapFree(GetProcessHeap(), 0, object);
1188 *ppShader = 0;
1189 } else {
1190 /* TODO: Store the VS declarations locally so that they can be derefferenced with a value higher than VS_HIGHESTFIXEDFXF */
1191 shader_handle *handle = alloc_shader_handle(This);
1192 if (!handle) {
1193 ERR("Failed to allocate shader handle\n");
1194 IDirect3DVertexShader8_Release((IUnknown *)object);
1195 hrc = E_OUTOFMEMORY;
1196 } else {
1197 object->handle = handle;
1198 *handle = object;
1199 *ppShader = (handle - This->shader_handles) + VS_HIGHESTFIXEDFXF + 1;
1202 TRACE("(%p) : returning %p (handle %#x)\n", This, object, *ppShader);
1204 return hrc;
1207 static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
1208 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1209 HRESULT hrc = D3D_OK;
1211 TRACE("(%p) : Relay\n", This);
1212 if (VS_HIGHESTFIXEDFXF >= pShader) {
1213 TRACE("Setting FVF, %d %d\n", VS_HIGHESTFIXEDFXF, pShader);
1214 IWineD3DDevice_SetFVF(This->WineD3DDevice, pShader);
1216 /* Call SetVertexShader with a NULL shader to set the vertexshader in the stateblock to NULL. */
1217 IWineD3DDevice_SetVertexShader(This->WineD3DDevice, NULL);
1218 } else {
1219 TRACE("Setting shader\n");
1220 if (This->allocated_shader_handles <= pShader - (VS_HIGHESTFIXEDFXF + 1)) {
1221 FIXME("(%p) : Number of shaders exceeds the maximum number of possible shaders\n", This);
1222 hrc = D3DERR_INVALIDCALL;
1223 } else {
1224 IDirect3DVertexShader8Impl *shader = This->shader_handles[pShader - (VS_HIGHESTFIXEDFXF + 1)];
1225 hrc = IWineD3DDevice_SetVertexShader(This->WineD3DDevice, 0 == shader ? NULL : shader->wineD3DVertexShader);
1228 TRACE("(%p) : returning hr(%u)\n", This, hrc);
1230 return hrc;
1233 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShader(LPDIRECT3DDEVICE8 iface, DWORD* ppShader) {
1234 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1235 IWineD3DVertexShader *pShader;
1236 HRESULT hrc = D3D_OK;
1238 TRACE("(%p) : Relay device@%p\n", This, This->WineD3DDevice);
1239 hrc = IWineD3DDevice_GetVertexShader(This->WineD3DDevice, &pShader);
1240 if (D3D_OK == hrc) {
1241 if(0 != pShader) {
1242 IDirect3DVertexShader8Impl *d3d8_shader;
1243 hrc = IWineD3DVertexShader_GetParent(pShader, (IUnknown **)&d3d8_shader);
1244 IWineD3DVertexShader_Release(pShader);
1245 *ppShader = (d3d8_shader->handle - This->shader_handles) + (VS_HIGHESTFIXEDFXF + 1);
1246 } else {
1247 WARN("(%p) : The shader has been set to NULL\n", This);
1249 /* TODO: Find out what should be returned, e.g. the FVF */
1250 *ppShader = 0;
1251 hrc = D3DERR_INVALIDCALL;
1253 } else {
1254 WARN("(%p) : Call to IWineD3DDevice_GetVertexShader failed %u (device %p)\n", This, hrc, This->WineD3DDevice);
1256 TRACE("(%p) : returning %#x\n", This, *ppShader);
1258 return hrc;
1261 static HRESULT WINAPI IDirect3DDevice8Impl_DeleteVertexShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
1262 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1264 TRACE("(%p) : pShader %#x\n", This, pShader);
1266 if (pShader <= VS_HIGHESTFIXEDFXF || This->allocated_shader_handles <= pShader - (VS_HIGHESTFIXEDFXF + 1)) {
1267 ERR("(%p) : Trying to delete an invalid handle\n", This);
1268 return D3DERR_INVALIDCALL;
1269 } else {
1270 shader_handle *handle = &This->shader_handles[pShader - (VS_HIGHESTFIXEDFXF + 1)];
1271 IDirect3DVertexShader8Impl *shader = *handle;
1272 while(IUnknown_Release((IUnknown *)shader));
1273 free_shader_handle(This, handle);
1276 return D3D_OK;
1279 static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, CONST void* pConstantData, DWORD ConstantCount) {
1280 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1281 TRACE("(%p) : Relay\n", This);
1283 return IWineD3DDevice_SetVertexShaderConstantF(This->WineD3DDevice, Register, (CONST float *)pConstantData, ConstantCount);
1286 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, void* pConstantData, DWORD ConstantCount) {
1287 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1288 TRACE("(%p) : Relay\n", This);
1290 return IWineD3DDevice_GetVertexShaderConstantF(This->WineD3DDevice, Register, (float *)pConstantData, ConstantCount);
1293 /* FIXME: There currently isn't a proper way to retrieve the declaration from
1294 * the wined3d shader. However, rather than simply adding this, the relation
1295 * between d3d8 and wined3d shaders should be fixed. A d3d8 vertex shader
1296 * should contain both a wined3d vertex shader and a wined3d vertex
1297 * declaration, and eg. SetVertexShader in d3d8 should set both of them in
1298 * wined3d. This would also allow us to get rid of the vertexDeclaration field
1299 * in IWineD3DVertexShaderImpl */
1300 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderDeclaration(LPDIRECT3DDEVICE8 iface, DWORD pVertexShader, void* pData, DWORD* pSizeOfData) {
1301 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1302 IDirect3DVertexShader8Impl *shader = NULL;
1304 TRACE("(%p) : pVertexShader %#x, pData %p, pSizeOfData %p\n", This, pVertexShader, pData, pSizeOfData);
1306 if (pVertexShader <= VS_HIGHESTFIXEDFXF || This->allocated_shader_handles <= pVertexShader - (VS_HIGHESTFIXEDFXF + 1)) {
1307 ERR("Passed an invalid shader handle.\n");
1308 return D3DERR_INVALIDCALL;
1311 shader = This->shader_handles[pVertexShader - (VS_HIGHESTFIXEDFXF + 1)];
1312 FIXME("Unimplemented, returning D3DERR_INVALIDCALL\n");
1313 return D3DERR_INVALIDCALL;
1316 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderFunction(LPDIRECT3DDEVICE8 iface, DWORD pVertexShader, void* pData, DWORD* pSizeOfData) {
1317 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1318 IDirect3DVertexShader8Impl *shader = NULL;
1320 TRACE("(%p) : pVertexShader %#x, pData %p, pSizeOfData %p\n", This, pVertexShader, pData, pSizeOfData);
1322 if (pVertexShader <= VS_HIGHESTFIXEDFXF || This->allocated_shader_handles <= pVertexShader - (VS_HIGHESTFIXEDFXF + 1)) {
1323 ERR("Passed an invalid shader handle.\n");
1324 return D3DERR_INVALIDCALL;
1327 shader = This->shader_handles[pVertexShader - (VS_HIGHESTFIXEDFXF + 1)];
1328 return IWineD3DVertexShader_GetFunction(shader->wineD3DVertexShader, pData, (UINT *)pSizeOfData);
1331 static HRESULT WINAPI IDirect3DDevice8Impl_SetIndices(LPDIRECT3DDEVICE8 iface, IDirect3DIndexBuffer8* pIndexData, UINT baseVertexIndex) {
1332 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1333 TRACE("(%p) Relay\n", This);
1334 return IWineD3DDevice_SetIndices(This->WineD3DDevice,
1335 NULL == pIndexData ? NULL : ((IDirect3DIndexBuffer8Impl *)pIndexData)->wineD3DIndexBuffer,
1336 baseVertexIndex);
1339 static HRESULT WINAPI IDirect3DDevice8Impl_GetIndices(LPDIRECT3DDEVICE8 iface, IDirect3DIndexBuffer8** ppIndexData,UINT* pBaseVertexIndex) {
1340 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1341 IWineD3DIndexBuffer *retIndexData = NULL;
1342 HRESULT rc = D3D_OK;
1344 TRACE("(%p) Relay\n", This);
1346 if(ppIndexData == NULL){
1347 return D3DERR_INVALIDCALL;
1350 rc = IWineD3DDevice_GetIndices(This->WineD3DDevice, &retIndexData, pBaseVertexIndex);
1351 if (D3D_OK == rc && NULL != retIndexData) {
1352 IWineD3DIndexBuffer_GetParent(retIndexData, (IUnknown **)ppIndexData);
1353 IWineD3DIndexBuffer_Release(retIndexData);
1354 } else {
1355 if(rc != D3D_OK) FIXME("Call to GetIndices failed\n");
1356 *ppIndexData = NULL;
1358 return rc;
1360 static HRESULT WINAPI IDirect3DDevice8Impl_CreatePixelShader(LPDIRECT3DDEVICE8 iface, CONST DWORD* pFunction, DWORD* ppShader) {
1361 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1362 IDirect3DPixelShader8Impl *object;
1363 HRESULT hrc = D3D_OK;
1365 TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This, pFunction, ppShader);
1367 if (NULL == ppShader) {
1368 TRACE("(%p) Invalid call\n", This);
1369 return D3DERR_INVALIDCALL;
1371 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1373 if (NULL == object) {
1374 return E_OUTOFMEMORY;
1375 } else {
1377 object->ref = 1;
1378 object->lpVtbl = &Direct3DPixelShader8_Vtbl;
1379 hrc = IWineD3DDevice_CreatePixelShader(This->WineD3DDevice, pFunction, &object->wineD3DPixelShader , (IUnknown *)object);
1380 if (D3D_OK != hrc) {
1381 FIXME("(%p) call to IWineD3DDevice_CreatePixelShader failed\n", This);
1382 HeapFree(GetProcessHeap(), 0 , object);
1383 *ppShader = 0;
1384 } else {
1385 shader_handle *handle = alloc_shader_handle(This);
1386 if (!handle) {
1387 ERR("Failed to allocate shader handle\n");
1388 IDirect3DVertexShader8_Release((IUnknown *)object);
1389 hrc = E_OUTOFMEMORY;
1390 } else {
1391 object->handle = handle;
1392 *handle = object;
1393 *ppShader = (handle - This->shader_handles) + VS_HIGHESTFIXEDFXF + 1;
1399 TRACE("(%p) : returning %p (handle %#x)\n", This, object, *ppShader);
1400 return hrc;
1403 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
1404 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1405 IDirect3DPixelShader8Impl *shader = NULL;
1407 TRACE("(%p) : pShader %#x\n", This, pShader);
1409 if (pShader > VS_HIGHESTFIXEDFXF && This->allocated_shader_handles > pShader - (VS_HIGHESTFIXEDFXF + 1)) {
1410 shader = This->shader_handles[pShader - (VS_HIGHESTFIXEDFXF + 1)];
1411 } else if (pShader) {
1412 ERR("Trying to set an invalid handle.\n");
1415 TRACE("(%p) : Setting shader %p\n", This, shader);
1416 return IWineD3DDevice_SetPixelShader(This->WineD3DDevice, shader == NULL ? NULL :shader->wineD3DPixelShader);
1419 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShader(LPDIRECT3DDEVICE8 iface, DWORD* ppShader) {
1420 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1421 IWineD3DPixelShader *object;
1423 HRESULT hrc = D3D_OK;
1424 TRACE("(%p) Relay\n", This);
1425 if (NULL == ppShader) {
1426 TRACE("(%p) Invalid call\n", This);
1427 return D3DERR_INVALIDCALL;
1430 hrc = IWineD3DDevice_GetPixelShader(This->WineD3DDevice, &object);
1431 if (D3D_OK == hrc && NULL != object) {
1432 IDirect3DPixelShader8Impl *d3d8_shader;
1433 hrc = IWineD3DPixelShader_GetParent(object, (IUnknown **)&d3d8_shader);
1434 IWineD3DPixelShader_Release(object);
1435 *ppShader = (d3d8_shader->handle - This->shader_handles) + (VS_HIGHESTFIXEDFXF + 1);
1436 } else {
1437 *ppShader = (DWORD)NULL;
1440 TRACE("(%p) : returning %#x\n", This, *ppShader);
1441 return hrc;
1444 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePixelShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
1445 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1447 TRACE("(%p) : pShader %#x\n", This, pShader);
1449 if (pShader <= VS_HIGHESTFIXEDFXF || This->allocated_shader_handles <= pShader - (VS_HIGHESTFIXEDFXF + 1)) {
1450 ERR("(%p) : Trying to delete an invalid handle\n", This);
1451 return D3DERR_INVALIDCALL;
1452 } else {
1453 shader_handle *handle = &This->shader_handles[pShader - (VS_HIGHESTFIXEDFXF + 1)];
1454 IDirect3DPixelShader8Impl *shader = *handle;
1455 while(IUnknown_Release((IUnknown *)shader));
1456 free_shader_handle(This, handle);
1459 return D3D_OK;
1462 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, CONST void* pConstantData, DWORD ConstantCount) {
1463 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1464 TRACE("(%p) Relay\n", This);
1466 return IWineD3DDevice_SetPixelShaderConstantF(This->WineD3DDevice, Register, (CONST float *)pConstantData, ConstantCount);
1469 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, void* pConstantData, DWORD ConstantCount) {
1470 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1471 TRACE("(%p) Relay\n", This);
1473 return IWineD3DDevice_GetPixelShaderConstantF(This->WineD3DDevice, Register, (float *)pConstantData, ConstantCount);
1476 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderFunction(LPDIRECT3DDEVICE8 iface, DWORD pPixelShader, void* pData, DWORD* pSizeOfData) {
1477 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1478 IDirect3DPixelShader8Impl *shader = NULL;
1480 TRACE("(%p) : pPixelShader %#x, pData %p, pSizeOfData %p\n", This, pPixelShader, pData, pSizeOfData);
1482 if (pPixelShader <= VS_HIGHESTFIXEDFXF || This->allocated_shader_handles <= pPixelShader - (VS_HIGHESTFIXEDFXF + 1)) {
1483 ERR("Passed an invalid shader handle.\n");
1484 return D3DERR_INVALIDCALL;
1487 shader = This->shader_handles[pPixelShader - (VS_HIGHESTFIXEDFXF + 1)];
1488 return IWineD3DPixelShader_GetFunction(shader->wineD3DPixelShader, pData, (UINT *)pSizeOfData);
1491 static HRESULT WINAPI IDirect3DDevice8Impl_DrawRectPatch(LPDIRECT3DDEVICE8 iface, UINT Handle,CONST float* pNumSegs,CONST D3DRECTPATCH_INFO* pRectPatchInfo) {
1492 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1493 TRACE("(%p) Relay\n", This);
1495 return IWineD3DDevice_DrawRectPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DRECTPATCH_INFO *)pRectPatchInfo);
1498 static HRESULT WINAPI IDirect3DDevice8Impl_DrawTriPatch(LPDIRECT3DDEVICE8 iface, UINT Handle,CONST float* pNumSegs,CONST D3DTRIPATCH_INFO* pTriPatchInfo) {
1499 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1500 TRACE("(%p) Relay\n", This);
1502 return IWineD3DDevice_DrawTriPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DTRIPATCH_INFO *)pTriPatchInfo);
1505 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePatch(LPDIRECT3DDEVICE8 iface, UINT Handle) {
1506 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1507 TRACE("(%p) Relay\n", This);
1509 return IWineD3DDevice_DeletePatch(This->WineD3DDevice, Handle);
1512 static HRESULT WINAPI IDirect3DDevice8Impl_SetStreamSource(LPDIRECT3DDEVICE8 iface, UINT StreamNumber,IDirect3DVertexBuffer8* pStreamData,UINT Stride) {
1513 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1514 TRACE("(%p) Relay\n" , This);
1516 return IWineD3DDevice_SetStreamSource(This->WineD3DDevice, StreamNumber,
1517 NULL == pStreamData ? NULL : ((IDirect3DVertexBuffer8Impl *)pStreamData)->wineD3DVertexBuffer,
1518 0/* Offset in bytes */, Stride);
1521 static HRESULT WINAPI IDirect3DDevice8Impl_GetStreamSource(LPDIRECT3DDEVICE8 iface, UINT StreamNumber,IDirect3DVertexBuffer8** pStream,UINT* pStride) {
1522 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1523 IWineD3DVertexBuffer *retStream = NULL;
1524 HRESULT rc = D3D_OK;
1526 TRACE("(%p) Relay\n" , This);
1528 if(pStream == NULL){
1529 return D3DERR_INVALIDCALL;
1532 rc = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber, (IWineD3DVertexBuffer **)&retStream, 0 /* Offset in bytes */, pStride);
1533 if (rc == D3D_OK && NULL != retStream) {
1534 IWineD3DVertexBuffer_GetParent(retStream, (IUnknown **)pStream);
1535 IWineD3DVertexBuffer_Release(retStream);
1536 }else{
1537 if (rc != D3D_OK){
1538 FIXME("Call to GetStreamSource failed %p\n", pStride);
1540 *pStream = NULL;
1543 return rc;
1547 const IDirect3DDevice8Vtbl Direct3DDevice8_Vtbl =
1549 IDirect3DDevice8Impl_QueryInterface,
1550 IDirect3DDevice8Impl_AddRef,
1551 IDirect3DDevice8Impl_Release,
1552 IDirect3DDevice8Impl_TestCooperativeLevel,
1553 IDirect3DDevice8Impl_GetAvailableTextureMem,
1554 IDirect3DDevice8Impl_ResourceManagerDiscardBytes,
1555 IDirect3DDevice8Impl_GetDirect3D,
1556 IDirect3DDevice8Impl_GetDeviceCaps,
1557 IDirect3DDevice8Impl_GetDisplayMode,
1558 IDirect3DDevice8Impl_GetCreationParameters,
1559 IDirect3DDevice8Impl_SetCursorProperties,
1560 IDirect3DDevice8Impl_SetCursorPosition,
1561 IDirect3DDevice8Impl_ShowCursor,
1562 IDirect3DDevice8Impl_CreateAdditionalSwapChain,
1563 IDirect3DDevice8Impl_Reset,
1564 IDirect3DDevice8Impl_Present,
1565 IDirect3DDevice8Impl_GetBackBuffer,
1566 IDirect3DDevice8Impl_GetRasterStatus,
1567 IDirect3DDevice8Impl_SetGammaRamp,
1568 IDirect3DDevice8Impl_GetGammaRamp,
1569 IDirect3DDevice8Impl_CreateTexture,
1570 IDirect3DDevice8Impl_CreateVolumeTexture,
1571 IDirect3DDevice8Impl_CreateCubeTexture,
1572 IDirect3DDevice8Impl_CreateVertexBuffer,
1573 IDirect3DDevice8Impl_CreateIndexBuffer,
1574 IDirect3DDevice8Impl_CreateRenderTarget,
1575 IDirect3DDevice8Impl_CreateDepthStencilSurface,
1576 IDirect3DDevice8Impl_CreateImageSurface,
1577 IDirect3DDevice8Impl_CopyRects,
1578 IDirect3DDevice8Impl_UpdateTexture,
1579 IDirect3DDevice8Impl_GetFrontBuffer,
1580 IDirect3DDevice8Impl_SetRenderTarget,
1581 IDirect3DDevice8Impl_GetRenderTarget,
1582 IDirect3DDevice8Impl_GetDepthStencilSurface,
1583 IDirect3DDevice8Impl_BeginScene,
1584 IDirect3DDevice8Impl_EndScene,
1585 IDirect3DDevice8Impl_Clear,
1586 IDirect3DDevice8Impl_SetTransform,
1587 IDirect3DDevice8Impl_GetTransform,
1588 IDirect3DDevice8Impl_MultiplyTransform,
1589 IDirect3DDevice8Impl_SetViewport,
1590 IDirect3DDevice8Impl_GetViewport,
1591 IDirect3DDevice8Impl_SetMaterial,
1592 IDirect3DDevice8Impl_GetMaterial,
1593 IDirect3DDevice8Impl_SetLight,
1594 IDirect3DDevice8Impl_GetLight,
1595 IDirect3DDevice8Impl_LightEnable,
1596 IDirect3DDevice8Impl_GetLightEnable,
1597 IDirect3DDevice8Impl_SetClipPlane,
1598 IDirect3DDevice8Impl_GetClipPlane,
1599 IDirect3DDevice8Impl_SetRenderState,
1600 IDirect3DDevice8Impl_GetRenderState,
1601 IDirect3DDevice8Impl_BeginStateBlock,
1602 IDirect3DDevice8Impl_EndStateBlock,
1603 IDirect3DDevice8Impl_ApplyStateBlock,
1604 IDirect3DDevice8Impl_CaptureStateBlock,
1605 IDirect3DDevice8Impl_DeleteStateBlock,
1606 IDirect3DDevice8Impl_CreateStateBlock,
1607 IDirect3DDevice8Impl_SetClipStatus,
1608 IDirect3DDevice8Impl_GetClipStatus,
1609 IDirect3DDevice8Impl_GetTexture,
1610 IDirect3DDevice8Impl_SetTexture,
1611 IDirect3DDevice8Impl_GetTextureStageState,
1612 IDirect3DDevice8Impl_SetTextureStageState,
1613 IDirect3DDevice8Impl_ValidateDevice,
1614 IDirect3DDevice8Impl_GetInfo,
1615 IDirect3DDevice8Impl_SetPaletteEntries,
1616 IDirect3DDevice8Impl_GetPaletteEntries,
1617 IDirect3DDevice8Impl_SetCurrentTexturePalette,
1618 IDirect3DDevice8Impl_GetCurrentTexturePalette,
1619 IDirect3DDevice8Impl_DrawPrimitive,
1620 IDirect3DDevice8Impl_DrawIndexedPrimitive,
1621 IDirect3DDevice8Impl_DrawPrimitiveUP,
1622 IDirect3DDevice8Impl_DrawIndexedPrimitiveUP,
1623 IDirect3DDevice8Impl_ProcessVertices,
1624 IDirect3DDevice8Impl_CreateVertexShader,
1625 IDirect3DDevice8Impl_SetVertexShader,
1626 IDirect3DDevice8Impl_GetVertexShader,
1627 IDirect3DDevice8Impl_DeleteVertexShader,
1628 IDirect3DDevice8Impl_SetVertexShaderConstant,
1629 IDirect3DDevice8Impl_GetVertexShaderConstant,
1630 IDirect3DDevice8Impl_GetVertexShaderDeclaration,
1631 IDirect3DDevice8Impl_GetVertexShaderFunction,
1632 IDirect3DDevice8Impl_SetStreamSource,
1633 IDirect3DDevice8Impl_GetStreamSource,
1634 IDirect3DDevice8Impl_SetIndices,
1635 IDirect3DDevice8Impl_GetIndices,
1636 IDirect3DDevice8Impl_CreatePixelShader,
1637 IDirect3DDevice8Impl_SetPixelShader,
1638 IDirect3DDevice8Impl_GetPixelShader,
1639 IDirect3DDevice8Impl_DeletePixelShader,
1640 IDirect3DDevice8Impl_SetPixelShaderConstant,
1641 IDirect3DDevice8Impl_GetPixelShaderConstant,
1642 IDirect3DDevice8Impl_GetPixelShaderFunction,
1643 IDirect3DDevice8Impl_DrawRectPatch,
1644 IDirect3DDevice8Impl_DrawTriPatch,
1645 IDirect3DDevice8Impl_DeletePatch
1648 /* Internal function called back during the CreateDevice to create a render target */
1649 HRESULT WINAPI D3D8CB_CreateSurface(IUnknown *device, IUnknown *pSuperior, UINT Width, UINT Height,
1650 WINED3DFORMAT Format, DWORD Usage, WINED3DPOOL Pool, UINT Level,
1651 IWineD3DSurface **ppSurface, HANDLE *pSharedHandle) {
1653 HRESULT res = D3D_OK;
1654 IDirect3DSurface8Impl *d3dSurface = NULL;
1655 BOOL Lockable = TRUE;
1657 if((WINED3DPOOL_DEFAULT == Pool && WINED3DUSAGE_DYNAMIC != Usage))
1658 Lockable = FALSE;
1660 TRACE("relay\n");
1661 res = IDirect3DDevice8Impl_CreateSurface((IDirect3DDevice8 *)device, Width, Height, (D3DFORMAT)Format, Lockable, FALSE/*Discard*/, Level, (IDirect3DSurface8 **)&d3dSurface, D3DRTYPE_SURFACE, Usage, Pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
1663 if (SUCCEEDED(res)) {
1664 *ppSurface = d3dSurface->wineD3DSurface;
1665 d3dSurface->container = pSuperior;
1666 IUnknown_Release(d3dSurface->parentDevice);
1667 d3dSurface->parentDevice = NULL;
1668 d3dSurface->forwardReference = pSuperior;
1669 } else {
1670 FIXME("(%p) IDirect3DDevice8_CreateSurface failed\n", device);
1672 return res;
1675 ULONG WINAPI D3D8CB_DestroySurface(IWineD3DSurface *pSurface) {
1676 IDirect3DSurface8Impl* surfaceParent;
1677 TRACE("(%p) call back\n", pSurface);
1679 IWineD3DSurface_GetParent(pSurface, (IUnknown **) &surfaceParent);
1680 /* GetParent's AddRef was forwarded to an object in destruction.
1681 * Releasing it here again would cause an endless recursion. */
1682 surfaceParent->forwardReference = NULL;
1683 return IDirect3DSurface8_Release((IDirect3DSurface8*) surfaceParent);